[PATCH] D44609: [Clang-Format] New option BeforeLambdaBody to manage lambda line break inside function parameter call (in Allman style)

2019-08-23 Thread Christian Venegas via Phabricator via cfe-commits
cvenegas added a comment.

I'm testing this patch on our codebase and it is working pretty well. We use 
the Allman style and the lambda problem has been an issue for many years. One 
thing to note in this patch is that some of the files have CRLF line endings 
but should be LF endings, which is why they're showing so many edits. I'm also 
seeing a clang tidy test failing with this patch. The 
readability-braces-around-statements tests seem to fail because the indent 
width is appending double of what it should.
void test() {

 if (cond("if0") /*comment*/) {
do_something("same-line");
  }

Hope this helps as this patch is the only reason why we still need to build 
clang-format instead of using the prebuilt binaries. Thanks!


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

https://reviews.llvm.org/D44609



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


[PATCH] D66621: [clang] Devirtualization for classes with destructors marked as 'final'

2019-08-23 Thread Logan Smith via Phabricator via cfe-commits
logan-5 updated this revision to Diff 217009.
logan-5 added a comment.

Add a missing null check.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66621

Files:
  clang/lib/AST/DeclCXX.cpp
  clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp


Index: clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
===
--- clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
+++ clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
@@ -24,6 +24,20 @@
   }
 }
 
+namespace Test2a {
+  struct A {
+virtual ~A() final {}
+virtual int f();
+  };
+
+  // CHECK-LABEL: define i32 @_ZN6Test2a1fEPNS_1AE
+  int f(A *a) {
+// CHECK: call i32 @_ZN6Test2a1A1fEv
+return a->f();
+  }
+}
+
+
 namespace Test3 {
   struct A {
 virtual int f();
Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -2067,10 +2067,15 @@
   if (DevirtualizedMethod->hasAttr())
 return DevirtualizedMethod;
 
-  // Similarly, if the class itself is marked 'final' it can't be overridden
-  // and we can therefore devirtualize the member function call.
+  // Similarly, if the class itself or its destructor is marked 'final',
+  // the class can't be derived from and we can therefore devirtualize the 
+  // member function call.
   if (BestDynamicDecl->hasAttr())
 return DevirtualizedMethod;
+  if (const auto *dtor = BestDynamicDecl->getDestructor()) {
+if (dtor->hasAttr())
+  return DevirtualizedMethod;
+  }
 
   if (const auto *DRE = dyn_cast(Base)) {
 if (const auto *VD = dyn_cast(DRE->getDecl()))


Index: clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
===
--- clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
+++ clang/test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
@@ -24,6 +24,20 @@
   }
 }
 
+namespace Test2a {
+  struct A {
+virtual ~A() final {}
+virtual int f();
+  };
+
+  // CHECK-LABEL: define i32 @_ZN6Test2a1fEPNS_1AE
+  int f(A *a) {
+// CHECK: call i32 @_ZN6Test2a1A1fEv
+return a->f();
+  }
+}
+
+
 namespace Test3 {
   struct A {
 virtual int f();
Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -2067,10 +2067,15 @@
   if (DevirtualizedMethod->hasAttr())
 return DevirtualizedMethod;
 
-  // Similarly, if the class itself is marked 'final' it can't be overridden
-  // and we can therefore devirtualize the member function call.
+  // Similarly, if the class itself or its destructor is marked 'final',
+  // the class can't be derived from and we can therefore devirtualize the 
+  // member function call.
   if (BestDynamicDecl->hasAttr())
 return DevirtualizedMethod;
+  if (const auto *dtor = BestDynamicDecl->getDestructor()) {
+if (dtor->hasAttr())
+  return DevirtualizedMethod;
+  }
 
   if (const auto *DRE = dyn_cast(Base)) {
 if (const auto *VD = dyn_cast(DRE->getDecl()))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66699: [PowerPC][Altivec] Fix constant argument for vec_dss

2019-08-23 Thread Jinsong Ji via Phabricator via cfe-commits
jsji created this revision.
jsji added reviewers: nemanjai, hfinkel.
Herald added subscribers: cfe-commits, shchenz, MaskRay, kbarton.
Herald added a project: clang.
jsji added a reviewer: PowerPC.
Herald added a subscriber: wuzish.

This is similar to vec_ct* in https://reviews.llvm.org/rL304205.

The argument must be a constant, otherwise instruction selection
will fail. always_inline is not enough for isel to always fold
everything away at -O0.

The fix is to turn the function into macros in altivec.h.

Fixes https://bugs.llvm.org/show_bug.cgi?id=43072


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66699

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/altivec-dss.c
  clang/test/CodeGen/builtins-ppc-error.c


Index: clang/test/CodeGen/builtins-ppc-error.c
===
--- clang/test/CodeGen/builtins-ppc-error.c
+++ clang/test/CodeGen/builtins-ppc-error.c
@@ -73,3 +73,8 @@
   __builtin_unpack_vector_int128(vsllli, index); //expected-error {{argument 
to '__builtin_unpack_vector_int128' must be a constant integer}}
   __builtin_unpack_vector_int128(vsllli, 5); //expected-error {{argument value 
5 is outside the valid range [0, 1]}}
 }
+
+void testDSS(int index) {
+  vec_dss(index); //expected-error {{argument to '__builtin_altivec_dss' must 
be a constant integer}}
+
+}
Index: clang/test/CodeGen/altivec-dss.c
===
--- /dev/null
+++ clang/test/CodeGen/altivec-dss.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple powerpc-linux-gnu -S -O0 -o - %s -target-feature 
+altivec | FileCheck %s
+
+// REQUIRES: powerpc-registered-target
+
+#include 
+
+// CHECK-LABEL: test1
+// CHECK: dss 
+void test1() {
+  vec_dss(1);
+}
Index: clang/lib/Headers/altivec.h
===
--- clang/lib/Headers/altivec.h
+++ clang/lib/Headers/altivec.h
@@ -3286,9 +3286,7 @@
 
 /* vec_dss */
 
-static __inline__ void __attribute__((__always_inline__)) vec_dss(int __a) {
-  __builtin_altivec_dss(__a);
-}
+#define vec_dss __builtin_altivec_dss
 
 /* vec_dssall */
 
Index: clang/include/clang/Basic/BuiltinsPPC.def
===
--- clang/include/clang/Basic/BuiltinsPPC.def
+++ clang/include/clang/Basic/BuiltinsPPC.def
@@ -55,7 +55,7 @@
 BUILTIN(__builtin_altivec_vctsxs, "V4SiV4fIi", "")
 BUILTIN(__builtin_altivec_vctuxs, "V4UiV4fIi", "")
 
-BUILTIN(__builtin_altivec_dss, "vUi", "")
+BUILTIN(__builtin_altivec_dss, "vUIi", "")
 BUILTIN(__builtin_altivec_dssall, "v", "")
 BUILTIN(__builtin_altivec_dst, "vvC*iUi", "")
 BUILTIN(__builtin_altivec_dstt, "vvC*iUi", "")


Index: clang/test/CodeGen/builtins-ppc-error.c
===
--- clang/test/CodeGen/builtins-ppc-error.c
+++ clang/test/CodeGen/builtins-ppc-error.c
@@ -73,3 +73,8 @@
   __builtin_unpack_vector_int128(vsllli, index); //expected-error {{argument to '__builtin_unpack_vector_int128' must be a constant integer}}
   __builtin_unpack_vector_int128(vsllli, 5); //expected-error {{argument value 5 is outside the valid range [0, 1]}}
 }
+
+void testDSS(int index) {
+  vec_dss(index); //expected-error {{argument to '__builtin_altivec_dss' must be a constant integer}}
+
+}
Index: clang/test/CodeGen/altivec-dss.c
===
--- /dev/null
+++ clang/test/CodeGen/altivec-dss.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple powerpc-linux-gnu -S -O0 -o - %s -target-feature +altivec | FileCheck %s
+
+// REQUIRES: powerpc-registered-target
+
+#include 
+
+// CHECK-LABEL: test1
+// CHECK: dss 
+void test1() {
+  vec_dss(1);
+}
Index: clang/lib/Headers/altivec.h
===
--- clang/lib/Headers/altivec.h
+++ clang/lib/Headers/altivec.h
@@ -3286,9 +3286,7 @@
 
 /* vec_dss */
 
-static __inline__ void __attribute__((__always_inline__)) vec_dss(int __a) {
-  __builtin_altivec_dss(__a);
-}
+#define vec_dss __builtin_altivec_dss
 
 /* vec_dssall */
 
Index: clang/include/clang/Basic/BuiltinsPPC.def
===
--- clang/include/clang/Basic/BuiltinsPPC.def
+++ clang/include/clang/Basic/BuiltinsPPC.def
@@ -55,7 +55,7 @@
 BUILTIN(__builtin_altivec_vctsxs, "V4SiV4fIi", "")
 BUILTIN(__builtin_altivec_vctuxs, "V4UiV4fIi", "")
 
-BUILTIN(__builtin_altivec_dss, "vUi", "")
+BUILTIN(__builtin_altivec_dss, "vUIi", "")
 BUILTIN(__builtin_altivec_dssall, "v", "")
 BUILTIN(__builtin_altivec_dst, "vvC*iUi", "")
 BUILTIN(__builtin_altivec_dstt, "vvC*iUi", "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66662: [clang-format] [PR43100] clang-format C# support does not add a space between "using" and paren

2019-08-23 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:169
+TEST_F(FormatTestCSharp, CSharpUsing) {
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filename) { }");
+}

owenpan wrote:
> Maybe set `SpaceBeforeParens` to `Always` first in order to really test the 
> new behavior?
I meant setting `SpaceBeforeParens` to ~~`Always`~~ `Never`. 


Repository:
  rC Clang

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

https://reviews.llvm.org/D2



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


r369834 - PR42513: Enter the proper DeclContext before substituting into an

2019-08-23 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Aug 23 19:30:00 2019
New Revision: 369834

URL: http://llvm.org/viewvc/llvm-project?rev=369834=rev
Log:
PR42513: Enter the proper DeclContext before substituting into an
default template argument expression.

We already did this for type template parameters and template template
parameters, but apparently forgot to do so for non-type template
parameters. This causes the substituted default argument expression to
be substituted in the proper context, and in particular to properly mark
its subexpressions as odr-used.

Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=369834=369833=369834=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Aug 23 19:30:00 2019
@@ -4693,6 +4693,7 @@ SubstDefaultTemplateArgument(Sema 
   for (unsigned i = 0, e = Param->getDepth(); i != e; ++i)
 TemplateArgLists.addOuterTemplateArguments(None);
 
+  Sema::ContextRAII SavedContext(SemaRef, Template->getDeclContext());
   EnterExpressionEvaluationContext ConstantEvaluated(
   SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
   return SemaRef.SubstExpr(Param->getDefaultArgument(), TemplateArgLists);

Modified: cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp?rev=369834=369833=369834=diff
==
--- cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp 
(original)
+++ cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp Fri Aug 
23 19:30:00 2019
@@ -268,13 +268,16 @@ namespace tuple_tests {
   // Don't get caught by surprise when X<...> doesn't even exist in the
   // selected specialization!
   namespace libcxx_2 {
-template struct tuple { // expected-note {{candidate}}
+template struct tuple {
   template struct X { static const bool value = false; };
+  // Substitution into X::value succeeds but produces the
+  // value-dependent expression
+  //   tuple::X<>::value
+  // FIXME: Is that the right behavior?
   template::value> tuple(U &&...u);
-  // expected-note@-1 {{substitution failure [with T = <>, U = ]: cannot reference member of primary template because deduced class 
template specialization 'tuple<>' is an explicit specialization}}
 };
 template <> class tuple<> {};
-tuple a = {1, 2, 3}; // expected-error {{no viable constructor or 
deduction guide}}
+tuple a = {1, 2, 3}; // expected-error {{excess elements in struct 
initializer}}
   }
 
   namespace libcxx_3 {

Modified: cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp?rev=369834=369833=369834=diff
==
--- cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx11.cpp Fri Aug 23 19:30:00 
2019
@@ -48,3 +48,20 @@ void Useage() {
 }
 }
 
+namespace PR42513 {
+  template void f();
+  constexpr int WidgetCtor(struct X1*);
+
+  struct X1 {
+friend constexpr int WidgetCtor(X1*);
+  };
+  template
+  struct StandardWidget {
+friend constexpr int WidgetCtor(X1*) {
+  return 0;
+}
+  };
+  template struct StandardWidget;
+
+  void use() { f(); }
+}


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


[PATCH] D66697: hwasan, codegen: Keep more lifetime markers used for hwasan

2019-08-23 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added a reviewer: eugenis.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
vitalybuka added a parent revision: D66695: msan, codegen, instcombine: Keep 
more lifetime markers used for msan.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66697

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/lifetime-sanitizer.c
  clang/test/CodeGenCXX/lifetime-sanitizer.cpp


Index: clang/test/CodeGenCXX/lifetime-sanitizer.cpp
===
--- clang/test/CodeGenCXX/lifetime-sanitizer.cpp
+++ clang/test/CodeGenCXX/lifetime-sanitizer.cpp
@@ -6,6 +6,9 @@
 // RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions 
-O0 \
 // RUN: -fsanitize=memory %s | \
 // RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
+// RUN: %clang -w -target aarch64-linux-gnu -S -emit-llvm -o - -fno-exceptions 
-O0 \
+// RUN: -fsanitize=hwaddress %s | \
+// RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
 
 extern int bar(char *A, int n);
 
Index: clang/test/CodeGen/lifetime-sanitizer.c
===
--- clang/test/CodeGen/lifetime-sanitizer.c
+++ clang/test/CodeGen/lifetime-sanitizer.c
@@ -5,6 +5,9 @@
 // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
 // RUN: -fsanitize=memory %s | \
 // RUN: FileCheck %s -check-prefix=LIFETIME
+// RUN: %clang -target aarch64-linux-gnu -S -emit-llvm -o - -O0 \
+// RUN: -fsanitize=hwaddress %s | \
+// RUN: FileCheck %s -check-prefix=LIFETIME
 
 extern int bar(char *A, int n);
 
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -49,6 +49,7 @@
 
   // Sanitizers may use markers.
   if (CGOpts.SanitizeAddressUseAfterScope ||
+  LangOpts.Sanitize.has(SanitizerKind::HWAddress) ||
   LangOpts.Sanitize.has(SanitizerKind::Memory))
 return true;
 
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -521,6 +521,7 @@
   ConditionalEvaluation *OldConditional = nullptr;
   CGBuilderTy::InsertPoint OldIP;
   if (isInConditionalBranch() && !E->getType().isDestructedType() &&
+  !SanOpts.has(SanitizerKind::HWAddress) &&
   !SanOpts.has(SanitizerKind::Memory) &&
   !CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) {
 OldConditional = OutermostConditional;


Index: clang/test/CodeGenCXX/lifetime-sanitizer.cpp
===
--- clang/test/CodeGenCXX/lifetime-sanitizer.cpp
+++ clang/test/CodeGenCXX/lifetime-sanitizer.cpp
@@ -6,6 +6,9 @@
 // RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
 // RUN: -fsanitize=memory %s | \
 // RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
+// RUN: %clang -w -target aarch64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
+// RUN: -fsanitize=hwaddress %s | \
+// RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
 
 extern int bar(char *A, int n);
 
Index: clang/test/CodeGen/lifetime-sanitizer.c
===
--- clang/test/CodeGen/lifetime-sanitizer.c
+++ clang/test/CodeGen/lifetime-sanitizer.c
@@ -5,6 +5,9 @@
 // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
 // RUN: -fsanitize=memory %s | \
 // RUN: FileCheck %s -check-prefix=LIFETIME
+// RUN: %clang -target aarch64-linux-gnu -S -emit-llvm -o - -O0 \
+// RUN: -fsanitize=hwaddress %s | \
+// RUN: FileCheck %s -check-prefix=LIFETIME
 
 extern int bar(char *A, int n);
 
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -49,6 +49,7 @@
 
   // Sanitizers may use markers.
   if (CGOpts.SanitizeAddressUseAfterScope ||
+  LangOpts.Sanitize.has(SanitizerKind::HWAddress) ||
   LangOpts.Sanitize.has(SanitizerKind::Memory))
 return true;
 
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -521,6 +521,7 @@
   ConditionalEvaluation *OldConditional = nullptr;
   CGBuilderTy::InsertPoint OldIP;
   if (isInConditionalBranch() && !E->getType().isDestructedType() &&
+  !SanOpts.has(SanitizerKind::HWAddress) &&
   !SanOpts.has(SanitizerKind::Memory) &&
   !CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) {
 OldConditional = OutermostConditional;
___
cfe-commits mailing list

[PATCH] D66695: msan, codegen, instcombine: Keep more lifetime markers used for msan

2019-08-23 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 216994.
vitalybuka added a comment.

update comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66695

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/lifetime-sanitizer.c
  clang/test/CodeGenCXX/lifetime-sanitizer.cpp
  compiler-rt/test/msan/loop-scope.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll

Index: llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll
===
--- llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll
+++ llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll
@@ -34,6 +34,21 @@
   ret void
 }
 
+define void @msan() sanitize_memory {
+entry:
+  ; CHECK-LABEL: @msan(
+  %text = alloca i8, align 1
+
+  call void @llvm.lifetime.start.p0i8(i64 1, i8* %text)
+  call void @llvm.lifetime.end.p0i8(i64 1, i8* %text)
+  ; CHECK: call void @llvm.lifetime.start
+  ; CHECK-NEXT: call void @llvm.lifetime.end
+
+  call void @foo(i8* %text) ; Keep alloca alive
+
+  ret void
+}
+
 define void @no_asan() {
 entry:
   ; CHECK-LABEL: @no_asan(
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3885,6 +3885,7 @@
 // Asan needs to poison memory to detect invalid access which is possible
 // even for empty lifetime range.
 if (II->getFunction()->hasFnAttribute(Attribute::SanitizeAddress) ||
+II->getFunction()->hasFnAttribute(Attribute::SanitizeMemory) ||
 II->getFunction()->hasFnAttribute(Attribute::SanitizeHWAddress))
   break;
 
Index: compiler-rt/test/msan/loop-scope.cpp
===
--- /dev/null
+++ compiler-rt/test/msan/loop-scope.cpp
@@ -0,0 +1,18 @@
+// RUN: %clangxx_msan -O2 %s -o %t && \
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include 
+
+int *p;
+
+int main() {
+  for (int i = 0; i < 3; i++) {
+int x;
+if (i == 0)
+  x = 0;
+p = 
+  }
+  return *p; // BOOM
+  // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
+  // CHECK:  #0 0x{{.*}} in main {{.*}}loop-scope.cpp:[[@LINE-2]]
+}
Index: clang/test/CodeGenCXX/lifetime-sanitizer.cpp
===
--- clang/test/CodeGenCXX/lifetime-sanitizer.cpp
+++ clang/test/CodeGenCXX/lifetime-sanitizer.cpp
@@ -3,6 +3,9 @@
 // RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
 // RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
 // RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
+// RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
+// RUN: -fsanitize=memory %s | \
+// RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
 
 extern int bar(char *A, int n);
 
Index: clang/test/CodeGen/lifetime-sanitizer.c
===
--- clang/test/CodeGen/lifetime-sanitizer.c
+++ clang/test/CodeGen/lifetime-sanitizer.c
@@ -2,6 +2,9 @@
 // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
 // RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
 // RUN: FileCheck %s -check-prefix=LIFETIME
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
+// RUN: -fsanitize=memory %s | \
+// RUN: FileCheck %s -check-prefix=LIFETIME
 
 extern int bar(char *A, int n);
 
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -47,13 +47,9 @@
   if (CGOpts.DisableLifetimeMarkers)
 return false;
 
-  // Disable lifetime markers in msan builds.
-  // FIXME: Remove this when msan works with lifetime markers.
-  if (LangOpts.Sanitize.has(SanitizerKind::Memory))
-return false;
-
-  // Asan uses markers for use-after-scope checks.
-  if (CGOpts.SanitizeAddressUseAfterScope)
+  // Sanitizers may use markers.
+  if (CGOpts.SanitizeAddressUseAfterScope ||
+  LangOpts.Sanitize.has(SanitizerKind::Memory))
 return true;
 
   // For now, only in optimized builds.
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -516,13 +516,12 @@
 
   // Avoid creating a conditional cleanup just to hold an llvm.lifetime.end
   // marker. Instead, start the lifetime of a conditional temporary earlier
-  // so that it's unconditional. Don't do this in ASan's use-after-scope
-  // mode so that it gets the more precise lifetime marks. If the type has
-  // a 

[PATCH] D66696: [ObjC generics] Fix not inheriting type bounds in categories/extensions.

2019-08-23 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: erik.pilkington, ahatanak.
Herald added subscribers: ributzka, dexonsmith, jkorous.

When a category/extension doesn't repeat a type bound, corresponding
type parameter is substituted with `id` when used as a type argument. As
a result, in the added test case it was causing errors like

> type argument 'T' (aka 'id') does not satisfy the bound ('id') of 
> type parameter 'T'

We are already checking that type parameters should be consistent
everywhere (see `checkTypeParamListConsistency`) and update
`ObjCTypeParamDecl` to have correct underlying type. And when we use the
type parameter as a method return type or a method parameter type, it is
substituted to the bounded type. But when we use the type parameter as a
type argument, we check `ObjCTypeParamType` that ignores the updated
underlying type and remains `id`.

Fix by desugaring `ObjCTypeParamType` to the underlying type, the same
way we are doing with `TypedefType`.

rdar://problem/54329242


https://reviews.llvm.org/D66696

Files:
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp
  clang/test/SemaObjC/parameterized_classes_subst.m


Index: clang/test/SemaObjC/parameterized_classes_subst.m
===
--- clang/test/SemaObjC/parameterized_classes_subst.m
+++ clang/test/SemaObjC/parameterized_classes_subst.m
@@ -467,3 +467,17 @@
 - (void)mapUsingBlock2:(id)block { // expected-warning{{conflicting parameter 
types in implementation}}
 }
 @end
+
+// --
+// Use a type parameter as a type argument.
+// --
+// Type bounds in a category/extension are omitted. rdar://problem/54329242
+@interface ParameterizedContainer>
+- (ParameterizedContainer *)inInterface;
+@end
+@interface ParameterizedContainer (Cat)
+- (ParameterizedContainer *)inCategory;
+@end
+@interface ParameterizedContainer ()
+- (ParameterizedContainer *)inExtension;
+@end
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -611,6 +611,10 @@
   initialize(protocols);
 }
 
+QualType ObjCTypeParamType::desugar() const {
+  return getDecl()->getUnderlyingType();
+}
+
 ObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base,
ArrayRef typeArgs,
ArrayRef protocols,
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -5554,7 +5554,7 @@
 
 public:
   bool isSugared() const { return true; }
-  QualType desugar() const { return getCanonicalTypeInternal(); }
+  QualType desugar() const;
 
   static bool classof(const Type *T) {
 return T->getTypeClass() == ObjCTypeParam;


Index: clang/test/SemaObjC/parameterized_classes_subst.m
===
--- clang/test/SemaObjC/parameterized_classes_subst.m
+++ clang/test/SemaObjC/parameterized_classes_subst.m
@@ -467,3 +467,17 @@
 - (void)mapUsingBlock2:(id)block { // expected-warning{{conflicting parameter types in implementation}}
 }
 @end
+
+// --
+// Use a type parameter as a type argument.
+// --
+// Type bounds in a category/extension are omitted. rdar://problem/54329242
+@interface ParameterizedContainer>
+- (ParameterizedContainer *)inInterface;
+@end
+@interface ParameterizedContainer (Cat)
+- (ParameterizedContainer *)inCategory;
+@end
+@interface ParameterizedContainer ()
+- (ParameterizedContainer *)inExtension;
+@end
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -611,6 +611,10 @@
   initialize(protocols);
 }
 
+QualType ObjCTypeParamType::desugar() const {
+  return getDecl()->getUnderlyingType();
+}
+
 ObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base,
ArrayRef typeArgs,
ArrayRef protocols,
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -5554,7 +5554,7 @@
 
 public:
   bool isSugared() const { return true; }
-  QualType desugar() const { return getCanonicalTypeInternal(); }
+  QualType desugar() const;
 
   static bool classof(const Type *T) {
 return T->getTypeClass() == ObjCTypeParam;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66695: msan, codegen, instcombine: Keep more lifetime markers used for msan

2019-08-23 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 216991.
vitalybuka added a comment.

return hwasan


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66695

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/lifetime-sanitizer.c
  clang/test/CodeGenCXX/lifetime-sanitizer.cpp
  compiler-rt/test/msan/loop-scope.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll

Index: llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll
===
--- llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll
+++ llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll
@@ -34,6 +34,21 @@
   ret void
 }
 
+define void @msan() sanitize_memory {
+entry:
+  ; CHECK-LABEL: @msan(
+  %text = alloca i8, align 1
+
+  call void @llvm.lifetime.start.p0i8(i64 1, i8* %text)
+  call void @llvm.lifetime.end.p0i8(i64 1, i8* %text)
+  ; CHECK: call void @llvm.lifetime.start
+  ; CHECK-NEXT: call void @llvm.lifetime.end
+
+  call void @foo(i8* %text) ; Keep alloca alive
+
+  ret void
+}
+
 define void @no_asan() {
 entry:
   ; CHECK-LABEL: @no_asan(
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3885,6 +3885,7 @@
 // Asan needs to poison memory to detect invalid access which is possible
 // even for empty lifetime range.
 if (II->getFunction()->hasFnAttribute(Attribute::SanitizeAddress) ||
+II->getFunction()->hasFnAttribute(Attribute::SanitizeMemory) ||
 II->getFunction()->hasFnAttribute(Attribute::SanitizeHWAddress))
   break;
 
Index: compiler-rt/test/msan/loop-scope.cpp
===
--- /dev/null
+++ compiler-rt/test/msan/loop-scope.cpp
@@ -0,0 +1,18 @@
+// RUN: %clangxx_msan -O2 %s -o %t && \
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include 
+
+int *p;
+
+int main() {
+  for (int i = 0; i < 3; i++) {
+int x;
+if (i == 0)
+  x = 0;
+p = 
+  }
+  return *p; // BOOM
+  // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
+  // CHECK:  #0 0x{{.*}} in main {{.*}}loop-scope.cpp:[[@LINE-2]]
+}
Index: clang/test/CodeGenCXX/lifetime-sanitizer.cpp
===
--- clang/test/CodeGenCXX/lifetime-sanitizer.cpp
+++ clang/test/CodeGenCXX/lifetime-sanitizer.cpp
@@ -3,6 +3,9 @@
 // RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
 // RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
 // RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
+// RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
+// RUN: -fsanitize=memory %s | \
+// RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
 
 extern int bar(char *A, int n);
 
Index: clang/test/CodeGen/lifetime-sanitizer.c
===
--- clang/test/CodeGen/lifetime-sanitizer.c
+++ clang/test/CodeGen/lifetime-sanitizer.c
@@ -2,6 +2,9 @@
 // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
 // RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
 // RUN: FileCheck %s -check-prefix=LIFETIME
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
+// RUN: -fsanitize=memory %s | \
+// RUN: FileCheck %s -check-prefix=LIFETIME
 
 extern int bar(char *A, int n);
 
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -47,13 +47,9 @@
   if (CGOpts.DisableLifetimeMarkers)
 return false;
 
-  // Disable lifetime markers in msan builds.
-  // FIXME: Remove this when msan works with lifetime markers.
-  if (LangOpts.Sanitize.has(SanitizerKind::Memory))
-return false;
-
-  // Asan uses markers for use-after-scope checks.
-  if (CGOpts.SanitizeAddressUseAfterScope)
+  // Sanitizers may use markers.
+  if (CGOpts.SanitizeAddressUseAfterScope ||
+  LangOpts.Sanitize.has(SanitizerKind::Memory)
 return true;
 
   // For now, only in optimized builds.
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -523,6 +523,7 @@
   ConditionalEvaluation *OldConditional = nullptr;
   CGBuilderTy::InsertPoint OldIP;
   if (isInConditionalBranch() && !E->getType().isDestructedType() &&
+  !SanOpts.has(SanitizerKind::Memory) &&
   !CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) {
 OldConditional = OutermostConditional;
 

[PATCH] D66695: msan, codegen, instcombine: Keep more lifetime markers used for msan

2019-08-23 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 216992.
vitalybuka added a comment.

fix compilation error


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66695

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/lifetime-sanitizer.c
  clang/test/CodeGenCXX/lifetime-sanitizer.cpp
  compiler-rt/test/msan/loop-scope.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll

Index: llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll
===
--- llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll
+++ llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll
@@ -34,6 +34,21 @@
   ret void
 }
 
+define void @msan() sanitize_memory {
+entry:
+  ; CHECK-LABEL: @msan(
+  %text = alloca i8, align 1
+
+  call void @llvm.lifetime.start.p0i8(i64 1, i8* %text)
+  call void @llvm.lifetime.end.p0i8(i64 1, i8* %text)
+  ; CHECK: call void @llvm.lifetime.start
+  ; CHECK-NEXT: call void @llvm.lifetime.end
+
+  call void @foo(i8* %text) ; Keep alloca alive
+
+  ret void
+}
+
 define void @no_asan() {
 entry:
   ; CHECK-LABEL: @no_asan(
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3885,6 +3885,7 @@
 // Asan needs to poison memory to detect invalid access which is possible
 // even for empty lifetime range.
 if (II->getFunction()->hasFnAttribute(Attribute::SanitizeAddress) ||
+II->getFunction()->hasFnAttribute(Attribute::SanitizeMemory) ||
 II->getFunction()->hasFnAttribute(Attribute::SanitizeHWAddress))
   break;
 
Index: compiler-rt/test/msan/loop-scope.cpp
===
--- /dev/null
+++ compiler-rt/test/msan/loop-scope.cpp
@@ -0,0 +1,18 @@
+// RUN: %clangxx_msan -O2 %s -o %t && \
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include 
+
+int *p;
+
+int main() {
+  for (int i = 0; i < 3; i++) {
+int x;
+if (i == 0)
+  x = 0;
+p = 
+  }
+  return *p; // BOOM
+  // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
+  // CHECK:  #0 0x{{.*}} in main {{.*}}loop-scope.cpp:[[@LINE-2]]
+}
Index: clang/test/CodeGenCXX/lifetime-sanitizer.cpp
===
--- clang/test/CodeGenCXX/lifetime-sanitizer.cpp
+++ clang/test/CodeGenCXX/lifetime-sanitizer.cpp
@@ -3,6 +3,9 @@
 // RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
 // RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
 // RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
+// RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
+// RUN: -fsanitize=memory %s | \
+// RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
 
 extern int bar(char *A, int n);
 
Index: clang/test/CodeGen/lifetime-sanitizer.c
===
--- clang/test/CodeGen/lifetime-sanitizer.c
+++ clang/test/CodeGen/lifetime-sanitizer.c
@@ -2,6 +2,9 @@
 // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
 // RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
 // RUN: FileCheck %s -check-prefix=LIFETIME
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
+// RUN: -fsanitize=memory %s | \
+// RUN: FileCheck %s -check-prefix=LIFETIME
 
 extern int bar(char *A, int n);
 
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -47,13 +47,9 @@
   if (CGOpts.DisableLifetimeMarkers)
 return false;
 
-  // Disable lifetime markers in msan builds.
-  // FIXME: Remove this when msan works with lifetime markers.
-  if (LangOpts.Sanitize.has(SanitizerKind::Memory))
-return false;
-
-  // Asan uses markers for use-after-scope checks.
-  if (CGOpts.SanitizeAddressUseAfterScope)
+  // Sanitizers may use markers.
+  if (CGOpts.SanitizeAddressUseAfterScope ||
+  LangOpts.Sanitize.has(SanitizerKind::Memory))
 return true;
 
   // For now, only in optimized builds.
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -523,6 +523,7 @@
   ConditionalEvaluation *OldConditional = nullptr;
   CGBuilderTy::InsertPoint OldIP;
   if (isInConditionalBranch() && !E->getType().isDestructedType() &&
+  !SanOpts.has(SanitizerKind::Memory) &&
   !CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) {
 OldConditional = OutermostConditional;

r369832 - Re-enable DependencyScannerTest on windows with the right fixes

2019-08-23 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Fri Aug 23 18:53:40 2019
New Revision: 369832

URL: http://llvm.org/viewvc/llvm-project?rev=369832=rev
Log:
Re-enable DependencyScannerTest on windows with the right fixes

It should now pass.

Modified:
cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp

Modified: cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp?rev=369832=369831=369832=diff
==
--- cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/DependencyScannerTest.cpp Fri Aug 23 18:53:40 
2019
@@ -16,6 +16,7 @@
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
@@ -26,8 +27,6 @@
 namespace clang {
 namespace tooling {
 
-#ifndef _WIN32
-
 namespace {
 
 /// Prints out all of the gathered dependencies into a string.
@@ -82,9 +81,14 @@ TEST(DependencyScanner, ScanDepsReuseFil
 
   auto VFS = new llvm::vfs::InMemoryFileSystem();
   VFS->setCurrentWorkingDirectory(CWD);
-  VFS->addFile("/root/header.h", 0, llvm::MemoryBuffer::getMemBuffer("\n"));
-  VFS->addHardLink("/root/symlink.h", "/root/header.h");
-  VFS->addFile("/root/test.cpp", 0,
+  auto Sept = llvm::sys::path::get_separator();
+  std::string HeaderPath = llvm::formatv("{0}root{0}header.h", Sept);
+  std::string SymlinkPath = llvm::formatv("{0}root{0}symlink.h", Sept);
+  std::string TestPath = llvm::formatv("{0}root{0}test.cpp", Sept);
+
+  VFS->addFile(HeaderPath, 0, llvm::MemoryBuffer::getMemBuffer("\n"));
+  VFS->addHardLink(SymlinkPath, HeaderPath);
+  VFS->addFile(TestPath, 0,
llvm::MemoryBuffer::getMemBuffer(
"#include \"symlink.h\"\n#include \"header.h\"\n"));
 
@@ -94,11 +98,12 @@ TEST(DependencyScanner, ScanDepsReuseFil
   std::vector Deps;
   TestDependencyScanningAction Action(Deps);
   Tool.run();
+  using llvm::sys::path::convert_to_slash;
   // The first invocation should return dependencies in order of access.
   ASSERT_EQ(Deps.size(), 3u);
-  EXPECT_EQ(Deps[0], "/root/test.cpp");
-  EXPECT_EQ(Deps[1], "/root/symlink.h");
-  EXPECT_EQ(Deps[2], "/root/header.h");
+  EXPECT_EQ(convert_to_slash(Deps[0]), "/root/test.cpp");
+  EXPECT_EQ(convert_to_slash(Deps[1]), "/root/symlink.h");
+  EXPECT_EQ(convert_to_slash(Deps[2]), "/root/header.h");
 
   // The file manager should still have two FileEntries, as one file is a
   // hardlink.
@@ -109,14 +114,12 @@ TEST(DependencyScanner, ScanDepsReuseFil
   Tool.run();
   // The second invocation should have the same order of dependencies.
   ASSERT_EQ(Deps.size(), 3u);
-  EXPECT_EQ(Deps[0], "/root/test.cpp");
-  EXPECT_EQ(Deps[1], "/root/symlink.h");
-  EXPECT_EQ(Deps[2], "/root/header.h");
+  EXPECT_EQ(convert_to_slash(Deps[0]), "/root/test.cpp");
+  EXPECT_EQ(convert_to_slash(Deps[1]), "/root/symlink.h");
+  EXPECT_EQ(convert_to_slash(Deps[2]), "/root/header.h");
 
   EXPECT_EQ(Files.getNumUniqueRealFiles(), 2u);
 }
 
-#endif
-
 } // end namespace tooling
 } // end namespace clang


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


[PATCH] D66695: msan, codegen, instcombine: Keep more lifetime markers used for msan

2019-08-23 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added a reviewer: eugenis.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits, hiraditya.
Herald added projects: clang, Sanitizers, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66695

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/lifetime-sanitizer.c
  clang/test/CodeGenCXX/lifetime-sanitizer.cpp
  compiler-rt/test/msan/loop-scope.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll

Index: llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll
===
--- llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll
+++ llvm/test/Transforms/InstCombine/lifetime-sanitizer.ll
@@ -34,6 +34,21 @@
   ret void
 }
 
+define void @msan() sanitize_memory {
+entry:
+  ; CHECK-LABEL: @msan(
+  %text = alloca i8, align 1
+
+  call void @llvm.lifetime.start.p0i8(i64 1, i8* %text)
+  call void @llvm.lifetime.end.p0i8(i64 1, i8* %text)
+  ; CHECK: call void @llvm.lifetime.start
+  ; CHECK-NEXT: call void @llvm.lifetime.end
+
+  call void @foo(i8* %text) ; Keep alloca alive
+
+  ret void
+}
+
 define void @no_asan() {
 entry:
   ; CHECK-LABEL: @no_asan(
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3885,7 +3885,7 @@
 // Asan needs to poison memory to detect invalid access which is possible
 // even for empty lifetime range.
 if (II->getFunction()->hasFnAttribute(Attribute::SanitizeAddress) ||
-II->getFunction()->hasFnAttribute(Attribute::SanitizeHWAddress))
+II->getFunction()->hasFnAttribute(Attribute::SanitizeMemory))
   break;
 
 if (removeTriviallyEmptyRange(*II, Intrinsic::lifetime_start,
Index: compiler-rt/test/msan/loop-scope.cpp
===
--- /dev/null
+++ compiler-rt/test/msan/loop-scope.cpp
@@ -0,0 +1,18 @@
+// RUN: %clangxx_msan -O2 %s -o %t && \
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+#include 
+
+int *p;
+
+int main() {
+  for (int i = 0; i < 3; i++) {
+int x;
+if (i == 0)
+  x = 0;
+p = 
+  }
+  return *p; // BOOM
+  // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
+  // CHECK:  #0 0x{{.*}} in main {{.*}}loop-scope.cpp:[[@LINE-2]]
+}
Index: clang/test/CodeGenCXX/lifetime-sanitizer.cpp
===
--- clang/test/CodeGenCXX/lifetime-sanitizer.cpp
+++ clang/test/CodeGenCXX/lifetime-sanitizer.cpp
@@ -3,6 +3,9 @@
 // RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
 // RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
 // RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
+// RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
+// RUN: -fsanitize=memory %s | \
+// RUN: FileCheck %s -check-prefixes=CHECK,LIFETIME
 
 extern int bar(char *A, int n);
 
Index: clang/test/CodeGen/lifetime-sanitizer.c
===
--- clang/test/CodeGen/lifetime-sanitizer.c
+++ clang/test/CodeGen/lifetime-sanitizer.c
@@ -2,6 +2,9 @@
 // RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
 // RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
 // RUN: FileCheck %s -check-prefix=LIFETIME
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
+// RUN: -fsanitize=memory %s | \
+// RUN: FileCheck %s -check-prefix=LIFETIME
 
 extern int bar(char *A, int n);
 
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -47,13 +47,9 @@
   if (CGOpts.DisableLifetimeMarkers)
 return false;
 
-  // Disable lifetime markers in msan builds.
-  // FIXME: Remove this when msan works with lifetime markers.
-  if (LangOpts.Sanitize.has(SanitizerKind::Memory))
-return false;
-
-  // Asan uses markers for use-after-scope checks.
-  if (CGOpts.SanitizeAddressUseAfterScope)
+  // Sanitizers may use markers.
+  if (CGOpts.SanitizeAddressUseAfterScope ||
+  LangOpts.Sanitize.has(SanitizerKind::Memory)
 return true;
 
   // For now, only in optimized builds.
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -523,6 +523,7 @@
   ConditionalEvaluation *OldConditional = nullptr;
   CGBuilderTy::InsertPoint OldIP;
   if (isInConditionalBranch() && !E->getType().isDestructedType() &&
+  !SanOpts.has(SanitizerKind::Memory) &&
   

r369830 - NFC: Rename some sanitizer related lifetime checks

2019-08-23 Thread Vitaly Buka via cfe-commits
Author: vitalybuka
Date: Fri Aug 23 18:31:38 2019
New Revision: 369830

URL: http://llvm.org/viewvc/llvm-project?rev=369830=rev
Log:
NFC: Rename some sanitizer related lifetime checks

Added:
cfe/trunk/test/CodeGen/lifetime-sanitizer.c
cfe/trunk/test/CodeGenCXX/lifetime-sanitizer.cpp
Removed:
cfe/trunk/test/CodeGen/lifetime-asan.c
cfe/trunk/test/CodeGenCXX/lifetime-asan.cpp

Removed: cfe/trunk/test/CodeGen/lifetime-asan.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/lifetime-asan.c?rev=369829=auto
==
--- cfe/trunk/test/CodeGen/lifetime-asan.c (original)
+++ cfe/trunk/test/CodeGen/lifetime-asan.c (removed)
@@ -1,21 +0,0 @@
-// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 %s | FileCheck 
%s -check-prefix=CHECK-O0
-// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
-// RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
-// RUN: FileCheck %s -check-prefix=CHECK-ASAN-USE-AFTER-SCOPE
-
-extern int bar(char *A, int n);
-
-// CHECK-O0-NOT: @llvm.lifetime.start
-int foo(int n) {
-  if (n) {
-// CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.start.p0i8(i64 10, i8* 
{{.*}})
-char A[10];
-return bar(A, 1);
-// CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.end.p0i8(i64 10, i8* {{.*}})
-  } else {
-// CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.start.p0i8(i64 20, i8* 
{{.*}})
-char A[20];
-return bar(A, 2);
-// CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.end.p0i8(i64 20, i8* {{.*}})
-  }
-}

Added: cfe/trunk/test/CodeGen/lifetime-sanitizer.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/lifetime-sanitizer.c?rev=369830=auto
==
--- cfe/trunk/test/CodeGen/lifetime-sanitizer.c (added)
+++ cfe/trunk/test/CodeGen/lifetime-sanitizer.c Fri Aug 23 18:31:38 2019
@@ -0,0 +1,21 @@
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 %s | FileCheck 
%s -check-prefix=CHECK-O0
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -O0 \
+// RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
+// RUN: FileCheck %s -check-prefix=LIFETIME
+
+extern int bar(char *A, int n);
+
+// CHECK-O0-NOT: @llvm.lifetime.start
+int foo(int n) {
+  if (n) {
+// LIFETIME: @llvm.lifetime.start.p0i8(i64 10, i8* {{.*}})
+char A[10];
+return bar(A, 1);
+// LIFETIME: @llvm.lifetime.end.p0i8(i64 10, i8* {{.*}})
+  } else {
+// LIFETIME: @llvm.lifetime.start.p0i8(i64 20, i8* {{.*}})
+char A[20];
+return bar(A, 2);
+// LIFETIME: @llvm.lifetime.end.p0i8(i64 20, i8* {{.*}})
+  }
+}

Removed: cfe/trunk/test/CodeGenCXX/lifetime-asan.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/lifetime-asan.cpp?rev=369829=auto
==
--- cfe/trunk/test/CodeGenCXX/lifetime-asan.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/lifetime-asan.cpp (removed)
@@ -1,42 +0,0 @@
-// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 
%s | FileCheck %s -check-prefixes=CHECK,CHECK-O0 
--implicit-check-not=llvm.lifetime
-// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 
\
-// RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
-// RUN: FileCheck %s -check-prefixes=CHECK,CHECK-ASAN-USE-AFTER-SCOPE
-
-extern int bar(char *A, int n);
-
-struct X { X(); ~X(); int *p; };
-struct Y { Y(); int *p; };
-
-extern "C" void a(), b(), c(), d();
-
-// CHECK-LABEL: @_Z3foo
-void foo(int n) {
-  // CHECK: call void @a()
-  a();
-
-  // CHECK: call void @b()
-  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 false
-  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 false
-  // CHECK: br i1
-  //
-  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.start
-  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 true
-  // CHECK: call void @_ZN1XC
-  // CHECK: br label
-  //
-  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.start
-  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 true
-  // CHECK: call void @_ZN1YC
-  // CHECK: br label
-  //
-  // CHECK: call void @c()
-  // CHECK-ASAN-USE-AFTER-SCOPE: br i1
-  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.end
-  // CHECK-ASAN-USE-AFTER-SCOPE: br i1
-  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.end
-  b(), (n ? X().p : Y().p), c();
-
-  // CHECK: call void @d()
-  d();
-}

Added: cfe/trunk/test/CodeGenCXX/lifetime-sanitizer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/lifetime-sanitizer.cpp?rev=369830=auto
==
--- cfe/trunk/test/CodeGenCXX/lifetime-sanitizer.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/lifetime-sanitizer.cpp Fri Aug 23 18:31:38 2019
@@ -0,0 +1,50 @@
+// RUN: %clang -w -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions 
-O0 %s | \
+// RUN:  FileCheck %s 

r369829 - PR40674: fix assertion failure if a structured binding declaration has a

2019-08-23 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Aug 23 18:23:57 2019
New Revision: 369829

URL: http://llvm.org/viewvc/llvm-project?rev=369829=rev
Log:
PR40674: fix assertion failure if a structured binding declaration has a
tuple-like decomposition that produces value-dependent reference
bindings.

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p3.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=369829=369828=369829=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Aug 23 18:23:57 2019
@@ -1225,7 +1225,8 @@ static bool checkTupleLikeDecomposition(
 if (E.isInvalid())
   return true;
 RefVD->setInit(E.get());
-RefVD->checkInitIsICE();
+if (!E.get()->isValueDependent())
+  RefVD->checkInitIsICE();
 
 E = S.BuildDeclarationNameExpr(CXXScopeSpec(),
DeclarationNameInfo(B->getDeclName(), Loc),

Modified: cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p3.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p3.cpp?rev=369829=369828=369829=diff
==
--- cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p3.cpp (original)
+++ cfe/trunk/test/CXX/dcl.decl/dcl.decomp/p3.cpp Fri Aug 23 18:23:57 2019
@@ -127,7 +127,7 @@ void referenced_type() {
   using ConstInt3 = decltype(bcr2);
 }
 
-struct C { template int get(); };
+struct C { template int get() const; };
 template<> struct std::tuple_size { static const int value = 1; };
 template<> struct std::tuple_element<0, C> { typedef int type; };
 
@@ -138,6 +138,12 @@ int member_get() {
   return c;
 }
 
+constexpr C c = C();
+template void dependent_binding_PR40674() {
+  const auto &[c] = *p;
+  (void)c;
+}
+
 struct D {
   // FIXME: Emit a note here explaining why this was ignored.
   template struct get {};


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


Re: [clang-tools-extra] r369763 - [clang-tidy] Possibility of displaying duplicate warnings

2019-08-23 Thread Galina Kistanova via cfe-commits
Hello Kristof,

This commit broke test to few builders:

http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/53703
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast

. . .
Failing Tests (1):
Clang Tools :: clang-tidy/duplicate-reports.cpp

Please have a look ASAP?

Thanks

Galina

On Fri, Aug 23, 2019 at 7:56 AM Kristof Umann via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: szelethus
> Date: Fri Aug 23 07:57:27 2019
> New Revision: 369763
>
> URL: http://llvm.org/viewvc/llvm-project?rev=369763=rev
> Log:
> [clang-tidy] Possibility of displaying duplicate warnings
>
> Summary: In case a checker is registered multiple times as an alias, the
> emitted warnings are uniqued by the report message. However, it is random
> which checker name is included in the warning. When processing the output
> of clang-tidy this behavior caused some problems. In this commit the
> uniquing key contains the checker name too.
>
> Reviewers: alexfh, xazax.hun, Szelethus, aaron.ballman, lebedev.ri,
> JonasToth, gribozavr
>
> Reviewed By: alexfh
>
> Subscribers: dkrupp, whisperity, rnkovacs, mgrang, cfe-commits
>
> Patch by Tibor Brunner!
>
> Tags: #clang
>
> Differential Revision: https://reviews.llvm.org/D65065
>
> Added:
> clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp
> Modified:
> clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
>
> Modified:
> clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=369763=369762=369763=diff
>
> ==
> --- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
> (original)
> +++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Fri
> Aug 23 07:57:27 2019
> @@ -742,8 +742,9 @@ struct LessClangTidyError {
>  const tooling::DiagnosticMessage  = LHS.Message;
>  const tooling::DiagnosticMessage  = RHS.Message;
>
> -return std::tie(M1.FilePath, M1.FileOffset, M1.Message) <
> -   std::tie(M2.FilePath, M2.FileOffset, M2.Message);
> +return
> +  std::tie(M1.FilePath, M1.FileOffset, LHS.DiagnosticName,
> M1.Message) <
> +  std::tie(M2.FilePath, M2.FileOffset, RHS.DiagnosticName,
> M2.Message);
>}
>  };
>  struct EqualClangTidyError {
>
> Added: clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp?rev=369763=auto
>
> ==
> --- clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp (added)
> +++ clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp Fri Aug
> 23 07:57:27 2019
> @@ -0,0 +1,15 @@
> +// RUN: %check_clang_tidy %s cert-err09-cpp,cert-err61-cpp %t
> +
> +void alwaysThrows() {
> +  int ex = 42;
> +  // CHECK-MESSAGES: warning: throw expression should throw anonymous
> temporary values instead [cert-err09-cpp]
> +  // CHECK-MESSAGES: warning: throw expression should throw anonymous
> temporary values instead [cert-err61-cpp]
> +  throw ex;
> +}
> +
> +void doTheJob() {
> +  try {
> +alwaysThrows();
> +  } catch (int&) {
> +  }
> +}
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66572: [analyzer] BugReporter Separation Ep.I.

2019-08-23 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ marked an inline comment as done.
NoQ added inline comments.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h:223
+  using visitor_iterator = VisitorList::iterator;
+  using visitor_range = llvm::iterator_range;
+

Szelethus wrote:
> I think I added a visitor range not long ago?
Yup, i just moved it from `BugReport` to `PathSensitiveBugReport`.
(hint: this yellow bar on the left of the insertion indicates that, you can 
also hover it to see where was the code moved from)


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

https://reviews.llvm.org/D66572



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


Re: r369591 - [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)

2019-08-23 Thread Nico Weber via cfe-commits
On Thu, Aug 22, 2019 at 4:05 PM Matthias Gehre via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hi Diana,
> hi Richard,
>
> thank you for the feedback!
>
> Diana,
> I remember that some gcc version had issues with raw string literals
> inside macros. I'll fix that to use normal
> string literals instead.
>

I think it's only a problem if the raw string is in a macro. Instead of

  FOO(R"(asdf)");

you can do

  const char kStr[] = R"(asdf)";
  FOO(kStr);

and gcc should be happy. (In case raw strings buy you something over normal
string literals.)


>
> Richard,
> We are definitely want the gsl::Pointer-based warnings that are enabled by
> default to be free of any false-positives.
> As you expected, this is showing a problem we have in another part of our
> analysis, and we will fix it before landing
> this PR again.
>
> Both, sorry for the breakage!
>
> Am Do., 22. Aug. 2019 um 19:47 Uhr schrieb Richard Smith <
> rich...@metafoo.co.uk>:
>
>> Reverted in r369677.
>>
>> On Thu, 22 Aug 2019 at 10:34, Richard Smith 
>> wrote:
>>
>>> Hi Matthias,
>>>
>>> This introduces false positives into -Wreturn-stack-address for an
>>> example such as:
>>>
>>> #include 
>>>
>>> std::vector::iterator downcast_to(std::vector::iterator value)
>>> {
>>>   return *
>>> }
>>>
>>> This breaks an internal build bot for us, so I'm going to revert this
>>> for now (though I expect this isn't the cause of the problem, but is rather
>>> exposing a problem elsewhere).
>>>
>>> If we can make the gsl::Pointer diagnostics false-positive-free, that's
>>> great, but otherwise we should use a different warning flag for the
>>> warnings that involve these annotations and use -Wreturn-stack-address for
>>> only the zero-false-positive cases that it historically diagnosed.
>>>
>>> Thanks, and sorry for the trouble.
>>>
>>> On Wed, 21 Aug 2019 at 15:07, Matthias Gehre via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
 Author: mgehre
 Date: Wed Aug 21 15:08:59 2019
 New Revision: 369591

 URL: http://llvm.org/viewvc/llvm-project?rev=369591=rev
 Log:
 [LifetimeAnalysis] Support more STL idioms (template forward
 declaration and DependentNameType)

 Summary:
 This fixes inference of gsl::Pointer on std::set::iterator with
 libstdc++ (the typedef for iterator
 on the template is a DependentNameType - we can only put the
 gsl::Pointer attribute
 on the underlaying record after instantiation)

 inference of gsl::Pointer on std::vector::iterator with libc++ (the
 class was forward-declared,
 we added the gsl::Pointer on the canonical decl (the forward decl), and
 later when the
 template was instantiated, there was no attribute on the definition so
 it was not instantiated).

 and a duplicate gsl::Pointer on some class with libstdc++ (we first
 added an attribute to
 a incomplete instantiation, and then another was copied from the
 template definition
 when the instantiation was completed).

 We now add the attributes to all redeclarations to fix thos issues and
 make their usage easier.

 Reviewers: gribozavr

 Subscribers: Szelethus, xazax.hun, cfe-commits

 Tags: #clang

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

 Added:
 cfe/trunk/unittests/Sema/GslOwnerPointerInference.cpp
 Modified:
 cfe/trunk/lib/Sema/SemaAttr.cpp
 cfe/trunk/lib/Sema/SemaDeclAttr.cpp
 cfe/trunk/lib/Sema/SemaInit.cpp
 cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
 cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
 cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer.cpp
 cfe/trunk/unittests/Sema/CMakeLists.txt

 Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
 URL:
 http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=369591=369590=369591=diff

 ==
 --- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
 +++ cfe/trunk/lib/Sema/SemaAttr.cpp Wed Aug 21 15:08:59 2019
 @@ -88,13 +88,11 @@ void Sema::AddMsStructLayoutForRecord(Re
  template 
  static void addGslOwnerPointerAttributeIfNotExisting(ASTContext
 ,
   CXXRecordDecl
 *Record) {
 -  CXXRecordDecl *Canonical = Record->getCanonicalDecl();
 -  if (Canonical->hasAttr() ||
 Canonical->hasAttr())
 +  if (Record->hasAttr() || Record->hasAttr())
  return;

 -  Canonical->addAttr(::new (Context) Attribute(SourceRange{}, Context,
 -   /*DerefType*/ nullptr,
 -   /*Spelling=*/0));
 +  for (Decl *Redecl : Record->redecls())
 +Redecl->addAttr(Attribute::CreateImplicit(Context,
 /*DerefType=*/nullptr));
  }

  void 

[PATCH] D65907: Introduce FileEntryRef and use it when handling includes to report correct dependencies when the FileManager is reused across invocations

2019-08-23 Thread James Nagurne via Phabricator via cfe-commits
JamesNagurne added a comment.

In D65907#1643650 , @arphaman wrote:

> No the windows test failure was different, there were no Deps at all. I'm 
> currently investigating it on a windows VM.
>
> @JamesNagurne I think there's some issue with the working directory, which is 
> not added in your case. Which platform are you running your build/test on? 
> Which cmake options are you using?


I apologize for not giving such information in the first reply. Unfortunately 
this isn't an easy remote reproduction, as our ToolChain and some integral 
changes aren't upstreamed. This is an embedded ARM cross-compiled on Linux. 
Might be able to reproduce with arm-none-none-eabi.
LLVM is built as an external project. Looking at the build system, it looks 
like we have the CMAKE_ARGS:

  -DLLVM_DEFAULT_TARGET_TRIPLE=arm-ti-none-eabi
  -DLLVM_EXTERNAL_CLANG_SOURCE_DIR=${CMAKE_SOURCE_DIR}/llvm-project/clang
  -DLLVM_TARGETS_TO_BUILD=ARM
  -DCMAKE_BUILD_TYPE=Release
  -DCMAKE_CXX_COMPILER=clang++
  -DCMAKE_C_COMPILER=clang
  -DLLVM_USE_LINKER=gold
  -GNinja

Nothing suspicious, except maybe the default triple and ARM target.
Looking at our (not upstream) toolchain file, we do have some RTLibs, 
LibInternal, libcxx, and System include changes, along with a -nostdsysteminc 
to avoid pulling host includes into our cross compiler. However, none of this 
should affect general "#include" behavior, correct?
Another glance at your changes don't seem to affect any target-specific 
handling either, at least directly.

I might have to just bite the bullet and drop into the test with a debugger.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D65907



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


r369822 - [libclang][index][NFC] Fix test for skipping already parsed function bodies

2019-08-23 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Fri Aug 23 15:51:23 2019
New Revision: 369822

URL: http://llvm.org/viewvc/llvm-project?rev=369822=rev
Log:
[libclang][index][NFC] Fix test for skipping already parsed function bodies

Modified:
cfe/trunk/test/Index/skip-parsed-bodies/compile_commands.json

Modified: cfe/trunk/test/Index/skip-parsed-bodies/compile_commands.json
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/skip-parsed-bodies/compile_commands.json?rev=369822=369821=369822=diff
==
--- cfe/trunk/test/Index/skip-parsed-bodies/compile_commands.json (original)
+++ cfe/trunk/test/Index/skip-parsed-bodies/compile_commands.json Fri Aug 23 
15:51:23 2019
@@ -12,7 +12,7 @@
 {
   "directory": ".",
   "command": "/usr/bin/clang++ -fsyntax-only -fno-ms-compatibility 
-fno-delayed-template-parsing t3.cpp -DBLAH",
-  "file": "t2.cpp"
+  "file": "t3.cpp"
 }
 ]
 


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


[PATCH] D66662: [clang-format] [PR43100] clang-format C# support does not add a space between "using" and paren

2019-08-23 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2618
+// using (FileStream fs...
+if (Style.isCSharp() && Left.is(tok::kw_using) && Right.is(tok::l_paren))
+  return true;

`if (Style.isCSharp() && Left.is(tok::kw_using))` would suffice as 
`Right.is(tok::l_paren)` is already checked on Line 2613.



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:169
+TEST_F(FormatTestCSharp, CSharpUsing) {
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filename) { }");
+}

Maybe set `SpaceBeforeParens` to `Always` first in order to really test the new 
behavior?


Repository:
  rC Clang

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

https://reviews.llvm.org/D2



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


[PATCH] D66686: [LifetimeAnalysis] Make it possible to disable the new warnings

2019-08-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun abandoned this revision.
xazax.hun added a comment.

Committed in https://reviews.llvm.org/rG6379e5c8a441 due to it was urgent for 
some users. Will address any comments post-commit.


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

https://reviews.llvm.org/D66686



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


Re: r369591 - [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)

2019-08-23 Thread Richard Smith via cfe-commits
Thank you for the fast turnaround here!

On Fri, 23 Aug 2019 at 15:26, Gábor Horváth via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> I committed this in r369817 to keep things moving. If you have any
> suggestion, complaints let me know and I will do my best to solve it
> post-commit ASAP.
>
> On Fri, 23 Aug 2019 at 14:51, Gábor Horváth  wrote:
>
>> Hi Richard,
>>
>> Sorry for the slow response, unfortunately the compile times are not
>> great on the machine I have access to at the moment.
>> Here is a patch, I'll commit it if you agree with the approach:
>> https://reviews.llvm.org/D66686
>>
>> Basically, the idea is to not run the new warning related code at all
>> when it is turned off, so other warning flags like ReturnStackAddress
>> should never be triggered by the new warnings.
>> In the future, we can come up with something else but I wanted to go for
>> the safe solution given the urgency.
>>
>> Cheers,
>> Gabor
>>
>> On Fri, 23 Aug 2019 at 13:31, Gábor Horváth  wrote:
>>
>>> Hi Richard,
>>>
>>> I'll move these behind a flag today. Moving forward, it would be great
>>> to have a way to dogfood those warnings without blocking you. We do run
>>> them over ~340 open source projects regularly, but clearly that is not
>>> enough :)
>>>
>>> Thanks,
>>> Gabor
>>>
>>> On Fri, 23 Aug 2019 at 13:03, Richard Smith 
>>> wrote:
>>>
 On Thu, 22 Aug 2019 at 13:05, Matthias Gehre via cfe-commits <
 cfe-commits@lists.llvm.org> wrote:

> Hi Diana,
> hi Richard,
>
> thank you for the feedback!
>
> Diana,
> I remember that some gcc version had issues with raw string literals
> inside macros. I'll fix that to use normal
> string literals instead.
>
> Richard,
> We are definitely want the gsl::Pointer-based warnings that are
> enabled by default to be free of any false-positives.
> As you expected, this is showing a problem we have in another part of
> our analysis, and we will fix it before landing
> this PR again.
>

 It looks like this revert wasn't enough to unblock us. We're currently
 unable to release compilers due to the scale of the new enabled-by-default
 diagnostics produced by these warnings, and we're not happy about turning
 off the existing (zero false positives) warning flags here in order to
 unblock our releases, because they're so valuable in catching errors. I'd
 expect others will hit similar issues when upgrading Clang. Even if there
 were no false positives in the new warning, it appears to be undeployable
 as-is because the new warning is behind the same warning flag as an
 existing high-value warning. So I think we need the new warnings to be
 moved behind different warning flags (a subgroup of ReturnStackAddress
 would be OK, but it needs to be independently controllable).

 If this can be done imminently, that would be OK, but otherwise I think
 we should temporarily roll this back until it can be moved to a separate
 warning group.

 Both, sorry for the breakage!
>
> Am Do., 22. Aug. 2019 um 19:47 Uhr schrieb Richard Smith <
> rich...@metafoo.co.uk>:
>
>> Reverted in r369677.
>>
>> On Thu, 22 Aug 2019 at 10:34, Richard Smith 
>> wrote:
>>
>>> Hi Matthias,
>>>
>>> This introduces false positives into -Wreturn-stack-address for an
>>> example such as:
>>>
>>> #include 
>>>
>>> std::vector::iterator downcast_to(std::vector::iterator
>>> value) {
>>>   return *
>>> }
>>>
>>> This breaks an internal build bot for us, so I'm going to revert
>>> this for now (though I expect this isn't the cause of the problem, but 
>>> is
>>> rather exposing a problem elsewhere).
>>>
>>> If we can make the gsl::Pointer diagnostics false-positive-free,
>>> that's great, but otherwise we should use a different warning flag for 
>>> the
>>> warnings that involve these annotations and use -Wreturn-stack-address 
>>> for
>>> only the zero-false-positive cases that it historically diagnosed.
>>>
>>> Thanks, and sorry for the trouble.
>>>
>>> On Wed, 21 Aug 2019 at 15:07, Matthias Gehre via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
 Author: mgehre
 Date: Wed Aug 21 15:08:59 2019
 New Revision: 369591

 URL: http://llvm.org/viewvc/llvm-project?rev=369591=rev
 Log:
 [LifetimeAnalysis] Support more STL idioms (template forward
 declaration and DependentNameType)

 Summary:
 This fixes inference of gsl::Pointer on std::set::iterator with
 libstdc++ (the typedef for iterator
 on the template is a DependentNameType - we can only put the
 gsl::Pointer attribute
 on the underlaying record after instantiation)

 inference of gsl::Pointer on std::vector::iterator with libc++ 

Re: r369591 - [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)

2019-08-23 Thread Gábor Horváth via cfe-commits
I committed this in r369817 to keep things moving. If you have any
suggestion, complaints let me know and I will do my best to solve it
post-commit ASAP.

On Fri, 23 Aug 2019 at 14:51, Gábor Horváth  wrote:

> Hi Richard,
>
> Sorry for the slow response, unfortunately the compile times are not great
> on the machine I have access to at the moment.
> Here is a patch, I'll commit it if you agree with the approach:
> https://reviews.llvm.org/D66686
>
> Basically, the idea is to not run the new warning related code at all when
> it is turned off, so other warning flags like ReturnStackAddress should
> never be triggered by the new warnings.
> In the future, we can come up with something else but I wanted to go for
> the safe solution given the urgency.
>
> Cheers,
> Gabor
>
> On Fri, 23 Aug 2019 at 13:31, Gábor Horváth  wrote:
>
>> Hi Richard,
>>
>> I'll move these behind a flag today. Moving forward, it would be great to
>> have a way to dogfood those warnings without blocking you. We do run them
>> over ~340 open source projects regularly, but clearly that is not enough :)
>>
>> Thanks,
>> Gabor
>>
>> On Fri, 23 Aug 2019 at 13:03, Richard Smith 
>> wrote:
>>
>>> On Thu, 22 Aug 2019 at 13:05, Matthias Gehre via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
 Hi Diana,
 hi Richard,

 thank you for the feedback!

 Diana,
 I remember that some gcc version had issues with raw string literals
 inside macros. I'll fix that to use normal
 string literals instead.

 Richard,
 We are definitely want the gsl::Pointer-based warnings that are enabled
 by default to be free of any false-positives.
 As you expected, this is showing a problem we have in another part of
 our analysis, and we will fix it before landing
 this PR again.

>>>
>>> It looks like this revert wasn't enough to unblock us. We're currently
>>> unable to release compilers due to the scale of the new enabled-by-default
>>> diagnostics produced by these warnings, and we're not happy about turning
>>> off the existing (zero false positives) warning flags here in order to
>>> unblock our releases, because they're so valuable in catching errors. I'd
>>> expect others will hit similar issues when upgrading Clang. Even if there
>>> were no false positives in the new warning, it appears to be undeployable
>>> as-is because the new warning is behind the same warning flag as an
>>> existing high-value warning. So I think we need the new warnings to be
>>> moved behind different warning flags (a subgroup of ReturnStackAddress
>>> would be OK, but it needs to be independently controllable).
>>>
>>> If this can be done imminently, that would be OK, but otherwise I think
>>> we should temporarily roll this back until it can be moved to a separate
>>> warning group.
>>>
>>> Both, sorry for the breakage!

 Am Do., 22. Aug. 2019 um 19:47 Uhr schrieb Richard Smith <
 rich...@metafoo.co.uk>:

> Reverted in r369677.
>
> On Thu, 22 Aug 2019 at 10:34, Richard Smith 
> wrote:
>
>> Hi Matthias,
>>
>> This introduces false positives into -Wreturn-stack-address for an
>> example such as:
>>
>> #include 
>>
>> std::vector::iterator downcast_to(std::vector::iterator
>> value) {
>>   return *
>> }
>>
>> This breaks an internal build bot for us, so I'm going to revert this
>> for now (though I expect this isn't the cause of the problem, but is 
>> rather
>> exposing a problem elsewhere).
>>
>> If we can make the gsl::Pointer diagnostics false-positive-free,
>> that's great, but otherwise we should use a different warning flag for 
>> the
>> warnings that involve these annotations and use -Wreturn-stack-address 
>> for
>> only the zero-false-positive cases that it historically diagnosed.
>>
>> Thanks, and sorry for the trouble.
>>
>> On Wed, 21 Aug 2019 at 15:07, Matthias Gehre via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: mgehre
>>> Date: Wed Aug 21 15:08:59 2019
>>> New Revision: 369591
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=369591=rev
>>> Log:
>>> [LifetimeAnalysis] Support more STL idioms (template forward
>>> declaration and DependentNameType)
>>>
>>> Summary:
>>> This fixes inference of gsl::Pointer on std::set::iterator with
>>> libstdc++ (the typedef for iterator
>>> on the template is a DependentNameType - we can only put the
>>> gsl::Pointer attribute
>>> on the underlaying record after instantiation)
>>>
>>> inference of gsl::Pointer on std::vector::iterator with libc++ (the
>>> class was forward-declared,
>>> we added the gsl::Pointer on the canonical decl (the forward decl),
>>> and later when the
>>> template was instantiated, there was no attribute on the definition
>>> so it was not instantiated).
>>>
>>> and 

r369820 - Fix a test to test what the name suggest.

2019-08-23 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Fri Aug 23 15:26:49 2019
New Revision: 369820

URL: http://llvm.org/viewvc/llvm-project?rev=369820=rev
Log:
Fix a test to test what the name suggest.

Modified:
cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg-disabled.cpp

Modified: cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg-disabled.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg-disabled.cpp?rev=369820=369819=369820=diff
==
--- cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg-disabled.cpp (original)
+++ cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg-disabled.cpp Fri Aug 23 
15:26:49 2019
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wno-dangling -Wreturn-stack-address -verify 
%s
+// RUN: %clang_cc1 -fsyntax-only -Wno-dangling-gsl -Wreturn-stack-address 
-verify %s
 
 struct [[gsl::Owner(int)]] MyIntOwner {
   MyIntOwner();


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


[PATCH] D66364: Diagnose use of _Thread_local as an extension when appropriate

2019-08-23 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

In D66364#1638026 , @aaron.ballman 
wrote:

> @rsmith are you fine with implementing the diagnostic for these keywords 
> piecemeal based on the pattern from this patch, or do you want to see an 
> omnibus patch that adds all of them at once?


I'm fine with doing it piecemeal.




Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:130
+def ext_c11_feature : Extension<
   "%0 is a C11-specific feature">, InGroup;
 

Please consider rewording this to "%0 is a C11 extension" to match what we do 
for C++XY extensions. (This will also start looking a little silly once C20 
adoption starts; features aren't C11-specific if they're also part of C20.)

As a separate change, though :)



Comment at: clang/test/Sema/thread-specifier.c:127-160
+// expected-warning@14 {{_Thread_local is a C11-specific feature}}
+// expected-warning@15 {{_Thread_local is a C11-specific feature}}
+// expected-warning@16 {{_Thread_local is a C11-specific feature}}
+// expected-warning@22 {{_Thread_local is a C11-specific feature}}
+// expected-warning@23 {{_Thread_local is a C11-specific feature}}
+// expected-warning@31 {{_Thread_local is a C11-specific feature}}
+// expected-warning@40 {{_Thread_local is a C11-specific feature}}

Hardcoding line numbers like this makes test maintenance painful. Using a 
different verify prefix seems like the easiest way to handle this:

```
// RUN: %clang_cc1 [...] -D__thread=_Thread_local -std=c++98 
-verify=expected,thread-local
[...]
__thread int t1; // thread-local-warning {{_Thread_local is a C11-specific 
feature}}
```


Repository:
  rC Clang

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

https://reviews.llvm.org/D66364



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


r369817 - [LifetimeAnalysis] Make it possible to disable the new warnings

2019-08-23 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Fri Aug 23 15:21:33 2019
New Revision: 369817

URL: http://llvm.org/viewvc/llvm-project?rev=369817=rev
Log:
[LifetimeAnalysis] Make it possible to disable the new warnings

Added:
cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg-disabled.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaInit.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=369817=369816=369817=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Aug 23 15:21:33 2019
@@ -289,9 +289,11 @@ def OverloadedShiftOpParentheses: DiagGr
 def DanglingElse: DiagGroup<"dangling-else">;
 def DanglingField : DiagGroup<"dangling-field">;
 def DanglingInitializerList : DiagGroup<"dangling-initializer-list">;
+def DanglingGsl : DiagGroup<"dangling-gsl">;
 def ReturnStackAddress : DiagGroup<"return-stack-address">;
 def Dangling : DiagGroup<"dangling", [DanglingField,
   DanglingInitializerList,
+  DanglingGsl,
   ReturnStackAddress]>;
 def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">;
 def ExpansionToDefined : DiagGroup<"expansion-to-defined">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=369817=369816=369817=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Aug 23 15:21:33 
2019
@@ -8121,7 +8121,7 @@ def warn_dangling_member : Warning<
 def warn_dangling_lifetime_pointer_member : Warning<
   "initializing pointer member %0 to point to a temporary object "
   "whose lifetime is shorter than the lifetime of the constructed object">,
-  InGroup;
+  InGroup;
 def note_lifetime_extending_member_declared_here : Note<
   "%select{%select{reference|'std::initializer_list'}0 member|"
   "member with %select{reference|'std::initializer_list'}0 subobject}1 "
@@ -8143,7 +8143,7 @@ def warn_new_dangling_reference : Warnin
 def warn_dangling_lifetime_pointer : Warning<
   "object backing the pointer "
   "will be destroyed at the end of the full-expression">,
-  InGroup;
+  InGroup;
 def warn_new_dangling_initializer_list : Warning<
   "array backing "
   "%select{initializer list subobject of the allocated object|"

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=369817=369816=369817=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Aug 23 15:21:33 2019
@@ -6553,11 +6553,13 @@ static bool pathContainsInit(IndirectLoc
 
 static void visitLocalsRetainedByInitializer(IndirectLocalPath ,
  Expr *Init, LocalVisitor Visit,
- bool RevisitSubinits);
+ bool RevisitSubinits,
+ bool EnableLifetimeWarnings);
 
 static void visitLocalsRetainedByReferenceBinding(IndirectLocalPath ,
   Expr *Init, ReferenceKind RK,
-  LocalVisitor Visit);
+  LocalVisitor Visit,
+  bool EnableLifetimeWarnings);
 
 template  static bool isRecordWithAttr(QualType Type) {
   if (auto *RD = Type->getAsCXXRecordDecl())
@@ -6646,9 +6648,9 @@ static void handleGslAnnotatedTypes(Indi
 Path.push_back({IndirectLocalPathEntry::GslPointerInit, Arg, D});
 if (Arg->isGLValue())
   visitLocalsRetainedByReferenceBinding(Path, Arg, RK_ReferenceBinding,
-Visit);
+Visit, true);
 else
-  visitLocalsRetainedByInitializer(Path, Arg, Visit, true);
+  visitLocalsRetainedByInitializer(Path, Arg, Visit, true, true);
 Path.pop_back();
   };
 
@@ -6723,9 +6725,9 @@ static void visitLifetimeBoundArguments(
 Path.push_back({IndirectLocalPathEntry::LifetimeBoundCall, Arg, D});
 if (Arg->isGLValue())
   visitLocalsRetainedByReferenceBinding(Path, Arg, RK_ReferenceBinding,
-Visit);
+Visit, false);
 else
-  visitLocalsRetainedByInitializer(Path, Arg, Visit, true);
+  

[PATCH] D66686: [LifetimeAnalysis] Make it possible to disable the new warnings

2019-08-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 216964.
xazax.hun added a comment.

- Added a test.


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

https://reviews.llvm.org/D66686

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaInit.cpp
  clang/test/Sema/warn-lifetime-analysis-nocfg-disabled.cpp

Index: clang/test/Sema/warn-lifetime-analysis-nocfg-disabled.cpp
===
--- /dev/null
+++ clang/test/Sema/warn-lifetime-analysis-nocfg-disabled.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only -Wno-dangling -Wreturn-stack-address -verify %s
+
+struct [[gsl::Owner(int)]] MyIntOwner {
+  MyIntOwner();
+  int *();
+};
+
+struct [[gsl::Pointer(int)]] MyIntPointer {
+  MyIntPointer(int *p = nullptr);
+  MyIntPointer(const MyIntOwner &);
+  int *();
+  MyIntOwner toOwner();
+};
+
+int () {
+  int i;
+  return i; // expected-warning {{reference to stack memory associated with local variable 'i' returned}}
+}
+
+MyIntPointer g() {
+  MyIntOwner o;
+  return o; // No warning, it is disabled.
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6553,11 +6553,13 @@
 
 static void visitLocalsRetainedByInitializer(IndirectLocalPath ,
  Expr *Init, LocalVisitor Visit,
- bool RevisitSubinits);
+ bool RevisitSubinits,
+ bool EnableLifetimeWarnings);
 
 static void visitLocalsRetainedByReferenceBinding(IndirectLocalPath ,
   Expr *Init, ReferenceKind RK,
-  LocalVisitor Visit);
+  LocalVisitor Visit,
+  bool EnableLifetimeWarnings);
 
 template  static bool isRecordWithAttr(QualType Type) {
   if (auto *RD = Type->getAsCXXRecordDecl())
@@ -6646,9 +6648,9 @@
 Path.push_back({IndirectLocalPathEntry::GslPointerInit, Arg, D});
 if (Arg->isGLValue())
   visitLocalsRetainedByReferenceBinding(Path, Arg, RK_ReferenceBinding,
-Visit);
+Visit, true);
 else
-  visitLocalsRetainedByInitializer(Path, Arg, Visit, true);
+  visitLocalsRetainedByInitializer(Path, Arg, Visit, true, true);
 Path.pop_back();
   };
 
@@ -6723,9 +6725,9 @@
 Path.push_back({IndirectLocalPathEntry::LifetimeBoundCall, Arg, D});
 if (Arg->isGLValue())
   visitLocalsRetainedByReferenceBinding(Path, Arg, RK_ReferenceBinding,
-Visit);
+Visit, false);
 else
-  visitLocalsRetainedByInitializer(Path, Arg, Visit, true);
+  visitLocalsRetainedByInitializer(Path, Arg, Visit, true, false);
 Path.pop_back();
   };
 
@@ -6744,7 +6746,8 @@
 /// glvalue expression \c Init.
 static void visitLocalsRetainedByReferenceBinding(IndirectLocalPath ,
   Expr *Init, ReferenceKind RK,
-  LocalVisitor Visit) {
+  LocalVisitor Visit,
+  bool EnableLifetimeWarnings) {
   RevertToOldSizeRAII RAII(Path);
 
   // Walk past any constructs which we can lifetime-extend across.
@@ -6781,7 +6784,8 @@
   else
 // We can't lifetime extend through this but we might still find some
 // retained temporaries.
-return visitLocalsRetainedByInitializer(Path, Init, Visit, true);
+return visitLocalsRetainedByInitializer(Path, Init, Visit, true,
+EnableLifetimeWarnings);
 }
 
 // Step into CXXDefaultInitExprs so we can diagnose cases where a
@@ -6796,11 +6800,12 @@
   if (auto *MTE = dyn_cast(Init)) {
 if (Visit(Path, Local(MTE), RK))
   visitLocalsRetainedByInitializer(Path, MTE->GetTemporaryExpr(), Visit,
-   true);
+   true, EnableLifetimeWarnings);
   }
 
   if (isa(Init)) {
-handleGslAnnotatedTypes(Path, Init, Visit);
+if (EnableLifetimeWarnings)
+  handleGslAnnotatedTypes(Path, Init, Visit);
 return visitLifetimeBoundArguments(Path, Init, Visit);
   }
 
@@ -6821,7 +6826,8 @@
   } else if (VD->getInit() && !isVarOnPath(Path, VD)) {
 Path.push_back({IndirectLocalPathEntry::VarInit, DRE, VD});
 visitLocalsRetainedByReferenceBinding(Path, VD->getInit(),
-  RK_ReferenceBinding, Visit);
+

Re: r369591 - [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)

2019-08-23 Thread Gábor Horváth via cfe-commits
Hi Richard,

Sorry for the slow response, unfortunately the compile times are not great
on the machine I have access to at the moment.
Here is a patch, I'll commit it if you agree with the approach:
https://reviews.llvm.org/D66686

Basically, the idea is to not run the new warning related code at all when
it is turned off, so other warning flags like ReturnStackAddress should
never be triggered by the new warnings.
In the future, we can come up with something else but I wanted to go for
the safe solution given the urgency.

Cheers,
Gabor

On Fri, 23 Aug 2019 at 13:31, Gábor Horváth  wrote:

> Hi Richard,
>
> I'll move these behind a flag today. Moving forward, it would be great to
> have a way to dogfood those warnings without blocking you. We do run them
> over ~340 open source projects regularly, but clearly that is not enough :)
>
> Thanks,
> Gabor
>
> On Fri, 23 Aug 2019 at 13:03, Richard Smith  wrote:
>
>> On Thu, 22 Aug 2019 at 13:05, Matthias Gehre via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Hi Diana,
>>> hi Richard,
>>>
>>> thank you for the feedback!
>>>
>>> Diana,
>>> I remember that some gcc version had issues with raw string literals
>>> inside macros. I'll fix that to use normal
>>> string literals instead.
>>>
>>> Richard,
>>> We are definitely want the gsl::Pointer-based warnings that are enabled
>>> by default to be free of any false-positives.
>>> As you expected, this is showing a problem we have in another part of
>>> our analysis, and we will fix it before landing
>>> this PR again.
>>>
>>
>> It looks like this revert wasn't enough to unblock us. We're currently
>> unable to release compilers due to the scale of the new enabled-by-default
>> diagnostics produced by these warnings, and we're not happy about turning
>> off the existing (zero false positives) warning flags here in order to
>> unblock our releases, because they're so valuable in catching errors. I'd
>> expect others will hit similar issues when upgrading Clang. Even if there
>> were no false positives in the new warning, it appears to be undeployable
>> as-is because the new warning is behind the same warning flag as an
>> existing high-value warning. So I think we need the new warnings to be
>> moved behind different warning flags (a subgroup of ReturnStackAddress
>> would be OK, but it needs to be independently controllable).
>>
>> If this can be done imminently, that would be OK, but otherwise I think
>> we should temporarily roll this back until it can be moved to a separate
>> warning group.
>>
>> Both, sorry for the breakage!
>>>
>>> Am Do., 22. Aug. 2019 um 19:47 Uhr schrieb Richard Smith <
>>> rich...@metafoo.co.uk>:
>>>
 Reverted in r369677.

 On Thu, 22 Aug 2019 at 10:34, Richard Smith 
 wrote:

> Hi Matthias,
>
> This introduces false positives into -Wreturn-stack-address for an
> example such as:
>
> #include 
>
> std::vector::iterator downcast_to(std::vector::iterator
> value) {
>   return *
> }
>
> This breaks an internal build bot for us, so I'm going to revert this
> for now (though I expect this isn't the cause of the problem, but is 
> rather
> exposing a problem elsewhere).
>
> If we can make the gsl::Pointer diagnostics false-positive-free,
> that's great, but otherwise we should use a different warning flag for the
> warnings that involve these annotations and use -Wreturn-stack-address for
> only the zero-false-positive cases that it historically diagnosed.
>
> Thanks, and sorry for the trouble.
>
> On Wed, 21 Aug 2019 at 15:07, Matthias Gehre via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: mgehre
>> Date: Wed Aug 21 15:08:59 2019
>> New Revision: 369591
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=369591=rev
>> Log:
>> [LifetimeAnalysis] Support more STL idioms (template forward
>> declaration and DependentNameType)
>>
>> Summary:
>> This fixes inference of gsl::Pointer on std::set::iterator with
>> libstdc++ (the typedef for iterator
>> on the template is a DependentNameType - we can only put the
>> gsl::Pointer attribute
>> on the underlaying record after instantiation)
>>
>> inference of gsl::Pointer on std::vector::iterator with libc++ (the
>> class was forward-declared,
>> we added the gsl::Pointer on the canonical decl (the forward decl),
>> and later when the
>> template was instantiated, there was no attribute on the definition
>> so it was not instantiated).
>>
>> and a duplicate gsl::Pointer on some class with libstdc++ (we first
>> added an attribute to
>> a incomplete instantiation, and then another was copied from the
>> template definition
>> when the instantiation was completed).
>>
>> We now add the attributes to all redeclarations to fix thos issues
>> and make their usage easier.
>>

[PATCH] D66686: [LifetimeAnalysis] Make it possible to disable the new warnings

2019-08-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 216962.
xazax.hun added a comment.

- Add the actual diff.


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

https://reviews.llvm.org/D66686

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaInit.cpp

Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6553,11 +6553,13 @@
 
 static void visitLocalsRetainedByInitializer(IndirectLocalPath ,
  Expr *Init, LocalVisitor Visit,
- bool RevisitSubinits);
+ bool RevisitSubinits,
+ bool EnableLifetimeWarnings);
 
 static void visitLocalsRetainedByReferenceBinding(IndirectLocalPath ,
   Expr *Init, ReferenceKind RK,
-  LocalVisitor Visit);
+  LocalVisitor Visit,
+  bool EnableLifetimeWarnings);
 
 template  static bool isRecordWithAttr(QualType Type) {
   if (auto *RD = Type->getAsCXXRecordDecl())
@@ -6646,9 +6648,9 @@
 Path.push_back({IndirectLocalPathEntry::GslPointerInit, Arg, D});
 if (Arg->isGLValue())
   visitLocalsRetainedByReferenceBinding(Path, Arg, RK_ReferenceBinding,
-Visit);
+Visit, true);
 else
-  visitLocalsRetainedByInitializer(Path, Arg, Visit, true);
+  visitLocalsRetainedByInitializer(Path, Arg, Visit, true, true);
 Path.pop_back();
   };
 
@@ -6723,9 +6725,9 @@
 Path.push_back({IndirectLocalPathEntry::LifetimeBoundCall, Arg, D});
 if (Arg->isGLValue())
   visitLocalsRetainedByReferenceBinding(Path, Arg, RK_ReferenceBinding,
-Visit);
+Visit, false);
 else
-  visitLocalsRetainedByInitializer(Path, Arg, Visit, true);
+  visitLocalsRetainedByInitializer(Path, Arg, Visit, true, false);
 Path.pop_back();
   };
 
@@ -6744,7 +6746,8 @@
 /// glvalue expression \c Init.
 static void visitLocalsRetainedByReferenceBinding(IndirectLocalPath ,
   Expr *Init, ReferenceKind RK,
-  LocalVisitor Visit) {
+  LocalVisitor Visit,
+  bool EnableLifetimeWarnings) {
   RevertToOldSizeRAII RAII(Path);
 
   // Walk past any constructs which we can lifetime-extend across.
@@ -6781,7 +6784,8 @@
   else
 // We can't lifetime extend through this but we might still find some
 // retained temporaries.
-return visitLocalsRetainedByInitializer(Path, Init, Visit, true);
+return visitLocalsRetainedByInitializer(Path, Init, Visit, true,
+EnableLifetimeWarnings);
 }
 
 // Step into CXXDefaultInitExprs so we can diagnose cases where a
@@ -6796,11 +6800,12 @@
   if (auto *MTE = dyn_cast(Init)) {
 if (Visit(Path, Local(MTE), RK))
   visitLocalsRetainedByInitializer(Path, MTE->GetTemporaryExpr(), Visit,
-   true);
+   true, EnableLifetimeWarnings);
   }
 
   if (isa(Init)) {
-handleGslAnnotatedTypes(Path, Init, Visit);
+if (EnableLifetimeWarnings)
+  handleGslAnnotatedTypes(Path, Init, Visit);
 return visitLifetimeBoundArguments(Path, Init, Visit);
   }
 
@@ -6821,7 +6826,8 @@
   } else if (VD->getInit() && !isVarOnPath(Path, VD)) {
 Path.push_back({IndirectLocalPathEntry::VarInit, DRE, VD});
 visitLocalsRetainedByReferenceBinding(Path, VD->getInit(),
-  RK_ReferenceBinding, Visit);
+  RK_ReferenceBinding, Visit,
+  EnableLifetimeWarnings);
   }
 }
 break;
@@ -6833,13 +6839,15 @@
 // handling all sorts of rvalues passed to a unary operator.
 const UnaryOperator *U = cast(Init);
 if (U->getOpcode() == UO_Deref)
-  visitLocalsRetainedByInitializer(Path, U->getSubExpr(), Visit, true);
+  visitLocalsRetainedByInitializer(Path, U->getSubExpr(), Visit, true,
+   EnableLifetimeWarnings);
 break;
   }
 
   case Stmt::OMPArraySectionExprClass: {
-visitLocalsRetainedByInitializer(
-Path, cast(Init)->getBase(), Visit, true);
+visitLocalsRetainedByInitializer(Path,
+ cast(Init)->getBase(),
+

[PATCH] D66686: [LifetimeAnalysis] Make it possible to disable the new warnings

2019-08-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun created this revision.
xazax.hun added reviewers: rsmith, mgehre.
xazax.hun added a project: clang.
Herald added subscribers: llvm-commits, Szelethus, Charusso, gamesh411, jfb, 
dkrupp, rnkovacs, hiraditya, javed.absar.
Herald added a project: LLVM.

This patch introduces quite a bit of plumbing, but I took this approach because 
it seems to be the safest, do not run any related code at all when the warnings 
are turned off.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66686

Files:
  llvm/lib/Target/AArch64/AArch64InstrFormats.td
  llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/load-addressing-modes.mir
  llvm/test/CodeGen/AArch64/GlobalISel/store-addressing-modes.mir
  llvm/test/CodeGen/AArch64/arm64-fastisel-gep-promote-before-add.ll

Index: llvm/test/CodeGen/AArch64/arm64-fastisel-gep-promote-before-add.ll
===
--- llvm/test/CodeGen/AArch64/arm64-fastisel-gep-promote-before-add.ll
+++ llvm/test/CodeGen/AArch64/arm64-fastisel-gep-promote-before-add.ll
@@ -1,6 +1,6 @@
 ; fastisel should not fold add with non-pointer bitwidth
 ; sext(a) + sext(b) != sext(a + b)
-; RUN: llc -mtriple=arm64-apple-darwin %s -O0 -o - | FileCheck %s
+; RUN: llc -fast-isel -mtriple=arm64-apple-darwin %s -O0 -o - | FileCheck %s
 
 define zeroext i8 @gep_promotion(i8* %ptr) nounwind uwtable ssp {
 entry:
Index: llvm/test/CodeGen/AArch64/GlobalISel/store-addressing-modes.mir
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/GlobalISel/store-addressing-modes.mir
@@ -0,0 +1,168 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -mtriple=aarch64-unknown-unknown -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s
+
+--- |
+  define void @strxrox(i64* %addr) { ret void }
+  define void @strdrox(i64* %addr) { ret void }
+  define void @strwrox(i64* %addr) { ret void }
+  define void @strsrox(i64* %addr) { ret void }
+  define void @strhrox(i64* %addr) { ret void }
+  define void @strqrox(i64* %addr) { ret void }
+  define void @shl(i64* %addr) { ret void }
+...
+
+---
+name:strxrox
+alignment:   2
+legalized:   true
+regBankSelected: true
+tracksRegLiveness: true
+machineFunctionInfo: {}
+body: |
+  bb.0:
+liveins: $x0, $x1, $x2
+; CHECK-LABEL: name: strxrox
+; CHECK: liveins: $x0, $x1, $x2
+; CHECK: [[COPY:%[0-9]+]]:gpr64sp = COPY $x0
+; CHECK: [[COPY1:%[0-9]+]]:gpr64 = COPY $x1
+; CHECK: [[COPY2:%[0-9]+]]:gpr64 = COPY $x2
+; CHECK: STRXroX [[COPY2]], [[COPY]], [[COPY1]], 0, 0 :: (store 8 into %ir.addr)
+%0:gpr(p0) = COPY $x0
+%1:gpr(s64) = COPY $x1
+%ptr:gpr(p0) = G_GEP %0, %1
+%3:gpr(s64) = COPY $x2
+G_STORE %3, %ptr :: (store 8 into %ir.addr)
+...
+---
+name:strdrox
+alignment:   2
+legalized:   true
+regBankSelected: true
+tracksRegLiveness: true
+machineFunctionInfo: {}
+body: |
+  bb.0:
+liveins: $x0, $x1, $d2
+; CHECK-LABEL: name: strdrox
+; CHECK: liveins: $x0, $x1, $d2
+; CHECK: [[COPY:%[0-9]+]]:gpr64sp = COPY $x0
+; CHECK: [[COPY1:%[0-9]+]]:gpr64 = COPY $x1
+; CHECK: [[COPY2:%[0-9]+]]:fpr64 = COPY $d2
+; CHECK: STRDroX [[COPY2]], [[COPY]], [[COPY1]], 0, 0 :: (store 8 into %ir.addr)
+%0:gpr(p0) = COPY $x0
+%1:gpr(s64) = COPY $x1
+%ptr:gpr(p0) = G_GEP %0, %1
+%3:fpr(s64) = COPY $d2
+G_STORE %3, %ptr :: (store 8 into %ir.addr)
+...
+---
+name:strwrox
+alignment:   2
+legalized:   true
+regBankSelected: true
+tracksRegLiveness: true
+machineFunctionInfo: {}
+body: |
+  bb.0:
+liveins: $x0, $x1, $w2
+; CHECK-LABEL: name: strwrox
+; CHECK: liveins: $x0, $x1, $w2
+; CHECK: [[COPY:%[0-9]+]]:gpr64sp = COPY $x0
+; CHECK: [[COPY1:%[0-9]+]]:gpr64 = COPY $x1
+; CHECK: [[COPY2:%[0-9]+]]:gpr32 = COPY $w2
+; CHECK: STRWroX [[COPY2]], [[COPY]], [[COPY1]], 0, 0 :: (store 4 into %ir.addr)
+%0:gpr(p0) = COPY $x0
+%1:gpr(s64) = COPY $x1
+%ptr:gpr(p0) = G_GEP %0, %1
+%3:gpr(s32) = COPY $w2
+G_STORE %3, %ptr :: (store 4 into %ir.addr)
+...
+---
+name:strsrox
+alignment:   2
+legalized:   true
+regBankSelected: true
+tracksRegLiveness: true
+machineFunctionInfo: {}
+body: |
+  bb.0:
+liveins: $x0, $x1, $s2
+; CHECK-LABEL: name: strsrox
+; CHECK: liveins: $x0, $x1, $s2
+; CHECK: [[COPY:%[0-9]+]]:gpr64sp = COPY $x0
+; CHECK: [[COPY1:%[0-9]+]]:gpr64 = COPY $x1
+; CHECK: [[COPY2:%[0-9]+]]:fpr32 = COPY $s2
+; CHECK: STRSroX [[COPY2]], [[COPY]], [[COPY1]], 0, 0 :: (store 4 into %ir.addr)
+%0:gpr(p0) = COPY $x0
+%1:gpr(s64) = COPY $x1
+%ptr:gpr(p0) = G_GEP %0, %1
+%3:fpr(s32) = COPY $s2
+G_STORE %3, %ptr :: (store 4 into %ir.addr)
+...
+---
+name:strhrox
+alignment:  

[PATCH] D66681: [clang-doc] Bump BitcodeWriter max line number to 32U

2019-08-23 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369811: [clang-doc] Bump BitcodeWriter max line number to 
32U (authored by juliehockett, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66681?vs=216942=216952#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66681

Files:
  clang-tools-extra/trunk/clang-doc/BitcodeWriter.h


Index: clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
===
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
@@ -40,7 +40,7 @@
   static constexpr unsigned IntSize = 16U;
   static constexpr unsigned StringLengthSize = 16U;
   static constexpr unsigned FilenameLengthSize = 16U;
-  static constexpr unsigned LineNumberSize = 16U;
+  static constexpr unsigned LineNumberSize = 32U;
   static constexpr unsigned ReferenceTypeSize = 8U;
   static constexpr unsigned USRLengthSize = 6U;
   static constexpr unsigned USRBitLengthSize = 8U;


Index: clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
===
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
@@ -40,7 +40,7 @@
   static constexpr unsigned IntSize = 16U;
   static constexpr unsigned StringLengthSize = 16U;
   static constexpr unsigned FilenameLengthSize = 16U;
-  static constexpr unsigned LineNumberSize = 16U;
+  static constexpr unsigned LineNumberSize = 32U;
   static constexpr unsigned ReferenceTypeSize = 8U;
   static constexpr unsigned USRLengthSize = 6U;
   static constexpr unsigned USRBitLengthSize = 8U;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r369811 - [clang-doc] Bump BitcodeWriter max line number to 32U

2019-08-23 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Fri Aug 23 14:14:05 2019
New Revision: 369811

URL: http://llvm.org/viewvc/llvm-project?rev=369811=rev
Log:
[clang-doc] Bump BitcodeWriter max line number to 32U

PR43039 reports hitting the assert on a very large file, so bumping this
to allow for larger files.

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

Modified:
clang-tools-extra/trunk/clang-doc/BitcodeWriter.h

Modified: clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.h?rev=369811=369810=369811=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.h (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.h Fri Aug 23 14:14:05 2019
@@ -40,7 +40,7 @@ struct BitCodeConstants {
   static constexpr unsigned IntSize = 16U;
   static constexpr unsigned StringLengthSize = 16U;
   static constexpr unsigned FilenameLengthSize = 16U;
-  static constexpr unsigned LineNumberSize = 16U;
+  static constexpr unsigned LineNumberSize = 32U;
   static constexpr unsigned ReferenceTypeSize = 8U;
   static constexpr unsigned USRLengthSize = 6U;
   static constexpr unsigned USRBitLengthSize = 8U;


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


[PATCH] D66681: [clang-doc] Bump BitcodeWriter max line number to 32U

2019-08-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM (small nit, people usually use PRXXX rather than bXXX to refer to issues)


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

https://reviews.llvm.org/D66681



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


[PATCH] D65907: Introduce FileEntryRef and use it when handling includes to report correct dependencies when the FileManager is reused across invocations

2019-08-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

In D65907#1643364 , @JamesNagurne 
wrote:

> @arphaman you disabled this test on Windows, but did not specify exactly how 
> it fails.
>  My team works on an embedded ARM compiler (most similar to arm-none-eabi), 
> and we're now seeing failures from DependencyScannerTest. I can't find a 
> buildbot failure for this test so I can't cross-reference to see if we have 
> the same issue.
>
> Does this failure look similar to what you saw on Windows, or could it be an 
> option we're adding as part of the Compilation setup?
>
>   [ RUN  ] DependencyScanner.ScanDepsReuseFilemanager
>   .../clang/unittests/Tooling/DependencyScannerTest.cpp:100: Failure
> Expected: Deps[1]
> Which is: "symlink.h"
>   To be equal to: "/root/symlink.h"
>   .../clang/unittests/Tooling/DependencyScannerTest.cpp:101: Failure
> Expected: Deps[2]
> Which is: "header.h"
>   To be equal to: "/root/header.h"
>   .../clang/unittests/Tooling/DependencyScannerTest.cpp:113: Failure
> Expected: Deps[1]
> Which is: "symlink.h"
>   To be equal to: "/root/symlink.h"
>   .../clang/unittests/Tooling/DependencyScannerTest.cpp:114: Failure
> Expected: Deps[2]
> Which is: "header.h"
>   To be equal to: "/root/header.h"
>   [  FAILED  ] DependencyScanner.ScanDepsReuseFilemanager (5 ms)


No the windows test failure was different, there were no Deps at all. I'm 
currently investigating it on a windows VM.

@JamesNagurne I think there's some issue with the working directory, which is 
not added in your case. Which platform are you running your build/test on? 
Which cmake options are you using?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D65907



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


[PATCH] D66681: [clang-doc] Bump BitcodeWriter max line number to 32U

2019-08-23 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added a reviewer: phosek.
juliehockett added a project: clang-tools-extra.

b43039 reports hitting the assert on a very large file, so bumping this to 
allow for larger files.


https://reviews.llvm.org/D66681

Files:
  clang-tools-extra/clang-doc/BitcodeWriter.h


Index: clang-tools-extra/clang-doc/BitcodeWriter.h
===
--- clang-tools-extra/clang-doc/BitcodeWriter.h
+++ clang-tools-extra/clang-doc/BitcodeWriter.h
@@ -40,7 +40,7 @@
   static constexpr unsigned IntSize = 16U;
   static constexpr unsigned StringLengthSize = 16U;
   static constexpr unsigned FilenameLengthSize = 16U;
-  static constexpr unsigned LineNumberSize = 16U;
+  static constexpr unsigned LineNumberSize = 32U;
   static constexpr unsigned ReferenceTypeSize = 8U;
   static constexpr unsigned USRLengthSize = 6U;
   static constexpr unsigned USRBitLengthSize = 8U;


Index: clang-tools-extra/clang-doc/BitcodeWriter.h
===
--- clang-tools-extra/clang-doc/BitcodeWriter.h
+++ clang-tools-extra/clang-doc/BitcodeWriter.h
@@ -40,7 +40,7 @@
   static constexpr unsigned IntSize = 16U;
   static constexpr unsigned StringLengthSize = 16U;
   static constexpr unsigned FilenameLengthSize = 16U;
-  static constexpr unsigned LineNumberSize = 16U;
+  static constexpr unsigned LineNumberSize = 32U;
   static constexpr unsigned ReferenceTypeSize = 8U;
   static constexpr unsigned USRLengthSize = 6U;
   static constexpr unsigned USRBitLengthSize = 8U;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r369591 - [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)

2019-08-23 Thread Gábor Horváth via cfe-commits
Hi Richard,

I'll move these behind a flag today. Moving forward, it would be great to
have a way to dogfood those warnings without blocking you. We do run them
over ~340 open source projects regularly, but clearly that is not enough :)

Thanks,
Gabor

On Fri, 23 Aug 2019 at 13:03, Richard Smith  wrote:

> On Thu, 22 Aug 2019 at 13:05, Matthias Gehre via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Hi Diana,
>> hi Richard,
>>
>> thank you for the feedback!
>>
>> Diana,
>> I remember that some gcc version had issues with raw string literals
>> inside macros. I'll fix that to use normal
>> string literals instead.
>>
>> Richard,
>> We are definitely want the gsl::Pointer-based warnings that are enabled
>> by default to be free of any false-positives.
>> As you expected, this is showing a problem we have in another part of our
>> analysis, and we will fix it before landing
>> this PR again.
>>
>
> It looks like this revert wasn't enough to unblock us. We're currently
> unable to release compilers due to the scale of the new enabled-by-default
> diagnostics produced by these warnings, and we're not happy about turning
> off the existing (zero false positives) warning flags here in order to
> unblock our releases, because they're so valuable in catching errors. I'd
> expect others will hit similar issues when upgrading Clang. Even if there
> were no false positives in the new warning, it appears to be undeployable
> as-is because the new warning is behind the same warning flag as an
> existing high-value warning. So I think we need the new warnings to be
> moved behind different warning flags (a subgroup of ReturnStackAddress
> would be OK, but it needs to be independently controllable).
>
> If this can be done imminently, that would be OK, but otherwise I think we
> should temporarily roll this back until it can be moved to a separate
> warning group.
>
> Both, sorry for the breakage!
>>
>> Am Do., 22. Aug. 2019 um 19:47 Uhr schrieb Richard Smith <
>> rich...@metafoo.co.uk>:
>>
>>> Reverted in r369677.
>>>
>>> On Thu, 22 Aug 2019 at 10:34, Richard Smith 
>>> wrote:
>>>
 Hi Matthias,

 This introduces false positives into -Wreturn-stack-address for an
 example such as:

 #include 

 std::vector::iterator downcast_to(std::vector::iterator
 value) {
   return *
 }

 This breaks an internal build bot for us, so I'm going to revert this
 for now (though I expect this isn't the cause of the problem, but is rather
 exposing a problem elsewhere).

 If we can make the gsl::Pointer diagnostics false-positive-free, that's
 great, but otherwise we should use a different warning flag for the
 warnings that involve these annotations and use -Wreturn-stack-address for
 only the zero-false-positive cases that it historically diagnosed.

 Thanks, and sorry for the trouble.

 On Wed, 21 Aug 2019 at 15:07, Matthias Gehre via cfe-commits <
 cfe-commits@lists.llvm.org> wrote:

> Author: mgehre
> Date: Wed Aug 21 15:08:59 2019
> New Revision: 369591
>
> URL: http://llvm.org/viewvc/llvm-project?rev=369591=rev
> Log:
> [LifetimeAnalysis] Support more STL idioms (template forward
> declaration and DependentNameType)
>
> Summary:
> This fixes inference of gsl::Pointer on std::set::iterator with
> libstdc++ (the typedef for iterator
> on the template is a DependentNameType - we can only put the
> gsl::Pointer attribute
> on the underlaying record after instantiation)
>
> inference of gsl::Pointer on std::vector::iterator with libc++ (the
> class was forward-declared,
> we added the gsl::Pointer on the canonical decl (the forward decl),
> and later when the
> template was instantiated, there was no attribute on the definition so
> it was not instantiated).
>
> and a duplicate gsl::Pointer on some class with libstdc++ (we first
> added an attribute to
> a incomplete instantiation, and then another was copied from the
> template definition
> when the instantiation was completed).
>
> We now add the attributes to all redeclarations to fix thos issues and
> make their usage easier.
>
> Reviewers: gribozavr
>
> Subscribers: Szelethus, xazax.hun, cfe-commits
>
> Tags: #clang
>
> Differential Revision: https://reviews.llvm.org/D66179
>
> Added:
> cfe/trunk/unittests/Sema/GslOwnerPointerInference.cpp
> Modified:
> cfe/trunk/lib/Sema/SemaAttr.cpp
> cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> cfe/trunk/lib/Sema/SemaInit.cpp
> cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
> cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
> cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer.cpp
> cfe/trunk/unittests/Sema/CMakeLists.txt
>
> Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
> URL:
> 

[PATCH] D66486: [LifetimeAnalysis] Detect more cases when the address of a local variable escapes

2019-08-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Sounds good! Let's do that :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66486



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


[PATCH] D66673: [OPENMP][NVPTX]Fix critical region codegen.

2019-08-23 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 216934.
ABataev added a comment.

Fix the test


Repository:
  rC Clang

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

https://reviews.llvm.org/D66673

Files:
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  test/OpenMP/nvptx_parallel_codegen.cpp


Index: test/OpenMP/nvptx_parallel_codegen.cpp
===
--- test/OpenMP/nvptx_parallel_codegen.cpp
+++ test/OpenMP/nvptx_parallel_codegen.cpp
@@ -343,6 +343,7 @@
 
 // CHECK-LABEL: define internal void @{{.+}}(i32* noalias %{{.+}}, i32* 
noalias %{{.+}}, i32* dereferenceable{{.*}})
 // CHECK:  [[CC:%.+]] = alloca i32,
+// CHECK:  [[MASK:%.+]] = call i32 @__kmpc_warp_active_thread_mask()
 // CHECK:  [[TID:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
 // CHECK:  [[NUM_THREADS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK:  store i32 0, i32* [[CC]],
@@ -362,7 +363,7 @@
 // CHECK:  store i32
 // CHECK:  call void @__kmpc_end_critical(
 
-// CHECK:  call void @__kmpc_barrier(%struct.ident_t* @{{.+}}, i32 %{{.+}})
+// CHECK:  call void @__kmpc_syncwarp(i32 [[MASK]])
 // CHECK:  [[NEW_CC_VAL:%.+]] = add nsw i32 [[CC_VAL]], 1
 // CHECK:  store i32 [[NEW_CC_VAL]], i32* [[CC]],
 // CHECK:  br label
Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
===
--- lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -107,6 +107,10 @@
   /// Call to void __kmpc_barrier_simple_spmd(ident_t *loc, kmp_int32
   /// global_tid);
   OMPRTL__kmpc_barrier_simple_spmd,
+  /// Call to int32_t __kmpc_warp_active_thread_mask(void);
+  OMPRTL_NVPTX__kmpc_warp_active_thread_mask,
+  /// Call to void __kmpc_syncwarp(int32_t Mask);
+  OMPRTL_NVPTX__kmpc_syncwarp,
 };
 
 /// Pre(post)-action for different OpenMP constructs specialized for NVPTX.
@@ -1794,6 +1798,20 @@
 ->addFnAttr(llvm::Attribute::Convergent);
 break;
   }
+  case OMPRTL_NVPTX__kmpc_warp_active_thread_mask: {
+// Build int32_t __kmpc_warp_active_thread_mask(void);
+auto *FnTy =
+llvm::FunctionType::get(CGM.Int32Ty, llvm::None, /*isVarArg=*/false);
+RTLFn = CGM.CreateRuntimeFunction(FnTy, "__kmpc_warp_active_thread_mask");
+break;
+  }
+  case OMPRTL_NVPTX__kmpc_syncwarp: {
+// Build void __kmpc_syncwarp(kmp_int32 Mask);
+auto *FnTy =
+llvm::FunctionType::get(CGM.VoidTy, CGM.Int32Ty, /*isVarArg=*/false);
+RTLFn = CGM.CreateRuntimeFunction(FnTy, "__kmpc_syncwarp");
+break;
+  }
   }
   return RTLFn;
 }
@@ -2700,6 +2718,9 @@
   llvm::BasicBlock *BodyBB = CGF.createBasicBlock("omp.critical.body");
   llvm::BasicBlock *ExitBB = CGF.createBasicBlock("omp.critical.exit");
 
+  // Get the mask of active threads in the warp.
+  llvm::Value *Mask = CGF.EmitRuntimeCall(
+  createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_warp_active_thread_mask));
   // Fetch team-local id of the thread.
   llvm::Value *ThreadID = getNVPTXThreadID(CGF);
 
@@ -2740,8 +2761,9 @@
   // Block waits for all threads in current team to finish then increments the
   // counter variable and returns to the loop.
   CGF.EmitBlock(SyncBB);
-  emitBarrierCall(CGF, Loc, OMPD_unknown, /*EmitChecks=*/false,
-  /*ForceSimpleCall=*/true);
+  // Reconverge active threads in the warp.
+  (void)CGF.EmitRuntimeCall(
+  createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_syncwarp), Mask);
 
   llvm::Value *IncCounterVal =
   CGF.Builder.CreateNSWAdd(CounterVal, CGF.Builder.getInt32(1));


Index: test/OpenMP/nvptx_parallel_codegen.cpp
===
--- test/OpenMP/nvptx_parallel_codegen.cpp
+++ test/OpenMP/nvptx_parallel_codegen.cpp
@@ -343,6 +343,7 @@
 
 // CHECK-LABEL: define internal void @{{.+}}(i32* noalias %{{.+}}, i32* noalias %{{.+}}, i32* dereferenceable{{.*}})
 // CHECK:  [[CC:%.+]] = alloca i32,
+// CHECK:  [[MASK:%.+]] = call i32 @__kmpc_warp_active_thread_mask()
 // CHECK:  [[TID:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
 // CHECK:  [[NUM_THREADS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
 // CHECK:  store i32 0, i32* [[CC]],
@@ -362,7 +363,7 @@
 // CHECK:  store i32
 // CHECK:  call void @__kmpc_end_critical(
 
-// CHECK:  call void @__kmpc_barrier(%struct.ident_t* @{{.+}}, i32 %{{.+}})
+// CHECK:  call void @__kmpc_syncwarp(i32 [[MASK]])
 // CHECK:  [[NEW_CC_VAL:%.+]] = add nsw i32 [[CC_VAL]], 1
 // CHECK:  store i32 [[NEW_CC_VAL]], i32* [[CC]],
 // CHECK:  br label
Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
===
--- lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -107,6 +107,10 @@
   /// Call to void __kmpc_barrier_simple_spmd(ident_t *loc, kmp_int32
   /// global_tid);
   OMPRTL__kmpc_barrier_simple_spmd,
+  /// Call to int32_t __kmpc_warp_active_thread_mask(void);
+  OMPRTL_NVPTX__kmpc_warp_active_thread_mask,
+  

[PATCH] D66673: [OPENMP][NVPTX]Fix critical region codegen.

2019-08-23 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D66673#1643544 , @jdoerfert wrote:

> I guess IR test should be affected already and it would be good to have the 
> run time test that breaks with barriers.


Runtime test is 
libomptarget/deviceRTLs/nvptx/test/parallel/spmd_parallel_regions.cpp


Repository:
  rC Clang

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

https://reviews.llvm.org/D66673



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


[PATCH] D66673: [OPENMP][NVPTX]Fix critical region codegen.

2019-08-23 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

I guess IR test should be affected already and it would be good to have the run 
time test that breaks with barriers.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66673



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


[PATCH] D66564: [clang-tidy] new FPGA struct pack align check

2019-08-23 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tidy/fpga/StructPackAlignCheck.h:1
+//===--- StructPackAlignCheck.h - clang-tidy-*- C++ 
-*-===//
+//

Please add space after clang-tidy. Same in source file.



Comment at: docs/clang-tidy/checks/fpga-struct-pack-align.rst:12
+
+Based on the "Altera SDK for OpenCL: Best Practices Guide" found here:
+https://www.altera.com/en_US/pdfs/literature/hb/opencl-sdk/aocl_optimization_guide.pdf

You could use link syntax. See Fuchsia checks as example.


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

https://reviews.llvm.org/D66564



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


Re: r369616 - [analyzer] Enable control dependency condition tracking by default

2019-08-23 Thread Artem Dergachev via cfe-commits
I had a look and i don't observe any regressions here. Both this test 
alone and the whole test suite in general take as much time as on 
r369520 for me. Additionally, -analyzer-stats doesn't indicate that any 
significant amount of time was spent in bug report post-processing.


On 8/23/19 11:41 AM, Kristóf Umann wrote:
Totally possible, thanks for letting me know! There should be plenty 
of room for caching, because I do calculate control dependencies in an 
excess for the same CFG, and the retrieval of a basic block from an 
ExplodedNode is anything but efficient, though I honestly didnt expect 
a performance hit that drastic (and havent experienced it either).


I'll roll out some fixes during the weekend. If the problem persists 
after that, I'd be happy to dig deeper.



On Fri, 23 Aug 2019, 20:33 Alexander Kornienko, > wrote:


I suspect that this patch makes analysis much slower in certain
cases. For example, the clang/test/Analysis/pr37802.cpp test has
become ~5 times slower in some configurations in our environment.
This happened somewhere between r369520 and r369679, and your
series of patches seems most suspicious :). Is it expected? Can it
be improved?

On Thu, Aug 22, 2019 at 5:07 AM Kristof Umann via cfe-commits
mailto:cfe-commits@lists.llvm.org>>
wrote:

Author: szelethus
Date: Wed Aug 21 20:08:48 2019
New Revision: 369616

URL: http://llvm.org/viewvc/llvm-project?rev=369616=rev
Log:
[analyzer] Enable control dependency condition tracking by default

This patch concludes my GSoC'19 project by enabling
track-conditions by default.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
    cfe/trunk/test/Analysis/analyzer-config.c
cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
cfe/trunk/test/Analysis/return-value-guaranteed.cpp
cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
URL:

http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def?rev=369616=369615=369616=diff

==
---
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
(original)
+++
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
Wed Aug 21 20:08:48 2019
@@ -294,7 +294,7 @@ ANALYZER_OPTION(bool, DisplayCTUProgress
 ANALYZER_OPTION(bool, ShouldTrackConditions, "track-conditions",
                 "Whether to track conditions that are a
control dependency of "
                 "an already tracked variable.",
-                false)
+                true)

 ANALYZER_OPTION(bool, ShouldTrackConditionsDebug,
"track-conditions-debug",
                 "Whether to place an event at each tracked
condition.",

Modified: cfe/trunk/test/Analysis/analyzer-config.c
URL:

http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.c?rev=369616=369615=369616=diff

==
--- cfe/trunk/test/Analysis/analyzer-config.c (original)
+++ cfe/trunk/test/Analysis/analyzer-config.c Wed Aug 21
20:08:48 2019
@@ -87,7 +87,7 @@
 // CHECK-NEXT: suppress-c++-stdlib = true
 // CHECK-NEXT: suppress-inlined-defensive-checks = true
 // CHECK-NEXT: suppress-null-return-paths = true
-// CHECK-NEXT: track-conditions = false
+// CHECK-NEXT: track-conditions = true
 // CHECK-NEXT: track-conditions-debug = false
 // CHECK-NEXT: unix.DynamicMemoryModeling:Optimistic = false
 // CHECK-NEXT: unroll-loops = false

Modified:
cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
URL:

http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m?rev=369616=369615=369616=diff

==
---
cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
(original)
+++
cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
Wed Aug 21 20:08:48 2019
@@ -16,6 +16,7 @@ extern int coin();
     return 0;
   }
   return 1; // expected-note{{Returning without writing to
'*var'}}
+  // expected-note@-1{{Returning the value 1, which
participates in a condition later}}
 }
 @end


Modified: 

[PATCH] D66486: [LifetimeAnalysis] Detect more cases when the address of a local variable escapes

2019-08-23 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre added a comment.

Yes, it means that the automatic inference of Pointer/Owner from base classes 
has the same issues as all of those automatic inferences: Once can construct a 
case where they are not true.
So for having no false-positives at all, we should avoid this inference by 
default and not consider MutableArrayRef to be a gsl::Pointer.
Instead, we disable the analysis when it sees an unannotated class (like here, 
MutableArrayRef).

Eventually, we can explicitly add the correct annotations to the 
MutableArrayRef and OwningArrayRef  source code,
and provide a command line option to opt into this kind of inference with 
possible false-positives.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66486



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


Re: r369591 - [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)

2019-08-23 Thread Richard Smith via cfe-commits
On Thu, 22 Aug 2019 at 13:05, Matthias Gehre via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Hi Diana,
> hi Richard,
>
> thank you for the feedback!
>
> Diana,
> I remember that some gcc version had issues with raw string literals
> inside macros. I'll fix that to use normal
> string literals instead.
>
> Richard,
> We are definitely want the gsl::Pointer-based warnings that are enabled by
> default to be free of any false-positives.
> As you expected, this is showing a problem we have in another part of our
> analysis, and we will fix it before landing
> this PR again.
>

It looks like this revert wasn't enough to unblock us. We're currently
unable to release compilers due to the scale of the new enabled-by-default
diagnostics produced by these warnings, and we're not happy about turning
off the existing (zero false positives) warning flags here in order to
unblock our releases, because they're so valuable in catching errors. I'd
expect others will hit similar issues when upgrading Clang. Even if there
were no false positives in the new warning, it appears to be undeployable
as-is because the new warning is behind the same warning flag as an
existing high-value warning. So I think we need the new warnings to be
moved behind different warning flags (a subgroup of ReturnStackAddress
would be OK, but it needs to be independently controllable).

If this can be done imminently, that would be OK, but otherwise I think we
should temporarily roll this back until it can be moved to a separate
warning group.

Both, sorry for the breakage!
>
> Am Do., 22. Aug. 2019 um 19:47 Uhr schrieb Richard Smith <
> rich...@metafoo.co.uk>:
>
>> Reverted in r369677.
>>
>> On Thu, 22 Aug 2019 at 10:34, Richard Smith 
>> wrote:
>>
>>> Hi Matthias,
>>>
>>> This introduces false positives into -Wreturn-stack-address for an
>>> example such as:
>>>
>>> #include 
>>>
>>> std::vector::iterator downcast_to(std::vector::iterator value)
>>> {
>>>   return *
>>> }
>>>
>>> This breaks an internal build bot for us, so I'm going to revert this
>>> for now (though I expect this isn't the cause of the problem, but is rather
>>> exposing a problem elsewhere).
>>>
>>> If we can make the gsl::Pointer diagnostics false-positive-free, that's
>>> great, but otherwise we should use a different warning flag for the
>>> warnings that involve these annotations and use -Wreturn-stack-address for
>>> only the zero-false-positive cases that it historically diagnosed.
>>>
>>> Thanks, and sorry for the trouble.
>>>
>>> On Wed, 21 Aug 2019 at 15:07, Matthias Gehre via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
 Author: mgehre
 Date: Wed Aug 21 15:08:59 2019
 New Revision: 369591

 URL: http://llvm.org/viewvc/llvm-project?rev=369591=rev
 Log:
 [LifetimeAnalysis] Support more STL idioms (template forward
 declaration and DependentNameType)

 Summary:
 This fixes inference of gsl::Pointer on std::set::iterator with
 libstdc++ (the typedef for iterator
 on the template is a DependentNameType - we can only put the
 gsl::Pointer attribute
 on the underlaying record after instantiation)

 inference of gsl::Pointer on std::vector::iterator with libc++ (the
 class was forward-declared,
 we added the gsl::Pointer on the canonical decl (the forward decl), and
 later when the
 template was instantiated, there was no attribute on the definition so
 it was not instantiated).

 and a duplicate gsl::Pointer on some class with libstdc++ (we first
 added an attribute to
 a incomplete instantiation, and then another was copied from the
 template definition
 when the instantiation was completed).

 We now add the attributes to all redeclarations to fix thos issues and
 make their usage easier.

 Reviewers: gribozavr

 Subscribers: Szelethus, xazax.hun, cfe-commits

 Tags: #clang

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

 Added:
 cfe/trunk/unittests/Sema/GslOwnerPointerInference.cpp
 Modified:
 cfe/trunk/lib/Sema/SemaAttr.cpp
 cfe/trunk/lib/Sema/SemaDeclAttr.cpp
 cfe/trunk/lib/Sema/SemaInit.cpp
 cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
 cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
 cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer.cpp
 cfe/trunk/unittests/Sema/CMakeLists.txt

 Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
 URL:
 http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=369591=369590=369591=diff

 ==
 --- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
 +++ cfe/trunk/lib/Sema/SemaAttr.cpp Wed Aug 21 15:08:59 2019
 @@ -88,13 +88,11 @@ void Sema::AddMsStructLayoutForRecord(Re
  template 
  static void addGslOwnerPointerAttributeIfNotExisting(ASTContext
 ,
  

r369803 - Do a sweep of symbol internalization. NFC.

2019-08-23 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Fri Aug 23 12:59:23 2019
New Revision: 369803

URL: http://llvm.org/viewvc/llvm-project?rev=369803=rev
Log:
Do a sweep of symbol internalization. NFC.

Modified:
cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp

Modified: cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp?rev=369803=369802=369803=diff
==
--- cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp Fri Aug 23 12:59:23 2019
@@ -823,7 +823,7 @@ static void callSpecialFunction(G &,
   Gen.callFunc(FuncName, QT, Addrs, CGF);
 }
 
-template  std::array createNullAddressArray();
+template  static std::array createNullAddressArray();
 
 template <> std::array createNullAddressArray() {
   return std::array({{Address(nullptr, CharUnits::Zero())}});

Modified: cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp?rev=369803=369802=369803=diff
==
--- cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp Fri Aug 23 
12:59:23 2019
@@ -15,6 +15,7 @@
 
 using namespace clang;
 
+namespace {
 class InterfaceStubFunctionsConsumer : public ASTConsumer {
   CompilerInstance 
   StringRef InFile;
@@ -293,6 +294,7 @@ public:
 writeIfsV1(Instance.getTarget().getTriple(), Symbols, context, Format, 
*OS);
   }
 };
+} // namespace
 
 std::unique_ptr
 GenerateInterfaceIfsExpV1Action::CreateASTConsumer(CompilerInstance ,

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=369803=369802=369803=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Fri Aug 23 12:59:23 2019
@@ -86,8 +86,8 @@ static bool isAttributeLateParsed(const
 }
 
 /// Check if the a start and end source location expand to the same macro.
-bool FindLocsWithCommonFileID(Preprocessor , SourceLocation StartLoc,
-  SourceLocation EndLoc) {
+static bool FindLocsWithCommonFileID(Preprocessor , SourceLocation StartLoc,
+ SourceLocation EndLoc) {
   if (!StartLoc.isMacroID() || !EndLoc.isMacroID())
 return false;
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=369803=369802=369803=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Fri Aug 23 12:59:23 2019
@@ -1060,10 +1060,11 @@ static const Stmt *getTerminatorConditio
   return S;
 }
 
-llvm::StringLiteral StrEnteringLoop = "Entering loop body";
-llvm::StringLiteral StrLoopBodyZero = "Loop body executed 0 times";
-llvm::StringLiteral StrLoopRangeEmpty = "Loop body skipped when range is 
empty";
-llvm::StringLiteral StrLoopCollectionEmpty =
+constexpr llvm::StringLiteral StrEnteringLoop = "Entering loop body";
+constexpr llvm::StringLiteral StrLoopBodyZero = "Loop body executed 0 times";
+constexpr llvm::StringLiteral StrLoopRangeEmpty =
+"Loop body skipped when range is empty";
+constexpr llvm::StringLiteral StrLoopCollectionEmpty =
 "Loop body skipped when collection is empty";
 
 static std::unique_ptr


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


r369801 - [OPENMP5]Use nonmonotonic modifier by default for non-static and

2019-08-23 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Aug 23 12:52:05 2019
New Revision: 369801

URL: http://llvm.org/viewvc/llvm-project?rev=369801=rev
Log:
[OPENMP5]Use nonmonotonic modifier by default for non-static and
non-ordered loops.

According to OpenMP 5.0, 2.9.2 Worksharing-Loop Construct, Desription, If the 
static schedule kind is specified or if the ordered clause is specified, and if 
the nonmonotonic modifier is not specified, the effect is as if the monotonic 
modifier is specified. Otherwise, unless the monotonic modifier is specified, 
the effect is as if the nonmonotonic modifier is specified.
The first part of this requirement is implemented in runtime. Patch adds
support for the second, nonmonotonic, part of this requirement.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/for_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=369801=369800=369801=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Fri Aug 23 12:52:05 2019
@@ -3509,7 +3509,7 @@ bool CGOpenMPRuntime::isDynamic(OpenMPSc
   return Schedule != OMP_sch_static;
 }
 
-static int addMonoNonMonoModifier(OpenMPSchedType Schedule,
+static int addMonoNonMonoModifier(CodeGenModule , OpenMPSchedType Schedule,
   OpenMPScheduleClauseModifier M1,
   OpenMPScheduleClauseModifier M2) {
   int Modifier = 0;
@@ -3543,6 +3543,18 @@ static int addMonoNonMonoModifier(OpenMP
   case OMPC_SCHEDULE_MODIFIER_unknown:
 break;
   }
+  // OpenMP 5.0, 2.9.2 Worksharing-Loop Construct, Desription.
+  // If the static schedule kind is specified or if the ordered clause is
+  // specified, and if the nonmonotonic modifier is not specified, the effect 
is
+  // as if the monotonic modifier is specified. Otherwise, unless the monotonic
+  // modifier is specified, the effect is as if the nonmonotonic modifier is
+  // specified.
+  if (CGM.getLangOpts().OpenMP >= 50 && Modifier == 0) {
+if (!(Schedule == OMP_sch_static_chunked || Schedule == OMP_sch_static ||
+  Schedule == OMP_sch_static_balanced_chunked ||
+  Schedule == OMP_ord_static_chunked || Schedule == OMP_ord_static))
+  Modifier = OMP_sch_modifier_nonmonotonic;
+  }
   return Schedule | Modifier;
 }
 
@@ -3567,13 +3579,14 @@ void CGOpenMPRuntime::emitForDispatchIni
   llvm::Value *Chunk = DispatchValues.Chunk ? DispatchValues.Chunk
 : CGF.Builder.getIntN(IVSize, 1);
   llvm::Value *Args[] = {
-  emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc),
+  emitUpdateLocation(CGF, Loc),
+  getThreadID(CGF, Loc),
   CGF.Builder.getInt32(addMonoNonMonoModifier(
-  Schedule, ScheduleKind.M1, ScheduleKind.M2)), // Schedule type
-  DispatchValues.LB,// Lower
-  DispatchValues.UB,// Upper
-  CGF.Builder.getIntN(IVSize, 1),   // Stride
-  Chunk // Chunk
+  CGM, Schedule, ScheduleKind.M1, ScheduleKind.M2)), // Schedule type
+  DispatchValues.LB, // Lower
+  DispatchValues.UB, // Upper
+  CGF.Builder.getIntN(IVSize, 1),// Stride
+  Chunk  // Chunk
   };
   CGF.EmitRuntimeCall(createDispatchInitFunction(IVSize, IVSigned), Args);
 }
@@ -3615,7 +3628,7 @@ static void emitForStaticInitCall(
   llvm::Value *Args[] = {
   UpdateLocation,
   ThreadId,
-  CGF.Builder.getInt32(addMonoNonMonoModifier(Schedule, M1,
+  CGF.Builder.getInt32(addMonoNonMonoModifier(CGF.CGM, Schedule, M1,
   M2)), // Schedule type
   Values.IL.getPointer(),   // 
   Values.LB.getPointer(),   // 

Modified: cfe/trunk/test/OpenMP/for_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_codegen.cpp?rev=369801=369800=369801=diff
==
--- cfe/trunk/test/OpenMP/for_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/for_codegen.cpp Fri Aug 23 12:52:05 2019
@@ -1,10 +1,14 @@
-// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - 
-fsanitize-address-use-after-scope | FileCheck %s --check-prefix=CHECK 
--check-prefix=LIFETIME
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - 
-fsanitize-address-use-after-scope | FileCheck %s --check-prefix=CHECK 
--check-prefix=LIFETIME --check-prefix=OMP45
+// 

[PATCH] D66486: [LifetimeAnalysis] Detect more cases when the address of a local variable escapes

2019-08-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Yeah, the analysis would work fine in this case. But that would mean that we 
should not propagate the Pointer annotations to derived classes as some of them 
in the wild do not follow the same ownership model.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66486



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


[PATCH] D66564: [clang-tidy] new FPGA struct pack align check

2019-08-23 Thread Frank Derry Wanye via Phabricator via cfe-commits
ffrankies updated this revision to Diff 216928.
ffrankies added a comment.

Implemented changes requested by Eugene.Zelenko


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

https://reviews.llvm.org/D66564

Files:
  clang-tidy/fpga/CMakeLists.txt
  clang-tidy/fpga/FPGATidyModule.cpp
  clang-tidy/fpga/StructPackAlignCheck.cpp
  clang-tidy/fpga/StructPackAlignCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fpga-struct-pack-align.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/fpga-struct-pack-align.cpp

Index: test/clang-tidy/fpga-struct-pack-align.cpp
===
--- /dev/null
+++ test/clang-tidy/fpga-struct-pack-align.cpp
@@ -0,0 +1,74 @@
+// RUN: %check_clang_tidy %s fpga-struct-pack-align %t -- -header-filter=.* "--" --include opencl-c.h -cl-std=CL1.2 -c 
+
+// Struct needs both alignment and packing
+struct error {
+char a;
+double b;
+char c;
+};
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'error' has inefficient access due to padding, only needs 10 bytes but is using 24 bytes, use "__attribute((packed))" [fpga-struct-pack-align]
+// CHECK-MESSAGES: :[[@LINE-6]]:8: warning: struct 'error' has inefficient access due to poor alignment. Currently aligned to 8 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+// Struct is explicitly packed, but needs alignment
+struct error_packed {
+char a;
+double b;
+char c;
+} __attribute((packed));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'error_packed' has inefficient access due to poor alignment. Currently aligned to 1 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+// Struct is properly packed, but needs alignment
+struct align_only {
+char a;
+char b;
+char c;
+char d;
+int e;
+double f;
+};
+// CHECK-MESSAGES: :[[@LINE-8]]:8: warning: struct 'align_only' has inefficient access due to poor alignment. Currently aligned to 8 bytes, but size 16 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+// Struct is perfectly packed but wrongly aligned
+struct bad_align {
+char a;
+double b;
+char c;
+} __attribute((packed)) __attribute((aligned(8)));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'bad_align' has inefficient access due to poor alignment. Currently aligned to 8 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+struct bad_align2 {
+char a;
+double b;
+char c;
+} __attribute((packed)) __attribute((aligned(32)));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'bad_align2' has inefficient access due to poor alignment. Currently aligned to 32 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+struct bad_align3 {
+char a;
+double b;
+char c;
+} __attribute((packed)) __attribute((aligned(4)));
+// CHECK-MESSAGES: :[[@LINE-5]]:8: warning: struct 'bad_align3' has inefficient access due to poor alignment. Currently aligned to 4 bytes, but size 10 bytes is large enough to benefit from "__attribute((aligned(16)))" [fpga-struct-pack-align]
+
+// Struct is both perfectly packed and aligned
+struct success {
+char a;
+double b;
+char c;
+} __attribute((packed)) __attribute((aligned(16)));
+//Should take 10 bytes and be aligned to 16 bytes
+
+// Struct is properly packed, and explicitly aligned
+struct success2 {
+int a;
+int b;
+int c;
+} __attribute((aligned(16)));
+
+// If struct is properly aligned, packing not needed
+struct error_aligned {
+char a;
+double b;
+char c;
+} __attribute((aligned(16)));
+
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -64,6 +64,7 @@
 ``cert-``  Checks related to CERT Secure Coding Guidelines.
 ``cppcoreguidelines-`` Checks related to C++ Core Guidelines.
 ``clang-analyzer-``Clang Static Analyzer checks.
+``fpga-``  Checks related to OpenCL programming for FPGAs.
 ``fuchsia-``   Checks related to Fuchsia coding conventions.
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -210,6 +210,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   fpga-struct-pack-align
fuchsia-default-arguments-calls
fuchsia-default-arguments-declarations
fuchsia-header-anon-namespaces (redirects to google-build-namespaces) 
Index: docs/clang-tidy/checks/fpga-struct-pack-align.rst

[PATCH] D66486: [LifetimeAnalysis] Detect more cases when the address of a local variable escapes

2019-08-23 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre added a comment.

When I understand you correctly, you are thinking about
the cases

  OwningArrayRef getRef();
  
  ArrayRef f() {
ArrayRef r = getRef(); // warning: r points into temporary owner
return r;
  }

and

  ArrayRef getRef() {
OwningArrayRef r;
return r;  // warning: returning reference to local variable
  }

which we will both diagnose correctly with the current analysis. In which case 
would our analysis have problems with the fact that ArrayRef is a Pointer and 
the derived OwningArrayRef is a Owner?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66486



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


[PATCH] D66676: [clang-tidy] TransformerClangTidyCheck: change choice of location for diagnostic message.

2019-08-23 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: gribozavr.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.

This patch changes the location specified to the
`ClangTidyCheck::diag()`. Currently, the beginning of the matched range is
used. This patch uses the beginning of the first fix's range.  This change both
simplifies the code and (hopefully) gives a more intuitive result: the reported
location aligns with the fix(es) provided, rather than the (arbitrary) range of
the rule's match.

N.B. this patch will break the line offset numbers in lit tests if the first fix
is not at the beginning of the match.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66676

Files:
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
@@ -18,18 +18,18 @@
 namespace tidy {
 namespace utils {
 namespace {
+using namespace ::clang::ast_matchers;
+
 using tooling::change;
 using tooling::IncludeFormat;
+using tooling::node;
 using tooling::RewriteRule;
+using tooling::statement;
 using tooling::text;
 using tooling::stencil::cat;
 
 // Invert the code of an if-statement, while maintaining its semantics.
 RewriteRule invertIf() {
-  using namespace ::clang::ast_matchers;
-  using tooling::node;
-  using tooling::statement;
-
   StringRef C = "C", T = "T", E = "E";
   RewriteRule Rule = tooling::makeRule(
   ifStmt(hasCondition(expr().bind(C)), hasThen(stmt().bind(T)),
@@ -67,6 +67,57 @@
   EXPECT_EQ(Expected, test::runCheckOnCode(Input));
 }
 
+class IntLitCheck : public TransformerClangTidyCheck {
+public:
+  IntLitCheck(StringRef Name, ClangTidyContext *Context)
+  : TransformerClangTidyCheck(tooling::makeRule(integerLiteral(),
+change(text("LIT")),
+text("no message")),
+  Name, Context) {}
+};
+
+// Tests that two changes in a single macro expansion do not lead to conflicts
+// in applying the changes.
+TEST(TransformerClangTidyCheckTest, TwoChangesInOneMacroExpansion) {
+  const std::string Input = R"cc(
+#define PLUS(a,b) (a) + (b)
+int f() { return PLUS(3, 4); }
+  )cc";
+  const std::string Expected = R"cc(
+#define PLUS(a,b) (a) + (b)
+int f() { return PLUS(LIT, LIT); }
+  )cc";
+
+  EXPECT_EQ(Expected, test::runCheckOnCode(Input));
+}
+
+class BinOpCheck : public TransformerClangTidyCheck {
+public:
+  BinOpCheck(StringRef Name, ClangTidyContext *Context)
+  : TransformerClangTidyCheck(
+tooling::makeRule(
+binaryOperator(hasOperatorName("+"), hasRHS(expr().bind("r"))),
+change(node("r"), text("RIGHT")), text("no message")),
+Name, Context) {}
+};
+
+// Tests case where the rule's match spans both source from the macro and its
+// argument, while the change spans only the argument AND there are two such
+// matches.  Here, we expect a conflict between the two matches and the second
+// to be ignored.
+TEST(TransformerClangTidyCheckTest, TwoMatchesInMacroExpansion) {
+  const std::string Input = R"cc(
+#define M(a,b) (1 + a) * (1 + b)
+int f() { return M(3, 4); }
+  )cc";
+  const std::string Expected = R"cc(
+#define M(a,b) (1 + a) * (1 + b)
+int f() { return M(RIGHT, RIGHT); }
+  )cc";
+
+  EXPECT_EQ(Expected, test::runCheckOnCode(Input));
+}
+
 // A trivial rewrite-rule generator that requires Objective-C code.
 Optional needsObjC(const LangOptions ,
 const ClangTidyCheck::OptionsView ) {
Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -71,14 +71,6 @@
   if (Result.Context->getDiagnostics().hasErrorOccurred())
 return;
 
-  // Verify the existence and validity of the AST node that roots this rule.
-  const ast_matchers::BoundNodes::IDToNodeMap  = Result.Nodes.getMap();
-  auto Root = NodesMap.find(RewriteRule::RootID);
-  assert(Root != NodesMap.end() && "Transformation failed: missing root node.");
-  SourceLocation RootLoc = Result.SourceManager->getExpansionLoc(
-  Root->second.getSourceRange().getBegin());
-  assert(RootLoc.isValid() && "Invalid location for Root node of match.");
-
   assert(Rule && "check() should not fire if Rule is None");
   RewriteRule::Case Case = tooling::detail::findSelectedCase(Result, *Rule);
   Expected> Transformations =
@@ -99,10 +91,12 @@
  << 

[PATCH] D66652: [libTooling] Transformer: refine `SourceLocation` specified as anchor of changes.

2019-08-23 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 216921.
ymandel marked 2 inline comments as done.
ymandel added a comment.

comments tweaks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66652

Files:
  clang/include/clang/Tooling/Refactoring/Transformer.h
  clang/lib/Tooling/Refactoring/Transformer.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -710,6 +710,57 @@
   testRule(ruleStrlenSize(), Input, Expected);
 }
 
+// Tests that two changes in a single macro expansion do not lead to conflicts
+// in applying the changes.
+TEST_F(TransformerTest, TwoChangesInOneMacroExpansion) {
+  std::string Input = R"cc(
+#define PLUS(a,b) (a) + (b)
+int f() { return PLUS(3, 4); }
+  )cc";
+  std::string Expected = R"cc(
+#define PLUS(a,b) (a) + (b)
+int f() { return PLUS(LIT, LIT); }
+  )cc";
+
+  testRule(makeRule(integerLiteral(), change(text("LIT"))), Input, Expected);
+}
+
+// Tests case where the rule's match spans both source from the macro and its
+// arg, with the begin location (the "anchor") being the arg.
+TEST_F(TransformerTest, MatchSpansMacroTextButChangeDoesNot) {
+  std::string Input = R"cc(
+#define PLUS_ONE(a) a + 1
+int f() { return PLUS_ONE(3); }
+  )cc";
+  std::string Expected = R"cc(
+#define PLUS_ONE(a) a + 1
+int f() { return PLUS_ONE(LIT); }
+  )cc";
+
+  StringRef E = "expr";
+  testRule(makeRule(binaryOperator(hasLHS(expr().bind(E))),
+change(node(E), text("LIT"))),
+   Input, Expected);
+}
+
+// Tests case where the rule's match spans both source from the macro and its
+// arg, with the begin location (the "anchor") being inside the macro.
+TEST_F(TransformerTest, MatchSpansMacroTextButChangeDoesNotAnchoredInMacro) {
+  std::string Input = R"cc(
+#define PLUS_ONE(a) 1 + a
+int f() { return PLUS_ONE(3); }
+  )cc";
+  std::string Expected = R"cc(
+#define PLUS_ONE(a) 1 + a
+int f() { return PLUS_ONE(LIT); }
+  )cc";
+
+  StringRef E = "expr";
+  testRule(makeRule(binaryOperator(hasRHS(expr().bind(E))),
+change(node(E), text("LIT"))),
+   Input, Expected);
+}
+
 // No rewrite is applied when the changed text does not encompass the entirety
 // of the expanded text. That is, the edit would have to be applied to the
 // macro's definition to succeed and editing the expansion point would not
Index: clang/lib/Tooling/Refactoring/Transformer.cpp
===
--- clang/lib/Tooling/Refactoring/Transformer.cpp
+++ clang/lib/Tooling/Refactoring/Transformer.cpp
@@ -150,6 +150,21 @@
   return Ms[0];
 }
 
+SourceLocation tooling::detail::getRuleMatchLoc(const MatchResult ) {
+  auto  = Result.Nodes.getMap();
+  auto Root = NodesMap.find(RewriteRule::RootID);
+  assert(Root != NodesMap.end() && "Transformation failed: missing root node.");
+  llvm::Optional RootRange = getRangeForEdit(
+  CharSourceRange::getTokenRange(Root->second.getSourceRange()),
+  *Result.Context);
+  if (RootRange)
+return RootRange->getBegin();
+  // The match doesn't have a coherent range, so fall back to the expansion
+  // location as the "beginning" of the match.
+  return Result.SourceManager->getExpansionLoc(
+  Root->second.getSourceRange().getBegin());
+}
+
 // Finds the case that was "selected" -- that is, whose matcher triggered the
 // `MatchResult`.
 const RewriteRule::Case &
@@ -178,12 +193,7 @@
   if (Result.Context->getDiagnostics().hasErrorOccurred())
 return;
 
-  // Verify the existence and validity of the AST node that roots this rule.
-  auto  = Result.Nodes.getMap();
-  auto Root = NodesMap.find(RewriteRule::RootID);
-  assert(Root != NodesMap.end() && "Transformation failed: missing root node.");
-  SourceLocation RootLoc = Result.SourceManager->getExpansionLoc(
-  Root->second.getSourceRange().getBegin());
+  SourceLocation RootLoc = tooling::detail::getRuleMatchLoc(Result);
   assert(RootLoc.isValid() && "Invalid location for Root node of match.");
 
   RewriteRule::Case Case = tooling::detail::findSelectedCase(Result, Rule);
Index: clang/include/clang/Tooling/Refactoring/Transformer.h
===
--- clang/include/clang/Tooling/Refactoring/Transformer.h
+++ clang/include/clang/Tooling/Refactoring/Transformer.h
@@ -254,6 +254,12 @@
 std::vector
 buildMatchers(const RewriteRule );
 
+/// Gets the beginning location of the source matched by a rewrite rule. If the
+/// match occurs within a macro expansion, returns the beginning of the
+/// expansion point. `Result` must come from the matching of a rewrite rule.
+SourceLocation
+getRuleMatchLoc(const ast_matchers::MatchFinder::MatchResult );
+
 /// Returns 

[PATCH] D63325: [Support][Time profiler] Make FE codegen blocks to be inside frontend blocks

2019-08-23 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a comment.

> Could it be an issue with python? What is the version you are using?

I would assume so...

  $ /usr/bin/python --version
  Python 3.7.4


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63325



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


[PATCH] D66673: [OPENMP][NVPTX]Fix critical region codegen.

2019-08-23 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev created this revision.
ABataev added a reviewer: ABataev.
Herald added subscribers: cfe-commits, guansong, jholewinski.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

Previously critical regions were emitted with the barrier making it a
worksharing construct though it is not. Also, it leads to incorrect
behavior in Cuda9+. Patch fixes this problem.


Repository:
  rC Clang

https://reviews.llvm.org/D66673

Files:
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp


Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
===
--- lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -107,6 +107,10 @@
   /// Call to void __kmpc_barrier_simple_spmd(ident_t *loc, kmp_int32
   /// global_tid);
   OMPRTL__kmpc_barrier_simple_spmd,
+  /// Call to int32_t __kmpc_warp_active_thread_mask(void);
+  OMPRTL_NVPTX__kmpc_warp_active_thread_mask,
+  /// Call to void __kmpc_syncwarp(int32_t Mask);
+  OMPRTL_NVPTX__kmpc_syncwarp,
 };
 
 /// Pre(post)-action for different OpenMP constructs specialized for NVPTX.
@@ -1794,6 +1798,20 @@
 ->addFnAttr(llvm::Attribute::Convergent);
 break;
   }
+  case OMPRTL_NVPTX__kmpc_warp_active_thread_mask: {
+// Build int32_t __kmpc_warp_active_thread_mask(void);
+auto *FnTy =
+llvm::FunctionType::get(CGM.Int32Ty, llvm::None, /*isVarArg=*/false);
+RTLFn = CGM.CreateRuntimeFunction(FnTy, "__kmpc_warp_active_thread_mask");
+break;
+  }
+  case OMPRTL_NVPTX__kmpc_syncwarp: {
+// Build void __kmpc_syncwarp(kmp_int32 Mask);
+auto *FnTy =
+llvm::FunctionType::get(CGM.VoidTy, CGM.Int32Ty, /*isVarArg=*/false);
+RTLFn = CGM.CreateRuntimeFunction(FnTy, "__kmpc_syncwarp");
+break;
+  }
   }
   return RTLFn;
 }
@@ -2700,6 +2718,9 @@
   llvm::BasicBlock *BodyBB = CGF.createBasicBlock("omp.critical.body");
   llvm::BasicBlock *ExitBB = CGF.createBasicBlock("omp.critical.exit");
 
+  // Get the mask of active threads in the warp.
+  llvm::Value *Mask = CGF.EmitRuntimeCall(
+  createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_warp_active_thread_mask));
   // Fetch team-local id of the thread.
   llvm::Value *ThreadID = getNVPTXThreadID(CGF);
 
@@ -2740,8 +2761,9 @@
   // Block waits for all threads in current team to finish then increments the
   // counter variable and returns to the loop.
   CGF.EmitBlock(SyncBB);
-  emitBarrierCall(CGF, Loc, OMPD_unknown, /*EmitChecks=*/false,
-  /*ForceSimpleCall=*/true);
+  // Reconverge active threads in the warp.
+  (void)CGF.EmitRuntimeCall(
+  createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_syncwarp), Mask);
 
   llvm::Value *IncCounterVal =
   CGF.Builder.CreateNSWAdd(CounterVal, CGF.Builder.getInt32(1));


Index: lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
===
--- lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
+++ lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -107,6 +107,10 @@
   /// Call to void __kmpc_barrier_simple_spmd(ident_t *loc, kmp_int32
   /// global_tid);
   OMPRTL__kmpc_barrier_simple_spmd,
+  /// Call to int32_t __kmpc_warp_active_thread_mask(void);
+  OMPRTL_NVPTX__kmpc_warp_active_thread_mask,
+  /// Call to void __kmpc_syncwarp(int32_t Mask);
+  OMPRTL_NVPTX__kmpc_syncwarp,
 };
 
 /// Pre(post)-action for different OpenMP constructs specialized for NVPTX.
@@ -1794,6 +1798,20 @@
 ->addFnAttr(llvm::Attribute::Convergent);
 break;
   }
+  case OMPRTL_NVPTX__kmpc_warp_active_thread_mask: {
+// Build int32_t __kmpc_warp_active_thread_mask(void);
+auto *FnTy =
+llvm::FunctionType::get(CGM.Int32Ty, llvm::None, /*isVarArg=*/false);
+RTLFn = CGM.CreateRuntimeFunction(FnTy, "__kmpc_warp_active_thread_mask");
+break;
+  }
+  case OMPRTL_NVPTX__kmpc_syncwarp: {
+// Build void __kmpc_syncwarp(kmp_int32 Mask);
+auto *FnTy =
+llvm::FunctionType::get(CGM.VoidTy, CGM.Int32Ty, /*isVarArg=*/false);
+RTLFn = CGM.CreateRuntimeFunction(FnTy, "__kmpc_syncwarp");
+break;
+  }
   }
   return RTLFn;
 }
@@ -2700,6 +2718,9 @@
   llvm::BasicBlock *BodyBB = CGF.createBasicBlock("omp.critical.body");
   llvm::BasicBlock *ExitBB = CGF.createBasicBlock("omp.critical.exit");
 
+  // Get the mask of active threads in the warp.
+  llvm::Value *Mask = CGF.EmitRuntimeCall(
+  createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_warp_active_thread_mask));
   // Fetch team-local id of the thread.
   llvm::Value *ThreadID = getNVPTXThreadID(CGF);
 
@@ -2740,8 +2761,9 @@
   // Block waits for all threads in current team to finish then increments the
   // counter variable and returns to the loop.
   CGF.EmitBlock(SyncBB);
-  emitBarrierCall(CGF, Loc, OMPD_unknown, /*EmitChecks=*/false,
-  /*ForceSimpleCall=*/true);
+  // Reconverge active threads in the warp.
+  (void)CGF.EmitRuntimeCall(
+  createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_syncwarp), Mask);
 
   llvm::Value *IncCounterVal =
   

[PATCH] D66486: [LifetimeAnalysis] Detect more cases when the address of a local variable escapes

2019-08-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In D66486#1643374 , @mgehre wrote:

> > Also it feels a bit weird to change the ownership semantics in a derived 
> > class, I bet that would violate the Liskov substitution principle.
>
> And then we see that llvm::OwningArrayRef inherits from llvm::ArrayRef ... 
> But maybe this direction (strengthening a Pointer into an Owner)
>  is okay.


I am not sure. Consider the following code:

  ArrayRef f() {
ArrayRef r = getRef();
return r;
  }

According to the substitution principle I should be able to replace `r` with a 
derived class:

  ArrayRef f() {
OwningArrayRef r = getOwningRef();
return r;
  }

But this will introduce a lifetime issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66486



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


[PATCH] D66486: [LifetimeAnalysis] Detect more cases when the address of a local variable escapes

2019-08-23 Thread Matthias Gehre via Phabricator via cfe-commits
mgehre added a comment.

> Also it feels a bit weird to change the ownership semantics in a derived 
> class, I bet that would violate the Liskov substitution principle.

And then we see that llvm::OwningArrayRef inherits from llvm::ArrayRef ... But 
maybe this direction (strengthening a Pointer into an Owner)
is okay. We'll need to go though the call rules, and see if something breaks 
when the caller passes an Owner to a function that takes a base class (i.e. 
Pointer).
My initial reaction is that this should work in general. An Owner is like a 
Pointer that points to {static}.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66486



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


[PATCH] D65907: Introduce FileEntryRef and use it when handling includes to report correct dependencies when the FileManager is reused across invocations

2019-08-23 Thread James Nagurne via Phabricator via cfe-commits
JamesNagurne added a comment.
Herald added a subscriber: ributzka.

@arphaman you disabled this test on Windows, but did not specify exactly how it 
fails.
My team works on an embedded ARM compiler (most similar to arm-none-eabi), and 
we're now seeing failures from DependencyScannerTest. I can't find a buildbot 
failure for this test so I can't cross-reference to see if we have the same 
issue.

Does this failure look similar to what you saw on Windows, or could it be an 
option we're adding as part of the Compilation setup?

  [ RUN  ] DependencyScanner.ScanDepsReuseFilemanager
  .../clang/unittests/Tooling/DependencyScannerTest.cpp:100: Failure
Expected: Deps[1]
Which is: "symlink.h"
  To be equal to: "/root/symlink.h"
  .../clang/unittests/Tooling/DependencyScannerTest.cpp:101: Failure
Expected: Deps[2]
Which is: "header.h"
  To be equal to: "/root/header.h"
  .../clang/unittests/Tooling/DependencyScannerTest.cpp:113: Failure
Expected: Deps[1]
Which is: "symlink.h"
  To be equal to: "/root/symlink.h"
  .../clang/unittests/Tooling/DependencyScannerTest.cpp:114: Failure
Expected: Deps[2]
Which is: "header.h"
  To be equal to: "/root/header.h"
  [  FAILED  ] DependencyScanner.ScanDepsReuseFilemanager (5 ms)


Repository:
  rL LLVM

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

https://reviews.llvm.org/D65907



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


Re: r369616 - [analyzer] Enable control dependency condition tracking by default

2019-08-23 Thread Kristóf Umann via cfe-commits
Totally possible, thanks for letting me know! There should be plenty of
room for caching, because I do calculate control dependencies in an excess
for the same CFG, and the retrieval of a basic block from an ExplodedNode
is anything but efficient, though I honestly didnt expect a performance hit
that drastic (and havent experienced it either).

I'll roll out some fixes during the weekend. If the problem persists
after that, I'd be happy to dig deeper.


On Fri, 23 Aug 2019, 20:33 Alexander Kornienko,  wrote:

> I suspect that this patch makes analysis much slower in certain cases. For
> example, the clang/test/Analysis/pr37802.cpp test has become ~5 times
> slower in some configurations in our environment. This happened somewhere
> between r369520 and r369679, and your series of patches seems most
> suspicious :). Is it expected? Can it be improved?
>
> On Thu, Aug 22, 2019 at 5:07 AM Kristof Umann via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: szelethus
>> Date: Wed Aug 21 20:08:48 2019
>> New Revision: 369616
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=369616=rev
>> Log:
>> [analyzer] Enable control dependency condition tracking by default
>>
>> This patch concludes my GSoC'19 project by enabling track-conditions by
>> default.
>>
>> Differential Revision: https://reviews.llvm.org/D66381
>>
>> Modified:
>> cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
>> cfe/trunk/test/Analysis/analyzer-config.c
>> cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
>> cfe/trunk/test/Analysis/return-value-guaranteed.cpp
>> cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
>>
>> Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def?rev=369616=369615=369616=diff
>>
>> ==
>> --- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
>> (original)
>> +++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def Wed
>> Aug 21 20:08:48 2019
>> @@ -294,7 +294,7 @@ ANALYZER_OPTION(bool, DisplayCTUProgress
>>  ANALYZER_OPTION(bool, ShouldTrackConditions, "track-conditions",
>>  "Whether to track conditions that are a control
>> dependency of "
>>  "an already tracked variable.",
>> -false)
>> +true)
>>
>>  ANALYZER_OPTION(bool, ShouldTrackConditionsDebug,
>> "track-conditions-debug",
>>  "Whether to place an event at each tracked condition.",
>>
>> Modified: cfe/trunk/test/Analysis/analyzer-config.c
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.c?rev=369616=369615=369616=diff
>>
>> ==
>> --- cfe/trunk/test/Analysis/analyzer-config.c (original)
>> +++ cfe/trunk/test/Analysis/analyzer-config.c Wed Aug 21 20:08:48 2019
>> @@ -87,7 +87,7 @@
>>  // CHECK-NEXT: suppress-c++-stdlib = true
>>  // CHECK-NEXT: suppress-inlined-defensive-checks = true
>>  // CHECK-NEXT: suppress-null-return-paths = true
>> -// CHECK-NEXT: track-conditions = false
>> +// CHECK-NEXT: track-conditions = true
>>  // CHECK-NEXT: track-conditions-debug = false
>>  // CHECK-NEXT: unix.DynamicMemoryModeling:Optimistic = false
>>  // CHECK-NEXT: unroll-loops = false
>>
>> Modified: cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m?rev=369616=369615=369616=diff
>>
>> ==
>> --- cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
>> (original)
>> +++ cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m Wed
>> Aug 21 20:08:48 2019
>> @@ -16,6 +16,7 @@ extern int coin();
>>  return 0;
>>}
>>return 1; // expected-note{{Returning without writing to '*var'}}
>> +  // expected-note@-1{{Returning the value 1, which participates in a
>> condition later}}
>>  }
>>  @end
>>
>>
>> Modified: cfe/trunk/test/Analysis/return-value-guaranteed.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/return-value-guaranteed.cpp?rev=369616=369615=369616=diff
>>
>> ==
>> --- cfe/trunk/test/Analysis/return-value-guaranteed.cpp (original)
>> +++ cfe/trunk/test/Analysis/return-value-guaranteed.cpp Wed Aug 21
>> 20:08:48 2019
>> @@ -24,6 +24,7 @@ bool parseFoo(Foo ) {
>>// class-note@-1 {{The value 0 is assigned to 'F.Field'}}
>>return !MCAsmParser::Error();
>>// class-note@-1 {{'MCAsmParser::Error' returns true}}
>> +  // class-note@-2 {{Returning zero, which participates in a condition
>> later}}
>>  }
>>
>>  bool parseFile() {
>> @@ -57,6 +58,7 @@ namespace 

[PATCH] D63325: [Support][Time profiler] Make FE codegen blocks to be inside frontend blocks

2019-08-23 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev added a comment.

In D63325#1643023 , @nathanchance 
wrote:

> Done, thanks for looking into this!
>
> F9847579: check-time-trace-sections.json 


Hmm, I still didn't manage to reproduce the issue using your json-file:

  [~/llvm] > cat check-time-trace-sections.json | python 
llvm-project/clang/test/Driver/check-time-trace-sections.py
  [~/llvm] > echo $status
  0

The file itself looks good for this test: all Codegen sections are inside any 
Frontend section and all Frontend sections are before all Backend sections.
Also your log shows no error messages, so test should pass ok. Could it be an 
issue with python? What is the version you are using?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63325



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


Re: r369616 - [analyzer] Enable control dependency condition tracking by default

2019-08-23 Thread Alexander Kornienko via cfe-commits
I suspect that this patch makes analysis much slower in certain cases. For
example, the clang/test/Analysis/pr37802.cpp test has become ~5 times
slower in some configurations in our environment. This happened somewhere
between r369520 and r369679, and your series of patches seems most
suspicious :). Is it expected? Can it be improved?

On Thu, Aug 22, 2019 at 5:07 AM Kristof Umann via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: szelethus
> Date: Wed Aug 21 20:08:48 2019
> New Revision: 369616
>
> URL: http://llvm.org/viewvc/llvm-project?rev=369616=rev
> Log:
> [analyzer] Enable control dependency condition tracking by default
>
> This patch concludes my GSoC'19 project by enabling track-conditions by
> default.
>
> Differential Revision: https://reviews.llvm.org/D66381
>
> Modified:
> cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
> cfe/trunk/test/Analysis/analyzer-config.c
> cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
> cfe/trunk/test/Analysis/return-value-guaranteed.cpp
> cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
>
> Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def?rev=369616=369615=369616=diff
>
> ==
> --- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
> (original)
> +++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def Wed
> Aug 21 20:08:48 2019
> @@ -294,7 +294,7 @@ ANALYZER_OPTION(bool, DisplayCTUProgress
>  ANALYZER_OPTION(bool, ShouldTrackConditions, "track-conditions",
>  "Whether to track conditions that are a control
> dependency of "
>  "an already tracked variable.",
> -false)
> +true)
>
>  ANALYZER_OPTION(bool, ShouldTrackConditionsDebug,
> "track-conditions-debug",
>  "Whether to place an event at each tracked condition.",
>
> Modified: cfe/trunk/test/Analysis/analyzer-config.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.c?rev=369616=369615=369616=diff
>
> ==
> --- cfe/trunk/test/Analysis/analyzer-config.c (original)
> +++ cfe/trunk/test/Analysis/analyzer-config.c Wed Aug 21 20:08:48 2019
> @@ -87,7 +87,7 @@
>  // CHECK-NEXT: suppress-c++-stdlib = true
>  // CHECK-NEXT: suppress-inlined-defensive-checks = true
>  // CHECK-NEXT: suppress-null-return-paths = true
> -// CHECK-NEXT: track-conditions = false
> +// CHECK-NEXT: track-conditions = true
>  // CHECK-NEXT: track-conditions-debug = false
>  // CHECK-NEXT: unix.DynamicMemoryModeling:Optimistic = false
>  // CHECK-NEXT: unroll-loops = false
>
> Modified: cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m?rev=369616=369615=369616=diff
>
> ==
> --- cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
> (original)
> +++ cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m Wed Aug
> 21 20:08:48 2019
> @@ -16,6 +16,7 @@ extern int coin();
>  return 0;
>}
>return 1; // expected-note{{Returning without writing to '*var'}}
> +  // expected-note@-1{{Returning the value 1, which participates in a
> condition later}}
>  }
>  @end
>
>
> Modified: cfe/trunk/test/Analysis/return-value-guaranteed.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/return-value-guaranteed.cpp?rev=369616=369615=369616=diff
>
> ==
> --- cfe/trunk/test/Analysis/return-value-guaranteed.cpp (original)
> +++ cfe/trunk/test/Analysis/return-value-guaranteed.cpp Wed Aug 21
> 20:08:48 2019
> @@ -24,6 +24,7 @@ bool parseFoo(Foo ) {
>// class-note@-1 {{The value 0 is assigned to 'F.Field'}}
>return !MCAsmParser::Error();
>// class-note@-1 {{'MCAsmParser::Error' returns true}}
> +  // class-note@-2 {{Returning zero, which participates in a condition
> later}}
>  }
>
>  bool parseFile() {
> @@ -57,6 +58,7 @@ namespace test_break {
>  struct MCAsmParser {
>static bool Error() {
>  return false; // class-note {{'MCAsmParser::Error' returns false}}
> +// class-note@-1 {{Returning zero, which participates in a condition
> later}}
>}
>  };
>
> @@ -72,6 +74,7 @@ bool parseFoo(Foo ) {
>return MCAsmParser::Error();
>// class-note@-1 {{Calling 'MCAsmParser::Error'}}
>// class-note@-2 {{Returning from 'MCAsmParser::Error'}}
> +  // class-note@-3 {{Returning zero, which participates in a condition
> later}}
>  }
>
>  bool parseFile() {
>
> Modified: cfe/trunk/test/Analysis/track-control-dependency-conditions.cpp
> 

[PATCH] D66646: Ensure that statements, expressions and types are trivially destructible with a static_assert

2019-08-23 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D66646#1642730 , @riccibruno wrote:

> In D66646#1642708 , @lebedev.ri 
> wrote:
>
> > SGTM, but i wonder if this should be done one level up, in 
> > `BumpPtrAllocator` itself?
>
>
> I don't understand. `BumpPtrAllocator` is only used to allocate raw memory 
> and doesn't know anything about how it is going to be used.


I was looking at `SpecificBumpPtrAllocator`, which knows it's type.
But if i look down the indirection, i think 
`AllocatorBase::Allocate()`/`AllocatorBase::Deallocate()` is the place.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66646



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


[PATCH] D66186: [Sema] Don't warn on printf('%hd', [char]) (PR41467)

2019-08-23 Thread Nathan Huckleberry via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369791: [Sema] Dont warn on printf(%hd, 
[char]) (PR41467) (authored by Nathan-Huckleberry, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66186?vs=216893=216904#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66186

Files:
  cfe/trunk/lib/AST/FormatString.cpp
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/FixIt/format.m
  cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp
  cfe/trunk/test/Sema/format-strings-pedantic.c
  cfe/trunk/test/Sema/format-strings.c


Index: cfe/trunk/test/FixIt/format.m
===
--- cfe/trunk/test/FixIt/format.m
+++ cfe/trunk/test/FixIt/format.m
@@ -205,9 +205,7 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%f"
   // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"(unichar)"
 
-  NSLog(@"%C", (char)0x260300); // expected-warning{{format specifies type 
'unichar' (aka 'unsigned short') but the argument has type 'char'}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
-  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:22}:"(unichar)"
+  NSLog(@"%C", (char)0x260300);
 
   NSLog(@"%C", 'a'); // expected-warning{{format specifies type 'unichar' (aka 
'unsigned short') but the argument has type 'char'}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
Index: cfe/trunk/test/Sema/format-strings.c
===
--- cfe/trunk/test/Sema/format-strings.c
+++ cfe/trunk/test/Sema/format-strings.c
@@ -277,8 +277,8 @@
 
 void should_understand_small_integers() {
   printf("%hhu", (short) 10); // expected-warning{{format specifies type 
'unsigned char' but the argument has type 'short'}}
-  printf("%hu\n", (unsigned char) 1); // expected-warning{{format specifies 
type 'unsigned short' but the argument has type 'unsigned char'}}
-  printf("%hu\n", (uint8_t)1); // expected-warning{{format specifies type 
'unsigned short' but the argument has type 'uint8_t'}}
+  printf("%hu\n", (unsigned char)1); // warning with -Wformat-pedantic only
+  printf("%hu\n", (uint8_t)1);   // warning with -Wformat-pedantic only
 }
 
 void test11(void *p, char *s) {
Index: cfe/trunk/test/Sema/format-strings-pedantic.c
===
--- cfe/trunk/test/Sema/format-strings-pedantic.c
+++ cfe/trunk/test/Sema/format-strings-pedantic.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wformat -Wformat-pedantic -isystem 
%S/Inputs %s
+
+int printf(const char *restrict, ...);
+
+typedef unsigned char uint8_t;
+
+void print_char_as_short() {
+  printf("%hu\n", (unsigned char)1); // expected-warning{{format specifies 
type 'unsigned short' but the argument has type 'unsigned char'}}
+  printf("%hu\n", (uint8_t)1);   // expected-warning{{format specifies 
type 'unsigned short' but the argument has type 'uint8_t' (aka 'unsigned 
char')}}
+}
Index: cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp
===
--- cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp
+++ cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp
@@ -79,10 +79,10 @@
   printf("%hhd", input); // no-warning
   printf("%hhd", CharConstant); // no-warning
 
-  // This is not correct but it is safe. We warn because '%hd' shows intent.
-  printf("%hd", input); // expected-warning{{format specifies type 'short' but 
the argument has underlying type 'char'}}
-  printf("%hd", CharConstant); // expected-warning{{format specifies type 
'short'}}
-  
+  // This is not correct, but it is safe. Only warned in pedantic mode because 
'%hd' shows intent.
+  printf("%hd", input);
+  printf("%hd", CharConstant);
+
   // This is not correct but it matches the promotion rules (and is safe).
   printf("%d", input); // no-warning
   printf("%d", CharConstant); // no-warning
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -8119,9 +8119,13 @@
   // function.
   if (ICE->getType() == S.Context.IntTy ||
   ICE->getType() == S.Context.UnsignedIntTy) {
-// All further checking is done on the subexpression.
-if (AT.matchesType(S.Context, ExprTy))
+// All further checking is done on the subexpression
+const analyze_printf::ArgType::MatchKind ImplicitMatch =
+AT.matchesType(S.Context, ExprTy);
+if (ImplicitMatch == analyze_printf::ArgType::Match)
   return true;
+if (ImplicitMatch == analyze_printf::ArgType::NoMatchPedantic)
+  Pedantic = true;
   }
 }
   } else 

[PATCH] D66667: Debug Info: Support for DW_AT_export_symbols for anonymous structs

2019-08-23 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: test/CodeGenCXX/debug-info-export_symbols.cpp:3
+
+// CHECK-DAG: !DICompositeType({{.*}}flags: DIFlagExportSymbols | 
DIFlagTypePassByValue
+struct A {

This should just be `CHECK:` if it stands by itself.

It would be better to match both composite types, establish which one is the 
inner one, and then verify that only that one has the attribute.


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

https://reviews.llvm.org/D7



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


r369791 - [Sema] Don't warn on printf('%hd', [char]) (PR41467)

2019-08-23 Thread Nathan Huckleberry via cfe-commits
Author: nathan-huckleberry
Date: Fri Aug 23 11:01:57 2019
New Revision: 369791

URL: http://llvm.org/viewvc/llvm-project?rev=369791=rev
Log:
[Sema] Don't warn on printf('%hd', [char]) (PR41467)

Summary: Link: https://bugs.llvm.org/show_bug.cgi?id=41467

Reviewers: rsmith, nickdesaulniers, aaron.ballman, lebedev.ri

Reviewed By: nickdesaulniers, aaron.ballman, lebedev.ri

Subscribers: lebedev.ri, nickdesaulniers, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/Sema/format-strings-pedantic.c
Modified:
cfe/trunk/lib/AST/FormatString.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/FixIt/format.m
cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp
cfe/trunk/test/Sema/format-strings.c

Modified: cfe/trunk/lib/AST/FormatString.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/FormatString.cpp?rev=369791=369790=369791=diff
==
--- cfe/trunk/lib/AST/FormatString.cpp (original)
+++ cfe/trunk/lib/AST/FormatString.cpp Fri Aug 23 11:01:57 2019
@@ -386,6 +386,8 @@ ArgType::matchesType(ASTContext , Qual
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  return NoMatchPedantic;
 return T == C.UnsignedCharTy || T == C.SignedCharTy ? Match
 : NoMatch;
   case BuiltinType::Short:

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=369791=369790=369791=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Aug 23 11:01:57 2019
@@ -8119,9 +8119,13 @@ CheckPrintfHandler::checkFormatExpr(cons
   // function.
   if (ICE->getType() == S.Context.IntTy ||
   ICE->getType() == S.Context.UnsignedIntTy) {
-// All further checking is done on the subexpression.
-if (AT.matchesType(S.Context, ExprTy))
+// All further checking is done on the subexpression
+const analyze_printf::ArgType::MatchKind ImplicitMatch =
+AT.matchesType(S.Context, ExprTy);
+if (ImplicitMatch == analyze_printf::ArgType::Match)
   return true;
+if (ImplicitMatch == analyze_printf::ArgType::NoMatchPedantic)
+  Pedantic = true;
   }
 }
   } else if (const CharacterLiteral *CL = dyn_cast(E)) {

Modified: cfe/trunk/test/FixIt/format.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/format.m?rev=369791=369790=369791=diff
==
--- cfe/trunk/test/FixIt/format.m (original)
+++ cfe/trunk/test/FixIt/format.m Fri Aug 23 11:01:57 2019
@@ -205,9 +205,7 @@ void test_percent_C() {
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%f"
   // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"(unichar)"
 
-  NSLog(@"%C", (char)0x260300); // expected-warning{{format specifies type 
'unichar' (aka 'unsigned short') but the argument has type 'char'}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
-  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:22}:"(unichar)"
+  NSLog(@"%C", (char)0x260300);
 
   NSLog(@"%C", 'a'); // expected-warning{{format specifies type 'unichar' (aka 
'unsigned short') but the argument has type 'char'}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"

Modified: cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp?rev=369791=369790=369791=diff
==
--- cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp (original)
+++ cfe/trunk/test/Sema/format-strings-enum-fixed-type.cpp Fri Aug 23 11:01:57 
2019
@@ -79,10 +79,10 @@ void testChar(CharEnum input) {
   printf("%hhd", input); // no-warning
   printf("%hhd", CharConstant); // no-warning
 
-  // This is not correct but it is safe. We warn because '%hd' shows intent.
-  printf("%hd", input); // expected-warning{{format specifies type 'short' but 
the argument has underlying type 'char'}}
-  printf("%hd", CharConstant); // expected-warning{{format specifies type 
'short'}}
-  
+  // This is not correct, but it is safe. Only warned in pedantic mode because 
'%hd' shows intent.
+  printf("%hd", input);
+  printf("%hd", CharConstant);
+
   // This is not correct but it matches the promotion rules (and is safe).
   printf("%d", input); // no-warning
   printf("%d", CharConstant); // no-warning

Added: cfe/trunk/test/Sema/format-strings-pedantic.c
URL: 

[PATCH] D66668: [OPENMP][Analysis] Add analysis of the map clauses.

2019-08-23 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev created this revision.
ABataev added a reviewer: NoQ.
Herald added a subscriber: guansong.
Herald added a project: clang.

Added basic analysis of map clauses. Only map clauses with to and tofrom
map type must be analyzed since all other map types (alloc, delete, etc.) do 
not require to use the value of the initial variable, instead they create the 
new copy of the variable.


Repository:
  rC Clang

https://reviews.llvm.org/D8

Files:
  include/clang/AST/OpenMPClause.h
  test/Analysis/cfg-openmp.cpp
  test/OpenMP/target_data_messages.c
  test/OpenMP/target_enter_data_map_messages.c
  test/OpenMP/target_map_messages.cpp
  test/OpenMP/target_parallel_for_map_messages.cpp
  test/OpenMP/target_parallel_for_simd_map_messages.cpp
  test/OpenMP/target_parallel_map_messages.cpp
  test/OpenMP/target_simd_map_messages.cpp
  test/OpenMP/target_teams_distribute_map_messages.cpp
  test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp
  test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
  test/OpenMP/target_teams_distribute_simd_map_messages.cpp
  test/OpenMP/target_teams_map_messages.cpp

Index: test/OpenMP/target_teams_map_messages.cpp
===
--- test/OpenMP/target_teams_map_messages.cpp
+++ test/OpenMP/target_teams_map_messages.cpp
@@ -21,6 +21,14 @@
   {}
 }
 #else
+
+void xxx(int argc) {
+  int map; // expected-note {{initialize the variable 'map' to silence this warning}}
+#pragma omp target teams map(tofrom: map) // expected-warning {{variable 'map' is uninitialized when used here}}
+  for (int i = 0; i < 10; ++i)
+;
+}
+
 template 
 struct SA {
   static int ss;
Index: test/OpenMP/target_teams_distribute_simd_map_messages.cpp
===
--- test/OpenMP/target_teams_distribute_simd_map_messages.cpp
+++ test/OpenMP/target_teams_distribute_simd_map_messages.cpp
@@ -9,6 +9,13 @@
   return argc;
 }
 
+void xxx(int argc) {
+  int map; // expected-note {{initialize the variable 'map' to silence this warning}}
+#pragma omp target teams distribute simd map(map) // expected-warning {{variable 'map' is uninitialized when used here}}
+  for (int i = 0; i < 10; ++i)
+;
+}
+
 struct S1; // expected-note 2 {{declared here}}
 extern S1 a;
 class S2 {
Index: test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
===
--- test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
+++ test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
@@ -9,6 +9,13 @@
   return argc;
 }
 
+void xxx(int argc) {
+  int map; // expected-note {{initialize the variable 'map' to silence this warning}}
+#pragma omp target teams distribute parallel for simd map(to: map) // expected-warning {{variable 'map' is uninitialized when used here}}
+  for (int i = 0; i < 10; ++i)
+;
+}
+
 struct S1; // expected-note 2 {{declared here}}
 extern S1 a;
 class S2 {
Index: test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp
===
--- test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp
+++ test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp
@@ -9,6 +9,13 @@
   return argc;
 }
 
+void xxx(int argc) {
+  int map; // expected-note {{initialize the variable 'map' to silence this warning}}
+#pragma omp target teams distribute parallel for map(tofrom: map) // expected-warning {{variable 'map' is uninitialized when used here}}
+  for (int i = 0; i < 10; ++i)
+;
+}
+
 struct S1; // expected-note 2 {{declared here}}
 extern S1 a;
 class S2 {
Index: test/OpenMP/target_teams_distribute_map_messages.cpp
===
--- test/OpenMP/target_teams_distribute_map_messages.cpp
+++ test/OpenMP/target_teams_distribute_map_messages.cpp
@@ -9,6 +9,13 @@
   return argc;
 }
 
+void xxx(int argc) {
+  int map; // expected-note {{initialize the variable 'map' to silence this warning}}
+#pragma omp target teams distribute map(map) // expected-warning {{variable 'map' is uninitialized when used here}}
+  for (int i = 0; i < 10; ++i)
+;
+}
+
 struct S1; // expected-note 2 {{declared here}}
 extern S1 a;
 class S2 {
Index: test/OpenMP/target_simd_map_messages.cpp
===
--- test/OpenMP/target_simd_map_messages.cpp
+++ test/OpenMP/target_simd_map_messages.cpp
@@ -9,6 +9,13 @@
   return argc;
 }
 
+void xxx(int argc) {
+  int map; // expected-note {{initialize the variable 'map' to silence this warning}}
+#pragma omp target simd map(to: map) // expected-warning {{variable 'map' is uninitialized when used here}}
+  for (int i = 0; i < 10; ++i)
+;
+}
+
 struct S1; // expected-note 2 {{declared here}}
 extern S1 a;
 class S2 {
Index: test/OpenMP/target_parallel_map_messages.cpp

[PATCH] D66667: Debug Info: Support for DW_AT_export_symbols for anonymous structs

2019-08-23 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik created this revision.
shafik added a reviewer: aprantl.
shafik added a project: debug-info.
shafik added a parent revision: D66605: Debug Info: Support for 
DW_AT_export_symbols for anonymous structs.

This implements the DWARF 5 feature described in:

http://dwarfstd.org/ShowIssue.php?issue=141212.1

To support recognizing anonymous structs:

  struct A { 
struct { // Anonymous struct 
int y;
};  
  } a;

This patch adds support in `CGDebugInfo::CreateLimitedType(...)` for this new 
flag and an accompanying test to verify this feature.


https://reviews.llvm.org/D7

Files:
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGenCXX/debug-info-export_symbols.cpp


Index: test/CodeGenCXX/debug-info-export_symbols.cpp
===
--- /dev/null
+++ test/CodeGenCXX/debug-info-export_symbols.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -triple 
%itanium_abi_triple %s -o - | FileCheck %s
+
+// CHECK-DAG: !DICompositeType({{.*}}flags: DIFlagExportSymbols | 
DIFlagTypePassByValue
+struct A {
+ // Anonymous class exports its symbols into A
+ struct {
+ int y;
+ };
+} a;
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3121,7 +3121,8 @@
 
   SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
 
-  // Explicitly record the calling convention for C++ records.
+  // Explicitly record the calling convention and export symbols for C++
+  // records.
   auto Flags = llvm::DINode::FlagZero;
   if (auto CXXRD = dyn_cast(RD)) {
 if (CGM.getCXXABI().getRecordArgABI(CXXRD) == CGCXXABI::RAA_Indirect)
@@ -3132,6 +3133,10 @@
 // Record if a C++ record is non-trivial type.
 if (!CXXRD->isTrivial())
   Flags |= llvm::DINode::FlagNonTrivial;
+
+// Record exports it symbols to the containing structure.
+if (CXXRD->isAnonymousStructOrUnion())
+Flags |= llvm::DINode::FlagExportSymbols;
   }
 
   llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(


Index: test/CodeGenCXX/debug-info-export_symbols.cpp
===
--- /dev/null
+++ test/CodeGenCXX/debug-info-export_symbols.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -triple %itanium_abi_triple %s -o - | FileCheck %s
+
+// CHECK-DAG: !DICompositeType({{.*}}flags: DIFlagExportSymbols | DIFlagTypePassByValue
+struct A {
+ // Anonymous class exports its symbols into A
+ struct {
+ int y;
+ };
+} a;
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3121,7 +3121,8 @@
 
   SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
 
-  // Explicitly record the calling convention for C++ records.
+  // Explicitly record the calling convention and export symbols for C++
+  // records.
   auto Flags = llvm::DINode::FlagZero;
   if (auto CXXRD = dyn_cast(RD)) {
 if (CGM.getCXXABI().getRecordArgABI(CXXRD) == CGCXXABI::RAA_Indirect)
@@ -3132,6 +3133,10 @@
 // Record if a C++ record is non-trivial type.
 if (!CXXRD->isTrivial())
   Flags |= llvm::DINode::FlagNonTrivial;
+
+// Record exports it symbols to the containing structure.
+if (CXXRD->isAnonymousStructOrUnion())
+Flags |= llvm::DINode::FlagExportSymbols;
   }
 
   llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66555: [driver] add a new option `-gen-cdb-fragment-path` to emit a fragment of a compilation database for each compilation

2019-08-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman marked 5 inline comments as done.
arphaman added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2067
+  const auto  = C.getDriver();
+  auto CWD = Driver.getVFS().getCurrentWorkingDirectory();
+  if (!CWD) {

jkorous wrote:
> Do we still need this now?
No, the CWD should actually be read in `DumpCompilationDatabase`. I updated 
that method.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2089
+  if (Err) {
+Driver.Diag(diag::err_drv_compilationdatabase) << Err.message();
+return;

jkorous wrote:
> Just to make sure - the error different on purpose here?
Not really needed I guess, I reused the error.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2092
+  }
+  CompilationDatabase =
+  std::make_unique(FD, /*shouldClose=*/true);

jkorous wrote:
> I'm not familiar with intended lifecycle of `CompilationDatabase ` member. 
> Just to make sure - we need neither to preserve the original value nor reset 
> the stream after we're done here (as in - nobody is going to write anything 
> after we're done here), right?
Yes, we should either preserve or not reset the stream once it's created. 
Multiple clang invocations can be constructed  from one driver run, so we want 
to keep the stream open while the driver is running.



Comment at: clang/lib/Driver/ToolChains/Clang.h:99
+  void DumpCompilationDatabaseFragmentToDir(
+  StringRef Dir, Compilation , StringRef Target, const InputInfo ,
+  const InputInfo , const llvm::opt::ArgList ) const;

jkorous wrote:
> BTW this looks kind of funny `const InputInfo , const InputInfo 
> `.
Yes, that's unfortunate type naming in Clang :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66555



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


[PATCH] D66555: [driver] add a new option `-gen-cdb-fragment-path` to emit a fragment of a compilation database for each compilation

2019-08-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 216898.
arphaman added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66555

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Clang.h
  clang/test/Driver/gen-cdb-fragment.c

Index: clang/test/Driver/gen-cdb-fragment.c
===
--- /dev/null
+++ clang/test/Driver/gen-cdb-fragment.c
@@ -0,0 +1,37 @@
+// REQUIRES: x86-registered-target
+// RUN: rm -rf %t.cdb
+// RUN: %clang -target x86_64-apple-macos10.15 -c %s -o -  -gen-cdb-fragment-path %t.cdb
+// RUN: ls %t.cdb | FileCheck --check-prefix=CHECK-LS %s
+// CHECK-LS: gen-cdb-fragment.c.{{.*}}.json
+
+// RUN: cat %t.cdb/*.json | FileCheck --check-prefix=CHECK %s
+// CHECK: { "directory": "{{.*}}", "file": "{{.*}}gen-cdb-fragment.c", "output": "-", "arguments": [{{.*}}, "--target=x86_64-apple-macos10.15"{{.*}}]},
+// RUN: cat %t.cdb/*.json | FileCheck --check-prefix=CHECK-FLAG %s
+// CHECK-FLAG-NOT: -gen-cdb-fragment-path
+
+// RUN: rm -rf %t.cdb
+// RUN: mkdir %t.cdb
+// RUN: ls %t.cdb | not FileCheck --check-prefix=CHECK-LS %s
+// RUN: %clang -target x86_64-apple-macos10.15 -S %s -o -  -gen-cdb-fragment-path %t.cdb
+// RUN: ls %t.cdb | FileCheck --check-prefix=CHECK-LS %s
+
+// Empty path is equivalent to '.'
+// RUN: rm -rf %t.cdb
+// RUN: mkdir %t.cdb
+// RUN: %clang -target x86_64-apple-macos10.15 -working-directory %t.cdb -c %s -o -  -gen-cdb-fragment-path ""
+// RUN: ls %t.cdb | FileCheck --check-prefix=CHECK-LS %s
+// RUN: cat %t.cdb/*.json | FileCheck --check-prefix=CHECK-CWD %s
+// CHECK-CWD: "directory": "{{.*}}.cdb"
+
+// -### does not emit the CDB fragment
+// RUN: rm -rf %t.cdb
+// RUN: mkdir %t.cdb
+// RUN: %clang -target x86_64-apple-macos10.15 -S %s -o -  -gen-cdb-fragment-path %t.cdb -###
+// RUN: ls %t.cdb | not FileCheck --check-prefix=CHECK-LS %s
+
+// -MJ is preferred over -gen-cdb-fragment-path
+// RUN: rm -rf %t.cdb
+// RUN: mkdir %t.cdb
+// RUN: %clang -target x86_64-apple-macos10.15 -S %s -o -  -gen-cdb-fragment-path %t.cdb -MJ %t.out
+// RUN: ls %t.cdb | not FileCheck --check-prefix=CHECK-LS %s
+// RUN: FileCheck %s < %t.out
Index: clang/lib/Driver/ToolChains/Clang.h
===
--- clang/lib/Driver/ToolChains/Clang.h
+++ clang/lib/Driver/ToolChains/Clang.h
@@ -95,6 +95,10 @@
const InputInfo , const InputInfo ,
const llvm::opt::ArgList ) const;
 
+  void DumpCompilationDatabaseFragmentToDir(
+  StringRef Dir, Compilation , StringRef Target, const InputInfo ,
+  const InputInfo , const llvm::opt::ArgList ) const;
+
 public:
   Clang(const ToolChain );
   ~Clang() override;
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2013,13 +2013,14 @@
 CompilationDatabase = std::move(File);
   }
   auto  = *CompilationDatabase;
-  SmallString<128> Buf;
-  if (llvm::sys::fs::current_path(Buf))
-Buf = ".";
-  CDB << "{ \"directory\": \"" << escape(Buf) << "\"";
+  auto CWD = D.getVFS().getCurrentWorkingDirectory();
+  if (!CWD)
+CWD = ".";
+  CDB << "{ \"directory\": \"" << escape(*CWD) << "\"";
   CDB << ", \"file\": \"" << escape(Input.getFilename()) << "\"";
   CDB << ", \"output\": \"" << escape(Output.getFilename()) << "\"";
   CDB << ", \"arguments\": [\"" << escape(D.ClangExecutable) << "\"";
+  SmallString<128> Buf;
   Buf = "-x";
   Buf += types::getTypeName(Input.getType());
   CDB << ", \"" << escape(Buf) << "\"";
@@ -2037,6 +2038,8 @@
 // Skip writing dependency output and the compilation database itself.
 if (O.getGroup().isValid() && O.getGroup().getID() == options::OPT_M_Group)
   continue;
+if (O.getID() == options::OPT_gen_cdb_fragment_path)
+  continue;
 // Skip inputs.
 if (O.getKind() == Option::InputClass)
   continue;
@@ -2051,6 +2054,40 @@
   CDB << ", \"" << escape(Buf) << "\"]},\n";
 }
 
+void Clang::DumpCompilationDatabaseFragmentToDir(
+StringRef Dir, Compilation , StringRef Target, const InputInfo ,
+const InputInfo , const llvm::opt::ArgList ) const {
+  // If this is a dry run, do not create the compilation database file.
+  if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH))
+return;
+
+  if (CompilationDatabase)
+DumpCompilationDatabase(C, "", Target, Output, Input, Args);
+
+  SmallString<256> Path = Dir;
+  const auto  = C.getDriver();
+  Driver.getVFS().makeAbsolute(Path);
+  auto Err = llvm::sys::fs::create_directory(Path, /*IgnoreExisting=*/true);
+  if (Err) {
+Driver.Diag(diag::err_drv_compilationdatabase) << Dir << Err.message();
+return;
+  }
+
+  llvm::sys::path::append(
+  

[PATCH] D66186: [Sema] Don't warn on printf('%hd', [char]) (PR41467)

2019-08-23 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri accepted this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

LG, thank you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66186



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


[clang-tools-extra] r369783 - Fix clang-tidy warning in clang-tidy

2019-08-23 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Fri Aug 23 10:27:04 2019
New Revision: 369783

URL: http://llvm.org/viewvc/llvm-project?rev=369783=rev
Log:
Fix clang-tidy warning in clang-tidy

argument name 'FixDescription' in comment does not match parameter name 
'Description'

Patch by Nils Barth!

Modified:
clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp?rev=369783=369782=369783=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UnusedUsingDeclsCheck.cpp Fri Aug 
23 10:27:04 2019
@@ -157,7 +157,7 @@ void UnusedUsingDeclsCheck::onEndOfTrans
   << Context.FoundUsingDecl;
   // Emit a fix and a fix description of the check;
   diag(Context.FoundUsingDecl->getLocation(),
-   /*FixDescription=*/"remove the using", DiagnosticIDs::Note)
+   /*Description=*/"remove the using", DiagnosticIDs::Note)
   << FixItHint::CreateRemoval(Context.UsingDeclRange);
 }
   }


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


[PATCH] D66186: [Sema] Don't warn on printf('%hd', [char]) (PR41467)

2019-08-23 Thread Nathan Huckleberry via Phabricator via cfe-commits
Nathan-Huckleberry updated this revision to Diff 216893.
Nathan-Huckleberry added a comment.

- Add if without else


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66186

Files:
  clang/lib/AST/FormatString.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/FixIt/format.m
  clang/test/Sema/format-strings-enum-fixed-type.cpp
  clang/test/Sema/format-strings-pedantic.c
  clang/test/Sema/format-strings.c


Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -277,8 +277,8 @@
 
 void should_understand_small_integers() {
   printf("%hhu", (short) 10); // expected-warning{{format specifies type 
'unsigned char' but the argument has type 'short'}}
-  printf("%hu\n", (unsigned char) 1); // expected-warning{{format specifies 
type 'unsigned short' but the argument has type 'unsigned char'}}
-  printf("%hu\n", (uint8_t)1); // expected-warning{{format specifies type 
'unsigned short' but the argument has type 'uint8_t'}}
+  printf("%hu\n", (unsigned char)1); // warning with -Wformat-pedantic only
+  printf("%hu\n", (uint8_t)1);   // warning with -Wformat-pedantic only
 }
 
 void test11(void *p, char *s) {
Index: clang/test/Sema/format-strings-pedantic.c
===
--- /dev/null
+++ clang/test/Sema/format-strings-pedantic.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wformat -Wformat-pedantic -isystem 
%S/Inputs %s
+
+int printf(const char *restrict, ...);
+
+typedef unsigned char uint8_t;
+
+void print_char_as_short() {
+  printf("%hu\n", (unsigned char)1); // expected-warning{{format specifies 
type 'unsigned short' but the argument has type 'unsigned char'}}
+  printf("%hu\n", (uint8_t)1);   // expected-warning{{format specifies 
type 'unsigned short' but the argument has type 'uint8_t' (aka 'unsigned 
char')}}
+}
Index: clang/test/Sema/format-strings-enum-fixed-type.cpp
===
--- clang/test/Sema/format-strings-enum-fixed-type.cpp
+++ clang/test/Sema/format-strings-enum-fixed-type.cpp
@@ -79,10 +79,10 @@
   printf("%hhd", input); // no-warning
   printf("%hhd", CharConstant); // no-warning
 
-  // This is not correct but it is safe. We warn because '%hd' shows intent.
-  printf("%hd", input); // expected-warning{{format specifies type 'short' but 
the argument has underlying type 'char'}}
-  printf("%hd", CharConstant); // expected-warning{{format specifies type 
'short'}}
-  
+  // This is not correct, but it is safe. Only warned in pedantic mode because 
'%hd' shows intent.
+  printf("%hd", input);
+  printf("%hd", CharConstant);
+
   // This is not correct but it matches the promotion rules (and is safe).
   printf("%d", input); // no-warning
   printf("%d", CharConstant); // no-warning
Index: clang/test/FixIt/format.m
===
--- clang/test/FixIt/format.m
+++ clang/test/FixIt/format.m
@@ -205,9 +205,7 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%f"
   // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"(unichar)"
 
-  NSLog(@"%C", (char)0x260300); // expected-warning{{format specifies type 
'unichar' (aka 'unsigned short') but the argument has type 'char'}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
-  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:22}:"(unichar)"
+  NSLog(@"%C", (char)0x260300);
 
   NSLog(@"%C", 'a'); // expected-warning{{format specifies type 'unichar' (aka 
'unsigned short') but the argument has type 'char'}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -8098,9 +8098,13 @@
   // function.
   if (ICE->getType() == S.Context.IntTy ||
   ICE->getType() == S.Context.UnsignedIntTy) {
-// All further checking is done on the subexpression.
-if (AT.matchesType(S.Context, ExprTy))
+// All further checking is done on the subexpression
+const analyze_printf::ArgType::MatchKind ImplicitMatch =
+AT.matchesType(S.Context, ExprTy);
+if (ImplicitMatch == analyze_printf::ArgType::Match)
   return true;
+if (ImplicitMatch == analyze_printf::ArgType::NoMatchPedantic)
+  Pedantic = true;
   }
 }
   } else if (const CharacterLiteral *CL = dyn_cast(E)) {
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -386,6 +386,8 @@
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case 

[PATCH] D66652: [libTooling] Transformer: refine `SourceLocation` specified as anchor of changes.

2019-08-23 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr accepted this revision.
gribozavr added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Tooling/Refactoring/Transformer.cpp:197
 
   // Verify the existence and validity of the AST node that roots this rule.
+  SourceLocation RootLoc = tooling::detail::getRuleMatchLoc(Result);

This comment was moved into the function and now looks out of place here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66652



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


[PATCH] D66665: [CUDA] Use activemask.b32 instruction to implement __activemask w/ CUDA-9.2+

2019-08-23 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
tra added a reviewer: timshen.
Herald added subscribers: sanjoy.google, bixia.

vote.ballot instruction is gone in recent CUDA versions and
vote.sync.ballot can not be used because it needs a thread mask parameter.
Fortunately PTX 6.2 (introduced with CUDA-9.2) provides activemask.b32
instruction for this.


https://reviews.llvm.org/D5

Files:
  clang/lib/Headers/__clang_cuda_intrinsics.h


Index: clang/lib/Headers/__clang_cuda_intrinsics.h
===
--- clang/lib/Headers/__clang_cuda_intrinsics.h
+++ clang/lib/Headers/__clang_cuda_intrinsics.h
@@ -211,7 +211,15 @@
   return __nvvm_vote_ballot_sync(mask, pred);
 }
 
-inline __device__ unsigned int __activemask() { return __nvvm_vote_ballot(1); }
+inline __device__ unsigned int __activemask() {
+#if CUDA_VERSION < 9020
+  return __nvvm_vote_ballot(1);
+#else
+  unsigned int mask;
+  asm volatile("activemask.b32 %0;" : "=r"(mask));
+  return mask;
+#endif
+}
 
 inline __device__ unsigned int __fns(unsigned mask, unsigned base, int offset) 
{
   return __nvvm_fns(mask, base, offset);


Index: clang/lib/Headers/__clang_cuda_intrinsics.h
===
--- clang/lib/Headers/__clang_cuda_intrinsics.h
+++ clang/lib/Headers/__clang_cuda_intrinsics.h
@@ -211,7 +211,15 @@
   return __nvvm_vote_ballot_sync(mask, pred);
 }
 
-inline __device__ unsigned int __activemask() { return __nvvm_vote_ballot(1); }
+inline __device__ unsigned int __activemask() {
+#if CUDA_VERSION < 9020
+  return __nvvm_vote_ballot(1);
+#else
+  unsigned int mask;
+  asm volatile("activemask.b32 %0;" : "=r"(mask));
+  return mask;
+#endif
+}
 
 inline __device__ unsigned int __fns(unsigned mask, unsigned base, int offset) {
   return __nvvm_fns(mask, base, offset);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66186: [Sema] Don't warn on printf('%hd', [char]) (PR41467)

2019-08-23 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri requested changes to this revision.
lebedev.ri added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/Sema/SemaChecking.cpp:8106
   return true;
+Pedantic = true;
   }

`if (ImplicitMatch == analyze_printf::ArgType::NoMatchPedantic)` should have 
stayed probably?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66186



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


[PATCH] D66511: [clang-scan-deps] Skip UTF-8 BOM in source minimizer

2019-08-23 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: lib/Lex/DependencyDirectivesSourceMinimizer.cpp:822
 bool Minimizer::minimizeImpl(const char *First, const char *const End) {
+  skipUTF8ByteOrderMark(First, End);
   while (First != End)

Is skipping this the right thing, or should it also be copied to the output?


Repository:
  rC Clang

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

https://reviews.llvm.org/D66511



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


[PATCH] D66186: [Sema] Don't warn on printf('%hd', [char]) (PR41467)

2019-08-23 Thread Nathan Huckleberry via Phabricator via cfe-commits
Nathan-Huckleberry updated this revision to Diff 216884.
Nathan-Huckleberry added a comment.

- Remove else


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66186

Files:
  clang/lib/AST/FormatString.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/FixIt/format.m
  clang/test/Sema/format-strings-enum-fixed-type.cpp
  clang/test/Sema/format-strings-pedantic.c
  clang/test/Sema/format-strings.c


Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -277,8 +277,8 @@
 
 void should_understand_small_integers() {
   printf("%hhu", (short) 10); // expected-warning{{format specifies type 
'unsigned char' but the argument has type 'short'}}
-  printf("%hu\n", (unsigned char) 1); // expected-warning{{format specifies 
type 'unsigned short' but the argument has type 'unsigned char'}}
-  printf("%hu\n", (uint8_t)1); // expected-warning{{format specifies type 
'unsigned short' but the argument has type 'uint8_t'}}
+  printf("%hu\n", (unsigned char)1); // warning with -Wformat-pedantic only
+  printf("%hu\n", (uint8_t)1);   // warning with -Wformat-pedantic only
 }
 
 void test11(void *p, char *s) {
Index: clang/test/Sema/format-strings-pedantic.c
===
--- /dev/null
+++ clang/test/Sema/format-strings-pedantic.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wformat -Wformat-pedantic -isystem 
%S/Inputs %s
+
+int printf(const char *restrict, ...);
+
+typedef unsigned char uint8_t;
+
+void print_char_as_short() {
+  printf("%hu\n", (unsigned char)1); // expected-warning{{format specifies 
type 'unsigned short' but the argument has type 'unsigned char'}}
+  printf("%hu\n", (uint8_t)1);   // expected-warning{{format specifies 
type 'unsigned short' but the argument has type 'uint8_t' (aka 'unsigned 
char')}}
+}
Index: clang/test/Sema/format-strings-enum-fixed-type.cpp
===
--- clang/test/Sema/format-strings-enum-fixed-type.cpp
+++ clang/test/Sema/format-strings-enum-fixed-type.cpp
@@ -79,10 +79,10 @@
   printf("%hhd", input); // no-warning
   printf("%hhd", CharConstant); // no-warning
 
-  // This is not correct but it is safe. We warn because '%hd' shows intent.
-  printf("%hd", input); // expected-warning{{format specifies type 'short' but 
the argument has underlying type 'char'}}
-  printf("%hd", CharConstant); // expected-warning{{format specifies type 
'short'}}
-  
+  // This is not correct, but it is safe. Only warned in pedantic mode because 
'%hd' shows intent.
+  printf("%hd", input);
+  printf("%hd", CharConstant);
+
   // This is not correct but it matches the promotion rules (and is safe).
   printf("%d", input); // no-warning
   printf("%d", CharConstant); // no-warning
Index: clang/test/FixIt/format.m
===
--- clang/test/FixIt/format.m
+++ clang/test/FixIt/format.m
@@ -205,9 +205,7 @@
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%f"
   // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:16}:"(unichar)"
 
-  NSLog(@"%C", (char)0x260300); // expected-warning{{format specifies type 
'unichar' (aka 'unsigned short') but the argument has type 'char'}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
-  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:16-[[@LINE-2]]:22}:"(unichar)"
+  NSLog(@"%C", (char)0x260300);
 
   NSLog(@"%C", 'a'); // expected-warning{{format specifies type 'unichar' (aka 
'unsigned short') but the argument has type 'char'}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -8098,9 +8098,12 @@
   // function.
   if (ICE->getType() == S.Context.IntTy ||
   ICE->getType() == S.Context.UnsignedIntTy) {
-// All further checking is done on the subexpression.
-if (AT.matchesType(S.Context, ExprTy))
+// All further checking is done on the subexpression
+const analyze_printf::ArgType::MatchKind ImplicitMatch =
+AT.matchesType(S.Context, ExprTy);
+if (ImplicitMatch == analyze_printf::ArgType::Match)
   return true;
+Pedantic = true;
   }
 }
   } else if (const CharacterLiteral *CL = dyn_cast(E)) {
Index: clang/lib/AST/FormatString.cpp
===
--- clang/lib/AST/FormatString.cpp
+++ clang/lib/AST/FormatString.cpp
@@ -386,6 +386,8 @@
   case BuiltinType::SChar:
   case BuiltinType::Char_U:
   case BuiltinType::UChar:
+if (T == C.UnsignedShortTy || T == C.ShortTy)
+  

r369779 - [OpenCL] Renamed value of std flag in C++ mode.

2019-08-23 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Fri Aug 23 10:10:33 2019
New Revision: 369779

URL: http://llvm.org/viewvc/llvm-project?rev=369779=rev
Log:
[OpenCL] Renamed value of std flag in C++ mode.
 
Clang should accept -std=clc++ (not -std=c++!) for OpenCL.

This was forgotten in r367008.


Modified:
cfe/trunk/include/clang/Basic/LangStandards.def
cfe/trunk/test/Driver/unknown-std.cl

Modified: cfe/trunk/include/clang/Basic/LangStandards.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangStandards.def?rev=369779=369778=369779=diff
==
--- cfe/trunk/include/clang/Basic/LangStandards.def (original)
+++ cfe/trunk/include/clang/Basic/LangStandards.def Fri Aug 23 10:10:33 2019
@@ -165,7 +165,7 @@ LANGSTANDARD(opencl12, "cl1.2",
 LANGSTANDARD(opencl20, "cl2.0",
  OpenCL, "OpenCL 2.0",
  LineComment | C99 | Digraphs | HexFloat | OpenCL)
-LANGSTANDARD(openclcpp, "c++",
+LANGSTANDARD(openclcpp, "clc++",
  OpenCL, "C++ for OpenCL",
  LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus17 
|
  Digraphs | HexFloat | OpenCL)

Modified: cfe/trunk/test/Driver/unknown-std.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/unknown-std.cl?rev=369779=369778=369779=diff
==
--- cfe/trunk/test/Driver/unknown-std.cl (original)
+++ cfe/trunk/test/Driver/unknown-std.cl Fri Aug 23 10:10:33 2019
@@ -10,7 +10,7 @@
 // CHECK-NEXT: note: use 'cl1.1' for 'OpenCL 1.1' standard
 // CHECK-NEXT: note: use 'cl1.2' for 'OpenCL 1.2' standard
 // CHECK-NEXT: note: use 'cl2.0' for 'OpenCL 2.0' standard
-// CHECK-NEXT: note: use 'c++' for 'C++ for OpenCL' standard
+// CHECK-NEXT: note: use 'clc++' for 'C++ for OpenCL' standard
 
 // Make sure that no other output is present.
 // CHECK-NOT: {{^.+$}}


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


[PATCH] D66511: [clang-scan-deps] Skip UTF-8 BOM in source minimizer

2019-08-23 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

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

https://reviews.llvm.org/D66511



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


[PATCH] D25845: [CUDA] Ignore implicit target attributes during function template instantiation.

2019-08-23 Thread Artem Belevich via Phabricator via cfe-commits
tra marked an inline comment as done.
tra added inline comments.



Comment at: cfe/trunk/lib/Sema/SemaDecl.cpp:8416
+// in the CheckFunctionTemplateSpecialization() call below.
+if (getLangOpts().CUDA & !isFunctionTemplateSpecialization)
+  maybeAddCUDAHostDeviceAttrs(NewFD, Previous);

tra wrote:
> RKSimon wrote:
> > @tra Sorry for touching such an old ticket - but cppcheck is warning that 
> > we are using a boolean result in a bitwise expression - I'm assuming this 
> > should be:
> > ```
> > if (getLangOpts().CUDA && !isFunctionTemplateSpecialization)
> > ```
> Good catch. I'll fix it.
Fixed in rL369777.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D25845



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


r369777 - Fixed a typo.

2019-08-23 Thread Artem Belevich via cfe-commits
Author: tra
Date: Fri Aug 23 09:24:17 2019
New Revision: 369777

URL: http://llvm.org/viewvc/llvm-project?rev=369777=rev
Log:
Fixed a typo.

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=369777=369776=369777=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Aug 23 09:24:17 2019
@@ -9006,7 +9006,7 @@ Sema::ActOnFunctionDeclarator(Scope *S,
 // may end up with different effective targets. Instead, a
 // specialization inherits its target attributes from its template
 // in the CheckFunctionTemplateSpecialization() call below.
-if (getLangOpts().CUDA & !isFunctionTemplateSpecialization)
+if (getLangOpts().CUDA && !isFunctionTemplateSpecialization)
   maybeAddCUDAHostDeviceAttrs(NewFD, Previous);
 
 // If it's a friend (and only if it's a friend), it's possible


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


r369775 - [OPENMP5.0]Add support for device_type clause in declare target

2019-08-23 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Aug 23 09:11:14 2019
New Revision: 369775

URL: http://llvm.org/viewvc/llvm-project?rev=369775=rev
Log:
[OPENMP5.0]Add support for device_type clause in declare target
construct.

OpenMP 5.0 introduced new clause for declare target directive, device_type 
clause, which may accept values host, nohost, and any. Host means
that the function must be emitted only for the host, nohost - only for
the device, and any - for both, device and the host.

Modified:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/OpenMPKinds.def
cfe/trunk/include/clang/Basic/OpenMPKinds.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTTypeTraits.cpp
cfe/trunk/lib/AST/OpenMPClause.cpp
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/test/OpenMP/declare_target_ast_print.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp
cfe/trunk/test/OpenMP/declare_target_messages.cpp
cfe/trunk/test/OpenMP/nvptx_allocate_messages.cpp
cfe/trunk/test/OpenMP/nvptx_asm_delayed_diags.c
cfe/trunk/test/OpenMP/target_vla_messages.cpp

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=369775=369774=369775=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Fri Aug 23 09:11:14 2019
@@ -2843,6 +2843,7 @@ bool RecursiveASTVisitor::Trave
 #include "clang/Basic/OpenMPKinds.def"
   case OMPC_threadprivate:
   case OMPC_uniform:
+  case OMPC_device_type:
   case OMPC_unknown:
 break;
   }

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=369775=369774=369775=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Fri Aug 23 09:11:14 2019
@@ -3207,11 +3207,16 @@ def OMPDeclareTargetDecl : InheritableAt
   let Args = [
 EnumArgument<"MapType", "MapTypeTy",
  [ "to", "link" ],
- [ "MT_To", "MT_Link" ]>
+ [ "MT_To", "MT_Link" ]>,
+EnumArgument<"DevType", "DevTypeTy",
+ [ "host", "nohost", "any" ],
+ [ "DT_Host", "DT_NoHost", "DT_Any" ]>
   ];
   let AdditionalMembers = [{
 void printPrettyPragma(raw_ostream , const PrintingPolicy ) 
const {
   // Use fake syntax because it is for testing and debugging purpose only.
+  if (getDevType() != DT_Any)
+OS << " device_type(" << ConvertDevTypeTyToStr(getDevType()) << ")";
   if (getMapType() != MT_To)
 OS << ' ' << ConvertMapTypeTyToStr(getMapType());
 }
@@ -3224,6 +3229,14 @@ def OMPDeclareTargetDecl : InheritableAt
 
   return llvm::None;
 }
+static llvm::Optional getDeviceType(const ValueDecl *VD) {
+  if (!VD->hasAttrs())
+return llvm::None;
+  if (const auto *Attr = VD->getAttr())
+return Attr->getDevType();
+
+  return llvm::None;
+}
   }];
 }
 

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=369775=369774=369775=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Fri Aug 23 09:11:14 2019
@@ -3176,6 +3176,27 @@ The syntax of the declare target directi
 #pragma omp declare target new-line
 declarations-definition-seq
 #pragma omp end declare target new-line
+
+or
+
+  .. code-block:: c
+
+#pragma omp declare target (extended-list) new-line
+
+or
+
+  .. code-block:: c
+
+#pragma omp declare target clause[ [,] clause ... ] new-line
+
+where clause is one of the following:
+
+
+  .. code-block:: c
+
+ to(extended-list)
+ link(list)
+ device_type(host | nohost | any)
   }];
 }
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=369775=369774=369775=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)

[PATCH] D66662: [clang-format] [PR43100] clang-format C# support does not add a space between "using" and paren

2019-08-23 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: djasper, klimek, owenpan.
MyDeveloperDay added a project: clang.

Addresses https://bugs.llvm.org/show_bug.cgi?id=43100

Formatting using statement in C# with clang-format removes the space between 
using and paren even when SpaceBeforeParens is !

  using(FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, 
FileShare.Read, bufferSize : 1))

this change simply overcomes this for when using C# settings in the 
.clang-format file

  using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, 
FileShare.Read, bufferSize : 1))

All FormatTests pass..

  [==] 688 tests from 21 test cases ran. (88508 ms total)
  [  PASSED  ] 688 tests.


Repository:
  rC Clang

https://reviews.llvm.org/D2

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -165,6 +165,10 @@
"public string Host {\n  set;\n  get;\n}");
 }
 
+TEST_F(FormatTestCSharp, CSharpUsing) {
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filename) { }");
+}
+
 TEST_F(FormatTestCSharp, CSharpRegions) {
   verifyFormat("#region aaa a "
"aaa long region");
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2614,6 +2614,9 @@
 if ((Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) ||
 (Left.is(tok::r_square) && Left.is(TT_AttributeSquare)))
   return true;
+// using (FileStream fs...
+if (Style.isCSharp() && Left.is(tok::kw_using) && Right.is(tok::l_paren))
+  return true;
 return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
 (Left.isOneOf(tok::pp_elif, tok::kw_for, tok::kw_while,


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -165,6 +165,10 @@
"public string Host {\n  set;\n  get;\n}");
 }
 
+TEST_F(FormatTestCSharp, CSharpUsing) {
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filename) { }");
+}
+
 TEST_F(FormatTestCSharp, CSharpRegions) {
   verifyFormat("#region aaa a "
"aaa long region");
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2614,6 +2614,9 @@
 if ((Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) ||
 (Left.is(tok::r_square) && Left.is(TT_AttributeSquare)))
   return true;
+// using (FileStream fs...
+if (Style.isCSharp() && Left.is(tok::kw_using) && Right.is(tok::l_paren))
+  return true;
 return Line.Type == LT_ObjCDecl || Left.is(tok::semi) ||
(Style.SpaceBeforeParens != FormatStyle::SBPO_Never &&
 (Left.isOneOf(tok::pp_elif, tok::kw_for, tok::kw_while,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r369773 - [NFC] Move some variable declarations into their 'if' conditions.

2019-08-23 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Fri Aug 23 08:58:35 2019
New Revision: 369773

URL: http://llvm.org/viewvc/llvm-project?rev=369773=rev
Log:
[NFC] Move some variable declarations into their 'if' conditions.

A couple of variables are being declared outside of the 'if' condition
that is their only actual use.  Additionally, switch a few 'const TYPE
*' to 'const auto *' for consistency.

Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=369773=369772=369773=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Aug 23 08:58:35 2019
@@ -470,14 +470,12 @@ void Sema::InstantiateAttrs(const MultiL
   continue;
 }
 
-const AssumeAlignedAttr *AssumeAligned = 
dyn_cast(TmplAttr);
-if (AssumeAligned) {
+if (const auto *AssumeAligned = dyn_cast(TmplAttr)) {
   instantiateDependentAssumeAlignedAttr(*this, TemplateArgs, 
AssumeAligned, New);
   continue;
 }
 
-const AlignValueAttr *AlignValue = dyn_cast(TmplAttr);
-if (AlignValue) {
+if (const auto *AlignValue = dyn_cast(TmplAttr)) {
   instantiateDependentAlignValueAttr(*this, TemplateArgs, AlignValue, New);
   continue;
 }
@@ -500,14 +498,14 @@ void Sema::InstantiateAttrs(const MultiL
   continue;
 }
 
-if (const CUDALaunchBoundsAttr *CUDALaunchBounds =
+if (const auto *CUDALaunchBounds =
 dyn_cast(TmplAttr)) {
   instantiateDependentCUDALaunchBoundsAttr(*this, TemplateArgs,
*CUDALaunchBounds, New);
   continue;
 }
 
-if (const ModeAttr *Mode = dyn_cast(TmplAttr)) {
+if (const auto *Mode = dyn_cast(TmplAttr)) {
   instantiateDependentModeAttr(*this, TemplateArgs, *Mode, New);
   continue;
 }
@@ -517,13 +515,13 @@ void Sema::InstantiateAttrs(const MultiL
   continue;
 }
 
-if (const AMDGPUFlatWorkGroupSizeAttr *AMDGPUFlatWorkGroupSize =
+if (const auto *AMDGPUFlatWorkGroupSize =
 dyn_cast(TmplAttr)) {
   instantiateDependentAMDGPUFlatWorkGroupSizeAttr(
   *this, TemplateArgs, *AMDGPUFlatWorkGroupSize, New);
 }
 
-if (const AMDGPUWavesPerEUAttr *AMDGPUFlatWorkGroupSize =
+if (const auto *AMDGPUFlatWorkGroupSize =
 dyn_cast(TmplAttr)) {
   instantiateDependentAMDGPUWavesPerEUAttr(*this, TemplateArgs,
*AMDGPUFlatWorkGroupSize, New);
@@ -537,7 +535,7 @@ void Sema::InstantiateAttrs(const MultiL
   }
 }
 
-if (auto ABIAttr = dyn_cast(TmplAttr)) {
+if (const auto *ABIAttr = dyn_cast(TmplAttr)) {
   AddParameterABIAttr(ABIAttr->getRange(), New, ABIAttr->getABI(),
   ABIAttr->getSpellingListIndex());
   continue;


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


[PATCH] D63325: [Support][Time profiler] Make FE codegen blocks to be inside frontend blocks

2019-08-23 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a comment.

Done, thanks for looking into this!

F9847579: check-time-trace-sections.json 


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63325



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


[PATCH] D66621: [clang] Devirtualization for classes with destructors marked as 'final'

2019-08-23 Thread Hiroshi Yamauchi via Phabricator via cfe-commits
yamauchi added a comment.

Nice.

In D66621#1642142 , @rsmith wrote:

> This seems subtle, but I believe it is correct.
>
> I wonder whether we should provide a warning for a non-final class has a 
> final destructor, since moving the `final` from the destructor to the class 
> seems like a more obvious way to present the code (and will likely lead to 
> better code generation in compilers that haven't realized they can do this).


Richard, do you think there may be some missed devirtualization optimizations 
that would trigger if the class, rather than the destructor, is declared final 
in Clang? It seems this patch would take care of common call devirtualizations.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66621



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


[PATCH] D66538: [AST] AST structural equivalence to work internally with pairs.

2019-08-23 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

In D66538#1642883 , @martong wrote:

> There is a third test which could be useful to test whether there is no 
> faulty cache entries there:
>
>   +TEST_F(StructuralEquivalenceCacheTest, DISABLED_NonEq) {
>   ...
>   +}
>


This is somewhat the same check that is done in the current tests when the 
`NonEquivalentDecls` is checked to not contain any pairs of equivalent Decls. 
(Specially this line:

  EXPECT_FALSE(isInNonEqCache(
findDeclPair(TU, functionDecl(hasName("x");

)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66538



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


[PATCH] D62131: [ASTImporter] Remove NonEquivalentDecls from ASTImporter

2019-08-23 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

> ... it is highly probable that if some pairs were ever non-equivalent they 
> will stay non-equivalent.

This may not be true in case of LLDB, because usually they do a minimal import, 
and in a later phase they do a normal import which imports e.g. the members of 
a class.
Clearly, in this case it is wrong to cache non-equivalent decls.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62131



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


[PATCH] D62131: [ASTImporter] Remove NonEquivalentDecls from ASTImporter

2019-08-23 Thread Gabor Marton via Phabricator via cfe-commits
martong abandoned this revision.
martong added a comment.

@a_sidorin Alexei,

With Balazs we had a long discussion and I think we reached a consensus and 
common understanding. Now I try to summarize it.

It turned out that this patch essentially renders the `NonEquivalentDecls` 
cache to be completely disabled, i.e. we never have a cache hit. (I tried an 
example test run with an assertion enabled for the cache hit.)
This is because in `Finish()`, when we find the first non-equivalent pair then 
we immediately break out from the while loop which pops out elements from the 
queue. This means we do not consider any elements left in the queue after this, 
so the "local" cache is never going to be used again.
This, however, explains why did we have better results with this patch: the 
cache was disabled, so those faulty entries which were cached (see Balazs's 
example above) could not cause a faulty behavior.

Secondly, I tried to fabricate a test case where the change of the redecl chain 
could render previously non-equivalent pairs to be equivalent. I could not 
create such. I also executed an experiment on llvm/master to see in case of a 
cache hit whether we would get a different result without the cache:

 // Check whether we already know that these two declarations are not
 // structurally equivalent.
 if (Context.NonEquivalentDecls.count(
  -  std::make_pair(D1->getCanonicalDecl(), D2->getCanonicalDecl(
  +  std::make_pair(D1->getCanonicalDecl(), D2->getCanonicalDecl( {
  +llvm::errs() << "Cache hit\n";
  +llvm::DenseSet> LocalNeqDecls;
  +StructuralEquivalenceContext LocalCtx(Context.FromCtx, Context.ToCtx,
  + LocalNeqDecls, Context.EqKind, false,
  + false, false);
  +assert(!LocalCtx.IsEquivalent(D1, D2));
   return false;
  +  }

The added assertion did not fire. (I executed it on Xerces for a ~100 TUs). So, 
it is highly probable that if some pairs were ever non-equivalent they will 
stay non-equivalent.
This is not true, however, the other way around. Equivalent decls may become 
non-equivalent (e.g. a fwd decl is being completed).

To solve the issue that is found by Balazs, I suggest to move on with 
https://reviews.llvm.org/D66538 and abandon this patch.
An alternative solution would be to cache after the `Finish()` has returned, 
but I prefer D66538  because it makes the 
whole algorithm simpler, plus we can get rid of the redecleration chain check. 
By getting rid of that, I believe we can have a more robust import mechanism, 
which is more resistant to lookup errors. ATM, if we have a lookup error then 
we end up having two identical declarations in different redecl chains, which 
may initiate a NameConflict error avalanche. With D66538 
 we can avoid that.

As a next step, probably we should remove the cache because it complicates the 
code and the added performance value is not recognizable. If you'd like I can 
do measurements to investigate the performance difference. However, on our 
internal fork we disabled the cache entirely for quite a long time (this patch 
is originated from there) and we did not experience any noticeable performance 
degradation during the analysis.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62131



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


[PATCH] D66538: [AST] AST structural equivalence to work internally with pairs.

2019-08-23 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 216851.
balazske added a comment.

- Updated tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66538

Files:
  clang/include/clang/AST/ASTStructuralEquivalence.h
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/unittests/AST/StructuralEquivalenceTest.cpp

Index: clang/unittests/AST/StructuralEquivalenceTest.cpp
===
--- clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1273,6 +1273,132 @@
   classTemplateSpecializationDecl(hasName("Primary")));
   EXPECT_FALSE(testStructuralMatch(t));
 }
+struct StructuralEquivalenceCacheTest : public StructuralEquivalenceTest {
+  llvm::DenseSet> NonEquivalentDecls;
+
+  template 
+  std::tuple
+  findDeclPair(std::tuple TU,
+   MatcherType M) {
+NodeType *D0 = FirstDeclMatcher().match(get<0>(TU), M);
+NodeType *D1 = FirstDeclMatcher().match(get<1>(TU), M);
+return std::make_tuple(D0, D1);
+  }
+
+  template 
+  bool isInNonEqCache(std::tuple D) {
+return NonEquivalentDecls.find(std::make_pair(get<0>(D), get<1>(D))) !=
+   NonEquivalentDecls.end();
+  }
+};
+
+TEST_F(StructuralEquivalenceCacheTest, SimpleNonEq) {
+  auto TU = makeTuDecls(
+  R"(
+  class A {};
+  class B {};
+  void x(A, A);
+  )",
+  R"(
+  class A {};
+  class B {};
+  void x(A, B);
+  )",
+  Lang_CXX);
+
+  StructuralEquivalenceContext Ctx(
+  get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
+  NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
+  auto X = findDeclPair(TU, functionDecl(hasName("x")));
+  bool Eq = Ctx.IsEquivalent(get<0>(X), get<1>(X));
+  EXPECT_FALSE(Eq);
+
+  EXPECT_FALSE(isInNonEqCache(findDeclPair(
+  TU, cxxRecordDecl(hasName("A"), unless(isImplicit());
+  EXPECT_FALSE(isInNonEqCache(findDeclPair(
+  TU, cxxRecordDecl(hasName("B"), unless(isImplicit());
+}
+
+TEST_F(StructuralEquivalenceCacheTest, SpecialNonEq) {
+  auto TU = makeTuDecls(
+  R"(
+  class A {};
+  class B { int i; };
+  void x(A *);
+  void y(A *);
+  class C {
+friend void x(A *);
+friend void y(A *);
+  };
+  )",
+  R"(
+  class A {};
+  class B { int i; };
+  void x(A *);
+  void y(B *);
+  class C {
+friend void x(A *);
+friend void y(B *);
+  };
+  )",
+  Lang_CXX);
+
+  TranslationUnitDecl *TU0 = get<0>(TU);
+  TranslationUnitDecl *TU1 = get<1>(TU);
+
+  StructuralEquivalenceContext Ctx(
+  TU0->getASTContext(), TU1->getASTContext(), NonEquivalentDecls,
+  StructuralEquivalenceKind::Default, false, false);
+  auto C = findDeclPair(
+  TU, cxxRecordDecl(hasName("C"), unless(isImplicit(;
+  bool Eq = Ctx.IsEquivalent(get<0>(C), get<1>(C));
+  EXPECT_FALSE(Eq);
+
+  EXPECT_FALSE(isInNonEqCache(C));
+  EXPECT_FALSE(isInNonEqCache(findDeclPair(
+  TU, cxxRecordDecl(hasName("A"), unless(isImplicit());
+  EXPECT_FALSE(isInNonEqCache(findDeclPair(
+  TU, cxxRecordDecl(hasName("B"), unless(isImplicit());
+  EXPECT_FALSE(isInNonEqCache(
+  findDeclPair(TU, functionDecl(hasName("x");
+  EXPECT_FALSE(isInNonEqCache(
+  findDeclPair(TU, functionDecl(hasName("y");
+}
+
+TEST_F(StructuralEquivalenceCacheTest, Cycle) {
+  auto TU = makeTuDecls(
+  R"(
+  class C;
+  class A { C *c; };
+  void x(A *);
+  class C {
+friend void x(A *);
+  };
+  )",
+  R"(
+  class C;
+  class A { C *c; };
+  void x(A *);
+  class C {
+friend void x(A *);
+  };
+  )",
+  Lang_CXX);
+
+  StructuralEquivalenceContext Ctx(
+  get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
+  NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
+  auto C = findDeclPair(
+  TU, cxxRecordDecl(hasName("C"), unless(isImplicit(;
+  bool Eq = Ctx.IsEquivalent(get<0>(C), get<1>(C));
+  EXPECT_TRUE(Eq);
+
+  EXPECT_FALSE(isInNonEqCache(C));
+  EXPECT_FALSE(isInNonEqCache(findDeclPair(
+  TU, cxxRecordDecl(hasName("A"), unless(isImplicit());
+  EXPECT_FALSE(isInNonEqCache(
+  findDeclPair(TU, functionDecl(hasName("x");
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1574,20 +1574,24 @@
  Decl *D1, Decl *D2) {
   // FIXME: Check for known structural equivalences via a callback of some sort.
 
+  D1 = D1->getCanonicalDecl();
+  D2 = D2->getCanonicalDecl();
+  std::pair P = std::make_pair(D1, D2);
+
   // Check whether we already know that these two 

[PATCH] D65065: [clang-tidy] Possibility of displaying duplicate warnings

2019-08-23 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369763: [clang-tidy] Possibility of displaying duplicate 
warnings (authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65065?vs=215122=216849#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65065

Files:
  clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp


Index: clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s cert-err09-cpp,cert-err61-cpp %t
+
+void alwaysThrows() {
+  int ex = 42;
+  // CHECK-MESSAGES: warning: throw expression should throw anonymous 
temporary values instead [cert-err09-cpp]
+  // CHECK-MESSAGES: warning: throw expression should throw anonymous 
temporary values instead [cert-err61-cpp]
+  throw ex;
+}
+
+void doTheJob() {
+  try {
+alwaysThrows();
+  } catch (int&) {
+  }
+}
Index: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -742,8 +742,9 @@
 const tooling::DiagnosticMessage  = LHS.Message;
 const tooling::DiagnosticMessage  = RHS.Message;
 
-return std::tie(M1.FilePath, M1.FileOffset, M1.Message) <
-   std::tie(M2.FilePath, M2.FileOffset, M2.Message);
+return
+  std::tie(M1.FilePath, M1.FileOffset, LHS.DiagnosticName, M1.Message) <
+  std::tie(M2.FilePath, M2.FileOffset, RHS.DiagnosticName, M2.Message);
   }
 };
 struct EqualClangTidyError {


Index: clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s cert-err09-cpp,cert-err61-cpp %t
+
+void alwaysThrows() {
+  int ex = 42;
+  // CHECK-MESSAGES: warning: throw expression should throw anonymous temporary values instead [cert-err09-cpp]
+  // CHECK-MESSAGES: warning: throw expression should throw anonymous temporary values instead [cert-err61-cpp]
+  throw ex;
+}
+
+void doTheJob() {
+  try {
+alwaysThrows();
+  } catch (int&) {
+  }
+}
Index: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -742,8 +742,9 @@
 const tooling::DiagnosticMessage  = LHS.Message;
 const tooling::DiagnosticMessage  = RHS.Message;
 
-return std::tie(M1.FilePath, M1.FileOffset, M1.Message) <
-   std::tie(M2.FilePath, M2.FileOffset, M2.Message);
+return
+  std::tie(M1.FilePath, M1.FileOffset, LHS.DiagnosticName, M1.Message) <
+  std::tie(M2.FilePath, M2.FileOffset, RHS.DiagnosticName, M2.Message);
   }
 };
 struct EqualClangTidyError {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r369763 - [clang-tidy] Possibility of displaying duplicate warnings

2019-08-23 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Fri Aug 23 07:57:27 2019
New Revision: 369763

URL: http://llvm.org/viewvc/llvm-project?rev=369763=rev
Log:
[clang-tidy] Possibility of displaying duplicate warnings

Summary: In case a checker is registered multiple times as an alias, the 
emitted warnings are uniqued by the report message. However, it is random which 
checker name is included in the warning. When processing the output of 
clang-tidy this behavior caused some problems. In this commit the uniquing key 
contains the checker name too.

Reviewers: alexfh, xazax.hun, Szelethus, aaron.ballman, lebedev.ri, JonasToth, 
gribozavr

Reviewed By: alexfh

Subscribers: dkrupp, whisperity, rnkovacs, mgrang, cfe-commits

Patch by Tibor Brunner!

Tags: #clang

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

Added:
clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=369763=369762=369763=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Fri Aug 
23 07:57:27 2019
@@ -742,8 +742,9 @@ struct LessClangTidyError {
 const tooling::DiagnosticMessage  = LHS.Message;
 const tooling::DiagnosticMessage  = RHS.Message;
 
-return std::tie(M1.FilePath, M1.FileOffset, M1.Message) <
-   std::tie(M2.FilePath, M2.FileOffset, M2.Message);
+return
+  std::tie(M1.FilePath, M1.FileOffset, LHS.DiagnosticName, M1.Message) <
+  std::tie(M2.FilePath, M2.FileOffset, RHS.DiagnosticName, M2.Message);
   }
 };
 struct EqualClangTidyError {

Added: clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp?rev=369763=auto
==
--- clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/duplicate-reports.cpp Fri Aug 23 
07:57:27 2019
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s cert-err09-cpp,cert-err61-cpp %t
+
+void alwaysThrows() {
+  int ex = 42;
+  // CHECK-MESSAGES: warning: throw expression should throw anonymous 
temporary values instead [cert-err09-cpp]
+  // CHECK-MESSAGES: warning: throw expression should throw anonymous 
temporary values instead [cert-err61-cpp]
+  throw ex;
+}
+
+void doTheJob() {
+  try {
+alwaysThrows();
+  } catch (int&) {
+  }
+}


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


[PATCH] D62131: [ASTImporter] Remove NonEquivalentDecls from ASTImporter

2019-08-23 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added a comment.

In D62131#1639168 , @balazske wrote:

> Example about how to get wrong things into `NonEquivalentDecls`:
>  We want to compare `class C` for structural equivalence in the following 
> codes:
>
>   class A {}; class B {int i;}; void x(A *); void y(A *); class C { friend 
> void x(A *); friend void y(A *); };
>
>
> and
>
>   class A {}; class B {int i;}; void x(A *); void y(B *); class C { friend 
> void x(A *); friend void y(B *); };
>
>
> The result is false for `C` but the `NonEquivalentDecls` will contain after 
> the compare a `void x(A*)`<->`void x(A*)` pair.
>
> The reason is that during the check we encounter first a `A`<->`B` pair 
> (iterating over the friends and friend functions, first `y` is encountered 
> and a check for `A` and `B` follows). The `B` is recorded as "tentative 
> equivalence" to `A`. Then we try to check `A` to `A` (during check of `x`) 
> but because there is a "tentative equivalence" with `B` from `A` the check 
> returns false (not equivalent). This false result is recorded as a 
> (incorrect) non-equivalence of the two `x` functions.
>  I want to replace the `DeclsToCheck` and `TentativeEquivalences` with a set 
> of `Decl` pairs (like the NonEquivalentDecls) so it will be possible to 
> record the same **from** Decl with multiple **to** values. (Is there a reason 
> for why there is a `NonEquivalentDecls` cache but not a `EquivalentDecls` or 
> simply a cache for result values?)


Yes, this is indeed a problem. But it is independent from the original problem 
this patch intends to solve.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62131



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


[PATCH] D66538: [AST] AST structural equivalence to work internally with pairs.

2019-08-23 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

There is a third test which could be useful to test whether there is no faulty 
cache entries there:

  +TEST_F(StructuralEquivalenceCacheTest, DISABLED_NonEq) {
  +  auto Decls =
  +  makeTuDecls(
  +  R"(
  +class A {};
  +class B {
  +  int i;
  +};
  +void x(A *);
  +void y(A *);
  +class C {
  +  friend void x(A *);
  +  friend void y(A *);
  +};
  +  )",
  +  R"(
  +class A {};
  +class B {
  +  int i;
  +};
  +void x(A *);
  +void y(B *);
  +class C {
  +  friend void x(A *);
  +  friend void y(B *);
  +};
  +  )", Lang_CXX);
  +
  +  TranslationUnitDecl *TU1 = get<0>(Decls);
  +  TranslationUnitDecl *TU2 = get<1>(Decls);
  +  auto *C1 = LastDeclMatcher().match(
  +  TU1, cxxRecordDecl(hasName("C"), unless(isImplicit(;
  +  auto *C2 = LastDeclMatcher().match(
  +  TU2, cxxRecordDecl(hasName("C"), unless(isImplicit(;
  +  auto *x1 =
  +  FirstDeclMatcher().match(TU1, 
functionDecl(hasName("x")));
  +  auto *x2 =
  +  FirstDeclMatcher().match(TU2, 
functionDecl(hasName("x")));
  +
  +  llvm::DenseSet> NonEquivalentDecls;
  +  {
  +StructuralEquivalenceContext Ctx(
  +C1->getASTContext(), C2->getASTContext(), NonEquivalentDecls,
  +StructuralEquivalenceKind::Default, false, false);
  +EXPECT_FALSE(Ctx.IsEquivalent(C1, C2));
  +  }
  +
  +  // Reuse the cache.
  +  {
  +StructuralEquivalenceContext Ctx(
  +C1->getASTContext(), C2->getASTContext(), NonEquivalentDecls,
  +StructuralEquivalenceKind::Default, false, false);
  +EXPECT_TRUE(Ctx.IsEquivalent(x1, x2));
  +  }
  +}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66538



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


[PATCH] D66653: [clang-format] Turn include regrouping on for Google ObjC style

2019-08-23 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D66653



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


[PATCH] D66653: [clang-format] Turn include regrouping on for Google ObjC style

2019-08-23 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Turns back include regrouping for Google ObjC style


Repository:
  rC Clang

https://reviews.llvm.org/D66653

Files:
  lib/Format/Format.cpp
  unittests/Format/SortIncludesTest.cpp


Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -653,18 +653,6 @@
   EXPECT_EQ(Code, sort(Code, "input.h", 0));
 }
 
-
-TEST_F(SortIncludesTest, DoNotRegroupGroupsInGoogleObjCStyle) {
-  FmtStyle = getGoogleStyle(FormatStyle::LK_ObjC);
-
-  EXPECT_EQ("#include \n"
-"#include \n"
-"#include \"a.h\"",
-sort("#include \n"
- "#include \n"
- "#include \"a.h\""));
-}
-
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -898,11 +898,6 @@
   } else if (Language == FormatStyle::LK_ObjC) {
 GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
 GoogleStyle.ColumnLimit = 100;
-// "Regroup" doesn't work well for ObjC yet (main header heuristic,
-// relationship between ObjC standard library headers and other heades,
-// #imports, etc.)
-GoogleStyle.IncludeStyle.IncludeBlocks =
-tooling::IncludeStyle::IBS_Preserve;
   }
 
   return GoogleStyle;


Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -653,18 +653,6 @@
   EXPECT_EQ(Code, sort(Code, "input.h", 0));
 }
 
-
-TEST_F(SortIncludesTest, DoNotRegroupGroupsInGoogleObjCStyle) {
-  FmtStyle = getGoogleStyle(FormatStyle::LK_ObjC);
-
-  EXPECT_EQ("#include \n"
-"#include \n"
-"#include \"a.h\"",
-sort("#include \n"
- "#include \n"
- "#include \"a.h\""));
-}
-
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -898,11 +898,6 @@
   } else if (Language == FormatStyle::LK_ObjC) {
 GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
 GoogleStyle.ColumnLimit = 100;
-// "Regroup" doesn't work well for ObjC yet (main header heuristic,
-// relationship between ObjC standard library headers and other heades,
-// #imports, etc.)
-GoogleStyle.IncludeStyle.IncludeBlocks =
-tooling::IncludeStyle::IBS_Preserve;
   }
 
   return GoogleStyle;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66014: [analyzer] Avoid unnecessary enum range check on LValueToRValue casts

2019-08-23 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

I seem to have been able to put this together by fetching the individual diffs 
and squashing them this time :)


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66014



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


[PATCH] D66397: [Diagnostics] Improve -Wxor-used-as-pow

2019-08-23 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

I am strongly in favour to just land this as is. :)


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

https://reviews.llvm.org/D66397



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


[PATCH] D66014: [analyzer] Avoid unnecessary enum range check on LValueToRValue casts

2019-08-23 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL369760: [analyzer] Avoid unnecessary enum range check on 
LValueToRValue casts (authored by Szelethus, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66014?vs=215433=216842#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66014

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
  cfe/trunk/test/Analysis/enum-cast-out-of-range.c
  cfe/trunk/test/Analysis/enum-cast-out-of-range.cpp


Index: cfe/trunk/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
@@ -91,6 +91,22 @@
 
 void EnumCastOutOfRangeChecker::checkPreStmt(const CastExpr *CE,
  CheckerContext ) const {
+
+  // Only perform enum range check on casts where such checks are valid.  For
+  // all other cast kinds (where enum range checks are unnecessary or invalid),
+  // just return immediately.  TODO: The set of casts whitelisted for enum
+  // range checking may be incomplete.  Better to add a missing cast kind to
+  // enable a missing check than to generate false negatives and have to remove
+  // those later.
+  switch (CE->getCastKind()) {
+  case CK_IntegralCast:
+break;
+
+  default:
+return;
+break;
+  }
+
   // Get the value of the expression to cast.
   const llvm::Optional ValueToCast =
   C.getSVal(CE->getSubExpr()).getAs();
Index: cfe/trunk/test/Analysis/enum-cast-out-of-range.c
===
--- cfe/trunk/test/Analysis/enum-cast-out-of-range.c
+++ cfe/trunk/test/Analysis/enum-cast-out-of-range.c
@@ -0,0 +1,34 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:   -analyzer-checker=core,alpha.cplusplus.EnumCastOutOfRange \
+// RUN:   -verify %s
+
+enum En_t {
+  En_0 = -4,
+  En_1,
+  En_2 = 1,
+  En_3,
+  En_4 = 4
+};
+
+void unscopedUnspecifiedCStyle() {
+  enum En_t Below = (enum En_t)(-5);// expected-warning {{not in the valid 
range}}
+  enum En_t NegVal1 = (enum En_t)(-4);  // OK.
+  enum En_t NegVal2 = (enum En_t)(-3);  // OK.
+  enum En_t InRange1 = (enum En_t)(-2); // expected-warning {{not in the valid 
range}}
+  enum En_t InRange2 = (enum En_t)(-1); // expected-warning {{not in the valid 
range}}
+  enum En_t InRange3 = (enum En_t)(0);  // expected-warning {{not in the valid 
range}}
+  enum En_t PosVal1 = (enum En_t)(1);   // OK.
+  enum En_t PosVal2 = (enum En_t)(2);   // OK.
+  enum En_t InRange4 = (enum En_t)(3);  // expected-warning {{not in the valid 
range}}
+  enum En_t PosVal3 = (enum En_t)(4);   // OK.
+  enum En_t Above = (enum En_t)(5); // expected-warning {{not in the valid 
range}}
+}
+
+enum En_t unused;
+void unusedExpr() {
+  // Following line is not something that EnumCastOutOfRangeChecker should
+  // evaluate.  Checker should either ignore this line or process it without
+  // producing any warnings.  However, compilation will (and should) still
+  // generate a warning having nothing to do with this checker.
+  unused; // expected-warning {{expression result unused}}
+}
Index: cfe/trunk/test/Analysis/enum-cast-out-of-range.cpp
===
--- cfe/trunk/test/Analysis/enum-cast-out-of-range.cpp
+++ cfe/trunk/test/Analysis/enum-cast-out-of-range.cpp
@@ -150,7 +150,15 @@
   scoped_specified_t InvalidAfterRangeEnd = (scoped_specified_t)(5); // 
expected-warning {{The value provided to the cast expression is not in the 
valid range of values for the enum}}
 }
 
-void rangeContstrained1(int input) {
+unscoped_unspecified_t unused;
+void unusedExpr() {
+  // following line is not something that EnumCastOutOfRangeChecker should 
evaluate.  checker should either ignore this line
+  // or process it without producing any warnings.  However, compilation will 
(and should) still generate a warning having
+  // nothing to do with this checker.
+  unused; // expected-warning {{expression result unused}}
+}
+
+void rangeConstrained1(int input) {
   if (input > -5 && input < 5)
 auto value = static_cast(input); // OK. Being 
conservative, this is a possibly good value.
 }


Index: cfe/trunk/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
@@ -91,6 +91,22 @@
 
 void EnumCastOutOfRangeChecker::checkPreStmt(const CastExpr *CE,
  CheckerContext ) const {
+
+  // Only perform enum range check on casts 

r369760 - [analyzer] Avoid unnecessary enum range check on LValueToRValue casts

2019-08-23 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Fri Aug 23 07:21:13 2019
New Revision: 369760

URL: http://llvm.org/viewvc/llvm-project?rev=369760=rev
Log:
[analyzer] Avoid unnecessary enum range check on LValueToRValue casts

Summary: EnumCastOutOfRangeChecker should not perform enum range checks on 
LValueToRValue casts, since this type of cast does not actually change the 
underlying type.   Performing the unnecessary check actually triggered an 
assertion failure deeper in EnumCastOutOfRange for certain input (which is 
captured in the accompanying test code).

Reviewers: #clang, Szelethus, gamesh411, NoQ

Reviewed By: Szelethus, gamesh411, NoQ

Subscribers: NoQ, gamesh411, xazax.hun, baloghadamsoftware, szepet, a.sidorin, 
mikhail.ramalho, donat.nagy, dkrupp, Charusso, bjope, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/Analysis/enum-cast-out-of-range.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
cfe/trunk/test/Analysis/enum-cast-out-of-range.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp?rev=369760=369759=369760=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp 
(original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp Fri Aug 
23 07:21:13 2019
@@ -91,6 +91,22 @@ void EnumCastOutOfRangeChecker::reportWa
 
 void EnumCastOutOfRangeChecker::checkPreStmt(const CastExpr *CE,
  CheckerContext ) const {
+
+  // Only perform enum range check on casts where such checks are valid.  For
+  // all other cast kinds (where enum range checks are unnecessary or invalid),
+  // just return immediately.  TODO: The set of casts whitelisted for enum
+  // range checking may be incomplete.  Better to add a missing cast kind to
+  // enable a missing check than to generate false negatives and have to remove
+  // those later.
+  switch (CE->getCastKind()) {
+  case CK_IntegralCast:
+break;
+
+  default:
+return;
+break;
+  }
+
   // Get the value of the expression to cast.
   const llvm::Optional ValueToCast =
   C.getSVal(CE->getSubExpr()).getAs();

Added: cfe/trunk/test/Analysis/enum-cast-out-of-range.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/enum-cast-out-of-range.c?rev=369760=auto
==
--- cfe/trunk/test/Analysis/enum-cast-out-of-range.c (added)
+++ cfe/trunk/test/Analysis/enum-cast-out-of-range.c Fri Aug 23 07:21:13 2019
@@ -0,0 +1,34 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:   -analyzer-checker=core,alpha.cplusplus.EnumCastOutOfRange \
+// RUN:   -verify %s
+
+enum En_t {
+  En_0 = -4,
+  En_1,
+  En_2 = 1,
+  En_3,
+  En_4 = 4
+};
+
+void unscopedUnspecifiedCStyle() {
+  enum En_t Below = (enum En_t)(-5);// expected-warning {{not in the valid 
range}}
+  enum En_t NegVal1 = (enum En_t)(-4);  // OK.
+  enum En_t NegVal2 = (enum En_t)(-3);  // OK.
+  enum En_t InRange1 = (enum En_t)(-2); // expected-warning {{not in the valid 
range}}
+  enum En_t InRange2 = (enum En_t)(-1); // expected-warning {{not in the valid 
range}}
+  enum En_t InRange3 = (enum En_t)(0);  // expected-warning {{not in the valid 
range}}
+  enum En_t PosVal1 = (enum En_t)(1);   // OK.
+  enum En_t PosVal2 = (enum En_t)(2);   // OK.
+  enum En_t InRange4 = (enum En_t)(3);  // expected-warning {{not in the valid 
range}}
+  enum En_t PosVal3 = (enum En_t)(4);   // OK.
+  enum En_t Above = (enum En_t)(5); // expected-warning {{not in the valid 
range}}
+}
+
+enum En_t unused;
+void unusedExpr() {
+  // Following line is not something that EnumCastOutOfRangeChecker should
+  // evaluate.  Checker should either ignore this line or process it without
+  // producing any warnings.  However, compilation will (and should) still
+  // generate a warning having nothing to do with this checker.
+  unused; // expected-warning {{expression result unused}}
+}

Modified: cfe/trunk/test/Analysis/enum-cast-out-of-range.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/enum-cast-out-of-range.cpp?rev=369760=369759=369760=diff
==
--- cfe/trunk/test/Analysis/enum-cast-out-of-range.cpp (original)
+++ cfe/trunk/test/Analysis/enum-cast-out-of-range.cpp Fri Aug 23 07:21:13 2019
@@ -150,7 +150,15 @@ void scopedSpecifiedCStyle() {
   scoped_specified_t InvalidAfterRangeEnd = (scoped_specified_t)(5); // 
expected-warning {{The value provided to the cast expression is not in the 
valid range of values for the enum}}
 }
 
-void rangeContstrained1(int input) {
+unscoped_unspecified_t unused;
+void unusedExpr() {
+  // following line is not something that 

[PATCH] D66397: [Diagnostics] Improve -Wxor-used-as-pow

2019-08-23 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a subscriber: regehr.
xbolva00 added a comment.

>> I now agree that it makes sense to warn when the operands are macros or 
>> variables.

I could re-add macro support and then @jfb or @regehr would blame this 
diagnostic because of macro support =] variables could open a new box of false 
positives.

Anyway, your motivating case:

>> minval -= 10 ^ -precision;  // 
>> https://codesearch.isocpp.org/actcd19/main/q/qgis/qgis_2.18.28+dfsg-2/src/gui/editorwidgets/qgsrangewidgetwrapper.cpp

This should be diagnosted. Location of "-" is not a macro.

>> real_loop += (((unsigned int) *argv[4]+k) - 48) * 10^(strlen(argv[4]) - 
>> (k+1));

Too complex, no chance to diagnose it here :) Not related to macros.

>> intermediate = (str[offset] - '0') / (10 ^ lpc);  // 
>> https://codesearch.isocpp.org/actcd19/main/p/pacemaker/pacemaker_1.1.18-2/lib/common/iso8601.c

lpc is not a macro, it is just loop int variable. Not related to macros.


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

https://reviews.llvm.org/D66397



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


[PATCH] D66652: [libTooling] Transformer: refine `SourceLocation` specified as anchor of changes.

2019-08-23 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 216838.
ymandel added a comment.

comment tweaks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66652

Files:
  clang/include/clang/Tooling/Refactoring/Transformer.h
  clang/lib/Tooling/Refactoring/Transformer.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -710,6 +710,57 @@
   testRule(ruleStrlenSize(), Input, Expected);
 }
 
+// Tests that two changes in a single macro expansion do not lead to conflicts
+// in applying the changes.
+TEST_F(TransformerTest, TwoChangesInOneMacroExpansion) {
+  std::string Input = R"cc(
+#define PLUS(a,b) (a) + (b)
+int f() { return PLUS(3, 4); }
+  )cc";
+  std::string Expected = R"cc(
+#define PLUS(a,b) (a) + (b)
+int f() { return PLUS(LIT, LIT); }
+  )cc";
+
+  testRule(makeRule(integerLiteral(), change(text("LIT"))), Input, Expected);
+}
+
+// Tests case where the rule's match spans both source from the macro and its
+// arg, with the begin location (the "anchor") being the arg.
+TEST_F(TransformerTest, MatchSpansMacroTextButChangeDoesNot) {
+  std::string Input = R"cc(
+#define PLUS_ONE(a) a + 1
+int f() { return PLUS_ONE(3); }
+  )cc";
+  std::string Expected = R"cc(
+#define PLUS_ONE(a) a + 1
+int f() { return PLUS_ONE(LIT); }
+  )cc";
+
+  StringRef E = "expr";
+  testRule(makeRule(binaryOperator(hasLHS(expr().bind(E))),
+change(node(E), text("LIT"))),
+   Input, Expected);
+}
+
+// Tests case where the rule's match spans both source from the macro and its
+// arg, with the begin location (the "anchor") being inside the macro.
+TEST_F(TransformerTest, MatchSpansMacroTextButChangeDoesNotAnchoredInMacro) {
+  std::string Input = R"cc(
+#define PLUS_ONE(a) 1 + a
+int f() { return PLUS_ONE(3); }
+  )cc";
+  std::string Expected = R"cc(
+#define PLUS_ONE(a) 1 + a
+int f() { return PLUS_ONE(LIT); }
+  )cc";
+
+  StringRef E = "expr";
+  testRule(makeRule(binaryOperator(hasRHS(expr().bind(E))),
+change(node(E), text("LIT"))),
+   Input, Expected);
+}
+
 // No rewrite is applied when the changed text does not encompass the entirety
 // of the expanded text. That is, the edit would have to be applied to the
 // macro's definition to succeed and editing the expansion point would not
Index: clang/lib/Tooling/Refactoring/Transformer.cpp
===
--- clang/lib/Tooling/Refactoring/Transformer.cpp
+++ clang/lib/Tooling/Refactoring/Transformer.cpp
@@ -150,6 +150,22 @@
   return Ms[0];
 }
 
+SourceLocation tooling::detail::getRuleMatchLoc(const MatchResult ) {
+  // Verify the existence and validity of the AST node that roots this rule.
+  auto  = Result.Nodes.getMap();
+  auto Root = NodesMap.find(RewriteRule::RootID);
+  assert(Root != NodesMap.end() && "Transformation failed: missing root node.");
+  llvm::Optional RootRange = getRangeForEdit(
+  CharSourceRange::getTokenRange(Root->second.getSourceRange()),
+  *Result.Context);
+  if (RootRange)
+return RootRange->getBegin();
+  // The match doens't have a coherent range, so fall back to the expansion
+  // location as the "beginning" of the match.
+  return Result.SourceManager->getExpansionLoc(
+  Root->second.getSourceRange().getBegin());
+}
+
 // Finds the case that was "selected" -- that is, whose matcher triggered the
 // `MatchResult`.
 const RewriteRule::Case &
@@ -179,11 +195,7 @@
 return;
 
   // Verify the existence and validity of the AST node that roots this rule.
-  auto  = Result.Nodes.getMap();
-  auto Root = NodesMap.find(RewriteRule::RootID);
-  assert(Root != NodesMap.end() && "Transformation failed: missing root node.");
-  SourceLocation RootLoc = Result.SourceManager->getExpansionLoc(
-  Root->second.getSourceRange().getBegin());
+  SourceLocation RootLoc = tooling::detail::getRuleMatchLoc(Result);
   assert(RootLoc.isValid() && "Invalid location for Root node of match.");
 
   RewriteRule::Case Case = tooling::detail::findSelectedCase(Result, Rule);
Index: clang/include/clang/Tooling/Refactoring/Transformer.h
===
--- clang/include/clang/Tooling/Refactoring/Transformer.h
+++ clang/include/clang/Tooling/Refactoring/Transformer.h
@@ -254,6 +254,12 @@
 std::vector
 buildMatchers(const RewriteRule );
 
+/// Gets the beginning location of the source matched by a rewrite rule. If the
+/// match occurs within a macro expansion, returns the beginning of the
+/// expansion point. `Result` must come from the matching of a rewrite rule.
+SourceLocation
+getRuleMatchLoc(const ast_matchers::MatchFinder::MatchResult );
+
 /// Returns the \c Case of \c Rule 

  1   2   >