[libunwind] r348832 - Don't export assembly functions when function visibility annotations are disabled

2018-12-10 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Mon Dec 10 23:34:14 2018
New Revision: 348832

URL: http://llvm.org/viewvc/llvm-project?rev=348832=rev
Log:
Don't export assembly functions when function visibility annotations are 
disabled

Patch by Peiyuan Song!

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

Modified:
libunwind/trunk/src/assembly.h

Modified: libunwind/trunk/src/assembly.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/assembly.h?rev=348832=348831=348832=diff
==
--- libunwind/trunk/src/assembly.h (original)
+++ libunwind/trunk/src/assembly.h Mon Dec 10 23:34:14 2018
@@ -76,7 +76,11 @@
   .section .drectve,"yn" SEPARATOR\
   .ascii "-export:", #name, "\0" SEPARATOR\
   .text
+#if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
+#define EXPORT_SYMBOL(name)
+#else
 #define EXPORT_SYMBOL(name) EXPORT_SYMBOL2(name)
+#endif
 #define HIDDEN_SYMBOL(name)
 
 #define NO_EXEC_STACK_DIRECTIVE


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


r348831 - Revert r348830 "[Sema]improve static_assert(!expr)"

2018-12-10 Thread Clement Courbet via cfe-commits
Author: courbet
Date: Mon Dec 10 23:28:00 2018
New Revision: 348831

URL: http://llvm.org/viewvc/llvm-project?rev=348831=rev
Log:
Revert r348830 "[Sema]improve static_assert(!expr)"

Submitted the wrong change.

Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaCXX/static-assert.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=348831=348830=348831=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Dec 10 23:28:00 2018
@@ -3071,20 +3071,6 @@ static void prettyPrintFailedBooleanCond
 }
 return;
   }
-  if (const auto *Paren = dyn_cast(FailedCond)) {
-OS << "(";
-prettyPrintFailedBooleanCondition(OS, Paren->getSubExpr(), Policy);
-OS << ")";
-return;
-  }
-  // If this is !(BooleanExpression), try pretty-printing the inner expression.
-  const auto *UnaryOp = dyn_cast(FailedCond);
-  if (UnaryOp && UnaryOp->getOpcode() == UO_LNot) {
-OS << "!";
-prettyPrintFailedBooleanCondition(OS, UnaryOp->getSubExpr(), Policy);
-return;
-  }
-
   FailedCond->printPretty(OS, nullptr, Policy);
 }
 

Modified: cfe/trunk/test/SemaCXX/static-assert.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/static-assert.cpp?rev=348831=348830=348831=diff
==
--- cfe/trunk/test/SemaCXX/static-assert.cpp (original)
+++ cfe/trunk/test/SemaCXX/static-assert.cpp Mon Dec 10 23:28:00 2018
@@ -111,10 +111,6 @@ static_assert(std::is_same::value' "message"}}
 static_assert(std::is_const::value, "message");
 // expected-error@-1{{static_assert failed due to requirement 
'std::is_const::value' "message"}}
-static_assert(!std::is_const::value, "message");
-// expected-error@-1{{static_assert failed due to requirement 
'!std::is_const::value' "message"}}
-static_assert(!(std::is_const::value), "message");
-// expected-error@-1{{static_assert failed due to requirement 
'!(std::is_const::value)' "message"}}
 
 struct BI_tag {};
 struct RAI_tag : BI_tag {};


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


[PATCH] D55483: Introduce the callback attribute and emit !callback metadata

2018-12-10 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert updated this revision to Diff 177662.
jdoerfert added a comment.

Update according to initial feedback


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55483/new/

https://reviews.llvm.org/D55483

Files:
  include/clang/AST/ASTContext.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/Builtins.def
  include/clang/Basic/Builtins.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/ASTContext.cpp
  lib/Basic/Builtins.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/attr-callback.c
  test/CodeGen/callback_annotated.c
  test/CodeGen/callback_openmp.c
  test/CodeGen/callback_pthread_create.c
  test/CodeGen/callback_qsort_r.c
  test/CodeGenCXX/attr-callback.cpp
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/OpenMP/parallel_codegen.cpp
  test/Sema/attr-callback-broken.c
  test/Sema/attr-callback.c
  test/SemaCXX/attr-callback-broken.cpp
  test/SemaCXX/attr-callback.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -1275,6 +1275,8 @@
 Ptr = llvm::make_unique(Arg, Attr, "unsigned");
   else if (ArgName == "VariadicUnsignedArgument")
 Ptr = llvm::make_unique(Arg, Attr, "unsigned");
+  else if (ArgName == "VariadicSignedArgument")
+Ptr = llvm::make_unique(Arg, Attr, "int");
   else if (ArgName == "VariadicStringArgument")
 Ptr = llvm::make_unique(Arg, Attr);
   else if (ArgName == "VariadicEnumArgument")
Index: test/SemaCXX/attr-callback.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-callback.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+// expected-no-diagnostics
+
+class C_in_class {
+#include "../Sema/attr-callback.c"
+};
+
+struct Base {
+
+  void no_args_1(void (*callback)(void));
+  __attribute__((callback(1))) void no_args_2(void (*callback)(void));
+  __attribute__((callback(1))) void no_args_3(void (*callback)(void)) {}
+
+  __attribute__((callback(1, 0))) virtual void
+  this_tr(void (*callback)(Base *));
+
+  __attribute__((callback(1, 0, -1, 0))) virtual void
+  this_unknown_this(void (*callback)(Base *, Base *, Base *));
+
+  __attribute__((callback(1))) virtual void
+  virtual_1(void (*callback)(void));
+
+  __attribute__((callback(1))) virtual void
+  virtual_2(void (*callback)(void));
+
+  __attribute__((callback(1))) virtual void
+  virtual_3(void (*callback)(void));
+};
+
+__attribute__((callback(1))) void
+Base::no_args_1(void (*callback)(void)) {
+}
+
+void Base::no_args_2(void (*callback)(void)) {
+}
+
+struct Derived_1 : public Base {
+
+  __attribute__((callback(1, 0))) virtual void
+  this_tr(void (*callback)(Base *)) override;
+
+  __attribute__((callback(1))) virtual void
+  virtual_1(void (*callback)(void)) override {}
+
+  virtual void
+  virtual_3(void (*callback)(void)) override {}
+};
+
+struct Derived_2 : public Base {
+
+  __attribute__((callback(1))) virtual void
+  virtual_1(void (*callback)(void)) override;
+
+  virtual void
+  virtual_2(void (*callback)(void)) override;
+
+  virtual void
+  virtual_3(void (*callback)(void)) override;
+};
+
+void Derived_2::virtual_1(void (*callback)(void)) {}
+
+__attribute__((callback(1))) void
+Derived_2::virtual_2(void (*callback)(void)) {}
+
+void Derived_2::virtual_3(void (*callback)(void)) {}
Index: test/SemaCXX/attr-callback-broken.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-callback-broken.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+class C_in_class {
+#define HAS_THIS
+#include "../Sema/attr-callback-broken.c"
+#undef HAS_THIS
+};
Index: test/Sema/attr-callback.c
===
--- /dev/null
+++ test/Sema/attr-callback.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+// expected-no-diagnostics
+
+__attribute__((callback(1))) void no_args(void (*callback)(void));
+__attribute__((callback(1, 2, 3)))   void args_1(void (*callback)(int, double), int a, double b);
+__attribute__((callback(2, 3, 3)))   void args_2(int a, void (*callback)(double, double), double b);
+__attribute__((callback(2, -1, -1))) void args_3(int a, void (*callback)(double, double), double b);
Index: test/Sema/attr-callback-broken.c
===
--- /dev/null
+++ test/Sema/attr-callback-broken.c
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+__attribute__((callback())) void no_callee(void (*callback)(void)); // expected-error {{'callback' attribute takes at least 1 argument}}
+
+__attribute__((callback(1, 1)))void too_many_args_1(void   (*callback)(void)) {}   // 

r348830 - [Sema]improve static_assert(!expr)

2018-12-10 Thread Clement Courbet via cfe-commits
Author: courbet
Date: Mon Dec 10 23:04:49 2018
New Revision: 348830

URL: http://llvm.org/viewvc/llvm-project?rev=348830=rev
Log:
[Sema]improve static_assert(!expr)

Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaCXX/static-assert.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=348830=348829=348830=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Dec 10 23:04:49 2018
@@ -3071,6 +3071,20 @@ static void prettyPrintFailedBooleanCond
 }
 return;
   }
+  if (const auto *Paren = dyn_cast(FailedCond)) {
+OS << "(";
+prettyPrintFailedBooleanCondition(OS, Paren->getSubExpr(), Policy);
+OS << ")";
+return;
+  }
+  // If this is !(BooleanExpression), try pretty-printing the inner expression.
+  const auto *UnaryOp = dyn_cast(FailedCond);
+  if (UnaryOp && UnaryOp->getOpcode() == UO_LNot) {
+OS << "!";
+prettyPrintFailedBooleanCondition(OS, UnaryOp->getSubExpr(), Policy);
+return;
+  }
+
   FailedCond->printPretty(OS, nullptr, Policy);
 }
 

Modified: cfe/trunk/test/SemaCXX/static-assert.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/static-assert.cpp?rev=348830=348829=348830=diff
==
--- cfe/trunk/test/SemaCXX/static-assert.cpp (original)
+++ cfe/trunk/test/SemaCXX/static-assert.cpp Mon Dec 10 23:04:49 2018
@@ -111,6 +111,10 @@ static_assert(std::is_same::value' "message"}}
 static_assert(std::is_const::value, "message");
 // expected-error@-1{{static_assert failed due to requirement 
'std::is_const::value' "message"}}
+static_assert(!std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 
'!std::is_const::value' "message"}}
+static_assert(!(std::is_const::value), "message");
+// expected-error@-1{{static_assert failed due to requirement 
'!(std::is_const::value)' "message"}}
 
 struct BI_tag {};
 struct RAI_tag : BI_tag {};


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


[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-10 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF marked 14 inline comments as done.
EricWF added a comment.

Address review comments. Fixes incoming.




Comment at: include/clang/AST/ExprCXX.h:218
+ SourceLocation RP, unsigned MinNumArgs = 0,
+ bool UsesADL = false)
   : CallExpr(C, CUDAKernelCallExprClass, fn, Config, args, t, VK, RP,

fowles wrote:
> Can CUDAKernelCalls ever use ADL?
Yeah, after further investigation, I don't think so. I'll revert this change.



Comment at: include/clang/AST/ExprCXX.h:499
+  : CallExpr(C, UserDefinedLiteralClass, Fn, Args, T, VK, LitEndLoc,
+ /*MinNumArgs=*/0, /*UsesADL=*/false),
 UDSuffixLoc(SuffixLoc) {}

fowles wrote:
> Same question, I assume user defined literals can only be called as string 
> suffixes and thus never get ADL
Right. Their argument is a literal of some sort. 



Comment at: lib/Sema/SemaOverload.cpp:8946
+   ExplicitTemplateArgs, Args, CandidateSet,
+   /*SuppressUserConversions=*/false,
+   PartialOverloading, 
/*IsADLCandidate=*/true);

fowles wrote:
> should this fix be in a separate change?
I'll commit the fix as a separate patch.



Comment at: lib/Serialization/ASTReaderStmt.cpp:735
   unsigned NumArgs = Record.readInt();
+  bool UsesADL = Record.readInt();
   assert((NumArgs == E->getNumArgs()) && "Wrong NumArgs!");

fowles wrote:
> readInt into a bool?
Yeah. You serialize and serialize all integer types using `readInt()`



Comment at: unittests/ASTMatchers/ASTMatchersNodeTest.cpp:204
+  StatementMatcher ADLMatch = callExpr(usesADL());
+  auto NS_Str = R"DELIM(
+  namespace NS {

fowles wrote:
> if you use cc or cpp as your delimiter, I think clang-format will recurse 
> correctly
That's super cool. Thanks!


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55534/new/

https://reviews.llvm.org/D55534



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


[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-10 Thread Matt Kulukundis via Phabricator via cfe-commits
fowles added inline comments.



Comment at: include/clang/AST/ExprCXX.h:218
+ SourceLocation RP, unsigned MinNumArgs = 0,
+ bool UsesADL = false)
   : CallExpr(C, CUDAKernelCallExprClass, fn, Config, args, t, VK, RP,

Can CUDAKernelCalls ever use ADL?



Comment at: include/clang/AST/ExprCXX.h:499
+  : CallExpr(C, UserDefinedLiteralClass, Fn, Args, T, VK, LitEndLoc,
+ /*MinNumArgs=*/0, /*UsesADL=*/false),
 UDSuffixLoc(SuffixLoc) {}

Same question, I assume user defined literals can only be called as string 
suffixes and thus never get ADL



Comment at: include/clang/ASTMatchers/ASTMatchers.h:1275
+/// NS::y(x); // Doesn't match
+/// y(42);
+///   }

y(42);  // Doesn't match



Comment at: include/clang/Sema/Overload.h:775
+/// True if the candidate was found using ADL.
+bool IsADLCandidate;
+

maybe bit pack these?  I think overload sets for operator<< actually get pretty 
big



Comment at: lib/Sema/SemaOverload.cpp:8946
+   ExplicitTemplateArgs, Args, CandidateSet,
+   /*SuppressUserConversions=*/false,
+   PartialOverloading, 
/*IsADLCandidate=*/true);

should this fix be in a separate change?



Comment at: lib/Sema/SemaOverload.cpp:12024
 return SemaRef.BuildResolvedCallExpr(Fn, FDecl, LParenLoc, Args, RParenLoc,
- ExecConfig);
+ ExecConfig, /*IsExecConfig*/ false,
+ (*Best)->IsADLCandidate);

/*IsExecConfig=*/



Comment at: lib/Sema/SemaOverload.cpp:12077
 return SemaRef.BuildResolvedCallExpr(Fn, FDecl, LParenLoc, Args, RParenLoc,
- ExecConfig);
+ ExecConfig, /*IsExecConfig*/ false,
+ (*Best)->IsADLCandidate);

here too



Comment at: lib/Serialization/ASTReaderStmt.cpp:735
   unsigned NumArgs = Record.readInt();
+  bool UsesADL = Record.readInt();
   assert((NumArgs == E->getNumArgs()) && "Wrong NumArgs!");

readInt into a bool?



Comment at: unittests/ASTMatchers/ASTMatchersNodeTest.cpp:204
+  StatementMatcher ADLMatch = callExpr(usesADL());
+  auto NS_Str = R"DELIM(
+  namespace NS {

if you use cc or cpp as your delimiter, I think clang-format will recurse 
correctly


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55534/new/

https://reviews.llvm.org/D55534



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


[PATCH] D54355: Use is.constant intrinsic for __builtin_constant_p

2018-12-10 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D54355#1326494 , @craig.topper 
wrote:

> I'm seeing a case where an inline assembly 'n' constraint is behaving 
> differently in -O0 now. Previously we would evaluate the __builtin_constant_p 
> as part of the EvaluateAsInt call in CodeGenFunction::EmitAsmInput, but I 
> think we're not doing that now. This causes us to fail later because the 
> constraint wasn't satisfied since we were in -O0 and thus we didn't optimize 
> the rest of the expression. The test case we have is a nasty mix of 
> __builtin_constant_p, __builtin_choose_expr, and __builtin_classify_type. I 
> can see about sharing it if needed.


`__builtin_constant_p()` is known to have different semantics at `-O0` than it 
does during optimizations. That said, we shouldn't be intentionally generating 
incorrect code. Could you test it against gcc to see if it has the same 
semantics? Otherwise, please add a testcase. :-)


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54355/new/

https://reviews.llvm.org/D54355



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


[PATCH] D55510: [ExprConstant] Improve memchr/memcmp for type mismatch and multibyte element types

2018-12-10 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

I'll update the tests to be in terms of constant/variable array length 
tomorrow. I think I've gotten through the rest of the comments.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55510/new/

https://reviews.llvm.org/D55510



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


[PATCH] D55510: [ExprConstant] Improve memchr/memcmp for type mismatch and multibyte element types

2018-12-10 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast updated this revision to Diff 177656.
hubert.reinterpretcast marked 3 inline comments as done.
hubert.reinterpretcast added a comment.

Address remaining ExprConstant.cpp review comments

Use BytesRemaining/BytesPerElement to improve readability;
tweak FIXME comment to refer to the _remaining_ bytes.
Use CharUnits-to-CharUnits comparisons where straightforward.
Tweak comment about internal representation mismatch.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55510/new/

https://reviews.llvm.org/D55510

Files:
  include/clang/Basic/DiagnosticASTKinds.td
  lib/AST/ExprConstant.cpp
  test/CodeGenCXX/builtins.cpp
  test/SemaCXX/constexpr-string.cpp

Index: test/SemaCXX/constexpr-string.cpp
===
--- test/SemaCXX/constexpr-string.cpp
+++ test/SemaCXX/constexpr-string.cpp
@@ -95,6 +95,52 @@
   static_assert(__builtin_memcmp("abab\0banana", "abab\0canada", 6) == -1);
   static_assert(__builtin_memcmp("abab\0banana", "abab\0canada", 5) == 0);
 
+  extern struct Incomplete incomplete;
+  static_assert(__builtin_memcmp(, "", 0u) == 0);
+  static_assert(__builtin_memcmp("", , 0u) == 0);
+  static_assert(__builtin_memcmp(, "", 1u) == 42); // expected-error {{not an integral constant}} expected-note {{read of incomplete type 'struct Incomplete'}}
+  static_assert(__builtin_memcmp("", , 1u) == 42); // expected-error {{not an integral constant}} expected-note {{read of incomplete type 'struct Incomplete'}}
+
+  constexpr unsigned char ku00fe00[] = {0x00, 0xfe, 0x00};
+  constexpr unsigned char ku00feff[] = {0x00, 0xfe, 0xff};
+  constexpr signed char ks00fe00[] = {0, -2, 0};
+  constexpr signed char ks00feff[] = {0, -2, -1};
+  static_assert(__builtin_memcmp(ku00feff, ks00fe00, 2) == 0);
+  static_assert(__builtin_memcmp(ku00feff, ks00fe00, 99) == 1);
+  static_assert(__builtin_memcmp(ku00fe00, ks00feff, 99) == -1);
+  static_assert(__builtin_memcmp(ks00feff, ku00fe00, 2) == 0);
+  static_assert(__builtin_memcmp(ks00feff, ku00fe00, 99) == 1);
+  static_assert(__builtin_memcmp(ks00fe00, ku00feff, 99) == -1);
+  static_assert(__builtin_memcmp(ks00fe00, ks00feff, 2) == 0);
+  static_assert(__builtin_memcmp(ks00feff, ks00fe00, 99) == 1);
+  static_assert(__builtin_memcmp(ks00fe00, ks00feff, 99) == -1);
+
+  struct Bool3Tuple { bool bb[3]; };
+  constexpr Bool3Tuple kb000100 = {{false, true, false}};
+  static_assert(sizeof(bool) != 1u || __builtin_memcmp(ks00fe00, kb000100.bb, 1) == 0);
+  static_assert(sizeof(bool) != 1u || __builtin_memcmp(ks00fe00, kb000100.bb, 2) == 1);
+
+  constexpr long ksl[] = {0, -1};
+  constexpr unsigned int kui[] = {0, 0u - 1};
+  constexpr unsigned long long kull[] = {0, 0ull - 1};
+  constexpr const auto *kuSizeofLong(void) {
+if constexpr(sizeof(long) == sizeof(int)) {
+  return kui;
+} else {
+  static_assert(sizeof(long) == sizeof(long long));
+  return kull;
+}
+  }
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), sizeof(long) - 1) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), sizeof(long) + 0) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), sizeof(long) + 1) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), 2*sizeof(long) - 1) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), 2*sizeof(long) + 0) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), 2*sizeof(long) + 1) == 42); // expected-error {{not an integral constant}} expected-note {{dereferenced one-past-the-end}}
+  static_assert(__builtin_memcmp(ksl + 1, kuSizeofLong() + 1, sizeof(long) - 1) == 0);
+  static_assert(__builtin_memcmp(ksl + 1, kuSizeofLong() + 1, sizeof(long) + 0) == 0);
+  static_assert(__builtin_memcmp(ksl + 1, kuSizeofLong() + 1, sizeof(long) + 1) == 42); // expected-error {{not an integral constant}} expected-note {{dereferenced one-past-the-end}}
+
   constexpr int a = strcmp("hello", "world"); // expected-error {{constant expression}} expected-note {{non-constexpr function 'strcmp' cannot be used in a constant expression}}
   constexpr int b = strncmp("hello", "world", 3); // expected-error {{constant expression}} expected-note {{non-constexpr function 'strncmp' cannot be used in a constant expression}}
   constexpr int c = memcmp("hello", "world", 3); // expected-error {{constant expression}} expected-note {{non-constexpr function 'memcmp' cannot be used in a constant expression}}
@@ -187,6 +233,27 @@
   static_assert(__builtin_memchr(nullptr, 'x', 3) == nullptr); // expected-error {{not an integral constant}} expected-note {{dereferenced null}}
   static_assert(__builtin_memchr(nullptr, 'x', 0) == nullptr); // FIXME: Should we reject this?
 
+  extern struct Incomplete incomplete;
+  static_assert(__builtin_memchr(, 0, 0u) == nullptr);
+  static_assert(__builtin_memchr(, 0, 1u) == nullptr); // expected-error {{not an integral constant}} expected-note {{read of incomplete type 'struct Incomplete'}}
+
+  

[PATCH] D55500: [Builtins] Implement __builtin_is_constant_evaluated for use in C++2a

2018-12-10 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF marked 2 inline comments as done.
EricWF added a comment.

Sorry for the delayed response. My email filters were incorrect.




Comment at: include/clang/Basic/Builtins.def:759
+// Random C++ builtins.
+LANGBUILTIN(__builtin_is_constant_evaluated, "b", "ncu", CXX_LANG)
+

bruno wrote:
> Name bikeshedding : perhaps the builtin name could be detached from the std:: 
> name? Suggestion: `__builtin_in_constant_evaluation_context`
I'm not sure detaching it from the `std::` name is desirable. Most importantly 
it should match w/e GCC does/decides to do.

But if it is, we should name in deference to the standardese it implements. 
Specifically weither an expression or conversion is //manifestly 
constant-evaluated// [[expr.const](http://eel.is/c++draft/expr.const#11)]p11.

Therefore I proffer  `__builtin_is_manifestly_constant_evaluated()` or 
`__builtin_is_being_manifestly_constant_evaluated()`.





Comment at: lib/AST/ExprConstant.cpp:8207
 
+  case Builtin::BI__builtin_is_constant_evaluated:
+return Success(Info.InConstantContext, E);

bruno wrote:
> Do we need compat and extension warnings for the use of this builtin before 
> c++2a? I assume people will play with the builtin before the library facility 
> is there. OTOH, since this will be mainly exposed as a library thing, 
> whatever check for c++ version is done at the library level should be enough?
No. We don't  warn for any other builtin used to serve the standard library 
(`__is_constructible()`, `__builtin_addressof()`, etc)

The builtin is useful in all dialects, and I suspect users will frequently want 
to call it directly. If `__has_builtin(__builtin_is_constant_evaluated)` 
returns true, it should be safe to use.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55500/new/

https://reviews.llvm.org/D55500



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


[PATCH] D55546: [clang] Add AST matcher for block expressions 

2018-12-10 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore created this revision.
Herald added a subscriber: cfe-commits.

This change adds a new AST matcher for block expressions.

Test Notes:
Ran the clang unit tests.


Repository:
  rC Clang

https://reviews.llvm.org/D55546

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/ASTMatchersInternal.cpp
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp


Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1386,6 +1386,10 @@
 hasDeclaration(namedDecl(hasName("y"));
 }
 
+TEST(BlockExprMatcher, BlockExpr) {
+  EXPECT_TRUE(matchesObjC("void f() { ^{}(); }", blockExpr()));
+}
+
 TEST(StatementCountIs, FindsNoStatementsInAnEmptyCompoundStatement) {
   EXPECT_TRUE(matches("void f() { }",
   compoundStmt(statementCountIs(0;
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -139,6 +139,7 @@
   REGISTER_MATCHER(binaryConditionalOperator);
   REGISTER_MATCHER(binaryOperator);
   REGISTER_MATCHER(blockDecl);
+  REGISTER_MATCHER(blockExpr);
   REGISTER_MATCHER(blockPointerType);
   REGISTER_MATCHER(booleanType);
   REGISTER_MATCHER(breakStmt);
Index: lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- lib/ASTMatchers/ASTMatchersInternal.cpp
+++ lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -688,6 +688,7 @@
 const internal::VariadicDynCastAllOfMatcher expr;
 const internal::VariadicDynCastAllOfMatcher declRefExpr;
 const internal::VariadicDynCastAllOfMatcher 
objcIvarRefExpr;
+const internal::VariadicDynCastAllOfMatcher blockExpr;
 const internal::VariadicDynCastAllOfMatcher ifStmt;
 const internal::VariadicDynCastAllOfMatcher forStmt;
 const internal::VariadicDynCastAllOfMatcher
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -1776,6 +1776,14 @@
 extern const internal::VariadicDynCastAllOfMatcher
 objcIvarRefExpr;
 
+/// Matches a reference to a block.
+///
+/// Example: matches "^{}":
+/// \code
+///   void f() { ^{}(); }
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher blockExpr;
+
 /// Matches if statements.
 ///
 /// Example matches 'if (x) {}'
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -707,6 +707,14 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtblockExprMatcherhttps://clang.llvm.org/doxygen/classclang_1_1BlockExpr.html;>BlockExpr...
+MAtches a reference to a 
block.
+
+Example: matches "^{}":
+  void f() { ^{}(); }
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtbreakStmtMatcherhttps://clang.llvm.org/doxygen/classclang_1_1BreakStmt.html;>BreakStmt...
 Matches break statements.
 


Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1386,6 +1386,10 @@
 hasDeclaration(namedDecl(hasName("y"));
 }
 
+TEST(BlockExprMatcher, BlockExpr) {
+  EXPECT_TRUE(matchesObjC("void f() { ^{}(); }", blockExpr()));
+}
+
 TEST(StatementCountIs, FindsNoStatementsInAnEmptyCompoundStatement) {
   EXPECT_TRUE(matches("void f() { }",
   compoundStmt(statementCountIs(0;
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -139,6 +139,7 @@
   REGISTER_MATCHER(binaryConditionalOperator);
   REGISTER_MATCHER(binaryOperator);
   REGISTER_MATCHER(blockDecl);
+  REGISTER_MATCHER(blockExpr);
   REGISTER_MATCHER(blockPointerType);
   REGISTER_MATCHER(booleanType);
   REGISTER_MATCHER(breakStmt);
Index: lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- lib/ASTMatchers/ASTMatchersInternal.cpp
+++ lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -688,6 +688,7 @@
 const internal::VariadicDynCastAllOfMatcher expr;
 const internal::VariadicDynCastAllOfMatcher declRefExpr;
 const internal::VariadicDynCastAllOfMatcher objcIvarRefExpr;
+const internal::VariadicDynCastAllOfMatcher blockExpr;
 const internal::VariadicDynCastAllOfMatcher ifStmt;
 const internal::VariadicDynCastAllOfMatcher forStmt;
 const internal::VariadicDynCastAllOfMatcher
Index: 

[PATCH] D55544: Warning: objc-encodings-larger-than=

2018-12-10 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added a comment.

FYI:
I have a clang-tidy check almost ready for review that aims to flag large 
Objective-C type encodings.




Comment at: include/clang/Basic/LangOptions.def:103
+BENIGN_LANGOPT(ObjCLargeEncodingSize, 32, 0,
+  "if non-zero, warn about Objective C encodings larger in bytes 
than this setting. 0 is no check.")
 LANGOPT(AppExt , 1, 0, "Objective-C App Extension")

Objective-C


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55544/new/

https://reviews.llvm.org/D55544



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


[PATCH] D55545: Allow IncludeSorter to use #import for Objective-C files

2018-12-10 Thread Joe Turner via Phabricator via cfe-commits
compositeprimes created this revision.
compositeprimes added reviewers: klimek, alexfh.
Herald added a subscriber: cfe-commits.

The change infers whether a source file is Objective-C using LangOpts, and if 
it detects Objective-C, it uses "#import" instead of "#include" for all 
inserted imports.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D55545

Files:
  clang-tidy/utils/IncludeSorter.cpp


Index: clang-tidy/utils/IncludeSorter.cpp
===
--- clang-tidy/utils/IncludeSorter.cpp
+++ clang-tidy/utils/IncludeSorter.cpp
@@ -113,9 +113,10 @@
 
 Optional IncludeSorter::CreateIncludeInsertion(StringRef FileName,
   bool IsAngled) {
+  std::string IncludeDirective = LangOpts->ObjC ? "#import " : "#include ";
   std::string IncludeStmt =
-  IsAngled ? llvm::Twine("#include <" + FileName + ">\n").str()
-   : llvm::Twine("#include \"" + FileName + "\"\n").str();
+  IsAngled ? llvm::Twine(IncludeDirective + "<" + FileName + ">\n").str()
+   : llvm::Twine(IncludeDirective + "\"" + FileName + 
"\"\n").str();
   if (SourceLocations.empty()) {
 // If there are no includes in this file, add it in the first line.
 // FIXME: insert after the file comment or the header guard, if present.


Index: clang-tidy/utils/IncludeSorter.cpp
===
--- clang-tidy/utils/IncludeSorter.cpp
+++ clang-tidy/utils/IncludeSorter.cpp
@@ -113,9 +113,10 @@
 
 Optional IncludeSorter::CreateIncludeInsertion(StringRef FileName,
   bool IsAngled) {
+  std::string IncludeDirective = LangOpts->ObjC ? "#import " : "#include ";
   std::string IncludeStmt =
-  IsAngled ? llvm::Twine("#include <" + FileName + ">\n").str()
-   : llvm::Twine("#include \"" + FileName + "\"\n").str();
+  IsAngled ? llvm::Twine(IncludeDirective + "<" + FileName + ">\n").str()
+   : llvm::Twine(IncludeDirective + "\"" + FileName + "\"\n").str();
   if (SourceLocations.empty()) {
 // If there are no includes in this file, add it in the first line.
 // FIXME: insert after the file comment or the header guard, if present.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55544: Warning: objc-encodings-larger-than=

2018-12-10 Thread Dave MacLachlan via Phabricator via cfe-commits
dmaclach created this revision.
dmaclach added a project: clang.
Herald added a subscriber: cfe-commits.

Issue a warning when the Objective C runtime encoding generated for an iVar, 
method, or block exceeds a user configurable value.

Off by default.

Note that handling iVars and methods will also get us properties.

Objective C runtime information can get very large (several K) and most of it 
is unused. Having the warning allows us to diagnose where the problem exists in 
our code.


Repository:
  rC Clang

https://reviews.llvm.org/D55544

Files:
  docs/ReleaseNotes.rst
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  include/clang/Sema/Sema.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclObjC.cpp
  lib/Sema/SemaExpr.cpp
  test/SemaObjC/objc-large-encoding-warn.m

Index: test/SemaObjC/objc-large-encoding-warn.m
===
--- test/SemaObjC/objc-large-encoding-warn.m
+++ test/SemaObjC/objc-large-encoding-warn.m
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -verify -Wobjc-encoding-larger-than=10 -Wno-objc-root-class %s
+
+struct MyStruct {
+  int a;
+  int b;
+  struct MyStruct *c;
+};
+
+@interface MyClass {
+  struct MyStruct iVarThatWarns; // expected-warning {{instance variable encoding of size 24 is larger than 10 bytes}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-encoding-larger-than="
+  struct MyStruct iVarThatDoesntWarn;
+#pragma clang diagnostic pop
+  id idThatDoesntWarn;
+}
+@end
+
+@implementation MyClass
+- (void)methodThatWarns:(struct MyStruct)aStruct {} // expected-warning {{instance method 'methodThatWarns:' encoding of size 33 is larger than 10 bytes}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-encoding-larger-than="
+- (void)methodThatDoesntWarn:(struct MyStruct)aStruct {}
+#pragma clang diagnostic pop
+- (void)methodThatAlsoDoesntWarn {}
+@end
+
+void BlockFunc() {
+  void(^aBlockThatWarns)(struct MyStruct) = ^(struct MyStruct a) {}; // expected-warning {{block argument encoding of size 31 is larger than 10 bytes}}
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wobjc-encoding-larger-than="
+  void(^aBlockThatDoesntWarn)(struct MyStruct) = ^(struct MyStruct a) {};
+#pragma clang diagnostic pop
+  void(^aBlockThatAlsoDoesntWarn)() = ^() {};
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -13777,6 +13777,16 @@
   if (getCurFunction())
 getCurFunction()->addBlock(BD);
 
+  /// Check for block objective C encoding size
+  if (getLangOpts().ObjC) {
+std::string encoding = Context.getObjCEncodingForBlock(Result);
+unsigned long encodingSize = LangOpts.ObjCLargeEncodingSize;
+if (encodingSize && encoding.length() > encodingSize) {
+  Diag(BD->getLocation(), diag::warn_objc_block_encoding_too_large)
+<< (unsigned)encoding.length() << (unsigned)encodingSize;
+}
+  }
+
   return Result;
 }
 
Index: lib/Sema/SemaDeclObjC.cpp
===
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -3875,6 +3875,23 @@
   }
 }
 
+// Run through the ivars and see if any of their encodings are > ObjCLargeEncodingSize.
+void Sema::DiagnoseLargeIvarEncodings(ObjCImplementationDecl *ID) {
+  unsigned long encodingSize = LangOpts.ObjCLargeEncodingSize;
+  if (encodingSize == 0) return;
+  for (ObjCIvarDecl *ivar = ID->getClassInterface()->all_declared_ivar_begin();
+   ivar; ivar = ivar->getNextIvar()) {
+QualType QT = Context.getBaseElementType(ivar->getType());
+std::string encoding;
+QualType NotEncodedT;
+Context.getObjCEncodingForType(QT, encoding, nullptr, );
+if (encoding.length() > encodingSize) {
+  Diag(ivar->getLocation(), diag::warn_objc_ivar_encoding_too_large)
+<< (unsigned)encoding.length() << (unsigned)encodingSize;
+}
+  }
+}
+
 // Note: For class/category implementations, allMethods is always null.
 Decl *Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd, ArrayRef allMethods,
ArrayRef allTUVars) {
@@ -4006,6 +4023,7 @@
   if (IDecl->hasDesignatedInitializers())
 DiagnoseMissingDesignatedInitOverrides(IC, IDecl);
   DiagnoseWeakIvars(*this, IC);
+  DiagnoseLargeIvarEncodings(IC);
   DiagnoseRetainableFlexibleArrayMember(*this, IDecl);
 
   bool HasRootClassAttr = IDecl->hasAttr();
@@ -4768,6 +4786,15 @@
 }
   }
 
+  /// Check for method encoding size.
+  std::string encoding = Context.getObjCEncodingForMethodDecl(ObjCMethod);
+  unsigned long encodingSize = LangOpts.ObjCLargeEncodingSize;
+  if (encodingSize && encoding.length() > encodingSize) {
+Diag(ObjCMethod->getLocation(), 

[PATCH] D55543: [CodeGen] Fix assertion on throwing object with inlined inherited constructor and non-trivial destructor.

2018-12-10 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: rsmith, rjmccall.
Herald added subscribers: dexonsmith, jkorous.

Fixes assertion

> Assertion failed: (isa(Val) && "cast() argument of incompatible 
> type!"), function cast, file llvm/Support/Casting.h, line 255.

It was triggered by trying to cast `FunctionDecl` to `CXXMethodDecl` as
`CGF.CurCodeDecl` in `CallBaseDtor::Emit`. It was happening because
cleanups were emitted in `ScalarExprEmitter::VisitExprWithCleanups`
after destroying `InlinedInheritingConstructorScope`, so
`CodeGenFunction.CurCodeDecl` didn't correspond to expected cleanup decl.

Fix the assertion by emitting cleanups before leaving
`InlinedInheritingConstructorScope` and changing `CurCodeDecl`.

rdar://problem/45805151


https://reviews.llvm.org/D55543

Files:
  clang/lib/CodeGen/CGClass.cpp
  clang/test/CodeGenCXX/throw-expressions.cpp


Index: clang/test/CodeGenCXX/throw-expressions.cpp
===
--- clang/test/CodeGenCXX/throw-expressions.cpp
+++ clang/test/CodeGenCXX/throw-expressions.cpp
@@ -112,3 +112,20 @@
   // CHECK: ret i32* @val
   return cond ? val : ((throw "foo"));
 }
+
+// Test throwing object with inlined inherited constructor and non-trivial 
cleanup.
+namespace rdar45805151 {
+  struct BaseException {
+// Use variadic args to force inlining the inherited constructor.
+BaseException(const char *format, ...) {}
+// Add explicit destructor to make it non-trivial.
+~BaseException() {}
+  };
+  struct BadException : public BaseException {
+using BaseException::BaseException;
+  };
+
+  void test9() {
+throw BadException("foo");
+  }
+}
Index: clang/lib/CodeGen/CGClass.cpp
===
--- clang/lib/CodeGen/CGClass.cpp
+++ clang/lib/CodeGen/CGClass.cpp
@@ -2196,6 +2196,7 @@
   GlobalDecl GD(Ctor, CtorType);
   InlinedInheritingConstructorScope Scope(*this, GD);
   ApplyInlineDebugLocation DebugScope(*this, GD);
+  RunCleanupsScope RunCleanups(*this);
 
   // Save the arguments to be passed to the inherited constructor.
   CXXInheritedCtorInitExprArgs = Args;


Index: clang/test/CodeGenCXX/throw-expressions.cpp
===
--- clang/test/CodeGenCXX/throw-expressions.cpp
+++ clang/test/CodeGenCXX/throw-expressions.cpp
@@ -112,3 +112,20 @@
   // CHECK: ret i32* @val
   return cond ? val : ((throw "foo"));
 }
+
+// Test throwing object with inlined inherited constructor and non-trivial cleanup.
+namespace rdar45805151 {
+  struct BaseException {
+// Use variadic args to force inlining the inherited constructor.
+BaseException(const char *format, ...) {}
+// Add explicit destructor to make it non-trivial.
+~BaseException() {}
+  };
+  struct BadException : public BaseException {
+using BaseException::BaseException;
+  };
+
+  void test9() {
+throw BadException("foo");
+  }
+}
Index: clang/lib/CodeGen/CGClass.cpp
===
--- clang/lib/CodeGen/CGClass.cpp
+++ clang/lib/CodeGen/CGClass.cpp
@@ -2196,6 +2196,7 @@
   GlobalDecl GD(Ctor, CtorType);
   InlinedInheritingConstructorScope Scope(*this, GD);
   ApplyInlineDebugLocation DebugScope(*this, GD);
+  RunCleanupsScope RunCleanups(*this);
 
   // Save the arguments to be passed to the inherited constructor.
   CXXInheritedCtorInitExprArgs = Args;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r348827 - Move CodeGenOptions from Frontend to Basic

2018-12-10 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Mon Dec 10 19:18:39 2018
New Revision: 348827

URL: http://llvm.org/viewvc/llvm-project?rev=348827=rev
Log:
Move CodeGenOptions from Frontend to Basic

Basic uses CodeGenOptions and should not depend on Frontend.

Added:
cfe/trunk/include/clang/Basic/CodeGenOptions.def
  - copied unchanged from r348826, 
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/include/clang/Basic/CodeGenOptions.h
  - copied, changed from r348826, 
cfe/trunk/include/clang/Frontend/CodeGenOptions.h
cfe/trunk/lib/Basic/CodeGenOptions.cpp
  - copied, changed from r348826, cfe/trunk/lib/Frontend/CodeGenOptions.cpp
Removed:
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/include/clang/Frontend/CodeGenOptions.h
cfe/trunk/lib/Frontend/CodeGenOptions.cpp
Modified:
cfe/trunk/include/clang/Frontend/CompilerInvocation.h
cfe/trunk/include/clang/module.modulemap
cfe/trunk/lib/Basic/CMakeLists.txt
cfe/trunk/lib/Basic/Targets/AMDGPU.cpp
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
cfe/trunk/lib/CodeGen/CGVTables.cpp
cfe/trunk/lib/CodeGen/CodeGenABITypes.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenPGO.h
cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
cfe/trunk/lib/CodeGen/CoverageMappingGen.h
cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Frontend/CMakeLists.txt
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Copied: cfe/trunk/include/clang/Basic/CodeGenOptions.h (from r348826, 
cfe/trunk/include/clang/Frontend/CodeGenOptions.h)
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CodeGenOptions.h?p2=cfe/trunk/include/clang/Basic/CodeGenOptions.h=cfe/trunk/include/clang/Frontend/CodeGenOptions.h=348826=348827=348827=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Basic/CodeGenOptions.h Mon Dec 10 19:18:39 2018
@@ -11,8 +11,8 @@
 //
 
//===--===//
 
-#ifndef LLVM_CLANG_FRONTEND_CODEGENOPTIONS_H
-#define LLVM_CLANG_FRONTEND_CODEGENOPTIONS_H
+#ifndef LLVM_CLANG_BASIC_CODEGENOPTIONS_H
+#define LLVM_CLANG_BASIC_CODEGENOPTIONS_H
 
 #include "clang/Basic/DebugInfoOptions.h"
 #include "clang/Basic/Sanitizers.h"
@@ -33,12 +33,12 @@ class CodeGenOptionsBase {
 public:
 #define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
 #define ENUM_CODEGENOPT(Name, Type, Bits, Default)
-#include "clang/Frontend/CodeGenOptions.def"
+#include "clang/Basic/CodeGenOptions.def"
 
 protected:
 #define CODEGENOPT(Name, Bits, Default)
 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) unsigned Name : Bits;
-#include "clang/Frontend/CodeGenOptions.def"
+#include "clang/Basic/CodeGenOptions.def"
 };
 
 /// CodeGenOptions - Track various options which control how the code
@@ -288,7 +288,7 @@ public:
 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) \
   Type get##Name() const { return static_cast(Name); } \
   void set##Name(Type Value) { Name = static_cast(Value); }
-#include "clang/Frontend/CodeGenOptions.def"
+#include "clang/Basic/CodeGenOptions.def"
 
   CodeGenOptions();
 

Removed: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=348826=auto
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def (removed)
@@ -1,366 +0,0 @@
-//===--- CodeGenOptions.def - Code generation option database - 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 the code generation options. Users of this file
-// must define the CODEGENOPT macro to make use of this information.
-// Optionally, the user may also define ENUM_CODEGENOPT (for options
-// that have enumeration type and VALUE_CODEGENOPT is a code
-// generation option that describes a value rather 

[PATCH] D54355: Use is.constant intrinsic for __builtin_constant_p

2018-12-10 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

I'm seeing a case where an inline assembly 'n' constraint is behaving 
differently in -O0 now. Previously we would evaluate the __builtin_constant_p 
as part of the EvaluateAsInt call in CodeGenFunction::EmitAsmInput, but I think 
we're not doing that now. This causes us to fail later because the constraint 
wasn't satisfied since we were in -O0 and thus we didn't optimize the rest of 
the expression. The test case we have is a nasty mix of __builtin_constant_p, 
__builtin_choose_expr, and __builtin_classify_type. I can see about sharing it 
if needed.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54355/new/

https://reviews.llvm.org/D54355



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


[PATCH] D55410: [clang-tidy] check for flagging using declarations in headers

2018-12-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/clang-tidy/checks/abseil-alias-free-headers.rst:13
+The style guide  http://google.github.io/styleguide/cppguide.html#Aliases 
discusses this
+issue in more detail

Naysh wrote:
> Eugene.Zelenko wrote:
> > Missing link to guidelines,
> @Eugene.Zelenko: Sorry, I'm not sure what you mean. Could you clarify what 
> guidelines you're referring to? 
Please see documentation in other using-related checks.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55410/new/

https://reviews.llvm.org/D55410



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


[PATCH] D55410: [clang-tidy] check for flagging using declarations in headers

2018-12-10 Thread Shyan Akmal via Phabricator via cfe-commits
Naysh added inline comments.



Comment at: docs/clang-tidy/checks/abseil-alias-free-headers.rst:13
+The style guide  http://google.github.io/styleguide/cppguide.html#Aliases 
discusses this
+issue in more detail

Eugene.Zelenko wrote:
> Missing link to guidelines,
@Eugene.Zelenko: Sorry, I'm not sure what you mean. Could you clarify what 
guidelines you're referring to? 


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55410/new/

https://reviews.llvm.org/D55410



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


[PATCH] D54921: [analyzer] Remove memoization from RunLoopAutoreleaseLeakChecker

2018-12-10 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC348822: [analyzer] Remove memoization from 
RunLoopAutoreleaseLeakChecker (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D54921?vs=175351=177635#toc

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54921/new/

https://reviews.llvm.org/D54921

Files:
  lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp


Index: lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
@@ -58,13 +58,12 @@
 
 } // end anonymous namespace
 
-
-using TriBoolTy = Optional;
-using MemoizationMapTy = llvm::DenseMap>;
-
-static TriBoolTy
-seenBeforeRec(const Stmt *Parent, const Stmt *A, const Stmt *B,
-  MemoizationMapTy ) {
+/// \return Whether {@code A} occurs before {@code B} in traversal of
+/// {@code Parent}.
+/// Conceptually a very incomplete/unsound approximation of happens-before
+/// relationship (A is likely to be evaluated before B),
+/// but useful enough in this case.
+static bool seenBefore(const Stmt *Parent, const Stmt *A, const Stmt *B) {
   for (const Stmt *C : Parent->children()) {
 if (!C) continue;
 
@@ -74,26 +73,9 @@
 if (C == B)
   return false;
 
-Optional  = Memoization[C];
-if (!Cached)
-  Cached = seenBeforeRec(C, A, B, Memoization);
-
-if (Cached->hasValue())
-  return Cached->getValue();
+return seenBefore(C, A, B);
   }
-
-  return None;
-}
-
-/// \return Whether {@code A} occurs before {@code B} in traversal of
-/// {@code Parent}.
-/// Conceptually a very incomplete/unsound approximation of happens-before
-/// relationship (A is likely to be evaluated before B),
-/// but useful enough in this case.
-static bool seenBefore(const Stmt *Parent, const Stmt *A, const Stmt *B) {
-  MemoizationMapTy Memoization;
-  TriBoolTy Val = seenBeforeRec(Parent, A, B, Memoization);
-  return Val.getValue();
+  return false;
 }
 
 static void emitDiagnostics(BoundNodes ,


Index: lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
@@ -58,13 +58,12 @@
 
 } // end anonymous namespace
 
-
-using TriBoolTy = Optional;
-using MemoizationMapTy = llvm::DenseMap>;
-
-static TriBoolTy
-seenBeforeRec(const Stmt *Parent, const Stmt *A, const Stmt *B,
-  MemoizationMapTy ) {
+/// \return Whether {@code A} occurs before {@code B} in traversal of
+/// {@code Parent}.
+/// Conceptually a very incomplete/unsound approximation of happens-before
+/// relationship (A is likely to be evaluated before B),
+/// but useful enough in this case.
+static bool seenBefore(const Stmt *Parent, const Stmt *A, const Stmt *B) {
   for (const Stmt *C : Parent->children()) {
 if (!C) continue;
 
@@ -74,26 +73,9 @@
 if (C == B)
   return false;
 
-Optional  = Memoization[C];
-if (!Cached)
-  Cached = seenBeforeRec(C, A, B, Memoization);
-
-if (Cached->hasValue())
-  return Cached->getValue();
+return seenBefore(C, A, B);
   }
-
-  return None;
-}
-
-/// \return Whether {@code A} occurs before {@code B} in traversal of
-/// {@code Parent}.
-/// Conceptually a very incomplete/unsound approximation of happens-before
-/// relationship (A is likely to be evaluated before B),
-/// but useful enough in this case.
-static bool seenBefore(const Stmt *Parent, const Stmt *A, const Stmt *B) {
-  MemoizationMapTy Memoization;
-  TriBoolTy Val = seenBeforeRec(Parent, A, B, Memoization);
-  return Val.getValue();
+  return false;
 }
 
 static void emitDiagnostics(BoundNodes ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r348821 - [analyzer] Hack for backwards compatibility for options for RetainCountChecker.

2018-12-10 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Dec 10 17:13:58 2018
New Revision: 348821

URL: http://llvm.org/viewvc/llvm-project?rev=348821=rev
Log:
[analyzer] Hack for backwards compatibility for options for RetainCountChecker.

To be removed once the clients update.

Modified:

cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
cfe/trunk/test/Analysis/test-separate-retaincount.cpp

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp?rev=348821=348820=348821=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp 
(original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp 
Mon Dec 10 17:13:58 2018
@@ -1530,7 +1530,19 @@ void ento::registerRetainCountChecker(Ch
   Chk->TrackObjCAndCFObjects = true;
 }
 
+// FIXME: remove this, hack for backwards compatibility:
+// it should be possible to enable the NS/CF retain count checker as
+// osx.cocoa.RetainCount, and it should be possible to disable
+// osx.OSObjectRetainCount using osx.cocoa.RetainCount:CheckOSObject=false.
+static bool hasPrevCheckOSObjectOptionDisabled(AnalyzerOptions ) {
+  auto I = Options.Config.find("osx.cocoa.RetainCount:CheckOSObject");
+  if (I != Options.Config.end())
+return I->getValue() == "false";
+  return false;
+}
+
 void ento::registerOSObjectRetainCountChecker(CheckerManager ) {
   auto *Chk = Mgr.registerChecker();
-  Chk->TrackOSObjects = true;
+  if (!hasPrevCheckOSObjectOptionDisabled(Mgr.getAnalyzerOptions()))
+Chk->TrackOSObjects = true;
 }

Modified: cfe/trunk/test/Analysis/test-separate-retaincount.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/test-separate-retaincount.cpp?rev=348821=348820=348821=diff
==
--- cfe/trunk/test/Analysis/test-separate-retaincount.cpp (original)
+++ cfe/trunk/test/Analysis/test-separate-retaincount.cpp Mon Dec 10 17:13:58 
2018
@@ -1,5 +1,6 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx 
-analyzer-disable-checker osx.cocoa.RetainCount -DNO_CF_OBJECT -verify %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx 
-analyzer-disable-checker osx.OSObjectRetainCount -DNO_OS_OBJECT -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx -analyzer-config 
"osx.cocoa.RetainCount:CheckOSObject=false" -DNO_OS_OBJECT -verify %s
 
 typedef const void * CFTypeRef;
 extern CFTypeRef CFRetain(CFTypeRef cf);


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


r348822 - [analyzer] Remove memoization from RunLoopAutoreleaseLeakChecker

2018-12-10 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Dec 10 17:14:17 2018
New Revision: 348822

URL: http://llvm.org/viewvc/llvm-project?rev=348822=rev
Log:
[analyzer] Remove memoization from RunLoopAutoreleaseLeakChecker

Memoization dose not seem to be necessary, as other statement visitors
run just fine without it,
and in fact seems to be causing memory corruptions.
Just removing it instead of investigating the root cause.

rdar://45945002

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp?rev=348822=348821=348822=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp 
(original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RunLoopAutoreleaseLeakChecker.cpp Mon 
Dec 10 17:14:17 2018
@@ -58,13 +58,12 @@ public:
 
 } // end anonymous namespace
 
-
-using TriBoolTy = Optional;
-using MemoizationMapTy = llvm::DenseMap>;
-
-static TriBoolTy
-seenBeforeRec(const Stmt *Parent, const Stmt *A, const Stmt *B,
-  MemoizationMapTy ) {
+/// \return Whether {@code A} occurs before {@code B} in traversal of
+/// {@code Parent}.
+/// Conceptually a very incomplete/unsound approximation of happens-before
+/// relationship (A is likely to be evaluated before B),
+/// but useful enough in this case.
+static bool seenBefore(const Stmt *Parent, const Stmt *A, const Stmt *B) {
   for (const Stmt *C : Parent->children()) {
 if (!C) continue;
 
@@ -74,26 +73,9 @@ seenBeforeRec(const Stmt *Parent, const
 if (C == B)
   return false;
 
-Optional  = Memoization[C];
-if (!Cached)
-  Cached = seenBeforeRec(C, A, B, Memoization);
-
-if (Cached->hasValue())
-  return Cached->getValue();
+return seenBefore(C, A, B);
   }
-
-  return None;
-}
-
-/// \return Whether {@code A} occurs before {@code B} in traversal of
-/// {@code Parent}.
-/// Conceptually a very incomplete/unsound approximation of happens-before
-/// relationship (A is likely to be evaluated before B),
-/// but useful enough in this case.
-static bool seenBefore(const Stmt *Parent, const Stmt *A, const Stmt *B) {
-  MemoizationMapTy Memoization;
-  TriBoolTy Val = seenBeforeRec(Parent, A, B, Memoization);
-  return Val.getValue();
+  return false;
 }
 
 static void emitDiagnostics(BoundNodes ,


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


r348820 - [analyzer] Display a diagnostics when an inlined function violates its os_consumed summary

2018-12-10 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Dec 10 17:13:40 2018
New Revision: 348820

URL: http://llvm.org/viewvc/llvm-project?rev=348820=rev
Log:
[analyzer] Display a diagnostics when an inlined function violates its 
os_consumed summary

This is currently a diagnostics, but might be upgraded to an error in the 
future,
especially if we introduce os_return_on_success attributes.

rdar://46359592

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

Modified:

cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
cfe/trunk/test/Analysis/osobject-retain-release.cpp

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp?rev=348820=348819=348820=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 Mon Dec 10 17:13:40 2018
@@ -113,13 +113,11 @@ static bool shouldGenerateNote(llvm::raw
   return true;
 }
 
-static void generateDiagnosticsForCallLike(
-  ProgramStateRef CurrSt,
-  const LocationContext *LCtx,
-  const RefVal ,
-  SymbolRef ,
-  const Stmt *S,
-  llvm::raw_string_ostream ) {
+static void generateDiagnosticsForCallLike(ProgramStateRef CurrSt,
+   const LocationContext *LCtx,
+   const RefVal , SymbolRef ,
+   const Stmt *S,
+   llvm::raw_string_ostream ) {
   if (const CallExpr *CE = dyn_cast(S)) {
 // Get the name of the callee (if it is available)
 // from the tracked SVal.
@@ -137,8 +135,8 @@ static void generateDiagnosticsForCallLi
 } else {
   os << "function call";
 }
-  } else if (isa(S)){
-os << "Operator new";
+  } else if (isa(S)) {
+os << "Operator 'new'";
   } else {
 assert(isa(S));
 CallEventManager  = CurrSt->getStateManager().getCallEventManager();
@@ -230,9 +228,94 @@ public:
 } // end namespace ento
 } // end namespace clang
 
+
+/// Find the first node with the parent stack frame.
+static const ExplodedNode *getCalleeNode(const ExplodedNode *Pred) {
+  const StackFrameContext *SC = Pred->getStackFrame();
+  if (SC->inTopFrame())
+return nullptr;
+  const StackFrameContext *PC = SC->getParent()->getStackFrame();
+  if (!PC)
+return nullptr;
+
+  const ExplodedNode *N = Pred;
+  while (N && N->getStackFrame() != PC) {
+N = N->getFirstPred();
+  }
+  return N;
+}
+
+
+/// Insert a diagnostic piece at function exit
+/// if a function parameter is annotated as "os_consumed",
+/// but it does not actually consume the reference.
+static std::shared_ptr
+annotateConsumedSummaryMismatch(const ExplodedNode *N,
+CallExitBegin ,
+const SourceManager ,
+CallEventManager ) {
+
+  const ExplodedNode *CN = getCalleeNode(N);
+  if (!CN)
+return nullptr;
+
+  CallEventRef<> Call = CEMgr.getCaller(N->getStackFrame(), N->getState());
+
+  std::string sbuf;
+  llvm::raw_string_ostream os(sbuf);
+  ArrayRef Parameters = Call->parameters();
+  for (unsigned I=0; I < Call->getNumArgs() && I < Parameters.size(); ++I) {
+const ParmVarDecl *PVD = Parameters[I];
+
+if (!PVD->hasAttr())
+  return nullptr;
+
+if (SymbolRef SR = Call->getArgSVal(I).getAsLocSymbol()) {
+  const RefVal *CountBeforeCall = getRefBinding(CN->getState(), SR);
+  const RefVal *CountAtExit = getRefBinding(N->getState(), SR);
+
+  if (!CountBeforeCall || !CountAtExit)
+continue;
+
+  unsigned CountBefore = CountBeforeCall->getCount();
+  unsigned CountAfter = CountAtExit->getCount();
+
+  bool AsExpected = CountBefore > 0 && CountAfter == CountBefore - 1;
+  if (!AsExpected) {
+os << "Parameter '";
+PVD->getNameForDiagnostic(os, PVD->getASTContext().getPrintingPolicy(),
+  /*Qualified=*/false);
+os << "' is marked as consuming, but the function does not consume "
+   << "the reference\n";
+  }
+}
+  }
+
+  if (os.str().empty())
+return nullptr;
+
+  // FIXME: remove the code duplication with NoStoreFuncVisitor.
+  PathDiagnosticLocation L;
+  if (const ReturnStmt *RS = CallExitLoc.getReturnStmt()) {
+L = PathDiagnosticLocation::createBegin(RS, SM, N->getLocationContext());
+  } else {
+L = PathDiagnosticLocation(
+Call->getRuntimeDefinition().getDecl()->getSourceRange().getEnd(), SM);
+  }
+
+  return std::make_shared(L, os.str());
+}
+
 std::shared_ptr
 CFRefReportVisitor::VisitNode(const ExplodedNode *N,
   BugReporterContext , BugReport ) {
+  

[PATCH] D55528: [analyzer] Resolve another bug where the name of the leaked object was not printed properly

2018-12-10 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC348819: [analyzer] Resolve another bug where the name of the 
leaked object was not… (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55528?vs=177601=177631#toc

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55528/new/

https://reviews.llvm.org/D55528

Files:
  lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
  test/Analysis/osobject-retain-release.cpp


Index: lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -405,11 +405,11 @@
 
 if (FB) {
   const MemRegion *R = FB.getRegion();
-  const VarRegion *VR = R->getBaseRegion()->getAs();
   // Do not show local variables belonging to a function other than
   // where the error is reported.
-  if (!VR || VR->getStackFrame() == LeakContext->getStackFrame())
-FirstBinding = R;
+  if (auto MR = dyn_cast(R->getMemorySpace()))
+if (MR->getStackFrame() == LeakContext->getStackFrame())
+  FirstBinding = R;
 }
 
 // AllocationNode is the last node in which the symbol was tracked.
Index: test/Analysis/osobject-retain-release.cpp
===
--- test/Analysis/osobject-retain-release.cpp
+++ test/Analysis/osobject-retain-release.cpp
@@ -153,8 +153,8 @@
 
 unsigned int check_leak_explicit_new() {
   OSArray *arr = new OSArray; // expected-note{{Operator new returns an 
OSObject of type OSArray with a +1 retain count}}
-  return arr->getCount(); // expected-note{{Object leaked: allocated object of 
type OSArray is not referenced later in this execution path and has a retain 
count of +1}}
-  // expected-warning@-1{{Potential leak of an object 
of type OSArray}}
+  return arr->getCount(); // expected-note{{Object leaked: object allocated 
and stored into 'arr' is not referenced later in this execution path and has a 
retain count of +1}}
+  // expected-warning@-1{{Potential leak of an object 
stored into 'arr'}}
 }
 
 unsigned int check_leak_factory() {


Index: lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -405,11 +405,11 @@
 
 if (FB) {
   const MemRegion *R = FB.getRegion();
-  const VarRegion *VR = R->getBaseRegion()->getAs();
   // Do not show local variables belonging to a function other than
   // where the error is reported.
-  if (!VR || VR->getStackFrame() == LeakContext->getStackFrame())
-FirstBinding = R;
+  if (auto MR = dyn_cast(R->getMemorySpace()))
+if (MR->getStackFrame() == LeakContext->getStackFrame())
+  FirstBinding = R;
 }
 
 // AllocationNode is the last node in which the symbol was tracked.
Index: test/Analysis/osobject-retain-release.cpp
===
--- test/Analysis/osobject-retain-release.cpp
+++ test/Analysis/osobject-retain-release.cpp
@@ -153,8 +153,8 @@
 
 unsigned int check_leak_explicit_new() {
   OSArray *arr = new OSArray; // expected-note{{Operator new returns an OSObject of type OSArray with a +1 retain count}}
-  return arr->getCount(); // expected-note{{Object leaked: allocated object of type OSArray is not referenced later in this execution path and has a retain count of +1}}
-  // expected-warning@-1{{Potential leak of an object of type OSArray}}
+  return arr->getCount(); // expected-note{{Object leaked: object allocated and stored into 'arr' is not referenced later in this execution path and has a retain count of +1}}
+  // expected-warning@-1{{Potential leak of an object stored into 'arr'}}
 }
 
 unsigned int check_leak_factory() {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r348819 - [analyzer] Resolve another bug where the name of the leaked object was not printed properly

2018-12-10 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Dec 10 17:13:20 2018
New Revision: 348819

URL: http://llvm.org/viewvc/llvm-project?rev=348819=rev
Log:
[analyzer] Resolve another bug where the name of the leaked object was not 
printed properly

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

Modified:

cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
cfe/trunk/test/Analysis/osobject-retain-release.cpp

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp?rev=348819=348818=348819=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 Mon Dec 10 17:13:20 2018
@@ -405,11 +405,11 @@ static AllocationInfo GetAllocationSite(
 
 if (FB) {
   const MemRegion *R = FB.getRegion();
-  const VarRegion *VR = R->getBaseRegion()->getAs();
   // Do not show local variables belonging to a function other than
   // where the error is reported.
-  if (!VR || VR->getStackFrame() == LeakContext->getStackFrame())
-FirstBinding = R;
+  if (auto MR = dyn_cast(R->getMemorySpace()))
+if (MR->getStackFrame() == LeakContext->getStackFrame())
+  FirstBinding = R;
 }
 
 // AllocationNode is the last node in which the symbol was tracked.

Modified: cfe/trunk/test/Analysis/osobject-retain-release.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/osobject-retain-release.cpp?rev=348819=348818=348819=diff
==
--- cfe/trunk/test/Analysis/osobject-retain-release.cpp (original)
+++ cfe/trunk/test/Analysis/osobject-retain-release.cpp Mon Dec 10 17:13:20 2018
@@ -153,8 +153,8 @@ void check_free_use_after_free() {
 
 unsigned int check_leak_explicit_new() {
   OSArray *arr = new OSArray; // expected-note{{Operator new returns an 
OSObject of type OSArray with a +1 retain count}}
-  return arr->getCount(); // expected-note{{Object leaked: allocated object of 
type OSArray is not referenced later in this execution path and has a retain 
count of +1}}
-  // expected-warning@-1{{Potential leak of an object 
of type OSArray}}
+  return arr->getCount(); // expected-note{{Object leaked: object allocated 
and stored into 'arr' is not referenced later in this execution path and has a 
retain count of +1}}
+  // expected-warning@-1{{Potential leak of an object 
stored into 'arr'}}
 }
 
 unsigned int check_leak_factory() {


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


[PATCH] D55066: [ASan] Minor documentation fix: clarify static linking limitation.

2018-12-10 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis accepted this revision.
eugenis added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55066/new/

https://reviews.llvm.org/D55066



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


[PATCH] D55447: [Sema] Fix Modified Type in address_space AttributedType

2018-12-10 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added inline comments.



Comment at: clang/tools/libclang/CXType.cpp:132
+  if (!(TU->ParsingOptions & CXTranslationUnit_IncludeAttributedTypes) &&
+  ATT->getAttrKind() != attr::AddressSpace) {
 return MakeCXType(ATT->getModifiedType(), TU);

aaron.ballman wrote:
> leonardchan wrote:
> > aaron.ballman wrote:
> > > This change seems surprising -- if the parsing options say the caller 
> > > does not want attributed types, why are we returning one anyway for 
> > > address space?
> > This has to do with ensuring `clang_getAddressSpace` still returns the 
> > proper address_space. It does this by essentially checking the qualifiers 
> > of the type, which we now attach to the `AttributedType` whereas before it 
> > was attached to the modified type.
> > 
> > This extra condition is necessary for ensuring that calling 
> > `clang_getAddressSpace` points to the qualified AttributedType instead of 
> > the unqualified modified type.
> My fear is that this will be breaking assumptions in third-party code. If 
> someone disables `CXTranslationUnit_IncludeAttributedTypes`, they are 
> unlikely to expect to receive an `AttributedType` and may react poorly to it.
Instead check if the type is address_space attributed and apply the qualifiers 
the modified type.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55447/new/

https://reviews.llvm.org/D55447



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


[PATCH] D55447: [Sema] Fix Modified Type in address_space AttributedType

2018-12-10 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 177620.
leonardchan marked 2 inline comments as done.
leonardchan added a comment.

- Added the CXX11 test


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55447/new/

https://reviews.llvm.org/D55447

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/address_space_attribute.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -126,10 +126,15 @@
   CXTypeKind TK = CXType_Invalid;
 
   if (TU && !T.isNull()) {
+ASTContext  = cxtu::getASTUnit(TU)->getASTContext();
+
 // Handle attributed types as the original type
 if (auto *ATT = T->getAs()) {
   if (!(TU->ParsingOptions & CXTranslationUnit_IncludeAttributedTypes)) {
-return MakeCXType(ATT->getModifiedType(), TU);
+QualType ResultTy = ATT->getModifiedType();
+if (ATT->getAttrKind() == attr::AddressSpace)
+  ResultTy = Ctx.getAddrSpaceQualType(ResultTy, T.getAddressSpace());
+return MakeCXType(ResultTy, TU);
   }
 }
 // Handle paren types as the original type
@@ -137,7 +142,6 @@
   return MakeCXType(PTT->getInnerType(), TU);
 }
 
-ASTContext  = cxtu::getASTUnit(TU)->getASTContext();
 if (Ctx.getLangOpts().ObjC) {
   QualType UnqualT = T.getUnqualifiedType();
   if (Ctx.isObjCIdType(UnqualT))
Index: clang/test/AST/address_space_attribute.cpp
===
--- /dev/null
+++ clang/test/AST/address_space_attribute.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 %s -ast-dump | FileCheck %s
+
+// Veryify the ordering of the address_space attribute still comes before the
+// type whereas other attributes are still printed after.
+
+template 
+void func() {
+  // CHECK: VarDecl {{.*}} x '__attribute__((address_space(1))) int *'
+  __attribute__((address_space(1))) int *x;
+
+  // CHECK: VarDecl {{.*}} a 'int * __attribute__((noderef))'
+  int __attribute__((noderef)) * a;
+
+  // CHECK: VarDecl {{.*}} y '__attribute__((address_space(2))) int *'
+  __attribute__((address_space(I))) int *y;
+
+  // CHECK: VarDecl {{.*}} z '__attribute__((address_space(3))) int *'
+  [[clang::address_space(3)]] int *z;
+}
+
+void func2() {
+  func<2>();
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5740,28 +5740,27 @@
 // Type Attribute Processing
 //===--===//
 
-/// BuildAddressSpaceAttr - Builds a DependentAddressSpaceType if an expression
-/// is uninstantiated. If instantiated it will apply the appropriate address space
-/// to the type. This function allows dependent template variables to be used in
-/// conjunction with the address_space attribute
-QualType Sema::BuildAddressSpaceAttr(QualType , Expr *AddrSpace,
- SourceLocation AttrLoc) {
+/// Build an AddressSpace index from a constant expression and diagnose any
+/// errors related to invalid address_spaces. Returns true on successfully
+/// building an AddressSpace index.
+static bool BuildAddressSpaceIndex(Sema , LangAS ,
+   const Expr *AddrSpace,
+   SourceLocation AttrLoc) {
   if (!AddrSpace->isValueDependent()) {
-
 llvm::APSInt addrSpace(32);
-if (!AddrSpace->isIntegerConstantExpr(addrSpace, Context)) {
-  Diag(AttrLoc, diag::err_attribute_argument_type)
+if (!AddrSpace->isIntegerConstantExpr(addrSpace, S.Context)) {
+  S.Diag(AttrLoc, diag::err_attribute_argument_type)
   << "'address_space'" << AANT_ArgumentIntegerConstant
   << AddrSpace->getSourceRange();
-  return QualType();
+  return false;
 }
 
 // Bounds checking.
 if (addrSpace.isSigned()) {
   if (addrSpace.isNegative()) {
-Diag(AttrLoc, diag::err_attribute_address_space_negative)
+S.Diag(AttrLoc, diag::err_attribute_address_space_negative)
 << AddrSpace->getSourceRange();
-return QualType();
+return false;
   }
   addrSpace.setIsSigned(false);
 }
@@ -5770,14 +5769,28 @@
 max =
 Qualifiers::MaxAddressSpace - (unsigned)LangAS::FirstTargetAddressSpace;
 if (addrSpace > max) {
-  Diag(AttrLoc, diag::err_attribute_address_space_too_high)
+  S.Diag(AttrLoc, diag::err_attribute_address_space_too_high)
   << (unsigned)max.getZExtValue() << AddrSpace->getSourceRange();
-  return QualType();
+  return false;
 }
 
-LangAS ASIdx =
+ASIdx =
 getLangASFromTargetAS(static_cast(addrSpace.getZExtValue()));
+return true;
+  }
 
+  // Default value for 

[PATCH] D55424: [analyzer] Supply all checkers with a shouldRegister function

2018-12-10 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Should we also pass `CheckerManager` into `shouldRegister...`? Or is it 
entirely useless?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55424/new/

https://reviews.llvm.org/D55424



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


[PATCH] D55534: [AST] Store "UsesADL" information in CallExpr.

2018-12-10 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF created this revision.
EricWF added reviewers: fowles, rsmith, klimek.
Herald added a reviewer: shafik.

Currently the Clang AST doesn't store information about how the callee of a 
CallExpr was found. Specifically if it was found using ADL.

However, this information is invaluable to tooling. Consider a tool which 
renames usages of a function. If the originally CallExpr was formed using ADL, 
then the tooling may need to additionally qualify the replacement.
Without information about how the callee was found, the tooling is left 
scratching it's head. Additionally, we want to be able to match ADL calls as 
quickly as possible, which means avoiding computing the answer on the fly.

This patch changes `CallExpr` to store whether it's callee was found using ADL. 
It does not change the size of any AST nodes.


Repository:
  rC Clang

https://reviews.llvm.org/D55534

Files:
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/Stmt.h
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/Sema/Overload.h
  include/clang/Sema/Sema.h
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/AST/ast-dump-expr.cpp
  unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -199,6 +199,32 @@
"-fno-delayed-template-parsing"));
 }
 
+TEST(Matcher, ADLCall) {
+  StatementMatcher ADLMatch = callExpr(usesADL());
+  auto NS_Str = R"DELIM(
+  namespace NS {
+struct X {};
+struct Y {};
+void f(X);
+template 
+void g(T);
+  }
+  struct MyX {};
+  void f(...);
+  void g(...);
+)DELIM";
+
+  auto MkStr = [&](std::string Body) -> std::string {
+std::string S = NS_Str;
+S += "void test_fn() { " + Body + " }";
+return S;
+  };
+
+  EXPECT_TRUE(matches(MkStr("NS::X x; f(x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("NS::X x; NS::f(x);"), ADLMatch));
+  EXPECT_TRUE(notMatches(MkStr("MyX x; f(x);"), ADLMatch));
+}
+
 TEST(Matcher, Call) {
   // FIXME: Do we want to overload Call() to directly take
   // Matcher, too?
Index: test/AST/ast-dump-expr.cpp
===
--- /dev/null
+++ test/AST/ast-dump-expr.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=c++14 -ast-dump %s \
+// RUN:| FileCheck -strict-whitespace %s
+
+namespace NS {
+struct X {};
+void f(X);
+void y(...);
+} // namespace NS
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}ADLCall 'void ()'
+void ADLCall() {
+  NS::X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  f(x);
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  y(x);
+}
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall 'void ()'
+void NonADLCall() {
+  NS::X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  NS::f(x);
+}
+
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall2 'void ()'
+void NonADLCall2() {
+  NS::X x;
+  using NS::f;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  f(x);
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void' adl{{$}}
+  y(x);
+}
+
+namespace test_adl_call_three {
+using namespace NS;
+// CHECK-LABEL: FunctionDecl 0x{{[^ ]*}} {{.*}}NonADLCall3 'void ()'
+void NonADLCall3() {
+  X x;
+  // CHECK: CallExpr 0x{{[^ ]*}} ]+}}> 'void'{{$}}
+  f(x);
+}
+} // namespace test_adl_call_three
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -646,6 +646,7 @@
 void ASTStmtWriter::VisitCallExpr(CallExpr *E) {
   VisitExpr(E);
   Record.push_back(E->getNumArgs());
+  Record.push_back(E->usesADL());
   Record.AddSourceLocation(E->getRParenLoc());
   Record.AddStmt(E->getCallee());
   for (CallExpr::arg_iterator Arg = E->arg_begin(), ArgEnd = E->arg_end();
Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -732,11 +732,13 @@
 void ASTStmtReader::VisitCallExpr(CallExpr *E) {
   VisitExpr(E);
   unsigned NumArgs = Record.readInt();
+  bool UsesADL = Record.readInt();
   assert((NumArgs == E->getNumArgs()) && "Wrong NumArgs!");
   E->setRParenLoc(ReadSourceLocation());
   E->setCallee(Record.readSubExpr());
   for (unsigned I = 0; I != NumArgs; ++I)
 E->setArg(I, Record.readSubExpr());
+  E->setUsesADL(UsesADL);
 }
 
 void ASTStmtReader::VisitCXXMemberCallExpr(CXXMemberCallExpr *E) {
Index: lib/Sema/SemaOverload.cpp
===
--- 

[PATCH] D55510: [ExprConstant] Improve memchr/memcmp for type mismatch and multibyte element types

2018-12-10 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast marked an inline comment as done.
hubert.reinterpretcast added inline comments.



Comment at: lib/AST/ExprConstant.cpp:6147-6148
+  return ZeroInitialization(E);
+if (!Result.checkNullPointerForFoldAccess(Info, E, AK_Read))
+  return false;
+QualType CharTy =

rsmith wrote:
> Why do we need to do this explicitly, rather than allowing to simply happen 
> as part of the first `handleLValueToRValueConversion` below?
We want the error message to be produced even if we bail early on not having a 
valid designator.



Comment at: lib/AST/ExprConstant.cpp:6150
+QualType CharTy =
+Info.Ctx.getBaseElementType(getType(Result.getLValueBase()));
+const bool IsRawByte = BuiltinOp == Builtin::BImemchr ||

rsmith wrote:
> Considering the LValue base here is incorrect. The object or array we're 
> copying could be a subobject, and the complete object type (the type of the 
> lvalue base) is irrelevant for such copies. Use 
> `Result.Designator.getType(Info.Ctx)` to find the type that the lvalue 
> designates. (You can bail out here if the designator is invalid; 
> `handleLValueToRValueConversion` will always fail on such cases anyway.
Got it; I also updated the tests to be sensitive to this issue.



Comment at: test/CodeGenCXX/builtins.cpp:41
+matchedFirstByteIn04030201();
+// CHECK: call void 
@_ZN27MemchrMultibyteElementTests26matchedFirstByteIn04030201Ev()
+  }

rsmith wrote:
> hubert.reinterpretcast wrote:
> > rsmith wrote:
> > > Please test this in a way that doesn't rely on IR generation 
> > > constant-evaluating `if` conditions. Moreover, there's nothing about IR 
> > > generation that you're actually testing here, so please phrase this as a 
> > > `Sema` test instead (eg, check that a VLA bound gets folded to a 
> > > constant). Likewise for the other tests below.
> > Not all of these cases can fold successfully with the current 
> > implementation. The check would need to be that we either fold (and get the 
> > right value), or don't fold at all.
> Seems fine to have a test that we don't fold certain cases at all, with a 
> comment saying that it's OK if we start folding them to a constant and what 
> that constant should be.
> 
> Generally the principle is that we want our unit tests to test as few layers 
> of the stack as possible; the chosen test directory should ideally correspond 
> to the layer under test. If you'd really like this to be more of an 
> integration test, that's fine too (eg, if you have code like this in a 
> platform header that really must be handled a certain way), but then it would 
> belong in `test/Integration`. If you do put it in `test/Integration`, it'd 
> then be reasonable to include -O in the test flags too, if that makes sense 
> for what you want to test.
I think a `SemaCXX` test based on the following pattern would work:
```
constexpr decltype(sizeof 0) Good = 42, Bad = 43;
template  struct A;
struct NotBad {};
template <> struct A : NotBad {};

template  A *evalFor(T (&)[N]);
NotBad *evalFor(...);
void chk(NotBad *);

void f() {
  int x[__builtin_memcmp("", "", 1) == 0 ? Good : Bad];
  chk(evalFor(x));
}
```


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55510/new/

https://reviews.llvm.org/D55510



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


[PATCH] D55510: [ExprConstant] Improve memchr/memcmp for type mismatch and multibyte element types

2018-12-10 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast updated this revision to Diff 177618.
hubert.reinterpretcast marked 6 inline comments as done.
hubert.reinterpretcast added a comment.

Use lvalue designator, add assertions for type matching


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55510/new/

https://reviews.llvm.org/D55510

Files:
  include/clang/Basic/DiagnosticASTKinds.td
  lib/AST/ExprConstant.cpp
  test/CodeGenCXX/builtins.cpp
  test/SemaCXX/constexpr-string.cpp

Index: test/SemaCXX/constexpr-string.cpp
===
--- test/SemaCXX/constexpr-string.cpp
+++ test/SemaCXX/constexpr-string.cpp
@@ -95,6 +95,52 @@
   static_assert(__builtin_memcmp("abab\0banana", "abab\0canada", 6) == -1);
   static_assert(__builtin_memcmp("abab\0banana", "abab\0canada", 5) == 0);
 
+  extern struct Incomplete incomplete;
+  static_assert(__builtin_memcmp(, "", 0u) == 0);
+  static_assert(__builtin_memcmp("", , 0u) == 0);
+  static_assert(__builtin_memcmp(, "", 1u) == 42); // expected-error {{not an integral constant}} expected-note {{read of incomplete type 'struct Incomplete'}}
+  static_assert(__builtin_memcmp("", , 1u) == 42); // expected-error {{not an integral constant}} expected-note {{read of incomplete type 'struct Incomplete'}}
+
+  constexpr unsigned char ku00fe00[] = {0x00, 0xfe, 0x00};
+  constexpr unsigned char ku00feff[] = {0x00, 0xfe, 0xff};
+  constexpr signed char ks00fe00[] = {0, -2, 0};
+  constexpr signed char ks00feff[] = {0, -2, -1};
+  static_assert(__builtin_memcmp(ku00feff, ks00fe00, 2) == 0);
+  static_assert(__builtin_memcmp(ku00feff, ks00fe00, 99) == 1);
+  static_assert(__builtin_memcmp(ku00fe00, ks00feff, 99) == -1);
+  static_assert(__builtin_memcmp(ks00feff, ku00fe00, 2) == 0);
+  static_assert(__builtin_memcmp(ks00feff, ku00fe00, 99) == 1);
+  static_assert(__builtin_memcmp(ks00fe00, ku00feff, 99) == -1);
+  static_assert(__builtin_memcmp(ks00fe00, ks00feff, 2) == 0);
+  static_assert(__builtin_memcmp(ks00feff, ks00fe00, 99) == 1);
+  static_assert(__builtin_memcmp(ks00fe00, ks00feff, 99) == -1);
+
+  struct Bool3Tuple { bool bb[3]; };
+  constexpr Bool3Tuple kb000100 = {{false, true, false}};
+  static_assert(sizeof(bool) != 1u || __builtin_memcmp(ks00fe00, kb000100.bb, 1) == 0);
+  static_assert(sizeof(bool) != 1u || __builtin_memcmp(ks00fe00, kb000100.bb, 2) == 1);
+
+  constexpr long ksl[] = {0, -1};
+  constexpr unsigned int kui[] = {0, 0u - 1};
+  constexpr unsigned long long kull[] = {0, 0ull - 1};
+  constexpr const auto *kuSizeofLong(void) {
+if constexpr(sizeof(long) == sizeof(int)) {
+  return kui;
+} else {
+  static_assert(sizeof(long) == sizeof(long long));
+  return kull;
+}
+  }
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), sizeof(long) - 1) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), sizeof(long) + 0) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), sizeof(long) + 1) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), 2*sizeof(long) - 1) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), 2*sizeof(long) + 0) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), 2*sizeof(long) + 1) == 42); // expected-error {{not an integral constant}} expected-note {{dereferenced one-past-the-end}}
+  static_assert(__builtin_memcmp(ksl + 1, kuSizeofLong() + 1, sizeof(long) - 1) == 0);
+  static_assert(__builtin_memcmp(ksl + 1, kuSizeofLong() + 1, sizeof(long) + 0) == 0);
+  static_assert(__builtin_memcmp(ksl + 1, kuSizeofLong() + 1, sizeof(long) + 1) == 42); // expected-error {{not an integral constant}} expected-note {{dereferenced one-past-the-end}}
+
   constexpr int a = strcmp("hello", "world"); // expected-error {{constant expression}} expected-note {{non-constexpr function 'strcmp' cannot be used in a constant expression}}
   constexpr int b = strncmp("hello", "world", 3); // expected-error {{constant expression}} expected-note {{non-constexpr function 'strncmp' cannot be used in a constant expression}}
   constexpr int c = memcmp("hello", "world", 3); // expected-error {{constant expression}} expected-note {{non-constexpr function 'memcmp' cannot be used in a constant expression}}
@@ -187,6 +233,27 @@
   static_assert(__builtin_memchr(nullptr, 'x', 3) == nullptr); // expected-error {{not an integral constant}} expected-note {{dereferenced null}}
   static_assert(__builtin_memchr(nullptr, 'x', 0) == nullptr); // FIXME: Should we reject this?
 
+  extern struct Incomplete incomplete;
+  static_assert(__builtin_memchr(, 0, 0u) == nullptr);
+  static_assert(__builtin_memchr(, 0, 1u) == nullptr); // expected-error {{not an integral constant}} expected-note {{read of incomplete type 'struct Incomplete'}}
+
+  const unsigned char  = 0xf0;
+  auto & = (const signed char []){-128}; // expected-warning {{compound literals are a C99-specific feature}}
+  static_assert(__builtin_memchr(, -(0x0f + 1), 1) == );
+  

[PATCH] D55482: [clang-tidy] Improve google-objc-function-naming diagnostics 

2018-12-10 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore marked 4 inline comments as done.
stephanemoore added inline comments.



Comment at: clang-tidy/google/FunctionNamingCheck.cpp:114-118
   diag(MatchedDecl->getLocation(),
-   "function name %0 not using function naming conventions described by "
-   "Google Objective-C style guide")
-  << MatchedDecl << generateFixItHint(MatchedDecl);
+   "%select{static|global}1 function name %0 must %select{be in|have an "
+   "appropriate prefix followed by}1 Pascal case as required by Google "
+   "Objective-C style guide")
+  << MatchedDecl << IsGlobal << generateFixItHint(MatchedDecl);

benhamilton wrote:
> Should we suggest making the function static when it fails this check? (I 
> assume the vast majority of functions which fail this check should really be 
> static.)
Are you asking whether we should suggest making global functions static when 
they are missing appropriate prefixes? If so, I think that would lead to 
undesired changes in various cases.

One common cause of this style violation is when someone endeavors to take a 
static function that is used in one translation unit and share it with other 
translation units by migrating it to a header. The Easy™ thing to do is migrate 
that static function to a header and convert it directly to a global function, 
avoiding the overhead of refactoring the function name and all call sites. The 
effort of the described refactoring approach is low compared to renaming the 
function to avoid symbol collisions in the global namespace as is generally 
recommended.

If a function's definition and declaration (if it exists) are both in an 
implementation file we can probably recommend making the function static 
though. Filed https://bugs.llvm.org/show_bug.cgi?id=39945.



Comment at: clang-tidy/google/FunctionNamingCheck.cpp:115
   diag(MatchedDecl->getLocation(),
-   "function name %0 not using function naming conventions described by "
-   "Google Objective-C style guide")
-  << MatchedDecl << generateFixItHint(MatchedDecl);
+   "%select{static|global}1 function name %0 must %select{be in|have an "
+   "appropriate prefix followed by}1 Pascal case as required by Google "

benhamilton wrote:
> I know "global" is the correct name, but I feel like "non-static" might be 
> clearer to folks dealing with these error messages.
> 
> WDYT?
> 
I'm wary of saying "non-static" because namespaced functions in Objective-C++ 
are not subject to the cited rules. The term "non-static" seems like it could 
be interpreted to extend to namespaced functions which could potentially 
mislead someone into adding prefixes to namespaced functions in Objective-C++.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55482/new/

https://reviews.llvm.org/D55482



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


[PATCH] D55482: [clang-tidy] Improve google-objc-function-naming diagnostics 

2018-12-10 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added inline comments.



Comment at: clang-tidy/google/FunctionNamingCheck.cpp:114-125
+  if (MatchedDecl->getStorageClass() == SC_Static) {
+diag(MatchedDecl->getLocation(),
+ "static function name %0 must be in Pascal case as required by "
+ "Google Objective-C style guide")
+<< MatchedDecl << generateFixItHint(MatchedDecl);
+return;
+  }

aaron.ballman wrote:
> I'd rather see these diagnostics combined: `%select{static|global}1 function 
> name %0 must %select{be in |have an appropriate prefixed followed by "}1 
> Pascal case as required by the Google Objective-C style guide` to simplify 
> the logic (since `generateFixItHint()` already does the right thing).
I had no idea about the select modifier! Good idea!



Comment at: test/clang-tidy/google-objc-function-naming.m:8
+// must be in Pascal case as required by Google Objective-C style guide
 // CHECK-FIXES: static bool Ispositive(int a) { return a > 0; }
 

MyDeveloperDay wrote:
> I realize there are words that begin with 'is...' but you could detect if the 
> function returned a boolean and started with "is,has,does" and could this 
> extrapolate to  IsPositive()  HasSomething(), DoesHaveSomething(),  this 
> might generate a better fixit candidate? (just a suggestion feel free to 
> ignore)
Sounds like something worth investigating.

Filed https://bugs.llvm.org/show_bug.cgi?id=39941


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55482/new/

https://reviews.llvm.org/D55482



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


[PATCH] D55482: [clang-tidy] Improve google-objc-function-naming diagnostics 

2018-12-10 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton accepted this revision.
benhamilton added a comment.
This revision is now accepted and ready to land.

Thanks, just minor suggestions.




Comment at: clang-tidy/google/FunctionNamingCheck.cpp:114-118
   diag(MatchedDecl->getLocation(),
-   "function name %0 not using function naming conventions described by "
-   "Google Objective-C style guide")
-  << MatchedDecl << generateFixItHint(MatchedDecl);
+   "%select{static|global}1 function name %0 must %select{be in|have an "
+   "appropriate prefix followed by}1 Pascal case as required by Google "
+   "Objective-C style guide")
+  << MatchedDecl << IsGlobal << generateFixItHint(MatchedDecl);

Should we suggest making the function static when it fails this check? (I 
assume the vast majority of functions which fail this check should really be 
static.)



Comment at: clang-tidy/google/FunctionNamingCheck.cpp:115
   diag(MatchedDecl->getLocation(),
-   "function name %0 not using function naming conventions described by "
-   "Google Objective-C style guide")
-  << MatchedDecl << generateFixItHint(MatchedDecl);
+   "%select{static|global}1 function name %0 must %select{be in|have an "
+   "appropriate prefix followed by}1 Pascal case as required by Google "

I know "global" is the correct name, but I feel like "non-static" might be 
clearer to folks dealing with these error messages.

WDYT?



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55482/new/

https://reviews.llvm.org/D55482



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


[PATCH] D55482: [clang-tidy] Improve google-objc-function-naming diagnostics 

2018-12-10 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore updated this revision to Diff 177609.
stephanemoore marked 4 inline comments as done.
stephanemoore added a comment.

Use the select modifier to customize diagnostics for static and non-static 
function instead of branching diagnostic code paths for static and non-static 
functions.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55482/new/

https://reviews.llvm.org/D55482

Files:
  clang-tidy/google/FunctionNamingCheck.cpp
  test/clang-tidy/google-objc-function-naming.m
  test/clang-tidy/google-objc-function-naming.mm

Index: test/clang-tidy/google-objc-function-naming.mm
===
--- test/clang-tidy/google-objc-function-naming.mm
+++ test/clang-tidy/google-objc-function-naming.mm
@@ -1,16 +1,19 @@
 // RUN: %check_clang_tidy %s google-objc-function-naming %t
 
 void printSomething() {}
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function name 'printSomething' not
-// using function naming conventions described by Google Objective-C style guide
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: global function name
+// 'printSomething' must have an appropriate prefix followed by Pascal case as
+// required by Google Objective-C style guide
 
 void PrintSomething() {}
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function name 'PrintSomething' not
-// using function naming conventions described by Google Objective-C style guide
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: global function name
+// 'PrintSomething' must have an appropriate prefix followed by Pascal case as
+// required by Google Objective-C style guide
 
 void ABCBad_Name() {}
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function name 'ABCBad_Name' not
-// using function naming conventions described by Google Objective-C style guide
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: global function name 'ABCBad_Name'
+// must have an appropriate prefix followed by Pascal case as required by Google
+// Objective-C style guide
 
 namespace {
 
Index: test/clang-tidy/google-objc-function-naming.m
===
--- test/clang-tidy/google-objc-function-naming.m
+++ test/clang-tidy/google-objc-function-naming.m
@@ -3,28 +3,35 @@
 typedef _Bool bool;
 
 static bool ispositive(int a) { return a > 0; }
-// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'ispositive' not using function naming conventions described by Google Objective-C style guide
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: static function name 'ispositive'
+// must be in Pascal case as required by Google Objective-C style guide
 // CHECK-FIXES: static bool Ispositive(int a) { return a > 0; }
 
 static bool is_positive(int a) { return a > 0; }
-// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'is_positive' not using function naming conventions described by Google Objective-C style guide
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: static function name 'is_positive'
+// must be in Pascal case as required by Google Objective-C style guide
 // CHECK-FIXES: static bool IsPositive(int a) { return a > 0; }
 
 static bool isPositive(int a) { return a > 0; }
-// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'isPositive' not using function naming conventions described by Google Objective-C style guide
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: static function name 'isPositive'
+// must be in Pascal case as required by Google Objective-C style guide
 // CHECK-FIXES: static bool IsPositive(int a) { return a > 0; }
 
 static bool Is_Positive(int a) { return a > 0; }
-// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function name 'Is_Positive' not using function naming conventions described by Google Objective-C style guide
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: static function name 'Is_Positive'
+// must be in Pascal case as required by Google Objective-C style guide
 // CHECK-FIXES: static bool IsPositive(int a) { return a > 0; }
 
 static bool IsPositive(int a) { return a > 0; }
 
 bool ispalindrome(const char *str);
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function name 'ispalindrome' not using function naming conventions described by Google Objective-C style guide
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: global function name 'ispalindrome'
+// must have an appropriate prefix followed by Pascal case as required by Google
+// Objective-C style guide
 
 static const char *md5(const char *str) { return 0; }
-// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: function name 'md5' not using function naming conventions described by Google Objective-C style guide
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: static function name 'md5' must be
+// in Pascal case as required by Google Objective-C style guide
 // CHECK-FIXES: static const char *Md5(const char *str) { return 0; }
 
 static const char *MD5(const char *str) { return 0; }
@@ -38,12 +45,16 @@
 static const char *StringFromNSString(id str) { return ""; }
 
 void ABLog_String(const 

[PATCH] D55510: [ExprConstant] Improve memchr/memcmp for type mismatch and multibyte element types

2018-12-10 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/AST/ExprConstant.cpp:8465
+return false;
+  uint64_t LengthPerElement{CharTy1Width / Info.Ctx.getCharWidth()};
+  assert(MaxLength && "MaxLength should not be zero: the following loop "

Use `toCharUnitsFromBits` here, and use `CharUnits` as a type-safe way of 
representing a size in terms of a number of `char`s. In fact, consider using 
`getTypeSizeInChars` a few lines above and only operating in `char`s, never 
bits.



Comment at: lib/AST/ExprConstant.cpp:8471-8476
+// We have compatible in-memory widths, but a possible type and 
internal
+// representation mismatch. Assuming two's complement representation,
+// including 0 for `false` and 1 for `true`, we can check an 
appropriate
+// number of elements for equality even if they are not byte-sized.
+const APSInt Char1InMem = Char1.getInt().extOrTrunc(CharTy1Width);
+const APSInt Char2InMem = Char2.getInt().extOrTrunc(CharTy1Width);

hubert.reinterpretcast wrote:
> rsmith wrote:
> > The *only* possible problem here is for `bool`, right? This comment would 
> > be clearer if it said that.
> We do assume two's complement representation (which C89 does not require to 
> be true); so, `bool` is more problematic than other things, but the comment 
> is not just about `bool`.
There is no type other than `bool` that needs the `extOrTrunc`; maybe drop the 
"especially"?



Comment at: lib/AST/ExprConstant.cpp:8488-8489
+  return false;
+if (MaxLength <= LengthPerElement)
+  break;
+MaxLength -= LengthPerElement;

hubert.reinterpretcast wrote:
> rsmith wrote:
> > This looks wrong. If `0 < MaxLength && MaxLength < LengthPerElement`, we're 
> > supposed to compare *part of* the next element; this current approach 
> > doesn't do that. (If you did one more full-element compare, that'd be 
> > conservatively correct because we're only checking for equality, not 
> > ordering, but perhaps we should only permit cases where `MaxLength` is a 
> > multiple of `LengthPerElement`?
> We //are// doing one more full-element compare to be conservatively correct. 
> There is a test for that.
Oh, I see now. Right. :)

Maybe add "Be careful not to compare more than MaxLength bytes" to the FIXME 
above, so a future maintainer doesn't get confused?



Comment at: test/CodeGenCXX/builtins.cpp:41
+matchedFirstByteIn04030201();
+// CHECK: call void 
@_ZN27MemchrMultibyteElementTests26matchedFirstByteIn04030201Ev()
+  }

hubert.reinterpretcast wrote:
> rsmith wrote:
> > Please test this in a way that doesn't rely on IR generation 
> > constant-evaluating `if` conditions. Moreover, there's nothing about IR 
> > generation that you're actually testing here, so please phrase this as a 
> > `Sema` test instead (eg, check that a VLA bound gets folded to a constant). 
> > Likewise for the other tests below.
> Not all of these cases can fold successfully with the current implementation. 
> The check would need to be that we either fold (and get the right value), or 
> don't fold at all.
Seems fine to have a test that we don't fold certain cases at all, with a 
comment saying that it's OK if we start folding them to a constant and what 
that constant should be.

Generally the principle is that we want our unit tests to test as few layers of 
the stack as possible; the chosen test directory should ideally correspond to 
the layer under test. If you'd really like this to be more of an integration 
test, that's fine too (eg, if you have code like this in a platform header that 
really must be handled a certain way), but then it would belong in 
`test/Integration`. If you do put it in `test/Integration`, it'd then be 
reasonable to include -O in the test flags too, if that makes sense for what 
you want to test.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55510/new/

https://reviews.llvm.org/D55510



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


r348809 - Update test for instcombine change

2018-12-10 Thread Matt Arsenault via cfe-commits
Author: arsenm
Date: Mon Dec 10 15:02:40 2018
New Revision: 348809

URL: http://llvm.org/viewvc/llvm-project?rev=348809=rev
Log:
Update test for instcombine change

Modified:
cfe/trunk/test/CodeGen/vector.c

Modified: cfe/trunk/test/CodeGen/vector.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vector.c?rev=348809=348808=348809=diff
==
--- cfe/trunk/test/CodeGen/vector.c (original)
+++ cfe/trunk/test/CodeGen/vector.c Mon Dec 10 15:02:40 2018
@@ -70,7 +70,7 @@ vec_int1 lax_vector_compare1(int x, vec_
 }
 
 // CHECK: define i32 @lax_vector_compare1(i32 {{.*}}, i32 {{.*}})
-// CHECK: icmp eq <1 x i32>
+// CHECK: icmp eq i32
 
 typedef int vec_int2 __attribute__((vector_size(8)));
 vec_int2 lax_vector_compare2(long long x, vec_int2 y) {


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


[PATCH] D54604: Automatic variable initialization

2018-12-10 Thread JF Bastien via Phabricator via cfe-commits
jfb updated this revision to Diff 177600.
jfb added a comment.

- Make sure uninit-variables.c doesn't break.
- Address Peter's comments, improve tests.
- Add an ugly option to enable zero init
- Update warning-flags.c
- Fix typo
- Use negative NaN with repeated 0xFF payload for all floating-point types. 
This is potentially faster to initialize than pure positive no-payload NaNs.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54604/new/

https://reviews.llvm.org/D54604

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Driver/Options.td
  include/clang/Driver/ToolChain.h
  lib/CodeGen/CGDecl.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/auto-var-init.cpp
  test/CodeGenCXX/trivial-auto-var-init-attribute.cpp
  test/CodeGenCXX/trivial-auto-var-init.cpp
  test/Driver/clang_f_opts.c
  test/Misc/warning-flags.c
  test/Sema/attr-trivial_auto_init.c
  test/Sema/uninit-variables.c

Index: test/Sema/uninit-variables.c
===
--- test/Sema/uninit-variables.c
+++ test/Sema/uninit-variables.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wconditional-uninitialized -fsyntax-only -fblocks %s -verify
+// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -Wconditional-uninitialized -ftrivial-auto-var-init=pattern -fsyntax-only -fblocks %s -verify
 
 typedef __typeof(sizeof(int)) size_t;
 void *malloc(size_t);
Index: test/Sema/attr-trivial_auto_init.c
===
--- /dev/null
+++ test/Sema/attr-trivial_auto_init.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+void good() {
+int dont_initialize_me __attribute((trivial_auto_init("uninitialized")));
+int zero_me __attribute((trivial_auto_init("zero")));
+int pattern_me __attribute((trivial_auto_init("pattern")));
+}
+
+void bad() {
+int im_bad __attribute((trivial_auto_init)); // expected-error {{'trivial_auto_init' attribute takes one argument}}
+int im_baaad __attribute((trivial_auto_init("uninitialized", "zero"))); // expected-error {{'trivial_auto_init' attribute takes one argument}}
+static int come_on __attribute((trivial_auto_init("uninitialized"))); // expected-warning {{'trivial_auto_init' attribute only applies to local variables}}
+int you_know __attribute((trivial_auto_init("pony"))); // expected-warning {{'trivial_auto_init' attribute argument not supported: pony}}
+int and_the_whole_world_has_to __attribute((trivial_auto_init(uninitialized))); // expected-error {{'trivial_auto_init' attribute requires a string}}
+}
+
+extern int answer_right_now __attribute((trivial_auto_init("uninitialized"))); // expected-warning {{'trivial_auto_init' attribute only applies to local variables}}
+int just_to_tell_you_once_again __attribute((trivial_auto_init("uninitialized"))); // expected-warning {{'trivial_auto_init' attribute only applies to local variables}}
+static int whos_bad __attribute((trivial_auto_init("uninitialized"))); // expected-warning {{'trivial_auto_init' attribute only applies to local variables}}
+
+void the_word_is_out() __attribute((trivial_auto_init("uninitialized"))) {} // expected-warning {{'trivial_auto_init' attribute only applies to local variables}}
+void youre_doin_wrong(__attribute((trivial_auto_init("uninitialized"))) int a) {} // expected-warning {{'trivial_auto_init' attribute only applies to local variables}}
+
+struct GonnaLockYouUp {
+  __attribute((trivial_auto_init("uninitialized"))) int before_too_long; // expected-warning {{'trivial_auto_init' attribute only applies to local variables}}
+} __attribute((trivial_auto_init("uninitialized"))); // expected-warning {{'trivial_auto_init' attribute only applies to local variables}}
Index: test/Misc/warning-flags.c
===
--- test/Misc/warning-flags.c
+++ test/Misc/warning-flags.c
@@ -18,7 +18,7 @@
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (75):
+CHECK: Warnings without flags (76):
 CHECK-NEXT:   ext_excess_initializers
 CHECK-NEXT:   ext_excess_initializers_in_char_array_initializer
 CHECK-NEXT:   ext_expected_semi_decl_list
@@ -53,6 +53,7 @@
 CHECK-NEXT:   warn_drv_assuming_mfloat_abi_is
 CHECK-NEXT:   warn_drv_clang_unsupported
 CHECK-NEXT:   warn_drv_pch_not_first_include
+CHECK-NEXT:   warn_drv_trivial_auto_var_init_zero_disabled
 CHECK-NEXT:   warn_dup_category_def
 CHECK-NEXT:   warn_enum_value_overflow
 CHECK-NEXT:   warn_expected_qualified_after_typename
Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ 

[PATCH] D55510: [ExprConstant] Improve memchr/memcmp for type mismatch and multibyte element types

2018-12-10 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast updated this revision to Diff 177597.
hubert.reinterpretcast marked 11 inline comments as done.
hubert.reinterpretcast added a comment.

Make an initial pass at addressing the review comments

Address comments on style and code comments


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55510/new/

https://reviews.llvm.org/D55510

Files:
  include/clang/Basic/DiagnosticASTKinds.td
  lib/AST/ExprConstant.cpp
  test/CodeGenCXX/builtins.cpp
  test/SemaCXX/constexpr-string.cpp

Index: test/SemaCXX/constexpr-string.cpp
===
--- test/SemaCXX/constexpr-string.cpp
+++ test/SemaCXX/constexpr-string.cpp
@@ -95,6 +95,51 @@
   static_assert(__builtin_memcmp("abab\0banana", "abab\0canada", 6) == -1);
   static_assert(__builtin_memcmp("abab\0banana", "abab\0canada", 5) == 0);
 
+  extern struct Incomplete incomplete;
+  static_assert(__builtin_memcmp(, "", 0u) == 0);
+  static_assert(__builtin_memcmp("", , 0u) == 0);
+  static_assert(__builtin_memcmp(, "", 1u) == 42); // expected-error {{not an integral constant}} expected-note {{read of incomplete type 'struct Incomplete'}}
+  static_assert(__builtin_memcmp("", , 1u) == 42); // expected-error {{not an integral constant}} expected-note {{read of incomplete type 'struct Incomplete'}}
+
+  constexpr unsigned char ku00fe00[] = {0x00, 0xfe, 0x00};
+  constexpr unsigned char ku00feff[] = {0x00, 0xfe, 0xff};
+  constexpr signed char ks00fe00[] = {0, -2, 0};
+  constexpr signed char ks00feff[] = {0, -2, -1};
+  static_assert(__builtin_memcmp(ku00feff, ks00fe00, 2) == 0);
+  static_assert(__builtin_memcmp(ku00feff, ks00fe00, 99) == 1);
+  static_assert(__builtin_memcmp(ku00fe00, ks00feff, 99) == -1);
+  static_assert(__builtin_memcmp(ks00feff, ku00fe00, 2) == 0);
+  static_assert(__builtin_memcmp(ks00feff, ku00fe00, 99) == 1);
+  static_assert(__builtin_memcmp(ks00fe00, ku00feff, 99) == -1);
+  static_assert(__builtin_memcmp(ks00fe00, ks00feff, 2) == 0);
+  static_assert(__builtin_memcmp(ks00feff, ks00fe00, 99) == 1);
+  static_assert(__builtin_memcmp(ks00fe00, ks00feff, 99) == -1);
+
+  constexpr bool kb000100[] = {false, true, false};
+  static_assert(sizeof(bool) != 1u || __builtin_memcmp(ks00fe00, kb000100, 1) == 0);
+  static_assert(sizeof(bool) != 1u || __builtin_memcmp(ks00fe00, kb000100, 2) == 1);
+
+  constexpr long ksl[] = {0, -1};
+  constexpr unsigned int kui[] = {0, 0u - 1};
+  constexpr unsigned long long kull[] = {0, 0ull - 1};
+  constexpr const auto *kuSizeofLong(void) {
+if constexpr(sizeof(long) == sizeof(int)) {
+  return kui;
+} else {
+  static_assert(sizeof(long) == sizeof(long long));
+  return kull;
+}
+  }
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), sizeof(long) - 1) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), sizeof(long) + 0) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), sizeof(long) + 1) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), 2*sizeof(long) - 1) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), 2*sizeof(long) + 0) == 0);
+  static_assert(__builtin_memcmp(ksl, kuSizeofLong(), 2*sizeof(long) + 1) == 42); // expected-error {{not an integral constant}} expected-note {{dereferenced one-past-the-end}}
+  static_assert(__builtin_memcmp(ksl + 1, kuSizeofLong() + 1, sizeof(long) - 1) == 0);
+  static_assert(__builtin_memcmp(ksl + 1, kuSizeofLong() + 1, sizeof(long) + 0) == 0);
+  static_assert(__builtin_memcmp(ksl + 1, kuSizeofLong() + 1, sizeof(long) + 1) == 42); // expected-error {{not an integral constant}} expected-note {{dereferenced one-past-the-end}}
+
   constexpr int a = strcmp("hello", "world"); // expected-error {{constant expression}} expected-note {{non-constexpr function 'strcmp' cannot be used in a constant expression}}
   constexpr int b = strncmp("hello", "world", 3); // expected-error {{constant expression}} expected-note {{non-constexpr function 'strncmp' cannot be used in a constant expression}}
   constexpr int c = memcmp("hello", "world", 3); // expected-error {{constant expression}} expected-note {{non-constexpr function 'memcmp' cannot be used in a constant expression}}
@@ -187,6 +232,26 @@
   static_assert(__builtin_memchr(nullptr, 'x', 3) == nullptr); // expected-error {{not an integral constant}} expected-note {{dereferenced null}}
   static_assert(__builtin_memchr(nullptr, 'x', 0) == nullptr); // FIXME: Should we reject this?
 
+  extern struct Incomplete incomplete;
+  static_assert(__builtin_memchr(, 0, 0u) == nullptr);
+  static_assert(__builtin_memchr(, 0, 1u) == nullptr); // expected-error {{not an integral constant}} expected-note {{read of incomplete type 'struct Incomplete'}}
+
+  const unsigned char  = 0xf0;
+  auto & = (const signed char []){-128}; // expected-warning {{compound literals are a C99-specific feature}}
+  static_assert(__builtin_memchr(, -(0x0f + 1), 1) == );
+  

[PATCH] D55510: [ExprConstant] Improve memchr/memcmp for type mismatch and multibyte element types

2018-12-10 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: lib/AST/ExprConstant.cpp:6159-6160
+// Give up on byte-oriented matching against multibyte elements.
+if (IsRawByte && Info.Ctx.getTypeSize(CharTy) > Info.Ctx.getCharWidth())
+  return false;
 // Figure out what value we're actually looking for (after converting to

rsmith wrote:
> Please add an assert here that the types do match in the non-raw-byte case. 
> (They must, or the subobject designator would be invalid; the only special 
> case is that a `void*` can point to anything, and only the `memchr` variants 
> here take a `void*`.)
Will do.



Comment at: lib/AST/ExprConstant.cpp:8471-8476
+// We have compatible in-memory widths, but a possible type and 
internal
+// representation mismatch. Assuming two's complement representation,
+// including 0 for `false` and 1 for `true`, we can check an 
appropriate
+// number of elements for equality even if they are not byte-sized.
+const APSInt Char1InMem = Char1.getInt().extOrTrunc(CharTy1Width);
+const APSInt Char2InMem = Char2.getInt().extOrTrunc(CharTy1Width);

rsmith wrote:
> The *only* possible problem here is for `bool`, right? This comment would be 
> clearer if it said that.
We do assume two's complement representation (which C89 does not require to be 
true); so, `bool` is more problematic than other things, but the comment is not 
just about `bool`.



Comment at: lib/AST/ExprConstant.cpp:8488-8489
+  return false;
+if (MaxLength <= LengthPerElement)
+  break;
+MaxLength -= LengthPerElement;

rsmith wrote:
> This looks wrong. If `0 < MaxLength && MaxLength < LengthPerElement`, we're 
> supposed to compare *part of* the next element; this current approach doesn't 
> do that. (If you did one more full-element compare, that'd be conservatively 
> correct because we're only checking for equality, not ordering, but perhaps 
> we should only permit cases where `MaxLength` is a multiple of 
> `LengthPerElement`?
We //are// doing one more full-element compare to be conservatively correct. 
There is a test for that.



Comment at: test/CodeGenCXX/builtins.cpp:41
+matchedFirstByteIn04030201();
+// CHECK: call void 
@_ZN27MemchrMultibyteElementTests26matchedFirstByteIn04030201Ev()
+  }

rsmith wrote:
> Please test this in a way that doesn't rely on IR generation 
> constant-evaluating `if` conditions. Moreover, there's nothing about IR 
> generation that you're actually testing here, so please phrase this as a 
> `Sema` test instead (eg, check that a VLA bound gets folded to a constant). 
> Likewise for the other tests below.
Not all of these cases can fold successfully with the current implementation. 
The check would need to be that we either fold (and get the right value), or 
don't fold at all.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55510/new/

https://reviews.llvm.org/D55510



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


[PATCH] D15881: [DWARF] Omitting the explicit import of an anonymous namespace is a debugger-tuning decision, not a target decision.

2018-12-10 Thread Paul Robinson via Phabricator via cfe-commits
probinson abandoned this revision.
probinson added a comment.
Herald added a subscriber: JDevlieghere.

Abandoning dead patch.  This wound up being done a different way.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D15881/new/

https://reviews.llvm.org/D15881



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


[PATCH] D44100: [ASTImporter] Reorder fields after structure import is finished

2018-12-10 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Alexey, good news! I have finished the testing of the above patch applied on 
top of 174545. Neither is a regression on Linux nor on macOS. (ASTTests, 
check-clang-astmerge, check-clang-import, check-clang-analysis, check-lldb).


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D44100/new/

https://reviews.llvm.org/D44100



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


[PATCH] D55488: Add utility for dumping a label with child nodes

2018-12-10 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: lib/AST/ASTDumper.cpp:89
 void dumpDecl(const Decl *D);
-void dumpStmt(const Stmt *S);
+void dumpStmt(const Stmt *S, const std::string  = {});
 

aaron.ballman wrote:
> Label
> 
> Rather than using `{}`, how about `""` (same behavior, but looks more 
> idiomatic).
> 
> Why `std::string` instead of `StringRef`? I expect this will be called mostly 
> with string literals, which saves an allocation. The other labels are using 
> `const char *`, which would be another reasonable option. Whatever we go 
> with, it'd be nice to make the label types agree across the calls.
The actual print in TextTreeStructure is deferred, so it can't be `const char*` 
or `StringRef`.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55488/new/

https://reviews.llvm.org/D55488



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


[PATCH] D55488: Add utility for dumping a label with child nodes

2018-12-10 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 177595.
steveire added a comment.

Clean up API a bit.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55488/new/

https://reviews.llvm.org/D55488

Files:
  include/clang/AST/ASTDumperUtils.h
  lib/AST/ASTDumper.cpp
  test/AST/ast-dump-stmt.cpp

Index: test/AST/ast-dump-stmt.cpp
===
--- test/AST/ast-dump-stmt.cpp
+++ test/AST/ast-dump-stmt.cpp
@@ -91,8 +91,7 @@
   U us[3] = {1};
 // CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
 // CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
-// CHECK-NEXT:   |-array filler
-// CHECK-NEXT:   | `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 'int'
+// CHECK-NEXT:   |-array_filler: InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 'int'
 // CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 'int'
 // CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1
 }
Index: lib/AST/ASTDumper.cpp
===
--- lib/AST/ASTDumper.cpp
+++ lib/AST/ASTDumper.cpp
@@ -62,6 +62,10 @@
 template void dumpChild(Fn doDumpChild) {
   TreeStructure.addChild(doDumpChild);
 }
+template 
+void dumpChild(const std::string , Fn doDumpChild) {
+  TreeStructure.addChild(Label, doDumpChild);
+}
 
   public:
 ASTDumper(raw_ostream , const CommandTraits *Traits,
@@ -82,7 +86,7 @@
 void setDeserialize(bool D) { Deserialize = D; }
 
 void dumpDecl(const Decl *D);
-void dumpStmt(const Stmt *S);
+void dumpStmt(const Stmt *S, const std::string  = {});
 
 // Utilities
 void dumpType(QualType T) { NodeDumper.dumpType(T); }
@@ -1697,8 +1701,8 @@
 //  Stmt dumping methods.
 //===--===//
 
-void ASTDumper::dumpStmt(const Stmt *S) {
-  dumpChild([=] {
+void ASTDumper::dumpStmt(const Stmt *S, const std::string ) {
+  dumpChild(Label, [=] {
 if (!S) {
   ColorScope Color(OS, ShowColors, NullColor);
   OS << "<<>>";
@@ -1964,10 +1968,7 @@
 NodeDumper.dumpBareDeclRef(Field);
   }
   if (auto *Filler = ILE->getArrayFiller()) {
-dumpChild([=] {
-  OS << "array filler";
-  dumpStmt(Filler);
-});
+dumpStmt(Filler, "array_filler");
   }
 }
 
Index: include/clang/AST/ASTDumperUtils.h
===
--- include/clang/AST/ASTDumperUtils.h
+++ include/clang/AST/ASTDumperUtils.h
@@ -109,8 +109,16 @@
   std::string Prefix;
 
 public:
-  /// Add a child of the current node.  Calls doAddChild without arguments
-  template  void addChild(Fn doAddChild) {
+  /// Add a child of the current node.
+  /// Calls doAddChild without arguments
+  template 
+  void addChild(Fn doAddChild) {
+return addChild("", doAddChild);
+  }
+  /// Add a child of the current node with an optional label.
+  /// Calls doAddChild without arguments.
+  template 
+  void addChild(const std::string , Fn doAddChild) {
 // If we're at the top level, there's nothing interesting to do; just
 // run the dumper.
 if (TopLevel) {
@@ -126,7 +134,7 @@
   return;
 }
 
-auto dumpWithIndent = [this, doAddChild](bool isLastChild) {
+auto dumpWithIndent = [this, doAddChild, Label](bool isLastChild) {
   // Print out the appropriate tree structure and work out the prefix for
   // children of this node. For instance:
   //
@@ -143,6 +151,10 @@
 OS << '\n';
 ColorScope Color(OS, ShowColors, IndentColor);
 OS << Prefix << (isLastChild ? '`' : '|') << '-';
+if (!Label.empty()) {
+  OS << Label << ": ";
+}
+
 this->Prefix.push_back(isLastChild ? ' ' : '|');
 this->Prefix.push_back(' ');
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55483: Introduce the callback attribute and emit !callback metadata

2018-12-10 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert marked 2 inline comments as done.
jdoerfert added a comment.

In D55483#1326029 , @aaron.ballman 
wrote:

> This is missing all of the Sema and SemaCXX tests. Should have tests for 
> member functions, variadic functions, incorrect arguments, incorrect 
> subjects, etc.


I will write more tests and update this revision.




Comment at: include/clang/Basic/Attr.td:1204
+  VariadicUnsignedArgument<"PayloadIndices">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [Undocumented];

aaron.ballman wrote:
> Should this also apply to Objective-C methods?
> 
> Why should the user specify this attribute on the function as opposed to on 
> the parameter? e.g.,
> ```
> // Why this:
> __attribute__((callback (1, 2, 3)))
> void* broker0(void* (*callee)(void *), void *payload, int otherPayload) {
>   return callee(payload);
> }
> 
> // Instead of this:
> void* broker0(void* (*callee)(void *) __attribute__((callback (2, 3))), void 
> *payload, int otherPayload) {
>   return callee(payload);
> }
> 
> // Or this:
> void* broker0(void* (*callee)(void *) __attribute__((callback (payload, 
> otherPayload))), void *payload, int otherPayload) {
>   return callee(payload);
> }
> ```
> I ask because these "use an index" attributes are really hard for users to 
> use in practice. They have to account for 0-vs-1 based indexing, implicit 
> this parameters, etc and if we can avoid that, it may be worth the effort.
> Should this also apply to Objective-C methods?

I don't need it to and unless somebody does, I'd say no.


> I ask because these "use an index" attributes are really hard for users to 
> use in practice. They have to account for 0-vs-1 based indexing, implicit 
> this parameters, etc and if we can avoid that, it may be worth the effort.

I was thinking that the function notation makes it clear that there is *only 
one callback per function* allowed right now. I don't expect many manual users 
of this feature until we improve the middle-end support, so it is unclear to me 
if this requirement needs to be removed as well.

Other than that, some thoughts: 
- I do not feel strongly about this.
- The middle requirement seems not much better n the first, we would still need 
to deal with index numbers (callbacks without arguments are not really 
interesting for now). 
- The last encoding requires us to define a symbol for "unknown argument" 
(maybe _ or ?).



Comment at: include/clang/Basic/Attr.td:1205
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [Undocumented];
+}

aaron.ballman wrote:
> No new undocumented attributes, please.
Ok, I can write documentation similar to the commit message and the lang-ref 
documentation for the callback metadata.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55483/new/

https://reviews.llvm.org/D55483



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


Re: r348794 - Change InitListExpr dump to label and pointer

2018-12-10 Thread Stephen Kelly via cfe-commits

I suggest continuing this discussion here: https://reviews.llvm.org/D55488

On 10/12/2018 21:42, Aaron Ballman wrote:

On Mon, Dec 10, 2018 at 4:13 PM Richard Smith via cfe-commits
 wrote:

On Mon, 10 Dec 2018 at 12:56, Stephen Kelly via cfe-commits 
 wrote:

Author: steveire
Date: Mon Dec 10 12:53:32 2018
New Revision: 348794

URL: http://llvm.org/viewvc/llvm-project?rev=348794=rev
Log:
Change InitListExpr dump to label and pointer

Summary: Don't add a child just for the label.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

Modified:
 cfe/trunk/lib/AST/ASTDumper.cpp
 cfe/trunk/test/AST/ast-dump-stmt.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=348794=348793=348794=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Mon Dec 10 12:53:32 2018
@@ -1951,11 +1951,12 @@ void ASTDumper::VisitInitListExpr(const
  OS << " field ";
  NodeDumper.dumpBareDeclRef(Field);
}
+
if (auto *Filler = ILE->getArrayFiller()) {
-dumpChild([=] {
-  OS << "array filler";
-  dumpStmt(Filler);
-});
+OS << " array_filler";
+NodeDumper.dumpPointer(Filler);
+
+dumpStmt(Filler);
}
  }


Modified: cfe/trunk/test/AST/ast-dump-stmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-stmt.cpp?rev=348794=348793=348794=diff
==
--- cfe/trunk/test/AST/ast-dump-stmt.cpp (original)
+++ cfe/trunk/test/AST/ast-dump-stmt.cpp Mon Dec 10 12:53:32 2018
@@ -90,9 +90,8 @@ void TestUnionInitList()
  {
U us[3] = {1};
  // CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
-// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
-// CHECK-NEXT:   |-array filler
-// CHECK-NEXT:   | `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
'int'
+// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]' array_filler 
0x{{.+}}
+// CHECK-NEXT:   |-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
'int'
  // CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
'int'
  // CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1
  }


I'm pretty strongly against this particular change.

Thank you for speaking up while this is still fresh in everyone's minds!


I think this makes this form of InitListExpr dump *vastly* harder to read. The 
incredibly-easy-to-miss "array_filler" marker on the outer InitListExpr 
completely changes the meaning of the rest of the dump.

I don't see how this changes the meaning of the dump. It establishes
the relationship between an InitListExpr and its optional array filler
node, just like the original form did.


The old dump form was much more readable. If you want to save vertical space, you could 
consider making the "array filler" label a prefix for the child:

// CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
// CHECK-NEXT:   |-array filler: InitListExpr {{.+}}  'U' field Field 
{{.+}} 'i' 'int'
// CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 'int'
// CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1

... but I think the approach of this patch is not acceptable: it harms the 
primary purpose of -ast-dump, which is to form a human-readable dump of the AST.

The whitespace concerns are annoying because it becomes harder to
navigate the tree structure over larger dumps, but is not a
deal-breaker for me. The one-off nature of how this was being dumped
is a much bigger concern, and the way it was originally being handled
makes the refactoring Stephen and I are working on more awkward. We
did consider adding a prefix label, but that's also novel in the AST
dump. The form that I approved is consistent with how we handle
dumping relationships in other places, which is why I felt it was a
good compromise (in fact, to me, this consistency improves readability
over entire dumps because there are less novel relationship markers).

Given that we're trying to add a bit more structure to the dump, I
think what would help us is a consistent rule for how to lay out the
dump when showing a relationship between a parent and its multiple
child AST nodes. If you're fine with this:

// CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
// CHECK-NEXT:   |-array filler: InitListExpr {{.+}}  'U'
field Field {{.+}} 'i' 'int'
// CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 'int'
// CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1

Are you also fine if we use it consistently when dumping multiple
child nodes, like the combiner and initializer in
https://reviews.llvm.org/D55395? What about for the LHS and RHS of a
binary operator?

~Aaron

___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D55488: Add utility for dumping a label with child nodes

2018-12-10 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 177594.
steveire marked an inline comment as done.
steveire added a comment.

Update with new approach


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55488/new/

https://reviews.llvm.org/D55488

Files:
  include/clang/AST/ASTDumperUtils.h
  lib/AST/ASTDumper.cpp
  test/AST/ast-dump-stmt.cpp

Index: test/AST/ast-dump-stmt.cpp
===
--- test/AST/ast-dump-stmt.cpp
+++ test/AST/ast-dump-stmt.cpp
@@ -91,8 +91,7 @@
   U us[3] = {1};
 // CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
 // CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
-// CHECK-NEXT:   |-array filler
-// CHECK-NEXT:   | `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 'int'
+// CHECK-NEXT:   |-array_filler: InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 'int'
 // CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 'int'
 // CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1
 }
Index: lib/AST/ASTDumper.cpp
===
--- lib/AST/ASTDumper.cpp
+++ lib/AST/ASTDumper.cpp
@@ -62,6 +62,10 @@
 template void dumpChild(Fn doDumpChild) {
   TreeStructure.addChild(doDumpChild);
 }
+template 
+void dumpChild(const std::string , Fn doDumpChild) {
+  TreeStructure.addChild(Label, doDumpChild);
+}
 
   public:
 ASTDumper(raw_ostream , const CommandTraits *Traits,
@@ -82,7 +86,7 @@
 void setDeserialize(bool D) { Deserialize = D; }
 
 void dumpDecl(const Decl *D);
-void dumpStmt(const Stmt *S);
+void dumpStmt(const Stmt *S, const std::string  = {});
 
 // Utilities
 void dumpType(QualType T) { NodeDumper.dumpType(T); }
@@ -1697,8 +1701,8 @@
 //  Stmt dumping methods.
 //===--===//
 
-void ASTDumper::dumpStmt(const Stmt *S) {
-  dumpChild([=] {
+void ASTDumper::dumpStmt(const Stmt *S, const std::string ) {
+  dumpChild(Label, [=] {
 if (!S) {
   ColorScope Color(OS, ShowColors, NullColor);
   OS << "<<>>";
@@ -1964,10 +1968,7 @@
 NodeDumper.dumpBareDeclRef(Field);
   }
   if (auto *Filler = ILE->getArrayFiller()) {
-dumpChild([=] {
-  OS << "array filler";
-  dumpStmt(Filler);
-});
+dumpStmt(Filler, "array_filler");
   }
 }
 
Index: include/clang/AST/ASTDumperUtils.h
===
--- include/clang/AST/ASTDumperUtils.h
+++ include/clang/AST/ASTDumperUtils.h
@@ -109,8 +109,16 @@
   std::string Prefix;
 
 public:
-  /// Add a child of the current node.  Calls doAddChild without arguments
-  template  void addChild(Fn doAddChild) {
+  /// Add a child of the current node with a label.
+  /// Calls doAddChild without arguments
+  template 
+  void addChild(const std::string , Fn doAddChild) {
+return addChild(doAddChild, Label);
+  }
+  /// Add a child of the current node with an optional label.
+  /// Calls doAddChild without arguments.
+  template 
+  void addChild(Fn doAddChild, const std::string  = "") {
 // If we're at the top level, there's nothing interesting to do; just
 // run the dumper.
 if (TopLevel) {
@@ -126,7 +134,7 @@
   return;
 }
 
-auto dumpWithIndent = [this, doAddChild](bool isLastChild) {
+auto dumpWithIndent = [this, doAddChild, Label](bool isLastChild) {
   // Print out the appropriate tree structure and work out the prefix for
   // children of this node. For instance:
   //
@@ -143,6 +151,10 @@
 OS << '\n';
 ColorScope Color(OS, ShowColors, IndentColor);
 OS << Prefix << (isLastChild ? '`' : '|') << '-';
+if (!Label.empty()) {
+  OS << Label << ": ";
+}
+
 this->Prefix.push_back(isLastChild ? ' ' : '|');
 this->Prefix.push_back(' ');
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r348794 - Change InitListExpr dump to label and pointer

2018-12-10 Thread Aaron Ballman via cfe-commits
On Mon, Dec 10, 2018 at 4:13 PM Richard Smith via cfe-commits
 wrote:
>
> On Mon, 10 Dec 2018 at 12:56, Stephen Kelly via cfe-commits 
>  wrote:
>>
>> Author: steveire
>> Date: Mon Dec 10 12:53:32 2018
>> New Revision: 348794
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=348794=rev
>> Log:
>> Change InitListExpr dump to label and pointer
>>
>> Summary: Don't add a child just for the label.
>>
>> Reviewers: aaron.ballman
>>
>> Subscribers: cfe-commits
>>
>> Differential Revision: https://reviews.llvm.org/D55495
>>
>> Modified:
>> cfe/trunk/lib/AST/ASTDumper.cpp
>> cfe/trunk/test/AST/ast-dump-stmt.cpp
>>
>> Modified: cfe/trunk/lib/AST/ASTDumper.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=348794=348793=348794=diff
>> ==
>> --- cfe/trunk/lib/AST/ASTDumper.cpp (original)
>> +++ cfe/trunk/lib/AST/ASTDumper.cpp Mon Dec 10 12:53:32 2018
>> @@ -1951,11 +1951,12 @@ void ASTDumper::VisitInitListExpr(const
>>  OS << " field ";
>>  NodeDumper.dumpBareDeclRef(Field);
>>}
>> +
>>if (auto *Filler = ILE->getArrayFiller()) {
>> -dumpChild([=] {
>> -  OS << "array filler";
>> -  dumpStmt(Filler);
>> -});
>> +OS << " array_filler";
>> +NodeDumper.dumpPointer(Filler);
>> +
>> +dumpStmt(Filler);
>>}
>>  }
>>
>>
>> Modified: cfe/trunk/test/AST/ast-dump-stmt.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-stmt.cpp?rev=348794=348793=348794=diff
>> ==
>> --- cfe/trunk/test/AST/ast-dump-stmt.cpp (original)
>> +++ cfe/trunk/test/AST/ast-dump-stmt.cpp Mon Dec 10 12:53:32 2018
>> @@ -90,9 +90,8 @@ void TestUnionInitList()
>>  {
>>U us[3] = {1};
>>  // CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
>> -// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
>> -// CHECK-NEXT:   |-array filler
>> -// CHECK-NEXT:   | `-InitListExpr {{.+}}  'U' field Field {{.+}} 
>> 'i' 'int'
>> +// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]' array_filler 
>> 0x{{.+}}
>> +// CHECK-NEXT:   |-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
>> 'int'
>>  // CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
>> 'int'
>>  // CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1
>>  }
>
>
> I'm pretty strongly against this particular change.

Thank you for speaking up while this is still fresh in everyone's minds!

> I think this makes this form of InitListExpr dump *vastly* harder to read. 
> The incredibly-easy-to-miss "array_filler" marker on the outer InitListExpr 
> completely changes the meaning of the rest of the dump.

I don't see how this changes the meaning of the dump. It establishes
the relationship between an InitListExpr and its optional array filler
node, just like the original form did.

> The old dump form was much more readable. If you want to save vertical space, 
> you could consider making the "array filler" label a prefix for the child:
>
> // CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
> // CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
> // CHECK-NEXT:   |-array filler: InitListExpr {{.+}}  'U' field Field 
> {{.+}} 'i' 'int'
> // CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
> 'int'
> // CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1
>
> ... but I think the approach of this patch is not acceptable: it harms the 
> primary purpose of -ast-dump, which is to form a human-readable dump of the 
> AST.

The whitespace concerns are annoying because it becomes harder to
navigate the tree structure over larger dumps, but is not a
deal-breaker for me. The one-off nature of how this was being dumped
is a much bigger concern, and the way it was originally being handled
makes the refactoring Stephen and I are working on more awkward. We
did consider adding a prefix label, but that's also novel in the AST
dump. The form that I approved is consistent with how we handle
dumping relationships in other places, which is why I felt it was a
good compromise (in fact, to me, this consistency improves readability
over entire dumps because there are less novel relationship markers).

Given that we're trying to add a bit more structure to the dump, I
think what would help us is a consistent rule for how to lay out the
dump when showing a relationship between a parent and its multiple
child AST nodes. If you're fine with this:

// CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
// CHECK-NEXT:   |-array filler: InitListExpr {{.+}}  'U'
field Field {{.+}} 'i' 'int'
// CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 'int'
// CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1

Are you also fine if we use it consistently when dumping multiple
child nodes, like the combiner and initializer in
https://reviews.llvm.org/D55395? What about for the LHS and RHS of a
binary operator?

~Aaron

[PATCH] D55510: [ExprConstant] Improve memchr/memcmp for type mismatch and multibyte element types

2018-12-10 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/AST/ExprConstant.cpp:6147-6148
+  return ZeroInitialization(E);
+if (!Result.checkNullPointerForFoldAccess(Info, E, AK_Read))
+  return false;
+QualType CharTy =

Why do we need to do this explicitly, rather than allowing to simply happen as 
part of the first `handleLValueToRValueConversion` below?



Comment at: lib/AST/ExprConstant.cpp:6150
+QualType CharTy =
+Info.Ctx.getBaseElementType(getType(Result.getLValueBase()));
+const bool IsRawByte = BuiltinOp == Builtin::BImemchr ||

Considering the LValue base here is incorrect. The object or array we're 
copying could be a subobject, and the complete object type (the type of the 
lvalue base) is irrelevant for such copies. Use 
`Result.Designator.getType(Info.Ctx)` to find the type that the lvalue 
designates. (You can bail out here if the designator is invalid; 
`handleLValueToRValueConversion` will always fail on such cases anyway.



Comment at: lib/AST/ExprConstant.cpp:6159-6160
+// Give up on byte-oriented matching against multibyte elements.
+if (IsRawByte && Info.Ctx.getTypeSize(CharTy) > Info.Ctx.getCharWidth())
+  return false;
 // Figure out what value we're actually looking for (after converting to

Please add an assert here that the types do match in the non-raw-byte case. 
(They must, or the subobject designator would be invalid; the only special case 
is that a `void*` can point to anything, and only the `memchr` variants here 
take a `void*`.)



Comment at: lib/AST/ExprConstant.cpp:8433-8436
+QualType CharTy1 =
+Info.Ctx.getBaseElementType(getType(String1.getLValueBase()));
+QualType CharTy2 =
+Info.Ctx.getBaseElementType(getType(String2.getLValueBase()));

Per above comment, this is not correct.



Comment at: lib/AST/ExprConstant.cpp:8467
+  assert(MaxLength);
+  for (;;) {
+APValue Char1, Char2;

Style nit: please use `while (true)` rather than `for (;;)`



Comment at: lib/AST/ExprConstant.cpp:8471-8476
+// We have compatible in-memory widths, but a possible type and 
internal
+// representation mismatch. Assuming two's complement representation,
+// including 0 for `false` and 1 for `true`, we can check an 
appropriate
+// number of elements for equality even if they are not byte-sized.
+const APSInt Char1InMem = Char1.getInt().extOrTrunc(CharTy1Width);
+const APSInt Char2InMem = Char2.getInt().extOrTrunc(CharTy1Width);

The *only* possible problem here is for `bool`, right? This comment would be 
clearer if it said that.



Comment at: lib/AST/ExprConstant.cpp:8484
+  }
+  return false;
+}

Please add a comment before this return indicating that the result depends on 
byte order (and maybe a FIXME to compare the bytes in the right order rather 
than bailing out). We're going to need to deal with the byte order / 
representation problem for `std::bit_cast` pretty soon anyway.



Comment at: lib/AST/ExprConstant.cpp:8488-8489
+  return false;
+if (MaxLength <= LengthPerElement)
+  break;
+MaxLength -= LengthPerElement;

This looks wrong. If `0 < MaxLength && MaxLength < LengthPerElement`, we're 
supposed to compare *part of* the next element; this current approach doesn't 
do that. (If you did one more full-element compare, that'd be conservatively 
correct because we're only checking for equality, not ordering, but perhaps we 
should only permit cases where `MaxLength` is a multiple of `LengthPerElement`?



Comment at: test/CodeGenCXX/builtins.cpp:41
+matchedFirstByteIn04030201();
+// CHECK: call void 
@_ZN27MemchrMultibyteElementTests26matchedFirstByteIn04030201Ev()
+  }

Please test this in a way that doesn't rely on IR generation 
constant-evaluating `if` conditions. Moreover, there's nothing about IR 
generation that you're actually testing here, so please phrase this as a `Sema` 
test instead (eg, check that a VLA bound gets folded to a constant). Likewise 
for the other tests below.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55510/new/

https://reviews.llvm.org/D55510



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


[PATCH] D48342: [libcxx] Optimize vectors construction of trivial types from an iterator range with const-ness mismatch.

2018-12-10 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added inline comments.



Comment at: libcxx/include/memory:1658
+|| !__has_construct::value) &&
+ is_trivially_move_constructible<_DestTp>::value,
 void

Quuxplusone wrote:
> Shouldn't this be something like `is_trivially_constructible<_DestTp, 
> _SourceTp&>`?  I mean, we're never doing move-construction here. We're 
> constructing `_DestTp` from `_SourceTp&`, which is either copy-construction 
> or non-const-copy-construction, depending on the constness of `_SourceTp`.
> 
> `is_trivially_constructible` has pitfalls in general — 
> https://quuxplusone.github.io/blog/2018/07/03/trivially-constructible-from/ — 
> but I think we won't fall into any of those pits as long as we're testing 
> that `_SourceTp` is cv-qualified `_DestTp`.
> Shouldn't this be something like `is_trivially_constructible<_DestTp, 
> _SourceTp&>`?

I think you're right. We should also fix `__construct_forward` and 
`__construct_backward`, but maybe as part of a separate change since the three 
are consistently using `is_trivially_move_constructible` (and so there might be 
a reason for this).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D48342/new/

https://reviews.llvm.org/D48342



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


r348799 - Revert "Change InitListExpr dump to label and pointer"

2018-12-10 Thread Stephen Kelly via cfe-commits
Author: steveire
Date: Mon Dec 10 13:20:05 2018
New Revision: 348799

URL: http://llvm.org/viewvc/llvm-project?rev=348799=rev
Log:
Revert "Change InitListExpr dump to label and pointer"

This reverts commit r348794.

Modified:
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/test/AST/ast-dump-stmt.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=348799=348798=348799=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Mon Dec 10 13:20:05 2018
@@ -1963,12 +1963,11 @@ void ASTDumper::VisitInitListExpr(const
 OS << " field ";
 NodeDumper.dumpBareDeclRef(Field);
   }
-
   if (auto *Filler = ILE->getArrayFiller()) {
-OS << " array_filler";
-NodeDumper.dumpPointer(Filler);
-
-dumpStmt(Filler);
+dumpChild([=] {
+  OS << "array filler";
+  dumpStmt(Filler);
+});
   }
 }
 

Modified: cfe/trunk/test/AST/ast-dump-stmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-stmt.cpp?rev=348799=348798=348799=diff
==
--- cfe/trunk/test/AST/ast-dump-stmt.cpp (original)
+++ cfe/trunk/test/AST/ast-dump-stmt.cpp Mon Dec 10 13:20:05 2018
@@ -90,8 +90,9 @@ void TestUnionInitList()
 {
   U us[3] = {1};
 // CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
-// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]' array_filler 
0x{{.+}}
-// CHECK-NEXT:   |-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
'int'
+// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
+// CHECK-NEXT:   |-array filler
+// CHECK-NEXT:   | `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
'int'
 // CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
'int'
 // CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1
 }


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


Re: r348794 - Change InitListExpr dump to label and pointer

2018-12-10 Thread Stephen Kelly via cfe-commits

I'll revert it to allow for further discussion.

On 10/12/2018 21:12, Richard Smith wrote:
On Mon, 10 Dec 2018 at 12:56, Stephen Kelly via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:


Author: steveire
Date: Mon Dec 10 12:53:32 2018
New Revision: 348794

URL: http://llvm.org/viewvc/llvm-project?rev=348794=rev
Log:
Change InitListExpr dump to label and pointer

Summary: Don't add a child just for the label.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

Modified:
    cfe/trunk/lib/AST/ASTDumper.cpp
    cfe/trunk/test/AST/ast-dump-stmt.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL:

http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=348794=348793=348794=diff

==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Mon Dec 10 12:53:32 2018
@@ -1951,11 +1951,12 @@ void ASTDumper::VisitInitListExpr(const
     OS << " field ";
     NodeDumper.dumpBareDeclRef(Field);
   }
+
   if (auto *Filler = ILE->getArrayFiller()) {
-    dumpChild([=] {
-      OS << "array filler";
-      dumpStmt(Filler);
-    });
+    OS << " array_filler";
+    NodeDumper.dumpPointer(Filler);
+
+    dumpStmt(Filler);
   }
 }


Modified: cfe/trunk/test/AST/ast-dump-stmt.cpp
URL:

http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-stmt.cpp?rev=348794=348793=348794=diff

==
--- cfe/trunk/test/AST/ast-dump-stmt.cpp (original)
+++ cfe/trunk/test/AST/ast-dump-stmt.cpp Mon Dec 10 12:53:32 2018
@@ -90,9 +90,8 @@ void TestUnionInitList()
 {
   U us[3] = {1};
 // CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
-// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
-// CHECK-NEXT:   |-array filler
-// CHECK-NEXT:   | `-InitListExpr {{.+}}  'U' field Field
{{.+}} 'i' 'int'
+// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
array_filler 0x{{.+}}
+// CHECK-NEXT:   |-InitListExpr {{.+}}  'U' field Field
{{.+}} 'i' 'int'
 // CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field
{{.+}} 'i' 'int'
 // CHECK-NEXT:     `-IntegerLiteral {{.+}}  'int' 1
 }


I'm pretty strongly against this particular change. I think this makes 
this form of InitListExpr dump *vastly* harder to read. The 
incredibly-easy-to-miss "array_filler" marker on the outer 
InitListExpr completely changes the meaning of the rest of the dump.


The old dump form was much more readable. If you want to save vertical 
space, you could consider making the "array filler" label a prefix for 
the child:


// CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
// CHECK-NEXT:   |-array filler: InitListExpr {{.+}}  'U' 
field Field {{.+}} 'i' 'int'
// CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 
'i' 'int'

// CHECK-NEXT:     `-IntegerLiteral {{.+}}  'int' 1

... but I think the approach of this patch is not acceptable: it harms 
the primary purpose of -ast-dump, which is to form a human-readable 
dump of the AST.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55245: [clang-tidy] Add the abseil-duration-subtraction check

2018-12-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tidy/abseil/DurationRewriter.cpp:77
+  getInverseForScale(Scale);
+  if (const auto *MaybeCallArg = selectFirst(
+  "e",

hwright wrote:
> JonasToth wrote:
> > In Principle the `Node` could have multiple expressions that are a call if 
> > there is nesting. 
> > The transformation is correct from what I see right now, but might result 
> > in the necessity of multiple passes for the check. (Is the addition version 
> > affected from that too?)
> > 
> > Given the recursive nature of the matcher you could construct a nesting 
> > with the inner part being a subtraction, too. The generated fixes would 
> > conflict and none of them would be applied. At least thats what I would 
> > expect right now. Please take a look at this issue.
> There isn't an imminent addition version at this point.
> 
> This matcher isn't recursive: it's just looking at the entire node to see if 
> it is a call to the inverse function.  If an inverse is embedded as part of a 
> deeper expression, it won't see it (e.g., there no `hasDescendant` in this 
> matcher).
Matchers are recursive. There will be a next match of the inner nodes below 
this node, just by AST traversal.



Comment at: clang-tidy/abseil/DurationSubtractionCheck.cpp:38
+  // Don't try to replace things inside of macro definitions.
+  if (Binop->getExprLoc().isMacroID())
+return;

`Loc.isInvalid()` too. You can pass in macros from the command line that result 
in invalid sourcelocations.



Comment at: test/clang-tidy/Inputs/absl/time/time.h:1
+// Mimic the implementation of absl::Duration
+namespace absl {

hwright wrote:
> JonasToth wrote:
> > I think having the extraction of the common test-stuff into this header as 
> > one commit would be better. Would you prepare such a patch? I can commit 
> > for you. It probably makes sense if you ask for commit access 
> > (https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access). Do as 
> > you wish.
> I can do this, but it might take a bit to get the commit bit turned on.
Maybe, I (or someone else) have no problem commiting for you.



Comment at: test/clang-tidy/abseil-duration-subtraction.cpp:12
+  // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(1))
+  x = absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(d1);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the 
duration domain [abseil-duration-subtraction]

hwright wrote:
> JonasToth wrote:
> > From this example starting:
> > 
> > - The RHS should be a nested expression with function calls, as the RHS is 
> > transformed to create the adversary example i mean in the transformation 
> > function above.
> > 
> > ```
> > absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(absl::ToDoubleSeconds(d) - 
> > absl::ToDoubleSeconds(d1));
> > ```
> > I think you need the proper conversion function, as the result of the 
> > expression is `double` and you need a `Duration`, right?
> > 
> > But in principle starting from this idea the transformation might break.
> I think there may be some confusion here (and that's entirely my fault. :) )
> 
> We should never get this expression as input to the check, since it doesn't 
> compile (as you point out):
> ```
> absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(absl::ToDoubleSeconds(d) - 
> absl::ToDoubleSeconds(d1));
> ```
> 
> Since `absl::ToDoubleSeconds` requires that its argument is an 
> `absl::Duration`, but the expression `absl::ToDoubleSeconds(d) - 
> absl::ToDoubleSeconds(d1)` results in a `double`, we can't get this as input.
> 
> There may be other expressions which could be input, but in practice they 
> don't really happen.  I've added a contrived example to the tests, but at 
> some point the tests get too complex and confuse the fix matching 
> infrastructure.
Your last sentence is the thing ;) Murphies Law will hit this check, too. In my 
opinion wrong transformations are very unfortunate and should be avoided if 
possible (in this case possible).
You can simply require that the expression of type double does not contain any 
duration subtraction calls.

This is even possible in the matcher-part of the check.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55245/new/

https://reviews.llvm.org/D55245



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


Re: r348794 - Change InitListExpr dump to label and pointer

2018-12-10 Thread Richard Smith via cfe-commits
On Mon, 10 Dec 2018 at 12:56, Stephen Kelly via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: steveire
> Date: Mon Dec 10 12:53:32 2018
> New Revision: 348794
>
> URL: http://llvm.org/viewvc/llvm-project?rev=348794=rev
> Log:
> Change InitListExpr dump to label and pointer
>
> Summary: Don't add a child just for the label.
>
> Reviewers: aaron.ballman
>
> Subscribers: cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D55495
>
> Modified:
> cfe/trunk/lib/AST/ASTDumper.cpp
> cfe/trunk/test/AST/ast-dump-stmt.cpp
>
> Modified: cfe/trunk/lib/AST/ASTDumper.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=348794=348793=348794=diff
>
> ==
> --- cfe/trunk/lib/AST/ASTDumper.cpp (original)
> +++ cfe/trunk/lib/AST/ASTDumper.cpp Mon Dec 10 12:53:32 2018
> @@ -1951,11 +1951,12 @@ void ASTDumper::VisitInitListExpr(const
>  OS << " field ";
>  NodeDumper.dumpBareDeclRef(Field);
>}
> +
>if (auto *Filler = ILE->getArrayFiller()) {
> -dumpChild([=] {
> -  OS << "array filler";
> -  dumpStmt(Filler);
> -});
> +OS << " array_filler";
> +NodeDumper.dumpPointer(Filler);
> +
> +dumpStmt(Filler);
>}
>  }
>
>
> Modified: cfe/trunk/test/AST/ast-dump-stmt.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-stmt.cpp?rev=348794=348793=348794=diff
>
> ==
> --- cfe/trunk/test/AST/ast-dump-stmt.cpp (original)
> +++ cfe/trunk/test/AST/ast-dump-stmt.cpp Mon Dec 10 12:53:32 2018
> @@ -90,9 +90,8 @@ void TestUnionInitList()
>  {
>U us[3] = {1};
>  // CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
> -// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
> -// CHECK-NEXT:   |-array filler
> -// CHECK-NEXT:   | `-InitListExpr {{.+}}  'U' field Field {{.+}}
> 'i' 'int'
> +// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
> array_filler 0x{{.+}}
> +// CHECK-NEXT:   |-InitListExpr {{.+}}  'U' field Field {{.+}}
> 'i' 'int'
>  // CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}}
> 'i' 'int'
>  // CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1
>  }


I'm pretty strongly against this particular change. I think this makes this
form of InitListExpr dump *vastly* harder to read. The
incredibly-easy-to-miss "array_filler" marker on the outer InitListExpr
completely changes the meaning of the rest of the dump.

The old dump form was much more readable. If you want to save vertical
space, you could consider making the "array filler" label a prefix for the
child:

// CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
// CHECK-NEXT:   |-array filler: InitListExpr {{.+}}  'U' field
Field {{.+}} 'i' 'int'
// CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i'
'int'
// CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1

... but I think the approach of this patch is not acceptable: it harms the
primary purpose of -ast-dump, which is to form a human-readable dump of the
AST.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r348798 - Fix nits

2018-12-10 Thread Roman Lebedev via cfe-commits
On Tue, Dec 11, 2018 at 12:07 AM Stephen Kelly via cfe-commits
 wrote:
>
> Author: steveire
> Date: Mon Dec 10 13:04:04 2018
> New Revision: 348798
>
> URL: http://llvm.org/viewvc/llvm-project?rev=348798=rev
> Log:
> Fix nits
Can you *please* write proper commit messages, pretty please?
I have asked this two times already.
It will make reading through git log hard,
and is already making reading throughout the -commits mail hard.

> Modified:
> cfe/trunk/lib/AST/ASTDumper.cpp
>
> Modified: cfe/trunk/lib/AST/ASTDumper.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=348798=348797=348798=diff
> ==
> --- cfe/trunk/lib/AST/ASTDumper.cpp (original)
> +++ cfe/trunk/lib/AST/ASTDumper.cpp Mon Dec 10 13:04:04 2018
> @@ -100,12 +100,12 @@ namespace  {
>  void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo );
>  void dumpTemplateArgumentLoc(const TemplateArgumentLoc ,
>   const Decl *From = nullptr,
> - const char *label = nullptr);
> + const char *Label = nullptr);
>  void dumpTemplateArgumentList(const TemplateArgumentList );
>  void dumpTemplateArgument(const TemplateArgument ,
>SourceRange R = SourceRange(),
>const Decl *From = nullptr,
> -  const char *label = nullptr);
> +  const char *Label = nullptr);
>  template 
>  void dumpTemplateDeclSpecialization(const SpecializationDecl *D,
>  bool DumpExplicitInst,
> @@ -678,8 +678,8 @@ void ASTDumper::dumpTemplateArgumentList
>  }
>
>  void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc ,
> -const Decl *From, const char *label) 
> {
> -  dumpTemplateArgument(A.getArgument(), A.getSourceRange(), From, label);
> +const Decl *From, const char *Label) 
> {
> +  dumpTemplateArgument(A.getArgument(), A.getSourceRange(), From, Label);
>  }
>
>  void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList ) {
> @@ -688,15 +688,14 @@ void ASTDumper::dumpTemplateArgumentList
>  }
>
>  void ASTDumper::dumpTemplateArgument(const TemplateArgument , SourceRange 
> R,
> - const Decl *From, const char *label) {
> + const Decl *From, const char *Label) {
>dumpChild([=] {
>  OS << "TemplateArgument";
>  if (R.isValid())
>NodeDumper.dumpSourceRange(R);
>
> -if (From) {
> -  dumpDeclRef(From, label);
> -}
> +if (From)
> +  dumpDeclRef(From, Label);
>
>  switch (A.getKind()) {
>  case TemplateArgument::Null:
>
>
> ___
> 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


r348798 - Fix nits

2018-12-10 Thread Stephen Kelly via cfe-commits
Author: steveire
Date: Mon Dec 10 13:04:04 2018
New Revision: 348798

URL: http://llvm.org/viewvc/llvm-project?rev=348798=rev
Log:
Fix nits

Modified:
cfe/trunk/lib/AST/ASTDumper.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=348798=348797=348798=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Mon Dec 10 13:04:04 2018
@@ -100,12 +100,12 @@ namespace  {
 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo );
 void dumpTemplateArgumentLoc(const TemplateArgumentLoc ,
  const Decl *From = nullptr,
- const char *label = nullptr);
+ const char *Label = nullptr);
 void dumpTemplateArgumentList(const TemplateArgumentList );
 void dumpTemplateArgument(const TemplateArgument ,
   SourceRange R = SourceRange(),
   const Decl *From = nullptr,
-  const char *label = nullptr);
+  const char *Label = nullptr);
 template 
 void dumpTemplateDeclSpecialization(const SpecializationDecl *D,
 bool DumpExplicitInst,
@@ -678,8 +678,8 @@ void ASTDumper::dumpTemplateArgumentList
 }
 
 void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc ,
-const Decl *From, const char *label) {
-  dumpTemplateArgument(A.getArgument(), A.getSourceRange(), From, label);
+const Decl *From, const char *Label) {
+  dumpTemplateArgument(A.getArgument(), A.getSourceRange(), From, Label);
 }
 
 void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList ) {
@@ -688,15 +688,14 @@ void ASTDumper::dumpTemplateArgumentList
 }
 
 void ASTDumper::dumpTemplateArgument(const TemplateArgument , SourceRange R,
- const Decl *From, const char *label) {
+ const Decl *From, const char *Label) {
   dumpChild([=] {
 OS << "TemplateArgument";
 if (R.isValid())
   NodeDumper.dumpSourceRange(R);
 
-if (From) {
-  dumpDeclRef(From, label);
-}
+if (From)
+  dumpDeclRef(From, Label);
 
 switch (A.getKind()) {
 case TemplateArgument::Null:


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


[PATCH] D55393: Re-order content of template parameter dumps

2018-12-10 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL348797: Re-order content of template parameter dumps 
(authored by steveire, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55393?vs=177412=177591#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55393/new/

https://reviews.llvm.org/D55393

Files:
  cfe/trunk/lib/AST/ASTDumper.cpp
  cfe/trunk/test/AST/ast-dump-decl.cpp

Index: cfe/trunk/lib/AST/ASTDumper.cpp
===
--- cfe/trunk/lib/AST/ASTDumper.cpp
+++ cfe/trunk/lib/AST/ASTDumper.cpp
@@ -98,10 +98,14 @@
 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
 void dumpTemplateParameters(const TemplateParameterList *TPL);
 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo );
-void dumpTemplateArgumentLoc(const TemplateArgumentLoc );
+void dumpTemplateArgumentLoc(const TemplateArgumentLoc ,
+ const Decl *From = nullptr,
+ const char *label = nullptr);
 void dumpTemplateArgumentList(const TemplateArgumentList );
 void dumpTemplateArgument(const TemplateArgument ,
-  SourceRange R = SourceRange());
+  SourceRange R = SourceRange(),
+  const Decl *From = nullptr,
+  const char *label = nullptr);
 template 
 void dumpTemplateDeclSpecialization(const SpecializationDecl *D,
 bool DumpExplicitInst,
@@ -673,8 +677,9 @@
 dumpTemplateArgumentLoc(TALI[i]);
 }
 
-void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc ) {
-  dumpTemplateArgument(A.getArgument(), A.getSourceRange());
+void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc ,
+const Decl *From, const char *label) {
+  dumpTemplateArgument(A.getArgument(), A.getSourceRange(), From, label);
 }
 
 void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList ) {
@@ -682,12 +687,17 @@
 dumpTemplateArgument(TAL[i]);
 }
 
-void ASTDumper::dumpTemplateArgument(const TemplateArgument , SourceRange R) {
+void ASTDumper::dumpTemplateArgument(const TemplateArgument , SourceRange R,
+ const Decl *From, const char *label) {
   dumpChild([=] {
 OS << "TemplateArgument";
 if (R.isValid())
   NodeDumper.dumpSourceRange(R);
 
+if (From) {
+  dumpDeclRef(From, label);
+}
+
 switch (A.getKind()) {
 case TemplateArgument::Null:
   OS << " null";
@@ -1380,10 +1390,10 @@
 OS << " ...";
   NodeDumper.dumpName(D);
   if (D->hasDefaultArgument())
-dumpTemplateArgument(D->getDefaultArgument());
-  if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
-dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
-   : "previous");
+dumpTemplateArgument(D->getDefaultArgument(), SourceRange(),
+ D->getDefaultArgStorage().getInheritedFrom(),
+ D->defaultArgumentWasInherited() ? "inherited from"
+  : "previous");
 }
 
 void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) {
@@ -1393,10 +1403,10 @@
 OS << " ...";
   NodeDumper.dumpName(D);
   if (D->hasDefaultArgument())
-dumpTemplateArgument(D->getDefaultArgument());
-  if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
-dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
-   : "previous");
+dumpTemplateArgument(D->getDefaultArgument(), SourceRange(),
+ D->getDefaultArgStorage().getInheritedFrom(),
+ D->defaultArgumentWasInherited() ? "inherited from"
+  : "previous");
 }
 
 void ASTDumper::VisitTemplateTemplateParmDecl(
@@ -1407,10 +1417,9 @@
   NodeDumper.dumpName(D);
   dumpTemplateParameters(D->getTemplateParameters());
   if (D->hasDefaultArgument())
-dumpTemplateArgumentLoc(D->getDefaultArgument());
-  if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
-dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
-   : "previous");
+dumpTemplateArgumentLoc(
+D->getDefaultArgument(), D->getDefaultArgStorage().getInheritedFrom(),
+D->defaultArgumentWasInherited() ? "inherited from" : "previous");
 }
 
 void ASTDumper::VisitUsingDecl(const UsingDecl *D) {
Index: cfe/trunk/test/AST/ast-dump-decl.cpp
===
--- cfe/trunk/test/AST/ast-dump-decl.cpp
+++ 

r348797 - Re-order content of template parameter dumps

2018-12-10 Thread Stephen Kelly via cfe-commits
Author: steveire
Date: Mon Dec 10 13:03:00 2018
New Revision: 348797

URL: http://llvm.org/viewvc/llvm-project?rev=348797=rev
Log:
Re-order content of template parameter dumps

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/test/AST/ast-dump-decl.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=348797=348796=348797=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Mon Dec 10 13:03:00 2018
@@ -98,10 +98,14 @@ namespace  {
 void dumpCXXCtorInitializer(const CXXCtorInitializer *Init);
 void dumpTemplateParameters(const TemplateParameterList *TPL);
 void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo );
-void dumpTemplateArgumentLoc(const TemplateArgumentLoc );
+void dumpTemplateArgumentLoc(const TemplateArgumentLoc ,
+ const Decl *From = nullptr,
+ const char *label = nullptr);
 void dumpTemplateArgumentList(const TemplateArgumentList );
 void dumpTemplateArgument(const TemplateArgument ,
-  SourceRange R = SourceRange());
+  SourceRange R = SourceRange(),
+  const Decl *From = nullptr,
+  const char *label = nullptr);
 template 
 void dumpTemplateDeclSpecialization(const SpecializationDecl *D,
 bool DumpExplicitInst,
@@ -673,8 +677,9 @@ void ASTDumper::dumpTemplateArgumentList
 dumpTemplateArgumentLoc(TALI[i]);
 }
 
-void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc ) {
-  dumpTemplateArgument(A.getArgument(), A.getSourceRange());
+void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc ,
+const Decl *From, const char *label) {
+  dumpTemplateArgument(A.getArgument(), A.getSourceRange(), From, label);
 }
 
 void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList ) {
@@ -682,12 +687,17 @@ void ASTDumper::dumpTemplateArgumentList
 dumpTemplateArgument(TAL[i]);
 }
 
-void ASTDumper::dumpTemplateArgument(const TemplateArgument , SourceRange R) 
{
+void ASTDumper::dumpTemplateArgument(const TemplateArgument , SourceRange R,
+ const Decl *From, const char *label) {
   dumpChild([=] {
 OS << "TemplateArgument";
 if (R.isValid())
   NodeDumper.dumpSourceRange(R);
 
+if (From) {
+  dumpDeclRef(From, label);
+}
+
 switch (A.getKind()) {
 case TemplateArgument::Null:
   OS << " null";
@@ -1380,10 +1390,10 @@ void ASTDumper::VisitTemplateTypeParmDec
 OS << " ...";
   NodeDumper.dumpName(D);
   if (D->hasDefaultArgument())
-dumpTemplateArgument(D->getDefaultArgument());
-  if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
-dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
-   : "previous");
+dumpTemplateArgument(D->getDefaultArgument(), SourceRange(),
+ D->getDefaultArgStorage().getInheritedFrom(),
+ D->defaultArgumentWasInherited() ? "inherited from"
+  : "previous");
 }
 
 void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) 
{
@@ -1393,10 +1403,10 @@ void ASTDumper::VisitNonTypeTemplateParm
 OS << " ...";
   NodeDumper.dumpName(D);
   if (D->hasDefaultArgument())
-dumpTemplateArgument(D->getDefaultArgument());
-  if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
-dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
-   : "previous");
+dumpTemplateArgument(D->getDefaultArgument(), SourceRange(),
+ D->getDefaultArgStorage().getInheritedFrom(),
+ D->defaultArgumentWasInherited() ? "inherited from"
+  : "previous");
 }
 
 void ASTDumper::VisitTemplateTemplateParmDecl(
@@ -1407,10 +1417,9 @@ void ASTDumper::VisitTemplateTemplatePar
   NodeDumper.dumpName(D);
   dumpTemplateParameters(D->getTemplateParameters());
   if (D->hasDefaultArgument())
-dumpTemplateArgumentLoc(D->getDefaultArgument());
-  if (auto *From = D->getDefaultArgStorage().getInheritedFrom())
-dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from"
-   : "previous");
+dumpTemplateArgumentLoc(
+D->getDefaultArgument(), D->getDefaultArgStorage().getInheritedFrom(),
+D->defaultArgumentWasInherited() ? "inherited from" : 

[PATCH] D55433: [clang-tidy] Adding a new modernize use nodiscard checker

2018-12-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tidy/modernize/UseNodiscardCheck.cpp:29
+AST_MATCHER(CXXMethodDecl, isOverloadedOperator) {
+  // Don't put [[nodiscard]] front of operators.
+  return Node.isOverloadedOperator();

s/front/in front/



Comment at: clang-tidy/modernize/UseNodiscardCheck.cpp:45
+  return llvm::any_of(Node.parameters(), [](const ParmVarDecl *Par) {
+QualType  = Par->getType();
+

please remove the reference.



Comment at: clang-tidy/modernize/UseNodiscardCheck.cpp:66
+  // If we are using C++17 attributes we are going to need c++17
+  if (NoDiscardMacro == "[[nodiscard]]") {
+if (!getLangOpts().CPlusPlus17)

please merge the `if` conditions with `&&`, you could even add the next if with 
an `||`, but with proper parens.



Comment at: clang-tidy/modernize/UseNodiscardCheck.cpp:105
+  << FixItHint::CreateInsertion(retLoc, NoDiscardMacro + " ");
+  return;
+}

this `return` is not necessary



Comment at: test/clang-tidy/modernize-use-nodiscard.cpp:11
+
+class Foo
+{

Please add test that uses typedefs and `using` for the types that are passed 
into the functions.



Comment at: test/clang-tidy/modernize-use-nodiscard.cpp:126
+template
+class Bar
+{

I think the template tests should be improved.
What happens for `T empty()`, `typename T::value_type empty()` and so on. THe 
same for the parameters for functions/methods (including function templates).

Thinking of it, it might be a good idea to ignore functions where the heuristic 
depends on the template-paramters.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55433/new/

https://reviews.llvm.org/D55433



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


[PATCH] D55245: [clang-tidy] Add the abseil-duration-subtraction check

2018-12-10 Thread Hyrum Wright via Phabricator via cfe-commits
hwright updated this revision to Diff 177590.
hwright marked 9 inline comments as done.
hwright added a comment.

Add tests


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55245/new/

https://reviews.llvm.org/D55245

Files:
  clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tidy/abseil/CMakeLists.txt
  clang-tidy/abseil/DurationComparisonCheck.cpp
  clang-tidy/abseil/DurationRewriter.cpp
  clang-tidy/abseil/DurationRewriter.h
  clang-tidy/abseil/DurationSubtractionCheck.cpp
  clang-tidy/abseil/DurationSubtractionCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/abseil-duration-subtraction.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/Inputs/absl/time/time.h
  test/clang-tidy/abseil-duration-comparison.cpp
  test/clang-tidy/abseil-duration-factory-float.cpp
  test/clang-tidy/abseil-duration-factory-scale.cpp
  test/clang-tidy/abseil-duration-subtraction.cpp

Index: test/clang-tidy/abseil-duration-subtraction.cpp
===
--- /dev/null
+++ test/clang-tidy/abseil-duration-subtraction.cpp
@@ -0,0 +1,64 @@
+// RUN: %check_clang_tidy %s abseil-duration-subtraction %t -- -- -I %S/Inputs
+
+#include "absl/time/time.h"
+
+void f() {
+  double x;
+  absl::Duration d, d1, d2;
+
+  x = absl::ToDoubleSeconds(d) - 1.0;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(1))
+  x = absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(d1);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleSeconds(d - d1);
+  x = absl::ToDoubleSeconds(d) - 6.5 - 8.0;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(6.5)) - 8.0;
+  x = absl::ToDoubleHours(d) - 1.0;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleHours(d - absl::Hours(1))
+  x = absl::ToDoubleMinutes(d) - 1;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleMinutes(d - absl::Minutes(1))
+  x = absl::ToDoubleMilliseconds(d) - 9;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleMilliseconds(d - absl::Milliseconds(9))
+  x = absl::ToDoubleMicroseconds(d) - 9;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleMicroseconds(d - absl::Microseconds(9))
+  x = absl::ToDoubleNanoseconds(d) - 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleNanoseconds(d - absl::Nanoseconds(42))
+
+  // We can rewrite the argument of the duration conversion
+#define THIRTY absl::Seconds(30)
+  x = absl::ToDoubleSeconds(THIRTY) - 1.0;
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleSeconds(THIRTY - absl::Seconds(1))
+#undef THIRTY
+
+  // Some other contexts
+  if (absl::ToDoubleSeconds(d) - 1.0 > 10) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: if (absl::ToDoubleSeconds(d - absl::Seconds(1)) > 10) {}
+
+  // A nested occurance
+  x = absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(absl::Seconds(5));
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(5))
+  x = absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(absl::Seconds(absl::ToDoubleSeconds(d1)));
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the duration domain [abseil-duration-subtraction]
+  // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(absl::ToDoubleSeconds(d1)))
+
+  // These should not match
+  x = 5 - 6;
+  x = 4 - absl::ToDoubleSeconds(d) - 6.5 - 8.0;
+  x = absl::ToDoubleSeconds(d) + 1.0;
+  x = absl::ToDoubleSeconds(d) * 1.0;
+  x = absl::ToDoubleSeconds(d) / 1.0;
+
+#define MINUS_FIVE(z) absl::ToDoubleSeconds(z) - 5
+  x = MINUS_FIVE(d);
+#undef MINUS_FIVE
+}
Index: test/clang-tidy/abseil-duration-factory-scale.cpp
===
--- test/clang-tidy/abseil-duration-factory-scale.cpp
+++ test/clang-tidy/abseil-duration-factory-scale.cpp
@@ -1,32 +1,6 @@
-// RUN: %check_clang_tidy %s abseil-duration-factory-scale %t
+// RUN: %check_clang_tidy %s abseil-duration-factory-scale %t -- -- -I %S/Inputs
 

[PATCH] D55245: [clang-tidy] Add the abseil-duration-subtraction check

2018-12-10 Thread Hyrum Wright via Phabricator via cfe-commits
hwright added inline comments.



Comment at: clang-tidy/abseil/DurationRewriter.cpp:21
+struct DurationScale2IndexFunctor {
+  using argument_type = DurationScale;
+  unsigned operator()(DurationScale Scale) const {

JonasToth wrote:
> Are you using `argument_type`? Browser searching did only show one result.
This is required by `IndexedMap`, if I understand correctly.



Comment at: clang-tidy/abseil/DurationRewriter.cpp:23
+  unsigned operator()(DurationScale Scale) const {
+return static_cast(Scale);
+  }

JonasToth wrote:
> Why not `std::uint8_t` as its the underlying type for the `enum`?
This is required by `IndexedMap`, if I understand correctly.



Comment at: clang-tidy/abseil/DurationRewriter.cpp:77
+  getInverseForScale(Scale);
+  if (const auto *MaybeCallArg = selectFirst(
+  "e",

JonasToth wrote:
> In Principle the `Node` could have multiple expressions that are a call if 
> there is nesting. 
> The transformation is correct from what I see right now, but might result in 
> the necessity of multiple passes for the check. (Is the addition version 
> affected from that too?)
> 
> Given the recursive nature of the matcher you could construct a nesting with 
> the inner part being a subtraction, too. The generated fixes would conflict 
> and none of them would be applied. At least thats what I would expect right 
> now. Please take a look at this issue.
There isn't an imminent addition version at this point.

This matcher isn't recursive: it's just looking at the entire node to see if it 
is a call to the inverse function.  If an inverse is embedded as part of a 
deeper expression, it won't see it (e.g., there no `hasDescendant` in this 
matcher).



Comment at: test/clang-tidy/Inputs/absl/time/time.h:1
+// Mimic the implementation of absl::Duration
+namespace absl {

JonasToth wrote:
> I think having the extraction of the common test-stuff into this header as 
> one commit would be better. Would you prepare such a patch? I can commit for 
> you. It probably makes sense if you ask for commit access 
> (https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access). Do as 
> you wish.
I can do this, but it might take a bit to get the commit bit turned on.



Comment at: test/clang-tidy/abseil-duration-subtraction.cpp:12
+  // CHECK-FIXES: absl::ToDoubleSeconds(d - absl::Seconds(1))
+  x = absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(d1);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform subtraction in the 
duration domain [abseil-duration-subtraction]

JonasToth wrote:
> From this example starting:
> 
> - The RHS should be a nested expression with function calls, as the RHS is 
> transformed to create the adversary example i mean in the transformation 
> function above.
> 
> ```
> absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(absl::ToDoubleSeconds(d) - 
> absl::ToDoubleSeconds(d1));
> ```
> I think you need the proper conversion function, as the result of the 
> expression is `double` and you need a `Duration`, right?
> 
> But in principle starting from this idea the transformation might break.
I think there may be some confusion here (and that's entirely my fault. :) )

We should never get this expression as input to the check, since it doesn't 
compile (as you point out):
```
absl::ToDoubleSeconds(d) - absl::ToDoubleSeconds(absl::ToDoubleSeconds(d) - 
absl::ToDoubleSeconds(d1));
```

Since `absl::ToDoubleSeconds` requires that its argument is an 
`absl::Duration`, but the expression `absl::ToDoubleSeconds(d) - 
absl::ToDoubleSeconds(d1)` results in a `double`, we can't get this as input.

There may be other expressions which could be input, but in practice they don't 
really happen.  I've added a contrived example to the tests, but at some point 
the tests get too complex and confuse the fix matching infrastructure.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55245/new/

https://reviews.llvm.org/D55245



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


[PATCH] D55405: [CMake] Use hidden visibility for static libc++ in Fuchsia

2018-12-10 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr accepted this revision.
mcgrathr added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55405/new/

https://reviews.llvm.org/D55405



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


[PATCH] D55395: Re-order content in OMPDeclareReductionDecl dump

2018-12-10 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL348795: Re-order content in OMPDeclareReductionDecl dump 
(authored by steveire, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55395?vs=177428=177589#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55395/new/

https://reviews.llvm.org/D55395

Files:
  cfe/trunk/lib/AST/ASTDumper.cpp
  cfe/trunk/test/AST/dump.cpp


Index: cfe/trunk/test/AST/dump.cpp
===
--- cfe/trunk/test/AST/dump.cpp
+++ cfe/trunk/test/AST/dump.cpp
@@ -13,14 +13,14 @@
 
 #pragma omp declare reduction(fun : float : omp_out += omp_in) 
initializer(omp_priv = omp_orig + 15)
 
-// CHECK:  |-OMPDeclareReductionDecl {{.+}}  col:35 
operator+ 'int' combiner
+// CHECK:  |-OMPDeclareReductionDecl {{.+}}  col:35 
operator+ 'int' combiner 0x{{.+}}
 // CHECK-NEXT: | |-CompoundAssignOperator {{.+}}  'int' lvalue 
'*=' ComputeLHSTy='int' ComputeResultTy='int'
 // CHECK-NEXT: | | |-DeclRefExpr {{.+}}  'int' lvalue Var {{.+}} 
'omp_out' 'int'
 // CHECK-NEXT: | | `-ImplicitCastExpr {{.+}}  'int' 
 // CHECK-NEXT: | |   `-DeclRefExpr {{.+}}  'int' lvalue Var {{.+}} 
'omp_in' 'int'
 // CHECK-NEXT: | |-VarDecl {{.+}}  col:35 implicit used omp_in 'int'
 // CHECK-NEXT: | `-VarDecl {{.+}}  col:35 implicit used omp_out 'int'
-// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}}  col:40 operator+ 
'char' combiner
+// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}}  col:40 operator+ 
'char' combiner 0x{{.+}}
 // CHECK-NEXT: | |-CompoundAssignOperator {{.+}}  'char' 
lvalue '*=' ComputeLHSTy='int' ComputeResultTy='int'
 // CHECK-NEXT: | | |-DeclRefExpr {{.+}}  'char' lvalue Var {{.+}} 
'omp_out' 'char'
 // CHECK-NEXT: | | `-ImplicitCastExpr {{.+}}  'int' 
@@ -28,7 +28,7 @@
 // CHECK-NEXT: | | `-DeclRefExpr {{.+}}  'char' lvalue Var {{.+}} 
'omp_in' 'char'
 // CHECK-NEXT: | |-VarDecl {{.+}}  col:40 implicit used omp_in 'char'
 // CHECK-NEXT: | `-VarDecl {{.+}}  col:40 implicit used omp_out 'char'
-// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}}  col:37 
fun 'float' combiner initializer
+// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}}  col:37 
fun 'float' combiner 0x{{.+}} initializer 0x{{.+}}
 // CHECK-NEXT: | |-CompoundAssignOperator {{.+}}  'float' 
lvalue '+=' ComputeLHSTy='float' ComputeResultTy='float'
 // CHECK-NEXT: | | |-DeclRefExpr {{.+}}  'float' lvalue Var {{.+}} 
'omp_out' 'float'
 // CHECK-NEXT: | | `-ImplicitCastExpr {{.+}}  'float' 
Index: cfe/trunk/lib/AST/ASTDumper.cpp
===
--- cfe/trunk/lib/AST/ASTDumper.cpp
+++ cfe/trunk/lib/AST/ASTDumper.cpp
@@ -1040,9 +1040,10 @@
   NodeDumper.dumpName(D);
   NodeDumper.dumpType(D->getType());
   OS << " combiner";
-  dumpStmt(D->getCombiner());
-  if (auto *Initializer = D->getInitializer()) {
+  NodeDumper.dumpPointer(D->getCombiner());
+  if (const auto *Initializer = D->getInitializer()) {
 OS << " initializer";
+NodeDumper.dumpPointer(Initializer);
 switch (D->getInitializerKind()) {
 case OMPDeclareReductionDecl::DirectInit:
   OS << " omp_priv = ";
@@ -1053,8 +1054,11 @@
 case OMPDeclareReductionDecl::CallInit:
   break;
 }
-dumpStmt(Initializer);
   }
+
+  dumpStmt(D->getCombiner());
+  if (const auto *Initializer = D->getInitializer())
+dumpStmt(Initializer);
 }
 
 void ASTDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) {


Index: cfe/trunk/test/AST/dump.cpp
===
--- cfe/trunk/test/AST/dump.cpp
+++ cfe/trunk/test/AST/dump.cpp
@@ -13,14 +13,14 @@
 
 #pragma omp declare reduction(fun : float : omp_out += omp_in) initializer(omp_priv = omp_orig + 15)
 
-// CHECK:  |-OMPDeclareReductionDecl {{.+}}  col:35 operator+ 'int' combiner
+// CHECK:  |-OMPDeclareReductionDecl {{.+}}  col:35 operator+ 'int' combiner 0x{{.+}}
 // CHECK-NEXT: | |-CompoundAssignOperator {{.+}}  'int' lvalue '*=' ComputeLHSTy='int' ComputeResultTy='int'
 // CHECK-NEXT: | | |-DeclRefExpr {{.+}}  'int' lvalue Var {{.+}} 'omp_out' 'int'
 // CHECK-NEXT: | | `-ImplicitCastExpr {{.+}}  'int' 
 // CHECK-NEXT: | |   `-DeclRefExpr {{.+}}  'int' lvalue Var {{.+}} 'omp_in' 'int'
 // CHECK-NEXT: | |-VarDecl {{.+}}  col:35 implicit used omp_in 'int'
 // CHECK-NEXT: | `-VarDecl {{.+}}  col:35 implicit used omp_out 'int'
-// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}}  col:40 operator+ 'char' combiner
+// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}}  col:40 operator+ 'char' combiner 0x{{.+}}
 // CHECK-NEXT: | |-CompoundAssignOperator {{.+}}  'char' lvalue '*=' ComputeLHSTy='int' ComputeResultTy='int'
 // CHECK-NEXT: | | |-DeclRefExpr {{.+}}  'char' lvalue Var {{.+}} 'omp_out' 'char'
 // CHECK-NEXT: | | `-ImplicitCastExpr {{.+}}  'int' 
@@ 

[PATCH] D55495: Change InitListExpr dump to label and pointer

2018-12-10 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL348794: Change InitListExpr dump to label and pointer 
(authored by steveire, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55495?vs=177426=177588#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55495/new/

https://reviews.llvm.org/D55495

Files:
  cfe/trunk/lib/AST/ASTDumper.cpp
  cfe/trunk/test/AST/ast-dump-stmt.cpp


Index: cfe/trunk/test/AST/ast-dump-stmt.cpp
===
--- cfe/trunk/test/AST/ast-dump-stmt.cpp
+++ cfe/trunk/test/AST/ast-dump-stmt.cpp
@@ -90,9 +90,8 @@
 {
   U us[3] = {1};
 // CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
-// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
-// CHECK-NEXT:   |-array filler
-// CHECK-NEXT:   | `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
'int'
+// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]' array_filler 
0x{{.+}}
+// CHECK-NEXT:   |-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
'int'
 // CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
'int'
 // CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1
 }
Index: cfe/trunk/lib/AST/ASTDumper.cpp
===
--- cfe/trunk/lib/AST/ASTDumper.cpp
+++ cfe/trunk/lib/AST/ASTDumper.cpp
@@ -1951,11 +1951,12 @@
 OS << " field ";
 NodeDumper.dumpBareDeclRef(Field);
   }
+
   if (auto *Filler = ILE->getArrayFiller()) {
-dumpChild([=] {
-  OS << "array filler";
-  dumpStmt(Filler);
-});
+OS << " array_filler";
+NodeDumper.dumpPointer(Filler);
+
+dumpStmt(Filler);
   }
 }
 


Index: cfe/trunk/test/AST/ast-dump-stmt.cpp
===
--- cfe/trunk/test/AST/ast-dump-stmt.cpp
+++ cfe/trunk/test/AST/ast-dump-stmt.cpp
@@ -90,9 +90,8 @@
 {
   U us[3] = {1};
 // CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
-// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
-// CHECK-NEXT:   |-array filler
-// CHECK-NEXT:   | `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 'int'
+// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]' array_filler 0x{{.+}}
+// CHECK-NEXT:   |-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 'int'
 // CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 'int'
 // CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1
 }
Index: cfe/trunk/lib/AST/ASTDumper.cpp
===
--- cfe/trunk/lib/AST/ASTDumper.cpp
+++ cfe/trunk/lib/AST/ASTDumper.cpp
@@ -1951,11 +1951,12 @@
 OS << " field ";
 NodeDumper.dumpBareDeclRef(Field);
   }
+
   if (auto *Filler = ILE->getArrayFiller()) {
-dumpChild([=] {
-  OS << "array filler";
-  dumpStmt(Filler);
-});
+OS << " array_filler";
+NodeDumper.dumpPointer(Filler);
+
+dumpStmt(Filler);
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r348794 - Change InitListExpr dump to label and pointer

2018-12-10 Thread Stephen Kelly via cfe-commits
Author: steveire
Date: Mon Dec 10 12:53:32 2018
New Revision: 348794

URL: http://llvm.org/viewvc/llvm-project?rev=348794=rev
Log:
Change InitListExpr dump to label and pointer

Summary: Don't add a child just for the label.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/test/AST/ast-dump-stmt.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=348794=348793=348794=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Mon Dec 10 12:53:32 2018
@@ -1951,11 +1951,12 @@ void ASTDumper::VisitInitListExpr(const
 OS << " field ";
 NodeDumper.dumpBareDeclRef(Field);
   }
+
   if (auto *Filler = ILE->getArrayFiller()) {
-dumpChild([=] {
-  OS << "array filler";
-  dumpStmt(Filler);
-});
+OS << " array_filler";
+NodeDumper.dumpPointer(Filler);
+
+dumpStmt(Filler);
   }
 }
 

Modified: cfe/trunk/test/AST/ast-dump-stmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-stmt.cpp?rev=348794=348793=348794=diff
==
--- cfe/trunk/test/AST/ast-dump-stmt.cpp (original)
+++ cfe/trunk/test/AST/ast-dump-stmt.cpp Mon Dec 10 12:53:32 2018
@@ -90,9 +90,8 @@ void TestUnionInitList()
 {
   U us[3] = {1};
 // CHECK: VarDecl {{.+}}  col:5 us 'U [3]' cinit
-// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]'
-// CHECK-NEXT:   |-array filler
-// CHECK-NEXT:   | `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
'int'
+// CHECK-NEXT: `-InitListExpr {{.+}}  'U [3]' array_filler 
0x{{.+}}
+// CHECK-NEXT:   |-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
'int'
 // CHECK-NEXT:   `-InitListExpr {{.+}}  'U' field Field {{.+}} 'i' 
'int'
 // CHECK-NEXT: `-IntegerLiteral {{.+}}  'int' 1
 }


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


r348795 - Re-order content in OMPDeclareReductionDecl dump

2018-12-10 Thread Stephen Kelly via cfe-commits
Author: steveire
Date: Mon Dec 10 12:53:39 2018
New Revision: 348795

URL: http://llvm.org/viewvc/llvm-project?rev=348795=rev
Log:
Re-order content in OMPDeclareReductionDecl dump

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/test/AST/dump.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=348795=348794=348795=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Mon Dec 10 12:53:39 2018
@@ -1040,9 +1040,10 @@ void ASTDumper::VisitOMPDeclareReduction
   NodeDumper.dumpName(D);
   NodeDumper.dumpType(D->getType());
   OS << " combiner";
-  dumpStmt(D->getCombiner());
-  if (auto *Initializer = D->getInitializer()) {
+  NodeDumper.dumpPointer(D->getCombiner());
+  if (const auto *Initializer = D->getInitializer()) {
 OS << " initializer";
+NodeDumper.dumpPointer(Initializer);
 switch (D->getInitializerKind()) {
 case OMPDeclareReductionDecl::DirectInit:
   OS << " omp_priv = ";
@@ -1053,8 +1054,11 @@ void ASTDumper::VisitOMPDeclareReduction
 case OMPDeclareReductionDecl::CallInit:
   break;
 }
-dumpStmt(Initializer);
   }
+
+  dumpStmt(D->getCombiner());
+  if (const auto *Initializer = D->getInitializer())
+dumpStmt(Initializer);
 }
 
 void ASTDumper::VisitOMPRequiresDecl(const OMPRequiresDecl *D) {

Modified: cfe/trunk/test/AST/dump.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/dump.cpp?rev=348795=348794=348795=diff
==
--- cfe/trunk/test/AST/dump.cpp (original)
+++ cfe/trunk/test/AST/dump.cpp Mon Dec 10 12:53:39 2018
@@ -13,14 +13,14 @@ int ga, gb;
 
 #pragma omp declare reduction(fun : float : omp_out += omp_in) 
initializer(omp_priv = omp_orig + 15)
 
-// CHECK:  |-OMPDeclareReductionDecl {{.+}}  col:35 
operator+ 'int' combiner
+// CHECK:  |-OMPDeclareReductionDecl {{.+}}  col:35 
operator+ 'int' combiner 0x{{.+}}
 // CHECK-NEXT: | |-CompoundAssignOperator {{.+}}  'int' lvalue 
'*=' ComputeLHSTy='int' ComputeResultTy='int'
 // CHECK-NEXT: | | |-DeclRefExpr {{.+}}  'int' lvalue Var {{.+}} 
'omp_out' 'int'
 // CHECK-NEXT: | | `-ImplicitCastExpr {{.+}}  'int' 
 // CHECK-NEXT: | |   `-DeclRefExpr {{.+}}  'int' lvalue Var {{.+}} 
'omp_in' 'int'
 // CHECK-NEXT: | |-VarDecl {{.+}}  col:35 implicit used omp_in 'int'
 // CHECK-NEXT: | `-VarDecl {{.+}}  col:35 implicit used omp_out 'int'
-// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}}  col:40 operator+ 
'char' combiner
+// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}}  col:40 operator+ 
'char' combiner 0x{{.+}}
 // CHECK-NEXT: | |-CompoundAssignOperator {{.+}}  'char' 
lvalue '*=' ComputeLHSTy='int' ComputeResultTy='int'
 // CHECK-NEXT: | | |-DeclRefExpr {{.+}}  'char' lvalue Var {{.+}} 
'omp_out' 'char'
 // CHECK-NEXT: | | `-ImplicitCastExpr {{.+}}  'int' 
@@ -28,7 +28,7 @@ int ga, gb;
 // CHECK-NEXT: | | `-DeclRefExpr {{.+}}  'char' lvalue Var {{.+}} 
'omp_in' 'char'
 // CHECK-NEXT: | |-VarDecl {{.+}}  col:40 implicit used omp_in 'char'
 // CHECK-NEXT: | `-VarDecl {{.+}}  col:40 implicit used omp_out 'char'
-// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}}  col:37 
fun 'float' combiner initializer
+// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}}  col:37 
fun 'float' combiner 0x{{.+}} initializer 0x{{.+}}
 // CHECK-NEXT: | |-CompoundAssignOperator {{.+}}  'float' 
lvalue '+=' ComputeLHSTy='float' ComputeResultTy='float'
 // CHECK-NEXT: | | |-DeclRefExpr {{.+}}  'float' lvalue Var {{.+}} 
'omp_out' 'float'
 // CHECK-NEXT: | | `-ImplicitCastExpr {{.+}}  'float' 


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


[PATCH] D55433: [clang-tidy] Adding a new modernize use nodiscard checker

2018-12-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/clang-tidy/checks/modernize-use-nodiscard.rst:49
+
+
+.. code-block:: c++

Unnecessary empty line.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55433/new/

https://reviews.llvm.org/D55433



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


[PATCH] D53738: [Fixed Point Arithmetic] Fixed Point Addition

2018-12-10 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I'm fine with making this change under the assumption that we've gotten the 
language rule right.  Even if that weren't abstractly reasonable for general 
language work — and I do think it's reasonable when we have a good-faith 
question about the right semantics — this is clearly still an experimental 
implementation and will be for several months yet, and hopefully it won't take 
that long for us to get a response.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53738/new/

https://reviews.llvm.org/D53738



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


[PATCH] D55447: [Sema] Fix Modified Type in address_space AttributedType

2018-12-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Sema/address_space_attribute.cpp:9
+  // CHECK: VarDecl {{.*}} x '__attribute__((address_space(1))) int *'
+  __attribute__((address_space(1))) int *x;
+

leonardchan wrote:
> aaron.ballman wrote:
> > Can you also add a test using the `[[clang::address_space(1)]]` spelling 
> > and ensure that it is printed properly?
> I do not think `address_space` has double bracket spelling. Is there a 
> specific attribute under Attr.td or other td file that specifies if an 
> attribute is supported with c++ spelling?
All attributes with the `Clang` spelling are given a GNU-style 
(`__attribute__((foo))`) spelling and a double-square bracket 
(`[[clang::foo]]`) spelling in the clang vendor namespace (for both C++ and C). 
Attributes with the `GCC` spelling are similar in that they provide a GNU-style 
and double-square bracket spelling (in the `gnu` vendor namespace), though the 
`[[]]` spelling is currently only for C++.



Comment at: clang/tools/libclang/CXType.cpp:132
+  if (!(TU->ParsingOptions & CXTranslationUnit_IncludeAttributedTypes) &&
+  ATT->getAttrKind() != attr::AddressSpace) {
 return MakeCXType(ATT->getModifiedType(), TU);

leonardchan wrote:
> aaron.ballman wrote:
> > This change seems surprising -- if the parsing options say the caller does 
> > not want attributed types, why are we returning one anyway for address 
> > space?
> This has to do with ensuring `clang_getAddressSpace` still returns the proper 
> address_space. It does this by essentially checking the qualifiers of the 
> type, which we now attach to the `AttributedType` whereas before it was 
> attached to the modified type.
> 
> This extra condition is necessary for ensuring that calling 
> `clang_getAddressSpace` points to the qualified AttributedType instead of the 
> unqualified modified type.
My fear is that this will be breaking assumptions in third-party code. If 
someone disables `CXTranslationUnit_IncludeAttributedTypes`, they are unlikely 
to expect to receive an `AttributedType` and may react poorly to it.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55447/new/

https://reviews.llvm.org/D55447



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


[PATCH] D53738: [Fixed Point Arithmetic] Fixed Point Addition

2018-12-10 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In D53738#1325998 , @rjmccall wrote:

> We sent the question out, but we haven't gotten a response yet.  I think 
> going forward under the idea that this just changes the type but does the 
> operation on the original operand types is the right way to go forward in the 
> short term.


Ok. Do you think it would be safe to submit this patch currently with the 
operations handled as you mentioned, or should we wait until we get a response 
and I can attach future revisions to this patch?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53738/new/

https://reviews.llvm.org/D53738



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


[PATCH] D48342: [libcxx] Optimize vectors construction of trivial types from an iterator range with const-ness mismatch.

2018-12-10 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: libcxx/include/memory:1645
 
-template 
+template 
 _LIBCPP_INLINE_VISIBILITY

ldionne wrote:
> Quuxplusone wrote:
> > ldionne wrote:
> > > Coming at it from a slightly different angle, I would think this is what 
> > > we want:
> > > 
> > > ```
> > > template  > >   class _RawSourceTp = typename remove_const<_SourceTp>::type,
> > >   class _RawDestTp = typename remove_const<_DestTp>::type>
> > > _LIBCPP_INLINE_VISIBILITY static typename enable_if<
> > >   
> > >  // We can use memcpy instead of a loop with construct if...
> > > is_trivially_move_constructible<_DestTp>::value &&
> > >  // - the Dest is trivially move constructible, and
> > > is_same<_RawSourceTp, _RawDestTp>::value &&   
> > >  // - both types are the same modulo constness, and either
> > > (__is_default_allocator::value || 
> > >  //   + the allocator is the default allocator (and we know `construct` 
> > > is just placement-new), or
> > >  !__has_construct > > const&>::value), //   + the allocator does not provide a custom 
> > > `construct` method (so we'd fall back to placement-new)
> > > void>::type
> > > __construct_range_forward(allocator_type&, _SourceTp* __begin1, 
> > > _SourceTp* __end1, _DestTp*& __begin2)
> > > {
> > > ptrdiff_t _Np = __end1 - __begin1;
> > > if (_Np > 0)
> > > {
> > > _VSTD::memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * 
> > > sizeof(_DestTp));
> > > __begin2 += _Np;
> > > }
> > > }
> > > ```
> > > 
> > > And then we should have
> > > 
> > > ```
> > > template 
> > > struct __is_default_allocator : false_type { };
> > > 
> > > template 
> > > struct __is_default_allocator<_VSTD::allocator<_Tp> > : true_type { };
> > > ```
> > > 
> > > Does this make sense?
> > > 
> > > Also, I'm not sure I understand why we use `const_cast` on the 
> > > destination type. It seems like we should instead enforce that it is 
> > > non-const? But this is a pre-existing thing in the code, this doesn't 
> > > affect this review.
> > > 
> > I agree that it is wrong to express the check in terms of 
> > `is_same>`; it should be expressed in terms 
> > of a trait which is satisfied by `std::allocator`-for-any-T. @ldionne 
> > expressed it in terms of `__is_default_allocator`. I continue to ask 
> > that it be expressed in terms of `__has_trivial_construct > _SourceTp&>`, where libc++ specializes 
> > `__has_trivial_construct, ...>` if need be.
> > 
> > Orthogonally, the condition `__has_construct > _SourceTp const&>` is wrong because it has an extra `const`. It is 
> > conceivable — though of course implausible/pathological — for 
> > `construct(T*, T&)` to exist and do something different from `construct(T*, 
> > const T&)`.
> > I continue to ask that it be expressed in terms of 
> > `__has_trivial_construct`, where libc++ 
> > specializes `__has_trivial_construct, ...>` if need be.
> 
> Would you be OK with us applying this fix and then generalizing 
> `__is_default_allocator` into `__has_trivial_construct` as a followup? I 
> suspect we'll have more discussion around that generalization and I'd like 
> for us to fix this bug because I find PR37574 somewhat concerning and I'd 
> like for it to be fixed soon (like within a couple of days).
> 
> > Orthogonally, the condition `__has_construct > _SourceTp const&>` is wrong because it has an extra const. It is 
> > conceivable — though of course implausible/pathological — for 
> > `construct(T*, T&)` to exist and do something different from `construct(T*, 
> > const T&)`.
> 
> 
> Good catch. IIUC, `__has_construct` 
> would work?
> 
> Would you be OK with us applying this fix and then generalizing 
> `__is_default_allocator` into `__has_trivial_construct` as a followup?

Yes, I would; although I am somewhat cynical about the followup ever actually 
happening. :P

> IIUC, `__has_construct` would work?

Yes.



Comment at: libcxx/include/memory:1658
+|| !__has_construct::value) &&
+ is_trivially_move_constructible<_DestTp>::value,
 void

Shouldn't this be something like `is_trivially_constructible<_DestTp, 
_SourceTp&>`?  I mean, we're never doing move-construction here. We're 
constructing `_DestTp` from `_SourceTp&`, which is either copy-construction or 
non-const-copy-construction, depending on the constness of `_SourceTp`.

`is_trivially_constructible` has pitfalls in general — 
https://quuxplusone.github.io/blog/2018/07/03/trivially-constructible-from/ — 
but I think we won't fall into any of those pits as long as we're testing that 
`_SourceTp` is cv-qualified `_DestTp`.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D48342/new/

https://reviews.llvm.org/D48342




[PATCH] D55447: [Sema] Fix Modified Type in address_space AttributedType

2018-12-10 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 177587.
leonardchan marked 3 inline comments as done.

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55447/new/

https://reviews.llvm.org/D55447

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/address_space_attribute.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -128,7 +128,8 @@
   if (TU && !T.isNull()) {
 // Handle attributed types as the original type
 if (auto *ATT = T->getAs()) {
-  if (!(TU->ParsingOptions & CXTranslationUnit_IncludeAttributedTypes)) {
+  if (!(TU->ParsingOptions & CXTranslationUnit_IncludeAttributedTypes) &&
+  ATT->getAttrKind() != attr::AddressSpace) {
 return MakeCXType(ATT->getModifiedType(), TU);
   }
 }
Index: clang/test/AST/address_space_attribute.cpp
===
--- /dev/null
+++ clang/test/AST/address_space_attribute.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -ast-dump | FileCheck %s
+
+// Veryify the ordering of the address_space attribute still comes before the
+// type whereas other attributes are still printed after.
+
+template 
+void func() {
+  // CHECK: VarDecl {{.*}} x '__attribute__((address_space(1))) int *'
+  __attribute__((address_space(1))) int *x;
+
+  // CHECK: VarDecl {{.*}} a 'int * __attribute__((noderef))'
+  int __attribute__((noderef)) * a;
+
+  __attribute__((address_space(I))) int *y;
+  // CHECK: VarDecl {{.*}} y '__attribute__((address_space(2))) int *'
+}
+
+void func2() {
+  func<2>();
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5740,28 +5740,27 @@
 // Type Attribute Processing
 //===--===//
 
-/// BuildAddressSpaceAttr - Builds a DependentAddressSpaceType if an expression
-/// is uninstantiated. If instantiated it will apply the appropriate address space
-/// to the type. This function allows dependent template variables to be used in
-/// conjunction with the address_space attribute
-QualType Sema::BuildAddressSpaceAttr(QualType , Expr *AddrSpace,
- SourceLocation AttrLoc) {
+/// Build an AddressSpace index from a constant expression and diagnose any
+/// errors related to invalid address_spaces. Returns true on successfully
+/// building an AddressSpace index.
+static bool BuildAddressSpaceIndex(Sema , LangAS ,
+   const Expr *AddrSpace,
+   SourceLocation AttrLoc) {
   if (!AddrSpace->isValueDependent()) {
-
 llvm::APSInt addrSpace(32);
-if (!AddrSpace->isIntegerConstantExpr(addrSpace, Context)) {
-  Diag(AttrLoc, diag::err_attribute_argument_type)
+if (!AddrSpace->isIntegerConstantExpr(addrSpace, S.Context)) {
+  S.Diag(AttrLoc, diag::err_attribute_argument_type)
   << "'address_space'" << AANT_ArgumentIntegerConstant
   << AddrSpace->getSourceRange();
-  return QualType();
+  return false;
 }
 
 // Bounds checking.
 if (addrSpace.isSigned()) {
   if (addrSpace.isNegative()) {
-Diag(AttrLoc, diag::err_attribute_address_space_negative)
+S.Diag(AttrLoc, diag::err_attribute_address_space_negative)
 << AddrSpace->getSourceRange();
-return QualType();
+return false;
   }
   addrSpace.setIsSigned(false);
 }
@@ -5770,14 +5769,28 @@
 max =
 Qualifiers::MaxAddressSpace - (unsigned)LangAS::FirstTargetAddressSpace;
 if (addrSpace > max) {
-  Diag(AttrLoc, diag::err_attribute_address_space_too_high)
+  S.Diag(AttrLoc, diag::err_attribute_address_space_too_high)
   << (unsigned)max.getZExtValue() << AddrSpace->getSourceRange();
-  return QualType();
+  return false;
 }
 
-LangAS ASIdx =
+ASIdx =
 getLangASFromTargetAS(static_cast(addrSpace.getZExtValue()));
+return true;
+  }
 
+  // Default value for DependentAddressSpaceTypes
+  ASIdx = LangAS::Default;
+  return true;
+}
+
+/// BuildAddressSpaceAttr - Builds a DependentAddressSpaceType if an expression
+/// is uninstantiated. If instantiated it will apply the appropriate address
+/// space to the type. This function allows dependent template variables to be
+/// used in conjunction with the address_space attribute
+QualType Sema::BuildAddressSpaceAttr(QualType , LangAS ASIdx, Expr *AddrSpace,
+ SourceLocation AttrLoc) {
+  if (!AddrSpace->isValueDependent()) {
 // If this type is already address space qualified with a different
 // address space, reject it.
 // ISO/IEC TR 

[PATCH] D55447: [Sema] Fix Modified Type in address_space AttributedType

2018-12-10 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added inline comments.



Comment at: clang/test/Sema/address_space_attribute.cpp:9
+  // CHECK: VarDecl {{.*}} x '__attribute__((address_space(1))) int *'
+  __attribute__((address_space(1))) int *x;
+

aaron.ballman wrote:
> Can you also add a test using the `[[clang::address_space(1)]]` spelling and 
> ensure that it is printed properly?
I do not think `address_space` has double bracket spelling. Is there a specific 
attribute under Attr.td or other td file that specifies if an attribute is 
supported with c++ spelling?



Comment at: clang/tools/libclang/CXType.cpp:132
+  if (!(TU->ParsingOptions & CXTranslationUnit_IncludeAttributedTypes) &&
+  ATT->getAttrKind() != attr::AddressSpace) {
 return MakeCXType(ATT->getModifiedType(), TU);

aaron.ballman wrote:
> This change seems surprising -- if the parsing options say the caller does 
> not want attributed types, why are we returning one anyway for address space?
This has to do with ensuring `clang_getAddressSpace` still returns the proper 
address_space. It does this by essentially checking the qualifiers of the type, 
which we now attach to the `AttributedType` whereas before it was attached to 
the modified type.

This extra condition is necessary for ensuring that calling 
`clang_getAddressSpace` points to the qualified AttributedType instead of the 
unqualified modified type.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55447/new/

https://reviews.llvm.org/D55447



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


[PATCH] D55433: [clang-tidy] Adding a new modernize use nodiscard checker

2018-12-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 177584.
MyDeveloperDay marked 11 inline comments as done.
MyDeveloperDay added a comment.

Addressing review comments

- grammatical errors in documentation and comments
- prevent adding [[nodiscard]] to macros
- clean up list.rst


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55433/new/

https://reviews.llvm.org/D55433

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseNodiscardCheck.cpp
  clang-tidy/modernize/UseNodiscardCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-nodiscard.rst
  test/clang-tidy/modernize-use-nodiscard-cxx11.cpp
  test/clang-tidy/modernize-use-nodiscard-no-macro.cpp
  test/clang-tidy/modernize-use-nodiscard.cpp

Index: test/clang-tidy/modernize-use-nodiscard.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-nodiscard.cpp
@@ -0,0 +1,142 @@
+// RUN: %check_clang_tidy %s modernize-use-nodiscard %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-nodiscard.ReplacementString, value: 'NO_DISCARD'}]}" \
+// RUN: -- -std=c++17 \
+
+#define MUST_USE_RESULT __attribute__((warn_unused_result))
+#define NO_DISCARD [[nodiscard]]
+#define NO_RETURN [[noreturn]]
+
+#define BOOLEAN_FUNC bool f23() const
+
+class Foo
+{
+public:
+bool f1() const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f1' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD bool f1() const;
+
+bool f2(int) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f2' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD bool f2(int) const;
+
+bool f3(const int &) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f3' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD bool f3(const int &) const;
+
+bool f4(void) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f4' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD bool f4(void) const;
+
+// negative tests
+
+void f5() const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: void f5() const;
+
+bool f6();
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: bool f6();
+
+bool f7(int &);
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: bool f7(int &);
+
+bool f8(int &) const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: bool f8(int &) const;
+
+bool f9(int *) const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: bool f9(int *) const;
+
+bool f10(const int &,int &) const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: bool f10(const int &,int &) const;
+
+NO_DISCARD bool f12() const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: NO_DISCARD bool f12() const;
+
+MUST_USE_RESULT bool f13() const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: MUST_USE_RESULT bool f13() const;
+   
+[[nodiscard]] bool f11() const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: {{\[\[nodiscard\]\]}} bool f11() const;
+
+bool _f20() const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function '_f20' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD bool _f20() const;
+
+NO_RETURN bool f21() const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: NO_RETURN bool f21() const;
+
+~Foo();
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: ~Foo();
+
+bool operator +=(int) const;
+// CHECK-MESSAGES-NOT: warning:
+// CHECK-FIXES: bool operator +=(int) const;
+   
+// extra keywords (virtual,inline,const) on return type
+
+virtual bool f14() const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f14' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD virtual bool f14() const;
+
+const bool f15() const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f15' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD const bool f15() const;
+
+inline const bool f16() const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f16' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD inline const bool f16() const;
+
+inline virtual const bool f17() const;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f17' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD inline virtual const bool f17() const;
+
+// inline with body
+bool f18() const {
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f18' should be marked NO_DISCARD [modernize-use-nodiscard]
+// CHECK-FIXES: NO_DISCARD bool f18() const {
+return true;
+}
+
+   

[PATCH] D55483: Introduce the callback attribute and emit !callback metadata

2018-12-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

This is missing all of the Sema and SemaCXX tests. Should have tests for member 
functions, variadic functions, incorrect arguments, incorrect subjects, etc.




Comment at: include/clang/Basic/Attr.td:1204
+  VariadicUnsignedArgument<"PayloadIndices">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [Undocumented];

Should this also apply to Objective-C methods?

Why should the user specify this attribute on the function as opposed to on the 
parameter? e.g.,
```
// Why this:
__attribute__((callback (1, 2, 3)))
void* broker0(void* (*callee)(void *), void *payload, int otherPayload) {
  return callee(payload);
}

// Instead of this:
void* broker0(void* (*callee)(void *) __attribute__((callback (2, 3))), void 
*payload, int otherPayload) {
  return callee(payload);
}

// Or this:
void* broker0(void* (*callee)(void *) __attribute__((callback (payload, 
otherPayload))), void *payload, int otherPayload) {
  return callee(payload);
}
```
I ask because these "use an index" attributes are really hard for users to use 
in practice. They have to account for 0-vs-1 based indexing, implicit this 
parameters, etc and if we can avoid that, it may be worth the effort.



Comment at: include/clang/Basic/Attr.td:1205
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [Undocumented];
+}

No new undocumented attributes, please.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55483/new/

https://reviews.llvm.org/D55483



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


[PATCH] D55447: [Sema] Fix Modified Type in address_space AttributedType

2018-12-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Sema/address_space_attribute.cpp:1
+// RUN: %clang_cc1 %s -ast-dump | FileCheck %s
+

This test should be moved to the AST directory instead of Sema.



Comment at: clang/test/Sema/address_space_attribute.cpp:9
+  // CHECK: VarDecl {{.*}} x '__attribute__((address_space(1))) int *'
+  __attribute__((address_space(1))) int *x;
+

Can you also add a test using the `[[clang::address_space(1)]]` spelling and 
ensure that it is printed properly?



Comment at: clang/tools/libclang/CXType.cpp:132
+  if (!(TU->ParsingOptions & CXTranslationUnit_IncludeAttributedTypes) &&
+  ATT->getAttrKind() != attr::AddressSpace) {
 return MakeCXType(ATT->getModifiedType(), TU);

This change seems surprising -- if the parsing options say the caller does not 
want attributed types, why are we returning one anyway for address space?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55447/new/

https://reviews.llvm.org/D55447



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


[PATCH] D55212: Handle alloc_size attribute on function pointers

2018-12-10 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson marked an inline comment as done.
arichardson added inline comments.



Comment at: test/Misc/pragma-attribute-supported-attributes-list.test:15
+// FIXME: After changing the subject from Function to HasFunctionProto, 
AllocSize is no longer listed (similar to Format, etc)
+// FIXME-NEXT: AllocSize (SubjectMatchRule_function)
 // CHECK-NEXT: AlwaysDestroy (SubjectMatchRule_variable)

aaron.ballman wrote:
> arichardson wrote:
> > This seems to also affect __attribute((format)) and others so I'm not sure 
> > whether removing AllocSize from this list is a blocker for this patch.
> I believe you may need to add an `AttrSubjectMatcherSubRule` in Attr.td to 
> expose the attribute for `#pragma clang attribute` support. Can you see if 
> you can support it instead of shrinking this list? Otherwise, I worry that 
> this change will break code that was using the pragma to apply the attribute 
> to declarations.
The problem here already has a fixme in attr.td:

```
  // FIXME: There's a matcher ambiguity with objc methods and blocks since
  // functionType excludes them but functionProtoType includes them.
  // AttrSubjectMatcherSubRule<"functionProtoType", [HasFunctionProto]>
```

It seems like this was already added as part of the initial pragma clang 
attribute commit in https://reviews.llvm.org/D30009

I had a look at the AttrEmitter.cpp in tablegen but couldn't find a 
straightforward solution.
I'll add @arphaman to the review.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55212/new/

https://reviews.llvm.org/D55212



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


[PATCH] D53738: [Fixed Point Arithmetic] Fixed Point Addition

2018-12-10 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

We sent the question out, but we haven't gotten a response yet.  I think going 
forward under the idea that this just changes the type but does the operation 
on the original operand types is the right way to go forward in the short term.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53738/new/

https://reviews.llvm.org/D53738



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


[PATCH] D55212: Handle alloc_size attribute on function pointers

2018-12-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: test/Misc/pragma-attribute-supported-attributes-list.test:15
+// FIXME: After changing the subject from Function to HasFunctionProto, 
AllocSize is no longer listed (similar to Format, etc)
+// FIXME-NEXT: AllocSize (SubjectMatchRule_function)
 // CHECK-NEXT: AlwaysDestroy (SubjectMatchRule_variable)

arichardson wrote:
> This seems to also affect __attribute((format)) and others so I'm not sure 
> whether removing AllocSize from this list is a blocker for this patch.
I believe you may need to add an `AttrSubjectMatcherSubRule` in Attr.td to 
expose the attribute for `#pragma clang attribute` support. Can you see if you 
can support it instead of shrinking this list? Otherwise, I worry that this 
change will break code that was using the pragma to apply the attribute to 
declarations.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55212/new/

https://reviews.llvm.org/D55212



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


[PATCH] D55527: Normalize GlobalDecls when used with CPUDispatch

2018-12-10 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: rsmith, aaron.ballman.

Previously, CPUDispatch functionality did some wacky things with
GlobalDecls, which resulted in multiple GlobalDecls having the same
mangled name. This patch corrects this in a few ways:

First, it Moves the emission of CPUDispatch resolvers to the end of the
translation unit.  This is akin to how 'target' multiversioning works,
and permits the resolver emission mechanism to see all possible
FunctionDecls in the TU.

Second, it changes the meaning of the GlobalDecl MultiVersionIndex to
MultiVersionOrdinal.  In the case of CPUSpecific, '0' now means "A call
to a non-present CPUDispatch function".  Other ordinals are the order of
the CPU Name in the attribute source.  In the case of CPUDispatch, '0'
is the resolver function, and other ordinals represent the non-present
CPU-Specific version.

Because of this, the 1:1 relationship between a GlobalDecl and a
Mangled Name is restored. Additionally, it results in functions only
being emitted when necessary, rather than use a variety of hackery to
emit in cases we presume they would be used.


https://reviews.llvm.org/D55527

Files:
  include/clang/AST/GlobalDecl.h
  include/clang/Basic/Attr.td
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  test/CodeGen/attr-cpuspecific.c

Index: test/CodeGen/attr-cpuspecific.c
===
--- test/CodeGen/attr-cpuspecific.c
+++ test/CodeGen/attr-cpuspecific.c
@@ -29,21 +29,7 @@
 
 ATTR(cpu_dispatch(ivybridge, knl))
 void TwoVersions(void);
-// LINUX: define void ()* @TwoVersions.resolver()
-// LINUX: call void @__cpu_indicator_init
-// LINUX: ret void ()* @TwoVersions.Z
-// LINUX: ret void ()* @TwoVersions.S
-// LINUX: call void @llvm.trap
-// LINUX: unreachable
-
-// WINDOWS: define dso_local void @TwoVersions()
-// WINDOWS: call void @__cpu_indicator_init()
-// WINDOWS: call void @TwoVersions.Z()
-// WINDOWS-NEXT: ret void
-// WINDOWS: call void @TwoVersions.S()
-// WINDOWS-NEXT: ret void
-// WINDOWS: call void @llvm.trap
-// WINDOWS: unreachable
+// Resolvers are emitted at the end, so the check lines are at the bottom.
 
 ATTR(cpu_specific(ivybridge))
 void TwoVersions(void){}
@@ -82,6 +68,59 @@
 // has an extra config to emit!
 ATTR(cpu_dispatch(ivybridge, knl, atom))
 void TwoVersionsSameAttr(void);
+// Resolvers are emitted at the end, so the check lines are at the bottom.
+
+ATTR(cpu_dispatch(atom, ivybridge, knl))
+void ThreeVersionsSameAttr(void){}
+// Resolvers are emitted at the end, so the check lines are at the bottom.
+
+// No Cpu Specific options.
+ATTR(cpu_dispatch(atom, ivybridge, knl))
+void NoSpecifics(void);
+// Resolvers are emitted at the end, so the check lines are at the bottom.
+
+ATTR(cpu_dispatch(atom, generic, ivybridge, knl))
+void HasGeneric(void);
+// Resolvers are emitted at the end, so the check lines are at the bottom.
+
+ATTR(cpu_dispatch(atom, generic, ivybridge, knl))
+void HasParams(int i, double d);
+// Resolvers are emitted at the end, so the check lines are at the bottom.
+
+ATTR(cpu_dispatch(atom, generic, ivybridge, knl))
+int HasParamsAndReturn(int i, double d);
+// Resolvers are emitted at the end, so the check lines are at the bottom.
+
+ATTR(cpu_dispatch(atom, generic, pentium))
+int GenericAndPentium(int i, double d);
+// Resolvers are emitted at the end, so the check lines are at the bottom.
+
+ATTR(cpu_dispatch(atom, pentium))
+int DispatchFirst(void);
+// Resolvers are emitted at the end, so the check lines are at the bottom.
+
+ATTR(cpu_specific(atom))
+int DispatchFirst(void) {return 0;}
+ATTR(cpu_specific(pentium))
+int DispatchFirst(void) {return 1;}
+// Resolver emit causes these to be emited, so they happen later.
+
+// LINUX: define void ()* @TwoVersions.resolver()
+// LINUX: call void @__cpu_indicator_init
+// LINUX: ret void ()* @TwoVersions.Z
+// LINUX: ret void ()* @TwoVersions.S
+// LINUX: call void @llvm.trap
+// LINUX: unreachable
+
+// WINDOWS: define dso_local void @TwoVersions()
+// WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: call void @TwoVersions.Z()
+// WINDOWS-NEXT: ret void
+// WINDOWS: call void @TwoVersions.S()
+// WINDOWS-NEXT: ret void
+// WINDOWS: call void @llvm.trap
+// WINDOWS: unreachable
+
 // LINUX: define void ()* @TwoVersionsSameAttr.resolver()
 // LINUX: ret void ()* @TwoVersionsSameAttr.Z
 // LINUX: ret void ()* @TwoVersionsSameAttr.S
@@ -99,8 +138,6 @@
 // WINDOWS: call void @llvm.trap
 // WINDOWS: unreachable
 
-ATTR(cpu_dispatch(atom, ivybridge, knl))
-void ThreeVersionsSameAttr(void){}
 // LINUX: define void ()* @ThreeVersionsSameAttr.resolver()
 // LINUX: call void @__cpu_indicator_init
 // LINUX: ret void ()* @ThreeVersionsSameAttr.Z
@@ -120,9 +157,16 @@
 // WINDOWS: call void @llvm.trap
 // WINDOWS: unreachable
 
-// No Cpu Specific options.
-ATTR(cpu_dispatch(atom, ivybridge, knl))
-void NoSpecifics(void);
+// LINUX: define i32 @DispatchFirst.O
+// LINUX: ret i32 0

[PATCH] D54489: Implement -frecord-command-line (-frecord-gcc-switches)

2018-12-10 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

There may be changes to some details in the LLVM patch; once they are finalized 
I will update the Clang patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54489/new/

https://reviews.llvm.org/D54489



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


[PATCH] D55508: [clang-tidy] insert release notes for new checkers alphabetically

2018-12-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In D55508#1325960 , @Eugene.Zelenko 
wrote:

> By the word, will be good idea to have script which check alphabetical order 
> and use it during build. Sometimes alphabetical order may be violated after 
> merge with trunk.


I think that should be in the `validate-check.py` proposed in the other patch. 
If we just add it to the normal testing/documentation generation it would be 
best. I think it is like a unit-test in spirit.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55508/new/

https://reviews.llvm.org/D55508



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


[PATCH] D55488: Add utility for dumping a label with child nodes

2018-12-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/AST/ASTDumperUtils.h:115
+  template 
+  void addChild(const std::string , Fn doAddChild) {
+if (label.empty())

label -> Label
doAddChild -> DoAddChild



Comment at: include/clang/AST/ASTDumperUtils.h:117
+if (label.empty())
+  return addChild(doAddChild);
+addChild([=] {

While correct, this is a bit too clever -- can you switch to using a more 
idiomatic return statement?



Comment at: lib/AST/ASTDumper.cpp:66
+template 
+void dumpChild(const std::string , Fn doDumpChild) {
+  TreeStructure.addChild(label, doDumpChild);

Label, DoDumpChild



Comment at: lib/AST/ASTDumper.cpp:89
 void dumpDecl(const Decl *D);
-void dumpStmt(const Stmt *S);
+void dumpStmt(const Stmt *S, const std::string  = {});
 

Label

Rather than using `{}`, how about `""` (same behavior, but looks more 
idiomatic).

Why `std::string` instead of `StringRef`? I expect this will be called mostly 
with string literals, which saves an allocation. The other labels are using 
`const char *`, which would be another reasonable option. Whatever we go with, 
it'd be nice to make the label types agree across the calls.



Comment at: lib/AST/ASTDumper.cpp:1692
 
-void ASTDumper::dumpStmt(const Stmt *S) {
-  dumpChild([=] {
+void ASTDumper::dumpStmt(const Stmt *S, const std::string ) {
+  dumpChild(label, [=] {

label -> Label


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55488/new/

https://reviews.llvm.org/D55488



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


[PATCH] D55508: [clang-tidy] insert release notes for new checkers alphabetically

2018-12-10 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

By the word, will be good idea to have script which check alphabetical order 
and use it during build. Sometimes alphabetical order may be violated after 
merge with trunk.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55508/new/

https://reviews.llvm.org/D55508



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


[clang-tools-extra] r348793 - [clang-tidy] insert release notes for new checkers alphabetically

2018-12-10 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Mon Dec 10 11:41:53 2018
New Revision: 348793

URL: http://llvm.org/viewvc/llvm-project?rev=348793=rev
Log:
[clang-tidy]  insert release notes for new checkers alphabetically

Summary:
Almost all code review comments on new checkers {D55433} {D48866} {D54349} seem 
to ask for the release notes to be added alphabetically, plus I've seen commits 
by @Eugene.Zelenko reordering the lists

Make add_new_check.py add those release notes alphabetically based on checker 
name

If include-fixer section is seen add it at the end

Minor change in the message format to prevent double newlines added before the 
checker.

Do the tools themselves have unit tests? (sorry new to this game)

- Tested adding new checker at the beginning
- Tested on adding new checker in the middle
- Tested on empty ReleasesNotes.rst (as we would see after RC)

Patch by MyDeveloperDay.

Reviewers: alexfh, JonasToth, curdeius, aaron.ballman, benhamilton, hokein

Reviewed By: JonasToth

Subscribers: cfe-commits, xazax.hun, Eugene.Zelenko

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/add_new_check.py

Modified: clang-tools-extra/trunk/clang-tidy/add_new_check.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/add_new_check.py?rev=348793=348792=348793=diff
==
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py Mon Dec 10 11:41:53 2018
@@ -200,23 +200,47 @@ def add_release_notes(module_path, modul
   with open(filename, 'r') as f:
 lines = f.readlines()
 
+  lineMatcher = re.compile('Improvements to clang-tidy')
+  nextSectionMatcher = re.compile('Improvements to include-fixer')
+  checkerMatcher = re.compile('- New :doc:`(.*)')
+
   print('Updating %s...' % filename)
   with open(filename, 'w') as f:
 note_added = False
 header_found = False
+next_header_found = False
+add_note_here = False
 
 for line in lines:
   if not note_added:
-match = re.search('Improvements to clang-tidy', line)
+match = lineMatcher.match(line)
+match_next = nextSectionMatcher.match(line)
+match_checker = checkerMatcher.match(line)
+if match_checker:
+  last_checker = match_checker.group(1)
+  if last_checker > check_name_dashes:
+add_note_here = True
+
+if match_next:
+  next_header_found = True
+  add_note_here = True
+
 if match:
   header_found = True
-elif header_found:
+  f.write(line)
+  continue
+
+if line.startswith(''):
+  f.write(line)
+  continue
+
+if header_found and add_note_here:
   if not line.startswith(''):
-f.write("""
-- New :doc:`%s
+f.write("""- New :doc:`%s
   ` check.
 
   FIXME: add release notes.
+
 """ % (check_name_dashes, check_name_dashes))
 note_added = True
 


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


[PATCH] D55508: [clang-tidy] insert release notes for new checkers alphabetically

2018-12-10 Thread Jonas Toth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL348793: [clang-tidy]  insert release notes for new checkers 
alphabetically (authored by JonasToth, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55508?vs=177538=177578#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55508/new/

https://reviews.llvm.org/D55508

Files:
  clang-tools-extra/trunk/clang-tidy/add_new_check.py


Index: clang-tools-extra/trunk/clang-tidy/add_new_check.py
===
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py
@@ -200,23 +200,47 @@
   with open(filename, 'r') as f:
 lines = f.readlines()
 
+  lineMatcher = re.compile('Improvements to clang-tidy')
+  nextSectionMatcher = re.compile('Improvements to include-fixer')
+  checkerMatcher = re.compile('- New :doc:`(.*)')
+
   print('Updating %s...' % filename)
   with open(filename, 'w') as f:
 note_added = False
 header_found = False
+next_header_found = False
+add_note_here = False
 
 for line in lines:
   if not note_added:
-match = re.search('Improvements to clang-tidy', line)
+match = lineMatcher.match(line)
+match_next = nextSectionMatcher.match(line)
+match_checker = checkerMatcher.match(line)
+if match_checker:
+  last_checker = match_checker.group(1)
+  if last_checker > check_name_dashes:
+add_note_here = True
+
+if match_next:
+  next_header_found = True
+  add_note_here = True
+
 if match:
   header_found = True
-elif header_found:
+  f.write(line)
+  continue
+
+if line.startswith(''):
+  f.write(line)
+  continue
+
+if header_found and add_note_here:
   if not line.startswith(''):
-f.write("""
-- New :doc:`%s
+f.write("""- New :doc:`%s
   ` check.
 
   FIXME: add release notes.
+
 """ % (check_name_dashes, check_name_dashes))
 note_added = True
 


Index: clang-tools-extra/trunk/clang-tidy/add_new_check.py
===
--- clang-tools-extra/trunk/clang-tidy/add_new_check.py
+++ clang-tools-extra/trunk/clang-tidy/add_new_check.py
@@ -200,23 +200,47 @@
   with open(filename, 'r') as f:
 lines = f.readlines()
 
+  lineMatcher = re.compile('Improvements to clang-tidy')
+  nextSectionMatcher = re.compile('Improvements to include-fixer')
+  checkerMatcher = re.compile('- New :doc:`(.*)')
+
   print('Updating %s...' % filename)
   with open(filename, 'w') as f:
 note_added = False
 header_found = False
+next_header_found = False
+add_note_here = False
 
 for line in lines:
   if not note_added:
-match = re.search('Improvements to clang-tidy', line)
+match = lineMatcher.match(line)
+match_next = nextSectionMatcher.match(line)
+match_checker = checkerMatcher.match(line)
+if match_checker:
+  last_checker = match_checker.group(1)
+  if last_checker > check_name_dashes:
+add_note_here = True
+
+if match_next:
+  next_header_found = True
+  add_note_here = True
+
 if match:
   header_found = True
-elif header_found:
+  f.write(line)
+  continue
+
+if line.startswith(''):
+  f.write(line)
+  continue
+
+if header_found and add_note_here:
   if not line.startswith(''):
-f.write("""
-- New :doc:`%s
+f.write("""- New :doc:`%s
   ` check.
 
   FIXME: add release notes.
+
 """ % (check_name_dashes, check_name_dashes))
 note_added = True
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55508: [clang-tidy] insert release notes for new checkers alphabetically

2018-12-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In D55508#1325834 , @MyDeveloperDay 
wrote:

> In D55508#1325758 , @JonasToth wrote:
>
> > LGTM. Do you have commit access?
>
>
> I do not I'm afraid


I will commit for you.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55508/new/

https://reviews.llvm.org/D55508



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


[PATCH] D53738: [Fixed Point Arithmetic] Fixed Point Addition

2018-12-10 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In D53738#1320936 , @rjmccall wrote:

> Okay, thanks, that makes sense to me.
>
> I'll ask around to find a way to contact the C committee.


@rjmccall Any updates on this? If we aren't able to find a way to contact 
anyone affiliated with publishing the spec, we could at least double check 
against avr-gcc for consistency regarding semantics.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D53738/new/

https://reviews.llvm.org/D53738



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


[PATCH] D55500: [Builtins] Implement __builtin_is_constant_evaluated for use in C++2a

2018-12-10 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Hi Eric,

Thanks for working on this!




Comment at: include/clang/Basic/Builtins.def:759
+// Random C++ builtins.
+LANGBUILTIN(__builtin_is_constant_evaluated, "b", "ncu", CXX_LANG)
+

Name bikeshedding : perhaps the builtin name could be detached from the std:: 
name? Suggestion: `__builtin_in_constant_evaluation_context`



Comment at: lib/AST/ExprConstant.cpp:8207
 
+  case Builtin::BI__builtin_is_constant_evaluated:
+return Success(Info.InConstantContext, E);

Do we need compat and extension warnings for the use of this builtin before 
c++2a? I assume people will play with the builtin before the library facility 
is there. OTOH, since this will be mainly exposed as a library thing, whatever 
check for c++ version is done at the library level should be enough?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55500/new/

https://reviews.llvm.org/D55500



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


r348790 - Add an explicit triple to this test to fix failing test bots.

2018-12-10 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Mon Dec 10 11:18:11 2018
New Revision: 348790

URL: http://llvm.org/viewvc/llvm-project?rev=348790=rev
Log:
Add an explicit triple to this test to fix failing test bots.

Modified:
cfe/trunk/test/AST/ast-dump-expr.c

Modified: cfe/trunk/test/AST/ast-dump-expr.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-expr.c?rev=348790=348789=348790=diff
==
--- cfe/trunk/test/AST/ast-dump-expr.c (original)
+++ cfe/trunk/test/AST/ast-dump-expr.c Mon Dec 10 11:18:11 2018
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -Wno-unused-value -std=gnu11 -ast-dump %s | FileCheck 
-strict-whitespace %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu11 
-ast-dump %s | FileCheck -strict-whitespace %s
 
 void Comma(void) {
   1, 2, 3;
@@ -213,15 +213,15 @@ void UnaryOperators(int a, int *b) {
   // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
 
   sizeof a;
-  // CHECK: UnaryExprOrTypeTraitExpr 0x{{[^ ]*}}  
'unsigned long long' sizeof
+  // CHECK: UnaryExprOrTypeTraitExpr 0x{{[^ ]*}}  
'unsigned long' sizeof
   // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
 
   sizeof(int);
-  // CHECK: UnaryExprOrTypeTraitExpr 0x{{[^ ]*}}  
'unsigned long long' sizeof 'int'
+  // CHECK: UnaryExprOrTypeTraitExpr 0x{{[^ ]*}}  
'unsigned long' sizeof 'int'
 
   _Alignof(int);
   // FIXME: Uses C++ spelling for alignof in C mode.
-  // CHECK: UnaryExprOrTypeTraitExpr 0x{{[^ ]*}}  
'unsigned long long' alignof 'int'
+  // CHECK: UnaryExprOrTypeTraitExpr 0x{{[^ ]*}}  
'unsigned long' alignof 'int'
 }
 
 struct S {
@@ -287,7 +287,7 @@ void PrimaryExpressions(int a) {
   // CHECK: CharacterLiteral 0x{{[^ ]*}}  'int' 97
 
   L'a';
-  // CHECK: CharacterLiteral 0x{{[^ ]*}}  'unsigned short' 
97
+  // CHECK: CharacterLiteral 0x{{[^ ]*}}  'int' 97
 
   "a";
   // ImplicitCastExpr
@@ -295,7 +295,7 @@ void PrimaryExpressions(int a) {
 
   L"a";
   // ImplicitCastExpr
-  // CHECK: StringLiteral 0x{{[^ ]*}}  'unsigned short [2]' lvalue L"a"
+  // CHECK: StringLiteral 0x{{[^ ]*}}  'int [2]' lvalue L"a"
 
   u8"a";
   // ImplicitCastExpr


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


[PATCH] D48342: [libcxx] Optimize vectors construction of trivial types from an iterator range with const-ness mismatch.

2018-12-10 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added inline comments.



Comment at: libcxx/include/memory:1645
 
-template 
+template 
 _LIBCPP_INLINE_VISIBILITY

Quuxplusone wrote:
> ldionne wrote:
> > Coming at it from a slightly different angle, I would think this is what we 
> > want:
> > 
> > ```
> > template  >   class _RawSourceTp = typename remove_const<_SourceTp>::type,
> >   class _RawDestTp = typename remove_const<_DestTp>::type>
> > _LIBCPP_INLINE_VISIBILITY static typename enable_if<
> >
> > // We can use memcpy instead of a loop with construct if...
> > is_trivially_move_constructible<_DestTp>::value && 
> > // - the Dest is trivially move constructible, and
> > is_same<_RawSourceTp, _RawDestTp>::value &&
> > // - both types are the same modulo constness, and either
> > (__is_default_allocator::value ||  
> > //   + the allocator is the default allocator (and we know `construct` is 
> > just placement-new), or
> >  !__has_construct::value), 
> > //   + the allocator does not provide a custom `construct` method (so we'd 
> > fall back to placement-new)
> > void>::type
> > __construct_range_forward(allocator_type&, _SourceTp* __begin1, _SourceTp* 
> > __end1, _DestTp*& __begin2)
> > {
> > ptrdiff_t _Np = __end1 - __begin1;
> > if (_Np > 0)
> > {
> > _VSTD::memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * 
> > sizeof(_DestTp));
> > __begin2 += _Np;
> > }
> > }
> > ```
> > 
> > And then we should have
> > 
> > ```
> > template 
> > struct __is_default_allocator : false_type { };
> > 
> > template 
> > struct __is_default_allocator<_VSTD::allocator<_Tp> > : true_type { };
> > ```
> > 
> > Does this make sense?
> > 
> > Also, I'm not sure I understand why we use `const_cast` on the destination 
> > type. It seems like we should instead enforce that it is non-const? But 
> > this is a pre-existing thing in the code, this doesn't affect this review.
> > 
> I agree that it is wrong to express the check in terms of 
> `is_same>`; it should be expressed in terms of 
> a trait which is satisfied by `std::allocator`-for-any-T. @ldionne 
> expressed it in terms of `__is_default_allocator`. I continue to ask that 
> it be expressed in terms of `__has_trivial_construct _SourceTp&>`, where libc++ specializes 
> `__has_trivial_construct, ...>` if need be.
> 
> Orthogonally, the condition `__has_construct _SourceTp const&>` is wrong because it has an extra `const`. It is 
> conceivable — though of course implausible/pathological — for `construct(T*, 
> T&)` to exist and do something different from `construct(T*, const T&)`.
> I continue to ask that it be expressed in terms of 
> `__has_trivial_construct`, where libc++ specializes 
> `__has_trivial_construct, ...>` if need be.

Would you be OK with us applying this fix and then generalizing 
`__is_default_allocator` into `__has_trivial_construct` as a followup? I 
suspect we'll have more discussion around that generalization and I'd like for 
us to fix this bug because I find PR37574 somewhat concerning and I'd like for 
it to be fixed soon (like within a couple of days).

> Orthogonally, the condition `__has_construct _SourceTp const&>` is wrong because it has an extra const. It is conceivable 
> — though of course implausible/pathological — for `construct(T*, T&)` to 
> exist and do something different from `construct(T*, const T&)`.


Good catch. IIUC, `__has_construct` would 
work?



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D48342/new/

https://reviews.llvm.org/D48342



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


[PATCH] D55097: [constexpr][c++2a] Try-catch blocks in constexpr functions

2018-12-10 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL348789: [constexpr][c++2a] Try-catch blocks in constexpr 
functions (authored by bruno, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55097?vs=177367=177564#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55097/new/

https://reviews.llvm.org/D55097

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/AST/ExprConstant.cpp
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
  cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
  cfe/trunk/test/CXX/drs/dr6xx.cpp
  cfe/trunk/www/cxx_status.html

Index: cfe/trunk/www/cxx_status.html
===
--- cfe/trunk/www/cxx_status.html
+++ cfe/trunk/www/cxx_status.html
@@ -953,13 +953,15 @@
 
   Relaxations of constexpr restrictions
   http://wg21.link/p1064r0;>P1064R0
-  No
+  No
 

 http://wg21.link/p1002r1;>P1002R1
+SVN
   
   
 http://wg21.link/p1327r1;>P1327R1
+No
   
   
 http://wg21.link/p1330r0;>P1330R0
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2357,6 +2357,13 @@
   "use of this statement in a constexpr %select{function|constructor}0 "
   "is incompatible with C++ standards before C++14">,
   InGroup, DefaultIgnore;
+def ext_constexpr_body_invalid_stmt_cxx2a : ExtWarn<
+  "use of this statement in a constexpr %select{function|constructor}0 "
+  "is a C++2a extension">, InGroup;
+def warn_cxx17_compat_constexpr_body_invalid_stmt : Warning<
+  "use of this statement in a constexpr %select{function|constructor}0 "
+  "is incompatible with C++ standards before C++2a">,
+  InGroup, DefaultIgnore;
 def ext_constexpr_type_definition : ExtWarn<
   "type definition in a constexpr %select{function|constructor}0 "
   "is a C++14 extension">, InGroup;
@@ -2409,6 +2416,16 @@
   "previous return statement is here">;
 def err_constexpr_function_try_block : Error<
   "function try block not allowed in constexpr %select{function|constructor}0">;
+
+// c++2a function try blocks in constexpr
+def ext_constexpr_function_try_block_cxx2a : ExtWarn<
+  "function try block in constexpr %select{function|constructor}0 is "
+  "a C++2a extension">, InGroup;
+def warn_cxx17_compat_constexpr_function_try_block : Warning<
+  "function try block in constexpr %select{function|constructor}0 is "
+  "incompatible with C++ standards before C++2a">,
+  InGroup, DefaultIgnore;
+
 def err_constexpr_union_ctor_no_init : Error<
   "constexpr union constructor does not initialize any member">;
 def err_constexpr_ctor_missing_init : Error<
Index: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
===
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -verify -std=c++11 -fcxx-exceptions -Werror=c++1y-extensions %s
-// RUN: %clang_cc1 -verify -std=c++1y -fcxx-exceptions -DCXX1Y %s
+// RUN: %clang_cc1 -verify -std=c++11 -fcxx-exceptions -Werror=c++1y-extensions -Werror=c++2a-extensions %s
+// RUN: %clang_cc1 -verify -std=c++1y -fcxx-exceptions -DCXX1Y -Werror=c++2a-extensions %s
+// RUN: %clang_cc1 -verify -std=c++2a -fcxx-exceptions -DCXX1Y -DCXX2A %s
 
 namespace N {
   typedef char C;
@@ -49,8 +50,14 @@
 // - its function-body shall not be a function-try-block;
 struct U {
   constexpr U()
-try // expected-error {{function try block not allowed in constexpr constructor}}
+try
+#ifndef CXX2A
+  // expected-error@-2 {{function try block in constexpr constructor is a C++2a extension}}
+#endif
 : u() {
+#ifndef CXX1Y
+  // expected-error@-2 {{use of this statement in a constexpr constructor is a C++14 extension}}
+#endif
   } catch (...) {
 throw;
   }
Index: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
===
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++11 -Werror=c++1y-extensions %s
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++1y -DCXX1Y %s
+// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++11 -Werror=c++1y-extensions -Werror=c++2a-extensions %s
+// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu -std=c++1y -DCXX1Y -Werror=c++2a-extensions %s
+// RUN: %clang_cc1 -verify -fcxx-exceptions 

r348789 - [constexpr][c++2a] Try-catch blocks in constexpr functions

2018-12-10 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Mon Dec 10 11:03:12 2018
New Revision: 348789

URL: http://llvm.org/viewvc/llvm-project?rev=348789=rev
Log:
[constexpr][c++2a] Try-catch blocks in constexpr functions

Implement support for try-catch blocks in constexpr functions, as
proposed in http://wg21.link/P1002 and voted in San Diego for c++20.

The idea is that we can still never throw inside constexpr, so the catch
block is never entered. A try-catch block like this:

try { f(); } catch (...) { }

is then morally equivalent to just

{ f(); }

Same idea should apply for function/constructor try blocks.

rdar://problem/45530773

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
cfe/trunk/test/CXX/drs/dr6xx.cpp
cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=348789=348788=348789=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Dec 10 11:03:12 
2018
@@ -2357,6 +2357,13 @@ def warn_cxx11_compat_constexpr_body_inv
   "use of this statement in a constexpr %select{function|constructor}0 "
   "is incompatible with C++ standards before C++14">,
   InGroup, DefaultIgnore;
+def ext_constexpr_body_invalid_stmt_cxx2a : ExtWarn<
+  "use of this statement in a constexpr %select{function|constructor}0 "
+  "is a C++2a extension">, InGroup;
+def warn_cxx17_compat_constexpr_body_invalid_stmt : Warning<
+  "use of this statement in a constexpr %select{function|constructor}0 "
+  "is incompatible with C++ standards before C++2a">,
+  InGroup, DefaultIgnore;
 def ext_constexpr_type_definition : ExtWarn<
   "type definition in a constexpr %select{function|constructor}0 "
   "is a C++14 extension">, InGroup;
@@ -2409,6 +2416,16 @@ def note_constexpr_body_previous_return
   "previous return statement is here">;
 def err_constexpr_function_try_block : Error<
   "function try block not allowed in constexpr 
%select{function|constructor}0">;
+
+// c++2a function try blocks in constexpr
+def ext_constexpr_function_try_block_cxx2a : ExtWarn<
+  "function try block in constexpr %select{function|constructor}0 is "
+  "a C++2a extension">, InGroup;
+def warn_cxx17_compat_constexpr_function_try_block : Warning<
+  "function try block in constexpr %select{function|constructor}0 is "
+  "incompatible with C++ standards before C++2a">,
+  InGroup, DefaultIgnore;
+
 def err_constexpr_union_ctor_no_init : Error<
   "constexpr union constructor does not initialize any member">;
 def err_constexpr_ctor_missing_init : Error<

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=348789=348788=348789=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Dec 10 11:03:12 2018
@@ -4279,6 +4279,9 @@ static EvalStmtResult EvaluateStmt(StmtR
   case Stmt::CaseStmtClass:
   case Stmt::DefaultStmtClass:
 return EvaluateStmt(Result, Info, cast(S)->getSubStmt(), Case);
+  case Stmt::CXXTryStmtClass:
+// Evaluate try blocks by evaluating all sub statements.
+return EvaluateStmt(Result, Info, cast(S)->getTryBlock(), 
Case);
   }
 }
 

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=348789=348788=348789=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Dec 10 11:03:12 2018
@@ -1803,7 +1803,7 @@ static void CheckConstexprCtorInitialize
 static bool
 CheckConstexprFunctionStmt(Sema , const FunctionDecl *Dcl, Stmt *S,
SmallVectorImpl ,
-   SourceLocation ) {
+   SourceLocation , SourceLocation ) 
{
   // - its function-body shall be [...] a compound-statement that contains only
   switch (S->getStmtClass()) {
   case Stmt::NullStmtClass:
@@ -1840,7 +1840,7 @@ CheckConstexprFunctionStmt(Sema 
 CompoundStmt *CompStmt = cast(S);
 for (auto *BodyIt : CompStmt->body()) {
   if (!CheckConstexprFunctionStmt(SemaRef, Dcl, BodyIt, ReturnStmts,
-  Cxx1yLoc))
+  Cxx1yLoc, Cxx2aLoc))
 return false;
 }
 return true;
@@ -1858,11 +1858,11 @@ CheckConstexprFunctionStmt(Sema 
 
 IfStmt *If = cast(S);
 if 

[PATCH] D55525: [Driver] Add support for -fembed-bitcode for assembly file

2018-12-10 Thread Steven Wu via Phabricator via cfe-commits
steven_wu created this revision.
steven_wu added reviewers: compnerd, dexonsmith.
Herald added a subscriber: jkorous.

Handle -fembed-bitcode for assembly inputs. When the input file is
assembly, write a marker as "__LLVM,__asm" section.

Fix llvm.org/pr39659


Repository:
  rC Clang

https://reviews.llvm.org/D55525

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/embed-bitcode.s
  tools/driver/cc1as_main.cpp

Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -33,6 +33,7 @@
 #include "llvm/MC/MCParser/MCAsmParser.h"
 #include "llvm/MC/MCParser/MCTargetAsmParser.h"
 #include "llvm/MC/MCRegisterInfo.h"
+#include "llvm/MC/MCSectionMachO.h"
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/MCTargetOptions.h"
@@ -132,6 +133,7 @@
   unsigned NoExecStack : 1;
   unsigned FatalWarnings : 1;
   unsigned IncrementalLinkerCompatible : 1;
+  unsigned EmbedBitcode : 1;
 
   /// The name of the relocation model to use.
   std::string RelocationModel;
@@ -153,6 +155,7 @@
 FatalWarnings = 0;
 IncrementalLinkerCompatible = 0;
 DwarfVersion = 0;
+EmbedBitcode = 0;
   }
 
   static bool CreateFromArgs(AssemblerInvocation ,
@@ -284,6 +287,16 @@
   Args.hasArg(OPT_mincremental_linker_compatible);
   Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym);
 
+  // EmbedBitcode Option. If -fembed-bitcode is enabled, set the flag.
+  // EmbedBitcode behaves the same for all embed options for assembly files.
+  if (auto *A = Args.getLastArg(OPT_fembed_bitcode_EQ)) {
+Opts.EmbedBitcode = llvm::StringSwitch(A->getValue())
+.Case("all", 1)
+.Case("bitcode", 1)
+.Case("marker", 1)
+.Default(0);
+  }
+
   return Success;
 }
 
@@ -449,6 +462,16 @@
 Str.get()->InitSections(Opts.NoExecStack);
   }
 
+  // When -fembed-bitcode is passed to clang_as, a 1-byte marker
+  // is emitted in __LLVM,__asm section if the object file is MachO format.
+  if (Opts.EmbedBitcode && Ctx.getObjectFileInfo()->getObjectFileType() ==
+   MCObjectFileInfo::IsMachO) {
+MCSection *AsmLabel = Ctx.getMachOSection(
+"__LLVM", "__asm", MachO::S_REGULAR, 4, SectionKind::getReadOnly());
+Str.get()->SwitchSection(AsmLabel);
+Str.get()->EmitZeros(1);
+  }
+
   // Assembly to object compilation should leverage assembly info.
   Str->setUseAssemblerInfoForParsing(true);
 
Index: test/Driver/embed-bitcode.s
===
--- /dev/null
+++ test/Driver/embed-bitcode.s
@@ -0,0 +1,12 @@
+// REQUIRES: arm-registered-target
+
+// RUN: %clang -c -target armv7-apple-ios10 %s -fembed-bitcode -### 2>&1 | FileCheck %s -check-prefix=CHECK-AS
+// RUN: %clang -c -target armv7-apple-ios10 %s -fembed-bitcode-marker -### 2>&1 | FileCheck %s -check-prefix=CHECK-AS-MARKER
+// CHECK-AS: -cc1as
+// CHECK-AS: -fembed-bitcode=all
+// CHECK-AS-MARKER: -fembed-bitcode=marker
+
+// RUN: %clang -c -target armv7-apple-ios10 %s -fembed-bitcode -o %t.o
+// RUN: llvm-readobj -section-headers %t.o | FileCheck --check-prefix=CHECK-SECTION %s
+// CHECK-SECTION: Name: __asm
+// CHECK-SECTION-NEXT: Segment: __LLVM
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -2167,6 +2167,11 @@
 CmdArgs.push_back("-target-feature");
 CmdArgs.push_back(MipsTargetFeature);
   }
+
+  // forward -fembed-bitcode to assmebler
+  if (C.getDriver().embedBitcodeEnabled() ||
+  C.getDriver().embedBitcodeMarkerOnly())
+Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ);
 }
 
 static void RenderFloatingPointOptions(const ToolChain , const Driver ,
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -675,7 +675,7 @@
   Flags<[DriverOption]>;
 
 def fembed_bitcode_EQ : Joined<["-"], "fembed-bitcode=">,
-Group, Flags<[DriverOption, CC1Option]>, MetaVarName<"">,
+Group, Flags<[DriverOption, CC1Option, CC1AsOption]>, MetaVarName<"">,
 HelpText<"Embed LLVM bitcode (option: off, all, bitcode, marker)">;
 def fembed_bitcode : Flag<["-"], "fembed-bitcode">, Group,
   Alias, AliasArgs<["all"]>,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21230: Do not embed all the cc1 options in bitcode commandline

2018-12-10 Thread Steven Wu via Phabricator via cfe-commits
steven_wu abandoned this revision.
steven_wu added a comment.
Herald added subscribers: jkorous, mehdi_amini.

This is upstreamed by Saleem already


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D21230/new/

https://reviews.llvm.org/D21230



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


[PATCH] D55508: [clang-tidy] insert release notes for new checkers alphabetically

2018-12-10 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D55508#1325758 , @JonasToth wrote:

> LGTM. Do you have commit access?


I do not I'm afraid


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55508/new/

https://reviews.llvm.org/D55508



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


Re: r348685 - Move diagnostic enums into Basic.

2018-12-10 Thread David Blaikie via cfe-commits
Hey Richard,

Thanks for cleaning up some of the layering here!

I /think/ I vaguely recall having a conversation with Richard Smith about a
different direction to fix the layering of the diagnostics system - but it
was/is more involved. Ah, here, apparently I sent out a WIP patch & must've
got engaged in other things: https://reviews.llvm.org/D41357 - not sure if
this is a better/workable/useful way forward, or whether we should go with
sinking the specific diagnostics into the Diagnostics library as you've
done/started doing here (I don't have much context in my head right now, so
I forget exactly what's involved in fully pushing them all down into
Diagnostics).

Just some thoughts/directions/ideas,
- Dave

On Fri, Dec 7, 2018 at 9:07 PM Richard Trieu via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rtrieu
> Date: Fri Dec  7 21:05:03 2018
> New Revision: 348685
>
> URL: http://llvm.org/viewvc/llvm-project?rev=348685=rev
> Log:
> Move diagnostic enums into Basic.
>
> Move enums from */*Diagnostic.h to Basic/Diagnostic*.h.
> Basic/AllDiagnostics.h
> needs all the enums and moving the sources to Basic prevents a
> Basic->*->Basic
> dependency loop.  This also allows each Basic/Diagnostics*Kinds.td to have
> a
> header at Basic/Diagnostic*.h (except for Common).  The old headers are
> kept in place since other packages are still using them.
>
> Added:
> cfe/trunk/include/clang/Basic/DiagnosticAST.h
>   - copied, changed from r348541,
> cfe/trunk/include/clang/AST/ASTDiagnostic.h
> cfe/trunk/include/clang/Basic/DiagnosticAnalysis.h
>   - copied, changed from r348541,
> cfe/trunk/include/clang/Analysis/AnalysisDiagnostic.h
> cfe/trunk/include/clang/Basic/DiagnosticComment.h
>   - copied, changed from r348541,
> cfe/trunk/include/clang/AST/CommentDiagnostic.h
> cfe/trunk/include/clang/Basic/DiagnosticCrossTU.h
>   - copied, changed from r348541,
> cfe/trunk/include/clang/CrossTU/CrossTUDiagnostic.h
> cfe/trunk/include/clang/Basic/DiagnosticDriver.h
>   - copied, changed from r348541,
> cfe/trunk/include/clang/Driver/DriverDiagnostic.h
> cfe/trunk/include/clang/Basic/DiagnosticFrontend.h
>   - copied, changed from r348541,
> cfe/trunk/include/clang/Frontend/FrontendDiagnostic.h
> cfe/trunk/include/clang/Basic/DiagnosticLex.h
>   - copied, changed from r348541,
> cfe/trunk/include/clang/Lex/LexDiagnostic.h
> cfe/trunk/include/clang/Basic/DiagnosticParse.h
>   - copied, changed from r348541,
> cfe/trunk/include/clang/Parse/ParseDiagnostic.h
> cfe/trunk/include/clang/Basic/DiagnosticRefactoring.h
>   - copied, changed from r348541,
> cfe/trunk/include/clang/Tooling/Refactoring/RefactoringDiagnostic.h
> cfe/trunk/include/clang/Basic/DiagnosticSema.h
>   - copied, changed from r348541,
> cfe/trunk/include/clang/Sema/SemaDiagnostic.h
> cfe/trunk/include/clang/Basic/DiagnosticSerialization.h
>   - copied, changed from r348541,
> cfe/trunk/include/clang/Serialization/SerializationDiagnostic.h
> Modified:
> cfe/trunk/include/clang/AST/ASTDiagnostic.h
> cfe/trunk/include/clang/AST/CommentDiagnostic.h
> cfe/trunk/include/clang/Analysis/AnalysisDiagnostic.h
> cfe/trunk/include/clang/Basic/AllDiagnostics.h
> cfe/trunk/include/clang/CrossTU/CrossTUDiagnostic.h
> cfe/trunk/include/clang/Driver/DriverDiagnostic.h
> cfe/trunk/include/clang/Frontend/FrontendDiagnostic.h
> cfe/trunk/include/clang/Lex/LexDiagnostic.h
> cfe/trunk/include/clang/Parse/ParseDiagnostic.h
> cfe/trunk/include/clang/Sema/SemaDiagnostic.h
> cfe/trunk/include/clang/Serialization/SerializationDiagnostic.h
> cfe/trunk/include/clang/Tooling/Refactoring/RefactoringDiagnostic.h
>
> Modified: cfe/trunk/include/clang/AST/ASTDiagnostic.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTDiagnostic.h?rev=348685=348684=348685=diff
>
> ==
> --- cfe/trunk/include/clang/AST/ASTDiagnostic.h (original)
> +++ cfe/trunk/include/clang/AST/ASTDiagnostic.h Fri Dec  7 21:05:03 2018
> @@ -11,19 +11,9 @@
>  #define LLVM_CLANG_AST_ASTDIAGNOSTIC_H
>
>  #include "clang/Basic/Diagnostic.h"
> +#include "clang/Basic/DiagnosticAST.h"
>
>  namespace clang {
> -  namespace diag {
> -enum {
> -#define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,\
> - SFINAE,NOWERROR,SHOWINSYSHEADER,CATEGORY) ENUM,
> -#define ASTSTART
> -#include "clang/Basic/DiagnosticASTKinds.inc"
> -#undef DIAG
> -  NUM_BUILTIN_AST_DIAGNOSTICS
> -};
> -  }  // end namespace diag
> -
>/// DiagnosticsEngine argument formatting function for diagnostics that
>/// involve AST nodes.
>///
>
> Modified: cfe/trunk/include/clang/AST/CommentDiagnostic.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentDiagnostic.h?rev=348685=348684=348685=diff
>
> 

[PATCH] D55447: [Sema] Fix Modified Type in address_space AttributedType

2018-12-10 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 177561.
leonardchan marked an inline comment as done.

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55447/new/

https://reviews.llvm.org/D55447

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/Sema/address_space_attribute.cpp
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -128,7 +128,8 @@
   if (TU && !T.isNull()) {
 // Handle attributed types as the original type
 if (auto *ATT = T->getAs()) {
-  if (!(TU->ParsingOptions & CXTranslationUnit_IncludeAttributedTypes)) {
+  if (!(TU->ParsingOptions & CXTranslationUnit_IncludeAttributedTypes) &&
+  ATT->getAttrKind() != attr::AddressSpace) {
 return MakeCXType(ATT->getModifiedType(), TU);
   }
 }
Index: clang/test/Sema/address_space_attribute.cpp
===
--- /dev/null
+++ clang/test/Sema/address_space_attribute.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -ast-dump | FileCheck %s
+
+// Veryify the ordering of the address_space attribute still comes before the
+// type whereas other attributes are still printed after.
+
+template 
+void func() {
+  // CHECK: VarDecl {{.*}} x '__attribute__((address_space(1))) int *'
+  __attribute__((address_space(1))) int *x;
+
+  // CHECK: VarDecl {{.*}} a 'int * __attribute__((noderef))'
+  int __attribute__((noderef)) * a;
+
+  __attribute__((address_space(I))) int *y;
+  // CHECK: VarDecl {{.*}} y '__attribute__((address_space(2))) int *'
+}
+
+void func2() {
+  func<2>();
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5740,28 +5740,27 @@
 // Type Attribute Processing
 //===--===//
 
-/// BuildAddressSpaceAttr - Builds a DependentAddressSpaceType if an expression
-/// is uninstantiated. If instantiated it will apply the appropriate address space
-/// to the type. This function allows dependent template variables to be used in
-/// conjunction with the address_space attribute
-QualType Sema::BuildAddressSpaceAttr(QualType , Expr *AddrSpace,
- SourceLocation AttrLoc) {
+/// Build an AddressSpace index from a constant expression and diagnose any
+/// errors related to invalid address_spaces. Returns true on successfully
+/// building an AddressSpace index.
+static bool BuildAddressSpaceIndex(Sema , LangAS ,
+   const Expr *AddrSpace,
+   SourceLocation AttrLoc) {
   if (!AddrSpace->isValueDependent()) {
-
 llvm::APSInt addrSpace(32);
-if (!AddrSpace->isIntegerConstantExpr(addrSpace, Context)) {
-  Diag(AttrLoc, diag::err_attribute_argument_type)
+if (!AddrSpace->isIntegerConstantExpr(addrSpace, S.Context)) {
+  S.Diag(AttrLoc, diag::err_attribute_argument_type)
   << "'address_space'" << AANT_ArgumentIntegerConstant
   << AddrSpace->getSourceRange();
-  return QualType();
+  return false;
 }
 
 // Bounds checking.
 if (addrSpace.isSigned()) {
   if (addrSpace.isNegative()) {
-Diag(AttrLoc, diag::err_attribute_address_space_negative)
+S.Diag(AttrLoc, diag::err_attribute_address_space_negative)
 << AddrSpace->getSourceRange();
-return QualType();
+return false;
   }
   addrSpace.setIsSigned(false);
 }
@@ -5770,14 +5769,28 @@
 max =
 Qualifiers::MaxAddressSpace - (unsigned)LangAS::FirstTargetAddressSpace;
 if (addrSpace > max) {
-  Diag(AttrLoc, diag::err_attribute_address_space_too_high)
+  S.Diag(AttrLoc, diag::err_attribute_address_space_too_high)
   << (unsigned)max.getZExtValue() << AddrSpace->getSourceRange();
-  return QualType();
+  return false;
 }
 
-LangAS ASIdx =
+ASIdx =
 getLangASFromTargetAS(static_cast(addrSpace.getZExtValue()));
+return true;
+  }
 
+  // Default value for DependentAddressSpaceTypes
+  ASIdx = LangAS::Default;
+  return true;
+}
+
+/// BuildAddressSpaceAttr - Builds a DependentAddressSpaceType if an expression
+/// is uninstantiated. If instantiated it will apply the appropriate address
+/// space to the type. This function allows dependent template variables to be
+/// used in conjunction with the address_space attribute
+QualType Sema::BuildAddressSpaceAttr(QualType , LangAS ASIdx, Expr *AddrSpace,
+ SourceLocation AttrLoc) {
+  if (!AddrSpace->isValueDependent()) {
 // If this type is already address space qualified with a different
 // address space, reject it.
 // ISO/IEC 

r348786 - Adding tests for -ast-dump; NFC.

2018-12-10 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Mon Dec 10 10:37:47 2018
New Revision: 348786

URL: http://llvm.org/viewvc/llvm-project?rev=348786=rev
Log:
Adding tests for -ast-dump; NFC.

This adds tests for expressions in C.

Added:
cfe/trunk/test/AST/ast-dump-expr.c

Added: cfe/trunk/test/AST/ast-dump-expr.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-expr.c?rev=348786=auto
==
--- cfe/trunk/test/AST/ast-dump-expr.c (added)
+++ cfe/trunk/test/AST/ast-dump-expr.c Mon Dec 10 10:37:47 2018
@@ -0,0 +1,339 @@
+// RUN: %clang_cc1 -Wno-unused-value -std=gnu11 -ast-dump %s | FileCheck 
-strict-whitespace %s
+
+void Comma(void) {
+  1, 2, 3;
+  // CHECK: BinaryOperator 0x{{[^ ]*}}  'int' ','
+  // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}}  'int' ','
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 1
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 2
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 3
+}
+
+void Assignment(int a) {
+  a = 12;
+  // CHECK: BinaryOperator 0x{{[^ ]*}}  'int' '='
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 12
+
+  a += a;
+  // CHECK: CompoundAssignOperator 0x{{[^ ]*}}  
'int' '+=' ComputeLHSTy='int' ComputeResultTy='int'
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+}
+
+void Conditionals(int a) {
+  a ? 0 : 1;
+  // CHECK: ConditionalOperator 0x{{[^ ]*}}  'int'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 0
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+  a ?: 0;
+  // CHECK: BinaryConditionalOperator 0x{{[^ ]*}}  
'int'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: OpaqueValueExpr 0x{{[^ ]*}}  'int'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: OpaqueValueExpr 0x{{[^ ]*}}  'int'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}}  'int' 0
+}
+
+void BinaryOperators(int a, int b) {
+  // Logical operators
+  a || b;
+  // CHECK: BinaryOperator 0x{{[^ ]*}}  'int' '||'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'b' 'int'
+
+  a && b;
+  // CHECK: BinaryOperator 0x{{[^ ]*}}  'int' '&&'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'b' 'int'
+
+  // Bitwise operators
+  a | b;
+  // CHECK: BinaryOperator 0x{{[^ ]*}}  'int' '|'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'b' 'int'
+
+  a ^ b;
+  // CHECK: BinaryOperator 0x{{[^ ]*}}  'int' '^'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'b' 'int'
+
+  a & b;
+  // CHECK: BinaryOperator 0x{{[^ ]*}}  'int' '&'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'b' 'int'
+
+  // Equality operators
+  a == b;
+  // CHECK: BinaryOperator 0x{{[^ ]*}}  'int' '=='
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'b' 'int'
+
+  a != b;
+  // CHECK: BinaryOperator 0x{{[^ ]*}}  'int' '!='
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'b' 'int'
+
+  // Relational operators
+  a < b;
+  // CHECK: BinaryOperator 0x{{[^ ]*}}  'int' '<'
+  // CHECK-NEXT: ImplicitCastExpr
+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'int' lvalue ParmVar 0x{{[^ 
]*}} 'a' 'int'
+  // CHECK-NEXT: 

  1   2   >