[PATCH] D28445: [Analyzer] Extend taint propagation and checking

2017-02-01 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a subscriber: a.sidorin.
NoQ added a comment.

Hello! Sorry, i'm very distracted recently.

I think your new approach should work, however it would be much easier and more 
straightforward to just ask the store manager to provide the default-bound 
symbol for a region directly, instead of trying to derive from it manually and 
then underive it back. In inline comments i also show that sometimes we're not 
really that much interested in the particular derived symbols.




Comment at: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:442
+
+const RecordDecl *RD = RT->getDecl()->getDefinition();
+for (const auto *I : RD->fields()) {

We need to be careful in the case when we don't have the definition in the 
current translation unit. In this case we may still have derived symbols by 
casting the pointer into some blindly guessed type, which may be primitive or 
having well-defined primitive fields.

By the way, in D26837 i'm suspecting that there are other errors of this kind 
in the checker, eg. when a function returns a void pointer, we put taint on 
symbols of type "void", which is weird.

Adding Alexey who may recall something on this topic.



Comment at: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp:455
+  } else if (T->isArrayType()) {
+const ArrayType *AT = T->getAsArrayTypeUnsafe();
+const ElementRegion *ER =

The "safe" way to do this is to use one of the `ASTContext`'s 
`get***ArrayType()` methods.



Comment at: lib/StaticAnalyzer/Core/ProgramState.cpp:667
 
+  // If this a derived symbol, taint the parent symbol.
+  if (const SymbolDerived *SD = dyn_cast(Sym))

While this is quite vague, i can imagine us wanting to taint only a particular 
field of a symbolic structure. Considering that taint also automatically 
propagates in the opposite direction (from parent symbol to derived symbol), 
i'd rather preserve some freedom by moving this code to the taint-checker (and 
other places where we may want to generate taint; for now, it's 
`getLCVSymbol()`), forcing them to manually lookup the parent symbol and put 
taint there when they want to.



Comment at: test/Analysis/taint-tester.c:53
   scanf("%d", &xy.x);
   int tx = xy.x; // expected-warning + {{tainted}}
+  int ty = xy.y; // expected-warning + {{tainted}}

I don't think you'd be able to pass this test by tweaking the taint mechanisms 
alone. The original FIXME here appears because the second `scanf()` destroys 
the first `scanf()`'s binding, together with the default-bound symbol. There's 
no way you preserve taint on `y` without adding taint on `z`, unless you model 
`scanf()` to update only specific store bindings.

In any case, this makes a good example for my comment in `addTaint()`. Because 
false positives are worse than false negatives, we shouldn't add taint to the 
default-bound symbol here.


https://reviews.llvm.org/D28445



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29358: [OpenMP] Report an error for -faltivec on anything other than PowerPC.

2017-02-01 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Did not find any errors in this patch, neither in code, nor in test


Repository:
  rL LLVM

https://reviews.llvm.org/D29358



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29339: [OpenMP] Add support for auxiliary triple specification

2017-02-01 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/Frontend/CompilerInstance.cpp:914-915
+  // Create TargetInfo for the other side of CUDA and OpenMP compilation.
+  if ((getLangOpts().CUDA && !getFrontendOpts().AuxTriple.empty()) ||
+  (getLangOpts().OpenMPIsDevice && !getFrontendOpts().AuxTriple.empty())) {
 auto TO = std::make_shared();

It's better to check `!getFrontendOpts().AuxTriple.empty()` only once in this 
condition


Repository:
  rL LLVM

https://reviews.llvm.org/D29339



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293752 - clang-format: Don't force-wrap multiline RHSs for 2-operand experssions.

2017-02-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Feb  1 03:23:39 2017
New Revision: 293752

URL: http://llvm.org/viewvc/llvm-project?rev=293752&view=rev
Log:
clang-format: Don't force-wrap multiline RHSs for 2-operand experssions.

This rows back on r288120, r291801 and r292110. I apologize in advance
for the churn. All of those revisions where meant to make the wrapping
of RHS expressions more consistent. However, now that they are
consistent, we seem to be a bit too eager.

The reasoning here is that I think it is generally correct that we want
to line-wrap before multiline RHS expressions (or multiline arguments to
a function call). However, if there are only two of such operands or
arguments, there is always a clear vertical separation between them and
the additional line break seems much less desirable.

Somewhat good examples are expressions like:

  EXPECT_EQ(2, someLongExpression(
   orCall));

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=293752&r1=293751&r2=293752&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Wed Feb  1 03:23:39 2017
@@ -424,7 +424,12 @@ void ContinuationIndenter::addTokenOnCur
 (P->is(TT_BinaryOperator) &&
  Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None) ||
 (P->is(TT_ConditionalExpr) && Style.BreakBeforeTernaryOperators);
-if (!BreakBeforeOperator ||
+// Don't do this if there are only two operands. In these cases, there is
+// always a nice vertical separation between them and the extra line break
+// does not help.
+bool HasTwoOperands =
+P->OperatorIndex == 0 && !P->NextOperator && 
!P->is(TT_ConditionalExpr);
+if ((!BreakBeforeOperator && !HasTwoOperands) ||
 (!State.Stack.back().LastOperatorWrapped && BreakBeforeOperator))
   State.Stack.back().NoLineBreakInOperand = true;
   }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=293752&r1=293751&r2=293752&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Feb  1 03:23:39 2017
@@ -4060,9 +4060,14 @@ TEST_F(FormatTest, ExpressionIndentation
"aa +\n"
"bbb) {\n}");
   verifyFormat("if () {\n"
+   "} else if (a && b > // break\n"
+   "c) {\n"
+   "}");
+  verifyFormat("if () {\n"
"} else if (a &&\n"
"   b > // break\n"
-   "   c) {\n"
+   "   c &&\n"
+   "   d) {\n"
"}");
 
   // Presence of a trailing comment used to change indentation of b.
@@ -4167,7 +4172,7 @@ TEST_F(FormatTest, NoOperandAlignment) {
Style);
   verifyFormat("int a = aa\n"
"+ b\n"
-   "* ;",
+   "* ;\n",
Style);
 
   Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
@@ -4659,9 +4664,13 @@ TEST_F(FormatTest, BreaksDesireably) {
   "aa(new Aaaa(\n"
   "a));");
   verifyFormat(
+  "aa(aaa, new Aaaa(\n"
+  "a));");
+  verifyFormat(
   "aa(aaa,\n"
   "   new Aaaa(\n"
-  "   a));");
+  "   a),\n"
+  "   );");
   verifyFormat("a(aa +\n"
"  aa,\n"
"  aa);");
@@ -5140,11 +5149,18 @@ TEST_F(FormatTest, ParenthesesAndOperand
 
 TEST_F(FormatTest, BreaksConditionalExpressions) {
   verifyFormat(
-  "(,\n"
+  "(, aa\n"
+  "   ? a\n"
+  "   : aa);");
+  verifyFormat(
+  "(aa, ,\n"
   " aa ? aa

r293754 - Fix Index test after recent clang-format change.

2017-02-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Feb  1 04:00:10 2017
New Revision: 293754

URL: http://llvm.org/viewvc/llvm-project?rev=293754&view=rev
Log:
Fix Index test after recent clang-format change.

Modified:
cfe/trunk/test/Index/overriding-ftemplate-comments.cpp

Modified: cfe/trunk/test/Index/overriding-ftemplate-comments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/overriding-ftemplate-comments.cpp?rev=293754&r1=293753&r2=293754&view=diff
==
--- cfe/trunk/test/Index/overriding-ftemplate-comments.cpp (original)
+++ cfe/trunk/test/Index/overriding-ftemplate-comments.cpp Wed Feb  1 04:00:10 
2017
@@ -77,10 +77,10 @@ void comment_to_html_conversion_21();
 template  class 
BBB > class AAA>
 void comment_to_html_conversion_22();
 
-// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#v#template
  
class BBB>\n  class AAA>\nvoid 
comment_to_html_conversion_22()C10
 Ccc 1 
AAA1
 Zzz 
C2 
Ccc 2 
C3 
Ccc 3 
C4 
Ccc 4 
BBB 
Bbb]
+// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#v#template
  class 
BBB>\n  class AAA>\nvoid 
comment_to_html_conversion_22()C10
 Ccc 1 
AAA1
 Zzz 
C2 
Ccc 2 
C3 
Ccc 3 
C4 
Ccc 4 
BBB 
Bbb]
 
 template 
class QQQ> class PPP>
 void comment_to_html_conversion_22();
 
-// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#v#template
  class QQQ>\n class PPP>\nvoid 
comment_to_html_conversion_22()CCC10
 Ccc 1 
PPP1
 Zzz 
CCC2 
Ccc 2 
CCC3 
Ccc 3 
CCC4 
Ccc 4 
QQQ 
Bbb]
+// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#v#template
 \n class QQQ> class PPP>\nvoid 
comment_to_html_conversion_22()CCC10
 Ccc 1 
PPP1
 Zzz 
CCC2 
Ccc 2 
CCC3 
Ccc 3 
CCC4 
Ccc 4 
QQQ 
Bbb]
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29383: [clang-format] Fix regression about not aligning trailing comments in case they were previously aligned, but at different indent.

2017-02-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good


https://reviews.llvm.org/D29383



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293755 - [clang-format] Fix regression about not aligning trailing comments in case they were previously aligned, but at different indent.

2017-02-01 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Wed Feb  1 04:10:04 2017
New Revision: 293755

URL: http://llvm.org/viewvc/llvm-project?rev=293755&view=rev
Log:
[clang-format] Fix regression about not aligning trailing comments in case they 
were previously aligned, but at different indent.

Summary:
Comment reflower was adding untouchable tokens in case two consecutive comment 
lines are aligned in the source code. This disallows the whitespace manager to 
re-indent them later.

source:
```
int i = f(abc, // line 1
  d, // line 2
 // line 3
  b);
```
Since line 2 and line 3 are aligned, the reflower was marking line 3 as 
untouchable; however the three comment lines need to be re-aligned.
output before:
```
int i = f(abc, // line 1
  d,   // line 2
 // line 3
  b);
```
output after:
```
int i = f(abc, // line 1
  d,   // line 2
   // line 3
  b);
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: sammccall, cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D29383

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=293755&r1=293754&r2=293755&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Wed Feb  1 04:10:04 2017
@@ -803,18 +803,16 @@ void BreakableLineCommentSection::replac
   ContentColumn[LineIndex] -
   (Content[LineIndex].data() - Lines[LineIndex].data()) +
   (OriginalPrefix[LineIndex].size() - Prefix[LineIndex].size());
-  if (tokenAt(LineIndex).OriginalColumn != LineColumn) {
-Whitespaces.replaceWhitespace(*Tokens[LineIndex],
-  /*Newlines=*/1,
-  /*Spaces=*/LineColumn,
-  /*StartOfTokenColumn=*/LineColumn,
-  /*InPPDirective=*/false);
-  } else {
-// The whitespace preceding the first line of this token does not need
-// to be touched.
-Whitespaces.addUntouchableToken(tokenAt(LineIndex),
-/*InPPDirective=*/false);
-  }
+
+  // We always want to create a replacement instead of adding an 
untouchable
+  // token, even if LineColumn is the same as the original column of the
+  // token. This is because WhitespaceManager doesn't align trailing
+  // comments if they are untouchable.
+  Whitespaces.replaceWhitespace(*Tokens[LineIndex],
+/*Newlines=*/1,
+/*Spaces=*/LineColumn,
+/*StartOfTokenColumn=*/LineColumn,
+/*InPPDirective=*/false);
 }
   }
   if (OriginalPrefix[LineIndex] != Prefix[LineIndex]) {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=293755&r1=293754&r2=293755&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Feb  1 04:10:04 2017
@@ -2238,7 +2238,7 @@ TEST_F(FormatTest, ReflowsComments) {
   EXPECT_EQ("int i; // This long\n"
 "   // line gets\n"
 "   // broken.\n"
-"   //  \n"
+"   //\n"
 "   // keep.\n",
 format("int i; // This long line gets broken.\n"
"   //  \n"
@@ -11741,7 +11741,7 @@ TEST_F(ReplacementTest, SortIncludesAfte
   EXPECT_EQ(Expected, *Result);
 }
 
-TEST_F(FormatTest, AllignTrailingComments) {
+TEST_F(FormatTest, AlignTrailingComments) {
   EXPECT_EQ("#define MACRO(V)   \\\n"
 "  V(Rt2) /* one more char */   \\\n"
 "  V(Rs)  /* than here  */  \\\n"
@@ -11751,6 +11751,15 @@ TEST_F(FormatTest, AllignTrailingComment
"V(Rs) /* than here  */\\\n"
"/* comment 3 */ \\\n",
getLLVMStyleWithColumns(40)));
+  EXPECT_EQ("int i = f(abc, // line 1\n"
+"  d,   // line 2\n"
+"   // line 3\n"
+"  b);",
+format("int i = f(abc, // line 1\n"
+   "  d, // line 2\n"
+   " // line 3\n"
+   "  b);",
+   getLLVMStyleWithColumns(40)));
 }
 } // end namespace
 } // end namespace format


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/

[PATCH] D29383: [clang-format] Fix regression about not aligning trailing comments in case they were previously aligned, but at different indent.

2017-02-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293755: [clang-format] Fix regression about not aligning 
trailing comments in case they… (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D29383?vs=86595&id=86596#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29383

Files:
  cfe/trunk/lib/Format/BreakableToken.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -2238,7 +2238,7 @@
   EXPECT_EQ("int i; // This long\n"
 "   // line gets\n"
 "   // broken.\n"
-"   //  \n"
+"   //\n"
 "   // keep.\n",
 format("int i; // This long line gets broken.\n"
"   //  \n"
@@ -11741,7 +11741,7 @@
   EXPECT_EQ(Expected, *Result);
 }
 
-TEST_F(FormatTest, AllignTrailingComments) {
+TEST_F(FormatTest, AlignTrailingComments) {
   EXPECT_EQ("#define MACRO(V)   \\\n"
 "  V(Rt2) /* one more char */   \\\n"
 "  V(Rs)  /* than here  */  \\\n"
@@ -11751,6 +11751,15 @@
"V(Rs) /* than here  */\\\n"
"/* comment 3 */ \\\n",
getLLVMStyleWithColumns(40)));
+  EXPECT_EQ("int i = f(abc, // line 1\n"
+"  d,   // line 2\n"
+"   // line 3\n"
+"  b);",
+format("int i = f(abc, // line 1\n"
+   "  d, // line 2\n"
+   " // line 3\n"
+   "  b);",
+   getLLVMStyleWithColumns(40)));
 }
 } // end namespace
 } // end namespace format
Index: cfe/trunk/lib/Format/BreakableToken.cpp
===
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -803,18 +803,16 @@
   ContentColumn[LineIndex] -
   (Content[LineIndex].data() - Lines[LineIndex].data()) +
   (OriginalPrefix[LineIndex].size() - Prefix[LineIndex].size());
-  if (tokenAt(LineIndex).OriginalColumn != LineColumn) {
-Whitespaces.replaceWhitespace(*Tokens[LineIndex],
-  /*Newlines=*/1,
-  /*Spaces=*/LineColumn,
-  /*StartOfTokenColumn=*/LineColumn,
-  /*InPPDirective=*/false);
-  } else {
-// The whitespace preceding the first line of this token does not need
-// to be touched.
-Whitespaces.addUntouchableToken(tokenAt(LineIndex),
-/*InPPDirective=*/false);
-  }
+
+  // We always want to create a replacement instead of adding an 
untouchable
+  // token, even if LineColumn is the same as the original column of the
+  // token. This is because WhitespaceManager doesn't align trailing
+  // comments if they are untouchable.
+  Whitespaces.replaceWhitespace(*Tokens[LineIndex],
+/*Newlines=*/1,
+/*Spaces=*/LineColumn,
+/*StartOfTokenColumn=*/LineColumn,
+/*InPPDirective=*/false);
 }
   }
   if (OriginalPrefix[LineIndex] != Prefix[LineIndex]) {


Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -2238,7 +2238,7 @@
   EXPECT_EQ("int i; // This long\n"
 "   // line gets\n"
 "   // broken.\n"
-"   //  \n"
+"   //\n"
 "   // keep.\n",
 format("int i; // This long line gets broken.\n"
"   //  \n"
@@ -11741,7 +11741,7 @@
   EXPECT_EQ(Expected, *Result);
 }
 
-TEST_F(FormatTest, AllignTrailingComments) {
+TEST_F(FormatTest, AlignTrailingComments) {
   EXPECT_EQ("#define MACRO(V)   \\\n"
 "  V(Rt2) /* one more char */   \\\n"
 "  V(Rs)  /* than here  */  \\\n"
@@ -11751,6 +11751,15 @@
"V(Rs) /* than here  */\\\n"
"/* comment 3 */ \\\n",
getLLVMStyleWithColumns(40)));
+  EXPECT_EQ("int i = f(abc, // line 1\n"
+"  d,   // line 2\n"
+"   // line 3\n"
+"  b);",
+format("int i = f(abc, // line 1\n"
+   "  d, // line 2\n"
+   " // line 3\n"
+   "  b);",
+

[PATCH] D29384: [analyzer] Fix an assertion fail in CStringSyntaxChecker

2017-02-01 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun created this revision.

Right now CStringSytanxChecker assumes that the argument of a sizeof expression 
is an expression. The argument can also be a type. In this case an assertion 
fail will be triggered when the SubExpression is being queried. I fixed this 
issue and did other minor cleanups in the checker.


Repository:
  rL LLVM

https://reviews.llvm.org/D29384

Files:
  lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
  test/Analysis/cstring-syntax.c


Index: test/Analysis/cstring-syntax.c
===
--- test/Analysis/cstring-syntax.c
+++ test/Analysis/cstring-syntax.c
@@ -10,4 +10,6 @@
   strncat(dest, "AAA", sizeof(dest)); // 
expected-warning {{Potential buffer overflow. Replace with}}
   strncat(dest, "AAA", sizeof(dest) - 
strlen(dest)); // expected-warning {{Potential buffer overflow. Replace with}}
   strncat(dest, src, sizeof(src)); // expected-warning {{Potential buffer 
overflow. Replace with}}
+  // Should not crash when sizeof has a type argument.
+  strncat(dest, "AAA", sizeof(char));
 }
Index: lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
@@ -36,25 +36,24 @@
   AnalysisDeclContext* AC;
 
   /// Check if two expressions refer to the same declaration.
-  inline bool sameDecl(const Expr *A1, const Expr *A2) {
-if (const DeclRefExpr *D1 = dyn_cast(A1->IgnoreParenCasts()))
-  if (const DeclRefExpr *D2 = 
dyn_cast(A2->IgnoreParenCasts()))
+  bool sameDecl(const Expr *A1, const Expr *A2) {
+if (const auto *D1 = dyn_cast(A1->IgnoreParenCasts()))
+  if (const auto *D2 = dyn_cast(A2->IgnoreParenCasts()))
 return D1->getDecl() == D2->getDecl();
 return false;
   }
 
   /// Check if the expression E is a sizeof(WithArg).
-  inline bool isSizeof(const Expr *E, const Expr *WithArg) {
-if (const UnaryExprOrTypeTraitExpr *UE =
-dyn_cast(E))
-  if (UE->getKind() == UETT_SizeOf)
+  bool isSizeof(const Expr *E, const Expr *WithArg) {
+if (const auto *UE = dyn_cast(E))
+  if (UE->getKind() == UETT_SizeOf && !UE->isArgumentType())
 return sameDecl(UE->getArgumentExpr(), WithArg);
 return false;
   }
 
   /// Check if the expression E is a strlen(WithArg).
-  inline bool isStrlen(const Expr *E, const Expr *WithArg) {
-if (const CallExpr *CE = dyn_cast(E)) {
+  bool isStrlen(const Expr *E, const Expr *WithArg) {
+if (const auto *CE = dyn_cast(E)) {
   const FunctionDecl *FD = CE->getDirectCallee();
   if (!FD)
 return false;
@@ -65,14 +64,14 @@
   }
 
   /// Check if the expression is an integer literal with value 1.
-  inline bool isOne(const Expr *E) {
-if (const IntegerLiteral *IL = dyn_cast(E))
+  bool isOne(const Expr *E) {
+if (const auto *IL = dyn_cast(E))
   return (IL->getValue().isIntN(1));
 return false;
   }
 
-  inline StringRef getPrintableName(const Expr *E) {
-if (const DeclRefExpr *D = dyn_cast(E->IgnoreParenCasts()))
+  StringRef getPrintableName(const Expr *E) {
+if (const auto *D = dyn_cast(E->IgnoreParenCasts()))
   return D->getDecl()->getName();
 return StringRef();
   }
@@ -82,8 +81,8 @@
   bool containsBadStrncatPattern(const CallExpr *CE);
 
 public:
-  WalkAST(const CheckerBase *checker, BugReporter &br, AnalysisDeclContext *ac)
-  : Checker(checker), BR(br), AC(ac) {}
+  WalkAST(const CheckerBase *Checker, BugReporter &BR, AnalysisDeclContext *AC)
+  : Checker(Checker), BR(BR), AC(AC) {}
 
   // Statement visitor methods.
   void VisitChildren(Stmt *S);
@@ -108,8 +107,7 @@
   const Expr *LenArg = CE->getArg(2);
 
   // Identify wrong size expressions, which are commonly used instead.
-  if (const BinaryOperator *BE =
-  dyn_cast(LenArg->IgnoreParenCasts())) {
+  if (const auto *BE = dyn_cast(LenArg->IgnoreParenCasts())) {
 // - sizeof(dst) - strlen(dst)
 if (BE->getOpcode() == BO_Sub) {
   const Expr *L = BE->getLHS();


Index: test/Analysis/cstring-syntax.c
===
--- test/Analysis/cstring-syntax.c
+++ test/Analysis/cstring-syntax.c
@@ -10,4 +10,6 @@
   strncat(dest, "AAA", sizeof(dest)); // expected-warning {{Potential buffer overflow. Replace with}}
   strncat(dest, "AAA", sizeof(dest) - strlen(dest)); // expected-warning {{Potential buffer overflow. Replace with}}
   strncat(dest, src, sizeof(src)); // expected-warning {{Potential buffer overflow. Replace with}}
+  // Should not crash when sizeof has a type argument.
+  strncat(dest, "AAA", sizeof(char));
 }
Index: lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp

[PATCH] D20561: Warn when taking address of packed member

2017-02-01 Thread Roger via Phabricator via cfe-commits
royger reopened this revision.
royger added a comment.
This revision is now accepted and ready to land.

Hello,

This addition is silly, and too noisy for real world usage.

For once, it doesn't really check whether the access is actually unaligned or 
not, and then on x86 for example unaligned accesses are allowed (although with 
a performance penalty). Please either make this only complain about real 
unaligned accesses, or remove it. I don't think it's going to be used by any 
real-world projects, since it's too noise and gives false positives.


Repository:
  rL LLVM

https://reviews.llvm.org/D20561



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293759 - Revert r293518 as it caused module linking error in clang-reorder-fields

2017-02-01 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Wed Feb  1 04:52:02 2017
New Revision: 293759

URL: http://llvm.org/viewvc/llvm-project?rev=293759&view=rev
Log:
Revert r293518 as it caused module linking error in clang-reorder-fields

This commit reverts "r293518 - [ASTMatchers] Sprinkle some constexpr on the
global matcher constructors" because after it a buildbot that builds clang
stage 2 with modules failed to link clang-reorder-fields.

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=293759&r1=293758&r2=293759&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Wed Feb  1 
04:52:02 2017
@@ -1459,7 +1459,7 @@ class VariadicDynCastAllOfMatcher
 : public VariadicFunction, Matcher,
   makeDynCastAllOfComposite> {
 public:
-  constexpr VariadicDynCastAllOfMatcher() {}
+  VariadicDynCastAllOfMatcher() {}
 };
 
 /// \brief A \c VariadicAllOfMatcher object is a variadic functor that takes
@@ -1477,7 +1477,7 @@ class VariadicAllOfMatcher
 : public VariadicFunction, Matcher,
   makeAllOfComposite> {
 public:
-  constexpr VariadicAllOfMatcher() {}
+  VariadicAllOfMatcher() {}
 };
 
 /// \brief Matches nodes of type \c TLoc for which the inner
@@ -1598,7 +1598,7 @@ public:
 
   struct Func
   : public VariadicFunction, &Self::create> {
-constexpr Func() {}
+Func() {}
   };
 
 private:


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r293518 - [ASTMatchers] Sprinkle some constexpr on the global matcher constructors.

2017-02-01 Thread Alex L via cfe-commits
Hi Benjamin,

This commit has caused a linking in our stage 2 modules buildbot at
http://lab.llvm.org:8080/green/job/clang-stage2-cmake-modulesRDA/.
Specifically, after this commit 'clang-reorder-fields' gets the following
linking error:

FAILED: bin/clang-reorder-fields
: && 
/Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-modulesRDA@2/host-compiler/bin/clang++
  -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic
-Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor
-Wdelete-non-virtual-dtor -Wstring-conversion -Werror=date-time -std=c++11
-fmodules
-fmodules-cache-path=/Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-modulesRDA@2/clang-build/module.cache
-fcxx-modules -gmodules -fcolor-diagnostics -fno-common
-Woverloaded-virtual -Wno-nested-anon-types -O2 -g -DNDEBUG
-Wl,-search_paths_first -Wl,-headerpad_max_install_names -Wl,-dead_strip
tools/clang/tools/extra/clang-reorder-fields/tool/CMakeFiles/clang-reorder-fields.dir/ClangReorderFields.cpp.o
 -o bin/clang-reorder-fields  lib/libLLVMSupport.a lib/libclangBasic.a
lib/libclangFrontend.a lib/libclangReorderFields.a lib/libclangRewrite.a
lib/libclangTooling.a lib/libclangToolingCore.a lib/libclangIndex.a
lib/libclangFrontend.a lib/libclangParse.a lib/libLLVMMCParser.a
lib/libclangSerialization.a lib/libclangSema.a lib/libclangEdit.a
lib/libclangAnalysis.a lib/libLLVMBitReader.a lib/libLLVMProfileData.a
lib/libclangDriver.a lib/libLLVMOption.a lib/libclangASTMatchers.a
lib/libclangFormat.a lib/libclangToolingCore.a lib/libclangRewrite.a
lib/libclangAST.a lib/libclangLex.a lib/libclangBasic.a lib/libLLVMCore.a
lib/libLLVMMC.a lib/libLLVMSupport.a -lcurses -lz -lm lib/libLLVMDemangle.a
-Wl,-rpath,@loader_path/../lib && :
Undefined symbols for architecture x86_64:
  "clang::ast_matchers::recordDecl", referenced from:
  clang::reorder_fields::(anonymous
namespace)::ReorderingConsumer::HandleTranslationUnit(clang::ASTContext&)
in libclangReorderFields.a(ReorderFieldsAction.cpp.o)
ld: symbol(s) not found for architecture x86_64

This might be a bug/regression in clang and modules since in my opinion the
link should succeed. I've reverted your commit in r293759 while we are
investigating.

Thanks,
Alex


On 30 January 2017 at 18:20, Benjamin Kramer via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: d0k
> Date: Mon Jan 30 12:20:00 2017
> New Revision: 293518
>
> URL: http://llvm.org/viewvc/llvm-project?rev=293518&view=rev
> Log:
> [ASTMatchers] Sprinkle some constexpr on the global matcher constructors.
>
> This dramatically reduces the size of the global constructors we emit
> for those variables in debug mode.
>
> Modified:
> cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>
> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/ASTMatchers/ASTMatchersInternal.h?rev=293518&r1=293517&r2=293518&
> view=diff
> 
> ==
> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Mon Jan 30
> 12:20:00 2017
> @@ -1459,7 +1459,7 @@ class VariadicDynCastAllOfMatcher
>  : public VariadicFunction, Matcher,
>makeDynCastAllOfComposite TargetT>> {
>  public:
> -  VariadicDynCastAllOfMatcher() {}
> +  constexpr VariadicDynCastAllOfMatcher() {}
>  };
>
>  /// \brief A \c VariadicAllOfMatcher object is a variadic functor that
> takes
> @@ -1477,7 +1477,7 @@ class VariadicAllOfMatcher
>  : public VariadicFunction, Matcher,
>makeAllOfComposite> {
>  public:
> -  VariadicAllOfMatcher() {}
> +  constexpr VariadicAllOfMatcher() {}
>  };
>
>  /// \brief Matches nodes of type \c TLoc for which the inner
> @@ -1598,7 +1598,7 @@ public:
>
>struct Func
>: public VariadicFunction, &Self::create>
> {
> -Func() {}
> +constexpr Func() {}
>};
>
>  private:
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D6549: ASTImporter: Propagate implicit flag to imported record and field decls

2017-02-01 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

This should be fixed in r269693.


https://reviews.llvm.org/D6549



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20561: Warn when taking address of packed member

2017-02-01 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 added a comment.

In https://reviews.llvm.org/D20561#662922, @royger wrote:

>


Hi,

some targets do not support unaligned accesses so this warning is valuable in 
terms of portability. In platforms where unaligned accesses are allowed, it may 
happen that such accesses incur in a performance penalty. So there is also 
value in terms of performance.

We fixed all identified false positives in later patches to this one. So maybe 
you want to check against trunk clang. If trunk still diagnoses false 
positives, please report them to me and I will be more than happy to fix them.

Kind regards.


Repository:
  rL LLVM

https://reviews.llvm.org/D20561



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28989: [X86][MS]Adjacent comments within multi-line inline assembly statement

2017-02-01 Thread Marina Yatsina via Phabricator via cfe-commits
myatsina accepted this revision.
myatsina added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rL LLVM

https://reviews.llvm.org/D28989



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20561: Warn when taking address of packed member

2017-02-01 Thread Roger via Phabricator via cfe-commits
royger added a comment.

In https://reviews.llvm.org/D20561#662959, @rogfer01 wrote:

> We fixed all identified false positives in later patches to this one. So 
> maybe you want to check against trunk clang. If trunk still diagnoses false 
> positives, please report them to me and I will be more than happy to fix them.


Can you tell me which revisions are those? It seems like they are not contained 
in clang 4.0 AFAICT.


Repository:
  rL LLVM

https://reviews.llvm.org/D20561



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20561: Warn when taking address of packed member

2017-02-01 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 added a comment.

In https://reviews.llvm.org/D20561#662963, @royger wrote:

> In https://reviews.llvm.org/D20561#662959, @rogfer01 wrote:
>
> > We fixed all identified false positives in later patches to this one. So 
> > maybe you want to check against trunk clang. If trunk still diagnoses false 
> > positives, please report them to me and I will be more than happy to fix 
> > them.
>
>
> Can you tell me which revisions are those? It seems like they are not 
> contained in clang 4.0 AFAICT.


https://reviews.llvm.org/rL283304
https://reviews.llvm.org/rL286798

The fixes for the false positives are in the second change but the first is 
required for the second to apply cleanly.

Regards


Repository:
  rL LLVM

https://reviews.llvm.org/D20561



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D6550: ASTImporter: Fix missing SourceLoc imports

2017-02-01 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Hi Gabor. One of the bugs fixed in this patch is still present in master, other 
two are already fixed.




Comment at: lib/AST/ASTImporter.cpp:2749
   // Create the imported function.
+  SourceLocation StartLoc = Importer.Import(D->getInnerLocStart());
   TypeSourceInfo *TInfo = Importer.Import(D->getTypeSourceInfo());

This chunk should be fixed by r236012.



Comment at: lib/AST/ASTImporter.cpp:3310
   D->getSelectorLocs(SelLocs);
+  for (SourceLocation &Loc : SelLocs)
+Loc = Importer.Import(Loc);

Still actual.



Comment at: lib/AST/ASTImporter.cpp:4613
+  return ToContext.getTrivialTypeSourceInfo(
+  T, Import(FromTSI->getTypeLoc().getLocStart()));
 }

Fixed by r241542.


https://reviews.llvm.org/D6550



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20561: Warn when taking address of packed member

2017-02-01 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.

... and both revisions should be in the 4.0 branch (taken from r291814)

I was looking forward to this warning to help iron out alignment issues at 
compile-time instead of runtime (our ARM CPUs don't like unaligned access). 
@royger, can you expand a little on what you mean by

> For once, it doesn't really check whether the access is actually unaligned or 
> no

? Isn't that exactly what it does? Or do you mean in relation to whether the 
target allows unaligned access or not?


Repository:
  rL LLVM

https://reviews.llvm.org/D20561



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20561: Warn when taking address of packed member

2017-02-01 Thread Roger via Phabricator via cfe-commits
royger added a comment.

In https://reviews.llvm.org/D20561#663006, @kimgr wrote:

> ... and both revisions should be in the 4.0 branch (taken from r291814)
>
> I was looking forward to this warning to help iron out alignment issues at 
> compile-time instead of runtime (our ARM CPUs don't like unaligned access). 
> @royger, can you expand a little on what you mean by
>
> > For once, it doesn't really check whether the access is actually unaligned 
> > or no
>
> ? Isn't that exactly what it does? Or do you mean in relation to whether the 
> target allows unaligned access or not?


Take the following example structure:

  typedef union __attribute__((__packed__)) segment_attributes {
  uint16_t bytes;
  struct
  {
  uint16_t type:4;/* 0;  Bit 40-43 */
  uint16_t s:   1;/* 4;  Bit 44 */
  uint16_t dpl: 2;/* 5;  Bit 45-46 */
  uint16_t p:   1;/* 7;  Bit 47 */
  uint16_t avl: 1;/* 8;  Bit 52 */
  uint16_t l:   1;/* 9;  Bit 53 */
  uint16_t db:  1;/* 10; Bit 54 */
  uint16_t g:   1;/* 11; Bit 55 */
  uint16_t pad: 4;
  } fields;
  } segment_attributes_t;
  
  
  struct __attribute__((__packed__)) segment_register {
  uint16_t   sel;
  segment_attributes_t attr;
  uint32_t   limit;
  uint64_t   base;
  };

clang is complaining about:

  vmx.c:973:38: error: taking address of packed member 'base' of class or 
structure 'segment_register' may result in an unaligned pointer value 
[-Werror,-Waddress-of-packed-member]
  __vmread(GUEST_CS_BASE, ®->base);
   ^

But "base" is indeed aligned (it would be at the same offset without the 
__packed__ attribute), so I'm not sure why it complains.


Repository:
  rL LLVM

https://reviews.llvm.org/D20561



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r293763 - [clang-tidy] Remove debug logging.

2017-02-01 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Feb  1 06:41:34 2017
New Revision: 293763

URL: http://llvm.org/viewvc/llvm-project?rev=293763&view=rev
Log:
[clang-tidy] Remove debug logging.

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseUsingCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseUsingCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseUsingCheck.cpp?rev=293763&r1=293762&r2=293763&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseUsingCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseUsingCheck.cpp Wed Feb  1 
06:41:34 2017
@@ -79,11 +79,6 @@ void UseUsingCheck::check(const MatchFin
   auto &Context = *Result.Context;
   auto &SM = *Result.SourceManager;
 
-  if (auto *D = MatchedDecl->getUnderlyingType()->getAsCXXRecordDecl()) {
-//TypeLoc TL = MatchedDecl->getTypeSourceInfo()->getTypeLoc();
-llvm::errs() << D->getNameAsString() << "\n";
-  }
-
   auto Diag =
   diag(MatchedDecl->getLocStart(), "use 'using' instead of 'typedef'");
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20561: Warn when taking address of packed member

2017-02-01 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

It is not true that all false positives have been fixed, some of the more 
complex cases involving nested data structures are still open.

@royger: Your example is missing explicit alignment. packed has two side 
effects: remove internal padding and set the alignment to 1. That means that 
the offset of base doesn't matter so much because reg itself is not necessarily 
aligned.


Repository:
  rL LLVM

https://reviews.llvm.org/D20561



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20561: Warn when taking address of packed member

2017-02-01 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 added a comment.

In https://reviews.llvm.org/D20561#663069, @joerg wrote:

> It is not true that all false positives have been fixed, some of the more 
> complex cases involving nested data structures are still open.


I could not find any in bugzilla after a quick search. So please feel free to 
point me to them (or CC) if you identify more false positives. I'm interested 
in fixing them.

Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D20561



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20561: Warn when taking address of packed member

2017-02-01 Thread Roger via Phabricator via cfe-commits
royger added a comment.

In https://reviews.llvm.org/D20561#663069, @joerg wrote:

> @royger: Your example is missing explicit alignment. packed has two side 
> effects: remove internal padding and set the alignment to 1. That means that 
> the offset of base doesn't matter so much because reg itself is not 
> necessarily aligned.


Does this means that it's "working as intended" then? I could expect this to 
complain when doing something like:

  struct __attribute__((__packed__)) bar {
  uint64_t x1;
  uint16_t x2;
  uint64_t x3;
  };
  
  &bar->x3;

But not in the previous case.


Repository:
  rL LLVM

https://reviews.llvm.org/D20561



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29393: [clang-tidy] Don't warn about call to unresolved operator*

2017-02-01 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons created this revision.
Herald added a subscriber: JDevlieghere.

The misc-unconventional-assign-operator check had a false positive
warning when the 'operator*' in 'return *this' was unresolved.

Change matcher to allow calls to unresolved operator.

Fixes PR31531.


https://reviews.llvm.org/D29393

Files:
  clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
  test/clang-tidy/misc-unconventional-assign-operator.cpp


Index: test/clang-tidy/misc-unconventional-assign-operator.cpp
===
--- test/clang-tidy/misc-unconventional-assign-operator.cpp
+++ test/clang-tidy/misc-unconventional-assign-operator.cpp
@@ -87,3 +87,21 @@
 return n;
   }
 };
+
+enum E { e };
+E operator*(E, E);
+
+template 
+struct UnresolvedOperator {
+  UnresolvedOperator &operator=(const UnresolvedOperator &) { return *this; }
+};
+
+UnresolvedOperator UnresolvedOperatorInt;
+
+template 
+struct Template {
+  Template &operator=(const Template &) { return this; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: operator=() should always 
return '*this'
+};
+
+Template TemplateInt;
Index: clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
===
--- clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
+++ clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
@@ -58,7 +58,10 @@
   this);
 
   const auto IsBadReturnStatement = 
returnStmt(unless(has(ignoringParenImpCasts(
-  unaryOperator(hasOperatorName("*"), hasUnaryOperand(cxxThisExpr()));
+  anyOf(unaryOperator(hasOperatorName("*"), 
hasUnaryOperand(cxxThisExpr())),
+cxxOperatorCallExpr(argumentCountIs(1),
+callee(unresolvedLookupExpr()),
+hasArgument(0, cxxThisExpr(;
   const auto IsGoodAssign = cxxMethodDecl(IsAssign, HasGoodReturnType);
 
   Finder->addMatcher(returnStmt(IsBadReturnStatement, 
forFunction(IsGoodAssign))


Index: test/clang-tidy/misc-unconventional-assign-operator.cpp
===
--- test/clang-tidy/misc-unconventional-assign-operator.cpp
+++ test/clang-tidy/misc-unconventional-assign-operator.cpp
@@ -87,3 +87,21 @@
 return n;
   }
 };
+
+enum E { e };
+E operator*(E, E);
+
+template 
+struct UnresolvedOperator {
+  UnresolvedOperator &operator=(const UnresolvedOperator &) { return *this; }
+};
+
+UnresolvedOperator UnresolvedOperatorInt;
+
+template 
+struct Template {
+  Template &operator=(const Template &) { return this; }
+  // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: operator=() should always return '*this'
+};
+
+Template TemplateInt;
Index: clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
===
--- clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
+++ clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp
@@ -58,7 +58,10 @@
   this);
 
   const auto IsBadReturnStatement = returnStmt(unless(has(ignoringParenImpCasts(
-  unaryOperator(hasOperatorName("*"), hasUnaryOperand(cxxThisExpr()));
+  anyOf(unaryOperator(hasOperatorName("*"), hasUnaryOperand(cxxThisExpr())),
+cxxOperatorCallExpr(argumentCountIs(1),
+callee(unresolvedLookupExpr()),
+hasArgument(0, cxxThisExpr(;
   const auto IsGoodAssign = cxxMethodDecl(IsAssign, HasGoodReturnType);
 
   Finder->addMatcher(returnStmt(IsBadReturnStatement, forFunction(IsGoodAssign))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


RE: r290539 - [inline-asm]No error for conflict between inputs\outputs and clobber list

2017-02-01 Thread Yatsina, Marina via cfe-commits
It should.
Ziv, there seems to be some bug with the implementation, can you fix it please?

Thanks,
Marina

-Original Message-
From: Dimitry Andric [mailto:dimi...@andric.com] 
Sent: Tuesday, January 31, 2017 22:39
To: Yatsina, Marina 
Cc: cfe-commits ; Izhar, Ziv 
Subject: Re: r290539 - [inline-asm]No error for conflict between inputs\outputs 
and clobber list

On 26 Dec 2016, at 13:23, Marina Yatsina via cfe-commits 
 wrote:
> 
> Author: myatsina
> Date: Mon Dec 26 06:23:42 2016
> New Revision: 290539
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=290539&view=rev
> Log:
> [inline-asm]No error for conflict between inputs\outputs and clobber 
> list
> 
> According to extended asm syntax, a case where the clobber list includes a 
> variable from the inputs or outputs should be an error - conflict.
> for example:
> 
> const long double a = 0.0;
> int main()
> {
> 
> char b;
> double t1 = a;
> __asm__ ("fucompp": "=a" (b) : "u" (t1), "t" (t1) : "cc", "st", 
> "st(1)");
> 
> return 0;
> }
> 
> This should conflict with the output - t1 which is st, and st which is st 
> aswell.

In FreeBSD ports, we are now getting this new error message when compiling 
svgalib (see https://bugs.freebsd.org/216154), when compiling with clang 4.0.0.

While fixing it, we noticed something strange (or interesting, depending on 
your point of view), namely that it does not seem to handle the first input or 
output operand, e.g. "0".  For example, svgalib has this inline function:

/* Always 32-bit align destination, even for a small number of bytes. */ static 
inline void *  __memcpy_aligndest(void *dest, const void *src, int n) {
__asm__ __volatile__("cmpl $3, %%ecx\n\t"
 "ja 1f\n\t"
 "call * __memcpy_jumptable (, %%ecx, 4)\n\t"
 "jmp 2f\n\t"
 "1:call __memcpyasm_regargs\n\t"
 "2:":
 :"S"(dest), "d"(src), "c"(n)
 :"ax", "0", "1", "2");
return dest;
}

The error produced for this is:

svgalib-1.4.3/gl/inlstring.h:281:17: error: asm-specifier for input or output 
variable conflicts with asm clobber list
 :"ax", "0", "1", "2");
 ^

And indeed, removing the "1" and "2" input operands fixes the error.  However, 
by definition, "0" is always an input or output operand, so should it not 
produce an error too?

-Dimitry

-
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29339: [OpenMP] Add support for auxiliary triple specification

2017-02-01 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 86635.
gtbercea added a comment.

Condition changed to only check triple once.


Repository:
  rL LLVM

https://reviews.llvm.org/D29339

Files:
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInstance.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/InitPreprocessor.cpp
  test/Driver/openmp-offload.c

Index: test/Driver/openmp-offload.c
===
--- test/Driver/openmp-offload.c
+++ test/Driver/openmp-offload.c
@@ -248,32 +248,32 @@
 //
 // Compile for the powerpc device.
 //
-// CHK-COMMANDS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-emit-obj" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" "
+// CHK-COMMANDS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-obj" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" "
 // CHK-COMMANDS-SAME: [[T1OBJ:[^\\/]+\.o]]" "-x" "c" "{{.*}}[[INPUT]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]"
 // CHK-COMMANDS: ld{{(\.exe)?}}" {{.*}}"-o" "
 // CHK-COMMANDS-SAME: [[T1BIN:[^\\/]+\.out]]" {{.*}}"{{.*}}[[T1OBJ]]"
-// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-E" {{.*}}"-fopenmp" {{.*}}"-o" "
+// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-E" {{.*}}"-fopenmp" {{.*}}"-o" "
 // CHK-COMMANDS-ST-SAME: [[T1PP:[^\\/]+\.i]]" "-x" "c" "{{.*}}[[INPUT]]"
-// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-emit-llvm-bc" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" "
+// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-llvm-bc" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" "
 // CHK-COMMANDS-ST-SAME: [[T1BC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[T1PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]"
-// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-S" {{.*}}"-fopenmp" {{.*}}"-o" "
+// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-S" {{.*}}"-fopenmp" {{.*}}"-o" "
 // CHK-COMMANDS-ST-SAME: [[T1ASM:[^\\/]+\.s]]" "-x" "ir" "{{.*}}[[T1BC]]"
 // CHK-COMMANDS-ST: clang{{.*}}" "-cc1as" "-triple" "powerpc64le-ibm-linux-gnu" "-filetype" "obj" {{.*}}"-o" "
 // CHK-COMMANDS-ST-SAME: [[T1OBJ:[^\\/]+\.o]]" "{{.*}}[[T1ASM]]"
 // CHK-COMMANDS-ST: ld{{(\.exe)?}}" {{.*}}"-shared" {{.*}}"-o" "
 // CHK-COMMANDS-ST-SAME: [[T1BIN:[^\\/]+\.out-openmp-powerpc64le-ibm-linux-gnu]]" {{.*}}"{{.*}}[[T1OBJ]]"
 //
 // Compile for the x86 device.
 //
-// CHK-COMMANDS: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp"  {{.*}}"-o" "
+// CHK-COMMANDS: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-obj" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp"  {{.*}}"-o" "
 // CHK-COMMANDS-SAME: [[T2OBJ:[^\\/]+\.o]]" "-x" "c" "{{.*}}[[INPUT]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]"
 // CHK-COMMANDS: ld{{(\.exe)?}}" {{.*}}"-o" "
 // CHK-COMMANDS-SAME: [[T2BIN:[^\\/]+\.out]]" {{.*}}"{{.*}}[[T2OBJ]]"
-// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-E" {{.*}}"-fopenmp" {{.*}}"-o" "
+// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-E" {{.*}}"-fopenmp" {{.*}}"-o" "
 // CHK-COMMANDS-ST-SAME: [[T2PP:[^\\/]+\.i]]" "-x" "c" "{{.*}}[[INPUT]]"
-// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-llvm-bc" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" "
+// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-emit-llvm-bc" {{.*}}"-pic-level" "2" {{.*}}"-fopenmp" {{.*}}"-o" "
 // CHK-COMMANDS-ST-SAME: [[T2BC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[T2PP]]" "-fopenmp-is-device" "-fopenmp-host-ir-file-path" "{{.*}}[[HOSTBC]]"
-// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-S" {{.*}}"-fopenmp" {{.*}}"-o" "
+// CHK-COMMANDS-ST: clang{{.*}}" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-aux-triple" "powerpc64le--linux" "-S" {{.*}}"-fopenmp" {{.*}}"-o" "
 // CHK-COMMANDS-ST-SAME: [[T2ASM:[^\\/]+\.s]]" "-x" "ir" "{{.*}}[[T2BC]]"
 // CHK-COMMANDS-ST: clang{{.*}}" "-cc1as" "-triple" "x86_64-pc-linux-gnu" "-filetype" "obj" {{.*}}"-o" "
 // CHK-COMMANDS-ST-SAME: [[T2OBJ:[^\\/]+\.o]]" "{{.*}}[[T2ASM]]"
@@ -396,25 +396,25 @@
 // CHK-BUJOBS-ST-SAME: [[HOSTBC:[^\\/]+\.bc]]" "-x" "cpp-output" "{{.*}}[[HOSTPP]]" "-fopenmp-targets=powerpc64le-ibm-linux-gnu,x86_64-pc-linux-gnu"
 
 // Create target 1 object.
-// CHK-BUJOBS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-emit-obj" {{.*}}"-fopenmp" {{.*}}"-o" "
+// CHK-BUJOBS: clang{{.*}}" "-cc1" "-triple" "powerpc64le-ibm-linux-gnu" "-aux-triple" "powerpc64le--linux" "-e

Re: r293518 - [ASTMatchers] Sprinkle some constexpr on the global matcher constructors.

2017-02-01 Thread Alex L via cfe-commits
I've narrowed the problem down to the difference in the linkage type for
"clang::ast_matchers::recordDecl" between the module and non-module build:

Module:
@_ZN5clang12ast_matchersL10recordDeclE = external global
%"class.clang::ast_matchers::internal::VariadicDynCastAllOfMatcher.847",
align 1

Non-module:
@_ZN5clang12ast_matchersL10recordDeclE = internal constant
%"class.clang::ast_matchers::internal::VariadicDynCastAllOfMatcher.916"
undef, align 1, !dbg !7

On 1 February 2017 at 11:03, Alex L  wrote:

> Hi Benjamin,
>
> This commit has caused a linking in our stage 2 modules buildbot at
> http://lab.llvm.org:8080/green/job/clang-stage2-cmake-modulesRDA/.
> Specifically, after this commit 'clang-reorder-fields' gets the following
> linking error:
>
> FAILED: bin/clang-reorder-fields
> : && /Users/buildslave/jenkins/sharedspace/clang-stage2-cmake-modulesRDA@2
> /host-compiler/bin/clang++   -fPIC -fvisibility-inlines-hidden -Wall -W
> -Wno-unused-parameter -Wwrite-strings -Wcast-qual
> -Wmissing-field-initializers -pedantic -Wno-long-long
> -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor
> -Wstring-conversion -Werror=date-time -std=c++11 -fmodules
> -fmodules-cache-path=/Users/buildslave/jenkins/sharedspace/clang-stage2-
> cmake-modulesRDA@2/clang-build/module.cache -fcxx-modules -gmodules
> -fcolor-diagnostics -fno-common -Woverloaded-virtual -Wno-nested-anon-types
> -O2 -g -DNDEBUG -Wl,-search_paths_first -Wl,-headerpad_max_install_names
> -Wl,-dead_strip tools/clang/tools/extra/clang-reorder-fields/tool/
> CMakeFiles/clang-reorder-fields.dir/ClangReorderFields.cpp.o  -o
> bin/clang-reorder-fields  lib/libLLVMSupport.a lib/libclangBasic.a
> lib/libclangFrontend.a lib/libclangReorderFields.a lib/libclangRewrite.a
> lib/libclangTooling.a lib/libclangToolingCore.a lib/libclangIndex.a
> lib/libclangFrontend.a lib/libclangParse.a lib/libLLVMMCParser.a
> lib/libclangSerialization.a lib/libclangSema.a lib/libclangEdit.a
> lib/libclangAnalysis.a lib/libLLVMBitReader.a lib/libLLVMProfileData.a
> lib/libclangDriver.a lib/libLLVMOption.a lib/libclangASTMatchers.a
> lib/libclangFormat.a lib/libclangToolingCore.a lib/libclangRewrite.a
> lib/libclangAST.a lib/libclangLex.a lib/libclangBasic.a lib/libLLVMCore.a
> lib/libLLVMMC.a lib/libLLVMSupport.a -lcurses -lz -lm lib/libLLVMDemangle.a
> -Wl,-rpath,@loader_path/../lib && :
> Undefined symbols for architecture x86_64:
>   "clang::ast_matchers::recordDecl", referenced from:
>   clang::reorder_fields::(anonymous namespace)::ReorderingConsumer::
> HandleTranslationUnit(clang::ASTContext&) in libclangReorderFields.a(
> ReorderFieldsAction.cpp.o)
> ld: symbol(s) not found for architecture x86_64
>
> This might be a bug/regression in clang and modules since in my opinion
> the link should succeed. I've reverted your commit in r293759 while we are
> investigating.
>
> Thanks,
> Alex
>
>
> On 30 January 2017 at 18:20, Benjamin Kramer via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: d0k
>> Date: Mon Jan 30 12:20:00 2017
>> New Revision: 293518
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=293518&view=rev
>> Log:
>> [ASTMatchers] Sprinkle some constexpr on the global matcher constructors.
>>
>> This dramatically reduces the size of the global constructors we emit
>> for those variables in debug mode.
>>
>> Modified:
>> cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>>
>> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> ASTMatchers/ASTMatchersInternal.h?rev=293518&r1=293517&r2=
>> 293518&view=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
>> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Mon Jan 30
>> 12:20:00 2017
>> @@ -1459,7 +1459,7 @@ class VariadicDynCastAllOfMatcher
>>  : public VariadicFunction,
>> Matcher,
>>makeDynCastAllOfComposite> TargetT>> {
>>  public:
>> -  VariadicDynCastAllOfMatcher() {}
>> +  constexpr VariadicDynCastAllOfMatcher() {}
>>  };
>>
>>  /// \brief A \c VariadicAllOfMatcher object is a variadic functor
>> that takes
>> @@ -1477,7 +1477,7 @@ class VariadicAllOfMatcher
>>  : public VariadicFunction, Matcher,
>>makeAllOfComposite> {
>>  public:
>> -  VariadicAllOfMatcher() {}
>> +  constexpr VariadicAllOfMatcher() {}
>>  };
>>
>>  /// \brief Matches nodes of type \c TLoc for which the inner
>> @@ -1598,7 +1598,7 @@ public:
>>
>>struct Func
>>: public VariadicFunction,
>> &Self::create> {
>> -Func() {}
>> +constexpr Func() {}
>>};
>>
>>  private:
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
___

[clang-tools-extra] r293771 - [clang-tidy] misc-argument-comment: ignore comments after arguments

2017-02-01 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Feb  1 09:28:25 2017
New Revision: 293771

URL: http://llvm.org/viewvc/llvm-project?rev=293771&view=rev
Log:
[clang-tidy] misc-argument-comment: ignore comments after arguments

Modified:
clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp?rev=293771&r1=293770&r2=293771&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp Wed Feb  1 
09:28:25 2017
@@ -67,16 +67,19 @@ getCommentsInRange(ASTContext *Ctx, Char
 Token Tok;
 if (TheLexer.LexFromRawLexer(Tok))
   break;
-if (Tok.getLocation() == Range.getEnd() || Tok.getKind() == tok::eof)
+if (Tok.getLocation() == Range.getEnd() || Tok.is(tok::eof))
   break;
 
-if (Tok.getKind() == tok::comment) {
+if (Tok.is(tok::comment)) {
   std::pair CommentLoc =
   SM.getDecomposedLoc(Tok.getLocation());
   assert(CommentLoc.first == BeginLoc.first);
   Comments.emplace_back(
   Tok.getLocation(),
   StringRef(Buffer.begin() + CommentLoc.second, Tok.getLength()));
+} else {
+  // Clear comments found before the different token, e.g. comma.
+  Comments.clear();
 }
   }
 

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp?rev=293771&r1=293770&r2=293771&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp Wed Feb  
1 09:28:25 2017
@@ -13,6 +13,8 @@ void g() {
   // CHECK-MESSAGES: :[[@LINE-5]]:19: note: 'y' declared here
   f(/*y=*/0, /*z=*/0);
   // CHECK-FIXES: {{^}}  f(/*y=*/0, /*z=*/0);
+
+  (0 /*=*/, /**/ 0); // Unsupported formats.
 }
 
 struct Closure {};


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24969: [Sema] Use the instantiated name of destructors in FindInstantiatedDecl and RebuildMemberExpr

2017-02-01 Thread Hans Wennborg via cfe-commits
On Tue, Jan 31, 2017 at 3:23 PM, Richard Smith  wrote:
> On 31 January 2017 at 14:49, Hans Wennborg  wrote:
>>
>> Richard, what do you think? I don't believe this fixes a 3.9
>> regression, but the fix looks small, so it might be worth it.
>
>
> I think on the whole the benefit of this change outweighs the risk of it
> regressing something.

Merged in r293782.

Thanks,
Hans

>
>>
>> On Tue, Jan 31, 2017 at 12:07 PM, Akira Hatanaka 
>> wrote:
>> > Thanks for the review. r293678.
>> >
>> > Should this be merged to 4.0?
>> >
>> >> On Jan 31, 2017, at 12:04 PM, Akira Hatanaka via Phabricator via
>> >> cfe-commits  wrote:
>> >>
>> >> This revision was automatically updated to reflect the committed
>> >> changes.
>> >> Closed by commit rL293678: [Sema] Transform a templated name before
>> >> looking it up in (authored by ahatanak).
>> >>
>> >> Changed prior to commit:
>> >>  https://reviews.llvm.org/D24969?vs=82134&id=86474#toc
>> >>
>> >> Repository:
>> >>  rL LLVM
>> >>
>> >> https://reviews.llvm.org/D24969
>> >>
>> >> Files:
>> >>  cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>> >>  cfe/trunk/lib/Sema/TreeTransform.h
>> >>  cfe/trunk/test/SemaCXX/destructor.cpp
>> >>
>> >>
>> >> Index: cfe/trunk/test/SemaCXX/destructor.cpp
>> >> ===
>> >> --- cfe/trunk/test/SemaCXX/destructor.cpp
>> >> +++ cfe/trunk/test/SemaCXX/destructor.cpp
>> >> @@ -431,3 +431,23 @@
>> >>
>> >> // The constructor definition should not have errors
>> >> Invalid::~Invalid() {}
>> >> +
>> >> +namespace PR30361 {
>> >> +template 
>> >> +struct C1 {
>> >> +  ~C1() {}
>> >> +  operator C1* () { return nullptr; }
>> >> +  void foo1();
>> >> +};
>> >> +
>> >> +template
>> >> +void C1::foo1() {
>> >> +  C1::operator C1*();
>> >> +  C1::~C1();
>> >> +}
>> >> +
>> >> +void foo1() {
>> >> +  C1 x;
>> >> +  x.foo1();
>> >> +}
>> >> +}
>> >> Index: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>> >> ===
>> >> --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>> >> +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>> >> @@ -4990,8 +4990,12 @@
>> >> NamedDecl *Result = nullptr;
>> >> // FIXME: If the name is a dependent name, this lookup won't
>> >> necessarily
>> >> // find it. Does that ever matter?
>> >> -if (D->getDeclName()) {
>> >> -  DeclContext::lookup_result Found =
>> >> ParentDC->lookup(D->getDeclName());
>> >> +if (auto Name = D->getDeclName()) {
>> >> +  DeclarationNameInfo NameInfo(Name, D->getLocation());
>> >> +  Name = SubstDeclarationNameInfo(NameInfo,
>> >> TemplateArgs).getName();
>> >> +  if (!Name)
>> >> +return nullptr;
>> >> +  DeclContext::lookup_result Found = ParentDC->lookup(Name);
>> >>   Result = findInstantiationOf(Context, D, Found.begin(),
>> >> Found.end());
>> >> } else {
>> >>   // Since we don't have a name for the entity we're looking for,
>> >> Index: cfe/trunk/lib/Sema/TreeTransform.h
>> >> ===
>> >> --- cfe/trunk/lib/Sema/TreeTransform.h
>> >> +++ cfe/trunk/lib/Sema/TreeTransform.h
>> >> @@ -8966,12 +8966,18 @@
>> >>   // base (and therefore couldn't do the check) and a
>> >>   // nested-name-qualifier (and therefore could do the lookup).
>> >>   NamedDecl *FirstQualifierInScope = nullptr;
>> >> +  DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
>> >> +  if (MemberNameInfo.getName()) {
>> >> +MemberNameInfo =
>> >> getDerived().TransformDeclarationNameInfo(MemberNameInfo);
>> >> +if (!MemberNameInfo.getName())
>> >> +  return ExprError();
>> >> +  }
>> >>
>> >>   return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
>> >> E->isArrow(),
>> >> QualifierLoc,
>> >> TemplateKWLoc,
>> >> -E->getMemberNameInfo(),
>> >> +MemberNameInfo,
>> >> Member,
>> >> FoundDecl,
>> >> (E->hasExplicitTemplateArgs()
>> >>
>> >>
>> >> ___
>> >> cfe-commits mailing list
>> >> cfe-commits@lists.llvm.org
>> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>> >
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r291963 - [clang] Emit `diagnose_if` warnings from system headers

2017-02-01 Thread Hans Wennborg via cfe-commits
Merged this (r291963) in r293783.

And the others (r293360 + r293369) in r293784.

Thanks,
Hans

On Tue, Jan 31, 2017 at 7:17 PM, Richard Smith  wrote:
> I'm fine with these patches being merged. Hopefully we still have plenty of
> time to shake out any problems between now and the release.
>
> On 31 January 2017 at 19:09, George Burgess IV 
> wrote:
>>
>> > IIUC the major risk is that diagnose_if itself turns out to be broken,
>> > not that we'd miscompile anything?
>>
>> Correct. These patches should be NFC to code that doesn't use diagnose_if.
>>
>> If something about that patch *had* to break existing
>> non-diagnose_if-aware code, we're now calling Sema::CheckFunctionCall (which
>> checks diagnose_if attributes, checks we're not passing a nullptr into
>> _Nonnull args, ...) for more kinds of C++ function calls than before. We
>> weren't calling it before in these places as an optimization: in theory, it
>> wasn't possible for CheckFunctionCall to find issues in calls to things like
>> conversion functions. Now that we have diagnose_if, it is.
>>
>> On Tue, Jan 31, 2017 at 6:31 PM, Hans Wennborg  wrote:
>>>
>>> I'm Ok with taking the larger patch (r293360 + r293369) too. It's been
>>> in tree for a bit, there is still a number of weeks before the
>>> release, and IIUC the major risk is that diagnose_if itself turns out
>>> to be broken, not that we'd miscompile anything?
>>>
>>> On Tue, Jan 31, 2017 at 11:11 AM, Richard Smith 
>>> wrote:
>>> > Yes, this makes sense. We should also decide what we're going to do
>>> > about
>>> > the larger diagnose_if patch that George has asked to be ported to
>>> > Clang 4.
>>> > Are you comfortable taking a patch of that size? If not, perhaps we
>>> > should
>>> > disable the attribute for the Clang 4 release instead.
>>> >
>>> >
>>> > On 31 January 2017 at 10:36, Hans Wennborg  wrote:
>>> >>
>>> >> Ping?
>>> >>
>>> >> On Thu, Jan 26, 2017 at 10:21 AM, Hans Wennborg 
>>> >> wrote:
>>> >> > Ping?
>>> >> >
>>> >> > On Mon, Jan 23, 2017 at 4:27 PM, Hans Wennborg 
>>> >> > wrote:
>>> >> >> Ping?
>>> >> >>
>>> >> >> On Tue, Jan 17, 2017 at 4:16 PM, Hans Wennborg 
>>> >> >> wrote:
>>> >> >>> Richard, what do you think?
>>> >> >>>
>>> >> >>> On Fri, Jan 13, 2017 at 3:16 PM, Eric Fiselier 
>>> >> >>> wrote:
>>> >>  I would love to see this merged. It would make it easier to write
>>> >>  libc++
>>> >>  tests if the tests didn't have to worry about the old 4.0
>>> >>  behavior.
>>> >> 
>>> >>  CC'ing Richard: Would merging this be OK?
>>> >> 
>>> >>  On Fri, Jan 13, 2017 at 3:46 PM, George Burgess IV
>>> >>   wrote:
>>> >> >
>>> >> > Do we want to consider merging this into the release branch?
>>> >> > Seems
>>> >> > like
>>> >> > more of a bugfix than a feature to me.
>>> >> >
>>> >> > On Fri, Jan 13, 2017 at 2:11 PM, Eric Fiselier via cfe-commits
>>> >> >  wrote:
>>> >> >>
>>> >> >> Author: ericwf
>>> >> >> Date: Fri Jan 13 16:11:40 2017
>>> >> >> New Revision: 291963
>>> >> >>
>>> >> >> URL: http://llvm.org/viewvc/llvm-project?rev=291963&view=rev
>>> >> >> Log:
>>> >> >> [clang] Emit `diagnose_if` warnings from system headers
>>> >> >>
>>> >> >> Summary: In order for libc++ to meaningfully use `diagnose_if`
>>> >> >> warnings
>>> >> >> they need to be emitted from system headers by default. This
>>> >> >> patch
>>> >> >> changes
>>> >> >> the `diagnose_if` warning diagnostic to be shown in system
>>> >> >> headers.
>>> >> >>
>>> >> >> Reviewers: george.burgess.iv, rsmith, aaron.ballman
>>> >> >>
>>> >> >> Subscribers: cfe-commits
>>> >> >>
>>> >> >> Differential Revision: https://reviews.llvm.org/D28703
>>> >> >>
>>> >> >> Added:
>>> >> >> cfe/trunk/test/Sema/Inputs/diagnose-if-warn-system-header.h
>>> >> >> Modified:
>>> >> >> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> >> >> cfe/trunk/test/Sema/diagnose_if.c
>>> >> >>
>>> >> >> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> >> >> URL:
>>> >> >>
>>> >> >>
>>> >> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=291963&r1=291962&r2=291963&view=diff
>>> >> >>
>>> >> >>
>>> >> >>
>>> >> >> ==
>>> >> >> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> >> >> (original)
>>> >> >> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri
>>> >> >> Jan 13
>>> >> >> 16:11:40 2017
>>> >> >> @@ -3380,7 +3380,8 @@ def note_ovl_candidate_has_pass_object_s
>>> >> >>  "candidate address cannot be taken because parameter %0
>>> >> >> has "
>>> >> >>  "pass_object_size attribute">;
>>> >> >>  def err_diagnose_if_succeeded : Error<"%0">;
>>> >> >> -def warn_diagnose_if_succeeded : Warning<"%0">

Re: r293360 - Change how we handle diagnose_if attributes.

2017-02-01 Thread Hans Wennborg via cfe-commits
Merged in r293784, as discussed on the commit thread for r291963.

Thanks,
Hans

On Sun, Jan 29, 2017 at 5:59 PM, George Burgess IV
 wrote:
> Hi!
>
> Now that the buidbots seem content, I think that this (...along with the
> minor fix to the test in r293369) should be committed to the 4.0 branch.
>
> Richard, Hans, are you both OK with this?
>
> On Fri, Jan 27, 2017 at 6:19 PM, George Burgess IV via cfe-commits
>  wrote:
>>
>> Author: gbiv
>> Date: Fri Jan 27 20:19:40 2017
>> New Revision: 293360
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=293360&view=rev
>> Log:
>> Change how we handle diagnose_if attributes.
>>
>> This patch changes how we handle argument-dependent `diagnose_if`
>> attributes. In particular, we now check them in the same place that we
>> check for things like passing NULL to Nonnull args, etc. This is
>> basically better in every way than how we were handling them before. :)
>>
>> This fixes PR31638, PR31639, and PR31640.
>>
>> Differential Revision: https://reviews.llvm.org/D28889
>>
>> Modified:
>> cfe/trunk/include/clang/Sema/Overload.h
>> cfe/trunk/include/clang/Sema/Sema.h
>> cfe/trunk/lib/Sema/SemaChecking.cpp
>> cfe/trunk/lib/Sema/SemaExpr.cpp
>> cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> cfe/trunk/lib/Sema/SemaLookup.cpp
>> cfe/trunk/lib/Sema/SemaOverload.cpp
>> cfe/trunk/test/Sema/diagnose_if.c
>> cfe/trunk/test/SemaCXX/diagnose_if.cpp
>>
>> Modified: cfe/trunk/include/clang/Sema/Overload.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=293360&r1=293359&r2=293360&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/Sema/Overload.h (original)
>> +++ cfe/trunk/include/clang/Sema/Overload.h Fri Jan 27 20:19:40 2017
>> @@ -675,26 +675,6 @@ namespace clang {
>>  /// to be used while performing partial ordering of function
>> templates.
>>  unsigned ExplicitCallArguments;
>>
>> -/// The number of diagnose_if attributes that this overload
>> triggered.
>> -/// If any of the triggered attributes are errors, this won't count
>> -/// diagnose_if warnings.
>> -unsigned NumTriggeredDiagnoseIfs = 0;
>> -
>> -/// Basically a TinyPtrVector that doesn't own the
>> vector:
>> -/// If NumTriggeredDiagnoseIfs is 0 or 1, this is a DiagnoseIfAttr *,
>> -/// otherwise it's a pointer to an array of `NumTriggeredDiagnoseIfs`
>> -/// DiagnoseIfAttr *s.
>> -llvm::PointerUnion
>> DiagnoseIfInfo;
>> -
>> -/// Gets an ArrayRef for the data at DiagnoseIfInfo. Note that this
>> may give
>> -/// you a pointer into DiagnoseIfInfo.
>> -ArrayRef getDiagnoseIfInfo() const {
>> -  auto *Ptr = NumTriggeredDiagnoseIfs <= 1
>> -  ? DiagnoseIfInfo.getAddrOfPtr1()
>> -  : DiagnoseIfInfo.get();
>> -  return {Ptr, NumTriggeredDiagnoseIfs};
>> -}
>> -
>>  union {
>>DeductionFailureInfo DeductionFailure;
>>
>> @@ -759,9 +739,8 @@ namespace clang {
>>  SmallVector Candidates;
>>  llvm::SmallPtrSet Functions;
>>
>> -// Allocator for ConversionSequenceLists and DiagnoseIfAttr* arrays.
>> -// We store the first few of each of these inline to avoid allocation
>> for
>> -// small sets.
>> +// Allocator for ConversionSequenceLists. We store the first few of
>> these
>> +// inline to avoid allocation for small sets.
>>  llvm::BumpPtrAllocator SlabAllocator;
>>
>>  SourceLocation Loc;
>> @@ -776,6 +755,8 @@ namespace clang {
>>  /// from the slab allocator.
>>  /// FIXME: It would probably be nice to have a SmallBumpPtrAllocator
>>  /// instead.
>> +/// FIXME: Now that this only allocates ImplicitConversionSequences,
>> do we
>> +/// want to un-generalize this?
>>  template 
>>  T *slabAllocate(unsigned N) {
>>// It's simpler if this doesn't need to consider alignment.
>> @@ -809,11 +790,6 @@ namespace clang {
>>  SourceLocation getLocation() const { return Loc; }
>>  CandidateSetKind getKind() const { return Kind; }
>>
>> -/// Make a DiagnoseIfAttr* array in a block of memory that will live
>> for
>> -/// as long as this OverloadCandidateSet. Returns a pointer to the
>> start
>> -/// of that array.
>> -DiagnoseIfAttr **addDiagnoseIfComplaints(ArrayRef
>> CA);
>> -
>>  /// \brief Determine when this overload candidate will be new to the
>>  /// overload set.
>>  bool isNewCandidate(Decl *F) {
>>
>> Modified: cfe/trunk/include/clang/Sema/Sema.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=293360&r1=293359&r2=293360&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/Sema/Sema.h (original)
>> +++ cfe/trunk/include/clang/Sema/Sema.h Fri Jan 27 20:19:40 2017
>> @@ -2545,14 +2545,14 @@ public:
>>void AddMethodCandidate(DeclAccessPair FoundDecl,

[PATCH] D27651: [clang-format] Even with AlignConsecutiveDeclarations, PointerAlignment: Right should keep *s and &s to the right

2017-02-01 Thread Ken-Patrick Lehrmann via Phabricator via cfe-commits
KP added a comment.

In https://reviews.llvm.org/D27651#661490, @djasper wrote:

> I have given stuff in WhitespaceManager access to the actual FormatToken in 
> r293616. Hopefully that simplifies this patch.


Thanks! I'll try to rebase and see what can be improved.


https://reviews.llvm.org/D27651



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293787 - [CodeGen][ObjC] Avoid asserting on block pointer types in

2017-02-01 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Wed Feb  1 11:37:28 2017
New Revision: 293787

URL: http://llvm.org/viewvc/llvm-project?rev=293787&view=rev
Log:
[CodeGen][ObjC] Avoid asserting on block pointer types in
isPointerZeroInitializable

rdar://30111891

Added:
cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m
Modified:
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=293787&r1=293786&r2=293787&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Wed Feb  1 11:37:28 2017
@@ -738,7 +738,7 @@ CodeGenTypes::getCGRecordLayout(const Re
 }
 
 bool CodeGenTypes::isPointerZeroInitializable(QualType T) {
-  assert (T->isAnyPointerType() && "Invalid type");
+  assert((T->isAnyPointerType() || T->isBlockPointerType()) && "Invalid type");
   return isZeroInitializable(T);
 }
 

Added: cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m?rev=293787&view=auto
==
--- cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m (added)
+++ cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m Wed Feb  1 11:37:28 2017
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -Wno-objc-root-class -fblocks -o /dev/null -triple x86_64-- 
-emit-llvm %s
+// REQUIRES: asserts
+// Verify there is no assertion.
+
+// rdar://30111891
+
+typedef unsigned long long uint64_t;
+typedef enum AnEnum : uint64_t AnEnum;
+enum AnEnum: uint64_t {
+AnEnumA
+};
+
+typedef void (^BlockType)();
+@interface MyClass
+@end
+@implementation MyClass
+- (void)_doStuff {
+  struct {
+int identifier;
+AnEnum type;
+BlockType handler;
+  } var = {
+"hello",
+AnEnumA,
+((void *)0)
+  };
+}
+@end


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r293787 - [CodeGen][ObjC] Avoid asserting on block pointer types in

2017-02-01 Thread Alex L via cfe-commits
Hi Hans,

Would it be possible to merge this for 4.0?

Cheers,
Alex

On 1 February 2017 at 17:37, Alex Lorenz via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: arphaman
> Date: Wed Feb  1 11:37:28 2017
> New Revision: 293787
>
> URL: http://llvm.org/viewvc/llvm-project?rev=293787&view=rev
> Log:
> [CodeGen][ObjC] Avoid asserting on block pointer types in
> isPointerZeroInitializable
>
> rdar://30111891
>
> Added:
> cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m
> Modified:
> cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/
> CodeGenTypes.cpp?rev=293787&r1=293786&r2=293787&view=diff
> 
> ==
> --- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Wed Feb  1 11:37:28 2017
> @@ -738,7 +738,7 @@ CodeGenTypes::getCGRecordLayout(const Re
>  }
>
>  bool CodeGenTypes::isPointerZeroInitializable(QualType T) {
> -  assert (T->isAnyPointerType() && "Invalid type");
> +  assert((T->isAnyPointerType() || T->isBlockPointerType()) && "Invalid
> type");
>return isZeroInitializable(T);
>  }
>
>
> Added: cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> CodeGenObjC/block-ptr-type-crash.m?rev=293787&view=auto
> 
> ==
> --- cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m (added)
> +++ cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m Wed Feb  1 11:37:28
> 2017
> @@ -0,0 +1,28 @@
> +// RUN: %clang_cc1 -Wno-objc-root-class -fblocks -o /dev/null -triple
> x86_64-- -emit-llvm %s
> +// REQUIRES: asserts
> +// Verify there is no assertion.
> +
> +// rdar://30111891
> +
> +typedef unsigned long long uint64_t;
> +typedef enum AnEnum : uint64_t AnEnum;
> +enum AnEnum: uint64_t {
> +AnEnumA
> +};
> +
> +typedef void (^BlockType)();
> +@interface MyClass
> +@end
> +@implementation MyClass
> +- (void)_doStuff {
> +  struct {
> +int identifier;
> +AnEnum type;
> +BlockType handler;
> +  } var = {
> +"hello",
> +AnEnumA,
> +((void *)0)
> +  };
> +}
> +@end
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29401: Fix MSVC Compatibility around dependent type with missing 'typename'

2017-02-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.

As we know, MSVC is pretty relaxed when it comes to 'typename'.  Clang so far 
does a pretty darn good job of permitting the behavior, however there was 1 
missed case that compiles in MSVC (as of 2015), but not in clang.  I've updated 
the test for similar ones that also/still pass, but were not tested.

  template
  struct S { 
typedef int TD;
  };
  template
  void foo() {
S::TD varname =0;
  }
  
  void foo2(){
foo();
  }

The above was previously an error in clang in -fms-compatibility mode.  This 
patch alters the parser in MSVC mode to correctly assume the 'typename' above 
where necessary.


https://reviews.llvm.org/D29401

Files:
  lib/Parse/ParseStmt.cpp
  test/SemaCXX/MicrosoftCompatibility.cpp


Index: lib/Parse/ParseStmt.cpp
===
--- lib/Parse/ParseStmt.cpp
+++ lib/Parse/ParseStmt.cpp
@@ -183,7 +183,8 @@
 
 // Look up the identifier, and typo-correct it to a keyword if it's not
 // found.
-if (Next.isNot(tok::coloncolon)) {
+if (Next.isNot(tok::coloncolon) && (!getLangOpts().MSVCCompat ||
+Next.isNot(tok::less))) {
   // Try to limit which sets of keywords should be included in typo
   // correction based on what the next token is.
   if (TryAnnotateName(/*IsAddressOfOperand*/ false,
Index: test/SemaCXX/MicrosoftCompatibility.cpp
===
--- test/SemaCXX/MicrosoftCompatibility.cpp
+++ test/SemaCXX/MicrosoftCompatibility.cpp
@@ -218,6 +218,9 @@
 void function_missing_typename(const T::Type param)// expected-warning 
{{missing 'typename' prior to dependent type name}}
 {
 const T::Type var = 2; // expected-warning {{missing 'typename' prior to 
dependent type name}}
+const A::TYPE var2 = 2; // expected-warning {{missing 'typename' prior 
to dependent type name}}
+A::TYPE var3 = 2; // expected-warning {{missing 'typename' prior to 
dependent type name}}
+MissingTypename::A::TYPE var4 = 2; // expected-warning {{missing 
'typename' prior to dependent type name}}
 }
 
 template void function_missing_typename(const D::Type param);


Index: lib/Parse/ParseStmt.cpp
===
--- lib/Parse/ParseStmt.cpp
+++ lib/Parse/ParseStmt.cpp
@@ -183,7 +183,8 @@
 
 // Look up the identifier, and typo-correct it to a keyword if it's not
 // found.
-if (Next.isNot(tok::coloncolon)) {
+if (Next.isNot(tok::coloncolon) && (!getLangOpts().MSVCCompat ||
+Next.isNot(tok::less))) {
   // Try to limit which sets of keywords should be included in typo
   // correction based on what the next token is.
   if (TryAnnotateName(/*IsAddressOfOperand*/ false,
Index: test/SemaCXX/MicrosoftCompatibility.cpp
===
--- test/SemaCXX/MicrosoftCompatibility.cpp
+++ test/SemaCXX/MicrosoftCompatibility.cpp
@@ -218,6 +218,9 @@
 void function_missing_typename(const T::Type param)// expected-warning {{missing 'typename' prior to dependent type name}}
 {
 const T::Type var = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
+const A::TYPE var2 = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
+A::TYPE var3 = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
+MissingTypename::A::TYPE var4 = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
 }
 
 template void function_missing_typename(const D::Type param);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29401: Fix MSVC Compatibility around dependent type with missing 'typename'

2017-02-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Some quick line-comments here.




Comment at: lib/Parse/ParseStmt.cpp:186
 // found.
-if (Next.isNot(tok::coloncolon)) {
+if (Next.isNot(tok::coloncolon) && (!getLangOpts().MSVCCompat ||
+Next.isNot(tok::less))) {

Clang-tidy created this layout here that I'm not thrilled with, if OK, I'd like 
to move the entirety of the 2nd component to the "&&" on its own line.  
Additionally, if anyone has a better way to do this logic, I'm all ears!



Comment at: test/SemaCXX/MicrosoftCompatibility.cpp:222
+const A::TYPE var2 = 2; // expected-warning {{missing 'typename' prior 
to dependent type name}}
+A::TYPE var3 = 2; // expected-warning {{missing 'typename' prior to 
dependent type name}}
+MissingTypename::A::TYPE var4 = 2; // expected-warning {{missing 
'typename' prior to dependent type name}}

This is the line that previously failed.  Curiously, the one above and below 
seemed to succeed without this change.


https://reviews.llvm.org/D29401



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16135: Macro Debug Info support in Clang

2017-02-01 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud marked 7 inline comments as done.
aaboud added a comment.

Thanks Adrian and Richard for the comments, I appreciate that.
I am uploading a new patch that address most of the comments.

Adrian, I answered some of your comments below.

Thanks,
Amjad




Comment at: lib/CodeGen/MacroPPCallbacks.cpp:31
+  MacroInfo::arg_iterator AI = MI.arg_begin(), E = MI.arg_end();
+  for (; AI + 1 != E; ++AI) {
+Name << (*AI)->getName();

aprantl wrote:
> std::next() ?
I am not that satisfied with this function, and I hope we can do it in a better 
way.
This function is based on a code I took from this a static function in file 
"lib\Frontend\PrintPreprocessedOutput.cpp":

```
/// PrintMacroDefinition - Print a macro definition in a form that will be
/// properly accepted back as a definition.
static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI,
 Preprocessor &PP, raw_ostream &OS) {
```



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:44
+if (MI.isGNUVarargs())
+  Name << "..."; // #define foo(x...)
+

aprantl wrote:
> LLVM style prefers comments to be full sentences and above the code.
As I said above, this code is taken from 
"lib\Frontend\PrintPreprocessedOutput.cpp"
Also, I ran clang-format on it, and it did not suggest to change this line.

But, I do not mind fixing this, if it is the preferred comment style.



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:154
+StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+  // Only care about "include" directives.
+  if (!IncludeTok.is(tok::identifier))

aprantl wrote:
> #include as opposed to #import? If so, why?
I am not familiar with "#import" keyword.
1. Is it handled differently by clang that #include?
2. Do we need to generate macro debug info for it?

The reason I have this switch below, is that I am not sure if we call this 
"InclusionDirective" callback for identifiers that are not "#include".

However, I see no harm of updating the LastHashLoc every time we enter this 
function. The value will not be used unless it is set just before calling 
"FileChanged"callback.



Comment at: lib/CodeGen/ModuleBuilder.cpp:68
 SmallVector DeferredInlineMethodDefinitions;
+CGDebugInfo *DebugInfoRef;
 

aprantl wrote:
> What does Ref stand for?
Ref - stands for reference, I think I do not need the "Ref" prefix for this 
member, only for the get function.
But, I will follow Richards suggestion that will eliminate the need for this 
member.


https://reviews.llvm.org/D16135



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16135: Macro Debug Info support in Clang

2017-02-01 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud updated this revision to Diff 86669.
aaboud marked an inline comment as done.
aaboud added a comment.

Address Adrian and Richard comments.

Please, review the new patch and let me know if I need to change anything else.

Thanks,
Amjad


https://reviews.llvm.org/D16135

Files:
  include/clang/CodeGen/ModuleBuilder.h
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenAction.cpp
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/CodeGen/ModuleBuilder.cpp
  test/CodeGen/debug-info-global-constant.c

Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -92,6 +92,10 @@
   return M.get();
 }
 
+CGDebugInfo *getCGDebugInfo() {
+  return Builder->getModuleDebugInfo();
+}
+
 llvm::Module *ReleaseModule() {
   return M.release();
 }
@@ -299,6 +303,10 @@
   return static_cast(this)->ReleaseModule();
 }
 
+CGDebugInfo *CodeGenerator::getCGDebugInfo() {
+  return static_cast(this)->getCGDebugInfo();
+}
+
 const Decl *CodeGenerator::GetDeclForMangledName(llvm::StringRef name) {
   return static_cast(this)->GetDeclForMangledName(name);
 }
Index: lib/CodeGen/MacroPPCallbacks.h
===
--- lib/CodeGen/MacroPPCallbacks.h
+++ lib/CodeGen/MacroPPCallbacks.h
@@ -0,0 +1,107 @@
+//===--- MacroPPCallbacks.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines implementation for the macro preprocessors callbacks.
+//
+//===--===//
+
+#include "clang/Lex/PPCallbacks.h"
+
+namespace llvm {
+class DIMacroFile;
+class DIMacroNode;
+}
+namespace clang {
+class Preprocessor;
+class MacroInfo;
+class CodeGenerator;
+
+class MacroPPCallbacks : public PPCallbacks {
+  /// A pointer to code generator, where debug info generator can be found.
+  CodeGenerator *Gen;
+
+  /// Preprocessor.
+  Preprocessor &PP;
+
+  /// Location of recent included file, used for line number.
+  SourceLocation LastHashLoc;
+
+  /// Location of main file, used for file info.
+  SourceLocation MainFileLoc;
+
+  /// Counts current number of command line included files, which was entered
+  /// and was not exited yet.
+  int CommandIncludeFiles = 0;
+
+  enum FileScopeStatus {
+NoScope,  // Scope is not initialized yet.
+InitializedScope, // Main file scope is initialized but not set yet.
+BuiltinScope, //  file scope.
+CommandLineScope, //  file scope.
+CommandLineScopeIncludes, // Included file, from  file, scope.
+MainFileScope // Main file scope.
+  };
+  FileScopeStatus Status;
+
+  /// Parent contains all entered files that were not exited yet according to
+  /// the inclusion order.
+  llvm::SmallVector Scopes;
+
+  /// Get current DIMacroFile scope.
+  /// \return current DIMacroFile scope or nullptr if there is no such scope.
+  llvm::DIMacroFile *getCurrentScope();
+
+  /// Get current line location or invalid location.
+  /// \param Loc current line location.
+  /// \return current line location \p `Loc`, or invalid location if it's in a
+  /// skipped file scope.
+  SourceLocation getCorrectLocation(SourceLocation Loc);
+
+  /// Use the passed preprocessor to calculate the macro name and value from
+  /// the given macro info and identifier info.
+  ///
+  /// \param II Identifier info, used to get the Macro name.
+  /// \param MI Macro info, used to get the Macro argumets and values.
+  /// \param PP Preprocessor.
+  /// \param [out] Name Place holder for returned macro name and arguments.
+  /// \param [out] Value Place holder for returned macro value.
+  static void calculatMacroDefinition(const IdentifierInfo &II,
+  const MacroInfo &MI, Preprocessor &PP,
+  raw_ostream &Name, raw_ostream &Value);
+
+public:
+  MacroPPCallbacks(CodeGenerator *Gen, Preprocessor &PP);
+
+  /// Callback invoked whenever a source file is entered or exited.
+  ///
+  /// \param Loc Indicates the new location.
+  /// \param PrevFID the file that was exited if \p Reason is ExitFile.
+  void FileChanged(SourceLocation Loc, FileChangeReason Reason,
+   SrcMgr::CharacteristicKind FileType,
+   FileID PrevFID = FileID()) override;
+
+  /// Callback invoked whenever a directive (#xxx) is processed.
+  void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
+  StringRef FileName, bool IsAngled,
+

Re: r291963 - [clang] Emit `diagnose_if` warnings from system headers

2017-02-01 Thread George Burgess IV via cfe-commits
Awesome. Thank you all! :)

On Wed, Feb 1, 2017 at 9:25 AM, Hans Wennborg  wrote:

> Merged this (r291963) in r293783.
>
> And the others (r293360 + r293369) in r293784.
>
> Thanks,
> Hans
>
> On Tue, Jan 31, 2017 at 7:17 PM, Richard Smith 
> wrote:
> > I'm fine with these patches being merged. Hopefully we still have plenty
> of
> > time to shake out any problems between now and the release.
> >
> > On 31 January 2017 at 19:09, George Burgess IV <
> george.burgess...@gmail.com>
> > wrote:
> >>
> >> > IIUC the major risk is that diagnose_if itself turns out to be broken,
> >> > not that we'd miscompile anything?
> >>
> >> Correct. These patches should be NFC to code that doesn't use
> diagnose_if.
> >>
> >> If something about that patch *had* to break existing
> >> non-diagnose_if-aware code, we're now calling Sema::CheckFunctionCall
> (which
> >> checks diagnose_if attributes, checks we're not passing a nullptr into
> >> _Nonnull args, ...) for more kinds of C++ function calls than before. We
> >> weren't calling it before in these places as an optimization: in
> theory, it
> >> wasn't possible for CheckFunctionCall to find issues in calls to things
> like
> >> conversion functions. Now that we have diagnose_if, it is.
> >>
> >> On Tue, Jan 31, 2017 at 6:31 PM, Hans Wennborg 
> wrote:
> >>>
> >>> I'm Ok with taking the larger patch (r293360 + r293369) too. It's been
> >>> in tree for a bit, there is still a number of weeks before the
> >>> release, and IIUC the major risk is that diagnose_if itself turns out
> >>> to be broken, not that we'd miscompile anything?
> >>>
> >>> On Tue, Jan 31, 2017 at 11:11 AM, Richard Smith <
> richardsm...@google.com>
> >>> wrote:
> >>> > Yes, this makes sense. We should also decide what we're going to do
> >>> > about
> >>> > the larger diagnose_if patch that George has asked to be ported to
> >>> > Clang 4.
> >>> > Are you comfortable taking a patch of that size? If not, perhaps we
> >>> > should
> >>> > disable the attribute for the Clang 4 release instead.
> >>> >
> >>> >
> >>> > On 31 January 2017 at 10:36, Hans Wennborg 
> wrote:
> >>> >>
> >>> >> Ping?
> >>> >>
> >>> >> On Thu, Jan 26, 2017 at 10:21 AM, Hans Wennborg 
> >>> >> wrote:
> >>> >> > Ping?
> >>> >> >
> >>> >> > On Mon, Jan 23, 2017 at 4:27 PM, Hans Wennborg  >
> >>> >> > wrote:
> >>> >> >> Ping?
> >>> >> >>
> >>> >> >> On Tue, Jan 17, 2017 at 4:16 PM, Hans Wennborg <
> h...@chromium.org>
> >>> >> >> wrote:
> >>> >> >>> Richard, what do you think?
> >>> >> >>>
> >>> >> >>> On Fri, Jan 13, 2017 at 3:16 PM, Eric Fiselier 
> >>> >> >>> wrote:
> >>> >>  I would love to see this merged. It would make it easier to
> write
> >>> >>  libc++
> >>> >>  tests if the tests didn't have to worry about the old 4.0
> >>> >>  behavior.
> >>> >> 
> >>> >>  CC'ing Richard: Would merging this be OK?
> >>> >> 
> >>> >>  On Fri, Jan 13, 2017 at 3:46 PM, George Burgess IV
> >>> >>   wrote:
> >>> >> >
> >>> >> > Do we want to consider merging this into the release branch?
> >>> >> > Seems
> >>> >> > like
> >>> >> > more of a bugfix than a feature to me.
> >>> >> >
> >>> >> > On Fri, Jan 13, 2017 at 2:11 PM, Eric Fiselier via cfe-commits
> >>> >> >  wrote:
> >>> >> >>
> >>> >> >> Author: ericwf
> >>> >> >> Date: Fri Jan 13 16:11:40 2017
> >>> >> >> New Revision: 291963
> >>> >> >>
> >>> >> >> URL: http://llvm.org/viewvc/llvm-project?rev=291963&view=rev
> >>> >> >> Log:
> >>> >> >> [clang] Emit `diagnose_if` warnings from system headers
> >>> >> >>
> >>> >> >> Summary: In order for libc++ to meaningfully use
> `diagnose_if`
> >>> >> >> warnings
> >>> >> >> they need to be emitted from system headers by default. This
> >>> >> >> patch
> >>> >> >> changes
> >>> >> >> the `diagnose_if` warning diagnostic to be shown in system
> >>> >> >> headers.
> >>> >> >>
> >>> >> >> Reviewers: george.burgess.iv, rsmith, aaron.ballman
> >>> >> >>
> >>> >> >> Subscribers: cfe-commits
> >>> >> >>
> >>> >> >> Differential Revision: https://reviews.llvm.org/D28703
> >>> >> >>
> >>> >> >> Added:
> >>> >> >> cfe/trunk/test/Sema/Inputs/di
> agnose-if-warn-system-header.h
> >>> >> >> Modified:
> >>> >> >> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> >>> >> >> cfe/trunk/test/Sema/diagnose_if.c
> >>> >> >>
> >>> >> >> Modified: cfe/trunk/include/clang/Basic/
> DiagnosticSemaKinds.td
> >>> >> >> URL:
> >>> >> >>
> >>> >> >>
> >>> >> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
> Basic/DiagnosticSemaKinds.td?rev=291963&r1=291962&r2=291963&view=diff
> >>> >> >>
> >>> >> >>
> >>> >> >>
> >>> >> >> 
> ==
> >>> >> >> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> >>> >> >> (original)
> >>> >> >> +++ cfe/trunk/i

Re: r293043 - [analyzer] Fix MacOSXAPIChecker fp with static locals seen from nested blocks.

2017-02-01 Thread Artem Dergachev via cfe-commits

Hans,

This is a fixed and tested version of the previously-merged-and-reverted 
r292800, do we still have time to land this into 4.0?


Thanks,
Artem.

On 1/25/17 1:21 PM, Artem Dergachev via cfe-commits wrote:

Author: dergachev
Date: Wed Jan 25 04:21:45 2017
New Revision: 293043

URL: http://llvm.org/viewvc/llvm-project?rev=293043&view=rev
Log:
[analyzer] Fix MacOSXAPIChecker fp with static locals seen from nested blocks.

This is an attempt to avoid new false positives caused by the reverted r292800,
however the scope of the fix is significantly reduced - some variables are still
in incorrect memory spaces.

Relevant test cases added.

rdar://problem/30105546
rdar://problem/30156693
Differential revision: https://reviews.llvm.org/D28946

Added:
 cfe/trunk/test/Analysis/null-deref-static.m
Modified:
 cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
 cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
 cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
 cfe/trunk/test/Analysis/dispatch-once.m

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp?rev=293043&r1=293042&r2=293043&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp Wed Jan 25 
04:21:45 2017
@@ -94,11 +94,18 @@ void MacOSXAPIChecker::CheckDispatchOnce
bool SuggestStatic = false;
os << "Call to '" << FName << "' uses";
if (const VarRegion *VR = dyn_cast(RB)) {
+const VarDecl *VD = VR->getDecl();
+// FIXME: These should have correct memory space and thus should be 
filtered
+// out earlier. This branch only fires when we're looking from a block,
+// which we analyze as a top-level declaration, onto a static local
+// in a function that contains the block.
+if (VD->isStaticLocal())
+  return;
  // We filtered out globals earlier, so it must be a local variable
  // or a block variable which is under UnknownSpaceRegion.
  if (VR != R)
os << " memory within";
-if (VR->getDecl()->hasAttr())
+if (VD->hasAttr())
os << " the block variable '";
  else
os << " the local variable '";

Modified: cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp?rev=293043&r1=293042&r2=293043&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp Wed Jan 25 04:21:45 2017
@@ -816,9 +816,11 @@ const VarRegion* MemRegionManager::getVa
  
  const StackFrameContext *STC = V.get();
  
-if (!STC)

+if (!STC) {
+  // FIXME: Assign a more sensible memory space to static locals
+  // we see from within blocks that we analyze as top-level declarations.
sReg = getUnknownRegion();
-else {
+} else {
if (D->hasLocalStorage()) {
  sReg = isa(D) || isa(D)
 ? static_cast(getStackArgumentsRegion(STC))

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=293043&r1=293042&r2=293043&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Wed Jan 25 04:21:45 2017
@@ -1849,6 +1849,8 @@ SVal RegionStoreManager::getBindingForVa
  
  // Function-scoped static variables are default-initialized to 0; if they

  // have an initializer, it would have been processed by now.
+// FIXME: This is only true when we're starting analysis from main().
+// We're losing a lot of coverage here.
  if (isa(MS))
return svalBuilder.makeZeroVal(T);
  


Modified: cfe/trunk/test/Analysis/dispatch-once.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dispatch-once.m?rev=293043&r1=293042&r2=293043&view=diff
==
--- cfe/trunk/test/Analysis/dispatch-once.m (original)
+++ cfe/trunk/test/Analysis/dispatch-once.m Wed Jan 25 04:21:45 2017
@@ -107,3 +107,10 @@ void test_block_var_from_outside_block()
};
dispatch_once(&once, ^{}); // expected-warning{{Call to 'dispatch_once' 
uses the block variable 'once' for the predicate value.}}
  }
+
+void test_static_var_from_outside_block() {
+  static dispatch_once_t once;
+  ^{
+dispatch_once(&once, ^{}); // no-warning
+  };
+}

Added: cfe/trunk/test/Analysis/null-deref-static.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/null-deref-static.m?rev=293043&view=auto
===

[PATCH] D29369: [ubsan] Omit superflous overflow checks for promoted arithmetic (PR20193)

2017-02-01 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: lib/CodeGen/CGExprScalar.cpp:72
+  if (const auto *UO = dyn_cast(Op.E))
+return IsPromotedInteger(UO->getSubExpr());
+

Checking isPromotableIntegerType doesn't work the way you want it to; types can 
be "promoted" without actually widening them.  For example, enum types are 
promotable, and in C++ wchar_t is promotable.


https://reviews.llvm.org/D29369



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r293787 - [CodeGen][ObjC] Avoid asserting on block pointer types in

2017-02-01 Thread Hans Wennborg via cfe-commits
OK. Merged in r293797.

Thanks,
Hans

On Wed, Feb 1, 2017 at 9:50 AM, Alex L  wrote:
> Hi Hans,
>
> Would it be possible to merge this for 4.0?
>
> Cheers,
> Alex
>
> On 1 February 2017 at 17:37, Alex Lorenz via cfe-commits
>  wrote:
>>
>> Author: arphaman
>> Date: Wed Feb  1 11:37:28 2017
>> New Revision: 293787
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=293787&view=rev
>> Log:
>> [CodeGen][ObjC] Avoid asserting on block pointer types in
>> isPointerZeroInitializable
>>
>> rdar://30111891
>>
>> Added:
>> cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m
>> Modified:
>> cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
>>
>> Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=293787&r1=293786&r2=293787&view=diff
>>
>> ==
>> --- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Wed Feb  1 11:37:28 2017
>> @@ -738,7 +738,7 @@ CodeGenTypes::getCGRecordLayout(const Re
>>  }
>>
>>  bool CodeGenTypes::isPointerZeroInitializable(QualType T) {
>> -  assert (T->isAnyPointerType() && "Invalid type");
>> +  assert((T->isAnyPointerType() || T->isBlockPointerType()) && "Invalid
>> type");
>>return isZeroInitializable(T);
>>  }
>>
>>
>> Added: cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m?rev=293787&view=auto
>>
>> ==
>> --- cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m (added)
>> +++ cfe/trunk/test/CodeGenObjC/block-ptr-type-crash.m Wed Feb  1 11:37:28
>> 2017
>> @@ -0,0 +1,28 @@
>> +// RUN: %clang_cc1 -Wno-objc-root-class -fblocks -o /dev/null -triple
>> x86_64-- -emit-llvm %s
>> +// REQUIRES: asserts
>> +// Verify there is no assertion.
>> +
>> +// rdar://30111891
>> +
>> +typedef unsigned long long uint64_t;
>> +typedef enum AnEnum : uint64_t AnEnum;
>> +enum AnEnum: uint64_t {
>> +AnEnumA
>> +};
>> +
>> +typedef void (^BlockType)();
>> +@interface MyClass
>> +@end
>> +@implementation MyClass
>> +- (void)_doStuff {
>> +  struct {
>> +int identifier;
>> +AnEnum type;
>> +BlockType handler;
>> +  } var = {
>> +"hello",
>> +AnEnumA,
>> +((void *)0)
>> +  };
>> +}
>> +@end
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29118: [clang-tidy] safety-no-vector-bool

2017-02-01 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe abandoned this revision.
jbcoe added a comment.

Posting a comment re-opened this patch. The approach taken cannot handle 
templates using `std::vector`, a radical rework is needed.

https://reviews.llvm.org/D29267 introduces the safety critical module with a 
much simpler check (no assembler).


https://reviews.llvm.org/D29118



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r293043 - [analyzer] Fix MacOSXAPIChecker fp with static locals seen from nested blocks.

2017-02-01 Thread Hans Wennborg via cfe-commits
If Anna is Ok with it, I'm fine with merging.

Thanks,
Hans

On Wed, Feb 1, 2017 at 10:29 AM, Artem Dergachev  wrote:
> Hans,
>
> This is a fixed and tested version of the previously-merged-and-reverted
> r292800, do we still have time to land this into 4.0?
>
> Thanks,
> Artem.
>
>
> On 1/25/17 1:21 PM, Artem Dergachev via cfe-commits wrote:
>>
>> Author: dergachev
>> Date: Wed Jan 25 04:21:45 2017
>> New Revision: 293043
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=293043&view=rev
>> Log:
>> [analyzer] Fix MacOSXAPIChecker fp with static locals seen from nested
>> blocks.
>>
>> This is an attempt to avoid new false positives caused by the reverted
>> r292800,
>> however the scope of the fix is significantly reduced - some variables are
>> still
>> in incorrect memory spaces.
>>
>> Relevant test cases added.
>>
>> rdar://problem/30105546
>> rdar://problem/30156693
>> Differential revision: https://reviews.llvm.org/D28946
>>
>> Added:
>>  cfe/trunk/test/Analysis/null-deref-static.m
>> Modified:
>>  cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
>>  cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
>>  cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
>>  cfe/trunk/test/Analysis/dispatch-once.m
>>
>> Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp?rev=293043&r1=293042&r2=293043&view=diff
>>
>> ==
>> --- cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp (original)
>> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp Wed Jan 25
>> 04:21:45 2017
>> @@ -94,11 +94,18 @@ void MacOSXAPIChecker::CheckDispatchOnce
>> bool SuggestStatic = false;
>> os << "Call to '" << FName << "' uses";
>> if (const VarRegion *VR = dyn_cast(RB)) {
>> +const VarDecl *VD = VR->getDecl();
>> +// FIXME: These should have correct memory space and thus should be
>> filtered
>> +// out earlier. This branch only fires when we're looking from a
>> block,
>> +// which we analyze as a top-level declaration, onto a static local
>> +// in a function that contains the block.
>> +if (VD->isStaticLocal())
>> +  return;
>>   // We filtered out globals earlier, so it must be a local variable
>>   // or a block variable which is under UnknownSpaceRegion.
>>   if (VR != R)
>> os << " memory within";
>> -if (VR->getDecl()->hasAttr())
>> +if (VD->hasAttr())
>> os << " the block variable '";
>>   else
>> os << " the local variable '";
>>
>> Modified: cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp?rev=293043&r1=293042&r2=293043&view=diff
>>
>> ==
>> --- cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp (original)
>> +++ cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp Wed Jan 25 04:21:45
>> 2017
>> @@ -816,9 +816,11 @@ const VarRegion* MemRegionManager::getVa
>> const StackFrameContext *STC = V.get();
>>   -if (!STC)
>> +if (!STC) {
>> +  // FIXME: Assign a more sensible memory space to static locals
>> +  // we see from within blocks that we analyze as top-level
>> declarations.
>> sReg = getUnknownRegion();
>> -else {
>> +} else {
>> if (D->hasLocalStorage()) {
>>   sReg = isa(D) || isa(D)
>>  ? static_cast> MemRegion*>(getStackArgumentsRegion(STC))
>>
>> Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=293043&r1=293042&r2=293043&view=diff
>>
>> ==
>> --- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
>> +++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Wed Jan 25 04:21:45
>> 2017
>> @@ -1849,6 +1849,8 @@ SVal RegionStoreManager::getBindingForVa
>> // Function-scoped static variables are default-initialized to 0;
>> if they
>>   // have an initializer, it would have been processed by now.
>> +// FIXME: This is only true when we're starting analysis from main().
>> +// We're losing a lot of coverage here.
>>   if (isa(MS))
>> return svalBuilder.makeZeroVal(T);
>>
>> Modified: cfe/trunk/test/Analysis/dispatch-once.m
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dispatch-once.m?rev=293043&r1=293042&r2=293043&view=diff
>>
>> ==
>> --- cfe/trunk/test/Analysis/dispatch-once.m (original)
>> +++ cfe/trunk/test/Analysis/dispatch-once.m Wed Jan 25 04:21:45 2017
>> @@ -107,3 +107,10 @@ void test_block_var_from_outside_block()
>> };
>> dispatch_on

r293800 - Drop 'dllimport' when redeclaring inline function template without the attribute (PR31695)

2017-02-01 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Wed Feb  1 12:52:53 2017
New Revision: 293800

URL: http://llvm.org/viewvc/llvm-project?rev=293800&view=rev
Log:
Drop 'dllimport' when redeclaring inline function template without the 
attribute (PR31695)

For non-template dllimport functions, MSVC allows providing an inline
definition without spelling out the attribute again. In the example below, f
remains a dllimport function.

  __declspec(dllimport) int f();
  inline int f() { return 42; }

  int useit() {
return f();
  }

However, for a function template, not putting dllimport on the redeclaration
causes it to be dropped. In the example below, f is not dllimport.

  template  __declspec(dllimport) int f();
  template  inline int f() { return 42; }

  int useit() {
return f();
  }

This patch makes Clang match MSVC for the second example.

MSVC does not warn about the attribute being dropped in the example above, but
I think we should. (MSVC does warn if the inline keyword isn't used.)

Differential Revision: https://reviews.llvm.org/D29152

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGenCXX/dllimport.cpp
cfe/trunk/test/SemaCXX/dllimport.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=293800&r1=293799&r2=293800&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Feb  1 12:52:53 2017
@@ -5702,13 +5702,17 @@ static void checkDLLAttributeRedeclarati
   if (OldDecl->isInvalidDecl())
 return;
 
+  bool IsTemplate = false;
   if (TemplateDecl *OldTD = dyn_cast(OldDecl)) {
 OldDecl = OldTD->getTemplatedDecl();
+IsTemplate = true;
 if (!IsSpecialization)
   IsDefinition = false;
   }
-  if (TemplateDecl *NewTD = dyn_cast(NewDecl))
+  if (TemplateDecl *NewTD = dyn_cast(NewDecl)) {
 NewDecl = NewTD->getTemplatedDecl();
+IsTemplate = true;
+  }
 
   if (!OldDecl || !NewDecl)
 return;
@@ -5761,9 +5765,10 @@ static void checkDLLAttributeRedeclarati
   }
 
   // A redeclaration is not allowed to drop a dllimport attribute, the only
-  // exceptions being inline function definitions, local extern declarations,
-  // qualified friend declarations or special MSVC extension: in the last case,
-  // the declaration is treated as if it were marked dllexport.
+  // exceptions being inline function definitions (except for function
+  // templates), local extern declarations, qualified friend declarations or
+  // special MSVC extension: in the last case, the declaration is treated as if
+  // it were marked dllexport.
   bool IsInline = false, IsStaticDataMember = false, IsQualifiedFriend = false;
   bool IsMicrosoft = S.Context.getTargetInfo().getCXXABI().isMicrosoft();
   if (const auto *VD = dyn_cast(NewDecl)) {
@@ -5778,7 +5783,8 @@ static void checkDLLAttributeRedeclarati
 FD->getFriendObjectKind() == Decl::FOK_Declared;
   }
 
-  if (OldImportAttr && !HasNewAttr && !IsInline && !IsStaticDataMember &&
+  if (OldImportAttr && !HasNewAttr &&
+  (!IsInline || (IsMicrosoft && IsTemplate)) && !IsStaticDataMember &&
   !NewDecl->isLocalExternDecl() && !IsQualifiedFriend) {
 if (IsMicrosoft && IsDefinition) {
   S.Diag(NewDecl->getLocation(),

Modified: cfe/trunk/test/CodeGenCXX/dllimport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport.cpp?rev=293800&r1=293799&r2=293800&view=diff
==
--- cfe/trunk/test/CodeGenCXX/dllimport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllimport.cpp Wed Feb  1 12:52:53 2017
@@ -405,17 +405,17 @@ USE(inlineFuncTmpl1 inline void __attribute__((dllimport)) inlineFuncTmpl2() 
{}
 USE(inlineFuncTmpl2)
 
-// MSC-DAG: declare dllimport void 
@"\01??$inlineFuncTmplDecl@UImplicitInst_ImportedYAXXZ"()
+// MSC-DAG: define linkonce_odr void 
@"\01??$inlineFuncTmplDecl@UImplicitInst_ImportedYAXXZ"()
 // GNU-DAG: define linkonce_odr void 
@_Z18inlineFuncTmplDeclI21ImplicitInst_ImportedEvv()
-// MO1-DAG: define available_externally dllimport void 
@"\01??$inlineFuncTmplDecl@UImplicitInst_ImportedYAXXZ"()
+// MO1-DAG: define linkonce_odr void 
@"\01??$inlineFuncTmplDecl@UImplicitInst_ImportedYAXXZ"()
 // GO1-DAG: define linkonce_odr void 
@_Z18inlineFuncTmplDeclI21ImplicitInst_ImportedEvv()
 template __declspec(dllimport) inline void inlineFuncTmplDecl();
 template  void inlineFuncTmplDecl() {}
 USE(inlineFuncTmplDecl)
 
-// MSC-DAG: declare dllimport void 
@"\01??$inlineFuncTmplDef@UImplicitInst_ImportedYAXXZ"()
+// MSC-DAG: define linkonce_odr void 
@"\01??$inlineFuncTmplDef@UImplicitInst_ImportedYAXXZ"()
 // GNU-DAG: define linkonce_odr void 
@_Z17inlineFuncTmplDefI21ImplicitInst_ImportedEvv()
-// MO1-DAG: define available_externally dllimport void 
@"\01??$inlineFuncTmplDef@

[PATCH] D29152: Drop 'dllimport' when redeclaring inline function template without the attribute (PR31695)

2017-02-01 Thread Hans Wennborg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293800: Drop 'dllimport' when redeclaring inline function 
template without the… (authored by hans).

Changed prior to commit:
  https://reviews.llvm.org/D29152?vs=85818&id=86676#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29152

Files:
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/CodeGenCXX/dllimport.cpp
  cfe/trunk/test/SemaCXX/dllimport.cpp

Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -5702,13 +5702,17 @@
   if (OldDecl->isInvalidDecl())
 return;
 
+  bool IsTemplate = false;
   if (TemplateDecl *OldTD = dyn_cast(OldDecl)) {
 OldDecl = OldTD->getTemplatedDecl();
+IsTemplate = true;
 if (!IsSpecialization)
   IsDefinition = false;
   }
-  if (TemplateDecl *NewTD = dyn_cast(NewDecl))
+  if (TemplateDecl *NewTD = dyn_cast(NewDecl)) {
 NewDecl = NewTD->getTemplatedDecl();
+IsTemplate = true;
+  }
 
   if (!OldDecl || !NewDecl)
 return;
@@ -5761,9 +5765,10 @@
   }
 
   // A redeclaration is not allowed to drop a dllimport attribute, the only
-  // exceptions being inline function definitions, local extern declarations,
-  // qualified friend declarations or special MSVC extension: in the last case,
-  // the declaration is treated as if it were marked dllexport.
+  // exceptions being inline function definitions (except for function
+  // templates), local extern declarations, qualified friend declarations or
+  // special MSVC extension: in the last case, the declaration is treated as if
+  // it were marked dllexport.
   bool IsInline = false, IsStaticDataMember = false, IsQualifiedFriend = false;
   bool IsMicrosoft = S.Context.getTargetInfo().getCXXABI().isMicrosoft();
   if (const auto *VD = dyn_cast(NewDecl)) {
@@ -5778,7 +5783,8 @@
 FD->getFriendObjectKind() == Decl::FOK_Declared;
   }
 
-  if (OldImportAttr && !HasNewAttr && !IsInline && !IsStaticDataMember &&
+  if (OldImportAttr && !HasNewAttr &&
+  (!IsInline || (IsMicrosoft && IsTemplate)) && !IsStaticDataMember &&
   !NewDecl->isLocalExternDecl() && !IsQualifiedFriend) {
 if (IsMicrosoft && IsDefinition) {
   S.Diag(NewDecl->getLocation(),
Index: cfe/trunk/test/SemaCXX/dllimport.cpp
===
--- cfe/trunk/test/SemaCXX/dllimport.cpp
+++ cfe/trunk/test/SemaCXX/dllimport.cpp
@@ -396,20 +396,28 @@
 template __declspec(dllimport) void funcTmplDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
 
 // Import inline function template.
-#ifdef GNU
-// expected-warning@+5{{'dllimport' attribute ignored on inline function}}
-// expected-warning@+5{{'dllimport' attribute ignored on inline function}}
-// expected-warning@+6{{'dllimport' attribute ignored on inline function}}
-// expected-warning@+9{{'inlineFuncTmplDef' redeclared inline; 'dllimport' attribute ignored}}
-#endif
-template __declspec(dllimport) inline void inlineFuncTmpl1() {}
-template inline void __attribute__((dllimport)) inlineFuncTmpl2() {}
+#ifdef GNU // MinGW always ignores dllimport on inline functions.
 
-template __declspec(dllimport) inline void inlineFuncTmplDecl();
+template __declspec(dllimport) inline void inlineFuncTmpl1() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
+template inline void __attribute__((dllimport)) inlineFuncTmpl2() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
+
+template __declspec(dllimport) inline void inlineFuncTmplDecl(); // expected-warning{{'dllimport' attribute ignored on inline function}}
 template  void inlineFuncTmplDecl() {}
 
 template __declspec(dllimport) void inlineFuncTmplDef();
-templateinline void inlineFuncTmplDef() {}
+templateinline void inlineFuncTmplDef() {} // expected-warning{{'inlineFuncTmplDef' redeclared inline; 'dllimport' attribute ignored}}
+
+#else // MSVC drops dllimport when the function template is redeclared without it. (It doesn't warn, but we do.)
+
+template __declspec(dllimport) inline void inlineFuncTmpl1() {}
+template inline void __attribute__((dllimport)) inlineFuncTmpl2() {}
+
+template __declspec(dllimport) inline void inlineFuncTmplDecl(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
+template  void inlineFuncTmplDecl() {} // expected-warning{{'inlineFuncTmplDecl' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
+
+template __declspec(dllimport) void inlineFuncTmplDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
+templateinline void inlineFuncTmplDef() {} // expected-warning{{'inlineFuncTmplDef' redeclared without 'dllimpor

[PATCH] D28989: [X86][MS]Adjacent comments within multi-line inline assembly statement

2017-02-01 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

Sorry, missed this, looks good.


Repository:
  rL LLVM

https://reviews.llvm.org/D28989



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16135: Macro Debug Info support in Clang

2017-02-01 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

Thanks! Couple more inline comments.




Comment at: lib/CodeGen/CGDebugInfo.h:415
 
+  /// Get macro debug info.
+  llvm::DIMacro *CreateMacro(llvm::DIMacroFile *Parent, unsigned MType,

It would be good to be a bit more descriptive here. If the comment just repeats 
the name of the function it is not worth keeping,
/// Create debug info for a macro (definition/use/?).



Comment at: lib/CodeGen/CGDebugInfo.h:420
+
+  /// Get temporary macro file debug info.
+  llvm::DIMacroFile *CreateTempMacroFile(llvm::DIMacroFile *Parent,

E.g.,
/// Create debug info for a file referenced by an #include directive.



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:44
+if (MI.isGNUVarargs())
+  Name << "..."; // #define foo(x...)
+

aaboud wrote:
> aprantl wrote:
> > LLVM style prefers comments to be full sentences and above the code.
> As I said above, this code is taken from 
> "lib\Frontend\PrintPreprocessedOutput.cpp"
> Also, I ran clang-format on it, and it did not suggest to change this line.
> 
> But, I do not mind fixing this, if it is the preferred comment style.
I think it would be a good idea to clean this up. Feel free to either do this 
now or in a separate commit.



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:154
+StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+  // Only care about "include" directives.
+  if (!IncludeTok.is(tok::identifier))

aaboud wrote:
> aprantl wrote:
> > #include as opposed to #import? If so, why?
> I am not familiar with "#import" keyword.
> 1. Is it handled differently by clang that #include?
> 2. Do we need to generate macro debug info for it?
> 
> The reason I have this switch below, is that I am not sure if we call this 
> "InclusionDirective" callback for identifiers that are not "#include".
> 
> However, I see no harm of updating the LastHashLoc every time we enter this 
> function. The value will not be used unless it is set just before calling 
> "FileChanged"callback.
#import comes from Objective-C. It is equivalent to #include + #pragma once.
I'm curious whether this comment means that it isn't handled?



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:88
+  // Invalid location represents line zero.
+  return SourceLocation();
+}

I think the entire function can be replaced with
```
if ((Status == MainFileScope) ||
(Status == CommandLineScopeIncludes && CommandIncludeFiles))
  return Loc;
return SourceLocation();
```



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:100
+  bool CreateMacroFile = false;
+  bool PopScope = false;
+  SourceLocation LineLoc = getCorrectLocation(LastHashLoc);

Could you try splitting this function up into two functions?

MacroPPCallbacks::FileEntered()
MacroPPCallbacks::FileExited()

and the common code factored out into a helper? The control flow here seems 
unnecessarily complex with all the flags.



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:177
+  llvm::raw_string_ostream Value(ValueBuffer);
+  calculatMacroDefinition(*Id, *MD->getMacroInfo(), PP, Name, Value);
+  Gen->getCGDebugInfo()->CreateMacro(getCurrentScope(),

calculat*e*MacroDefinition
(is there a better word than calculate?)


https://reviews.llvm.org/D16135



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29208: Prevent ICE in dllexport class with _Atomic() data member

2017-02-01 Thread John McCall via Phabricator via cfe-commits
rjmccall requested changes to this revision.
rjmccall added inline comments.
This revision now requires changes to proceed.



Comment at: lib/CodeGen/CGClass.cpp:1135
 MemberExpr *ME2 = dyn_cast(RHS);
-if (dyn_cast(ME2->getMemberDecl()) != Field)
+if (!ME2 || dyn_cast(ME2->getMemberDecl()) != Field)
   return nullptr;

I would prefer:

  if (MemberExpr *ME2 = dyn_cast(RHS)) {
if (ME2->getMemberDecl() == Field)
  return Field;
  }
  return nullptr;


https://reviews.llvm.org/D29208



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27651: [clang-format] Even with AlignConsecutiveDeclarations, PointerAlignment: Right should keep *s and &s to the right

2017-02-01 Thread Ken-Patrick Lehrmann via Phabricator via cfe-commits
KP updated this revision to Diff 86681.
KP added a comment.

Rebase after r293616.

Replace isPointerOrReference with a direct check on the token type.


https://reviews.llvm.org/D27651

Files:
  lib/Format/WhitespaceManager.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -9409,9 +9409,11 @@
   verifyFormat("int  oneTwoThree = {0}; // comment\n"
"unsigned oneTwo  = 0;   // comment",
Alignment);
+
+  // PAS_RIGHT
   EXPECT_EQ("void SomeFunction(int parameter = 0) {\n"
 "  int const i   = 1;\n"
-"  int * j   = 2;\n"
+"  int  *j   = 2;\n"
 "  int   big = 1;\n"
 "\n"
 "  unsigned oneTwoThree = 123;\n"
@@ -9432,6 +9434,141 @@
"int ll=1;\n"
"}",
Alignment));
+  EXPECT_EQ("void SomeFunction(int parameter = 0) {\n"
+"  int const i   = 1;\n"
+"  int **j   = 2, ***k;\n"
+"  int  &k   = i;\n"
+"  int &&l   = i + j;\n"
+"  int   big = 1;\n"
+"\n"
+"  unsigned oneTwoThree = 123;\n"
+"  int  oneTwo  = 12;\n"
+"  method();\n"
+"  float k  = 2;\n"
+"  int   ll = 1;\n"
+"}",
+format("void SomeFunction(int parameter= 0) {\n"
+   " int const  i= 1;\n"
+   "  int **j=2,***k;\n"
+   "int &k=i;\n"
+   "int &&l=i+j;\n"
+   " int big  =  1;\n"
+   "\n"
+   "unsigned oneTwoThree  =123;\n"
+   "int oneTwo = 12;\n"
+   "  method();\n"
+   "float k= 2;\n"
+   "int ll=1;\n"
+   "}",
+   Alignment));
+
+  // PAS_LEFT
+  FormatStyle AlignmentLeft = Alignment;
+  AlignmentLeft.PointerAlignment = FormatStyle::PAS_Left;
+  EXPECT_EQ("void SomeFunction(int parameter = 0) {\n"
+"  int const i   = 1;\n"
+"  int*  j   = 2;\n"
+"  int   big = 1;\n"
+"\n"
+"  unsigned oneTwoThree = 123;\n"
+"  int  oneTwo  = 12;\n"
+"  method();\n"
+"  float k  = 2;\n"
+"  int   ll = 1;\n"
+"}",
+format("void SomeFunction(int parameter= 0) {\n"
+   " int const  i= 1;\n"
+   "  int *j=2;\n"
+   " int big  =  1;\n"
+   "\n"
+   "unsigned oneTwoThree  =123;\n"
+   "int oneTwo = 12;\n"
+   "  method();\n"
+   "float k= 2;\n"
+   "int ll=1;\n"
+   "}",
+   AlignmentLeft));
+  EXPECT_EQ("void SomeFunction(int parameter = 0) {\n"
+"  int const i   = 1;\n"
+"  int** j   = 2;\n"
+"  int&  k   = i;\n"
+"  int&& l   = i + j;\n"
+"  int   big = 1;\n"
+"\n"
+"  unsigned oneTwoThree = 123;\n"
+"  int  oneTwo  = 12;\n"
+"  method();\n"
+"  float k  = 2;\n"
+"  int   ll = 1;\n"
+"}",
+format("void SomeFunction(int parameter= 0) {\n"
+   " int const  i= 1;\n"
+   "  int **j=2;\n"
+   "int &k=i;\n"
+   "int &&l=i+j;\n"
+   " int big  =  1;\n"
+   "\n"
+   "unsigned oneTwoThree  =123;\n"
+   "int oneTwo = 12;\n"
+   "  method();\n"
+   "float k= 2;\n"
+   "int ll=1;\n"
+   "}",
+   AlignmentLeft));
+  // PAS_MIDDLE
+  FormatStyle AlignmentMiddle = Alignment;
+  AlignmentMiddle.PointerAlignment = FormatStyle::PAS_Middle;
+  EXPECT_EQ("void SomeFunction(int parameter = 0) {\n"
+"  int const i   = 1;\n"
+"  int * j   = 2;\n"
+"  int   big = 1;\n"
+"\n"
+"  unsigned oneTwoThree = 123;\n"
+"  int  oneTwo  = 12;\n"
+"  method();\n"
+"  float k  = 2;\n"
+"  int   ll = 1;\n"
+"}",
+format("void SomeFunction(int parameter= 0) {\n"
+   " int const  i= 1;\n"
+   "  int *j=2;\n"
+   " int big  =  1;\n"
+   "\n"
+   "unsigned oneTwoThree  =123;\n"
+   "int oneTwo = 12;\n"
+   "  method();\n"
+   "float k= 2;\n"
+   

[PATCH] D25674: [Concepts] Class template associated constraints

2017-02-01 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

Ping!


https://reviews.llvm.org/D25674



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxxabi] r292638 - Fix catch_reference_nullptr.pass.cpp test for GCC.

2017-02-01 Thread Hans Wennborg via cfe-commits
On Tue, Jan 31, 2017 at 11:40 AM, Renato Golin  wrote:
> On 31 January 2017 at 18:36, Hans Wennborg  wrote:
 Can you attach all commits that need to be backported into a bug
 against PR31622?

 We should probably squash them all before merge.
>>>
>>> What's the status here?
>>
>> Ping?
>
> Hum, I think Eric did create the bug, but now I can't remember which.

I can't find it.

Also I'm confused, since I haven't seen anything besides r292638
mentioned. Are there other changes besides that up for merging?

Thanks,
Hans
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21279: Fix some issues in clang-format's AlignConsecutive modes

2017-02-01 Thread Ben Harper via Phabricator via cfe-commits
bmharper added a comment.

Thanks - the merge conflicts don't look too bad. I should have it cleaned up by 
tomorrow.


https://reviews.llvm.org/D21279



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28462: clang-format: Add new style option AlignConsecutiveMacros

2017-02-01 Thread Erik Nyquist via Phabricator via cfe-commits
enyquist added a comment.

Thanks :) I should get a chance to return to this next week.


Repository:
  rL LLVM

https://reviews.llvm.org/D28462



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29415: [Assembler] Inline assembly diagnostics test.

2017-02-01 Thread Sanne Wouda via Phabricator via cfe-commits
sanwou01 created this revision.
Herald added a subscriber: mehdi_amini.

Add a test for improved inline assembly diagnostics in llvm.


https://reviews.llvm.org/D29415

Files:
  test/Misc/inline-asm-diags.c


Index: test/Misc/inline-asm-diags.c
===
--- /dev/null
+++ test/Misc/inline-asm-diags.c
@@ -0,0 +1,23 @@
+// RUN: not %clang -c --target=armv7a-arm-none-eabi %s -o /dev/null 2>&1 | 
FileCheck %s
+
+void foo2() {
+   asm(" wibble");
+}
+
+// CHECK: 4:6: error: invalid instruction
+// CHECK:   asm(" wibble");
+// CHECK:   ^
+// CHECK: :1:3: note: instantiated into assembly here
+// CHECK:  wibble
+// CHECK:  ^~
+
+void foo() {
+   asm(" .word -bar");
+}
+
+// CHECK: 15:6: error: expected relocatable expression
+// CHECK:   asm(" .word -bar");
+// CHECK:   ^
+// CHECK: :1:3: note: instantiated into assembly here
+// CHECK:  .word -bar
+// CHECK:  ^


Index: test/Misc/inline-asm-diags.c
===
--- /dev/null
+++ test/Misc/inline-asm-diags.c
@@ -0,0 +1,23 @@
+// RUN: not %clang -c --target=armv7a-arm-none-eabi %s -o /dev/null 2>&1 | FileCheck %s
+
+void foo2() {
+	asm(" wibble");
+}
+
+// CHECK: 4:6: error: invalid instruction
+// CHECK:   asm(" wibble");
+// CHECK:   ^
+// CHECK: :1:3: note: instantiated into assembly here
+// CHECK:  wibble
+// CHECK:  ^~
+
+void foo() {
+	asm(" .word -bar");
+}
+
+// CHECK: 15:6: error: expected relocatable expression
+// CHECK:   asm(" .word -bar");
+// CHECK:   ^
+// CHECK: :1:3: note: instantiated into assembly here
+// CHECK:  .word -bar
+// CHECK:  ^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293808 - [Sema][ObjC] Don't pass a DeclRefExpr that doesn't reference a VarDecl

2017-02-01 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Feb  1 14:22:26 2017
New Revision: 293808

URL: http://llvm.org/viewvc/llvm-project?rev=293808&view=rev
Log:
[Sema][ObjC] Don't pass a DeclRefExpr that doesn't reference a VarDecl
to WeakObjectProfileTy's constructor.

This fixes an assertion failure in WeakObjectProfileTy's constructor.

rdar://problem/30112633

Modified:
cfe/trunk/lib/Sema/ScopeInfo.cpp
cfe/trunk/test/SemaObjC/arc-repeated-weak.mm

Modified: cfe/trunk/lib/Sema/ScopeInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ScopeInfo.cpp?rev=293808&r1=293807&r2=293808&view=diff
==
--- cfe/trunk/lib/Sema/ScopeInfo.cpp (original)
+++ cfe/trunk/lib/Sema/ScopeInfo.cpp Wed Feb  1 14:22:26 2017
@@ -184,7 +184,7 @@ void FunctionScopeInfo::markSafeWeakUse(
   }
 
   // Has this weak object been seen before?
-  FunctionScopeInfo::WeakObjectUseMap::iterator Uses;
+  FunctionScopeInfo::WeakObjectUseMap::iterator Uses = WeakObjectUses.end();
   if (const ObjCPropertyRefExpr *RefExpr = dyn_cast(E)) {
 if (!RefExpr->isObjectReceiver())
   return;
@@ -197,10 +197,10 @@ void FunctionScopeInfo::markSafeWeakUse(
   }
   else if (const ObjCIvarRefExpr *IvarE = dyn_cast(E))
 Uses = WeakObjectUses.find(WeakObjectProfileTy(IvarE));
-  else if (const DeclRefExpr *DRE = dyn_cast(E))
-Uses = WeakObjectUses.find(WeakObjectProfileTy(DRE));
-  else if (const ObjCMessageExpr *MsgE = dyn_cast(E)) {
-Uses = WeakObjectUses.end();
+  else if (const DeclRefExpr *DRE = dyn_cast(E)) {
+if (isa(DRE->getDecl()))
+  Uses = WeakObjectUses.find(WeakObjectProfileTy(DRE));
+  } else if (const ObjCMessageExpr *MsgE = dyn_cast(E)) {
 if (const ObjCMethodDecl *MD = MsgE->getMethodDecl()) {
   if (const ObjCPropertyDecl *Prop = MD->findPropertyDecl()) {
 Uses =

Modified: cfe/trunk/test/SemaObjC/arc-repeated-weak.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-repeated-weak.mm?rev=293808&r1=293807&r2=293808&view=diff
==
--- cfe/trunk/test/SemaObjC/arc-repeated-weak.mm (original)
+++ cfe/trunk/test/SemaObjC/arc-repeated-weak.mm Wed Feb  1 14:22:26 2017
@@ -462,3 +462,16 @@ void foo() {
   use(NSBundle.foo2.weakProp); // expected-warning{{weak property 'weakProp' 
may be accessed multiple times}}
   use(NSBundle2.foo2.weakProp); // expected-note{{also accessed here}}
 }
+
+// This used to crash in the constructor of WeakObjectProfileTy when a
+// DeclRefExpr was passed that didn't reference a VarDecl.
+
+typedef INTF * INTFPtrTy;
+
+enum E {
+  e1
+};
+
+void foo1() {
+  INTFPtrTy tmp = (INTFPtrTy)e1; // expected-error{{cast of 'E' to 'INTFPtrTy' 
(aka 'INTF *') is disallowed with ARC}}
+}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293810 - [CodeGen] Update test after recent changes in llvm (r293799).

2017-02-01 Thread Davide Italiano via cfe-commits
Author: davide
Date: Wed Feb  1 14:43:28 2017
New Revision: 293810

URL: http://llvm.org/viewvc/llvm-project?rev=293810&view=rev
Log:
[CodeGen] Update test after recent changes in llvm (r293799).

Modified:
cfe/trunk/test/CodeGen/link-bitcode-file.c

Modified: cfe/trunk/test/CodeGen/link-bitcode-file.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/link-bitcode-file.c?rev=293810&r1=293809&r2=293810&view=diff
==
--- cfe/trunk/test/CodeGen/link-bitcode-file.c (original)
+++ cfe/trunk/test/CodeGen/link-bitcode-file.c Wed Feb  1 14:43:28 2017
@@ -27,7 +27,7 @@ int f2(void) { return 43; }
 #else
 
 // CHECK-NO-BC-LABEL: define i32 @g
-// CHECK-NO-BC: ret i32 42
+// CHECK-NO-BC: ret i32 %call
 int g(void) {
   return f();
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxxabi] r292638 - Fix catch_reference_nullptr.pass.cpp test for GCC.

2017-02-01 Thread Renato Golin via cfe-commits
On 1 February 2017 at 19:33, Hans Wennborg  wrote:
> Also I'm confused, since I haven't seen anything besides r292638
> mentioned. Are there other changes besides that up for merging?

I think the other commits were back-ported by other means (other PRs).

Regardless, this is an important commit that fixes a number of
problems building libc++ and should go in 4.0.

I'll see if I can find the others and will let you know.

cheers,
--renato
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxxabi] r292638 - Fix catch_reference_nullptr.pass.cpp test for GCC.

2017-02-01 Thread Renato Golin via cfe-commits
Right, the other one was 292607 and has already been merged. Sorry for
the confusion. We just need to merge this one and we're done.

--renato

On 1 February 2017 at 21:14, Renato Golin  wrote:
> On 1 February 2017 at 19:33, Hans Wennborg  wrote:
>> Also I'm confused, since I haven't seen anything besides r292638
>> mentioned. Are there other changes besides that up for merging?
>
> I think the other commits were back-ported by other means (other PRs).
>
> Regardless, this is an important commit that fixes a number of
> problems building libc++ and should go in 4.0.
>
> I'll see if I can find the others and will let you know.
>
> cheers,
> --renato
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29396: [clang-format] Don't reflow lines starting with TODO, FIXME or XXX.

2017-02-01 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.


https://reviews.llvm.org/D29396



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20561: Warn when taking address of packed member

2017-02-01 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

The last review left out the case of naturally aligned packed members, IIRC. I 
have to go over the warning list in NetBSD again, but I'm moderately sure it is 
not fixed.

The better example is:

  struct __attribute__((__packed__)) bar {
  uint16_t x1;
  uint16_t x2;
  };
  
  &bar->x2;

...which is not aligned.


Repository:
  rL LLVM

https://reviews.llvm.org/D20561



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29419: [Analyzer] Checker for mismatched iterators

2017-02-01 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.

A new checker to check whether multiple iterators which should refer to the 
same container refer to different ones. Here we include comparisons, 
constructors which take an iterator pair and any template function which takes 
iterator pair(s).


https://reviews.llvm.org/D29419

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  test/Analysis/Inputs/system-header-simulator-cxx.h
  test/Analysis/diagnostics/explicit-suppression.cpp
  test/Analysis/mismatched-iterator.cpp

Index: test/Analysis/mismatched-iterator.cpp
===
--- /dev/null
+++ test/Analysis/mismatched-iterator.cpp
@@ -0,0 +1,121 @@
+// RUN: %clang_cc1 -std=c++11 -analyze -analyzer-checker=core,cplusplus,alpha.cplusplus.MismatchedIterator -analyzer-eagerly-assume %s -verify
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+void good_insert1(std::vector &v, int n) {
+  v.insert(v.cbegin(), n); // no-warning
+}
+
+
+void good_insert2(std::vector &v, int len, int n) {
+  v.insert(v.cbegin(), len, n); // no-warning
+}
+
+void good_insert3(std::vector &v1, std::vector &v2) {
+  v1.insert(v1.cbegin(), v2.cbegin(), v2.cend()); // no-warning
+}
+
+void good_insert4(std::vector &v, int len, int n) {
+  v.insert(v.cbegin(), {n-1, n, n+1}); // no-warning
+}
+
+void good_insert_find(std::vector &v, int n, int m) {
+  auto i = std::find(v.begin(), v.end(), n);
+  v.insert(i, m); // no-warning
+}
+
+void good_erase1(std::vector &v) {
+  v.erase(v.cbegin()); // no-warning
+}
+
+void good_erase2(std::vector &v) {
+  v.erase(v.cbegin(), v.cend()); // no-warning
+}
+
+void good_emplace(std::vector &v, int n) {
+  v.emplace(v.cbegin(), n); // no-warning
+}
+
+void good_ctor(std::vector &v) {
+  std::vector new_v(v.begin(), v.end()); // no-warning
+}
+
+void good_find(std::vector &v, int n) {
+  std::find(v.begin(), v.end(), n); // no-warning
+}
+
+void good_find_first_of(std::vector &v1, std::vector &v2) {
+  std::find_first_of(v1.begin(), v1.end(), v2.begin(), v2.end()); // no-warning
+}
+
+void good_comparison(std::vector &v) {
+  if (v.begin() == v.end()) {} // no-warning
+}
+
+void bad_insert1(std::vector &v1, std::vector &v2, int n) {
+  v2.insert(v1.cbegin(), n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_insert2(std::vector &v1, std::vector &v2, int len, int n) {
+  v2.insert(v1.cbegin(), len, n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_insert3(std::vector &v1, std::vector &v2) {
+  v2.insert(v1.cbegin(), v2.cbegin(), v2.cend()); // expected-warning{{Iterator access mismatched}}
+  v1.insert(v1.cbegin(), v1.cbegin(), v2.cend()); // expected-warning{{Iterator access mismatched}}
+  v1.insert(v1.cbegin(), v2.cbegin(), v1.cend()); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_insert4(std::vector &v1, std::vector &v2, int len, int n) {
+  v2.insert(v1.cbegin(), {n-1, n, n+1}); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_erase1(std::vector &v1, std::vector &v2) {
+  v2.erase(v1.cbegin()); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_erase2(std::vector &v1, std::vector &v2) {
+  v2.erase(v2.cbegin(), v1.cend()); // expected-warning{{Iterator access mismatched}}
+  v2.erase(v1.cbegin(), v2.cend()); // expected-warning{{Iterator access mismatched}}
+  v2.erase(v1.cbegin(), v1.cend()); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_emplace(std::vector &v1, std::vector &v2, int n) {
+  v2.emplace(v1.cbegin(), n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_ctor(std::vector &v1, std::vector &v2) {
+  std::vector new_v(v1.begin(), v2.end()); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_find(std::vector &v1, std::vector &v2, int n) {
+  std::find(v1.begin(), v2.end(), n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_find_first_of(std::vector &v1, std::vector &v2) {
+  std::find_first_of(v1.begin(), v2.end(), v2.begin(), v2.end()); // expected-warning{{Iterator access mismatched}}
+  std::find_first_of(v1.begin(), v1.end(), v2.begin(), v1.end()); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_comparison(std::vector &v1, std::vector &v2) {
+  if (v1.begin() != v2.end()) { // expected-warning{{Iterator access mismatched}}
+*v1.begin();
+  }
+}
+
+void bad_insert_find(std::vector &v1, std::vector &v2, int n, int m) {
+  auto i = std::find(v1.begin(), v1.end(), n);
+  v2.insert(i, m); // expected-warning{{Iterator access mismatched}}
+}
+
+void good_overwrite(std::vector &v1, std::vector &v2, int n) {
+  auto i = v1.cbegin();
+  i = v2.cbegin();
+  v2.insert(i, n); // no-warning
+}
+
+void bad_overwrite(std::vector &v1, std::vector &v2, int n) {
+  auto i = v1.cbegin();
+  i = v2.cbegin();
+  v1.insert(i, n); // expected-warning{{Iterator access mismatched}}
+}
Index: test/Analysis/diagnostics/explicit-suppression.cpp

[PATCH] D29419: [Analyzer] Checker for mismatched iterators

2017-02-01 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 86709.
baloghadamsoftware added a comment.
Herald added a subscriber: mgorny.

The checker itself disappeared mystically from the previous diff...


https://reviews.llvm.org/D29419

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  test/Analysis/Inputs/system-header-simulator-cxx.h
  test/Analysis/diagnostics/explicit-suppression.cpp
  test/Analysis/mismatched-iterator.cpp

Index: test/Analysis/mismatched-iterator.cpp
===
--- /dev/null
+++ test/Analysis/mismatched-iterator.cpp
@@ -0,0 +1,121 @@
+// RUN: %clang_cc1 -std=c++11 -analyze -analyzer-checker=core,cplusplus,alpha.cplusplus.MismatchedIterator -analyzer-eagerly-assume %s -verify
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+void good_insert1(std::vector &v, int n) {
+  v.insert(v.cbegin(), n); // no-warning
+}
+
+
+void good_insert2(std::vector &v, int len, int n) {
+  v.insert(v.cbegin(), len, n); // no-warning
+}
+
+void good_insert3(std::vector &v1, std::vector &v2) {
+  v1.insert(v1.cbegin(), v2.cbegin(), v2.cend()); // no-warning
+}
+
+void good_insert4(std::vector &v, int len, int n) {
+  v.insert(v.cbegin(), {n-1, n, n+1}); // no-warning
+}
+
+void good_insert_find(std::vector &v, int n, int m) {
+  auto i = std::find(v.begin(), v.end(), n);
+  v.insert(i, m); // no-warning
+}
+
+void good_erase1(std::vector &v) {
+  v.erase(v.cbegin()); // no-warning
+}
+
+void good_erase2(std::vector &v) {
+  v.erase(v.cbegin(), v.cend()); // no-warning
+}
+
+void good_emplace(std::vector &v, int n) {
+  v.emplace(v.cbegin(), n); // no-warning
+}
+
+void good_ctor(std::vector &v) {
+  std::vector new_v(v.begin(), v.end()); // no-warning
+}
+
+void good_find(std::vector &v, int n) {
+  std::find(v.begin(), v.end(), n); // no-warning
+}
+
+void good_find_first_of(std::vector &v1, std::vector &v2) {
+  std::find_first_of(v1.begin(), v1.end(), v2.begin(), v2.end()); // no-warning
+}
+
+void good_comparison(std::vector &v) {
+  if (v.begin() == v.end()) {} // no-warning
+}
+
+void bad_insert1(std::vector &v1, std::vector &v2, int n) {
+  v2.insert(v1.cbegin(), n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_insert2(std::vector &v1, std::vector &v2, int len, int n) {
+  v2.insert(v1.cbegin(), len, n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_insert3(std::vector &v1, std::vector &v2) {
+  v2.insert(v1.cbegin(), v2.cbegin(), v2.cend()); // expected-warning{{Iterator access mismatched}}
+  v1.insert(v1.cbegin(), v1.cbegin(), v2.cend()); // expected-warning{{Iterator access mismatched}}
+  v1.insert(v1.cbegin(), v2.cbegin(), v1.cend()); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_insert4(std::vector &v1, std::vector &v2, int len, int n) {
+  v2.insert(v1.cbegin(), {n-1, n, n+1}); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_erase1(std::vector &v1, std::vector &v2) {
+  v2.erase(v1.cbegin()); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_erase2(std::vector &v1, std::vector &v2) {
+  v2.erase(v2.cbegin(), v1.cend()); // expected-warning{{Iterator access mismatched}}
+  v2.erase(v1.cbegin(), v2.cend()); // expected-warning{{Iterator access mismatched}}
+  v2.erase(v1.cbegin(), v1.cend()); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_emplace(std::vector &v1, std::vector &v2, int n) {
+  v2.emplace(v1.cbegin(), n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_ctor(std::vector &v1, std::vector &v2) {
+  std::vector new_v(v1.begin(), v2.end()); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_find(std::vector &v1, std::vector &v2, int n) {
+  std::find(v1.begin(), v2.end(), n); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_find_first_of(std::vector &v1, std::vector &v2) {
+  std::find_first_of(v1.begin(), v2.end(), v2.begin(), v2.end()); // expected-warning{{Iterator access mismatched}}
+  std::find_first_of(v1.begin(), v1.end(), v2.begin(), v1.end()); // expected-warning{{Iterator access mismatched}}
+}
+
+void bad_comparison(std::vector &v1, std::vector &v2) {
+  if (v1.begin() != v2.end()) { // expected-warning{{Iterator access mismatched}}
+*v1.begin();
+  }
+}
+
+void bad_insert_find(std::vector &v1, std::vector &v2, int n, int m) {
+  auto i = std::find(v1.begin(), v1.end(), n);
+  v2.insert(i, m); // expected-warning{{Iterator access mismatched}}
+}
+
+void good_overwrite(std::vector &v1, std::vector &v2, int n) {
+  auto i = v1.cbegin();
+  i = v2.cbegin();
+  v2.insert(i, n); // no-warning
+}
+
+void bad_overwrite(std::vector &v1, std::vector &v2, int n) {
+  auto i = v1.cbegin();
+  i = v2.cbegin();
+  v1.insert(i, n); // expected-warning{{Iterator access mismatched}}
+}
Index: test/Analysis/diagnostics/explicit-suppression.cpp
===

[libcxxabi] r293813 - Merging r292638:

2017-02-01 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Wed Feb  1 15:30:36 2017
New Revision: 293813

URL: http://llvm.org/viewvc/llvm-project?rev=293813&view=rev
Log:
Merging r292638:

r292638 | ericwf | 2017-01-20 11:34:19 -0800 (Fri, 20 Jan 2017) | 9 lines

Fix catch_reference_nullptr.pass.cpp test for GCC.

This test contained an implicit conversion from nullptr to bool.
Clang warns about this but the test had supressed that warning.
However GCC diagnoses the same code as an error and requires
-fpermissive to accept it.

This patch fixes both the warning and the error by explicitly
converting the pointer to bool.


Modified:
libcxxabi/branches/release_40/   (props changed)
libcxxabi/branches/release_40/test/catch_reference_nullptr.pass.cpp

Propchange: libcxxabi/branches/release_40/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Feb  1 15:30:36 2017
@@ -1 +1 @@
-/libcxxabi/trunk:292135,292418
+/libcxxabi/trunk:292135,292418,292638

Modified: libcxxabi/branches/release_40/test/catch_reference_nullptr.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/branches/release_40/test/catch_reference_nullptr.pass.cpp?rev=293813&r1=293812&r2=293813&view=diff
==
--- libcxxabi/branches/release_40/test/catch_reference_nullptr.pass.cpp 
(original)
+++ libcxxabi/branches/release_40/test/catch_reference_nullptr.pass.cpp Wed Feb 
 1 15:30:36 2017
@@ -12,12 +12,6 @@
 #include 
 #include 
 
-// Clang emits a warning on converting an object of type nullptr_t to bool,
-// even in generic code. Suppress it.
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wnull-conversion"
-#endif
-
 struct A {};
 
 template
@@ -25,7 +19,7 @@ static void catch_nullptr_test() {
   try {
 throw nullptr;
   } catch (T &p) {
-assert(CanCatchNullptr && !p);
+assert(CanCatchNullptr && !static_cast(p));
   } catch (...) {
 assert(!CanCatchNullptr);
   }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxxabi] r292638 - Fix catch_reference_nullptr.pass.cpp test for GCC.

2017-02-01 Thread Hans Wennborg via cfe-commits
Merged this one in r293813.

Cheers,
Hans

On Wed, Feb 1, 2017 at 1:16 PM, Renato Golin  wrote:
> Right, the other one was 292607 and has already been merged. Sorry for
> the confusion. We just need to merge this one and we're done.
>
> --renato
>
> On 1 February 2017 at 21:14, Renato Golin  wrote:
>> On 1 February 2017 at 19:33, Hans Wennborg  wrote:
>>> Also I'm confused, since I haven't seen anything besides r292638
>>> mentioned. Are there other changes besides that up for merging?
>>
>> I think the other commits were back-ported by other means (other PRs).
>>
>> Regardless, this is an important commit that fixes a number of
>> problems building libc++ and should go in 4.0.
>>
>> I'll see if I can find the others and will let you know.
>>
>> cheers,
>> --renato
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293815 - Fix hole in our enforcement of rule requiring 'typename' prior to a dependent

2017-02-01 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Feb  1 15:36:38 2017
New Revision: 293815

URL: http://llvm.org/viewvc/llvm-project?rev=293815&view=rev
Log:
Fix hole in our enforcement of rule requiring 'typename' prior to a dependent
name. If the dependent name happened to end in a template-id (X::Y), we
would fail to notice that the 'typename' keyword is missing when resolving it
to a type.

It turns out that GCC has a similar bug. If this shows up in much real code, we
can easily downgrade this to an ExtWarn.

Added:
cfe/trunk/test/CXX/temp/temp.res/p3.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp
cfe/trunk/test/CXX/temp/temp.decls/temp.variadic/sizeofpack.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=293815&r1=293814&r2=293815&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Feb  1 15:36:38 
2017
@@ -4324,6 +4324,8 @@ def note_typename_refers_here : Note<
 "referenced member %0 is declared here">;
 def err_typename_missing : Error<
   "missing 'typename' prior to dependent type name '%0%1'">;
+def err_typename_missing_template : Error<
+  "missing 'typename' prior to dependent type template name '%0%1'">;
 def ext_typename_missing : ExtWarn<
   "missing 'typename' prior to dependent type name '%0%1'">,
   InGroup>;

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=293815&r1=293814&r2=293815&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed Feb  1 15:36:38 2017
@@ -2694,7 +2694,7 @@ private:
SourceLocation TemplateKWLoc,
UnqualifiedId &TemplateName,
bool AllowTypeAnnotation = true);
-  void AnnotateTemplateIdTokenAsType();
+  void AnnotateTemplateIdTokenAsType(bool IsClassName = false);
   bool IsTemplateArgumentList(unsigned Skip = 0);
   bool ParseTemplateArgumentList(TemplateArgList &TemplateArgs);
   ParsedTemplateArgument ParseTemplateTemplateArgument();

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=293815&r1=293814&r2=293815&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Feb  1 15:36:38 2017
@@ -5931,7 +5931,8 @@ public:
   SourceLocation LAngleLoc,
   ASTTemplateArgsPtr TemplateArgs,
   SourceLocation RAngleLoc,
-  bool IsCtorOrDtorName = false);
+  bool IsCtorOrDtorName = false,
+  bool IsClassName = false);
 
   /// \brief Parsed an elaborated-type-specifier that refers to a template-id,
   /// such as \c class T::template apply.

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=293815&r1=293814&r2=293815&view=diff
==
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Feb  1 15:36:38 2017
@@ -1076,7 +1076,7 @@ TypeResult Parser::ParseBaseTypeSpecifie
 TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
 if (TemplateId->Kind == TNK_Type_template ||
 TemplateId->Kind == TNK_Dependent_template_name) {
-  AnnotateTemplateIdTokenAsType();
+  AnnotateTemplateIdTokenAsType(/*IsClassName*/true);
 
   assert(Tok.is(tok::annot_typename) && "template-id -> type failed");
   ParsedType Type = getTypeAnnotation(Tok);
@@ -1124,10 +1124,10 @@ TypeResult Parser::ParseBaseTypeSpecifie
 
 // Parse the full template-id, then turn it into a type.
 if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(),
-TemplateName, true))
+TemplateName))
   return true;
-if (TNK == TNK_Dependent_template_name)
-  AnnotateTemplateIdTokenAsType();
+if (TNK == TNK_Type_template || TNK == TNK_Dependent_template_name)
+  AnnotateTemplateIdTokenAsType(/*IsClassName*/true);
 
 // If we didn't end up with a typename token, there's nothing more we
 // can do.
@@

r293817 - Repoint 'missing typename' diagnostic to the location where 'typename' should be added.

2017-02-01 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Feb  1 15:41:18 2017
New Revision: 293817

URL: http://llvm.org/viewvc/llvm-project?rev=293817&view=rev
Log:
Repoint 'missing typename' diagnostic to the location where 'typename' should 
be added.

Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/CXX/temp/temp.res/p3.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=293817&r1=293816&r2=293817&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Feb  1 15:41:18 2017
@@ -2440,7 +2440,7 @@ Sema::ActOnTemplateIdType(CXXScopeSpec &
 //   qualified-id denotes a type, forming an
 //   elaborated-type-specifier (7.1.5.3).
 if (!LookupCtx && isDependentScopeSpecifier(SS)) {
-  Diag(TemplateIILoc, diag::err_typename_missing_template)
+  Diag(SS.getBeginLoc(), diag::err_typename_missing_template)
 << SS.getScopeRep() << TemplateII->getName();
   // Recover as if 'typename' were specified.
   // FIXME: This is not quite correct recovery as we don't transform SS

Modified: cfe/trunk/test/CXX/temp/temp.res/p3.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.res/p3.cpp?rev=293817&r1=293816&r2=293817&view=diff
==
--- cfe/trunk/test/CXX/temp/temp.res/p3.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.res/p3.cpp Wed Feb  1 15:41:18 2017
@@ -12,7 +12,8 @@ struct X {
   };
 };
 
-template A::B f1(); // expected-error {{missing 'typename' 
prior to dependent type template name 'A::B'}}
+template A // expected-error {{missing 'typename' prior to 
dependent type template name 'A::B'}}
+  ::B f1();
 template A::C f2(); // expected-error {{missing 'typename' 
prior to dependent type template name 'A::C'}}
 
 // FIXME: Should these cases really be valid? There doesn't appear to be a 
rule prohibiting them...


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16135: Macro Debug Info support in Clang

2017-02-01 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud added a comment.

Thanks Adrian for the fast response.
See some answers below.

I will update the code and upload a new patch soon.




Comment at: lib/CodeGen/MacroPPCallbacks.cpp:154
+StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+  // Only care about "include" directives.
+  if (!IncludeTok.is(tok::identifier))

aprantl wrote:
> aaboud wrote:
> > aprantl wrote:
> > > #include as opposed to #import? If so, why?
> > I am not familiar with "#import" keyword.
> > 1. Is it handled differently by clang that #include?
> > 2. Do we need to generate macro debug info for it?
> > 
> > The reason I have this switch below, is that I am not sure if we call this 
> > "InclusionDirective" callback for identifiers that are not "#include".
> > 
> > However, I see no harm of updating the LastHashLoc every time we enter this 
> > function. The value will not be used unless it is set just before calling 
> > "FileChanged"callback.
> #import comes from Objective-C. It is equivalent to #include + #pragma once.
> I'm curious whether this comment means that it isn't handled?
I will remove the switch and update the LastHashLoc unconditionally.
I did not check Objective-C debug info, but I assume it will work fine once I 
change these lines.



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:88
+  // Invalid location represents line zero.
+  return SourceLocation();
+}

aprantl wrote:
> I think the entire function can be replaced with
> ```
> if ((Status == MainFileScope) ||
> (Status == CommandLineScopeIncludes && CommandIncludeFiles))
>   return Loc;
> return SourceLocation();
> ```
Sure, will do.
The reason I have a switch, because I had more cases during the implementation 
that I get rid of.



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:100
+  bool CreateMacroFile = false;
+  bool PopScope = false;
+  SourceLocation LineLoc = getCorrectLocation(LastHashLoc);

aprantl wrote:
> Could you try splitting this function up into two functions?
> 
> MacroPPCallbacks::FileEntered()
> MacroPPCallbacks::FileExited()
> 
> and the common code factored out into a helper? The control flow here seems 
> unnecessarily complex with all the flags.
Will try restructure.
The way I implemented this is by having stages (parsing levels).
The control flow is to identify the current stage and decide how to continue 
from there.

I will see what I can do to make the code much clear.



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:177
+  llvm::raw_string_ostream Value(ValueBuffer);
+  calculatMacroDefinition(*Id, *MD->getMacroInfo(), PP, Name, Value);
+  Gen->getCGDebugInfo()->CreateMacro(getCurrentScope(),

aprantl wrote:
> calculat*e*MacroDefinition
> (is there a better word than calculate?)
How about:
GenerateMacroDefinition
PrintMacroDefinition
ParseMacroDefinition

Do you think any of the above would be better choice?


https://reviews.llvm.org/D16135



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28952: [analyzer] Add new Z3 constraint manager backend

2017-02-01 Thread Dominic Chen via Phabricator via cfe-commits
ddcc added a comment.

In https://reviews.llvm.org/D28952#659728, @nlopes wrote:

> Let me give just 2 more Z3-related suggestions:
>
> - instead of re-creating the solver, it might be faster to do Z3_solver_reset
> - "once in a while" it might be helpful to delete everything (all solvers, 
> asts, context) and call Z3_reset_memory.  Z3's small object pool is not very 
> good and keeps growing /ad infinitum/, so cleaning it up once a while is a 
> good thing (improves cache usage and reduces memory consumption).
>
>   BTW, you may want to call Z3_finalize_memory at exit to keep clang 
> valgrind/asan-clean.  (Z3 keeps a lot of internal buffers otherwise)


Thanks, the most recent revision now reuses the solver object, and frees Z3 
memory at exit. I'm skipping the reset memory part for now, because my 
understanding is that a new instance of `clang -cc1` will be spun up for each 
compilation unit anyway, and it'd be tricky to find a suitable point to do that 
while maintaining consistency.

On the testsuite, the runtime is now down to 185 secs, and a valgrind test is 
much cleaner.


https://reviews.llvm.org/D28952



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29205: Change debug-info-for-profiling from a TargetOption to a function attribute.

2017-02-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Oops, forgot to write stuff so the approval appears on-list.

Anyway - looks good/approved.


https://reviews.llvm.org/D29205



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29384: [analyzer] Fix an assertion fail in CStringSyntaxChecker

2017-02-01 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

This looks good to me. Thanks for fixing this!


Repository:
  rL LLVM

https://reviews.llvm.org/D29384



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293834 - Change debug-info-for-profiling from a TargetOption to a function attribute.

2017-02-01 Thread Dehao Chen via cfe-commits
Author: dehao
Date: Wed Feb  1 16:45:21 2017
New Revision: 293834

URL: http://llvm.org/viewvc/llvm-project?rev=293834&view=rev
Log:
Change debug-info-for-profiling from a TargetOption to a function attribute.

Summary: cfe change for https://reviews.llvm.org/D29203

Reviewers: echristo, dblaikie

Reviewed By: dblaikie

Subscribers: mehdi_amini, cfe-commits

Differential Revision: https://reviews.llvm.org/D29205

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=293834&r1=293833&r2=293834&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Wed Feb  1 16:45:21 2017
@@ -568,7 +568,6 @@ void EmitAssemblyHelper::CreateTargetMac
   Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
   Options.CompressDebugSections = CodeGenOpts.CompressDebugSections;
   Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
-  Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling;
 
   // Set EABI version.
   Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion)

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=293834&r1=293833&r2=293834&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Feb  1 16:45:21 2017
@@ -509,7 +509,8 @@ void CGDebugInfo::CreateCompileUnit() {
Checksum),
   Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
   CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */,
-  CGM.getCodeGenOpts().SplitDwarfInlining);
+  CGM.getCodeGenOpts().SplitDwarfInlining,
+  CGM.getCodeGenOpts().DebugInfoForProfiling);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29369: [ubsan] Omit superflous overflow checks for promoted arithmetic (PR20193)

2017-02-01 Thread Vedant Kumar via Phabricator via cfe-commits
vsk marked an inline comment as done.
vsk added inline comments.



Comment at: lib/CodeGen/CGExprScalar.cpp:72
+  if (const auto *UO = dyn_cast(Op.E))
+return IsPromotedInteger(UO->getSubExpr());
+

efriedma wrote:
> Checking isPromotableIntegerType doesn't work the way you want it to; types 
> can be "promoted" without actually widening them.  For example, enum types 
> are promotable, and in C++ wchar_t is promotable.
Thanks for catching this! I have fixed the issue and will update this patch 
shortly.


https://reviews.llvm.org/D29369



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29369: [ubsan] Omit superflous overflow checks for promoted arithmetic (PR20193)

2017-02-01 Thread Vedant Kumar via Phabricator via cfe-commits
vsk updated this revision to Diff 86739.
vsk marked an inline comment as done.
vsk added a comment.

- Per Eli's comment: check that integers are actually widened, instead of 
incorrectly assuming they are always widened. I added some test cases for this.
- Address the 'fixme' regarding multiplication with unsigned operands.


https://reviews.llvm.org/D29369

Files:
  lib/CodeGen/CGExprScalar.cpp
  test/CodeGen/compound-assign-overflow.c
  test/CodeGen/ubsan-promoted-arith.cpp
  test/CodeGen/unsigned-promotion.c

Index: test/CodeGen/unsigned-promotion.c
===
--- test/CodeGen/unsigned-promotion.c
+++ test/CodeGen/unsigned-promotion.c
@@ -9,52 +9,6 @@
 unsigned short si, sj, sk;
 unsigned char ci, cj, ck;
 
-extern void opaqueshort(unsigned short);
-extern void opaquechar(unsigned char);
-
-// CHECKS-LABEL:   define void @testshortadd()
-// CHECKU-LABEL: define void @testshortadd()
-void testshortadd() {
-  // CHECKS:load i16, i16* @sj
-  // CHECKS:load i16, i16* @sk
-  // CHECKS:[[T1:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T2:%.*]], i32 [[T3:%.*]])
-  // CHECKS-NEXT:   [[T4:%.*]] = extractvalue { i32, i1 } [[T1]], 0
-  // CHECKS-NEXT:   [[T5:%.*]] = extractvalue { i32, i1 } [[T1]], 1
-  // CHECKS:call void @__ubsan_handle_add_overflow
-  //
-  // CHECKU:  [[T1:%.*]] = load i16, i16* @sj
-  // CHECKU:  [[T2:%.*]] = zext i16 [[T1]]
-  // CHECKU:  [[T3:%.*]] = load i16, i16* @sk
-  // CHECKU:  [[T4:%.*]] = zext i16 [[T3]]
-  // CHECKU-NOT:  llvm.sadd
-  // CHECKU-NOT:  llvm.uadd
-  // CHECKU:  [[T5:%.*]] = add nsw i32 [[T2]], [[T4]]
-
-  si = sj + sk;
-}
-
-// CHECKS-LABEL:   define void @testshortsub()
-// CHECKU-LABEL: define void @testshortsub()
-void testshortsub() {
-
-  // CHECKS:load i16, i16* @sj
-  // CHECKS:load i16, i16* @sk
-  // CHECKS:[[T1:%.*]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 [[T2:%.*]], i32 [[T3:%.*]])
-  // CHECKS-NEXT:   [[T4:%.*]] = extractvalue { i32, i1 } [[T1]], 0
-  // CHECKS-NEXT:   [[T5:%.*]] = extractvalue { i32, i1 } [[T1]], 1
-  // CHECKS:call void @__ubsan_handle_sub_overflow
-  //
-  // CHECKU:  [[T1:%.*]] = load i16, i16* @sj
-  // CHECKU:  [[T2:%.*]] = zext i16 [[T1]]
-  // CHECKU:  [[T3:%.*]] = load i16, i16* @sk
-  // CHECKU:  [[T4:%.*]] = zext i16 [[T3]]
-  // CHECKU-NOT:  llvm.ssub
-  // CHECKU-NOT:  llvm.usub
-  // CHECKU:  [[T5:%.*]] = sub nsw i32 [[T2]], [[T4]]
-
-  si = sj - sk;
-}
-
 // CHECKS-LABEL:   define void @testshortmul()
 // CHECKU-LABEL: define void @testshortmul()
 void testshortmul() {
@@ -76,50 +30,6 @@
   si = sj * sk;
 }
 
-// CHECKS-LABEL:   define void @testcharadd()
-// CHECKU-LABEL: define void @testcharadd()
-void testcharadd() {
-
-  // CHECKS:load i8, i8* @cj
-  // CHECKS:load i8, i8* @ck
-  // CHECKS:[[T1:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T2:%.*]], i32 [[T3:%.*]])
-  // CHECKS-NEXT:   [[T4:%.*]] = extractvalue { i32, i1 } [[T1]], 0
-  // CHECKS-NEXT:   [[T5:%.*]] = extractvalue { i32, i1 } [[T1]], 1
-  // CHECKS:call void @__ubsan_handle_add_overflow
-  //
-  // CHECKU:  [[T1:%.*]] = load i8, i8* @cj
-  // CHECKU:  [[T2:%.*]] = zext i8 [[T1]]
-  // CHECKU:  [[T3:%.*]] = load i8, i8* @ck
-  // CHECKU:  [[T4:%.*]] = zext i8 [[T3]]
-  // CHECKU-NOT:  llvm.sadd
-  // CHECKU-NOT:  llvm.uadd
-  // CHECKU:  [[T5:%.*]] = add nsw i32 [[T2]], [[T4]]
-
-  ci = cj + ck;
-}
-
-// CHECKS-LABEL:   define void @testcharsub()
-// CHECKU-LABEL: define void @testcharsub()
-void testcharsub() {
-
-  // CHECKS:load i8, i8* @cj
-  // CHECKS:load i8, i8* @ck
-  // CHECKS:[[T1:%.*]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 [[T2:%.*]], i32 [[T3:%.*]])
-  // CHECKS-NEXT:   [[T4:%.*]] = extractvalue { i32, i1 } [[T1]], 0
-  // CHECKS-NEXT:   [[T5:%.*]] = extractvalue { i32, i1 } [[T1]], 1
-  // CHECKS:call void @__ubsan_handle_sub_overflow
-  //
-  // CHECKU:  [[T1:%.*]] = load i8, i8* @cj
-  // CHECKU:  [[T2:%.*]] = zext i8 [[T1]]
-  // CHECKU:  [[T3:%.*]] = load i8, i8* @ck
-  // CHECKU:  [[T4:%.*]] = zext i8 [[T3]]
-  // CHECKU-NOT:  llvm.ssub
-  // CHECKU-NOT:  llvm.usub
-  // CHECKU:  [[T5:%.*]] = sub nsw i32 [[T2]], [[T4]]
-
-  ci = cj - ck;
-}
-
 // CHECKS-LABEL:   define void @testcharmul()
 // CHECKU-LABEL: define void @testcharmul()
 void testcharmul() {
Index: test/CodeGen/ubsan-promoted-arith.cpp
===
--- /dev/null
+++ test/CodeGen/ubsan-promoted-arith.cpp
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -fsanitize=signed-integer-overflow,unsigned-integer-overflow | FileCheck %s
+
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+
+enum E1 : int {
+  a
+};
+
+enum E2 : char {
+  b
+};
+
+// CHECK-L

r293839 - clang-format: Fix incorrect line breaks after forced operator wraps.

2017-02-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Feb  1 17:27:37 2017
New Revision: 293839

URL: http://llvm.org/viewvc/llvm-project?rev=293839&view=rev
Log:
clang-format: Fix incorrect line breaks after forced operator wraps.

Before:
  bool x = a //
   ||
   b
   //
   || ;

After:
  bool x = a //
   || b
   //
   || ;

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=293839&r1=293838&r2=293839&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Wed Feb  1 17:27:37 2017
@@ -420,7 +420,7 @@ void ContinuationIndenter::addTokenOnCur
   P->getPrecedence() != prec::Assignment &&
   P->getPrecedence() != prec::Relational) {
 bool BreakBeforeOperator =
-P->is(tok::lessless) ||
+P->MustBreakBefore || P->is(tok::lessless) ||
 (P->is(TT_BinaryOperator) &&
  Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None) ||
 (P->is(TT_ConditionalExpr) && Style.BreakBeforeTernaryOperators);

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=293839&r1=293838&r2=293839&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Feb  1 17:27:37 2017
@@ -4151,6 +4151,15 @@ TEST_F(FormatTest, ExpressionIndentation
Style);
 }
 
+TEST_F(FormatTest, EnforcedOperatorWraps) {
+  // Here we'd like to wrap after the || operators, but a comment is forcing an
+  // earlier wrap.
+  verifyFormat("bool x = a //\n"
+   " || b\n"
+   " //\n"
+   " || ;");
+}
+
 TEST_F(FormatTest, NoOperandAlignment) {
   FormatStyle Style = getLLVMStyle();
   Style.AlignOperands = false;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29432: Modular Codegen: Emit inline asm into users, not modular objects

2017-02-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie created this revision.

The best semantics I can come up with (based on discussions with
Richard) for inline asm and namespace scope internal linkage variables
in modular headers is to emit them into all users and never into modular
objects.

The reason for this is that such asm might create important symbols
(like the iostreams global initializer) that can only be produced if the
submodule is used (doesn't strictly apply to inline asm, as such - which
is currently emitted if the module is used at all (regardless of
submodules) I think). This does mean that if any modular code does use
these entities it will be ill formed/NDR (link error, generally) for
now. It could be diagnosed at parse/module-creation time.

This change has a bit of refactoring to allow this to work for inline
asm (& to work more efficiently for internal linkage namespace-scope
variables). Making the MODULAR_CODEGEN_DECLS and
EAGERLY_DESERIALIZED_DECLS distinct. Not only does this allow the
modular codegen not to needlessly deserialize and then ignore the
eagerly deserialized decls, it also allows there to be eagerly
deserialized decls that modular codegen never sees - such as inline asm.

(if this isn't the right design - if the absence of an entry in
eagerly/modular codegen shouldn't produce different behavior (ie: it
should only be an optimization) happy to make this work
differently/harder by making sure inline asm can be filtered, even if it
were loaded)

This change does a little work to preserve a scenario that it probably
doesn't need to: 'classic' AST codegen. There's a few tests
(test/Frontend/ast-*) that verify that the codegen of a serialized AST
file (without -fmodules-codegen) produces basically the same code as if
the AST hadn't been serialized. Is this important? Should we kill off
those tests & not worry about it? (this behavior is preserved by still
respecting the EAGERLY_DESERIALIZED_DECLS when deserializing an AST file
if it doesn't contain MODULAR_CODEGEN_DECLS).


https://reviews.llvm.org/D29432

Files:
  include/clang/AST/ASTContext.h
  include/clang/Serialization/ASTReader.h
  lib/AST/ASTContext.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGenCXX/modules-ts.cppm
  test/Modules/Inputs/codegen/foo.h
  test/Modules/codegen.test

Index: test/Modules/codegen.test
===
--- test/Modules/codegen.test
+++ test/Modules/codegen.test
@@ -12,14 +12,12 @@
 RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-llvm-passes %t/bar.pcm -fmodule-file=%t/foo.pcm | FileCheck --check-prefix=BAR-CMN --check-prefix=BAR-OPT %s
 RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-llvm-passes -fmodules -fmodule-file=%t/foo.pcm -fmodule-file=%t/bar.pcm %S/Inputs/codegen/use.cpp | FileCheck --check-prefix=USE-CMN --check-prefix=USE-OPT %s
 
-FOO-NOT: comdat
+FOO-NOT: {{comdat|module asm}}
 FOO: $_Z3foov = comdat any
 FOO: $_Z4foo2v = comdat any
 FOO: $_ZZ3foovE1i = comdat any
 FOO: @_ZZ3foovE1i = linkonce_odr global i32 0, comdat
 FOO-NOT: {{comdat|define|declare}}
-FOO: define void @_Z7foo_extv()
-FOO-NOT: {{define|declare}}
 FOO: define weak_odr void @_Z3foov() #{{[0-9]+}} comdat
 FOO-NOT: {{define|declare}}
 FOO: declare void @_Z2f1Ri(i32*
@@ -31,26 +29,37 @@
 
 FOO: define weak_odr void @_Z4foo2v() #{{[0-9]+}} comdat
 FOO-NOT: {{define|declare}}
+FOO: define void @_Z7foo_extv()
+FOO-NOT: {{define|declare}}
 
 
-BAR-CMN-NOT: comdat
+BAR-CMN-NOT: {{comdat|module asm}}
 BAR-CMN: $_Z3barv = comdat any
+BAR-CMN-NOT: comdat
+BAR-OPT: $_ZZ3foovE1i = comdat any
+BAR-OPT-NOT: comdat
 BAR-OPT: @_ZZ3foovE1i = linkonce_odr global i32 0, comdat
-BAR-CMN-NOT: {{comdat|define|declare}}
+BAR-CMN-NOT: {{define|declare}}
 BAR-CMN: define weak_odr void @_Z3barv() #{{[0-9]+}} comdat
 BAR-CMN-NOT: {{define|declare}}
 BAR: declare void @_Z3foov()
+BAR-NOT: {{define|declare}}
 Include all the available_externally definitions required for bar (foo -> f2)
 BAR-OPT: define available_externally void @_Z3foov()
-BAR-CMN-NOT: {{define|declare}}
+BAR-OPT-NOT: {{define|declare}}
 BAR-OPT: declare void @_Z2f1Ri(i32*
 BAR-OPT-NOT: {{define|declare}}
 BAR-OPT: define available_externally void @_ZL2f2v()
 BAR-OPT-NOT: {{define|declare}}
 
 
+USE-CMN-NOT: {{comdat|module asm}}
+USE-CMN: module asm ".byte 42"
+USE-CMN-NOT: {{comdat|module asm}}
+USE-OPT: $_ZZ3foovE1i = comdat any
+USE-OPT-CMN-NOT: {{comdat}}
 USE-OPT: @_ZZ3foovE1i = linkonce_odr global i32 0, comdat
-USE-CMN-NOT: {{comdat|define|declare}}
+USE-CMN-NOT: {{define|declare}}
 USE-CMN: define i32 @main()
 USE-CMN-NOT: {{define|declare}}
 USE: declare void @_Z3barv()
Index: test/Modules/Inputs/codegen/foo.h
===
--- test/Modules/Inputs/codegen/foo.h
+++ test/Modules/Inputs/codegen/foo.h
@@ -1,3 +1,4 @@
+asm(".byte 42");
 void f1(int &);
 static void f2() {}
 inline void foo() {
Index: test/CodeGenCXX/modul

Re: Add warning for c++ member variable shadowing

2017-02-01 Thread Richard Smith via cfe-commits
+  std::set bases;
+const auto baseName =
Specifier->getType()->getAsCXXRecordDecl()->getName();

Please capitalize local variable names. Also, please don't use the record
name as a key in your set; that's not guaranteed to be unique. Instead, you
could either use a set of canonical types or of canonical CXXRecordDecl*s.

+for (const auto *Field :
Specifier->getType()->getAsCXXRecordDecl()->fields()) {
+  if ((Field->getAccess() == AS_public || Field->getAccess() ==
AS_protected) &&
+  Field->getName() == FieldName) {

Use Specifier->getType()->getAsCXXRecordDecl()->lookup(Field->getName())
here to look up the field by name, rather than walking all the fields of
all base classes and checking if each of them has the right name. You
should also check for IndirectFieldDecls, for this case:

  struct A {
union { int x; float f; };
  };
  struct B : A {
int x;
  };

+bases.emplace(baseName);

It's more efficient to use insert rather than emplace when inserting an
element into a set.

+Diag(Loc, diag::warn_shadow_field)
+  << FieldName << RD->getName() << baseName;

It'd be nice to add a note here pointing at the base class member that was
shadowed.



On 31 January 2017 at 19:20, James Sun  wrote:

> Fixed!
>
>
>
> *From: *Saleem Abdulrasool 
> *Date: *Tuesday, January 31, 2017 at 6:53 PM
>
> *To: *James Sun 
> *Cc: *Richard Smith , "cfe-commits@lists.llvm.org"
> , Aaron Ballman 
> *Subject: *Re: Add warning for c++ member variable shadowing
>
>
>
> Hmm, the braces in the if (bases.find(...)...) are not needed.
>
>
>
> Could you also add a test case for virtual inheritance?
>
>
>
> On Mon, Jan 30, 2017 at 8:34 PM, James Sun  wrote:
>
> Hi Saleem
>
>
>
> Thanks for the quick response. A test case is added. It covers some
> ordinary cases as well as corner cases like multiple paths to the same base.
>
>
>
> Thanks
>
>
>
> James
>
>
>
> *From: *Saleem Abdulrasool 
> *Date: *Monday, January 30, 2017 at 6:50 PM
> *To: *James Sun 
> *Cc: *Richard Smith , "cfe-commits@lists.llvm.org"
> , Aaron Ballman 
>
>
> *Subject: *Re: Add warning for c++ member variable shadowing
>
>
>
> I think that the patch is starting to look pretty good!
>
>
>
> Can you add some test cases for the particular cases to diagnose in a
> separate test set to ensure that we have proper coverage of the various
> cases rather than relying on the existing test cases?  Something to make
> sure that we get the simple case right as well as the complex cases (e.g.
> we don't print duplicate warnings for multiple paths).
>
>
>
>
>
> On Mon, Jan 30, 2017 at 5:50 PM, James Sun  wrote:
>
> Hi Richard
>
>
>
> Sorry for the late reply. Thank you for giving the feedback! The updated
> version is attached. Please let me know if there is anything improper.
>
>
>
> Thanks
>
>
>
> James
>
>
>
> *From: * on behalf of Richard Smith <
> rich...@metafoo.co.uk>
> *Date: *Friday, January 27, 2017 at 3:03 PM
> *To: *James Sun 
> *Cc: *Saleem Abdulrasool , "
> cfe-commits@lists.llvm.org" , Aaron Ballman <
> aa...@aaronballman.com>
>
>
> *Subject: *Re: Add warning for c++ member variable shadowing
>
>
>
> +def warn_shadow_member_variable : Warning<
>
> +  "shadowed variable '%0' in type '%1' inheriting from type '%2'">,
>
>
>
> The phrasing of this is incorrect: the things you're warning about are not
> variables, they're non-static data members. Perhaps something like:
>
>
>
>   "non-static data member '%0' of '%1' shadows member inherited from type
> '%2'"
>
>
>
> +   InGroup;
>
>
>
> Would it make sense to put this in a subgroup of -Wshadow so that it can
> be controlled separately?
>
>
>
> +  /// Check if there is a member variable shadowing
>
>
>
> Please end comments in a period.
>
>
>
> +  void CheckShadowInheritedVariables(const SourceLocation &Loc,
>
>
>
> Likewise, 'Variables' is wrong. We would typically use the C term 'Fields'
> for these cases within Clang sources.
>
>
>
> +  for (const auto &Base : DC->bases()) {
>
> +if (const auto *TSI = Base.getTypeSourceInfo())
>
> +  if (const auto *BaseClass = TSI->getType()->getAsCXXRecordDecl()) {
>
> +for (const auto *Field : BaseClass->fields())
>
> +  if (Field->getName() == FieldName)
>
> +Diag(Loc, diag::warn_shadow_member_variable)
>
> +  << FieldName << RD->getName() << BaseClass->getName();
>
> +// Search parent's parents
>
> +CheckShadowInheritedVariables(Loc, FieldName, RD, BaseClass);
>
> +  }
>
> +  }
>
>
>
> Maybe we should avoid diagnosing shadowing of members that are
> inaccessible from the derived class? What about if the field name is
> ambiguous? Also, we shouldn't recurse if lookup finds something with the
> given name in this class, and ideally we would only visit each class once,
> even if it appears multiple times in a multiple-inheritance scenario.
> CXXRecordDecl::lookupInBases can handle most of these cases for you
> automatically, and will also let you build a set of paths t

[PATCH] D29432: Modular Codegen: Emit inline asm into users, not modular objects

2017-02-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Oh, one of the reasons I was sort of compelled to keep the 'classic' AST file 
compilation working was that when looking at the change history of the test 
cases exercising it I found that some changes had been motivated by a filed 
LLVM bug: https://llvm.org/bugs/show_bug.cgi?id=15377 - so I guess someone 
might've been trying to use it at some point?


https://reviews.llvm.org/D29432



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29369: [ubsan] Omit superflous overflow checks for promoted arithmetic (PR20193)

2017-02-01 Thread Vedant Kumar via Phabricator via cfe-commits
vsk updated this revision to Diff 86746.
vsk edited the summary of this revision.
vsk added a comment.

- Remove a stale test case in unsigned-promotion.c.


https://reviews.llvm.org/D29369

Files:
  lib/CodeGen/CGExprScalar.cpp
  test/CodeGen/compound-assign-overflow.c
  test/CodeGen/ubsan-promoted-arith.cpp
  test/CodeGen/unsigned-promotion.c

Index: test/CodeGen/unsigned-promotion.c
===
--- test/CodeGen/unsigned-promotion.c
+++ test/CodeGen/unsigned-promotion.c
@@ -7,53 +7,6 @@
 // RUN:   -fsanitize=unsigned-integer-overflow | FileCheck %s --check-prefix=CHECKU
 
 unsigned short si, sj, sk;
-unsigned char ci, cj, ck;
-
-extern void opaqueshort(unsigned short);
-extern void opaquechar(unsigned char);
-
-// CHECKS-LABEL:   define void @testshortadd()
-// CHECKU-LABEL: define void @testshortadd()
-void testshortadd() {
-  // CHECKS:load i16, i16* @sj
-  // CHECKS:load i16, i16* @sk
-  // CHECKS:[[T1:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T2:%.*]], i32 [[T3:%.*]])
-  // CHECKS-NEXT:   [[T4:%.*]] = extractvalue { i32, i1 } [[T1]], 0
-  // CHECKS-NEXT:   [[T5:%.*]] = extractvalue { i32, i1 } [[T1]], 1
-  // CHECKS:call void @__ubsan_handle_add_overflow
-  //
-  // CHECKU:  [[T1:%.*]] = load i16, i16* @sj
-  // CHECKU:  [[T2:%.*]] = zext i16 [[T1]]
-  // CHECKU:  [[T3:%.*]] = load i16, i16* @sk
-  // CHECKU:  [[T4:%.*]] = zext i16 [[T3]]
-  // CHECKU-NOT:  llvm.sadd
-  // CHECKU-NOT:  llvm.uadd
-  // CHECKU:  [[T5:%.*]] = add nsw i32 [[T2]], [[T4]]
-
-  si = sj + sk;
-}
-
-// CHECKS-LABEL:   define void @testshortsub()
-// CHECKU-LABEL: define void @testshortsub()
-void testshortsub() {
-
-  // CHECKS:load i16, i16* @sj
-  // CHECKS:load i16, i16* @sk
-  // CHECKS:[[T1:%.*]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 [[T2:%.*]], i32 [[T3:%.*]])
-  // CHECKS-NEXT:   [[T4:%.*]] = extractvalue { i32, i1 } [[T1]], 0
-  // CHECKS-NEXT:   [[T5:%.*]] = extractvalue { i32, i1 } [[T1]], 1
-  // CHECKS:call void @__ubsan_handle_sub_overflow
-  //
-  // CHECKU:  [[T1:%.*]] = load i16, i16* @sj
-  // CHECKU:  [[T2:%.*]] = zext i16 [[T1]]
-  // CHECKU:  [[T3:%.*]] = load i16, i16* @sk
-  // CHECKU:  [[T4:%.*]] = zext i16 [[T3]]
-  // CHECKU-NOT:  llvm.ssub
-  // CHECKU-NOT:  llvm.usub
-  // CHECKU:  [[T5:%.*]] = sub nsw i32 [[T2]], [[T4]]
-
-  si = sj - sk;
-}
 
 // CHECKS-LABEL:   define void @testshortmul()
 // CHECKU-LABEL: define void @testshortmul()
@@ -75,69 +28,3 @@
   // CHECKU:  [[T5:%.*]] = mul nsw i32 [[T2]], [[T4]]
   si = sj * sk;
 }
-
-// CHECKS-LABEL:   define void @testcharadd()
-// CHECKU-LABEL: define void @testcharadd()
-void testcharadd() {
-
-  // CHECKS:load i8, i8* @cj
-  // CHECKS:load i8, i8* @ck
-  // CHECKS:[[T1:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 [[T2:%.*]], i32 [[T3:%.*]])
-  // CHECKS-NEXT:   [[T4:%.*]] = extractvalue { i32, i1 } [[T1]], 0
-  // CHECKS-NEXT:   [[T5:%.*]] = extractvalue { i32, i1 } [[T1]], 1
-  // CHECKS:call void @__ubsan_handle_add_overflow
-  //
-  // CHECKU:  [[T1:%.*]] = load i8, i8* @cj
-  // CHECKU:  [[T2:%.*]] = zext i8 [[T1]]
-  // CHECKU:  [[T3:%.*]] = load i8, i8* @ck
-  // CHECKU:  [[T4:%.*]] = zext i8 [[T3]]
-  // CHECKU-NOT:  llvm.sadd
-  // CHECKU-NOT:  llvm.uadd
-  // CHECKU:  [[T5:%.*]] = add nsw i32 [[T2]], [[T4]]
-
-  ci = cj + ck;
-}
-
-// CHECKS-LABEL:   define void @testcharsub()
-// CHECKU-LABEL: define void @testcharsub()
-void testcharsub() {
-
-  // CHECKS:load i8, i8* @cj
-  // CHECKS:load i8, i8* @ck
-  // CHECKS:[[T1:%.*]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 [[T2:%.*]], i32 [[T3:%.*]])
-  // CHECKS-NEXT:   [[T4:%.*]] = extractvalue { i32, i1 } [[T1]], 0
-  // CHECKS-NEXT:   [[T5:%.*]] = extractvalue { i32, i1 } [[T1]], 1
-  // CHECKS:call void @__ubsan_handle_sub_overflow
-  //
-  // CHECKU:  [[T1:%.*]] = load i8, i8* @cj
-  // CHECKU:  [[T2:%.*]] = zext i8 [[T1]]
-  // CHECKU:  [[T3:%.*]] = load i8, i8* @ck
-  // CHECKU:  [[T4:%.*]] = zext i8 [[T3]]
-  // CHECKU-NOT:  llvm.ssub
-  // CHECKU-NOT:  llvm.usub
-  // CHECKU:  [[T5:%.*]] = sub nsw i32 [[T2]], [[T4]]
-
-  ci = cj - ck;
-}
-
-// CHECKS-LABEL:   define void @testcharmul()
-// CHECKU-LABEL: define void @testcharmul()
-void testcharmul() {
-
-  // CHECKS:load i8, i8* @cj
-  // CHECKS:load i8, i8* @ck
-  // CHECKS:[[T1:%.*]] = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 [[T2:%.*]], i32 [[T3:%.*]])
-  // CHECKS-NEXT:   [[T4:%.*]] = extractvalue { i32, i1 } [[T1]], 0
-  // CHECKS-NEXT:   [[T5:%.*]] = extractvalue { i32, i1 } [[T1]], 1
-  // CHECKS:call void @__ubsan_handle_mul_overflow
-  //
-  // CHECKU:  [[T1:%.*]] = load i8, i8* @cj
-  // CHECKU:  [[T2:%.*]] = zext i8 [[T1]]
-  // CHECKU:  [[T3:%.*]] = loa

[clang-tools-extra] r293845 - [clang-tidy] misc-argument-comment support for gmock

2017-02-01 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Feb  1 18:37:08 2017
New Revision: 293845

URL: http://llvm.org/viewvc/llvm-project?rev=293845&view=rev
Log:
[clang-tidy] misc-argument-comment support for gmock

Modified:
clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp?rev=293845&r1=293844&r2=293845&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp Wed Feb  1 
18:37:08 2017
@@ -179,6 +179,21 @@ void ArgumentCommentCheck::checkCallArgs
   }
 }
 
+static const FunctionDecl *resolveMocks(const MatchFinder::MatchResult &Result,
+const FunctionDecl *Func) {
+  if (auto *Method = dyn_cast(Func)) {
+if (Method->getLocation().isMacroID() &&
+Lexer::getImmediateMacroName(Method->getLocation(),
+ *Result.SourceManager,
+ Result.Context->getLangOpts())
+.contains("MOCK_METHOD") &&
+Method->size_overridden_methods() != 0) {
+  Func = *Method->begin_overridden_methods();
+}
+  }
+  return Func;
+}
+
 void ArgumentCommentCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *E = Result.Nodes.getNodeAs("expr");
   if (const auto *Call = dyn_cast(E)) {
@@ -186,6 +201,8 @@ void ArgumentCommentCheck::check(const M
 if (!Callee)
   return;
 
+Callee = resolveMocks(Result, Callee);
+
 checkCallArgs(Result.Context, Callee, Call->getCallee()->getLocEnd(),
   llvm::makeArrayRef(Call->getArgs(), Call->getNumArgs()));
   } else {

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp?rev=293845&r1=293844&r2=293845&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-argument-comment.cpp Wed Feb  
1 18:37:08 2017
@@ -53,3 +53,59 @@ void f(bool _with_underscores_);
 void ignores_underscores() {
   f(/*With_Underscores=*/false);
 }
+
+// gmock
+namespace testing {
+namespace internal {
+
+template 
+struct Function;
+
+template 
+struct Function {
+  typedef R Result;
+};
+
+template 
+struct Function
+: Function {
+  typedef A1 Argument1;
+};
+
+template 
+struct Function
+: Function {
+  typedef A2 Argument2;
+};
+} // namespace internal
+} // namespace testing
+
+#define GMOCK_RESULT_(tn, ...) \
+tn ::testing::internal::Function<__VA_ARGS__>::Result
+#define GMOCK_ARG_(tn, N, ...) \
+tn ::testing::internal::Function<__VA_ARGS__>::Argument##N
+#define GMOCK_METHOD2_(tn, constness, ct, Method, ...) \
+  GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
+  GMOCK_ARG_(tn, 1, __VA_ARGS__) gmock_a1, \
+  GMOCK_ARG_(tn, 2, __VA_ARGS__) gmock_a2) constness
+#define MOCK_METHOD2(m, ...) GMOCK_METHOD2_(, , , m, __VA_ARGS__)
+
+class Base {
+ public:
+  virtual void Method(int param_one_base, int param_two_base);
+};
+class Derived : public Base {
+ public:
+  virtual void Method(int param_one, int param_two);
+};
+class MockDerived : public Derived {
+ public:
+  MOCK_METHOD2(Method, void(int, int));
+};
+
+void test_gmock() {
+  MockDerived m;
+  m.Method(/*param_one=*/1, /*param_tw=*/2);
+// CHECK-MESSAGES: [[@LINE-1]]:29: warning: argument name 'param_tw' in 
comment does not match parameter name 'param_two'
+// CHECK-FIXES:   m.Method(/*param_one=*/1, /*param_two=*/2);
+}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293848 - [CodeGen] Update test after recent changes in llvm (r293846).

2017-02-01 Thread Davide Italiano via cfe-commits
Author: davide
Date: Wed Feb  1 18:47:53 2017
New Revision: 293848

URL: http://llvm.org/viewvc/llvm-project?rev=293848&view=rev
Log:
[CodeGen] Update test after recent changes in llvm (r293846).

Modified:
cfe/trunk/test/CodeGen/link-bitcode-file.c

Modified: cfe/trunk/test/CodeGen/link-bitcode-file.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/link-bitcode-file.c?rev=293848&r1=293847&r2=293848&view=diff
==
--- cfe/trunk/test/CodeGen/link-bitcode-file.c (original)
+++ cfe/trunk/test/CodeGen/link-bitcode-file.c Wed Feb  1 18:47:53 2017
@@ -27,7 +27,7 @@ int f2(void) { return 43; }
 #else
 
 // CHECK-NO-BC-LABEL: define i32 @g
-// CHECK-NO-BC: ret i32 %call
+// CHECK-NO-BC: ret i32 42
 int g(void) {
   return f();
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29208: Prevent ICE in dllexport class with _Atomic() data member

2017-02-01 Thread Warren Ristow via Phabricator via cfe-commits
wristow added inline comments.



Comment at: lib/CodeGen/CGClass.cpp:1135
 MemberExpr *ME2 = dyn_cast(RHS);
-if (dyn_cast(ME2->getMemberDecl()) != Field)
+if (!ME2 || dyn_cast(ME2->getMemberDecl()) != Field)
   return nullptr;

rjmccall wrote:
> I would prefer:
> 
>   if (MemberExpr *ME2 = dyn_cast(RHS)) {
> if (ME2->getMemberDecl() == Field)
>   return Field;
>   }
>   return nullptr;
I see that change removes the `dyn_cast`.  Was that intended, or an 
oversight?

In terms of changing the code-structure, in code on it's own, I do like the 
approach you described.  But in this case, there is a sequence of `if 
() return nullptr; ... if (conditionN) return nullptr; return 
Field;`.  Then after the block containing that set of guarded `nullptr` returns 
with a final `return Field;`, there is a similar block.  And then there is a 
third block with a similar set.  So changing the structure in that way breaks 
that pattern.  With that in mind, do you still want that change done?


https://reviews.llvm.org/D29208



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29208: Prevent ICE in dllexport class with _Atomic() data member

2017-02-01 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGClass.cpp:1135
 MemberExpr *ME2 = dyn_cast(RHS);
-if (dyn_cast(ME2->getMemberDecl()) != Field)
+if (!ME2 || dyn_cast(ME2->getMemberDecl()) != Field)
   return nullptr;

wristow wrote:
> rjmccall wrote:
> > I would prefer:
> > 
> >   if (MemberExpr *ME2 = dyn_cast(RHS)) {
> > if (ME2->getMemberDecl() == Field)
> >   return Field;
> >   }
> >   return nullptr;
> I see that change removes the `dyn_cast`.  Was that intended, or 
> an oversight?
> 
> In terms of changing the code-structure, in code on it's own, I do like the 
> approach you described.  But in this case, there is a sequence of `if 
> () return nullptr; ... if (conditionN) return nullptr; return 
> Field;`.  Then after the block containing that set of guarded `nullptr` 
> returns with a final `return Field;`, there is a similar block.  And then 
> there is a third block with a similar set.  So changing the structure in that 
> way breaks that pattern.  With that in mind, do you still want that change 
> done?
The dyn_cast has no effect.  There is no situation in which the declarations 
would compare equal without it where they would not with it, because Field is 
already known to be a FieldDecl.

The structure of the existing code is unlikely to stay the same.  Actually, 
that code is quite worrying — it's making a lot of assumptions about how Sema 
synthesizes defaulted assignment operator bodies.  But I didn't want to ask you 
to fix it when it's not the subject of your bug.


https://reviews.llvm.org/D29208



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293853 - Fix attribute name in diagnostic message to match actual attribute name.

2017-02-01 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Feb  1 19:50:47 2017
New Revision: 293853

URL: http://llvm.org/viewvc/llvm-project?rev=293853&view=rev
Log:
Fix attribute name in diagnostic message to match actual attribute name.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/test/SemaCXX/attr-require-constant-initialization.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=293853&r1=293852&r2=293853&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Feb  1 19:50:47 
2017
@@ -7041,7 +7041,7 @@ def err_incomplete_type_used_in_type_tra
 def err_require_constant_init_failed : Error<
   "variable does not have a constant initializer">;
 def note_declared_required_constant_init_here : Note<
-  "required by 'require_constant_initializer' attribute here">;
+  "required by 'require_constant_initialization' attribute here">;
 
 def err_dimension_expr_not_constant_integer : Error<
   "dimension expression does not evaluate to a constant unsigned int">;

Modified: cfe/trunk/test/SemaCXX/attr-require-constant-initialization.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-require-constant-initialization.cpp?rev=293853&r1=293852&r2=293853&view=diff
==
--- cfe/trunk/test/SemaCXX/attr-require-constant-initialization.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-require-constant-initialization.cpp Wed Feb  1 
19:50:47 2017
@@ -81,16 +81,16 @@ ATTR __thread const int &glvalue_ref_tl
 void test_basic_start_static_2_1() {
   const int non_global = 42;
   ATTR static const int &local_init = non_global; // expected-error {{variable 
does not have a constant initializer}}
-  // expected-note@-1 {{required by 'require_constant_initializer' attribute 
here}}
+  // expected-note@-1 {{required by 'require_constant_initialization' 
attribute here}}
   ATTR static const int &global_init = glvalue_int;
   ATTR static const int &temp_init = 42;
 }
 
 ATTR const int &temp_ref = 42;
 ATTR const int &temp_ref2 = ReturnInt(); // expected-error {{variable does not 
have a constant initializer}}
-// expected-note@-1 {{required by 'require_constant_initializer' attribute 
here}}
+// expected-note@-1 {{required by 'require_constant_initialization' attribute 
here}}
 ATTR const NonLit &nl_temp_ref = 42; // expected-error {{variable does not 
have a constant initializer}}
-// expected-note@-1 {{required by 'require_constant_initializer' attribute 
here}}
+// expected-note@-1 {{required by 'require_constant_initialization' attribute 
here}}
 
 #if __cplusplus >= 201103L
 ATTR const LitType &lit_temp_ref = 42;
@@ -98,7 +98,7 @@ ATTR const int &subobj_ref = LitType{}.v
 #endif
 
 ATTR const int &nl_subobj_ref = NonLit().value; // expected-error {{variable 
does not have a constant initializer}}
-// expected-note@-1 {{required by 'require_constant_initializer' attribute 
here}}
+// expected-note@-1 {{required by 'require_constant_initialization' attribute 
here}}
 
 struct TT1 {
   ATTR static const int &no_init;
@@ -107,7 +107,7 @@ struct TT1 {
   ATTR static const int &subobj_init;
 #if __cplusplus >= 201103L
   ATTR static thread_local const int &tl_glvalue_init;
-  ATTR static thread_local const int &tl_temp_init; // expected-note 
{{required by 'require_constant_initializer' attribute here}}
+  ATTR static thread_local const int &tl_temp_init; // expected-note 
{{required by 'require_constant_initialization' attribute here}}
 #endif
 };
 const int &TT1::glvalue_init = glvalue_int;
@@ -128,18 +128,18 @@ void test_basic_start_static_2_2() {
   ATTR static PODType pod;
 #else
   ATTR static PODType pod; // expected-error {{variable does not have a 
constant initializer}}
-// expected-note@-1 {{required by 'require_constant_initializer' attribute 
here}}
+// expected-note@-1 {{required by 'require_constant_initialization' attribute 
here}}
 #endif
   ATTR static PODType pot2 = {ReturnInt()}; // expected-error {{variable does 
not have a constant initializer}}
-// expected-note@-1 {{required by 
'require_constant_initializer' attribute here}}
+// expected-note@-1 {{required by 
'require_constant_initialization' attribute here}}
 
 #if __cplusplus >= 201103L
   constexpr LitType l;
   ATTR static LitType static_lit = l;
   ATTR static LitType static_lit2 = (void *)0; // expected-error {{variable 
does not have a constant initializer}}
-  // expected-note@-1 {{required by 'require_constant_initializer' attribute 
here}}
+  // expected-note@-1 {{required by 'require_constant_initialization' 
attribute here}}
   ATTR static LitType static_lit3 = ReturnInt(); // expected-error 

[PATCH] D29437: [ubsan] Detect signed overflow UB in remainder operations

2017-02-01 Thread Vedant Kumar via Phabricator via cfe-commits
vsk created this revision.

Teach ubsan to diagnose remainder operations which have undefined behavior due 
to signed overflow.

My copy of the C11 spec draft (6.5.5.6) says that: if the quotient a/b is 
representable, (a/b)*b + a%b shall equal a; otherwise, the behavior of both a/b 
and a%b is undefined. I take this to mean INT_MIN % -1 has signed overflow UB, 
so we should check for that.

Loosely depends on: https://reviews.llvm.org/D29369


https://reviews.llvm.org/D29437

Files:
  lib/CodeGen/CGExprScalar.cpp
  test/CodeGen/ubsan-promoted-arith.cpp


Index: test/CodeGen/ubsan-promoted-arith.cpp
===
--- test/CodeGen/ubsan-promoted-arith.cpp
+++ test/CodeGen/ubsan-promoted-arith.cpp
@@ -101,12 +101,14 @@
 // CHECK-NOT: ubsan_handle_divrem_overflow
 uchar rem2(uchar uc) { return uc % uc; }
 
-// FIXME: This is a long-standing false negative.
-//
 // CHECK-LABEL: define signext i8 @_Z4rem3
-// rdar30301609: ubsan_handle_divrem_overflow
+// CHECK: ubsan_handle_divrem_overflow
 char rem3(int i, char c) { return i % c; }
 
+// CHECK-LABEL: define signext i8 @_Z4rem4
+// CHECK-NOT: ubsan_handle_divrem_overflow
+char rem4(char c, int i) { return c % i; }
+
 // CHECK-LABEL: define signext i8 @_Z4inc1
 // CHECK-NOT: sadd.with.overflow
 char inc1(char c) { return c++ + (char)0; }
Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -2375,12 +2375,12 @@
 
 Value *ScalarExprEmitter::EmitRem(const BinOpInfo &Ops) {
   // Rem in C can't be a floating point type: C99 6.5.5p2.
-  if (CGF.SanOpts.has(SanitizerKind::IntegerDivideByZero)) {
+  if ((CGF.SanOpts.has(SanitizerKind::IntegerDivideByZero) ||
+   CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow)) &&
+  Ops.Ty->isIntegerType()) {
 CodeGenFunction::SanitizerScope SanScope(&CGF);
 llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty));
-
-if (Ops.Ty->isIntegerType())
-  EmitUndefinedBehaviorIntegerDivAndRemCheck(Ops, Zero, false);
+EmitUndefinedBehaviorIntegerDivAndRemCheck(Ops, Zero, false);
   }
 
   if (Ops.Ty->hasUnsignedIntegerRepresentation())


Index: test/CodeGen/ubsan-promoted-arith.cpp
===
--- test/CodeGen/ubsan-promoted-arith.cpp
+++ test/CodeGen/ubsan-promoted-arith.cpp
@@ -101,12 +101,14 @@
 // CHECK-NOT: ubsan_handle_divrem_overflow
 uchar rem2(uchar uc) { return uc % uc; }
 
-// FIXME: This is a long-standing false negative.
-//
 // CHECK-LABEL: define signext i8 @_Z4rem3
-// rdar30301609: ubsan_handle_divrem_overflow
+// CHECK: ubsan_handle_divrem_overflow
 char rem3(int i, char c) { return i % c; }
 
+// CHECK-LABEL: define signext i8 @_Z4rem4
+// CHECK-NOT: ubsan_handle_divrem_overflow
+char rem4(char c, int i) { return c % i; }
+
 // CHECK-LABEL: define signext i8 @_Z4inc1
 // CHECK-NOT: sadd.with.overflow
 char inc1(char c) { return c++ + (char)0; }
Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -2375,12 +2375,12 @@
 
 Value *ScalarExprEmitter::EmitRem(const BinOpInfo &Ops) {
   // Rem in C can't be a floating point type: C99 6.5.5p2.
-  if (CGF.SanOpts.has(SanitizerKind::IntegerDivideByZero)) {
+  if ((CGF.SanOpts.has(SanitizerKind::IntegerDivideByZero) ||
+   CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow)) &&
+  Ops.Ty->isIntegerType()) {
 CodeGenFunction::SanitizerScope SanScope(&CGF);
 llvm::Value *Zero = llvm::Constant::getNullValue(ConvertType(Ops.Ty));
-
-if (Ops.Ty->isIntegerType())
-  EmitUndefinedBehaviorIntegerDivAndRemCheck(Ops, Zero, false);
+EmitUndefinedBehaviorIntegerDivAndRemCheck(Ops, Zero, false);
   }
 
   if (Ops.Ty->hasUnsignedIntegerRepresentation())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24933: Enable configuration files in clang

2017-02-01 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 86761.
sepavloff added a comment.
Herald added a subscriber: danalbert.

Updated patch

Use more robust algorithm to determine custom compiler prefix.
Bring the code in sync with changes in llvm patch.


https://reviews.llvm.org/D24933

Files:
  docs/UsersManual.rst
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Config/config.h.cmake
  include/clang/Driver/Driver.h
  include/clang/Driver/ToolChain.h
  lib/Driver/Driver.cpp
  lib/Driver/ToolChain.cpp
  test/Driver/Inputs/config-1.cfg
  test/Driver/Inputs/config-2.cfg
  test/Driver/Inputs/config-2a.cfg
  test/Driver/Inputs/config-3.cfg
  test/Driver/Inputs/config-4.cfg
  test/Driver/Inputs/config-5.cfg
  test/Driver/Inputs/config/config-4.cfg
  test/Driver/config-file.c
  test/Driver/config-file2.c
  test/Driver/lit.local.cfg
  tools/driver/driver.cpp

Index: tools/driver/driver.cpp
===
--- tools/driver/driver.cpp
+++ tools/driver/driver.cpp
@@ -305,6 +305,16 @@
   return 1;
 }
 
+// Directories searched for configuration specified by option '--config'.
+static const ArrayRef SearchDirs = {
+#if defined(CLANG_CONFIG_FILE_USER_DIR)
+  CLANG_CONFIG_FILE_USER_DIR,
+#endif
+#if defined(CLANG_CONFIG_FILE_SYSTEM_DIR)
+  CLANG_CONFIG_FILE_SYSTEM_DIR
+#endif
+};
+
 int main(int argc_, const char **argv_) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv_[0]);
   llvm::PrettyStackTraceProgram X(argc_, argv_);
@@ -325,11 +335,45 @@
   llvm::InitializeAllTargets();
   std::string ProgName = argv[0];
   std::pair TargetAndMode =
-  ToolChain::getTargetAndModeFromProgramName(ProgName);
+  ToolChain::getTargetAndModeFromProgramName(ProgName, false);
 
   llvm::BumpPtrAllocator A;
   llvm::StringSaver Saver(A);
 
+  // Try reading options from configuration file.
+  llvm::SmallString<128> ConfigFile;
+  bool CfgFound;
+  std::string ErrText;
+
+  // First try config file specified in command line. It has higher priority
+  // than any other way to specify configuration.
+  CfgFound = llvm::cl::findConfigFile(ConfigFile, argv, SearchDirs, true,
+  ErrText);
+  if (!CfgFound && !ErrText.empty()) {
+llvm::errs() << ProgName << ": CommandLine Error :" << ErrText << '\n';
+return 1;
+  }
+
+  // If config file is not specified explicitly, try to determine configuration
+  // implicitly. First try to deduce configuration from executable name. For
+  // instance, a file 'armv7l-clang' applies config file 'armv7l.cfg'.
+  if (!CfgFound && !TargetAndMode.first.empty()) {
+CfgFound = llvm::cl::searchForFile(ConfigFile, SearchDirs, ProgName,
+   TargetAndMode.first + ".cfg");
+TargetAndMode.first.clear();
+  }
+
+  // If config file is found, read options from it.
+  unsigned NumConfigOptions = 0;
+  if (CfgFound) {
+if (!llvm::cl::readConfigFile(ConfigFile, Saver, argv, NumConfigOptions)) {
+  llvm::errs() << ProgName <<
+": CommandLine Error : Cannot read configuration file '" <<
+ConfigFile.c_str() << "'\n";
+  return 1;
+}
+  }
+
   // Parse response files using the GNU syntax, unless we're in CL mode. There
   // are two ways to put clang in CL compatibility mode: argv[0] is either
   // clang-cl or cl, or --driver-mode=cl is on the command line. The normal
@@ -400,8 +444,12 @@
   SmallVector PrependedOpts;
   getCLEnvVarOptions(OptCL.getValue(), Saver, PrependedOpts);
 
-  // Insert right after the program name to prepend to the argument list.
-  argv.insert(argv.begin() + 1, PrependedOpts.begin(), PrependedOpts.end());
+  // Insert right after the program name to prepend to the argument list. If
+  // there are options read from config file, put the options from "CL"
+  // after them, - config file is considered as a "patch" to compiler
+  // defaults.
+  argv.insert(argv.begin() + 1 + NumConfigOptions,
+  PrependedOpts.begin(), PrependedOpts.end());
 }
 // Arguments in "_CL_" are appended.
 llvm::Optional Opt_CL_ = llvm::sys::Process::GetEnv("_CL_");
@@ -446,6 +494,8 @@
   ProcessWarningOptions(Diags, *DiagOpts, /*ReportDiags=*/false);
 
   Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags);
+  if (!ConfigFile.empty())
+TheDriver.setConfigFile(ConfigFile.str(), NumConfigOptions);
   SetInstallDir(argv, TheDriver, CanonicalPrefixes);
 
   insertTargetAndModeArgs(TargetAndMode.first, TargetAndMode.second, argv,
Index: test/Driver/lit.local.cfg
===
--- test/Driver/lit.local.cfg
+++ test/Driver/lit.local.cfg
@@ -4,6 +4,8 @@
 config.substitutions.insert(0,
 ('%clang_cc1',
  """*** Do not use 'clang -cc1' in Driver tests. ***""") )
+config.substitutions.append( ('%bindir',
+  os.path.dirname(config.clang)) )
 
 # Remove harmful environmental variables for cl

[PATCH] D29369: [ubsan] Omit superflous overflow checks for promoted arithmetic (PR20193)

2017-02-01 Thread John Regehr via Phabricator via cfe-commits
regehr added a comment.

Out of curiosity, how many of these superfluous checks are not subsequently 
eliminated by InstCombine?


https://reviews.llvm.org/D29369



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29437: [ubsan] Detect signed overflow UB in remainder operations

2017-02-01 Thread John Regehr via Phabricator via cfe-commits
regehr added a comment.

Does this check need to be sensitive to the dialect of C/C++ that the user 
asked for? I know that it used to be the case that the standard could be read 
either way for this case, but as you observe it is now unambiguously UB.


https://reviews.llvm.org/D29437



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293863 - Modules: Simplify CompilerInstance constructor, NFC

2017-02-01 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Wed Feb  1 23:09:51 2017
New Revision: 293863

URL: http://llvm.org/viewvc/llvm-project?rev=293863&view=rev
Log:
Modules: Simplify CompilerInstance constructor, NFC

Initialize fields directly in header.  Note that the ModuleManager field is an
IntrusiveRefCntPtr, so there's no need for explicit initialization.

Modified:
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/lib/Frontend/CompilerInstance.cpp

Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=293863&r1=293862&r2=293863&view=diff
==
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Wed Feb  1 23:09:51 2017
@@ -142,13 +142,13 @@ class CompilerInstance : public ModuleLo
 
   /// \brief Whether we should (re)build the global module index once we
   /// have finished with this translation unit.
-  bool BuildGlobalModuleIndex;
+  bool BuildGlobalModuleIndex = false;
 
   /// \brief We have a full global module index, with all modules.
-  bool HaveFullGlobalModuleIndex;
+  bool HaveFullGlobalModuleIndex = false;
 
   /// \brief One or more modules failed to build.
-  bool ModuleBuildFailed;
+  bool ModuleBuildFailed = false;
 
   /// \brief Holds information about the output file.
   ///

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=293863&r1=293862&r2=293863&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Wed Feb  1 23:09:51 2017
@@ -57,10 +57,7 @@ CompilerInstance::CompilerInstance(
 std::shared_ptr PCHContainerOps,
 bool BuildingModule)
 : ModuleLoader(BuildingModule), Invocation(new CompilerInvocation()),
-  ModuleManager(nullptr),
-  ThePCHContainerOperations(std::move(PCHContainerOps)),
-  BuildGlobalModuleIndex(false), HaveFullGlobalModuleIndex(false),
-  ModuleBuildFailed(false) {}
+  ThePCHContainerOperations(std::move(PCHContainerOps)) {}
 
 CompilerInstance::~CompilerInstance() {
   assert(OutputFiles.empty() && "Still output files in flight?");


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29208: Prevent ICE in dllexport class with _Atomic() data member

2017-02-01 Thread Warren Ristow via Phabricator via cfe-commits
wristow updated this revision to Diff 86767.
wristow added a comment.

Code restructured.


https://reviews.llvm.org/D29208

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/atomic-dllexport.cpp


Index: test/CodeGenCXX/atomic-dllexport.cpp
===
--- test/CodeGenCXX/atomic-dllexport.cpp
+++ test/CodeGenCXX/atomic-dllexport.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++11 
-fms-extensions -O0 -o - %s | FileCheck --check-prefix=M32 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++11 
-fms-extensions -O0 -o - %s | FileCheck --check-prefix=M64 %s
+
+struct __declspec(dllexport) SomeStruct {
+  // Copy assignment operator should be produced, and exported:
+  // M32: define weak_odr dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) 
%struct.SomeStruct* @"\01??4SomeStruct@@QAEAAU0@ABU0@@Z"
+  // M64: define weak_odr dllexportdereferenceable({{[0-9]+}}) 
%struct.SomeStruct* @"\01??4SomeStruct@@QEAAAEAU0@AEBU0@@Z"
+  _Atomic(int) mData;
+};
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -1131,10 +1131,11 @@
   RHS = EC->getSubExpr();
 if (!RHS)
   return nullptr;
-MemberExpr *ME2 = dyn_cast(RHS);
-if (dyn_cast(ME2->getMemberDecl()) != Field)
-  return nullptr;
-return Field;
+if (MemberExpr *ME2 = dyn_cast(RHS)) {
+  if (ME2->getMemberDecl() == Field)
+return Field;
+}
+return nullptr;
   } else if (CXXMemberCallExpr *MCE = dyn_cast(S)) {
 CXXMethodDecl *MD = dyn_cast(MCE->getCalleeDecl());
 if (!(MD && isMemcpyEquivalentSpecialMember(MD)))


Index: test/CodeGenCXX/atomic-dllexport.cpp
===
--- test/CodeGenCXX/atomic-dllexport.cpp
+++ test/CodeGenCXX/atomic-dllexport.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++11 -fms-extensions -O0 -o - %s | FileCheck --check-prefix=M32 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++11 -fms-extensions -O0 -o - %s | FileCheck --check-prefix=M64 %s
+
+struct __declspec(dllexport) SomeStruct {
+  // Copy assignment operator should be produced, and exported:
+  // M32: define weak_odr dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) %struct.SomeStruct* @"\01??4SomeStruct@@QAEAAU0@ABU0@@Z"
+  // M64: define weak_odr dllexportdereferenceable({{[0-9]+}}) %struct.SomeStruct* @"\01??4SomeStruct@@QEAAAEAU0@AEBU0@@Z"
+  _Atomic(int) mData;
+};
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -1131,10 +1131,11 @@
   RHS = EC->getSubExpr();
 if (!RHS)
   return nullptr;
-MemberExpr *ME2 = dyn_cast(RHS);
-if (dyn_cast(ME2->getMemberDecl()) != Field)
-  return nullptr;
-return Field;
+if (MemberExpr *ME2 = dyn_cast(RHS)) {
+  if (ME2->getMemberDecl() == Field)
+return Field;
+}
+return nullptr;
   } else if (CXXMemberCallExpr *MCE = dyn_cast(S)) {
 CXXMethodDecl *MD = dyn_cast(MCE->getCalleeDecl());
 if (!(MD && isMemcpyEquivalentSpecialMember(MD)))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29208: Prevent ICE in dllexport class with _Atomic() data member

2017-02-01 Thread Warren Ristow via Phabricator via cfe-commits
wristow marked 2 inline comments as done.
wristow added inline comments.



Comment at: lib/CodeGen/CGClass.cpp:1135
 MemberExpr *ME2 = dyn_cast(RHS);
-if (dyn_cast(ME2->getMemberDecl()) != Field)
+if (!ME2 || dyn_cast(ME2->getMemberDecl()) != Field)
   return nullptr;

rjmccall wrote:
> wristow wrote:
> > rjmccall wrote:
> > > I would prefer:
> > > 
> > >   if (MemberExpr *ME2 = dyn_cast(RHS)) {
> > > if (ME2->getMemberDecl() == Field)
> > >   return Field;
> > >   }
> > >   return nullptr;
> > I see that change removes the `dyn_cast`.  Was that intended, or 
> > an oversight?
> > 
> > In terms of changing the code-structure, in code on it's own, I do like the 
> > approach you described.  But in this case, there is a sequence of `if 
> > () return nullptr; ... if (conditionN) return nullptr; return 
> > Field;`.  Then after the block containing that set of guarded `nullptr` 
> > returns with a final `return Field;`, there is a similar block.  And then 
> > there is a third block with a similar set.  So changing the structure in 
> > that way breaks that pattern.  With that in mind, do you still want that 
> > change done?
> The dyn_cast has no effect.  There is no situation in which the declarations 
> would compare equal without it where they would not with it, because Field is 
> already known to be a FieldDecl.
> 
> The structure of the existing code is unlikely to stay the same.  Actually, 
> that code is quite worrying — it's making a lot of assumptions about how Sema 
> synthesizes defaulted assignment operator bodies.  But I didn't want to ask 
> you to fix it when it's not the subject of your bug.
Got it.  Posted updated patch.


https://reviews.llvm.org/D29208



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29208: Prevent ICE in dllexport class with _Atomic() data member

2017-02-01 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Thanks, looks good.


https://reviews.llvm.org/D29208



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293867 - CodeGen: add a LLVM_FALLTHROUGH to a fallthrough (NFC)

2017-02-01 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Wed Feb  1 23:45:43 2017
New Revision: 293867

URL: http://llvm.org/viewvc/llvm-project?rev=293867&view=rev
Log:
CodeGen: add a LLVM_FALLTHROUGH to a fallthrough (NFC)

Drive by cleanup noticed while investigating an IR verifier assertion.

Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=293867&r1=293866&r2=293867&view=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Wed Feb  1 23:45:43 2017
@@ -1416,9 +1416,7 @@ void CodeGenFunction::EmitDestructorBody
   // we'd introduce *two* handler blocks.  In the Microsoft ABI, we
   // always delegate because we might not have a definition in this TU.
   switch (DtorType) {
-  case Dtor_Comdat:
-llvm_unreachable("not expecting a COMDAT");
-
+  case Dtor_Comdat: llvm_unreachable("not expecting a COMDAT");
   case Dtor_Deleting: llvm_unreachable("already handled deleting case");
 
   case Dtor_Complete:
@@ -1433,7 +1431,9 @@ void CodeGenFunction::EmitDestructorBody
 /*Delegating=*/false, LoadCXXThisAddress());
   break;
 }
+
 // Fallthrough: act like we're in the base variant.
+LLVM_FALLTHROUGH;
 
   case Dtor_Base:
 assert(Body);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29369: [ubsan] Omit superflous overflow checks for promoted arithmetic (PR20193)

2017-02-01 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

In https://reviews.llvm.org/D29369#664366, @regehr wrote:

> Out of curiosity, how many of these superfluous checks are not subsequently 
> eliminated by InstCombine?


I don't have numbers from a benchmark prepped. Here's what we get with the 
'ubsan-promoted-arith.cpp' test case from this patch:

| Setup| # of overflow checks |
| unpatched, -O0   | 22   |
| unpatched, -O0 + instcombine | 7|
| patched, -O0 | 8|
| patched, -O0 + instcombine   | 7|

(There's a difference between the "patched, -O0" setup and the "patched, -O0 + 
instcombine" setup because llvm figures out that the symbol 'a' is 0, and gets 
rid of an addition that way.)

At least for us, this patch is still worthwhile, because our use case is `-O0 
-fsanitized=undefined`. Also, this makes less work for instcombine, but I 
haven't measured the compile-time effect.


https://reviews.llvm.org/D29369



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits