r339093 - Auto var init test fix #2

2018-08-06 Thread JF Bastien via cfe-commits
Author: jfb
Date: Mon Aug  6 21:44:13 2018
New Revision: 339093

URL: http://llvm.org/viewvc/llvm-project?rev=339093=rev
Log:
Auto var init test fix #2

It turns out that the AVX bots have different alignment for their vectors, and 
my test mistakenly assumed a particular vector alignent on the stack. Instead, 
capture the alignment and test for it in subsequent operations.

Modified:
cfe/trunk/test/CodeGenCXX/auto-var-init.cpp

Modified: cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/auto-var-init.cpp?rev=339093=339092=339093=diff
==
--- cfe/trunk/test/CodeGenCXX/auto-var-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/auto-var-init.cpp Mon Aug  6 21:44:13 2018
@@ -946,53 +946,53 @@ TEST_BRACES(intvec16, int  __attribute__
 
 TEST_UNINIT(longlongvec32, long long  __attribute__((vector_size(32;
 // CHECK-LABEL: @test_longlongvec32_uninit()
-// CHECK:   %uninit = alloca <4 x i64>, align 16
+// CHECK:   %uninit = alloca <4 x i64>, align
 // CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
 
 TEST_BRACES(longlongvec32, long long  __attribute__((vector_size(32;
 // CHECK-LABEL: @test_longlongvec32_braces()
-// CHECK:   %braces = alloca <4 x i64>, align 16
-// CHECK-NEXT:  store <4 x i64> zeroinitializer, <4 x i64>* %braces, align 16
+// CHECK:   %braces = alloca <4 x i64>, align [[ALIGN:[0-9]*]]
+// CHECK-NEXT:  store <4 x i64> zeroinitializer, <4 x i64>* %braces, align 
[[ALIGN]]
 // CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
 
 TEST_CUSTOM(longlongvec32, long long  __attribute__((vector_size(32))), { 
0x, 0x, 0x, 0x 
});
 // CHECK-LABEL: @test_longlongvec32_custom()
-// CHECK:   %custom = alloca <4 x i64>, align 16
-// CHECK-NEXT:  store <4 x i64> , <4 x 
i64>* %custom, align 16
+// CHECK:   %custom = alloca <4 x i64>, align [[ALIGN:[0-9]*]]
+// CHECK-NEXT:  store <4 x i64> , <4 x 
i64>* %custom, align [[ALIGN]]
 // CHECK-NEXT:  call void @{{.*}}used{{.*}}%custom)
 
 TEST_UNINIT(floatvec16, float  __attribute__((vector_size(16;
 // CHECK-LABEL: @test_floatvec16_uninit()
-// CHECK:   %uninit = alloca <4 x float>, align 16
+// CHECK:   %uninit = alloca <4 x float>, align
 // CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
 
 TEST_BRACES(floatvec16, float  __attribute__((vector_size(16;
 // CHECK-LABEL: @test_floatvec16_braces()
-// CHECK:   %braces = alloca <4 x float>, align 16
-// CHECK-NEXT:  store <4 x float> zeroinitializer, <4 x float>* %braces, align 
16
+// CHECK:   %braces = alloca <4 x float>, align [[ALIGN:[0-9]*]]
+// CHECK-NEXT:  store <4 x float> zeroinitializer, <4 x float>* %braces, align 
[[ALIGN]]
 // CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
 
 TEST_CUSTOM(floatvec16, float  __attribute__((vector_size(16))), { 
3.1415926535897932384626433, 3.1415926535897932384626433, 
3.1415926535897932384626433, 3.1415926535897932384626433 });
 // CHECK-LABEL: @test_floatvec16_custom()
-// CHECK:   %custom = alloca <4 x float>, align 16
-// CHECK-NEXT:  store <4 x float> , <4 x 
float>* %custom, align 16
+// CHECK:   %custom = alloca <4 x float>, align [[ALIGN:[0-9]*]]
+// CHECK-NEXT:  store <4 x float> , <4 x 
float>* %custom, align [[ALIGN]]
 // CHECK-NEXT:  call void @{{.*}}used{{.*}}%custom)
 
 TEST_UNINIT(doublevec32, double  __attribute__((vector_size(32;
 // CHECK-LABEL: @test_doublevec32_uninit()
-// CHECK:   %uninit = alloca <4 x double>, align 16
+// CHECK:   %uninit = alloca <4 x double>, align
 // CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
 
 TEST_BRACES(doublevec32, double  __attribute__((vector_size(32;
 // CHECK-LABEL: @test_doublevec32_braces()
-// CHECK:   %braces = alloca <4 x double>, align 16
-// CHECK-NEXT:  store <4 x double> zeroinitializer, <4 x double>* %braces, 
align 16
+// CHECK:   %braces = alloca <4 x double>, align [[ALIGN:[0-9]*]]
+// CHECK-NEXT:  store <4 x double> zeroinitializer, <4 x double>* %braces, 
align [[ALIGN]]
 // CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
 
 TEST_CUSTOM(doublevec32, double  __attribute__((vector_size(32))), { 
3.1415926535897932384626433, 3.1415926535897932384626433, 
3.1415926535897932384626433, 3.1415926535897932384626433 });
 // CHECK-LABEL: @test_doublevec32_custom()
-// CHECK:   %custom = alloca <4 x double>, align 16
-// CHECK-NEXT:  store <4 x double> , <4 x 
double>* %custom, align 16
+// CHECK:   %custom = alloca <4 x double>, align [[ALIGN:[0-9]*]]
+// CHECK-NEXT:  store <4 x double> , <4 x 
double>* %custom, align [[ALIGN]]
 // CHECK-NEXT:  call void @{{.*}}used{{.*}}%custom)
 
 


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


[PATCH] D50088: [Sema] Fix an error with C++17 auto non-type template parameters

2018-08-06 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 159449.
erik.pilkington retitled this revision from "[Sema] Dig through AutoTypes that 
have been deduced to an undeduced AutoType in Type::isUndeducedType" to "[Sema] 
Fix an error with C++17 auto non-type template parameters".
erik.pilkington edited the summary of this revision.
erik.pilkington added a comment.

New patch uses a different approach to fix this. I edited the summary/title to 
explain. Sorry for the flip-flop!


https://reviews.llvm.org/D50088

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp


Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -335,3 +335,13 @@
   void g(int, int);
   using Int = A::B<>::param2;
 }
+
+namespace rdar41852459 {
+template  struct G {};
+
+template  struct S {
+  template  void f() {
+G x;
+  }
+};
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -974,7 +974,7 @@
 QualType Sema::CheckNonTypeTemplateParameterType(TypeSourceInfo *,
  SourceLocation Loc) {
   if (TSI->getType()->isUndeducedType()) {
-// C++1z [temp.dep.expr]p3:
+// C++17 [temp.dep.expr]p3:
 //   An id-expression is type-dependent if it contains
 //- an identifier associated by name lookup with a non-type
 //  template-parameter declared with a type that contains a
@@ -9866,6 +9866,15 @@
 if (!NewTSI)
   return true;
 
+if (NewTSI->getType()->isUndeducedType()) {
+  // C++17 [temp.dep.expr]p3:
+  //   An id-expression is type-dependent if it contains
+  //- an identifier associated by name lookup with a non-type
+  //  template-parameter declared with a type that contains a
+  //  placeholder type (7.1.7.4),
+  NewTSI = SubstAutoTypeSourceInfo(NewTSI, Context.DependentTy);
+}
+
 if (NewTSI != NTTP->getTypeSourceInfo()) {
   NTTP->setTypeSourceInfo(NewTSI);
   NTTP->setType(NewTSI->getType());


Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -335,3 +335,13 @@
   void g(int, int);
   using Int = A::B<>::param2;
 }
+
+namespace rdar41852459 {
+template  struct G {};
+
+template  struct S {
+  template  void f() {
+G x;
+  }
+};
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -974,7 +974,7 @@
 QualType Sema::CheckNonTypeTemplateParameterType(TypeSourceInfo *,
  SourceLocation Loc) {
   if (TSI->getType()->isUndeducedType()) {
-// C++1z [temp.dep.expr]p3:
+// C++17 [temp.dep.expr]p3:
 //   An id-expression is type-dependent if it contains
 //- an identifier associated by name lookup with a non-type
 //  template-parameter declared with a type that contains a
@@ -9866,6 +9866,15 @@
 if (!NewTSI)
   return true;
 
+if (NewTSI->getType()->isUndeducedType()) {
+  // C++17 [temp.dep.expr]p3:
+  //   An id-expression is type-dependent if it contains
+  //- an identifier associated by name lookup with a non-type
+  //  template-parameter declared with a type that contains a
+  //  placeholder type (7.1.7.4),
+  NewTSI = SubstAutoTypeSourceInfo(NewTSI, Context.DependentTy);
+}
+
 if (NewTSI != NTTP->getTypeSourceInfo()) {
   NTTP->setTypeSourceInfo(NewTSI);
   NTTP->setType(NewTSI->getType());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339090 - Remove broken command flag

2018-08-06 Thread JF Bastien via cfe-commits
Author: jfb
Date: Mon Aug  6 21:03:03 2018
New Revision: 339090

URL: http://llvm.org/viewvc/llvm-project?rev=339090=rev
Log:
Remove broken command flag

I was using it for testing, r339089 shouldn't have contained it.

Modified:
cfe/trunk/test/CodeGenCXX/auto-var-init.cpp

Modified: cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/auto-var-init.cpp?rev=339090=339089=339090=diff
==
--- cfe/trunk/test/CodeGenCXX/auto-var-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/auto-var-init.cpp Mon Aug  6 21:03:03 2018
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks 
-ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks %s -emit-llvm -o - 
| FileCheck %s
 
 template void used(T &) noexcept;
 


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


[PATCH] D45045: [DebugInfo] Generate debug information for labels.

2018-08-06 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai added a comment.

In https://reviews.llvm.org/D45045#1189201, @vext01 wrote:

> Hi,
>
> I've been experimenting some more with this patch.
>
> It seems to me that if a label is optimised away, but you've requested it be 
> preserved, then you get a DWARF label with a zero offset. Is that the 
> expected behaviour? Should it be documented?
>
> E.g.:
>
>   < 6><0x00dc>  DW_TAG_label
>   DW_AT_name  
> __YK_BLK_2_19418_0
>   DW_AT_low_pc0x
>
>
> Thanks!


I expect that even the code is optimized out, the label will point to somewhere 
in the function. If the whole function is optimized out, the label should not 
exist any more. It should not have address zero.

Do you have any test snippet to reproduce the bug? Thanks.


Repository:
  rL LLVM

https://reviews.llvm.org/D45045



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


[PATCH] D50361: [NFC] Test automatic variable initialization

2018-08-06 Thread JF Bastien via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339089: [NFC] Test automatic variable initialization 
(authored by jfb, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50361?vs=159397=159448#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50361

Files:
  test/CodeGenCXX/auto-var-init.cpp

Index: test/CodeGenCXX/auto-var-init.cpp
===
--- test/CodeGenCXX/auto-var-init.cpp
+++ test/CodeGenCXX/auto-var-init.cpp
@@ -0,0 +1,999 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks -ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s
+
+template void used(T &) noexcept;
+
+#define TEST_UNINIT(NAME, TYPE) \
+  using type_##NAME = TYPE; \
+  void test_##NAME##_uninit() { \
+type_##NAME uninit; \
+used(uninit);   \
+  }
+
+// Value initialization on scalars, aggregate initialization on aggregates.
+#define TEST_BRACES(NAME, TYPE) \
+  using type_##NAME = TYPE; \
+  void test_##NAME##_braces() { \
+type_##NAME braces = {};\
+used(braces);   \
+  }
+
+#define TEST_CUSTOM(NAME, TYPE, ...)\
+  using type_##NAME = TYPE; \
+  void test_##NAME##_custom() { \
+type_##NAME custom __VA_ARGS__; \
+used(custom);   \
+  }
+
+struct empty {};
+struct small { char c; };
+struct smallinit { char c = 42; };
+struct smallpartinit { char c = 42, d; };
+struct nullinit { char* null = nullptr; };
+struct padded { char c; int i; };
+struct paddednullinit { char c = 0; int i = 0; };
+struct bitfield { int i : 4; int j : 2; };
+struct bitfieldaligned { int i : 4; int : 0; int j : 2; };
+struct big { unsigned a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z; };
+struct arraytail { int i; int arr[]; };
+struct tailpad { short s; char c; };
+struct notlockfree { long long a[4]; };
+struct semivolatile { int i; volatile int vi; };
+struct semivolatileinit { int i = 0x; volatile int vi = 0x; };
+struct base { virtual ~base(); };
+struct derived : public base {};
+struct virtualderived : public virtual base, public virtual derived {};
+union matching { int i; float f; };
+union matchingreverse { float f; int i; };
+union unmatched { char c; int i; };
+union unmatchedreverse { int i; char c; };
+union unmatchedfp { float f; double d; };
+enum emptyenum {};
+enum smallenum { VALUE };
+
+extern "C" {
+
+TEST_UNINIT(char, char);
+// CHECK-LABEL: @test_char_uninit()
+// CHECK:   %uninit = alloca i8, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(char, char);
+// CHECK-LABEL: @test_char_braces()
+// CHECK:   %braces = alloca i8, align 1
+// CHECK-NEXT:  store i8 0, i8* %braces, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
+
+TEST_UNINIT(uchar, unsigned char);
+// CHECK-LABEL: @test_uchar_uninit()
+// CHECK:   %uninit = alloca i8, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(uchar, unsigned char);
+// CHECK-LABEL: @test_uchar_braces()
+// CHECK:   %braces = alloca i8, align 1
+// CHECK-NEXT:  store i8 0, i8* %braces, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
+
+TEST_UNINIT(schar, signed char);
+// CHECK-LABEL: @test_schar_uninit()
+// CHECK:   %uninit = alloca i8, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(schar, signed char);
+// CHECK-LABEL: @test_schar_braces()
+// CHECK:   %braces = alloca i8, align 1
+// CHECK-NEXT:  store i8 0, i8* %braces, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
+
+TEST_UNINIT(wchar_t, wchar_t);
+// CHECK-LABEL: @test_wchar_t_uninit()
+// CHECK:   %uninit = alloca i32, align 4
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(wchar_t, wchar_t);
+// CHECK-LABEL: @test_wchar_t_braces()
+// CHECK:   %braces = alloca i32, align 4
+// CHECK-NEXT:  store i32 0, i32* %braces, align 4
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
+
+TEST_UNINIT(short, short);
+// CHECK-LABEL: @test_short_uninit()
+// CHECK:   %uninit = alloca i16, align 2
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(short, short);
+// CHECK-LABEL: @test_short_braces()
+// CHECK:   %braces = alloca i16, align 2
+// CHECK-NEXT:  store i16 0, i16* %braces, align 2
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
+
+TEST_UNINIT(ushort, unsigned short);
+// CHECK-LABEL: @test_ushort_uninit()
+// CHECK:   %uninit = alloca i16, align 2
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(ushort, unsigned short);
+// CHECK-LABEL: @test_ushort_braces()
+// CHECK:   %braces = alloca i16, align 2
+// 

r339089 - [NFC] Test automatic variable initialization

2018-08-06 Thread JF Bastien via cfe-commits
Author: jfb
Date: Mon Aug  6 20:12:52 2018
New Revision: 339089

URL: http://llvm.org/viewvc/llvm-project?rev=339089=rev
Log:
[NFC] Test automatic variable initialization

Summary:
r337887 started using memset for automatic variable initialization where 
sensible. A follow-up discussion leads me to believe that we should better test 
automatic variable initialization, and that there are probably follow-up 
patches in clang and LLVM to improve codegen. It’ll be important to measure -O0 
compile time, and figure out which transforms should be in the frontend versus 
the backend.

This patch is just a test of the current behavior, no questions asked. 
Follow-up patches will tune the code generation.



Subscribers: dexonsmith, cfe-commits

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

Added:
cfe/trunk/test/CodeGenCXX/auto-var-init.cpp

Added: cfe/trunk/test/CodeGenCXX/auto-var-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/auto-var-init.cpp?rev=339089=auto
==
--- cfe/trunk/test/CodeGenCXX/auto-var-init.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/auto-var-init.cpp Mon Aug  6 20:12:52 2018
@@ -0,0 +1,999 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks 
-ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s
+
+template void used(T &) noexcept;
+
+#define TEST_UNINIT(NAME, TYPE) \
+  using type_##NAME = TYPE; \
+  void test_##NAME##_uninit() { \
+type_##NAME uninit; \
+used(uninit);   \
+  }
+
+// Value initialization on scalars, aggregate initialization on aggregates.
+#define TEST_BRACES(NAME, TYPE) \
+  using type_##NAME = TYPE; \
+  void test_##NAME##_braces() { \
+type_##NAME braces = {};\
+used(braces);   \
+  }
+
+#define TEST_CUSTOM(NAME, TYPE, ...)\
+  using type_##NAME = TYPE; \
+  void test_##NAME##_custom() { \
+type_##NAME custom __VA_ARGS__; \
+used(custom);   \
+  }
+
+struct empty {};
+struct small { char c; };
+struct smallinit { char c = 42; };
+struct smallpartinit { char c = 42, d; };
+struct nullinit { char* null = nullptr; };
+struct padded { char c; int i; };
+struct paddednullinit { char c = 0; int i = 0; };
+struct bitfield { int i : 4; int j : 2; };
+struct bitfieldaligned { int i : 4; int : 0; int j : 2; };
+struct big { unsigned a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, 
t, u, v, w, x, y, z; };
+struct arraytail { int i; int arr[]; };
+struct tailpad { short s; char c; };
+struct notlockfree { long long a[4]; };
+struct semivolatile { int i; volatile int vi; };
+struct semivolatileinit { int i = 0x; volatile int vi = 0x; };
+struct base { virtual ~base(); };
+struct derived : public base {};
+struct virtualderived : public virtual base, public virtual derived {};
+union matching { int i; float f; };
+union matchingreverse { float f; int i; };
+union unmatched { char c; int i; };
+union unmatchedreverse { int i; char c; };
+union unmatchedfp { float f; double d; };
+enum emptyenum {};
+enum smallenum { VALUE };
+
+extern "C" {
+
+TEST_UNINIT(char, char);
+// CHECK-LABEL: @test_char_uninit()
+// CHECK:   %uninit = alloca i8, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(char, char);
+// CHECK-LABEL: @test_char_braces()
+// CHECK:   %braces = alloca i8, align 1
+// CHECK-NEXT:  store i8 0, i8* %braces, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
+
+TEST_UNINIT(uchar, unsigned char);
+// CHECK-LABEL: @test_uchar_uninit()
+// CHECK:   %uninit = alloca i8, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(uchar, unsigned char);
+// CHECK-LABEL: @test_uchar_braces()
+// CHECK:   %braces = alloca i8, align 1
+// CHECK-NEXT:  store i8 0, i8* %braces, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
+
+TEST_UNINIT(schar, signed char);
+// CHECK-LABEL: @test_schar_uninit()
+// CHECK:   %uninit = alloca i8, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(schar, signed char);
+// CHECK-LABEL: @test_schar_braces()
+// CHECK:   %braces = alloca i8, align 1
+// CHECK-NEXT:  store i8 0, i8* %braces, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
+
+TEST_UNINIT(wchar_t, wchar_t);
+// CHECK-LABEL: @test_wchar_t_uninit()
+// CHECK:   %uninit = alloca i32, align 4
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(wchar_t, wchar_t);
+// CHECK-LABEL: @test_wchar_t_braces()
+// CHECK:   %braces = alloca i32, align 4
+// CHECK-NEXT:  store i32 0, i32* %braces, align 4
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
+
+TEST_UNINIT(short, short);
+// 

[PATCH] D50372: Introduce the VTable interleaving scheme to the CFI design documentation

2018-08-06 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

Please upload patches with context. `arc diff` will do this for you.




Comment at: clang/docs/ControlFlowIntegrityDesign.rst:277
 
+Forward-Edge CFI for Virtual Calls by Interleaving Virtual Tables
+=

I would add this as a subsection of "Forward-Edge CFI for Virtual Calls".



Comment at: clang/docs/ControlFlowIntegrityDesign.rst:286
+
+On the high level, the interleaving scheme consists of two steps: 1) order 
virtual tables by a pre-order 
+traversal of the class hierarchy and 2) interleave the virtual tables entry by 
entry.

On the high level -> At a high level



Comment at: clang/docs/ControlFlowIntegrityDesign.rst:322
+This step will arrange the virtual tables for A, B, C, and D in the order of 
*vtable-of-A, vtable-of-B, vtable-of-D, vtable-of-C*.
+In this order, for any class all the compatible virtual tables will appear 
consecutively.
+

I would move this sentence to the start of the subsection because it isn't 
specific to your example and clarify that although GlobalLayoutBuilder tries to 
place compatible vtables consecutively (but doesn't always succeed because the 
Itanium ABI glues vtables together), this algorithm requires them to appear 
consecutively.



Comment at: clang/docs/ControlFlowIntegrityDesign.rst:331
+works under this scheme because the interleaved virtual table has the property 
that for 
+each virtual funtion the distance between an entry of this function and the 
corresponding 
+address point is always the same. 

funtion -> function



Comment at: clang/docs/ControlFlowIntegrityDesign.rst:339
+  
+  A::offset-to-top, B::offset-to-top, D::offset-to-top, C::offset-to-top, 
::rtti, ::rtti, ::rtti, ::rtti, ::f1, ::f1, ::f1, ::f1, ::f2, 
::f2, ::f3, ::f4
+

This layout isn't necessarily going to work with traditional RTTI because the 
`__dynamic_cast` function is allowed to assume that the rtti and offset-to-top 
fields appear at the offsets behind the address point that the ABI says that 
they will appear at. Indeed, the libcxxabi implementation makes that assumption:

https://github.com/llvm-mirror/libcxxabi/blob/master/src/private_typeinfo.cpp#L627

It's probably more something to keep in mind for the implementation, but I 
think we at least need to mention the RTTI incompatibility here.


Repository:
  rC Clang

https://reviews.llvm.org/D50372



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


[PATCH] D50363: [analyzer] pr37204: Take signedness into account in BasicValueFactory::getTruthValue().

2018-08-06 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339088: [analyzer] pr37204: Take signedness into account in 
getTruthValue(). (authored by dergachev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50363?vs=159435=159446#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50363

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  test/Analysis/casts.c


Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -211,7 +211,8 @@
   }
 
   const llvm::APSInt (bool b, QualType T) {
-return getValue(b ? 1 : 0, Ctx.getIntWidth(T), true);
+return getValue(b ? 1 : 0, Ctx.getIntWidth(T),
+T->isUnsignedIntegerOrEnumerationType());
   }
 
   const llvm::APSInt (bool b) {
Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -182,3 +182,9 @@
 c += 1;
   }
 }
+
+void testSwitchWithSizeofs() {
+  switch (sizeof(char) == 1) { // expected-warning{{switch condition has 
boolean value}}
+  case sizeof(char):; // no-crash
+  }
+}


Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -211,7 +211,8 @@
   }
 
   const llvm::APSInt (bool b, QualType T) {
-return getValue(b ? 1 : 0, Ctx.getIntWidth(T), true);
+return getValue(b ? 1 : 0, Ctx.getIntWidth(T),
+T->isUnsignedIntegerOrEnumerationType());
   }
 
   const llvm::APSInt (bool b) {
Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -182,3 +182,9 @@
 c += 1;
   }
 }
+
+void testSwitchWithSizeofs() {
+  switch (sizeof(char) == 1) { // expected-warning{{switch condition has boolean value}}
+  case sizeof(char):; // no-crash
+  }
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339088 - [analyzer] pr37204: Take signedness into account in getTruthValue().

2018-08-06 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Aug  6 19:27:38 2018
New Revision: 339088

URL: http://llvm.org/viewvc/llvm-project?rev=339088=rev
Log:
[analyzer] pr37204: Take signedness into account in getTruthValue().

It now actually produces a signed APSInt when the QualType passed into it is
signed, which is what any caller would expect.

Fixes a couple of crashes.

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

Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
cfe/trunk/test/Analysis/casts.c

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h?rev=339088=339087=339088=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h 
(original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h 
Mon Aug  6 19:27:38 2018
@@ -211,7 +211,8 @@ public:
   }
 
   const llvm::APSInt (bool b, QualType T) {
-return getValue(b ? 1 : 0, Ctx.getIntWidth(T), true);
+return getValue(b ? 1 : 0, Ctx.getIntWidth(T),
+T->isUnsignedIntegerOrEnumerationType());
   }
 
   const llvm::APSInt (bool b) {

Modified: cfe/trunk/test/Analysis/casts.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/casts.c?rev=339088=339087=339088=diff
==
--- cfe/trunk/test/Analysis/casts.c (original)
+++ cfe/trunk/test/Analysis/casts.c Mon Aug  6 19:27:38 2018
@@ -182,3 +182,9 @@ void testLocNonLocSymbolRemainder(int a,
 c += 1;
   }
 }
+
+void testSwitchWithSizeofs() {
+  switch (sizeof(char) == 1) { // expected-warning{{switch condition has 
boolean value}}
+  case sizeof(char):; // no-crash
+  }
+}


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


[PATCH] D49627: [CFG] [analyzer] Constructors of member CXXOperatorCallExpr's argument 0 are not argument constructors.

2018-08-06 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339087: [analyzer] NFC: Document that we support implicit 
argument constructors. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D49627

Files:
  include/clang/Analysis/ConstructionContext.h
  test/Analysis/cfg-rich-constructors.cpp
  test/Analysis/temporaries.cpp


Index: include/clang/Analysis/ConstructionContext.h
===
--- include/clang/Analysis/ConstructionContext.h
+++ include/clang/Analysis/ConstructionContext.h
@@ -623,9 +623,16 @@
 };
 
 class ArgumentConstructionContext : public ConstructionContext {
-  const Expr *CE; // The call of which the context is an argument.
-  unsigned Index; // Which argument we're constructing.
-  const CXXBindTemporaryExpr *BTE; // Whether the object needs to be destroyed.
+  // The call of which the context is an argument.
+  const Expr *CE;
+
+  // Which argument we're constructing. Note that when numbering between
+  // arguments and parameters is inconsistent (eg., operator calls),
+  // this is the index of the argument, not of the parameter.
+  unsigned Index;
+
+  // Whether the object needs to be destroyed.
+  const CXXBindTemporaryExpr *BTE;
 
   friend class ConstructionContext; // Allows to create<>() itself.
 
Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -986,3 +986,21 @@
   *i = 99; // no-warning
 }
 } // namespace ctor_argument
+
+namespace operator_implicit_argument {
+struct S {
+  bool x;
+  S(bool x): x(x) {}
+  operator bool() const { return x; }
+};
+
+void foo() {
+  if (S(false)) {
+clang_analyzer_warnIfReached(); // no-warning
+  }
+  if (S(true)) {
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  }
+}
+} // namespace operator_implicit_argument
+
Index: test/Analysis/cfg-rich-constructors.cpp
===
--- test/Analysis/cfg-rich-constructors.cpp
+++ test/Analysis/cfg-rich-constructors.cpp
@@ -963,3 +963,35 @@
   C c = C();
 }
 } // namespace copy_elision_with_extra_arguments
+
+
+namespace operators {
+class C {
+public:
+  C(int);
+  C +(C Other);
+};
+
+// FIXME: Find construction context for the this-argument of the operator.
+// CHECK: void testOperators()
+// CHECK:[B1]
+// CHECK-NEXT: 1: operator+
+// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class 
operators::C &(*)(class o
+// CHECK-NEXT: 3: 1
+// CHECK-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.6], class operators::C)
+// CHECK-NEXT: 5: operators::C([B1.4]) (CXXFunctionalCastExpr, 
ConstructorConversion, class operato
+// CHECK-NEXT: 6: [B1.5]
+// CHECK-NEXT: 7: 2
+// CXX11-ELIDE-NEXT: 8: [B1.7] (CXXConstructExpr, [B1.10], [B1.11], class 
operators::C)
+// CXX11-NOELIDE-NEXT: 8: [B1.7] (CXXConstructExpr, [B1.10], class 
operators::C)
+// CXX11-NEXT: 9: operators::C([B1.8]) (CXXFunctionalCastExpr, 
ConstructorConversion, class operato
+// CXX11-NEXT:10: [B1.9]
+// CXX11-NEXT:11: [B1.10] (CXXConstructExpr, [B1.12]+1, class operators::C)
+// CXX11-NEXT:12: [B1.6] + [B1.11] (OperatorCall)
+// CXX17-NEXT: 8: [B1.7] (CXXConstructExpr, [B1.10]+1, class operators::C)
+// CXX17-NEXT: 9: operators::C([B1.8]) (CXXFunctionalCastExpr, 
ConstructorConversion, class operato
+// CXX17-NEXT:10: [B1.6] + [B1.9] (OperatorCall)
+void testOperators() {
+  C(1) + C(2);
+}
+} // namespace operators


Index: include/clang/Analysis/ConstructionContext.h
===
--- include/clang/Analysis/ConstructionContext.h
+++ include/clang/Analysis/ConstructionContext.h
@@ -623,9 +623,16 @@
 };
 
 class ArgumentConstructionContext : public ConstructionContext {
-  const Expr *CE; // The call of which the context is an argument.
-  unsigned Index; // Which argument we're constructing.
-  const CXXBindTemporaryExpr *BTE; // Whether the object needs to be destroyed.
+  // The call of which the context is an argument.
+  const Expr *CE;
+
+  // Which argument we're constructing. Note that when numbering between
+  // arguments and parameters is inconsistent (eg., operator calls),
+  // this is the index of the argument, not of the parameter.
+  unsigned Index;
+
+  // Whether the object needs to be destroyed.
+  const CXXBindTemporaryExpr *BTE;
 
   friend class ConstructionContext; // Allows to create<>() itself.
 
Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -986,3 +986,21 @@
   *i = 99; // no-warning
 }
 } // namespace ctor_argument
+
+namespace operator_implicit_argument {
+struct S {
+  bool x;
+  S(bool x): x(x) {}
+  operator bool() 

Re: r338301 - Avoid returning an invalid end source loc

2018-08-06 Thread David Blaikie via cfe-commits
test case?

On Mon, Jul 30, 2018 at 1:39 PM Stephen Kelly via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: steveire
> Date: Mon Jul 30 13:39:14 2018
> New Revision: 338301
>
> URL: http://llvm.org/viewvc/llvm-project?rev=338301=rev
> Log:
> Avoid returning an invalid end source loc
>
> Modified:
> cfe/trunk/include/clang/AST/DeclarationName.h
> cfe/trunk/lib/AST/DeclarationName.cpp
>
> Modified: cfe/trunk/include/clang/AST/DeclarationName.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclarationName.h?rev=338301=338300=338301=diff
>
> ==
> --- cfe/trunk/include/clang/AST/DeclarationName.h (original)
> +++ cfe/trunk/include/clang/AST/DeclarationName.h Mon Jul 30 13:39:14 2018
> @@ -558,7 +558,7 @@ public:
>SourceLocation getBeginLoc() const { return NameLoc; }
>
>/// getEndLoc - Retrieve the location of the last token.
> -  SourceLocation getEndLoc() const;
> +  SourceLocation getEndLoc() const { return getLocEnd(); }
>
>/// getSourceRange - The range of the declaration name.
>SourceRange getSourceRange() const LLVM_READONLY {
> @@ -570,9 +570,11 @@ public:
>}
>
>SourceLocation getLocEnd() const LLVM_READONLY {
> -SourceLocation EndLoc = getEndLoc();
> +SourceLocation EndLoc = getEndLocPrivate();
>  return EndLoc.isValid() ? EndLoc : getLocStart();
>}
> +private:
> +  SourceLocation getEndLocPrivate() const;
>  };
>
>  /// Insertion operator for diagnostics.  This allows sending
> DeclarationName's
>
> Modified: cfe/trunk/lib/AST/DeclarationName.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=338301=338300=338301=diff
>
> ==
> --- cfe/trunk/lib/AST/DeclarationName.cpp (original)
> +++ cfe/trunk/lib/AST/DeclarationName.cpp Mon Jul 30 13:39:14 2018
> @@ -689,7 +689,7 @@ void DeclarationNameInfo::printName(raw_
>llvm_unreachable("Unexpected declaration name kind");
>  }
>
> -SourceLocation DeclarationNameInfo::getEndLoc() const {
> +SourceLocation DeclarationNameInfo::getEndLocPrivate() const {
>switch (Name.getNameKind()) {
>case DeclarationName::Identifier:
>case DeclarationName::CXXDeductionGuideName:
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339087 - [analyzer] NFC: Document that we support implicit argument constructors.

2018-08-06 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Aug  6 19:22:59 2018
New Revision: 339087

URL: http://llvm.org/viewvc/llvm-project?rev=339087=rev
Log:
[analyzer] NFC: Document that we support implicit argument constructors.

The change in the AST in r338135 caused us to accidentally support
inlining constructors of operator implicit arguments. Previously they were
hard to support because they were treated as arguments in expressions
but not in declarations, but now they can be transparently treated as
simple temporaries.

Add tests and comments to explain how it now works.

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

Modified:
cfe/trunk/include/clang/Analysis/ConstructionContext.h
cfe/trunk/test/Analysis/cfg-rich-constructors.cpp
cfe/trunk/test/Analysis/temporaries.cpp

Modified: cfe/trunk/include/clang/Analysis/ConstructionContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ConstructionContext.h?rev=339087=339086=339087=diff
==
--- cfe/trunk/include/clang/Analysis/ConstructionContext.h (original)
+++ cfe/trunk/include/clang/Analysis/ConstructionContext.h Mon Aug  6 19:22:59 
2018
@@ -623,9 +623,16 @@ public:
 };
 
 class ArgumentConstructionContext : public ConstructionContext {
-  const Expr *CE; // The call of which the context is an argument.
-  unsigned Index; // Which argument we're constructing.
-  const CXXBindTemporaryExpr *BTE; // Whether the object needs to be destroyed.
+  // The call of which the context is an argument.
+  const Expr *CE;
+
+  // Which argument we're constructing. Note that when numbering between
+  // arguments and parameters is inconsistent (eg., operator calls),
+  // this is the index of the argument, not of the parameter.
+  unsigned Index;
+
+  // Whether the object needs to be destroyed.
+  const CXXBindTemporaryExpr *BTE;
 
   friend class ConstructionContext; // Allows to create<>() itself.
 

Modified: cfe/trunk/test/Analysis/cfg-rich-constructors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cfg-rich-constructors.cpp?rev=339087=339086=339087=diff
==
--- cfe/trunk/test/Analysis/cfg-rich-constructors.cpp (original)
+++ cfe/trunk/test/Analysis/cfg-rich-constructors.cpp Mon Aug  6 19:22:59 2018
@@ -963,3 +963,35 @@ void testCopyElisionWhenCopyConstructorH
   C c = C();
 }
 } // namespace copy_elision_with_extra_arguments
+
+
+namespace operators {
+class C {
+public:
+  C(int);
+  C +(C Other);
+};
+
+// FIXME: Find construction context for the this-argument of the operator.
+// CHECK: void testOperators()
+// CHECK:[B1]
+// CHECK-NEXT: 1: operator+
+// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class 
operators::C &(*)(class o
+// CHECK-NEXT: 3: 1
+// CHECK-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.6], class operators::C)
+// CHECK-NEXT: 5: operators::C([B1.4]) (CXXFunctionalCastExpr, 
ConstructorConversion, class operato
+// CHECK-NEXT: 6: [B1.5]
+// CHECK-NEXT: 7: 2
+// CXX11-ELIDE-NEXT: 8: [B1.7] (CXXConstructExpr, [B1.10], [B1.11], class 
operators::C)
+// CXX11-NOELIDE-NEXT: 8: [B1.7] (CXXConstructExpr, [B1.10], class 
operators::C)
+// CXX11-NEXT: 9: operators::C([B1.8]) (CXXFunctionalCastExpr, 
ConstructorConversion, class operato
+// CXX11-NEXT:10: [B1.9]
+// CXX11-NEXT:11: [B1.10] (CXXConstructExpr, [B1.12]+1, class operators::C)
+// CXX11-NEXT:12: [B1.6] + [B1.11] (OperatorCall)
+// CXX17-NEXT: 8: [B1.7] (CXXConstructExpr, [B1.10]+1, class operators::C)
+// CXX17-NEXT: 9: operators::C([B1.8]) (CXXFunctionalCastExpr, 
ConstructorConversion, class operato
+// CXX17-NEXT:10: [B1.6] + [B1.9] (OperatorCall)
+void testOperators() {
+  C(1) + C(2);
+}
+} // namespace operators

Modified: cfe/trunk/test/Analysis/temporaries.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/temporaries.cpp?rev=339087=339086=339087=diff
==
--- cfe/trunk/test/Analysis/temporaries.cpp (original)
+++ cfe/trunk/test/Analysis/temporaries.cpp Mon Aug  6 19:22:59 2018
@@ -986,3 +986,21 @@ void bar() {
   *i = 99; // no-warning
 }
 } // namespace ctor_argument
+
+namespace operator_implicit_argument {
+struct S {
+  bool x;
+  S(bool x): x(x) {}
+  operator bool() const { return x; }
+};
+
+void foo() {
+  if (S(false)) {
+clang_analyzer_warnIfReached(); // no-warning
+  }
+  if (S(true)) {
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  }
+}
+} // namespace operator_implicit_argument
+


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


[PATCH] D50372: Introduce the VTable interleaving scheme to the CFI design documentation

2018-08-06 Thread Zhaomo Yang via Phabricator via cfe-commits
zhaomo created this revision.
zhaomo added reviewers: pcc, vlad.tsyrklevich.
Herald added a subscriber: cfe-commits.

Dimitar et. al. in [1] proposed a novel VTable layout scheme that enables 
efficient implementation of virtual call CFI.

This patch adds an introduction of this scheme to the CFI design documentation.

[1] Protecting C++ Dynamic Dispatch Through VTable Interleaving. Dimitar 
Bounov, Rami Gökhan Kıcı, Sorin Lerner. 
https://cseweb.ucsd.edu/~lerner/papers/ivtbl-ndss16.pdf


Repository:
  rC Clang

https://reviews.llvm.org/D50372

Files:
  clang/docs/ControlFlowIntegrityDesign.rst


Index: clang/docs/ControlFlowIntegrityDesign.rst
===
--- clang/docs/ControlFlowIntegrityDesign.rst
+++ clang/docs/ControlFlowIntegrityDesign.rst
@@ -274,6 +274,74 @@
 need to check that the address is in range and well aligned. This is more
 likely to occur if the virtual tables are padded.
 
+Forward-Edge CFI for Virtual Calls by Interleaving Virtual Tables
+=
+
+Alternatively, Dimitar et. al. in [1]_ proposed a novel approach that 
interleaves virtual tables. 
+This approach is more efficient in terms of space because padding and bit 
vectors are no longer needed. 
+At the same time, it is also more efficient in terms of performance because in 
the interleaved virtual 
+table address points are consecutive, thus the validity check of a virtual 
vtable pointer is simplified 
+to a range check. 
+
+On the high level, the interleaving scheme consists of two steps: 1) order 
virtual tables by a pre-order 
+traversal of the class hierarchy and 2) interleave the virtual tables entry by 
entry.
+
+.. [1] `Protecting C++ Dynamic Dispatch Through VTable Interleaving 
`_. Dimitar Bounov, 
Rami Gökhan Kıcı, Sorin Lerner.
+
+Order virtual tables by a pre-order traversal of the class hierarchy 
+
+
+This step is common to both the old scheme described above and the 
interleaving scheme. For each class 
+this step ensures that classes in sub-hierarchies of this class are laid out 
as close as possible.
+
+For example, consider the following four C++ classes:
+
+.. code-block:: c++
+
+  struct A {
+virtual void f1();
+  };
+
+  struct B : A {
+virtual void f1();
+virtual void f2();
+  };
+
+  struct C : A {
+virtual void f1();
+virtual void f3();
+  };
+
+  struct D : B {
+virtual void f1();
+virtual void f2();
+virtual void f4();
+  };
+
+This step will arrange the virtual tables for A, B, C, and D in the order of 
*vtable-of-A, vtable-of-B, vtable-of-D, vtable-of-C*.
+In this order, for any class all the compatible virtual tables will appear 
consecutively.
+
+Interleave the virtual tables entry by entry
+
+
+This step is where the interleaving scheme deviates from the old scheme. 
Instead of laying out 
+whole virtual tables in the previously computed order, the interleaving scheme 
lays out table 
+entries one by one from the virtual tables in that order. Dynamic dispatch 
still 
+works under this scheme because the interleaved virtual table has the property 
that for 
+each virtual funtion the distance between an entry of this function and the 
corresponding 
+address point is always the same. 
+
+To follow the example used in the previous step, the interleaved virtual table 
will look like this:
+
+.. csv-table:: Interleaved Virtual Table Layout for A, B, C, D
+  :header: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+  
+  A::offset-to-top, B::offset-to-top, D::offset-to-top, C::offset-to-top, 
::rtti, ::rtti, ::rtti, ::rtti, ::f1, ::f1, ::f1, ::f1, ::f2, 
::f2, ::f3, ::f4
+
+Let us take f2 as an example to see the aforementioned property. In the 
interleaved virtual table, 
+there are two entries for f2: B::f2 and D::f2. The distance between ::f2 
+and its address point ::f1 is 3 entry-length, so is the distance between 
::f2 and ::f1.
+
 Forward-Edge CFI for Indirect Function Calls
 
 


Index: clang/docs/ControlFlowIntegrityDesign.rst
===
--- clang/docs/ControlFlowIntegrityDesign.rst
+++ clang/docs/ControlFlowIntegrityDesign.rst
@@ -274,6 +274,74 @@
 need to check that the address is in range and well aligned. This is more
 likely to occur if the virtual tables are padded.
 
+Forward-Edge CFI for Virtual Calls by Interleaving Virtual Tables
+=
+
+Alternatively, Dimitar et. al. in [1]_ proposed a novel approach that interleaves virtual tables. 
+This approach is more efficient in terms of space because padding and bit vectors are no longer needed. 
+At the same time, it is also more efficient in terms of performance 

[PATCH] D50291: [C++] Delay checking of constexpr-ness for special members.

2018-08-06 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/Sema/SemaDeclCXX.cpp:6045
   // Inform the class that we've finished declaring this member.
   Record->finishedDefaultedOrDeletedMember(M);
   M->setTrivialForCall(

Your new handling should go up here, before we mark the method as finished 
(rather than marking it as finished twice).



Comment at: lib/Sema/SemaDeclCXX.cpp:6557-6558
   //   would have been implicitly declared as constexpr,
-  // Do not apply this rule to members of class templates, since core issue 
1358
-  // makes such functions always instantiate to constexpr functions. For
-  // functions which cannot be constexpr (for non-constructors in C++11 and for
-  // destructors in C++1y), this is checked elsewhere.
-  bool Constexpr = defaultedSpecialMemberIsConstexpr(*this, RD, CSM,
- HasConstParam);
-  if ((getLangOpts().CPlusPlus14 ? !isa(MD)
- : isa(MD)) &&
-  MD->isConstexpr() && !Constexpr &&
-  MD->getTemplatedKind() == FunctionDecl::TK_NonTemplate) {
-Diag(MD->getLocStart(), diag::err_incorrect_defaulted_constexpr) << CSM;
-// FIXME: Explain why the special member can't be constexpr.
-HadError = true;
-  }
+  // We need to delay this, because at this point we may not have enough
+  // information to determine if MD is really constexpr or not.
 

We should only delay this for the first declaration, just as we only delay the 
corresponding check for exception specifications for the first declaration. 
(Maybe move the call to `CheckExplicitlyDefaultedSpecialMemberConstexpr(MD);` 
from the out-of-class default case to here, inside an `if (!First)`.)



Comment at: lib/Sema/SemaDeclCXX.cpp:6560-6575
   //   and may have an explicit exception-specification only if it is 
compatible
   //   with the exception-specification on the implicit declaration.
   if (Type->hasExceptionSpec()) {
 // Delay the check if this is the first declaration of the special member,
 // since we may not have parsed some necessary in-class initializers yet.
 if (First) {
   // If the exception specification needs to be instantiated, do so now,

We should really implement the exception specification part and the constexpr 
part the same way. Either we should have a single list of special members we 
need to finish, or we should figure them out at the end of the class (like 
you're doing for `constexpr` now). But implementing exception specs one way and 
`constexpr` a different way invites bugs.



Comment at: lib/Sema/SemaDeclCXX.cpp:6623
+
+  // Do not apply this rule to members of class templates, since core issue 
1358
+  // makes such functions always instantiate to constexpr functions. For

... what rule? (This comment has lost the prior comment that it's commenting 
on.)


Repository:
  rC Clang

https://reviews.llvm.org/D50291



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


[PATCH] D41284: [Concepts] Associated constraints infrastructure.

2018-08-06 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/AST/DeclTemplate.cpp:203
+
+Expr *TemplateDecl::getAssociatedConstraints() {
+  return getOrCollectAssociatedConstraints(getASTContext(),

Rather than producing an `Expr*` (which will presumably eventually need to 
contain synthetic `&&` expressions), this should produce a vector of 
constraints (notionally and'd together), which will (eventually) be either 
constraint-expressions or some representation of "the constraints implied by 
this template parameter". If you do that, I don't think there's any reason to 
cache this information on the `TemplateDecl`; it should be cheap enough to 
recompute when we need it.



Comment at: lib/Sema/SemaConcept.cpp:47-58
+ const Expr *NewAC) {
+  if (!(NewAC || OldAC))
+return true; // Nothing to check; no mismatch.
+  if (NewAC && OldAC) {
+llvm::FoldingSetNodeID OldACInfo, NewACInfo;
+NewAC->Profile(NewACInfo, Context, /*Canonical=*/true);
+OldAC->Profile(OldACInfo, Context, /*Canonical=*/true);

I'm sure we already have this "profile two expressions and check they are 
canonically equivalent" functionality factored out //somewhere//. Is there 
nothing like that that's appropriate to reuse here?



Comment at: lib/Sema/SemaTemplate.cpp:2145-2154
   if (RemoveDefaultArguments) {
-for (TemplateParameterList::iterator NewParam = NewParams->begin(),
-  NewParamEnd = NewParams->end();
- NewParam != NewParamEnd; ++NewParam) {
-  if (TemplateTypeParmDecl *TTP = 
dyn_cast(*NewParam))
+for (NamedDecl *NewParam : *NewParams) {
+  if (TemplateTypeParmDecl *TTP = dyn_cast(NewParam))
 TTP->removeDefaultArgument();
   else if (NonTypeTemplateParmDecl *NTTP
-= dyn_cast(*NewParam))
+= dyn_cast(NewParam))
 NTTP->removeDefaultArgument();

Unrelated cleanup: please commit this separately.



Comment at: lib/Sema/SemaTemplateInstantiateDecl.cpp:3141-3148
+  Expr *InstRequiresClause = nullptr;
+  if (Expr *E = L->getRequiresClause()) {
+ExprResult Res = SemaRef.SubstExpr(E, TemplateArgs);
+if (Res.isInvalid() || !Res.isUsable()) {
+  return nullptr;
+}
+InstRequiresClause = Res.get();

This is wrong (we should never substitute into a constraint-expression except 
as part of satisfaction or subsumption checks). Please at least add a FIXME.



Comment at: lib/Serialization/ASTReaderDecl.cpp:2003-2006
+bool HasAssociatedConstraints = Record.readInt();
+if (HasAssociatedConstraints) {
+   AssociatedConstraints = Record.readExpr();
+}

There doesn't seem to be a good reason to serialize the cached associated 
constraints, even if we want to keep them (which I don't think we do).



Comment at: lib/Serialization/ASTWriter.cpp:5856
   for (const auto  : *TemplateParams)
-AddDeclRef(P);
+AddDeclRef(P); // TODO: Concepts - constrained parameters.
+  if (const Expr *RequiresClause = TemplateParams->getRequiresClause()) {

What would be left "to do" here? For constrained parameters, there may be 
something interesting to track on the `*Template*ParmDecl`, but not here, I 
wouldn't think,


Repository:
  rC Clang

https://reviews.llvm.org/D41284



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


[PATCH] D41217: [Concepts] Concept Specialization Expressions

2018-08-06 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/AST/ExprCXX.h:4420
+  /// \brief The concept named.
+  ConceptDecl *NamedConcept;
+

You should also track the `FoundDecl` and the optional `NestedNameSpecifierLoc` 
(just like a `DeclRefExpr` would). Clang-based tools (particularly refactoring 
tools) need those. There's also an optional `template` keyword, but it can 
never matter in practice because the nested name specifier can never be 
dependent, so it's probably not the most high-priority thing to track.



Comment at: include/clang/AST/ExprCXX.h:4423-4424
+  /// \brief The template argument list used to specialize the concept.
+  TemplateArgumentList *TemplateArgs;
+  const ASTTemplateArgumentListInfo *TemplateArgInfo;
+

It'd be nice if at least one of these two arrays could be tail-allocated.



Comment at: include/clang/AST/ExprCXX.h:4459-4463
+  /// \brief Set new template arguments for this concept specialization. 
Returns
+  /// true if an error occured (the template arguments do not match the 
concept,
+  /// probably)
+  bool setTemplateArguments(ASTContext , Sema *S,
+const TemplateArgumentListInfo *TALI);

Passing `Sema` in here is a major layering violation. Here's how this should 
work:

 * The AST code represents the AST model; its functions should generally not be 
able to fail.
 * Sema checks the semantic constraints and enforces the validity of 
operations, and updates the AST node as appropriate

In this case, Sema should be checking the template argument list as written 
against the concept's parameter list, forming a resolved list of template 
arguments, and then passing both the as-written information and the resolved 
arguments to this AST node for storage.



Comment at: include/clang/AST/ExprCXX.h:4474-4481
+  void setSatisfied(bool Satisfied) {
+IsSatisfied = Satisfied;
+  }
+
+  SourceLocation getConceptNameLoc() const { return ConceptNameLoc; }
+  void setConceptNameLoc(SourceLocation Loc) {
+ConceptNameLoc = Loc;

Do you really need mutators for the 'satisfied' flag and the concept name 
location?



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2405
+  "substitution into constraint expression resulted in a non-constant "
+  "expression '%0'">;
+def err_non_bool_atomic_constraint : Error<

Find a way to describe this problem without pretty-printing a substituted 
expression.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2407
+def err_non_bool_atomic_constraint : Error<
+  "atomic constraint '%0' must be of type 'bool' (found %1)">;
+def note_in_concept_specialization : Note<

Remove the '%0' here; you're already underlining it with a `SourceRange` 
(right?).

Please read http://clang.llvm.org/docs/InternalsManual.html#the-format-string 
and in particular "Take advantage of location information. The user will be 
able to see the line and location of the caret, so you don’t need to tell them 
that the problem is with the 4th argument to the function: just point to it."





Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2409
+def note_in_concept_specialization : Note<
+  "in concept specialization '%0'">;
 

There's not really any such thing as a "concept specialization". Perhaps "while 
checking satisfaction of '%0'" or similar?



Comment at: lib/AST/ExprCXX.cpp:1460
+Expr *ConstraintExpr, bool ) {
+  if (auto *BO = dyn_cast(ConstraintExpr)) {
+if (BO->getOpcode() == BO_LAnd) {

You will need to skip over a top-level `ExprWithCleanups` (I can't think 
off-hand of any other nodes that could show up here, but there might be more).



Comment at: lib/AST/ExprCXX.cpp:1552-1553
+  IsSatisfied)) {
+S->Diag(getLocStart(),
+diag::note_in_concept_specialization) << this;
+return true;

Build a `CodeSynthesisContext` for this rather than adding an ad-hoc note to 
the last diagnostic that happens to come from substitution (which might not be 
the error you care about, and might even be suppressed by warning flags).



Comment at: lib/AST/ExprConstant.cpp:9085-9087
+  if (E->isValueDependent()) {
+return Error(E);
+  }

You don't need to check for this. If the evaluator is called on a 
value-dependent expression, that's a bug in the caller.



Comment at: lib/AST/StmtPrinter.cpp:2553
+void StmtPrinter::VisitConceptSpecializationExpr(ConceptSpecializationExpr *E) 
{
+  OS << E->getNamedConcept()->getName();
+  printTemplateArgumentList(OS, E->getTemplateArgumentListInfo()->arguments(),

You should print out the nested name specifier here. (And ideally also the 
`template` 

[PATCH] D47196: [Time-report ](2): Recursive timers in Clang

2018-08-06 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

I mean, which of the callers of startFrontendTimer() is calling it with a 
pointer to std::declval()?


https://reviews.llvm.org/D47196



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


[PATCH] D50363: [analyzer] pr37204: Take signedness into account in BasicValueFactory::getTruthValue().

2018-08-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 159435.
NoQ added a comment.

Whoops, how did this `T, ` thing get in there.


https://reviews.llvm.org/D50363

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  test/Analysis/casts.c
  test/Analysis/std-c-library-functions-inlined.c


Index: test/Analysis/std-c-library-functions-inlined.c
===
--- /dev/null
+++ test/Analysis/std-c-library-functions-inlined.c
@@ -0,0 +1,17 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=unix.StdCLibraryFunctions -verify 
%s
+// RUN: %clang_analyze_cc1 -triple i686-unknown-linux 
-analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux 
-analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple armv7-a15-linux 
-analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux 
-analyzer-checker=unix.StdCLibraryFunctions -verify %s
+
+// This test tests crashes that occur when standard functions are available
+// for inlining.
+
+// expected-no-diagnostics
+
+int isdigit(int _) { return !0; }
+void test_redefined_isdigit(int x) {
+  int (*func)(int) = isdigit;
+  for (; func(x);) // no-crash
+;
+}
Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -182,3 +182,9 @@
 c += 1;
   }
 }
+
+void testSwitchWithSizeofs() {
+  switch (sizeof(char) == 1) { // expected-warning{{switch condition has 
boolean value}}
+  case sizeof(char):; // no-crash
+  }
+}
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -211,7 +211,8 @@
   }
 
   const llvm::APSInt (bool b, QualType T) {
-return getValue(b ? 1 : 0, Ctx.getIntWidth(T), true);
+return getValue(b ? 1 : 0, Ctx.getIntWidth(T),
+T->isUnsignedIntegerOrEnumerationType());
   }
 
   const llvm::APSInt (bool b) {


Index: test/Analysis/std-c-library-functions-inlined.c
===
--- /dev/null
+++ test/Analysis/std-c-library-functions-inlined.c
@@ -0,0 +1,17 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s
+
+// This test tests crashes that occur when standard functions are available
+// for inlining.
+
+// expected-no-diagnostics
+
+int isdigit(int _) { return !0; }
+void test_redefined_isdigit(int x) {
+  int (*func)(int) = isdigit;
+  for (; func(x);) // no-crash
+;
+}
Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -182,3 +182,9 @@
 c += 1;
   }
 }
+
+void testSwitchWithSizeofs() {
+  switch (sizeof(char) == 1) { // expected-warning{{switch condition has boolean value}}
+  case sizeof(char):; // no-crash
+  }
+}
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -211,7 +211,8 @@
   }
 
   const llvm::APSInt (bool b, QualType T) {
-return getValue(b ? 1 : 0, Ctx.getIntWidth(T), true);
+return getValue(b ? 1 : 0, Ctx.getIntWidth(T),
+T->isUnsignedIntegerOrEnumerationType());
   }
 
   const llvm::APSInt (bool b) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40381: Parse concept definition

2018-08-06 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/AST/DeclTemplate.h:3007
 
+/// \brief Definition of concept, not just declaration actually.
+class ConceptDecl : public TemplateDecl {

This comment isn't appropriate. Please just describe what the node is. (And 
note that a definition is a kind of declaration, despite common parlance.)



Comment at: include/clang/AST/DeclTemplate.h:3035
+  SourceRange getSourceRange() const override LLVM_READONLY {
+return SourceRange(getLocation(), getLocation());
+  }

faisalv wrote:
> why not just fix it now?
>   return SourceRange(getTemplateParameters()->getTemplateLoc(), 
> ConstraintExpr->getLocEnd(); 
> 
> ?
There's a bigger problem here:

```
TemplateDecl *TD = /*some ConceptDecl*/;
auto SR = TD->getSourceRange(); // crash
```

`TemplateDecl` has a hard assumption that it contains a `TemplatedDecl`. So, 
three options:

1) Change `TemplateDecl` and all its users to remove this assumption (hard and 
leads to an awkward-to-use AST)
2) Add a `Decl` subclass that acts as the templated declaration in a concept 
declaration (corresponding to the C++ grammar's //concept-definition// 
production)
3) Make `ConceptDecl` //not// derive from a `TemplateDecl` at all

I think option 2 is my preference, but option 3 is also somewhat appealing 
(there are other ways in which a concept is not a template: for instance, it 
cannot be constrained, and it cannot be classified as either a type template or 
a non-type template, because its kind depends on the context in which it 
appears).

Of course, this leads to one of the Hard Problems Of Computer Science: naming 
things. `ConceptDecl` for a //concept-definition// and `ConceptTemplateDecl` 
for the //template-head concept-definition// would be consistent with the rest 
of the AST. It's a little unfortunate for the longer name to be the AST node 
that we actually interact with, but the consistency is probably worth the cost.



Comment at: include/clang/AST/DeclTemplate.h:3027
+  }
+
+  // TODO: Should do source range properly.

saar.raz wrote:
> Add setConstraintExpr (for use when calling CreateDeserialized, see 
> ASTDeclReader)
Please remove this again. `ASTDeclReader` should set the `ConstraintExpr` field 
directly. The AST is intended to be immutable after creation, so should 
generally not have setters.



Comment at: include/clang/AST/RecursiveASTVisitor.h:1728
+  TRY_TO(TraverseStmt(D->getConstraintExpr()));
+  // FIXME: Traverse all the concept specializations (one we implement forming 
template-ids with them).
+})

Hmm, concepts don't really have specializations, though, do they? (Much like 
alias templates.) And because they're substituted incrementally, and the result 
of evaluation can vary at different points in the same translation unit, it's 
not obvious how much we can actually cache.

I suppose I'll see this was handled in later patches in the series :)



Comment at: include/clang/Basic/DiagnosticParseKinds.td:1134
+def err_concept_unexpected_scope_spec : Error<
+  "concepts must be defined within their namespace">;
+}

I would expect something more general here. For an alias-declaration, we say:

"error: name defined in alias declaration must be an identifier"

This is then also appropriate for other kinds of invalid //concept-name//s such 
as

```
template concept operator int = true;
```



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2390-2391
   "%select{explicitly instantiated|explicitly specialized|partially 
specialized}1">;
+def err_concept_initialized_with_non_bool_type : Error<
+  "constraint expression must be 'bool' but found %0">;
+def err_concept_decls_may_only_appear_in_global_namespace_scope : Error<

"must be 'bool'" doesn't make sense. Maybe "constraint expression must be of 
type 'bool' but is of type %0" or similar?



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2394-2395
+  "concept declarations may only appear in global or namespace scope">;
+def err_concept_no_associated_constraints : Error<
+  "concept may not have associated constraints">;
+def err_concept_not_implemented : Error<

Do not use "may not" in this context; it's ambiguous (this could be read as 
"I'm not sure if this concept has associated constraints"). Use "cannot" 
instead.

(And generally prefer "can" over "may" or "must" in diagnostics.)



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2396-2397
+  "concept may not have associated constraints">;
+def err_concept_not_implemented : Error<
+  "this part's not implemented yet">;
+def err_concept_no_explicit_specialization : Error<

Please make this a bit less informal and a little more informative. Perhaps 
"sorry, unimplemented concepts feature used". For a temporary "under 

[PATCH] D50342: Changed how LLVM IR was generated to increase vectorization

2018-08-06 Thread Emmett Neyman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339080: Changed how LLVM IR was generated to increase 
vectorization (authored by emmettneyman, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50342?vs=159425=159427#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50342

Files:
  cfe/trunk/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp


Index: cfe/trunk/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- cfe/trunk/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
+++ cfe/trunk/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -53,7 +53,7 @@
 break;
   }
   std::string ptr_var = get_var();
-  os << ptr_var << " = getelementptr i32, i32* " << arr << ", i64 %ct\n";
+  os << ptr_var << " = getelementptr inbounds i32, i32* " << arr << ", i64 
%ct\n";
   return ptr_var;
 }
 std::string RvalueToString(std::ostream , const Rvalue ) {
@@ -122,21 +122,20 @@
   return os;
 }
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "define void @foo(i32* %a, i32* %b, i32* noalias %c, i64 %s) 
{\n"
-<< "%i = alloca i64\n"
-<< "store i64 0, i64* %i\n"
-<< "br label %loop\n\n"
+  return os << "target triple = \"x86_64-unknown-linux-gnu\"\n"
+<< "define void @foo(i32* %a, i32* %b, i32* %c, i64 %s) {\n"
+<< "%1 = icmp sgt i64 %s, 0\n"
+<< "br i1 %1, label %start, label %end\n"
+<< "start:\n"
+<< "br label %loop\n"
+<< "end:\n"
+<< "ret void\n"
 << "loop:\n"
-<< "%ct = load i64, i64* %i\n"
-<< "%comp = icmp eq i64 %ct, %s\n"
-<< "br i1 %comp, label %endloop, label %body\n\n"
-<< "body:\n"
+<< " %ct   = phi i64 [ %ctnew, %loop ], [ 0, %start ]\n"
 << x.statements()
-<< "%z = add i64 1, %ct\n"
-<< "store i64 %z, i64* %i\n"
-<< "br label %loop\n\n"
-<< "endloop:\n"
-<< "ret void\n}\n";
+<< "%ctnew = add i64 %ct, 1\n"
+<< "%j = icmp eq i64 %ctnew, %s\n"
+<< "br i1 %j, label %end, label %loop\n}\n";
 }
 
 // -


Index: cfe/trunk/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- cfe/trunk/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
+++ cfe/trunk/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -53,7 +53,7 @@
 break;
   }
   std::string ptr_var = get_var();
-  os << ptr_var << " = getelementptr i32, i32* " << arr << ", i64 %ct\n";
+  os << ptr_var << " = getelementptr inbounds i32, i32* " << arr << ", i64 %ct\n";
   return ptr_var;
 }
 std::string RvalueToString(std::ostream , const Rvalue ) {
@@ -122,21 +122,20 @@
   return os;
 }
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "define void @foo(i32* %a, i32* %b, i32* noalias %c, i64 %s) {\n"
-<< "%i = alloca i64\n"
-<< "store i64 0, i64* %i\n"
-<< "br label %loop\n\n"
+  return os << "target triple = \"x86_64-unknown-linux-gnu\"\n"
+<< "define void @foo(i32* %a, i32* %b, i32* %c, i64 %s) {\n"
+<< "%1 = icmp sgt i64 %s, 0\n"
+<< "br i1 %1, label %start, label %end\n"
+<< "start:\n"
+<< "br label %loop\n"
+<< "end:\n"
+<< "ret void\n"
 << "loop:\n"
-<< "%ct = load i64, i64* %i\n"
-<< "%comp = icmp eq i64 %ct, %s\n"
-<< "br i1 %comp, label %endloop, label %body\n\n"
-<< "body:\n"
+<< " %ct   = phi i64 [ %ctnew, %loop ], [ 0, %start ]\n"
 << x.statements()
-<< "%z = add i64 1, %ct\n"
-<< "store i64 %z, i64* %i\n"
-<< "br label %loop\n\n"
-<< "endloop:\n"
-<< "ret void\n}\n";
+<< "%ctnew = add i64 %ct, 1\n"
+<< "%j = icmp eq i64 %ctnew, %s\n"
+<< "br i1 %j, label %end, label %loop\n}\n";
 }
 
 // -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339080 - Changed how LLVM IR was generated to increase vectorization

2018-08-06 Thread Emmett Neyman via cfe-commits
Author: emmettneyman
Date: Mon Aug  6 16:11:38 2018
New Revision: 339080

URL: http://llvm.org/viewvc/llvm-project?rev=339080=rev
Log:
Changed how LLVM IR was generated to increase vectorization

Summary: Changed the structure of the generated IR to make it easier to 
vectorize

Reviewers: morehouse, kcc

Reviewed By: morehouse

Subscribers: cfe-commits, llvm-commits

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

Modified:
cfe/trunk/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp

Modified: cfe/trunk/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp?rev=339080=339079=339080=diff
==
--- cfe/trunk/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp (original)
+++ cfe/trunk/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp Mon Aug  
6 16:11:38 2018
@@ -53,7 +53,7 @@ std::string VarRefToString(std::ostream
 break;
   }
   std::string ptr_var = get_var();
-  os << ptr_var << " = getelementptr i32, i32* " << arr << ", i64 %ct\n";
+  os << ptr_var << " = getelementptr inbounds i32, i32* " << arr << ", i64 
%ct\n";
   return ptr_var;
 }
 std::string RvalueToString(std::ostream , const Rvalue ) {
@@ -122,21 +122,20 @@ std::ostream <<(std::ostream 
   return os;
 }
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "define void @foo(i32* %a, i32* %b, i32* noalias %c, i64 %s) 
{\n"
-<< "%i = alloca i64\n"
-<< "store i64 0, i64* %i\n"
-<< "br label %loop\n\n"
+  return os << "target triple = \"x86_64-unknown-linux-gnu\"\n"
+<< "define void @foo(i32* %a, i32* %b, i32* %c, i64 %s) {\n"
+<< "%1 = icmp sgt i64 %s, 0\n"
+<< "br i1 %1, label %start, label %end\n"
+<< "start:\n"
+<< "br label %loop\n"
+<< "end:\n"
+<< "ret void\n"
 << "loop:\n"
-<< "%ct = load i64, i64* %i\n"
-<< "%comp = icmp eq i64 %ct, %s\n"
-<< "br i1 %comp, label %endloop, label %body\n\n"
-<< "body:\n"
+<< " %ct   = phi i64 [ %ctnew, %loop ], [ 0, %start ]\n"
 << x.statements()
-<< "%z = add i64 1, %ct\n"
-<< "store i64 %z, i64* %i\n"
-<< "br label %loop\n\n"
-<< "endloop:\n"
-<< "ret void\n}\n";
+<< "%ctnew = add i64 %ct, 1\n"
+<< "%j = icmp eq i64 %ctnew, %s\n"
+<< "br i1 %j, label %end, label %loop\n}\n";
 }
 
 // -


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


[PATCH] D50342: Changed how LLVM IR was generated to increase vectorization

2018-08-06 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 159425.
emmettneyman added a comment.

  Rebased and ready to land


Repository:
  rC Clang

https://reviews.llvm.org/D50342

Files:
  clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp


Index: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
+++ clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -53,7 +53,7 @@
 break;
   }
   std::string ptr_var = get_var();
-  os << ptr_var << " = getelementptr i32, i32* " << arr << ", i64 %ct\n";
+  os << ptr_var << " = getelementptr inbounds i32, i32* " << arr << ", i64 
%ct\n";
   return ptr_var;
 }
 std::string RvalueToString(std::ostream , const Rvalue ) {
@@ -122,21 +122,20 @@
   return os;
 }
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "define void @foo(i32* %a, i32* %b, i32* noalias %c, i64 %s) 
{\n"
-<< "%i = alloca i64\n"
-<< "store i64 0, i64* %i\n"
-<< "br label %loop\n\n"
+  return os << "target triple = \"x86_64-unknown-linux-gnu\"\n"
+<< "define void @foo(i32* %a, i32* %b, i32* %c, i64 %s) {\n"
+<< "%1 = icmp sgt i64 %s, 0\n"
+<< "br i1 %1, label %start, label %end\n"
+<< "start:\n"
+<< "br label %loop\n"
+<< "end:\n"
+<< "ret void\n"
 << "loop:\n"
-<< "%ct = load i64, i64* %i\n"
-<< "%comp = icmp eq i64 %ct, %s\n"
-<< "br i1 %comp, label %endloop, label %body\n\n"
-<< "body:\n"
+<< " %ct   = phi i64 [ %ctnew, %loop ], [ 0, %start ]\n"
 << x.statements()
-<< "%z = add i64 1, %ct\n"
-<< "store i64 %z, i64* %i\n"
-<< "br label %loop\n\n"
-<< "endloop:\n"
-<< "ret void\n}\n";
+<< "%ctnew = add i64 %ct, 1\n"
+<< "%j = icmp eq i64 %ctnew, %s\n"
+<< "br i1 %j, label %end, label %loop\n}\n";
 }
 
 // -


Index: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
+++ clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -53,7 +53,7 @@
 break;
   }
   std::string ptr_var = get_var();
-  os << ptr_var << " = getelementptr i32, i32* " << arr << ", i64 %ct\n";
+  os << ptr_var << " = getelementptr inbounds i32, i32* " << arr << ", i64 %ct\n";
   return ptr_var;
 }
 std::string RvalueToString(std::ostream , const Rvalue ) {
@@ -122,21 +122,20 @@
   return os;
 }
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "define void @foo(i32* %a, i32* %b, i32* noalias %c, i64 %s) {\n"
-<< "%i = alloca i64\n"
-<< "store i64 0, i64* %i\n"
-<< "br label %loop\n\n"
+  return os << "target triple = \"x86_64-unknown-linux-gnu\"\n"
+<< "define void @foo(i32* %a, i32* %b, i32* %c, i64 %s) {\n"
+<< "%1 = icmp sgt i64 %s, 0\n"
+<< "br i1 %1, label %start, label %end\n"
+<< "start:\n"
+<< "br label %loop\n"
+<< "end:\n"
+<< "ret void\n"
 << "loop:\n"
-<< "%ct = load i64, i64* %i\n"
-<< "%comp = icmp eq i64 %ct, %s\n"
-<< "br i1 %comp, label %endloop, label %body\n\n"
-<< "body:\n"
+<< " %ct   = phi i64 [ %ctnew, %loop ], [ 0, %start ]\n"
 << x.statements()
-<< "%z = add i64 1, %ct\n"
-<< "store i64 %z, i64* %i\n"
-<< "br label %loop\n\n"
-<< "endloop:\n"
-<< "ret void\n}\n";
+<< "%ctnew = add i64 %ct, 1\n"
+<< "%j = icmp eq i64 %ctnew, %s\n"
+<< "br i1 %j, label %end, label %loop\n}\n";
 }
 
 // -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50111: [analyzer] Add ASTContext to CheckerManager

2018-08-06 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339079: [analyzer] Add ASTContext to CheckerManager 
(authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50111?vs=158834=159424#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50111

Files:
  include/clang/StaticAnalyzer/Core/CheckerManager.h
  include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
  include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h
  lib/StaticAnalyzer/Core/AnalysisManager.cpp
  lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp

Index: lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
===
--- lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
+++ lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
@@ -112,12 +112,12 @@
 }
 
 std::unique_ptr ento::createCheckerManager(
-AnalyzerOptions , const LangOptions ,
+ASTContext ,
+AnalyzerOptions ,
 ArrayRef plugins,
 ArrayRef> checkerRegistrationFns,
 DiagnosticsEngine ) {
-  std::unique_ptr checkerMgr(
-  new CheckerManager(langOpts, opts));
+  auto checkerMgr = llvm::make_unique(context, opts);
 
   SmallVector checkerOpts = getCheckerOptList(opts);
 
Index: lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -295,13 +295,12 @@
 
   void Initialize(ASTContext ) override {
 Ctx = 
-checkerMgr =
-createCheckerManager(*Opts, PP.getLangOpts(), Plugins,
- CheckerRegistrationFns, PP.getDiagnostics());
+checkerMgr = createCheckerManager(
+*Ctx, *Opts, Plugins, CheckerRegistrationFns, PP.getDiagnostics());
 
 Mgr = llvm::make_unique(
-*Ctx, PP.getDiagnostics(), PP.getLangOpts(), PathConsumers,
-CreateStoreMgr, CreateConstraintMgr, checkerMgr.get(), *Opts, Injector);
+*Ctx, PP.getDiagnostics(), PathConsumers, CreateStoreMgr,
+CreateConstraintMgr, checkerMgr.get(), *Opts, Injector);
   }
 
   /// Store the top level decls in the set to be processed later on.
Index: lib/StaticAnalyzer/Core/AnalysisManager.cpp
===
--- lib/StaticAnalyzer/Core/AnalysisManager.cpp
+++ lib/StaticAnalyzer/Core/AnalysisManager.cpp
@@ -14,28 +14,28 @@
 
 void AnalysisManager::anchor() { }
 
-AnalysisManager::AnalysisManager(
-ASTContext , DiagnosticsEngine , const LangOptions ,
-const PathDiagnosticConsumers , StoreManagerCreator storemgr,
-ConstraintManagerCreator constraintmgr, CheckerManager *checkerMgr,
-AnalyzerOptions , CodeInjector *injector)
-: AnaCtxMgr(ASTCtx, Options.UnoptimizedCFG,
-Options.includeImplicitDtorsInCFG(),
-/*AddInitializers=*/true, Options.includeTemporaryDtorsInCFG(),
-Options.includeLifetimeInCFG(),
-// Adding LoopExit elements to the CFG is a requirement for loop
-// unrolling.
-Options.includeLoopExitInCFG() || Options.shouldUnrollLoops(),
-Options.includeScopesInCFG(),
-Options.shouldSynthesizeBodies(),
-Options.shouldConditionalizeStaticInitializers(),
-/*addCXXNewAllocator=*/true,
-Options.includeRichConstructorsInCFG(),
-Options.shouldElideConstructors(),
-injector),
-  Ctx(ASTCtx), Diags(diags), LangOpts(lang), PathConsumers(PDC),
-  CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),
-  CheckerMgr(checkerMgr), options(Options) {
+AnalysisManager::AnalysisManager(ASTContext , DiagnosticsEngine ,
+ const PathDiagnosticConsumers ,
+ StoreManagerCreator storemgr,
+ ConstraintManagerCreator constraintmgr,
+ CheckerManager *checkerMgr,
+ AnalyzerOptions ,
+ CodeInjector *injector)
+: AnaCtxMgr(
+  ASTCtx, Options.UnoptimizedCFG, Options.includeImplicitDtorsInCFG(),
+  /*AddInitializers=*/true, Options.includeTemporaryDtorsInCFG(),
+  Options.includeLifetimeInCFG(),
+  // Adding LoopExit elements to the CFG is a requirement for loop
+  // unrolling.
+  Options.includeLoopExitInCFG() || Options.shouldUnrollLoops(),
+  Options.includeScopesInCFG(), Options.shouldSynthesizeBodies(),
+  Options.shouldConditionalizeStaticInitializers(),
+  /*addCXXNewAllocator=*/true, Options.includeRichConstructorsInCFG(),
+  Options.shouldElideConstructors(), injector),
+  

r339079 - [analyzer] Add ASTContext to CheckerManager

2018-08-06 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Aug  6 16:09:07 2018
New Revision: 339079

URL: http://llvm.org/viewvc/llvm-project?rev=339079=rev
Log:
[analyzer] Add ASTContext to CheckerManager

Some checkers require ASTContext. Having it in the constructor saves a
lot of boilerplate of having to pass it around.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h
cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h?rev=339079=339078=339079=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h Mon Aug  6 
16:09:07 2018
@@ -115,13 +115,14 @@ enum class ObjCMessageVisitKind {
 };
 
 class CheckerManager {
+  ASTContext 
   const LangOptions LangOpts;
   AnalyzerOptions 
   CheckName CurrentCheckName;
 
 public:
-  CheckerManager(const LangOptions , AnalyzerOptions )
-  : LangOpts(langOpts), AOptions(AOptions) {}
+  CheckerManager(ASTContext , AnalyzerOptions )
+  : Context(Context), LangOpts(Context.getLangOpts()), AOptions(AOptions) 
{}
 
   ~CheckerManager();
 
@@ -134,6 +135,7 @@ public:
 
   const LangOptions () const { return LangOpts; }
   AnalyzerOptions () { return AOptions; }
+  ASTContext () { return Context; }
 
   using CheckerRef = CheckerBase *;
   using CheckerTag = const void *;

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h?rev=339079=339078=339079=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h 
Mon Aug  6 16:09:07 2018
@@ -46,14 +46,12 @@ class AnalysisManager : public BugReport
 public:
   AnalyzerOptions 
 
-  AnalysisManager(ASTContext ,DiagnosticsEngine ,
-  const LangOptions ,
+  AnalysisManager(ASTContext , DiagnosticsEngine ,
   const PathDiagnosticConsumers ,
   StoreManagerCreator storemgr,
   ConstraintManagerCreator constraintmgr,
-  CheckerManager *checkerMgr,
-  AnalyzerOptions ,
-  CodeInjector* injector = nullptr);
+  CheckerManager *checkerMgr, AnalyzerOptions ,
+  CodeInjector *injector = nullptr);
 
   ~AnalysisManager() override;
 

Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h?rev=339079=339078=339079=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h Mon 
Aug  6 16:09:07 2018
@@ -10,6 +10,7 @@
 #ifndef LLVM_CLANG_STATICANALYZER_FRONTEND_CHECKERREGISTRATION_H
 #define LLVM_CLANG_STATICANALYZER_FRONTEND_CHECKERREGISTRATION_H
 
+#include "clang/AST/ASTContext.h"
 #include "clang/Basic/LLVM.h"
 #include 
 #include 
@@ -25,7 +26,8 @@ namespace ento {
   class CheckerRegistry;
 
   std::unique_ptr createCheckerManager(
-  AnalyzerOptions , const LangOptions ,
+  ASTContext ,
+  AnalyzerOptions ,
   ArrayRef plugins,
   ArrayRef> checkerRegistrationFns,
   DiagnosticsEngine );

Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp?rev=339079=339078=339079=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp Mon Aug  6 16:09:07 
2018
@@ -14,28 +14,28 @@ using namespace ento;
 
 void AnalysisManager::anchor() { }
 
-AnalysisManager::AnalysisManager(
-ASTContext , DiagnosticsEngine , const LangOptions ,
-const PathDiagnosticConsumers , StoreManagerCreator storemgr,
-ConstraintManagerCreator constraintmgr, CheckerManager *checkerMgr,
-AnalyzerOptions , CodeInjector *injector)
-: AnaCtxMgr(ASTCtx, Options.UnoptimizedCFG,
-

[PATCH] D50278: [Sema] Fix for crash on conditional operation with address_space pointer

2018-08-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:6522
+bool HasDifferingLAddrSpace = LAddrSpace != ResultAddrSpace;
+bool HasDifferingRAddrSpace = RAddrSpace != ResultAddrSpace;
+

I was going to tell you to use the predicate 
`Qualifiers::isAddressSpaceSupersetOf` here, but then I was looking at the uses 
of that, and I think the real fix is to just go into the implementation of 
`checkConditionalPointerCompatibility` and make the compatibility logic not 
OpenCL-specific.  The fast-path should just be whether the address spaces are 
different.

And it looks like this function has a bug where it always uses 
`LangAS::Default` outside of OpenCL even if the pointers are in the same 
address space.


Repository:
  rC Clang

https://reviews.llvm.org/D50278



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


[PATCH] D50342: Changed how LLVM IR was generated to increase vectorization

2018-08-06 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 159421.
emmettneyman added a comment.

Some small fixes to improve simplicity of generated IR


Repository:
  rC Clang

https://reviews.llvm.org/D50342

Files:
  clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp


Index: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
+++ clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -53,7 +53,7 @@
 break;
   }
   std::string ptr_var = get_var();
-  os << ptr_var << " = getelementptr i32, i32* " << arr << ", i64 %ct\n";
+  os << ptr_var << " = getelementptr inbounds i32, i32* " << arr << ", i64 
%ct\n";
   return ptr_var;
 }
 std::string RvalueToString(std::ostream , const Rvalue ) {
@@ -122,21 +122,20 @@
   return os;
 }
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "define void @foo(i32* %a, i32* %b, i32* noalias %c, i64 %s) 
{\n"
-<< "%i = alloca i64\n"
-<< "store i64 0, i64* %i\n"
-<< "br label %loop\n\n"
+  return os << "target triple = \"x86_64-unknown-linux-gnu\"\n"
+<< "define void @foo(i32* %a, i32* %b, i32* %c, i64 %s) {\n"
+<< "%1 = icmp sgt i64 %s, 0\n"
+<< "br i1 %1, label %start, label %end\n"
+<< "start:\n"
+<< "br label %loop\n"
+<< "end:\n"
+<< "ret void\n"
 << "loop:\n"
-<< "%ct = load i64, i64* %i\n"
-<< "%comp = icmp eq i64 %ct, %s\n"
-<< "br i1 %comp, label %endloop, label %body\n\n"
-<< "body:\n"
+<< " %ct   = phi i64 [ %ctnew, %loop ], [ 0, %start ]\n"
 << x.statements()
-<< "%z = add i64 1, %ct\n"
-<< "store i64 %z, i64* %i\n"
-<< "br label %loop\n\n"
-<< "endloop:\n"
-<< "ret void\n}\n";
+<< "%ctnew = add i64 %ct, 1\n"
+<< "%j = icmp eq i64 %ctnew, %s\n"
+<< "br i1 %j, label %end, label %loop\n}\n";
 }
 
 // -


Index: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
+++ clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -53,7 +53,7 @@
 break;
   }
   std::string ptr_var = get_var();
-  os << ptr_var << " = getelementptr i32, i32* " << arr << ", i64 %ct\n";
+  os << ptr_var << " = getelementptr inbounds i32, i32* " << arr << ", i64 %ct\n";
   return ptr_var;
 }
 std::string RvalueToString(std::ostream , const Rvalue ) {
@@ -122,21 +122,20 @@
   return os;
 }
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "define void @foo(i32* %a, i32* %b, i32* noalias %c, i64 %s) {\n"
-<< "%i = alloca i64\n"
-<< "store i64 0, i64* %i\n"
-<< "br label %loop\n\n"
+  return os << "target triple = \"x86_64-unknown-linux-gnu\"\n"
+<< "define void @foo(i32* %a, i32* %b, i32* %c, i64 %s) {\n"
+<< "%1 = icmp sgt i64 %s, 0\n"
+<< "br i1 %1, label %start, label %end\n"
+<< "start:\n"
+<< "br label %loop\n"
+<< "end:\n"
+<< "ret void\n"
 << "loop:\n"
-<< "%ct = load i64, i64* %i\n"
-<< "%comp = icmp eq i64 %ct, %s\n"
-<< "br i1 %comp, label %endloop, label %body\n\n"
-<< "body:\n"
+<< " %ct   = phi i64 [ %ctnew, %loop ], [ 0, %start ]\n"
 << x.statements()
-<< "%z = add i64 1, %ct\n"
-<< "store i64 %z, i64* %i\n"
-<< "br label %loop\n\n"
-<< "endloop:\n"
-<< "ret void\n}\n";
+<< "%ctnew = add i64 %ct, 1\n"
+<< "%j = icmp eq i64 %ctnew, %s\n"
+<< "br i1 %j, label %end, label %loop\n}\n";
 }
 
 // -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50342: Changed how LLVM IR was generated to increase vectorization

2018-08-06 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman added inline comments.



Comment at: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:127
+<< "define void @foo(i32* %a, i32* %b, i32* %c, i64 %s) {\n"
+<< "%1 = icmp sgt i64 %s, 0\n"
+<< "br i1 %1, label %start, label %end\n"

morehouse wrote:
> Should `%s` be signed?  Do we want unsigned compare here?
I don't think it matters since `%s` will always be positive (it will always be 
equal to 
`kArraySize` from `input_arrays.h`). 



Comment at: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:134
+<< "end:\n"
+<< "ret void\n"
 << "loop:\n"

morehouse wrote:
> Seems like the `endloop` label is unnecessary.  Does this help vectorize?  If 
> not, lets get rid of unconditional jumps to the next line.
I initially had it this way since that's how `-emit-llvm` generated the code. 
But it doesn't seem like it's necessary for loops to be vectorized upon further 
inspection.



Comment at: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:138
 << x.statements()
-<< "%z = add i64 1, %ct\n"
-<< "store i64 %z, i64* %i\n"
-<< "br label %loop\n\n"
-<< "endloop:\n"
-<< "ret void\n}\n";
+<< "%ctnew = add nuw nsw i64 %ct, 1\n"
+<< "%j = icmp eq i64 %ctnew, %s\n"

morehouse wrote:
> This will make overflow undefined... Isn't that the opposite of what we want? 
>  That will permit LLVM to assume overflow never happens and modify the code 
> in new ways based on that assumption.
That's a good point. It probably won't matter since this addition will never 
overflow (we're just starting at zero and incrementing by one). This is what 
was generated by `-emit-llvm`. I'll remove it to reduce confusion.


Repository:
  rC Clang

https://reviews.llvm.org/D50342



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


[PATCH] D43357: [Concepts] Function trailing requires clauses

2018-08-06 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Looking promising, but this patch will need some rework: you need to track the 
trailing requires clause on the `Declarator` itself, not on the `DeclChunk`, 
because it's not part of the `DeclChunk` (and may appear in contexts where 
there is no function chunk).




Comment at: include/clang/AST/Decl.h:1793-1796
+  /// \brief The constraint-expression introduced by the trailing
+  /// requires-clause provided in the function declaration, if any.
+  Expr *TrailingRequiresClause;
+

Please find a way to store this that doesn't make all `FunctionDecl`s 8 bytes 
larger. At the very least, you can move this to `CXXMethodDecl`, but perhaps 
it'd be better to include this as an optional component in the `DeclInfo`.



Comment at: include/clang/AST/Decl.h:1795
+  /// requires-clause provided in the function declaration, if any.
+  Expr *TrailingRequiresClause;
+

Not necessarily for this patch, but you'll need to think about how to represent 
a not-yet-instantiated trailing requires clause. (A requires clause isn't 
instantiated as part of instantiating the function it's attached to; it's 
instantiated later, when needed, like an exception specification or default 
argument.)



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2433
+def err_constrained_virtual_method : Error<
+  "a virtual function must not have a requires clause">;
+def err_reference_to_function_with_unsatisfied_constraints : Error<

"virtual function cannot have a requires clause" would be more in line with how 
we usually word diagnostics.



Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2435
+def err_reference_to_function_with_unsatisfied_constraints : Error<
+  "invalid reference to function %0 - constraints not satisfied">;
 

We generally separate a general problem and a specific problem with a colon, 
not a hyphen, in diagnostics.



Comment at: lib/Parse/ParseDecl.cpp:6098-6165
+  if (getLangOpts().CPlusPlus11 && Tok.is(tok::arrow)) {
+ParseTrailingReturn();
+  }
+  // Parse trailing requires-clause[opt].
+  if (getLangOpts().ConceptsTS && Tok.is(tok::kw_requires)) {
+LocalEndLoc = Tok.getLocation();
+ConsumeToken();

This is the wrong place to parse a //requires-clause//: a //requires-clause// 
is a trailing part of the overall //init-declarator// or //member-declarator//, 
not part of the function declarator chunk. For example:

```
using T = void ();
T x requires true; // ok, but you reject
void (f() requires true); // ill-formed but you accept
void (f()) requires true; // ok but you reject
```



Comment at: lib/Parse/ParseDecl.cpp:6102
+  // Parse trailing requires-clause[opt].
+  if (getLangOpts().ConceptsTS && Tok.is(tok::kw_requires)) {
+LocalEndLoc = Tok.getLocation();

The `ConceptsTS` check here is redundant. If we see a `kw_requires` token, the 
feature is enabled.



Comment at: lib/Parse/ParseDecl.cpp:6106-6110
+TentativeParsingAction TPA(*this);
+DiagnosticErrorTrap Trap(Diags);
+Diags.setSuppressAllDiagnostics(true);
+TrailingRequiresClause = ParseConstraintExpression();
+Diags.setSuppressAllDiagnostics(false);

This is not a reasonable way to deal with parse errors. Parsing an expression 
can have non-local effects, and suppressing diagnostics like this is not a safe 
way to provide error recovery. You're also suppressing all warnings within the 
expression, which is also inappropriate.

Instead, you should just parse the //requires-clause//. If you parse it 
correctly (not as a //constraint-expression//) the parse will stop before a 
possible `->` token anyway, because a top-level `->` expression is not 
permitted in a //constraint-logical-or-expression//.



Comment at: lib/Parse/ParseDecl.cpp:6109
+Diags.setSuppressAllDiagnostics(true);
+TrailingRequiresClause = ParseConstraintExpression();
+Diags.setSuppressAllDiagnostics(false);

This isn't right: a //constraint-logical-or-expression// is required here, not 
a //constraint-expression//.



Comment at: lib/Parse/ParseDecl.cpp:6112-6113
+
+if (!Trap.hasErrorOccurred() && TrailingRequiresClause.isUsable()
+&& !TrailingRequiresClause.isInvalid()) {
+  TPA.Commit();

Clang style puts the `&&` on the previous line.



Comment at: lib/Parse/ParseTentative.cpp:955-956
+  // A requires clause indicates a function declaration.
+  if (ParenCount) {
+SkipUntil(tok::l_paren);
+  } else {

This is wrong.`ParenCount` isn't just  *your* parens, it's all enclosing ones. 
And I don't think you need this check at all: the `requires` is either part of 
a suitable 

[PATCH] D50281: [lit, python] Always add quotes around the python path in lit

2018-08-06 Thread Stella Stamenova via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339074: [lit, python] Always add quotes around the python 
path in lit (authored by stella.stamenova, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50281?vs=159395=159415#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50281

Files:
  cfe/trunk/test/Tooling/clang-diff-json.cpp


Index: cfe/trunk/test/Tooling/clang-diff-json.cpp
===
--- cfe/trunk/test/Tooling/clang-diff-json.cpp
+++ cfe/trunk/test/Tooling/clang-diff-json.cpp
@@ -1,10 +1,10 @@
 // RUN: clang-diff -ast-dump-json %s -- \
-// RUN: | '%python' -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
+// RUN: | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN: | FileCheck %s
 
-// CHECK: "begin": 301,
+// CHECK: "begin": 311,
 // CHECK: "type": "FieldDecl",
-// CHECK: "end": 321,
+// CHECK: "end": 319,
 // CHECK: "type": "CXXRecordDecl",
 class A {
   int x;


Index: cfe/trunk/test/Tooling/clang-diff-json.cpp
===
--- cfe/trunk/test/Tooling/clang-diff-json.cpp
+++ cfe/trunk/test/Tooling/clang-diff-json.cpp
@@ -1,10 +1,10 @@
 // RUN: clang-diff -ast-dump-json %s -- \
-// RUN: | '%python' -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
+// RUN: | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN: | FileCheck %s
 
-// CHECK: "begin": 301,
+// CHECK: "begin": 311,
 // CHECK: "type": "FieldDecl",
-// CHECK: "end": 321,
+// CHECK: "end": 319,
 // CHECK: "type": "CXXRecordDecl",
 class A {
   int x;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339074 - [lit, python] Always add quotes around the python path in lit

2018-08-06 Thread Stella Stamenova via cfe-commits
Author: stella.stamenova
Date: Mon Aug  6 15:37:45 2018
New Revision: 339074

URL: http://llvm.org/viewvc/llvm-project?rev=339074=rev
Log:
[lit, python] Always add quotes around the python path in lit

Summary:
The issue with the python path is that the path to python on Windows can 
contain spaces. To make the tests always work, the path to python needs to be 
surrounded by quotes.

This is a companion change to: https://reviews.llvm.org/D50206

Reviewers: asmith, zturner

Subscribers: cfe-commits

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

Modified:
cfe/trunk/test/Tooling/clang-diff-json.cpp

Modified: cfe/trunk/test/Tooling/clang-diff-json.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/clang-diff-json.cpp?rev=339074=339073=339074=diff
==
--- cfe/trunk/test/Tooling/clang-diff-json.cpp (original)
+++ cfe/trunk/test/Tooling/clang-diff-json.cpp Mon Aug  6 15:37:45 2018
@@ -1,10 +1,10 @@
 // RUN: clang-diff -ast-dump-json %s -- \
-// RUN: | '%python' -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
+// RUN: | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN: | FileCheck %s
 
-// CHECK: "begin": 301,
+// CHECK: "begin": 311,
 // CHECK: "type": "FieldDecl",
-// CHECK: "end": 321,
+// CHECK: "end": 319,
 // CHECK: "type": "CXXRecordDecl",
 class A {
   int x;


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


[PATCH] D50342: Changed how LLVM IR was generated to increase vectorization

2018-08-06 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added inline comments.



Comment at: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:127
+<< "define void @foo(i32* %a, i32* %b, i32* %c, i64 %s) {\n"
+<< "%1 = icmp sgt i64 %s, 0\n"
+<< "br i1 %1, label %start, label %end\n"

Should `%s` be signed?  Do we want unsigned compare here?



Comment at: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:134
+<< "end:\n"
+<< "ret void\n"
 << "loop:\n"

Seems like the `endloop` label is unnecessary.  Does this help vectorize?  If 
not, lets get rid of unconditional jumps to the next line.



Comment at: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:138
 << x.statements()
-<< "%z = add i64 1, %ct\n"
-<< "store i64 %z, i64* %i\n"
-<< "br label %loop\n\n"
-<< "endloop:\n"
-<< "ret void\n}\n";
+<< "%ctnew = add nuw nsw i64 %ct, 1\n"
+<< "%j = icmp eq i64 %ctnew, %s\n"

This will make overflow undefined... Isn't that the opposite of what we want?  
That will permit LLVM to assume overflow never happens and modify the code in 
new ways based on that assumption.


Repository:
  rC Clang

https://reviews.llvm.org/D50342



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


[PATCH] D49511: [Sema/Attribute] Check for noderef attribute

2018-08-06 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 159409.
leonardchan marked 3 inline comments as done.
leonardchan added a comment.

- Changed tick to single quote in diagnostic


Repository:
  rC Clang

https://reviews.llvm.org/D49511

Files:
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprMember.cpp
  lib/Sema/SemaType.cpp
  test/Frontend/noderef.c
  test/Frontend/noderef_on_non_pointers.cpp
  test/Frontend/noderef_on_non_pointers.m

Index: test/Frontend/noderef_on_non_pointers.m
===
--- /dev/null
+++ test/Frontend/noderef_on_non_pointers.m
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -verify %s
+
+#define NODEREF __attribute__((noderef))
+
+@interface NSObject
++ (id)new;
+@end
+
+void func() {
+  id NODEREF obj = [NSObject new]; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+}
Index: test/Frontend/noderef_on_non_pointers.cpp
===
--- /dev/null
+++ test/Frontend/noderef_on_non_pointers.cpp
@@ -0,0 +1,88 @@
+// RUN: %clang_cc1 -fblocks -verify %s
+
+/**
+ * Test 'noderef' attribute against other pointer-like types.
+ */
+
+#define NODEREF __attribute__((noderef))
+
+void Normal() {
+  int NODEREF i;// expected-warning{{'noderef' can only be used on an array or pointer type}}
+  int NODEREF *i_ptr;   // ok
+  int NODEREF **i_ptr2; // ok
+  int *NODEREF i_ptr3;  // expected-warning{{'noderef' can only be used on an array or pointer type}}
+  int *NODEREF *i_ptr4; // ok
+
+  auto NODEREF *auto_i_ptr = i_ptr;
+  auto NODEREF auto_i = i; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+
+  struct {
+int x;
+int y;
+  } NODEREF *s;
+
+  int __attribute__((noderef(10))) * no_args; // expected-error{{'noderef' attribute takes no arguments}}
+}
+
+const int NODEREF *const_i_ptr;
+static int NODEREF *static_i_ptr;
+
+void ParenTypes() {
+  int NODEREF(*i_ptr);// ok (same as `int NODEREF *`)
+  int NODEREF *(*i_ptr2); // ok (same as `int NODEREF **`)
+}
+
+// Function declarations
+int NODEREF func();   // expected-warning{{'noderef' can only be used on an array or pointer type}}
+int NODEREF *func2(); // ok (returning pointer)
+
+typedef int NODEREF (*func3)(int); // expected-warning{{'noderef' can only be used on an array or pointer type}}
+typedef int NODEREF *(*func4)(int);
+
+void Arrays() {
+  int NODEREF i_arr[10];  // ok
+  int NODEREF i_arr2[10][10]; // ok
+  int NODEREF *i_arr3[10];// ok
+  int NODEREF i_arr4[] = {1, 2};
+}
+
+void ParenArrays() {
+  int NODEREF(i_ptr[10]);
+  int NODEREF(i_ptr2[10])[10];
+}
+
+typedef int NODEREF *(*func5[10])(int);
+
+// Arguments
+void func6(int NODEREF x); // expected-warning{{'noderef' can only be used on an array or pointer type}}
+void func7(int NODEREF *x);
+void func8() NODEREF;
+
+void References() {
+  int x = 2;
+  int NODEREF  = x; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+  int *xp = 
+  int NODEREF * = xp; // ok (reference to a NODEREF *)
+  int *NODEREF  = xp; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+}
+
+void BlockPointers() {
+  typedef int NODEREF (^IntBlock)(); // expected-warning{{'noderef' can only be used on an array or pointer type}}
+}
+
+class A {
+public:
+  int member;
+  int NODEREF *member2;
+  int NODEREF member3; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+};
+
+void MemberPointer() {
+  int NODEREF A::*var = ::member; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+}
+
+template 
+class B {
+  Ty NODEREF *member;
+  Ty NODEREF member2; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+};
Index: test/Frontend/noderef.c
===
--- /dev/null
+++ test/Frontend/noderef.c
@@ -0,0 +1,154 @@
+// RUN: %clang_cc1 -Wno-unused-value -verify %s
+
+#define NODEREF __attribute__((noderef))
+
+struct S {
+  int a;
+  int b;
+};
+
+struct S2 {
+  int a[2];
+  int NODEREF a2[2];
+  int *b;
+  int NODEREF *b2;
+  struct S *s;
+  struct S NODEREF *s2;
+};
+
+int NODEREF *func(int NODEREF *arg) {  // expected-note{{arg declared here}}
+  int y = *arg; // expected-warning{{dereferencing arg; was declared with a 'noderef' type}}
+  return arg;
+}
+
+void func2(int x) {}
+
+int test() {
+  int NODEREF *p;   // expected-note 31 {{p declared here}}
+  int *p2;
+
+  int x = *p;   // expected-warning{{dereferencing p; was declared with a 'noderef' type}}
+  x = *((int NODEREF *)p2); // expected-warning{{dereferencing expression marked as 'noderef'}}
+
+  int 

[PATCH] D50211: [analyzer] Fix displayed checker name for InnerPointerChecker

2018-08-06 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs added a comment.

In https://reviews.llvm.org/D50211#1190146, @NoQ wrote:

> Welcome to the club!


:D
Thanks, makes me feel better.


https://reviews.llvm.org/D50211



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


[PATCH] D50211: [analyzer] Fix displayed checker name for InnerPointerChecker

2018-08-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Welcome to the club!


https://reviews.llvm.org/D50211



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


[PATCH] D50211: [analyzer] Fix displayed checker name for InnerPointerChecker

2018-08-06 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs closed this revision.
rnkovacs added a comment.

Committed in r339067, I just messed up the revision-closing line in the commit 
message.


https://reviews.llvm.org/D50211



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


[PATCH] D50363: [analyzer] pr37204: Take signedness into account in BasicValueFactory::getTruthValue().

2018-08-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet, 
rnkovacs.
Herald added subscribers: cfe-commits, mikhail.ramalho, baloghadamsoftware, 
eraman.

I don't see why BasicValueFactory::getTruthValue(bool, QualType) always returns 
an unsigned `APSInt` even if the `QualType` is signed, so i fixed it.

This was causing a couple of crashes, including pr37204.


Repository:
  rC Clang

https://reviews.llvm.org/D50363

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  test/Analysis/casts.c
  test/Analysis/std-c-library-functions-inlined.c


Index: test/Analysis/std-c-library-functions-inlined.c
===
--- /dev/null
+++ test/Analysis/std-c-library-functions-inlined.c
@@ -0,0 +1,17 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=unix.StdCLibraryFunctions -verify 
%s
+// RUN: %clang_analyze_cc1 -triple i686-unknown-linux 
-analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux 
-analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple armv7-a15-linux 
-analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux 
-analyzer-checker=unix.StdCLibraryFunctions -verify %s
+
+// This test tests crashes that occur when standard functions are available
+// for inlining.
+
+// expected-no-diagnostics
+
+int isdigit(int _) { return !0; }
+void test_redefined_isdigit(int x) {
+  int (*func)(int) = isdigit;
+  for (; func(x);) // no-crash
+;
+}
Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -182,3 +182,9 @@
 c += 1;
   }
 }
+
+void testSwitchWithSizeofs() {
+  switch (sizeof(char) == 1) { // expected-warning{{switch condition has 
boolean value}}
+  case sizeof(char):; // no-crash
+  }
+}
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -211,7 +211,8 @@
   }
 
   const llvm::APSInt (bool b, QualType T) {
-return getValue(b ? 1 : 0, Ctx.getIntWidth(T), true);
+return T, getValue(b ? 1 : 0, Ctx.getIntWidth(T),
+   T->isUnsignedIntegerOrEnumerationType());
   }
 
   const llvm::APSInt (bool b) {


Index: test/Analysis/std-c-library-functions-inlined.c
===
--- /dev/null
+++ test/Analysis/std-c-library-functions-inlined.c
@@ -0,0 +1,17 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s
+// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s
+
+// This test tests crashes that occur when standard functions are available
+// for inlining.
+
+// expected-no-diagnostics
+
+int isdigit(int _) { return !0; }
+void test_redefined_isdigit(int x) {
+  int (*func)(int) = isdigit;
+  for (; func(x);) // no-crash
+;
+}
Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -182,3 +182,9 @@
 c += 1;
   }
 }
+
+void testSwitchWithSizeofs() {
+  switch (sizeof(char) == 1) { // expected-warning{{switch condition has boolean value}}
+  case sizeof(char):; // no-crash
+  }
+}
Index: include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
@@ -211,7 +211,8 @@
   }
 
   const llvm::APSInt (bool b, QualType T) {
-return getValue(b ? 1 : 0, Ctx.getIntWidth(T), true);
+return T, getValue(b ? 1 : 0, Ctx.getIntWidth(T),
+   T->isUnsignedIntegerOrEnumerationType());
   }
 
   const llvm::APSInt (bool b) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50278: [Sema] Fix for crash on conditional operation with address_space pointer

2018-08-06 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 159405.
leonardchan marked an inline comment as done.
leonardchan added a comment.

- Replaced instances of a `pointer type mismatch` warning involving 2 
conditional operands with different address spaces with a new error 
specifically for this situation.


Repository:
  rC Clang

https://reviews.llvm.org/D50278

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/Sema/address_spaces.c
  test/Sema/conditional-expr.c


Index: test/Sema/conditional-expr.c
===
--- test/Sema/conditional-expr.c
+++ test/Sema/conditional-expr.c
@@ -73,10 +73,12 @@
 
   int __attribute__((address_space(2))) *adr2;
   int __attribute__((address_space(3))) *adr3;
-  test0 ? adr2 : adr3; // expected-warning {{pointer type mismatch}} 
expected-warning {{expression result unused}}
+  test0 ? adr2 : adr3; // expected-warning {{expression result unused}}
+   // expected-error@-1{{unable to find common type 
between '__attribute__((address_space(2))) int *' and 
'__attribute__((address_space(3))) int *' for conditional operation}}
 
   // Make sure address-space mask ends up in the result type
-  (test0 ? (test0 ? adr2 : adr2) : nonconst_int); // expected-warning 
{{pointer type mismatch}} expected-warning {{expression result unused}}
+  (test0 ? (test0 ? adr2 : adr2) : nonconst_int); // expected-warning 
{{expression result unused}}
+  // expected-error@-1{{unable 
to find common type between '__attribute__((address_space(2))) int *' and 'int 
*' for conditional operation}}
 }
 
 int Postgresql() {
Index: test/Sema/address_spaces.c
===
--- test/Sema/address_spaces.c
+++ test/Sema/address_spaces.c
@@ -71,5 +71,5 @@
 
 // Clang extension doesn't forbid operations on pointers to different address 
spaces.
 char* cmp(_AS1 char *x,  _AS2 char *y) {
-  return x < y ? x : y; // expected-warning {{pointer type mismatch 
('__attribute__((address_space(1))) char *' and 
'__attribute__((address_space(2))) char *')}}
+  return x < y ? x : y; // expected-error{{unable to find common type between 
'__attribute__((address_space(1))) char *' and 
'__attribute__((address_space(2))) char *' for conditional operation}}
 }
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -6517,16 +6517,29 @@
 S.Context.getAddrSpaceQualType(S.Context.VoidTy, ResultAddrSpace));
 LHS = S.ImpCastExprToType(LHS.get(), incompatTy, LHSCastKind);
 RHS = S.ImpCastExprToType(RHS.get(), incompatTy, RHSCastKind);
-// FIXME: For OpenCL the warning emission and cast to void* leaves a room
-// for casts between types with incompatible address space qualifiers.
-// For the following code the compiler produces casts between global and
-// local address spaces of the corresponded innermost pointees:
-// local int *global *a;
-// global int *global *b;
-// a = (0 ? a : b); // see C99 6.5.16.1.p1.
-S.Diag(Loc, diag::ext_typecheck_cond_incompatible_pointers)
-<< LHSTy << RHSTy << LHS.get()->getSourceRange()
-<< RHS.get()->getSourceRange();
+
+bool HasDifferingLAddrSpace = LAddrSpace != ResultAddrSpace;
+bool HasDifferingRAddrSpace = RAddrSpace != ResultAddrSpace;
+
+if (S.getLangOpts().OpenCL ||
+!(HasDifferingLAddrSpace || HasDifferingRAddrSpace)) {
+  // FIXME: For OpenCL the warning emission and cast to void* leaves a room
+  // for casts between types with incompatible address space qualifiers.
+  // For the following code the compiler produces casts between global and
+  // local address spaces of the corresponded innermost pointees:
+  // local int *global *a;
+  // global int *global *b;
+  // a = (0 ? a : b); // see C99 6.5.16.1.p1.
+  S.Diag(Loc, diag::ext_typecheck_cond_incompatible_pointers)
+  << LHSTy << RHSTy << LHS.get()->getSourceRange()
+  << RHS.get()->getSourceRange();
+} else {
+  // If the addresse spacesare different, we do not allow a bitcast.
+  S.Diag(Loc, 
diag::err_typecheck_incompatible_conditional_pointer_operands)
+  << LHSTy << RHSTy << Sema::AA_Converting
+  << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
+}
+
 return incompatTy;
   }
 
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -6939,6 +6939,8 @@
   " changes retain/release properties of pointer">;
 def err_typecheck_comparison_of_distinct_blocks : Error<
   "comparison of distinct block types%diff{ ($ and $)|}0,1">;
+def err_typecheck_incompatible_conditional_pointer_operands : Error<
+  "unable 

r339067 - [analyzer] InnerPointerChecker: fix displayed checker name.

2018-08-06 Thread Reka Kovacs via cfe-commits
Author: rkovacs
Date: Mon Aug  6 15:03:42 2018
New Revision: 339067

URL: http://llvm.org/viewvc/llvm-project?rev=339067=rev
Log:
[analyzer] InnerPointerChecker: fix displayed checker name.

For InnerPointerChecker to function properly, both the checker itself
and parts of MallocChecker that handle relevant use-after-free problems
need to be turned on. So far, the latter part has been developed within
MallocChecker's NewDelete sub-checker, often causing warnings to appear
under that name. This patch defines a new CheckKind within MallocChecker
for the inner pointer checking functionality, so that the correct name
is displayed in warnings and in the ExplodedGraph.

Tested on clang-tidy.

Differential Review: https://reviews.llvm.org/D50211

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/InterCheckerAPI.h
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp?rev=339067=339066=339067=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp Mon Aug  6 
15:03:42 2018
@@ -15,6 +15,7 @@
 
 #include "AllocationState.h"
 #include "ClangSACheckers.h"
+#include "InterCheckerAPI.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -313,6 +314,6 @@ std::unique_ptr getI
 } // end namespace clang
 
 void ento::registerInnerPointerChecker(CheckerManager ) {
-  registerNewDeleteChecker(Mgr);
+  registerInnerPointerCheckerAux(Mgr);
   Mgr.registerChecker();
 }

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/InterCheckerAPI.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/InterCheckerAPI.h?rev=339067=339066=339067=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/InterCheckerAPI.h (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/InterCheckerAPI.h Mon Aug  6 15:03:42 
2018
@@ -20,5 +20,8 @@ namespace ento {
 /// Register the checker which evaluates CString API calls.
 void registerCStringCheckerBasic(CheckerManager );
 
+/// Register the part of MallocChecker connected to InnerPointerChecker.
+void registerInnerPointerCheckerAux(CheckerManager );
+
 }}
 #endif /* INTERCHECKERAPI_H_ */

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=339067=339066=339067=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Mon Aug  6 15:03:42 
2018
@@ -194,6 +194,7 @@ public:
 CK_NewDeleteChecker,
 CK_NewDeleteLeaksChecker,
 CK_MismatchedDeallocatorChecker,
+CK_InnerPointerChecker,
 CK_NumCheckKinds
   };
 
@@ -1662,13 +1663,10 @@ MallocChecker::getCheckIfTracked(Allocat
   case AF_IfNameIndex: {
 if (ChecksEnabled[CK_MallocChecker])
   return CK_MallocChecker;
-
-return Optional();
+return None;
   }
   case AF_CXXNew:
-  case AF_CXXNewArray:
-  // FIXME: Add new CheckKind for AF_InnerBuffer.
-  case AF_InnerBuffer: {
+  case AF_CXXNewArray: {
 if (IsALeakCheck) {
   if (ChecksEnabled[CK_NewDeleteLeaksChecker])
 return CK_NewDeleteLeaksChecker;
@@ -1677,7 +1675,12 @@ MallocChecker::getCheckIfTracked(Allocat
   if (ChecksEnabled[CK_NewDeleteChecker])
 return CK_NewDeleteChecker;
 }
-return Optional();
+return None;
+  }
+  case AF_InnerBuffer: {
+if (ChecksEnabled[CK_InnerPointerChecker])
+  return CK_InnerPointerChecker;
+return None;
   }
   case AF_None: {
 llvm_unreachable("no family");
@@ -1980,7 +1983,8 @@ void MallocChecker::ReportUseAfterFree(C
SymbolRef Sym) const {
 
   if (!ChecksEnabled[CK_MallocChecker] &&
-  !ChecksEnabled[CK_NewDeleteChecker])
+  !ChecksEnabled[CK_NewDeleteChecker] &&
+  !ChecksEnabled[CK_InnerPointerChecker])
 return;
 
   Optional CheckKind = getCheckIfTracked(C, Sym);
@@ -3109,6 +3113,18 @@ void ento::registerNewDeleteLeaksChecker
   }
 }
 
+// Intended to be used in InnerPointerChecker to register the part of
+// MallocChecker connected to it.
+void ento::registerInnerPointerCheckerAux(CheckerManager ) {
+registerCStringCheckerBasic(mgr);
+MallocChecker *checker = mgr.registerChecker();
+checker->IsOptimistic = mgr.getAnalyzerOptions().getBooleanOption(
+"Optimistic", false, checker);
+

[PATCH] D50361: [NFC] Test automatic variable initialization

2018-08-06 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

I'm honestly not sure there's anything to review here since it's just showing 
us what the current behavior is. LMK if I'm not testing something that I should.

I'd much rather test current behavior as one patch first, because then the 
follow-ups show a clear before / after diff instead of leaving you guessing as 
to what the previous behavior was.


Repository:
  rC Clang

https://reviews.llvm.org/D50361



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


[PATCH] D48661: [Fixed Point Arithmetic] Fixed Point Constant

2018-08-06 Thread Bruno Ricci via Phabricator via cfe-commits
bricci added a comment.

Added some comments inline. 
However I have not looked at the logic too closely and
have not looked at the tests at all.




Comment at: cfe/trunk/include/clang/AST/ASTContext.h:1966
   unsigned char getFixedPointIBits(QualType Ty) const;
+  FixedPointSemantics getFixedPointSemantics(QualType Ty) const;
+  APFixedPoint getFixedPointMax(QualType Ty) const;

could you add some comments for these functions ?
What are they doing ?



Comment at: cfe/trunk/include/clang/Basic/FixedPoint.h:24
+
+class ASTContext;
+class QualType;

This should be removed if unused. It is very strange to have
something basic like a fixed point type depending on ASTContext...



Comment at: cfe/trunk/include/clang/Basic/FixedPoint.h:31
+/// When HasUnsignedPadding is true and this type is signed, the first bit
+/// in the value this represents is treaded as padding.
+class FixedPointSemantics {

s/treaded/treated



Comment at: cfe/trunk/include/clang/Basic/FixedPoint.h:54
+  return Width - Scale;
+  }
+

Do you really need the branch here?
Why not just return
`Width - Scale - (IsSigned || (!IsSigned && HasUnsignedPadding))`

Also doc



Comment at: cfe/trunk/include/clang/Basic/FixedPoint.h:62
+  bool HasUnsignedPadding;
+};
+

My point is that you have two unsigned and then 3 bools.
This means that your class has now sizeof == 3*sizeof(unsigned)
This is annoying on 64 bits archs since pretty much everything
in clang is aligned to 8 bytes (because of pointer alignment requirements)
Just stuff your bits into Width or Scale. Moreover I think that
you could just use a single unsigned to store all of this.

For example you could here use a bit-field like so: 
unsigned Width : 15; (or any other appropriate split with Scale)
unsigned Scale : 14; (or any other appropriate split with Width)
unsigned IsSigned : 1;
unsigned IsSaturated : 1;
unsigned HasUnsignedPadding : 1;

Now I do not now if this matters or not in this case but it seems
to me that this is easy to do.



Comment at: cfe/trunk/include/clang/Basic/FixedPoint.h:85
+  Sema) {}
+
+   llvm::APSInt getValue() const { return llvm::APSInt(Val, !Sema.isSigned()); 
}

same comment about "sema"



Comment at: cfe/trunk/include/clang/Basic/FixedPoint.h:99
+  }
+
+  APFixedPoint shl(unsigned Amt) const {

Maybe a bit more documentation here...

Also use /// for comments explaining something to an user:
eg:

/// Create a new Frob blablabla
Frob makeFrobinator()

so that doxygen picks up these comments.

Use // for comments which are internal only
eg:

...
// TODO this is broken because blablabla
...



Comment at: cfe/trunk/include/clang/Basic/FixedPoint.h:110
+  }
+
+  // If LHS > RHS, return 1. If LHS == RHS, return 0. If LHS < RHS, return -1.

doc



Comment at: cfe/trunk/include/clang/Basic/FixedPoint.h:120
+  bool operator>(const APFixedPoint ) const { return compare(Other) > 0; 
}
+  bool operator<(const APFixedPoint ) const { return compare(Other) < 0; 
}
+  bool operator>=(const APFixedPoint ) const {

does this fit into 80 cols ?



Comment at: cfe/trunk/include/clang/Basic/FixedPoint.h:130
+  static APFixedPoint getMin(const FixedPointSemantics );
+
+private:

doc



Comment at: cfe/trunk/lib/AST/ASTContext.cpp:10439
+FixedPointSemantics ASTContext::getFixedPointSemantics(QualType Ty) const {
+  assert(Ty->isFixedPointType());
+  bool isSigned = Ty->isSignedFixedPointType();

assert( ... && "Ty is not a fixed point type!")



Comment at: cfe/trunk/lib/AST/ASTContext.cpp:10448
+APFixedPoint ASTContext::getFixedPointMax(QualType Ty) const {
+  assert(Ty->isFixedPointType());
+  return APFixedPoint::getMax(getFixedPointSemantics(Ty));

same



Comment at: cfe/trunk/lib/AST/ASTContext.cpp:10453
+APFixedPoint ASTContext::getFixedPointMin(QualType Ty) const {
+  assert(Ty->isFixedPointType());
+  return APFixedPoint::getMin(getFixedPointSemantics(Ty));

same



Comment at: cfe/trunk/lib/Basic/FixedPoint.cpp:15
+
+#include "clang/AST/ASTContext.h"
+#include "clang/Basic/FixedPoint.h"

Basic depends on ASTContext ? huh



Comment at: cfe/trunk/lib/Basic/FixedPoint.cpp:98
+  }
+
+  return 0;

Would this work: do a test for equality and return 0 if true,
then it seems to me that you can drop every `else if`.
Also maybe use the above trick to remove some branches.


Repository:
  rL LLVM

https://reviews.llvm.org/D48661



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

r339063 - [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name

2018-08-06 Thread Simon Marchi via cfe-commits
Author: simark
Date: Mon Aug  6 14:48:20 2018
New Revision: 339063

URL: http://llvm.org/viewvc/llvm-project?rev=339063=rev
Log:
[VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the 
requested name

Summary:
InMemoryFileSystem::status behaves differently than
RealFileSystem::status.  The Name contained in the Status returned by
RealFileSystem::status will be the path as requested by the caller,
whereas InMemoryFileSystem::status returns the normalized path.

For example, when requested the status for "../src/first.h",
RealFileSystem returns a Status with "../src/first.h" as the Name.
InMemoryFileSystem returns "/absolute/path/to/src/first.h".

The reason for this change is that I want to make a unit test in the
clangd testsuite (where we use an InMemoryFileSystem) to reproduce a
bug I get with the clangd program (where a RealFileSystem is used).
This difference in behavior "hides" the bug in the unit test version.

An indirect impact of this change is that a -Wnonportable-include-path
warning is now emitted in test PCH/case-insensitive-include.c.  This is
because the real path of the included file (with the wrong case) was not
available previously, whereas it is now.

Reviewers: malaperle, ilya-biryukov, bkramer

Reviewed By: ilya-biryukov

Subscribers: eric_niebler, malaperle, omtcyfz, hokein, bkramer, ilya-biryukov, 
ioeric, cfe-commits

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

Modified:
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Basic/VirtualFileSystem.cpp
cfe/trunk/test/PCH/case-insensitive-include.c
cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
cfe/trunk/unittests/Driver/ToolChainTest.cpp

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=339063=339062=339063=diff
==
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Mon Aug  6 14:48:20 2018
@@ -315,9 +315,11 @@ const FileEntry *FileManager::getFile(St
   UFE.InPCH = Data.InPCH;
   UFE.File = std::move(F);
   UFE.IsValid = true;
-  if (UFE.File)
-if (auto RealPathName = UFE.File->getName())
-  UFE.RealPathName = *RealPathName;
+
+  SmallString<128> RealPathName;
+  if (!FS->getRealPath(InterndFileName, RealPathName))
+UFE.RealPathName = RealPathName.str();
+
   return 
 }
 

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=339063=339062=339063=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Mon Aug  6 14:48:20 2018
@@ -474,12 +474,28 @@ class InMemoryNode {
   Status Stat;
   InMemoryNodeKind Kind;
 
+protected:
+  /// Return Stat.  This should only be used for internal/debugging use.  When
+  /// clients wants the Status of this node, they should use
+  /// \p getStatus(StringRef).
+  const Status () const { return Stat; }
+
 public:
   InMemoryNode(Status Stat, InMemoryNodeKind Kind)
   : Stat(std::move(Stat)), Kind(Kind) {}
   virtual ~InMemoryNode() = default;
 
-  const Status () const { return Stat; }
+  /// Return the \p Status for this node. \p RequestedName should be the name
+  /// through which the caller referred to this node. It will override
+  /// \p Status::Name in the return value, to mimic the behavior of \p 
RealFile.
+  Status getStatus(StringRef RequestedName) const {
+return Status::copyWithNewName(Stat, RequestedName);
+  }
+
+  /// Get the filename of this node (the name without the directory part).
+  StringRef getFileName() const {
+return llvm::sys::path::filename(Stat.getName());
+  }
   InMemoryNodeKind getKind() const { return Kind; }
   virtual std::string toString(unsigned Indent) const = 0;
 };
@@ -504,14 +520,21 @@ public:
   }
 };
 
-/// Adapt a InMemoryFile for VFS' File interface.
+/// Adapt a InMemoryFile for VFS' File interface.  The goal is to make
+/// \p InMemoryFileAdaptor mimic as much as possible the behavior of
+/// \p RealFile.
 class InMemoryFileAdaptor : public File {
   InMemoryFile 
+  /// The name to use when returning a Status for this file.
+  std::string RequestedName;
 
 public:
-  explicit InMemoryFileAdaptor(InMemoryFile ) : Node(Node) {}
+  explicit InMemoryFileAdaptor(InMemoryFile , std::string RequestedName)
+  : Node(Node), RequestedName(std::move(RequestedName)) {}
 
-  llvm::ErrorOr status() override { return Node.getStatus(); }
+  llvm::ErrorOr status() override {
+return Node.getStatus(RequestedName);
+  }
 
   llvm::ErrorOr>
   getBuffer(const Twine , int64_t FileSize, bool RequiresNullTerminator,
@@ -711,7 +734,7 @@ lookupInMemoryNode(const InMemoryFileSys
 llvm::ErrorOr InMemoryFileSystem::status(const Twine ) {
   auto Node = lookupInMemoryNode(*this, Root.get(), 

[PATCH] D48903: [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name

2018-08-06 Thread Simon Marchi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339063: [VirtualFileSystem] InMemoryFileSystem::status: 
Return a Status with the… (authored by simark, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D48903?vs=158625=159401#toc

Repository:
  rC Clang

https://reviews.llvm.org/D48903

Files:
  lib/Basic/FileManager.cpp
  lib/Basic/VirtualFileSystem.cpp
  test/PCH/case-insensitive-include.c
  unittests/Basic/VirtualFileSystemTest.cpp
  unittests/Driver/ToolChainTest.cpp

Index: test/PCH/case-insensitive-include.c
===
--- test/PCH/case-insensitive-include.c
+++ test/PCH/case-insensitive-include.c
@@ -13,7 +13,7 @@
 // RUN: touch -r %t-dir/case-insensitive-include.h %t.copy
 // RUN: mv %t.copy %t-dir/case-insensitive-include.h
 
-// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t.pch -I %t-dir -verify
+// RUN: %clang_cc1 -Wno-nonportable-include-path -fsyntax-only %s -include-pch %t.pch -I %t-dir -verify
 
 // expected-no-diagnostics
 
Index: lib/Basic/FileManager.cpp
===
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -315,9 +315,11 @@
   UFE.InPCH = Data.InPCH;
   UFE.File = std::move(F);
   UFE.IsValid = true;
-  if (UFE.File)
-if (auto RealPathName = UFE.File->getName())
-  UFE.RealPathName = *RealPathName;
+
+  SmallString<128> RealPathName;
+  if (!FS->getRealPath(InterndFileName, RealPathName))
+UFE.RealPathName = RealPathName.str();
+
   return 
 }
 
Index: lib/Basic/VirtualFileSystem.cpp
===
--- lib/Basic/VirtualFileSystem.cpp
+++ lib/Basic/VirtualFileSystem.cpp
@@ -474,12 +474,28 @@
   Status Stat;
   InMemoryNodeKind Kind;
 
+protected:
+  /// Return Stat.  This should only be used for internal/debugging use.  When
+  /// clients wants the Status of this node, they should use
+  /// \p getStatus(StringRef).
+  const Status () const { return Stat; }
+
 public:
   InMemoryNode(Status Stat, InMemoryNodeKind Kind)
   : Stat(std::move(Stat)), Kind(Kind) {}
   virtual ~InMemoryNode() = default;
 
-  const Status () const { return Stat; }
+  /// Return the \p Status for this node. \p RequestedName should be the name
+  /// through which the caller referred to this node. It will override
+  /// \p Status::Name in the return value, to mimic the behavior of \p RealFile.
+  Status getStatus(StringRef RequestedName) const {
+return Status::copyWithNewName(Stat, RequestedName);
+  }
+
+  /// Get the filename of this node (the name without the directory part).
+  StringRef getFileName() const {
+return llvm::sys::path::filename(Stat.getName());
+  }
   InMemoryNodeKind getKind() const { return Kind; }
   virtual std::string toString(unsigned Indent) const = 0;
 };
@@ -504,14 +520,21 @@
   }
 };
 
-/// Adapt a InMemoryFile for VFS' File interface.
+/// Adapt a InMemoryFile for VFS' File interface.  The goal is to make
+/// \p InMemoryFileAdaptor mimic as much as possible the behavior of
+/// \p RealFile.
 class InMemoryFileAdaptor : public File {
   InMemoryFile 
+  /// The name to use when returning a Status for this file.
+  std::string RequestedName;
 
 public:
-  explicit InMemoryFileAdaptor(InMemoryFile ) : Node(Node) {}
+  explicit InMemoryFileAdaptor(InMemoryFile , std::string RequestedName)
+  : Node(Node), RequestedName(std::move(RequestedName)) {}
 
-  llvm::ErrorOr status() override { return Node.getStatus(); }
+  llvm::ErrorOr status() override {
+return Node.getStatus(RequestedName);
+  }
 
   llvm::ErrorOr>
   getBuffer(const Twine , int64_t FileSize, bool RequiresNullTerminator,
@@ -711,7 +734,7 @@
 llvm::ErrorOr InMemoryFileSystem::status(const Twine ) {
   auto Node = lookupInMemoryNode(*this, Root.get(), Path);
   if (Node)
-return (*Node)->getStatus();
+return (*Node)->getStatus(Path.str());
   return Node.getError();
 }
 
@@ -724,7 +747,8 @@
   // When we have a file provide a heap-allocated wrapper for the memory buffer
   // to match the ownership semantics for File.
   if (auto *F = dyn_cast(*Node))
-return std::unique_ptr(new detail::InMemoryFileAdaptor(*F));
+return std::unique_ptr(
+new detail::InMemoryFileAdaptor(*F, Path.str()));
 
   // FIXME: errc::not_a_file?
   return make_error_code(llvm::errc::invalid_argument);
@@ -736,21 +760,33 @@
 class InMemoryDirIterator : public clang::vfs::detail::DirIterImpl {
   detail::InMemoryDirectory::const_iterator I;
   detail::InMemoryDirectory::const_iterator E;
+  std::string RequestedDirName;
+
+  void setCurrentEntry() {
+if (I != E) {
+  SmallString<256> Path(RequestedDirName);
+  llvm::sys::path::append(Path, I->second->getFileName());
+  CurrentEntry = I->second->getStatus(Path);
+} else {
+  // When we're at the end, make CurrentEntry invalid and DirIterImpl will
+  // do the rest.
+

[PATCH] D48903: [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name

2018-08-06 Thread Simon Marchi via Phabricator via cfe-commits
simark added a comment.

In https://reviews.llvm.org/D48903#1189056, @ilya-biryukov wrote:

> I see, thanks for the explanation.
>
> LGTM for the update revision, given we have confirmation the tests pass on 
> Windows.


Thanks, I'll push it, let's hope this time is the right time!


Repository:
  rC Clang

https://reviews.llvm.org/D48903



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


[PATCH] D50152: [CodeGen] Merge equivalent block copy/helper functions

2018-08-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

You might want to ask Richard on IRC if there are caveats when using that for 
these purposes.


Repository:
  rC Clang

https://reviews.llvm.org/D50152



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


[PATCH] D49438: [analyzer][UninitializedObjectChecker] New flag to turn off dereferencing

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

I'll be back in office tomorrow, about ~13 hours later. But feel free to commit 
it on my behalf if it's urgent.


https://reviews.llvm.org/D49438



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


[PATCH] D50152: [CodeGen] Merge equivalent block copy/helper functions

2018-08-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:1643
+if (Ctx.getBlockVarCopyInits(VD))
+  return true;
+  return false;

ahatanak wrote:
> ahatanak wrote:
> > rjmccall wrote:
> > > Can you just ask Sema to check `canThrow` for the expression and pass it 
> > > down?
> > Since this changes the existing behavior, I made changes to 
> > test/CodeGenCXX/block-byref-cxx-objc.cpp to test it. Previously, IRGen 
> > would emit an invoke to call `_Block_object_assign` when the constructor 
> > was marked as noexcept.
> Perhaps I misunderstood your comment, should I have Sema set a flag or 
> something in Expr when it calls a function that can throw?
Sema has a `canThrow` predicate that it uses when checking things like the 
`noexcept` expression.  I was thinking that you could pass that down with the 
copy expression in the AST for the block capture.

Constructors can have default-argument expressions that can throw even if the 
constructor itself can't, so it's important to do it that way.


Repository:
  rC Clang

https://reviews.llvm.org/D50152



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


[PATCH] D50361: [NFC] Test automatic variable initialization

2018-08-06 Thread JF Bastien via Phabricator via cfe-commits
jfb created this revision.
Herald added subscribers: cfe-commits, dexonsmith.

r337887 started using memset for automatic variable initialization where 
sensible. A follow-up discussion leads me to believe that we should better test 
automatic variable initialization, and that there are probably follow-up 
patches in clang and LLVM to improve codegen. It’ll be important to measure -O0 
compile time, and figure out which transforms should be in the frontend versus 
the backend.

This patch is just a test of the current behavior, no questions asked. 
Follow-up patches will tune the code generation.

rdar://problem/42981573


Repository:
  rC Clang

https://reviews.llvm.org/D50361

Files:
  test/CodeGenCXX/auto-var-init.cpp

Index: test/CodeGenCXX/auto-var-init.cpp
===
--- /dev/null
+++ test/CodeGenCXX/auto-var-init.cpp
@@ -0,0 +1,999 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fblocks -ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s
+
+template void used(T &) noexcept;
+
+#define TEST_UNINIT(NAME, TYPE) \
+  using type_##NAME = TYPE; \
+  void test_##NAME##_uninit() { \
+type_##NAME uninit; \
+used(uninit);   \
+  }
+
+// Value initialization on scalars, aggregate initialization on aggregates.
+#define TEST_BRACES(NAME, TYPE) \
+  using type_##NAME = TYPE; \
+  void test_##NAME##_braces() { \
+type_##NAME braces = {};\
+used(braces);   \
+  }
+
+#define TEST_CUSTOM(NAME, TYPE, ...)\
+  using type_##NAME = TYPE; \
+  void test_##NAME##_custom() { \
+type_##NAME custom __VA_ARGS__; \
+used(custom);   \
+  }
+
+struct empty {};
+struct small { char c; };
+struct smallinit { char c = 42; };
+struct smallpartinit { char c = 42, d; };
+struct nullinit { char* null = nullptr; };
+struct padded { char c; int i; };
+struct paddednullinit { char c = 0; int i = 0; };
+struct bitfield { int i : 4; int j : 2; };
+struct bitfieldaligned { int i : 4; int : 0; int j : 2; };
+struct big { unsigned a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z; };
+struct arraytail { int i; int arr[]; };
+struct tailpad { short s; char c; };
+struct notlockfree { long long a[4]; };
+struct semivolatile { int i; volatile int vi; };
+struct semivolatileinit { int i = 0x; volatile int vi = 0x; };
+struct base { virtual ~base(); };
+struct derived : public base {};
+struct virtualderived : public virtual base, public virtual derived {};
+union matching { int i; float f; };
+union matchingreverse { float f; int i; };
+union unmatched { char c; int i; };
+union unmatchedreverse { int i; char c; };
+union unmatchedfp { float f; double d; };
+enum emptyenum {};
+enum smallenum { VALUE };
+
+extern "C" {
+
+TEST_UNINIT(char, char);
+// CHECK-LABEL: @test_char_uninit()
+// CHECK:   %uninit = alloca i8, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(char, char);
+// CHECK-LABEL: @test_char_braces()
+// CHECK:   %braces = alloca i8, align 1
+// CHECK-NEXT:  store i8 0, i8* %braces, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
+
+TEST_UNINIT(uchar, unsigned char);
+// CHECK-LABEL: @test_uchar_uninit()
+// CHECK:   %uninit = alloca i8, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(uchar, unsigned char);
+// CHECK-LABEL: @test_uchar_braces()
+// CHECK:   %braces = alloca i8, align 1
+// CHECK-NEXT:  store i8 0, i8* %braces, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
+
+TEST_UNINIT(schar, signed char);
+// CHECK-LABEL: @test_schar_uninit()
+// CHECK:   %uninit = alloca i8, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(schar, signed char);
+// CHECK-LABEL: @test_schar_braces()
+// CHECK:   %braces = alloca i8, align 1
+// CHECK-NEXT:  store i8 0, i8* %braces, align 1
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
+
+TEST_UNINIT(wchar_t, wchar_t);
+// CHECK-LABEL: @test_wchar_t_uninit()
+// CHECK:   %uninit = alloca i32, align 4
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(wchar_t, wchar_t);
+// CHECK-LABEL: @test_wchar_t_braces()
+// CHECK:   %braces = alloca i32, align 4
+// CHECK-NEXT:  store i32 0, i32* %braces, align 4
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%braces)
+
+TEST_UNINIT(short, short);
+// CHECK-LABEL: @test_short_uninit()
+// CHECK:   %uninit = alloca i16, align 2
+// CHECK-NEXT:  call void @{{.*}}used{{.*}}%uninit)
+
+TEST_BRACES(short, short);
+// CHECK-LABEL: @test_short_braces()
+// CHECK:   %braces = alloca i16, align 2
+// CHECK-NEXT:  store i16 0, i16* %braces, align 2
+// CHECK-NEXT:  call void 

[PATCH] D49438: [analyzer][UninitializedObjectChecker] New flag to turn off dereferencing

2018-08-06 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

@Szelethus in any case, could you commit this change for now? I'm very keen on 
seeing the results on a few of our internal projects, and it's much easier to 
do that once the change is committed.


https://reviews.llvm.org/D49438



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


[PATCH] D50281: [lit, python] Always add quotes around the python path in lit

2018-08-06 Thread Stella Stamenova via Phabricator via cfe-commits
stella.stamenova updated this revision to Diff 159395.

Repository:
  rC Clang

https://reviews.llvm.org/D50281

Files:
  test/Tooling/clang-diff-json.cpp


Index: test/Tooling/clang-diff-json.cpp
===
--- test/Tooling/clang-diff-json.cpp
+++ test/Tooling/clang-diff-json.cpp
@@ -1,10 +1,10 @@
 // RUN: clang-diff -ast-dump-json %s -- \
-// RUN: | '%python' -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
+// RUN: | %python -c 'import json, sys; 
json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN: | FileCheck %s
 
-// CHECK: "begin": 301,
+// CHECK: "begin": 311,
 // CHECK: "type": "FieldDecl",
-// CHECK: "end": 321,
+// CHECK: "end": 319,
 // CHECK: "type": "CXXRecordDecl",
 class A {
   int x;


Index: test/Tooling/clang-diff-json.cpp
===
--- test/Tooling/clang-diff-json.cpp
+++ test/Tooling/clang-diff-json.cpp
@@ -1,10 +1,10 @@
 // RUN: clang-diff -ast-dump-json %s -- \
-// RUN: | '%python' -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
+// RUN: | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
 // RUN: | FileCheck %s
 
-// CHECK: "begin": 301,
+// CHECK: "begin": 311,
 // CHECK: "type": "FieldDecl",
-// CHECK: "end": 321,
+// CHECK: "end": 319,
 // CHECK: "type": "CXXRecordDecl",
 class A {
   int x;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r337005 - [NFC] Rename clang::AttributeList to clang::ParsedAttr

2018-08-06 Thread Michael Kruse via cfe-commits
Thank you.

Michael


2018-08-06 13:13 GMT-05:00 Keane, Erich :
> Good grief... I even made a note to remove this 'TODO' on my whiteboard!
>
> I discussed the name with AaronBallman who preferred ParsedAttr over 
> ParsedAttribute (since ParsedAttributes is also a type).
>
> Fixed in r339039.
>
> -Original Message-
> From: meiners...@googlemail.com [mailto:meiners...@googlemail.com] On Behalf 
> Of Michael Kruse
> Sent: Monday, August 6, 2018 11:00 AM
> To: Keane, Erich 
> Cc: cfe-commits 
> Subject: Re: r337005 - [NFC] Rename clang::AttributeList to clang::ParsedAttr
>
> 2018-07-13 10:07 GMT-05:00 Erich Keane via cfe-commits
> :
>> -class AttributeList { // TODO: This should really be called ParsedAttribute
>> +class ParsedAttr { // TODO: This should really be called ParsedAttribute
>
> Should this TODO be removed/ParsedAttr really be called ParsedAttribute?
>
> Michael
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50349: Port getStartLoc -> getBeginLoc

2018-08-06 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

+Hans (release manager for LLVM 7)

Hans, this patch series will affect the API of common Clang classes, resulting 
in patches to Clang SVN needing some (mechanical) modifications to be applied 
to the Clang 7 release branch if we land it now. What do you think about that? 
Would you prefer that we wait until after the 7.0.0 release to make 
cherry-picks easier?


Repository:
  rC Clang

https://reviews.llvm.org/D50349



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


[PATCH] D45444: [clang-tidy] implement new check for const-correctness

2018-08-06 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In https://reviews.llvm.org/D45444#1189262, @aaron.ballman wrote:

> However, I'm wondering how this should integrate with other const-correctness 
> efforts like `readability-non-const-parameter`?


I think this check/functionality will kinda replace the 
`readability-non-const-parameter` check. The readability check does not a full 
const-analysis too and i think only works on pointers or sth like this.
Maybe the check name will still exist, but use the `ExprMutAnalyzer` or it will 
become an alias to this with special configuration.
I would like to add support for marking methods `const` plus the ability for 
code transformation. Currently looking into `clang-refactor` framework to 
implement general refactoring primitives necessary for that.
In general its probably better to have one check, that handles all `const` 
issues.

> Also, I'm wondering how this check performs over a large code base like LLVM 
> -- how chatty are the diagnostics, and how bad is the false positive rate 
> (roughly)?

I will prepare a report for this tomorrow. Currently the LLVM builds take very 
long on my laptop :(


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45444



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


[PATCH] D50152: [CodeGen] Merge equivalent block copy/helper functions

2018-08-06 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:1643
+if (Ctx.getBlockVarCopyInits(VD))
+  return true;
+  return false;

ahatanak wrote:
> rjmccall wrote:
> > Can you just ask Sema to check `canThrow` for the expression and pass it 
> > down?
> Since this changes the existing behavior, I made changes to 
> test/CodeGenCXX/block-byref-cxx-objc.cpp to test it. Previously, IRGen would 
> emit an invoke to call `_Block_object_assign` when the constructor was marked 
> as noexcept.
Perhaps I misunderstood your comment, should I have Sema set a flag or 
something in Expr when it calls a function that can throw?


Repository:
  rC Clang

https://reviews.llvm.org/D50152



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


[PATCH] D45444: [clang-tidy] implement new check for const-correctness

2018-08-06 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 159390.
JonasToth marked 4 inline comments as done.
JonasToth added a comment.

- address review issues, todos/fixmes and diag nit


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45444

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp
  clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.h
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-const-correctness.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-const-correctness-pointer-as-values.cpp
  test/clang-tidy/cppcoreguidelines-const-correctness-values.cpp

Index: test/clang-tidy/cppcoreguidelines-const-correctness-values.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-const-correctness-values.cpp
@@ -0,0 +1,557 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-const-correctness %t
+
+// --- Provide test samples for primitive builtins -
+// - every 'p_*' variable is a 'potential_const_*' variable
+// - every 'np_*' variable is a 'non_potential_const_*' variable
+
+bool global;
+char np_global = 0; // globals can't be known to be const
+
+namespace foo {
+int scoped;
+float np_scoped = 1; // namespace variables are like globals
+} // namespace foo
+
+void some_function(double, wchar_t);
+
+void some_function(double np_arg0, wchar_t np_arg1) {
+  int p_local0 = 2;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared const
+
+  int np_local0;
+  const int np_local1 = 42;
+
+  unsigned int np_local2 = 3;
+  np_local2 <<= 4;
+
+  int np_local3 = 4;
+  ++np_local3;
+  int np_local4 = 4;
+  np_local4++;
+
+  int np_local5 = 4;
+  --np_local5;
+  int np_local6 = 4;
+  np_local6--;
+}
+
+void nested_scopes() {
+  int p_local0 = 2;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared const
+  int np_local0 = 42;
+
+  {
+int p_local1 = 42;
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: variable 'p_local1' of type 'int' can be declared const
+np_local0 *= 2;
+  }
+}
+
+void some_lambda_environment_capture_all_by_reference(double np_arg0) {
+  int np_local0 = 0;
+  int p_local0 = 1;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared const
+
+  int np_local2;
+  const int np_local3 = 2;
+
+  // Capturing all variables by reference prohibits making them const.
+  [&]() { ++np_local0; };
+
+  int p_local1 = 0;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'int' can be declared const
+}
+
+void some_lambda_environment_capture_all_by_value(double np_arg0) {
+  int np_local0 = 0;
+  int p_local0 = 1;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared const
+
+  int np_local1;
+  const int np_local2 = 2;
+
+  // Capturing by value has no influence on them.
+  [=]() { (void)p_local0; };
+
+  np_local0 += 10;
+}
+
+void function_inout_pointer(int *inout);
+void function_in_pointer(const int *in);
+
+void some_pointer_taking(int *out) {
+  int np_local0 = 42;
+  const int *const p0_np_local0 = _local0;
+  int *const p1_np_local0 = _local0;
+
+  int np_local1 = 42;
+  const int *const p0_np_local1 = _local1;
+  int *const p1_np_local1 = _local1;
+  *p1_np_local0 = 43;
+
+  int np_local2 = 42;
+  function_inout_pointer(_local2);
+
+  // Prevents const.
+  int np_local3 = 42;
+  out = _local3; // This returns and invalid address, its just about the AST
+
+  int p_local1 = 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'int' can be declared const
+  const int *const p0_p_local1 = _local1;
+
+  int p_local2 = 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local2' of type 'int' can be declared const
+  function_in_pointer(_local2);
+}
+
+void function_inout_ref(int );
+void function_in_ref(const int );
+
+void some_reference_taking() {
+  int np_local0 = 42;
+  const int _np_local0 = np_local0;
+  int _np_local0 = np_local0;
+  r1_np_local0 = 43;
+  const int _np_local0 = r1_np_local0;
+
+  int np_local1 = 42;
+  function_inout_ref(np_local1);
+
+  int p_local0 = 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared const
+  const int _p_local0 = p_local0;
+
+  int p_local1 = 42;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local1' of type 'int' can be declared const
+  function_in_ref(p_local1);
+}
+
+double *non_const_pointer_return() {
+  double p_local0 = 0.0;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'double' can be declared const
+  double np_local0 = 24.4;
+
+  return _local0;
+}
+
+const double *const_pointer_return() {
+  double p_local0 = 0.0;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 

[PATCH] D45444: [clang-tidy] implement new check for const-correctness

2018-08-06 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth marked an inline comment as done.
JonasToth added inline comments.



Comment at: clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp:183
+  // TODO Implement automatic code transformation to add the 'const'.
+  diag(Variable->getLocStart(), "variable %0 of type %1 can be declared const")
+  << Variable << Variable->getType();

aaron.ballman wrote:
> Still missing the single quotes around `const` in the diagnostic.
Ups. The comment has them :D


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45444



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


[PATCH] D45444: [clang-tidy] implement new check for const-correctness

2018-08-06 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth marked an inline comment as done.
JonasToth added inline comments.



Comment at: clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp:147
+  // Example: `int i = 10`, `int i` (will be used if program is correct)
+  const auto LocalValDecl = varDecl(unless(anyOf(
+  isLocal(), hasInitializer(anything()), unless(ConstType),

aaron.ballman wrote:
> JonasToth wrote:
> > @aaron.ballman The change was not valid for some reason. I leave it like it 
> > is if thats ok with you.
> That's really odd. I am fine leaving it as-is for this patch, but it 
> would be good to understand why that code fails as it seems like a reasonable 
> exposition.
Added a TODO. But maybe i did the transformation incorrectly too. Not all 
conditions are negative. Maybe all the negative ones can be inverted by 
demorgan. That should be correct.

I will check this out later.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45444



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


[PATCH] D50342: Changed how LLVM IR was generated to increase vectorization

2018-08-06 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 159389.
emmettneyman added a comment.

Added back more descriptive variable and loop names


Repository:
  rC Clang

https://reviews.llvm.org/D50342

Files:
  clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp


Index: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
+++ clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -53,7 +53,7 @@
 break;
   }
   std::string ptr_var = get_var();
-  os << ptr_var << " = getelementptr i32, i32* " << arr << ", i64 %ct\n";
+  os << ptr_var << " = getelementptr inbounds i32, i32* " << arr << ", i64 
%ct\n";
   return ptr_var;
 }
 std::string RvalueToString(std::ostream , const Rvalue ) {
@@ -122,21 +122,22 @@
   return os;
 }
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "define void @foo(i32* %a, i32* %b, i32* noalias %c, i64 %s) 
{\n"
-<< "%i = alloca i64\n"
-<< "store i64 0, i64* %i\n"
-<< "br label %loop\n\n"
+  return os << "target triple = \"x86_64-unknown-linux-gnu\"\n"
+<< "define void @foo(i32* %a, i32* %b, i32* %c, i64 %s) {\n"
+<< "%1 = icmp sgt i64 %s, 0\n"
+<< "br i1 %1, label %start, label %end\n"
+<< "start:\n"
+<< "br label %loop\n"
+<< "endloop:\n"
+<< "br label %end\n"
+<< "end:\n"
+<< "ret void\n"
 << "loop:\n"
-<< "%ct = load i64, i64* %i\n"
-<< "%comp = icmp eq i64 %ct, %s\n"
-<< "br i1 %comp, label %endloop, label %body\n\n"
-<< "body:\n"
+<< " %ct   = phi i64 [ %ctnew, %loop ], [ 0, %start ]\n"
 << x.statements()
-<< "%z = add i64 1, %ct\n"
-<< "store i64 %z, i64* %i\n"
-<< "br label %loop\n\n"
-<< "endloop:\n"
-<< "ret void\n}\n";
+<< "%ctnew = add nuw nsw i64 %ct, 1\n"
+<< "%j = icmp eq i64 %ctnew, %s\n"
+<< "br i1 %j, label %endloop, label %loop\n}\n";
 }
 
 // -


Index: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
+++ clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -53,7 +53,7 @@
 break;
   }
   std::string ptr_var = get_var();
-  os << ptr_var << " = getelementptr i32, i32* " << arr << ", i64 %ct\n";
+  os << ptr_var << " = getelementptr inbounds i32, i32* " << arr << ", i64 %ct\n";
   return ptr_var;
 }
 std::string RvalueToString(std::ostream , const Rvalue ) {
@@ -122,21 +122,22 @@
   return os;
 }
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "define void @foo(i32* %a, i32* %b, i32* noalias %c, i64 %s) {\n"
-<< "%i = alloca i64\n"
-<< "store i64 0, i64* %i\n"
-<< "br label %loop\n\n"
+  return os << "target triple = \"x86_64-unknown-linux-gnu\"\n"
+<< "define void @foo(i32* %a, i32* %b, i32* %c, i64 %s) {\n"
+<< "%1 = icmp sgt i64 %s, 0\n"
+<< "br i1 %1, label %start, label %end\n"
+<< "start:\n"
+<< "br label %loop\n"
+<< "endloop:\n"
+<< "br label %end\n"
+<< "end:\n"
+<< "ret void\n"
 << "loop:\n"
-<< "%ct = load i64, i64* %i\n"
-<< "%comp = icmp eq i64 %ct, %s\n"
-<< "br i1 %comp, label %endloop, label %body\n\n"
-<< "body:\n"
+<< " %ct   = phi i64 [ %ctnew, %loop ], [ 0, %start ]\n"
 << x.statements()
-<< "%z = add i64 1, %ct\n"
-<< "store i64 %z, i64* %i\n"
-<< "br label %loop\n\n"
-<< "endloop:\n"
-<< "ret void\n}\n";
+<< "%ctnew = add nuw nsw i64 %ct, 1\n"
+<< "%j = icmp eq i64 %ctnew, %s\n"
+<< "br i1 %j, label %endloop, label %loop\n}\n";
 }
 
 // -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50152: [CodeGen] Merge equivalent block copy/helper functions

2018-08-06 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 159388.
ahatanak marked 2 inline comments as done.
ahatanak added a comment.

Address review comments.


Repository:
  rC Clang

https://reviews.llvm.org/D50152

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGBlocks.h
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGNonTrivialStruct.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/blocks-1.c
  test/CodeGen/blocks.c
  test/CodeGen/sanitize-thread-no-checking-at-run-time.m
  test/CodeGenCXX/block-byref-cxx-objc.cpp
  test/CodeGenCXX/blocks.cpp
  test/CodeGenCXX/cxx-block-objects.cpp
  test/CodeGenObjC/arc-blocks.m
  test/CodeGenObjC/debug-info-block-helper.m
  test/CodeGenObjC/debug-info-blocks.m
  test/CodeGenObjC/mrc-weak.m
  test/CodeGenObjC/strong-in-c-struct.m
  test/CodeGenObjCXX/arc-blocks.mm
  test/CodeGenObjCXX/lambda-to-block.mm
  test/CodeGenObjCXX/mrc-weak.mm

Index: test/CodeGenObjCXX/mrc-weak.mm
===
--- test/CodeGenObjCXX/mrc-weak.mm
+++ test/CodeGenObjCXX/mrc-weak.mm
@@ -119,10 +119,10 @@
 // CHECK:   call void @use_block
 // CHECK:   call void @objc_destroyWeak
 
-// CHECK-LABEL: define internal void @__copy_helper_block
+// CHECK-LABEL: define linkonce_odr hidden void @__copy_helper_block
 // CHECK:   @objc_copyWeak
 
-// CHECK-LABEL: define internal void @__destroy_helper_block
+// CHECK-LABEL: define linkonce_odr hidden void @__destroy_helper_block
 // CHECK:   @objc_destroyWeak
 
 void test8(void) {
@@ -142,8 +142,8 @@
 // CHECK:   call void @objc_destroyWeak
 
 // CHECK-LABEL: define void @_Z14test9_baselinev()
-// CHECK:   define internal void @__copy_helper
-// CHECK:   define internal void @__destroy_helper
+// CHECK:   define linkonce_odr hidden void @__copy_helper
+// CHECK:   define linkonce_odr hidden void @__destroy_helper
 void test9_baseline(void) {
   Foo *p = get_object();
   use_block(^{ [p run]; });
Index: test/CodeGenObjCXX/lambda-to-block.mm
===
--- test/CodeGenObjCXX/lambda-to-block.mm
+++ test/CodeGenObjCXX/lambda-to-block.mm
@@ -12,7 +12,7 @@
 void hasLambda(Copyable x) {
   takesBlock([x] () { });
 }
-// CHECK-LABEL: define internal void @__copy_helper_block_
+// CHECK-LABEL: define internal void @"__copy_helper_block_
 // CHECK: call void @"_ZZ9hasLambda8CopyableEN3$_0C1ERKS0_"
 // CHECK-LABEL: define internal void @"_ZZ9hasLambda8CopyableEN3$_0C2ERKS0_"
 // CHECK: call void @_ZN8CopyableC1ERKS_
Index: test/CodeGenObjCXX/arc-blocks.mm
===
--- test/CodeGenObjCXX/arc-blocks.mm
+++ test/CodeGenObjCXX/arc-blocks.mm
@@ -1,8 +1,10 @@
 // RUN: %clang_cc1 -std=gnu++98 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -fexceptions -fobjc-arc-exceptions -o - %s | FileCheck -check-prefix CHECK %s
 // RUN: %clang_cc1 -std=gnu++98 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -fexceptions -fobjc-arc-exceptions -O1 -o - %s | FileCheck -check-prefix CHECK-O1 %s
+// RUN: %clang_cc1 -std=gnu++98 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-runtime-has-weak -fblocks -fobjc-arc -o - %s | FileCheck -check-prefix CHECK-NOEXCP %s
 
 // CHECK: [[A:.*]] = type { i64, [10 x i8*] }
 // CHECK: %[[STRUCT_TEST1_S0:.*]] = type { i32 }
+// CHECK: %[[STRUCT_TRIVIAL_INTERNAL:.*]] = type { i32 }
 // CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
 
 // CHECK: [[LAYOUT0:@.*]] = private unnamed_addr constant [3 x i8] c" 9\00"
@@ -55,34 +57,34 @@
 
 // Check that copy/dispose helper functions are exception safe.
 
-// CHECK-LABEL: define internal void @__copy_helper_block_(
-// CHECK: %[[BLOCK_SOURCE:.*]] = bitcast i8* %{{.*}} to <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>*
-// CHECK: %[[BLOCK_DEST:.*]] = bitcast i8* %{{.*}} to <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>*
+// CHECK-LABEL: define linkonce_odr hidden void @__copy_helper_block_ea8_32s40b48w56c15_ZTSN5test12S0E60c15_ZTSN5test12S0E(
+// CHECK: %[[BLOCK_SOURCE:.*]] = bitcast i8* %{{.*}} to <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]], %[[STRUCT_TRIVIAL_INTERNAL]] }>*
+// CHECK: %[[BLOCK_DEST:.*]] = bitcast i8* %{{.*}} to <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]], %[[STRUCT_TRIVIAL_INTERNAL]] }>*
 
-// CHECK: %[[V4:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>, <{ i8*, i32, i32, i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8*, i8*, i8*, %[[STRUCT_TEST1_S0]], %[[STRUCT_TEST1_S0]] }>* %[[BLOCK_SOURCE]], i32 0, i32 6
-// CHECK: %[[V5:.*]] = getelementptr 

[PATCH] D50359: Add a new library, libclang-cxx

2018-08-06 Thread Pirama Arumuga Nainar via Phabricator via cfe-commits
pirama added a comment.

This implements the new library proposed in 
http://lists.llvm.org/pipermail/cfe-dev/2018-August/058736.html.


Repository:
  rC Clang

https://reviews.llvm.org/D50359



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


[PATCH] D50359: Add a new library, libclang-cxx

2018-08-06 Thread Pirama Arumuga Nainar via Phabricator via cfe-commits
pirama created this revision.
Herald added a subscriber: mgorny.

The current libclang.so exports only the symbols required for the stable
C api.  This is opposed to libLLVM.so, which exports all the symbols
from the LLVM libraries, including those from the C++ API.  This patch
adds libclang-cxx.so that is similar to libLLVM.so and exports all
symbols from the clang libraries.  The motivation for this library is to
be used by Clang tools that use Clang's C++ api.  They no longer need to
link against the individual static libraries.


Repository:
  rC Clang

https://reviews.llvm.org/D50359

Files:
  CMakeLists.txt
  tools/CMakeLists.txt
  tools/libclang-cxx/CMakeLists.txt

Index: tools/libclang-cxx/CMakeLists.txt
===
--- /dev/null
+++ tools/libclang-cxx/CMakeLists.txt
@@ -0,0 +1,74 @@
+set(LIBS
+  clangBasic
+  clangCodeGen
+  clangDriver
+  clangFrontend
+  clangFrontendTool
+)
+
+if (CLANG_ENABLE_ARCMT)
+  list(APPEND LIBS clangARCMigrate)
+endif ()
+
+if (TARGET clangTidyPlugin)
+  add_definitions(-DCLANG_TOOL_EXTRA_BUILD)
+  list(APPEND LIBS clangTidyPlugin)
+  list(APPEND LIBS clangIncludeFixerPlugin)
+  if(LLVM_ENABLE_MODULES)
+list(APPEND LLVM_COMPILE_FLAGS "-fmodules-ignore-macro=CLANG_TOOL_EXTRA_BUILD")
+  endif()
+endif ()
+
+find_library(DL_LIBRARY_PATH dl)
+if (DL_LIBRARY_PATH)
+  list(APPEND LIBS dl)
+endif()
+
+if( LLVM_ENABLE_PIC )
+  set(ENABLE_SHARED SHARED)
+endif()
+
+if(NOT LLVM_ENABLE_PIC AND NOT WIN32)
+  set(ENABLE_STATIC STATIC)
+endif()
+
+if(WIN32)
+  set(output_name "libclang_cxx")
+else()
+  set(output_name "clang_cxx")
+endif()
+
+set(LIBS -Wl,--whole-archive ${LIBS} -Wl,--no-whole-archive)
+
+add_clang_library(libclang_cxx ${ENABLE_SHARED} ${ENABLE_STATIC}
+  OUTPUT_NAME ${output_name}
+
+  LINK_LIBS
+  ${LIBS}
+  )
+
+if(ENABLE_SHARED)
+  if(WIN32)
+set_target_properties(libclang_cxx
+  PROPERTIES
+  VERSION ${LIBCLANG_LIBRARY_VERSION}
+  DEFINE_SYMBOL _CINDEX_LIB_)
+  elseif(APPLE)
+  set(LIBCLANG_CXX_LINK_FLAGS " -Wl,-compatibility_version -Wl,1")
+  set(LIBCLANG_CXX_LINK_FLAGS "${LIBCLANG_CXX_LINK_FLAGS} -Wl,-current_version -Wl,${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
+
+set_property(TARGET libclang_cxx APPEND_STRING PROPERTY
+LINK_FLAGS ${LIBCLANG_CXX_LINK_FLAGS})
+  else()
+set_target_properties(libclang_cxx
+  PROPERTIES
+  VERSION ${LIBCLANG_LIBRARY_VERSION}
+  DEFINE_SYMBOL _CINDEX_LIB_)
+# FIXME: _CINDEX_LIB_ affects dllexport/dllimport on Win32.
+if(LLVM_ENABLE_MODULES AND NOT WIN32)
+  target_compile_options(libclang_cxx PRIVATE
+"-fmodules-ignore-macro=_CINDEX_LIB_"
+)
+endif()
+  endif()
+endif()
Index: tools/CMakeLists.txt
===
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -35,3 +35,4 @@
 
 # libclang may require clang-tidy in clang-tools-extra.
 add_clang_subdirectory(libclang)
+add_clang_subdirectory(libclang-cxx)
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -431,7 +431,7 @@
 "Major version number that will be appended to the clang executable name")
 set(LIBCLANG_LIBRARY_VERSION
 "${CLANG_VERSION_MAJOR}" CACHE STRING
-"Major version number that will be appended to the libclang library")
+"Major version number that will be appended to the libclang, libclang_cxx libraries")
 mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION)
 
 option(CLANG_INCLUDE_TESTS
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49438: [analyzer][UninitializedObjectChecker] New flag to turn off dereferencing

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

If we ignore references, check whether the pointee was constructed within the 
constructor, and maybe add some other clever heuristics, I'm very much in favor 
of enabling pointer chasing by enabled. But I totally support disabling it for 
now.


https://reviews.llvm.org/D49438



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


[PATCH] D50278: [Sema] Fix for crash on conditional operation with address_space pointer

2018-08-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: test/Sema/conditional-expr.c:78
+   // expected-error@-1{{converting 
'__attribute__((address_space(2))) int *' to type 'void *' changes address 
space of pointer}}
+   // expected-error@-2{{converting 
'__attribute__((address_space(3))) int *' to type 'void *' changes address 
space of pointer}}
 

leonardchan wrote:
> rjmccall wrote:
> > Also, these diagnostics seem wrong.  Where is `void *` coming from?
> When dumping the AST this is what the resulting type is for the conditional 
> expression already is if the operands are 2 pointers with different address 
> spaces.
> 
> According to this comment, the reason seems to be because this is what GCC 
> does:
> 
> ```
>  6512 // In this situation, we assume void* type. No especially good
>  6513 // reason, but this is what gcc does, and we do have to pick
>  6514 // to get a consistent AST.
> ```
That makes sense in general, but in this case it's not a great diagnostic; we 
should just emit an error when trying to pick a common type.


Repository:
  rC Clang

https://reviews.llvm.org/D50278



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


[PATCH] D49438: [analyzer][UninitializedObjectChecker] New flag to turn off dereferencing

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

In https://reviews.llvm.org/D49438#1189772, @george.karpenkov wrote:

> > I think what pointer chasing should do, is check whether that pointer owns 
> > the pointee
>
> But ownership is a convention, and it's not always deducible from a codebase.


How about the following case:

  struct A {
struct B {
  int b;
};
std::unique_ptr ptr;
A() : ptr(new B) {}
  };
  
  A a;

Here, `a->ptr->b` is clearly uninitialized, and I think it's fine to assume in 
most cases that no other pointer points to it right after `a`'s construction.

> I think of those as two separate checks, and I think we should only talk 
> about enabling the pointer-chasing after we had established that just 
> checking for uninitialized fields finds lots of valid bugs (and we can only 
> do that after it gets enabled for many projects)

I think in the earlier case `*this->ptr` should be regarded as a regular field, 
and it could be analyzed without fear of spamming too many reports. Currently 
the biggest problem is that many objects could contain references to the same 
object:

  struct A { int x; };
  struct B {
A 
B(A ) : a(a) {}
  };
  struct C {
A 
C(A ) : a(a) {}
  };
  
  A a;
  B b(a);
  C c(a); // a.x reported twice


https://reviews.llvm.org/D49438



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


[PATCH] D50278: [Sema] Fix for crash on conditional operation with address_space pointer

2018-08-06 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In https://reviews.llvm.org/D50278#1189919, @rjmccall wrote:

> I would expect this to replace the existing warning, not to appear together 
> with it.


Will do.




Comment at: test/Sema/conditional-expr.c:78
+   // expected-error@-1{{converting 
'__attribute__((address_space(2))) int *' to type 'void *' changes address 
space of pointer}}
+   // expected-error@-2{{converting 
'__attribute__((address_space(3))) int *' to type 'void *' changes address 
space of pointer}}
 

rjmccall wrote:
> Also, these diagnostics seem wrong.  Where is `void *` coming from?
When dumping the AST this is what the resulting type is for the conditional 
expression already is if the operands are 2 pointers with different address 
spaces.

According to this comment, the reason seems to be because this is what GCC does:

```
 6512 // In this situation, we assume void* type. No especially good
 6513 // reason, but this is what gcc does, and we do have to pick
 6514 // to get a consistent AST.
```


Repository:
  rC Clang

https://reviews.llvm.org/D50278



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


[PATCH] D50352: Mark up deprecated methods as such

2018-08-06 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

I don't think Clang/LLVM use `[[deprecated]]` anywhere. Just change the API and 
people have to migrate their code.


Repository:
  rC Clang

https://reviews.llvm.org/D50352



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


[PATCH] D44352: [Concepts] Constrained template parameters

2018-08-06 Thread Saar Raz via Phabricator via cfe-commits
saar.raz updated this revision to Diff 159378.
saar.raz added a comment.

Split TryParseConstrainedParameter and ParseConstrainedTemplateParameter in 
preparation for requries expressions.


Repository:
  rC Clang

https://reviews.llvm.org/D44352

Files:
  include/clang/AST/DeclTemplate.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/TemplateBase.h
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Parse/Parser.h
  include/clang/Sema/Sema.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/DeclTemplate.cpp
  lib/AST/ODRHash.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/ParseTemplate.cpp
  lib/Sema/SemaCXXScopeSpec.cpp
  lib/Sema/SemaConcept.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CXX/concepts-ts/temp/temp.constr/temp.constr.decl/class-template-decl.cpp
  test/CXX/concepts-ts/temp/temp.param/p10.cpp
  test/Parser/cxx-constrained-template-param-with-partial-id.cpp
  test/Parser/cxx-constrained-template-param.cpp
  tools/libclang/CIndex.cpp

Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -750,6 +750,10 @@
 }
 
 bool CursorVisitor::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
+  if (Expr *CE = D->getConstraintExpression())
+if (Visit(MakeCXCursor(CE, StmtParent, TU, RegionOfInterest)))
+  return true;
+
   // Visit the default argument.
   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
 if (TypeSourceInfo *DefArg = D->getDefaultArgumentInfo())
@@ -898,6 +902,10 @@
 bool CursorVisitor::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
   if (VisitDeclaratorDecl(D))
 return true;
+
+  if (Expr *CE = D->getConstraintExpression())
+if (Visit(MakeCXCursor(CE, StmtParent, TU, RegionOfInterest)))
+  return true;
   
   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
 if (Expr *DefArg = D->getDefaultArgument())
@@ -929,7 +937,11 @@
 bool CursorVisitor::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
   if (VisitTemplateParameters(D->getTemplateParameters()))
 return true;
-  
+
+  if (Expr *CE = D->getConstraintExpression())
+if (Visit(MakeCXCursor(CE, StmtParent, TU, RegionOfInterest)))
+  return true;
+
   if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited() &&
   VisitTemplateArgumentLoc(D->getDefaultArgument()))
 return true;
Index: test/Parser/cxx-constrained-template-param.cpp
===
--- /dev/null
+++ test/Parser/cxx-constrained-template-param.cpp
@@ -0,0 +1,90 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ %s -verify
+// expected-no-diagnostics
+
+namespace type
+{
+  template
+  concept C1 = true;
+
+  template
+  using A = T[10];
+
+  using a = A;
+
+  namespace ns {
+template
+concept C2 = true;
+  }
+
+  template requires sizeof(T1) <= sizeof(T2)
+  struct B { };
+
+  using b = B;
+
+  template
+  struct C { };
+
+  using c1 = C;
+  using c2 = C;
+}
+
+namespace non_type
+{
+  template
+  concept C1 = true;
+
+  template
+  int A = v;
+
+  int& a = A<1>;
+
+  namespace ns {
+template
+concept C2 = true;
+  }
+
+  template requires sizeof(v1) <= sizeof(v2)
+  struct B { };
+
+  using b = B;
+
+  template
+  struct C { };
+
+  using c1 = C;
+  using c2 = C;
+}
+
+namespace temp
+{
+  template
+  struct test1 { };
+
+  template
+  struct test2 { };
+
+  template typename T>
+  concept C1 = true;
+
+  template
+  using A = TT;
+
+  using a = A;
+
+  namespace ns {
+template typename... TT>
+concept C2 = true;
+  }
+
+  template
+requires sizeof(TT1) <= sizeof(TT2)
+  struct B { };
+
+  using b = B;
+
+  template
+  struct C { };
+
+  using c1 = C;
+  using c2 = C;
+}
\ No newline at end of file
Index: test/Parser/cxx-constrained-template-param-with-partial-id.cpp
===
--- /dev/null
+++ test/Parser/cxx-constrained-template-param-with-partial-id.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -std=c++2a -fconcepts-ts -x c++ %s -verify
+
+template
+concept C1 = true;
+
+template // expected-error {{concept 'C1' requires more than 1 template argument; provide the remaining arguments explicitly to use it here}} expected-error{{explicit specialization of alias templates is not permitted}}
+using badA = T[10];
+
+template T>
+using A = T[10];
+
+using a = A;
+
+namespace ns {
+  template
+  concept C2 = true;
+}
+
+template // expected-error 2{{concept 'C2' requires more than 1 template argument; provide the remaining arguments explicitly to use it here}}
+requires sizeof(T1) <= sizeof(T2) // expected-error{{expected unqualified-id}}
+struct badB { 

[PATCH] D50342: Changed how LLVM IR was generated to increase vectorization

2018-08-06 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added inline comments.



Comment at: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:129
+<< "br i1 %5, label %6, label %8\n"
+<< "; :6:\n"
+<< "br label %9\n"

emmettneyman wrote:
> morehouse wrote:
> > Does removing branch names really make this easier to vectorize?
> Same answer as above. Should I change these back?
I think the previous labels were more human-readable.


Repository:
  rC Clang

https://reviews.llvm.org/D50342



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


[PATCH] D50152: [CodeGen] Merge equivalent block copy/helper functions

2018-08-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:1630
+if (const CXXDestructorDecl *DD = RD->getDestructor())
+  if (const auto FPT = DD->getType()->getAs())
+// Conservatively assume the destructor can throw if the exception

I'm pretty sure this step can't fail.



Comment at: lib/CodeGen/CGBlocks.cpp:1643
+if (Ctx.getBlockVarCopyInits(VD))
+  return true;
+  return false;

Can you just ask Sema to check `canThrow` for the expression and pass it down?


Repository:
  rC Clang

https://reviews.llvm.org/D50152



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


[PATCH] D50278: [Sema] Fix for crash on conditional operation with address_space pointer

2018-08-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: test/Sema/conditional-expr.c:78
+   // expected-error@-1{{converting 
'__attribute__((address_space(2))) int *' to type 'void *' changes address 
space of pointer}}
+   // expected-error@-2{{converting 
'__attribute__((address_space(3))) int *' to type 'void *' changes address 
space of pointer}}
 

Also, these diagnostics seem wrong.  Where is `void *` coming from?


Repository:
  rC Clang

https://reviews.llvm.org/D50278



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


[PATCH] D50278: [Sema] Fix for crash on conditional operation with address_space pointer

2018-08-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I would expect this to replace the existing warning, not to appear together 
with it.


Repository:
  rC Clang

https://reviews.llvm.org/D50278



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


[PATCH] D49952: Check for NULL Destination-Type when creating ArrayConstant

2018-08-06 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Sure, that's fine.


https://reviews.llvm.org/D49952



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


[PATCH] D50342: Changed how LLVM IR was generated to increase vectorization

2018-08-06 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 159373.
emmettneyman added a comment.

Changed pc to unknown


Repository:
  rC Clang

https://reviews.llvm.org/D50342

Files:
  clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp


Index: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
+++ clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -43,17 +43,17 @@
   std::string arr;
   switch(x.arr()) {
   case VarRef::ARR_A:
-arr = "%a";
+arr = "%0";
 break;
   case VarRef::ARR_B:
-arr = "%b";
+arr = "%1";
 break;
   case VarRef::ARR_C:
-arr = "%c";
+arr = "%2";
 break;
   }
   std::string ptr_var = get_var();
-  os << ptr_var << " = getelementptr i32, i32* " << arr << ", i64 %ct\n";
+  os << ptr_var << " = getelementptr inbounds i32, i32* " << arr << ", i64 
%ct\n";
   return ptr_var;
 }
 std::string RvalueToString(std::ostream , const Rvalue ) {
@@ -122,21 +122,22 @@
   return os;
 }
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "define void @foo(i32* %a, i32* %b, i32* noalias %c, i64 %s) 
{\n"
-<< "%i = alloca i64\n"
-<< "store i64 0, i64* %i\n"
-<< "br label %loop\n\n"
-<< "loop:\n"
-<< "%ct = load i64, i64* %i\n"
-<< "%comp = icmp eq i64 %ct, %s\n"
-<< "br i1 %comp, label %endloop, label %body\n\n"
-<< "body:\n"
+  return os << "target triple = \"x86_64-unknown-linux-gnu\"\n"
+<< "define void @foo(i32*, i32*, i32*, i64) {\n"
+<< "%5 = icmp sgt i64 %3, 0\n"
+<< "br i1 %5, label %6, label %8\n"
+<< "; :6:\n"
+<< "br label %9\n"
+<< "; :7:\n"
+<< "br label %8\n"
+<< "; :8:\n"
+<< "ret void\n"
+<< "; :9:\n"
+<< " %ct   = phi i64 [ %10, %9 ], [ 0, %6 ]\n"
 << x.statements()
-<< "%z = add i64 1, %ct\n"
-<< "store i64 %z, i64* %i\n"
-<< "br label %loop\n\n"
-<< "endloop:\n"
-<< "ret void\n}\n";
+<< "%10 = add nuw nsw i64 %ct, 1\n"
+<< "%11 = icmp eq i64 %10, %3\n"
+<< "br i1 %11, label %7, label %9\n}\n";
 }
 
 // -


Index: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
+++ clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -43,17 +43,17 @@
   std::string arr;
   switch(x.arr()) {
   case VarRef::ARR_A:
-arr = "%a";
+arr = "%0";
 break;
   case VarRef::ARR_B:
-arr = "%b";
+arr = "%1";
 break;
   case VarRef::ARR_C:
-arr = "%c";
+arr = "%2";
 break;
   }
   std::string ptr_var = get_var();
-  os << ptr_var << " = getelementptr i32, i32* " << arr << ", i64 %ct\n";
+  os << ptr_var << " = getelementptr inbounds i32, i32* " << arr << ", i64 %ct\n";
   return ptr_var;
 }
 std::string RvalueToString(std::ostream , const Rvalue ) {
@@ -122,21 +122,22 @@
   return os;
 }
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "define void @foo(i32* %a, i32* %b, i32* noalias %c, i64 %s) {\n"
-<< "%i = alloca i64\n"
-<< "store i64 0, i64* %i\n"
-<< "br label %loop\n\n"
-<< "loop:\n"
-<< "%ct = load i64, i64* %i\n"
-<< "%comp = icmp eq i64 %ct, %s\n"
-<< "br i1 %comp, label %endloop, label %body\n\n"
-<< "body:\n"
+  return os << "target triple = \"x86_64-unknown-linux-gnu\"\n"
+<< "define void @foo(i32*, i32*, i32*, i64) {\n"
+<< "%5 = icmp sgt i64 %3, 0\n"
+<< "br i1 %5, label %6, label %8\n"
+<< "; :6:\n"
+<< "br label %9\n"
+<< "; :7:\n"
+<< "br label %8\n"
+<< "; :8:\n"
+<< "ret void\n"
+<< "; :9:\n"
+<< " %ct   = phi i64 [ %10, %9 ], [ 0, %6 ]\n"
 << x.statements()
-<< "%z = add i64 1, %ct\n"
-<< "store i64 %z, i64* %i\n"
-<< "br label %loop\n\n"
-<< "endloop:\n"
-<< "ret void\n}\n";
+<< "%10 = add nuw nsw i64 %ct, 1\n"
+<< "%11 = icmp eq i64 %10, %3\n"
+<< "br i1 %11, label %7, label %9\n}\n";
 }
 
 // -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50342: Changed how LLVM IR was generated to increase vectorization

2018-08-06 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman added inline comments.



Comment at: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:125
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "define void @foo(i32* %a, i32* %b, i32* noalias %c, i64 %s) 
{\n"
-<< "%i = alloca i64\n"
-<< "store i64 0, i64* %i\n"
-<< "br label %loop\n\n"
-<< "loop:\n"
-<< "%ct = load i64, i64* %i\n"
-<< "%comp = icmp eq i64 %ct, %s\n"
-<< "br i1 %comp, label %endloop, label %body\n\n"
-<< "body:\n"
+  return os << "target triple = \"x86_64-pc-linux-gnu\"\n"
+<< "define void @foo(i32*, i32*, i32*, i64) {\n"

morehouse wrote:
> What does `pc` mean in this triple?  I'm used to seeing 
> `x86_64-unknown-linux-gnu`.
It's probably generating `pc` since I'm using my desktop. I'll change it to 
`unknown` so it's not platform-specific.



Comment at: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:126
+  return os << "target triple = \"x86_64-pc-linux-gnu\"\n"
+<< "define void @foo(i32*, i32*, i32*, i64) {\n"
+<< "%5 = icmp sgt i64 %3, 0\n"

morehouse wrote:
> Does removing the variable names really make this easier to vectorize?
It doesn't, I just thought it was cleaner and produced slightly smaller IR. It 
also more closely mimics the behavior of the `-emit-llvm` flag.



Comment at: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:129
+<< "br i1 %5, label %6, label %8\n"
+<< "; :6:\n"
+<< "br label %9\n"

morehouse wrote:
> Does removing branch names really make this easier to vectorize?
Same answer as above. Should I change these back?


Repository:
  rC Clang

https://reviews.llvm.org/D50342



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


[PATCH] D50347: Add getBeginLoc API to replace getStartLoc

2018-08-06 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor resigned from this revision.
teemperor added a comment.
This revision now requires review to proceed.

Woops, I wanted to resign actually (and not accept this).


Repository:
  rC Clang

https://reviews.llvm.org/D50347



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


[PATCH] D50199: [MinGW] Predefine UNICODE if -municode is specified during compilation

2018-08-06 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339048: [MinGW] Predefine UNICODE if -municode is specified 
during compilation (authored by mstorsjo, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D50199

Files:
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/mingw.cpp


Index: test/Driver/mingw.cpp
===
--- test/Driver/mingw.cpp
+++ test/Driver/mingw.cpp
@@ -56,3 +56,8 @@
 // CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}x86_64-w64-mingw32"
 // CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}backward"
 // CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}x86_64-w64-mingw32{{/|}}include"
+
+// RUN: %clang -target i686-windows-gnu -E -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_MINGW_NO_UNICODE %s
+// RUN: %clang -target i686-windows-gnu -E -### %s -municode 2>&1 | FileCheck 
-check-prefix=CHECK_MINGW_UNICODE %s
+// CHECK_MINGW_NO_UNICODE-NOT: "-DUNICODE"
+// CHECK_MINGW_UNICODE: "-DUNICODE"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3346,6 +3346,9 @@
   if (Args.hasArg(options::OPT_static))
 CmdArgs.push_back("-static-define");
 
+  if (Args.hasArg(options::OPT_municode))
+CmdArgs.push_back("-DUNICODE");
+
   if (isa(JA))
 RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
 


Index: test/Driver/mingw.cpp
===
--- test/Driver/mingw.cpp
+++ test/Driver/mingw.cpp
@@ -56,3 +56,8 @@
 // CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}x86_64-w64-mingw32"
 // CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}backward"
 // CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}x86_64-w64-mingw32{{/|}}include"
+
+// RUN: %clang -target i686-windows-gnu -E -### %s 2>&1 | FileCheck -check-prefix=CHECK_MINGW_NO_UNICODE %s
+// RUN: %clang -target i686-windows-gnu -E -### %s -municode 2>&1 | FileCheck -check-prefix=CHECK_MINGW_UNICODE %s
+// CHECK_MINGW_NO_UNICODE-NOT: "-DUNICODE"
+// CHECK_MINGW_UNICODE: "-DUNICODE"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3346,6 +3346,9 @@
   if (Args.hasArg(options::OPT_static))
 CmdArgs.push_back("-static-define");
 
+  if (Args.hasArg(options::OPT_municode))
+CmdArgs.push_back("-DUNICODE");
+
   if (isa(JA))
 RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339048 - [MinGW] Predefine UNICODE if -municode is specified during compilation

2018-08-06 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Mon Aug  6 12:48:44 2018
New Revision: 339048

URL: http://llvm.org/viewvc/llvm-project?rev=339048=rev
Log:
[MinGW] Predefine UNICODE if -municode is specified during compilation

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/mingw.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=339048=339047=339048=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Aug  6 12:48:44 2018
@@ -3346,6 +3346,9 @@ void Clang::ConstructJob(Compilation ,
   if (Args.hasArg(options::OPT_static))
 CmdArgs.push_back("-static-define");
 
+  if (Args.hasArg(options::OPT_municode))
+CmdArgs.push_back("-DUNICODE");
+
   if (isa(JA))
 RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
 

Modified: cfe/trunk/test/Driver/mingw.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/mingw.cpp?rev=339048=339047=339048=diff
==
--- cfe/trunk/test/Driver/mingw.cpp (original)
+++ cfe/trunk/test/Driver/mingw.cpp Mon Aug  6 12:48:44 2018
@@ -56,3 +56,8 @@
 // CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}x86_64-w64-mingw32"
 // CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}lib{{/|}}gcc{{/|}}x86_64-w64-mingw32{{/|}}5.3-posix{{/|}}include{{/|}}c++{{/|}}backward"
 // CHECK_MINGW_UBUNTU_POSIX_TREE: 
"{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|}}x86_64-w64-mingw32{{/|}}include"
+
+// RUN: %clang -target i686-windows-gnu -E -### %s 2>&1 | FileCheck 
-check-prefix=CHECK_MINGW_NO_UNICODE %s
+// RUN: %clang -target i686-windows-gnu -E -### %s -municode 2>&1 | FileCheck 
-check-prefix=CHECK_MINGW_UNICODE %s
+// CHECK_MINGW_NO_UNICODE-NOT: "-DUNICODE"
+// CHECK_MINGW_UNICODE: "-DUNICODE"


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


[PATCH] D50355: Port getLocEnd -> getEndLoc

2018-08-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
Herald added subscribers: cfe-commits, kbarton, ioeric, nemanjai.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50355

Files:
  change-namespace/ChangeNamespace.cpp
  clang-move/ClangMove.cpp
  clang-tidy/android/CloexecCheck.cpp
  clang-tidy/bugprone/ArgumentCommentCheck.cpp
  clang-tidy/bugprone/CopyConstructorInitCheck.cpp
  clang-tidy/bugprone/InaccurateEraseCheck.cpp
  clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp
  clang-tidy/bugprone/StringIntegerAssignmentCheck.cpp
  clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp
  clang-tidy/bugprone/UnusedRaiiCheck.cpp
  clang-tidy/cppcoreguidelines/NoMallocCheck.cpp
  clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  clang-tidy/cppcoreguidelines/ProTypeCstyleCastCheck.cpp
  clang-tidy/fuchsia/DefaultArgumentsCheck.cpp
  clang-tidy/google/AvoidCStyleCastsCheck.cpp
  clang-tidy/google/ExplicitConstructorCheck.cpp
  clang-tidy/llvm/TwineLocalCheck.cpp
  clang-tidy/misc/RedundantExpressionCheck.cpp
  clang-tidy/misc/StaticAssertCheck.cpp
  clang-tidy/misc/UnusedAliasDeclsCheck.cpp
  clang-tidy/misc/UnusedParametersCheck.cpp
  clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tidy/modernize/AvoidBindCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/PassByValueCheck.cpp
  clang-tidy/modernize/RedundantVoidArgCheck.cpp
  clang-tidy/modernize/UseEmplaceCheck.cpp
  clang-tidy/modernize/UseEqualsDeleteCheck.cpp
  clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp
  clang-tidy/performance/FasterStringFindCheck.cpp
  clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tidy/readability/AvoidConstParamsInDecls.cpp
  clang-tidy/readability/BracesAroundStatementsCheck.cpp
  clang-tidy/readability/DeleteNullPointerCheck.cpp
  clang-tidy/readability/FunctionSizeCheck.cpp
  clang-tidy/readability/ImplicitBoolConversionCheck.cpp
  clang-tidy/readability/MisleadingIndentationCheck.cpp
  clang-tidy/readability/RedundantControlFlowCheck.cpp
  clang-tidy/readability/SimplifyBooleanExprCheck.cpp
  clang-tidy/readability/SimplifySubscriptExprCheck.cpp
  clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp
  unittests/clang-tidy/OverlappingReplacementsTest.cpp

Index: unittests/clang-tidy/OverlappingReplacementsTest.cpp
===
--- unittests/clang-tidy/OverlappingReplacementsTest.cpp
+++ unittests/clang-tidy/OverlappingReplacementsTest.cpp
@@ -52,7 +52,7 @@
 auto *Cond = If->getCond();
 SourceRange Range = Cond->getSourceRange();
 if (auto *D = If->getConditionVariable()) {
-  Range = SourceRange(D->getBeginLoc(), D->getLocEnd());
+  Range = SourceRange(D->getBeginLoc(), D->getEndLoc());
 }
 diag(Range.getBegin(), "the cake is a lie") << FixItHint::CreateReplacement(
 CharSourceRange::getTokenRange(Range), "false");
Index: clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp
===
--- clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp
+++ clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp
@@ -52,15 +52,15 @@
 return;
 
   SourceLocation AfterPtr = Lexer::getLocForEndOfToken(
-  PtrExpr->getLocEnd(), 0, *Result.SourceManager, getLangOpts());
+  PtrExpr->getEndLoc(), 0, *Result.SourceManager, getLangOpts());
 
   diag(DeleteExpr->getBeginLoc(),
"prefer '= nullptr' to 'delete x.release()' to reset unique_ptr<> "
"objects")
   << FixItHint::CreateRemoval(CharSourceRange::getCharRange(
  DeleteExpr->getBeginLoc(), PtrExpr->getBeginLoc()))
   << FixItHint::CreateReplacement(
- CharSourceRange::getTokenRange(AfterPtr, DeleteExpr->getLocEnd()),
+ CharSourceRange::getTokenRange(AfterPtr, DeleteExpr->getEndLoc()),
  " = nullptr");
 }
 
Index: clang-tidy/readability/SimplifySubscriptExprCheck.cpp
===
--- clang-tidy/readability/SimplifySubscriptExprCheck.cpp
+++ clang-tidy/readability/SimplifySubscriptExprCheck.cpp
@@ -63,7 +63,7 @@
 DiagBuilder << FixItHint::CreateInsertion(Member->getBeginLoc(), "(*")
 << FixItHint::CreateInsertion(Member->getOperatorLoc(), ")");
   DiagBuilder << FixItHint::CreateRemoval(
-  {Member->getOperatorLoc(), Call->getLocEnd()});
+  {Member->getOperatorLoc(), Call->getEndLoc()});
 }
 
 void SimplifySubscriptExprCheck::storeOptions(
Index: clang-tidy/readability/SimplifyBooleanExprCheck.cpp
===
--- clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -385,7 +385,7 @@
const Expr *ReplaceWith, bool Negated) {
 std::string Replacement =
 replacementExpression(Result, Negated, ReplaceWith);
-SourceRange 

[PATCH] D50353: Remove deprecated API

2018-08-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
Herald added a reviewer: teemperor.
Herald added a subscriber: cfe-commits.
Herald added a reviewer: teemperor.

Repository:
  rC Clang

https://reviews.llvm.org/D50353

Files:
  include/clang/AST/Comment.h
  include/clang/AST/Decl.h
  include/clang/AST/DeclBase.h
  include/clang/AST/DeclCXX.h
  include/clang/AST/DeclObjC.h
  include/clang/AST/DeclarationName.h
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/ExprObjC.h
  include/clang/AST/ExprOpenMP.h
  include/clang/AST/OpenMPClause.h
  include/clang/AST/RawCommentList.h
  include/clang/AST/Stmt.h
  include/clang/AST/StmtCXX.h
  include/clang/AST/StmtObjC.h
  include/clang/AST/StmtOpenMP.h
  include/clang/AST/TypeLoc.h
  include/clang/Analysis/CloneDetection.h
  include/clang/Sema/DeclSpec.h
  lib/CodeGen/CoverageMappingGen.cpp
  lib/Sema/SemaChecking.cpp

Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -6121,12 +6121,10 @@
 StartToken, StartTokenByteOffset);
   }
 
-  [[deprecated]] SourceLocation getLocStart() const LLVM_READONLY { return getBeginLoc();  }
   SourceLocation getBeginLoc() const LLVM_READONLY {
 return FExpr->getBeginLoc().getLocWithOffset(Offset);
   }
 
-  [[deprecated]] SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc();  }
   SourceLocation getEndLoc() const LLVM_READONLY { return FExpr->getEndLoc(); }
 };
 
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -67,7 +67,6 @@
 
   void setStartLoc(SourceLocation Loc) { LocStart = Loc; }
 
-  [[deprecated]] SourceLocation getStartLoc() const LLVM_READONLY { return getBeginLoc();  }
   SourceLocation getBeginLoc() const {
 assert(LocStart && "Region has no start location");
 return *LocStart;
Index: include/clang/Sema/DeclSpec.h
===
--- include/clang/Sema/DeclSpec.h
+++ include/clang/Sema/DeclSpec.h
@@ -505,9 +505,7 @@
   const CXXScopeSpec () const { return TypeScope; }
 
   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
-  [[deprecated]] SourceLocation getLocStart() const LLVM_READONLY { return getBeginLoc();  }
   SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
-  [[deprecated]] SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc();  }
   SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
 
   SourceLocation getTypeSpecWidthLoc() const { return TSWRange.getBegin(); }
@@ -1122,9 +1120,7 @@
   SourceRange getSourceRange() const LLVM_READONLY {
 return SourceRange(StartLocation, EndLocation);
   }
-  [[deprecated]] SourceLocation getLocStart() const LLVM_READONLY { return getBeginLoc();  }
   SourceLocation getBeginLoc() const LLVM_READONLY { return StartLocation; }
-  [[deprecated]] SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc();  }
   SourceLocation getEndLoc() const LLVM_READONLY { return EndLocation; }
 };
 
@@ -1874,9 +1870,7 @@
 
   /// Get the source range that spans this declarator.
   SourceRange getSourceRange() const LLVM_READONLY { return Range; }
-  [[deprecated]] SourceLocation getLocStart() const LLVM_READONLY { return getBeginLoc();  }
   SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
-  [[deprecated]] SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc();  }
   SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
 
   void SetSourceRange(SourceRange R) { Range = R; }
Index: include/clang/Analysis/CloneDetection.h
===
--- include/clang/Analysis/CloneDetection.h
+++ include/clang/Analysis/CloneDetection.h
@@ -122,7 +122,6 @@
   /// Returns the start sourcelocation of the first statement in this sequence.
   ///
   /// This method should only be called on a non-empty StmtSequence object.
-  [[deprecated]] SourceLocation getStartLoc() const LLVM_READONLY { return getBeginLoc();  }
   SourceLocation getBeginLoc() const;
 
   /// Returns the end sourcelocation of the last statement in this sequence.
Index: include/clang/AST/TypeLoc.h
===
--- include/clang/AST/TypeLoc.h
+++ include/clang/AST/TypeLoc.h
@@ -151,8 +151,6 @@
 return SourceRange(getBeginLoc(), getEndLoc());
   }
 
-  [[deprecated]] SourceLocation getLocStart() const LLVM_READONLY { return getBeginLoc();  }
-  [[deprecated]] SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc();  }
 
   /// Get the local source range.
   SourceRange getLocalSourceRange() const {
Index: include/clang/AST/StmtOpenMP.h

[PATCH] D50350: Port getLocStart -> getBeginLoc

2018-08-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
Herald added subscribers: cfe-commits, jfb, whisperity, jholewinski.
Herald added a reviewer: teemperor.

Repository:
  rC Clang

https://reviews.llvm.org/D50350

Files:
  docs/RAVFrontendAction.rst
  include/clang/AST/Comment.h
  include/clang/AST/Decl.h
  include/clang/AST/DeclCXX.h
  include/clang/AST/DeclObjC.h
  include/clang/AST/DeclarationName.h
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/ExprObjC.h
  include/clang/AST/ExprOpenMP.h
  include/clang/AST/LexicallyOrderedRecursiveASTVisitor.h
  include/clang/AST/RawCommentList.h
  include/clang/AST/Stmt.h
  include/clang/AST/StmtCXX.h
  include/clang/AST/StmtDataCollectors.td
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/Sema/Initialization.h
  include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
  lib/ARCMigrate/ObjCMT.cpp
  lib/ARCMigrate/TransAPIUses.cpp
  lib/ARCMigrate/TransAutoreleasePool.cpp
  lib/ARCMigrate/TransGCCalls.cpp
  lib/ARCMigrate/TransProtectedScope.cpp
  lib/ARCMigrate/TransRetainReleaseDealloc.cpp
  lib/ARCMigrate/TransUnbridgedCasts.cpp
  lib/ARCMigrate/TransformActions.cpp
  lib/AST/ASTContext.cpp
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/ASTStructuralEquivalence.cpp
  lib/AST/Decl.cpp
  lib/AST/DeclObjC.cpp
  lib/AST/DeclOpenMP.cpp
  lib/AST/DeclTemplate.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/RawCommentList.cpp
  lib/AST/SelectorLocationsKind.cpp
  lib/AST/Stmt.cpp
  lib/AST/StmtPrinter.cpp
  lib/Analysis/AnalysisDeclContext.cpp
  lib/Analysis/CloneDetection.cpp
  lib/Analysis/Consumed.cpp
  lib/Analysis/LiveVariables.cpp
  lib/Analysis/ReachableCode.cpp
  lib/Analysis/ThreadSafety.cpp
  lib/CodeGen/CGAtomic.cpp
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGCoroutine.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGException.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenPGO.cpp
  lib/CodeGen/CoverageMappingGen.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Edit/RewriteObjCFoundationAPI.cpp
  lib/Frontend/Rewrite/RewriteModernObjC.cpp
  lib/Frontend/Rewrite/RewriteObjC.cpp
  lib/Index/IndexBody.cpp
  lib/Index/IndexDecl.cpp
  lib/Index/USRGeneration.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/ParseObjc.cpp
  lib/Parse/ParseStmt.cpp
  lib/Sema/AnalysisBasedWarnings.cpp
  lib/Sema/JumpDiagnostics.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaAttr.cpp
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaCoroutine.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaDeclObjC.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaExprObjC.cpp
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaLambda.cpp
  lib/Sema/SemaLookup.cpp
  lib/Sema/SemaObjCProperty.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaPseudoObject.cpp
  lib/Sema/SemaStmt.cpp
  lib/Sema/SemaStmtAsm.cpp
  lib/Sema/SemaStmtAttr.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Sema/SemaTemplateVariadic.cpp
  lib/Sema/SemaType.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
  lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  lib/StaticAnalyzer/Checkers/MacOSXAPIChecker.cpp
  lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
  lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp
  lib/StaticAnalyzer/Checkers/ObjCUnusedIVarsChecker.cpp
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
  lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
  lib/StaticAnalyzer/Checkers/TraversalChecker.cpp
  lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
  lib/StaticAnalyzer/Core/BugReporter.cpp
  lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  lib/StaticAnalyzer/Core/CheckerHelpers.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
  lib/StaticAnalyzer/Core/PathDiagnostic.cpp
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  lib/Tooling/Refactoring/Extract/Extract.cpp
  lib/Tooling/Refactoring/Rename/USRFinder.cpp
  lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
  tools/clang-func-mapping/ClangFnMapGen.cpp
  tools/libclang/CIndex.cpp
  tools/libclang/CXIndexDataConsumer.cpp
  

[PATCH] D50348: :Add getEndLoc API to replace getLocEnd

2018-08-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D50348

Files:
  include/clang/AST/Comment.h
  include/clang/AST/Decl.h
  include/clang/AST/DeclBase.h
  include/clang/AST/DeclCXX.h
  include/clang/AST/DeclObjC.h
  include/clang/AST/DeclarationName.h
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/ExprObjC.h
  include/clang/AST/ExprOpenMP.h
  include/clang/AST/OpenMPClause.h
  include/clang/AST/RawCommentList.h
  include/clang/AST/Stmt.h
  include/clang/AST/StmtCXX.h
  include/clang/AST/StmtObjC.h
  include/clang/AST/StmtOpenMP.h
  include/clang/AST/TypeLoc.h
  include/clang/Sema/DeclSpec.h
  lib/AST/DeclObjC.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/Stmt.cpp
  lib/AST/StmtObjC.cpp
  lib/Sema/SemaChecking.cpp

Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -6126,7 +6126,8 @@
 return FExpr->getLocStart().getLocWithOffset(Offset);
   }
 
-  SourceLocation getLocEnd() const LLVM_READONLY { return FExpr->getLocEnd(); }
+  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc();  }
+  SourceLocation getEndLoc() const LLVM_READONLY { return FExpr->getLocEnd(); }
 };
 
 }  // namespace
Index: lib/AST/StmtObjC.cpp
===
--- lib/AST/StmtObjC.cpp
+++ lib/AST/StmtObjC.cpp
@@ -64,7 +64,7 @@
   return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
 }
 
-SourceLocation ObjCAtTryStmt::getLocEnd() const {
+SourceLocation ObjCAtTryStmt::getEndLoc() const {
   if (HasFinally)
 return getFinallyStmt()->getLocEnd();
   if (NumCatchStmts)
Index: lib/AST/Stmt.cpp
===
--- lib/AST/Stmt.cpp
+++ lib/AST/Stmt.cpp
@@ -288,7 +288,7 @@
   llvm_unreachable("unknown statement kind");
 }
 
-SourceLocation Stmt::getLocEnd() const {
+SourceLocation Stmt::getEndLoc() const {
   switch (getStmtClass()) {
   case Stmt::NoStmtClass: llvm_unreachable("statement without class");
 #define ABSTRACT_STMT(type)
Index: lib/AST/ExprCXX.cpp
===
--- lib/AST/ExprCXX.cpp
+++ lib/AST/ExprCXX.cpp
@@ -250,7 +250,7 @@
   return QualType();
 }
 
-SourceLocation CXXPseudoDestructorExpr::getLocEnd() const {
+SourceLocation CXXPseudoDestructorExpr::getEndLoc() const {
   SourceLocation End = DestroyedType.getLocation();
   if (TypeSourceInfo *TInfo = DestroyedType.getTypeSourceInfo())
 End = TInfo->getTypeLoc().getLocalSourceRange().getEnd();
@@ -456,7 +456,7 @@
   return Loc;
 }
 
-SourceLocation CXXConstructExpr::getLocEnd() const {
+SourceLocation CXXConstructExpr::getEndLoc() const {
   if (isa(this))
 return cast(this)->getLocEnd();
 
@@ -695,7 +695,7 @@
   return getTypeInfoAsWritten()->getTypeLoc().getLocStart();
 }
 
-SourceLocation CXXFunctionalCastExpr::getLocEnd() const {
+SourceLocation CXXFunctionalCastExpr::getEndLoc() const {
   return RParenLoc.isValid() ? RParenLoc : getSubExpr()->getLocEnd();
 }
 
@@ -780,7 +780,7 @@
   return Type->getTypeLoc().getBeginLoc();
 }
 
-SourceLocation CXXTemporaryObjectExpr::getLocEnd() const {
+SourceLocation CXXTemporaryObjectExpr::getEndLoc() const {
   SourceLocation Loc = getParenOrBraceRange().getEnd();
   if (Loc.isInvalid() && getNumArgs())
 Loc = getArg(getNumArgs()-1)->getLocEnd();
Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -452,7 +452,7 @@
 return getQualifierLoc().getBeginLoc();
   return getNameInfo().getLocStart();
 }
-SourceLocation DeclRefExpr::getLocEnd() const {
+SourceLocation DeclRefExpr::getEndLoc() const {
   if (hasExplicitTemplateArgs())
 return getRAngleLoc();
   return getNameInfo().getLocEnd();
@@ -1367,7 +1367,7 @@
 begin = getArg(0)->getLocStart();
   return begin;
 }
-SourceLocation CallExpr::getLocEnd() const {
+SourceLocation CallExpr::getEndLoc() const {
   if (isa(this))
 return cast(this)->getLocEnd();
 
@@ -1543,7 +1543,7 @@
 return BaseStartLoc;
   return MemberLoc;
 }
-SourceLocation MemberExpr::getLocEnd() const {
+SourceLocation MemberExpr::getEndLoc() const {
   SourceLocation EndLoc = getMemberNameInfo().getEndLoc();
   if (hasExplicitTemplateArgs())
 EndLoc = getRAngleLoc();
@@ -2034,7 +2034,7 @@
   return Beg;
 }
 
-SourceLocation InitListExpr::getLocEnd() const {
+SourceLocation InitListExpr::getEndLoc() const {
   if (InitListExpr *SyntacticForm = getSyntacticForm())
 return SyntacticForm->getLocEnd();
   SourceLocation End = RBraceLoc;
@@ -3862,7 +3862,7 @@
   return StartLoc;
 }
 
-SourceLocation DesignatedInitExpr::getLocEnd() const {
+SourceLocation DesignatedInitExpr::getEndLoc() const {
   return getInit()->getLocEnd();
 }
 
@@ -3925,7 +3925,7 @@
   return getBase()->getLocStart();

[PATCH] D50349: Port getStartLoc -> getBeginLoc

2018-08-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
Herald added a reviewer: teemperor.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D50349

Files:
  include/clang/AST/Decl.h
  lib/AST/ASTImporter.cpp
  lib/Analysis/CloneDetection.cpp
  lib/CodeGen/CoverageMappingGen.cpp
  lib/Sema/SemaStmt.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -530,7 +530,7 @@
   ProgramStateRef State = Pred->getState();
   const LocationContext *LCtx = Pred->getLocationContext();
   PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
-CNE->getStartLoc(),
+CNE->getBeginLoc(),
 "Error evaluating New Allocator Call");
   CallEventManager  = getStateManager().getCallEventManager();
   CallEventRef Call =
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -223,7 +223,7 @@
 
 void ASTStmtWriter::VisitDeclStmt(DeclStmt *S) {
   VisitStmt(S);
-  Record.AddSourceLocation(S->getStartLoc());
+  Record.AddSourceLocation(S->getBeginLoc());
   Record.AddSourceLocation(S->getEndLoc());
   DeclGroupRef DG = S->getDeclGroup();
   for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
Index: lib/Sema/TreeTransform.h
===
--- lib/Sema/TreeTransform.h
+++ lib/Sema/TreeTransform.h
@@ -6875,7 +6875,7 @@
   if (!getDerived().AlwaysRebuild() && !DeclChanged)
 return S;
 
-  return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
+  return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
 }
 
 template
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -2066,7 +2066,7 @@
   assert(DS && "first part of for range not a decl stmt");
 
   if (!DS->isSingleDecl()) {
-Diag(DS->getStartLoc(), diag::err_type_defined_in_for_range);
+Diag(DS->getBeginLoc(), diag::err_type_defined_in_for_range);
 return StmtError();
   }
 
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -117,7 +117,7 @@
   }
 
   SpellingRegion(SourceManager , SourceMappingRegion )
-  : SpellingRegion(SM, R.getStartLoc(), R.getEndLoc()) {}
+  : SpellingRegion(SM, R.getBeginLoc(), R.getEndLoc()) {}
 
   /// Check if the start and end locations appear in source order, i.e
   /// top->bottom, left->right.
@@ -230,7 +230,7 @@
 llvm::SmallSet Visited;
 SmallVector, 8> FileLocs;
 for (const auto  : SourceRegions) {
-  SourceLocation Loc = Region.getStartLoc();
+  SourceLocation Loc = Region.getBeginLoc();
   FileID File = SM.getFileID(Loc);
   if (!Visited.insert(File).second)
 continue;
@@ -312,7 +312,7 @@
 for (const auto  : SourceRegions) {
   assert(Region.hasEndLoc() && "incomplete region");
 
-  SourceLocation LocStart = Region.getStartLoc();
+  SourceLocation LocStart = Region.getBeginLoc();
   assert(SM.getFileID(LocStart).isValid() && "region in invalid file");
 
   // Ignore regions from system headers.
@@ -503,7 +503,7 @@
 DeferredRegion = None;
 
 // If the region ends in an expansion, find the expansion site.
-FileID StartFile = SM.getFileID(DR.getStartLoc());
+FileID StartFile = SM.getFileID(DR.getBeginLoc());
 if (SM.getFileID(DeferredEndLoc) != StartFile) {
   if (isNestedIn(DeferredEndLoc, StartFile)) {
 do {
@@ -516,12 +516,12 @@
 
 // The parent of this deferred region ends where the containing decl ends,
 // so the region isn't useful.
-if (DR.getStartLoc() == DeferredEndLoc)
+if (DR.getBeginLoc() == DeferredEndLoc)
   return Index;
 
 // If we're visiting statements in non-source order (e.g switch cases or
 // a loop condition) we can't construct a sensible deferred region.
-if (!SpellingRegion(SM, DR.getStartLoc(), DeferredEndLoc).isInSourceOrder())
+if (!SpellingRegion(SM, DR.getBeginLoc(), DeferredEndLoc).isInSourceOrder())
   return Index;
 
 DR.setGap(true);
@@ -563,7 +563,7 @@
 while (RegionStack.size() > ParentIndex) {
   SourceMappingRegion  = RegionStack.back();
   if (Region.hasStartLoc()) {
-SourceLocation StartLoc = Region.getStartLoc();
+SourceLocation StartLoc = Region.getBeginLoc();
 SourceLocation EndLoc = Region.hasEndLoc()
 ? 

[PATCH] D50347: Add getBeginLoc API to replace getStartLoc

2018-08-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
Herald added a reviewer: teemperor.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D50347

Files:
  include/clang/AST/ExprCXX.h
  include/clang/AST/Stmt.h
  include/clang/Analysis/CloneDetection.h
  lib/CodeGen/CoverageMappingGen.cpp


Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -67,7 +67,8 @@
 
   void setStartLoc(SourceLocation Loc) { LocStart = Loc; }
 
-  SourceLocation getStartLoc() const {
+  SourceLocation getStartLoc() const LLVM_READONLY { return getBeginLoc();  }
+  SourceLocation getBeginLoc() const {
 assert(LocStart && "Region has no start location");
 return *LocStart;
   }
Index: include/clang/Analysis/CloneDetection.h
===
--- include/clang/Analysis/CloneDetection.h
+++ include/clang/Analysis/CloneDetection.h
@@ -122,7 +122,8 @@
   /// Returns the start sourcelocation of the first statement in this sequence.
   ///
   /// This method should only be called on a non-empty StmtSequence object.
-  SourceLocation getStartLoc() const;
+  SourceLocation getStartLoc() const LLVM_READONLY { return getBeginLoc();  }
+  SourceLocation getBeginLoc() const;
 
   /// Returns the end sourcelocation of the last statement in this sequence.
   ///
Index: include/clang/AST/Stmt.h
===
--- include/clang/AST/Stmt.h
+++ include/clang/AST/Stmt.h
@@ -523,7 +523,7 @@
   DeclGroupRef getDeclGroup() { return DG; }
   void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
 
-  SourceLocation getStartLoc() const { return StartLoc; }
+  SourceLocation getStartLoc() const LLVM_READONLY { return getBeginLoc();  }
   void setStartLoc(SourceLocation L) { StartLoc = L; }
   SourceLocation getEndLoc() const { return EndLoc; }
   void setEndLoc(SourceLocation L) { EndLoc = L; }
Index: include/clang/AST/ExprCXX.h
===
--- include/clang/AST/ExprCXX.h
+++ include/clang/AST/ExprCXX.h
@@ -2069,7 +2069,8 @@
 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
   }
 
-  SourceLocation getStartLoc() const { return Range.getBegin(); }
+  SourceLocation getStartLoc() const LLVM_READONLY { return getBeginLoc();  }
+  SourceLocation getBeginLoc() const { return Range.getBegin(); }
   SourceLocation getEndLoc() const { return Range.getEnd(); }
 
   SourceRange getDirectInitRange() const { return DirectInitRange; }
@@ -2079,7 +2080,6 @@
   }
 
   SourceLocation getLocStart() const LLVM_READONLY { return getBeginLoc();  }
-  SourceLocation getBeginLoc() const LLVM_READONLY { return getStartLoc(); }
   SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
 
   static bool classof(const Stmt *T) {


Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -67,7 +67,8 @@
 
   void setStartLoc(SourceLocation Loc) { LocStart = Loc; }
 
-  SourceLocation getStartLoc() const {
+  SourceLocation getStartLoc() const LLVM_READONLY { return getBeginLoc();  }
+  SourceLocation getBeginLoc() const {
 assert(LocStart && "Region has no start location");
 return *LocStart;
   }
Index: include/clang/Analysis/CloneDetection.h
===
--- include/clang/Analysis/CloneDetection.h
+++ include/clang/Analysis/CloneDetection.h
@@ -122,7 +122,8 @@
   /// Returns the start sourcelocation of the first statement in this sequence.
   ///
   /// This method should only be called on a non-empty StmtSequence object.
-  SourceLocation getStartLoc() const;
+  SourceLocation getStartLoc() const LLVM_READONLY { return getBeginLoc();  }
+  SourceLocation getBeginLoc() const;
 
   /// Returns the end sourcelocation of the last statement in this sequence.
   ///
Index: include/clang/AST/Stmt.h
===
--- include/clang/AST/Stmt.h
+++ include/clang/AST/Stmt.h
@@ -523,7 +523,7 @@
   DeclGroupRef getDeclGroup() { return DG; }
   void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
 
-  SourceLocation getStartLoc() const { return StartLoc; }
+  SourceLocation getStartLoc() const LLVM_READONLY { return getBeginLoc();  }
   void setStartLoc(SourceLocation L) { StartLoc = L; }
   SourceLocation getEndLoc() const { return EndLoc; }
   void setEndLoc(SourceLocation L) { EndLoc = L; }
Index: include/clang/AST/ExprCXX.h
===
--- include/clang/AST/ExprCXX.h
+++ include/clang/AST/ExprCXX.h
@@ -2069,7 +2069,8 @@
 return SubExprs + Array + hasInitializer() + getNumPlacementArgs();
   }
 
-  SourceLocation getStartLoc() const { 

[PATCH] D50346: Add getBeginLoc API to replace getLocStart

2018-08-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D50346

Files:
  include/clang/AST/Comment.h
  include/clang/AST/Decl.h
  include/clang/AST/DeclBase.h
  include/clang/AST/DeclCXX.h
  include/clang/AST/DeclObjC.h
  include/clang/AST/DeclarationName.h
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/ExprObjC.h
  include/clang/AST/ExprOpenMP.h
  include/clang/AST/OpenMPClause.h
  include/clang/AST/RawCommentList.h
  include/clang/AST/Stmt.h
  include/clang/AST/StmtCXX.h
  include/clang/AST/StmtObjC.h
  include/clang/AST/StmtOpenMP.h
  include/clang/AST/TypeLoc.h
  include/clang/Sema/DeclSpec.h
  lib/AST/Expr.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/Stmt.cpp
  lib/Sema/SemaChecking.cpp

Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -6121,7 +6121,8 @@
 StartToken, StartTokenByteOffset);
   }
 
-  SourceLocation getLocStart() const LLVM_READONLY {
+  SourceLocation getLocStart() const LLVM_READONLY { return getBeginLoc();  }
+  SourceLocation getBeginLoc() const LLVM_READONLY {
 return FExpr->getLocStart().getLocWithOffset(Offset);
   }
 
Index: lib/AST/Stmt.cpp
===
--- lib/AST/Stmt.cpp
+++ lib/AST/Stmt.cpp
@@ -275,8 +275,8 @@
   llvm_unreachable("unknown statement kind!");
 }
 
-SourceLocation Stmt::getLocStart() const {
-//  llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n";
+SourceLocation Stmt::getBeginLoc() const {
+//  llvm::errs() << "getBeginLoc() for " << getStmtClassName() << "\n";
   switch (getStmtClass()) {
   case Stmt::NoStmtClass: llvm_unreachable("statement without class");
 #define ABSTRACT_STMT(type)
Index: lib/AST/ExprCXX.cpp
===
--- lib/AST/ExprCXX.cpp
+++ lib/AST/ExprCXX.cpp
@@ -89,7 +89,7 @@
 }
 
 // CXXScalarValueInitExpr
-SourceLocation CXXScalarValueInitExpr::getLocStart() const {
+SourceLocation CXXScalarValueInitExpr::getBeginLoc() const {
   return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : RParenLoc;
 }
 
@@ -450,7 +450,7 @@
   return E;
 }
 
-SourceLocation CXXConstructExpr::getLocStart() const {
+SourceLocation CXXConstructExpr::getBeginLoc() const {
   if (isa(this))
 return cast(this)->getLocStart();
   return Loc;
@@ -691,7 +691,7 @@
   return new (Buffer) CXXFunctionalCastExpr(EmptyShell(), PathSize);
 }
 
-SourceLocation CXXFunctionalCastExpr::getLocStart() const {
+SourceLocation CXXFunctionalCastExpr::getBeginLoc() const {
   return getTypeInfoAsWritten()->getTypeLoc().getLocStart();
 }
 
@@ -776,7 +776,7 @@
CXXConstructExpr::CK_Complete, ParenOrBraceRange),
   Type(TSI) {}
 
-SourceLocation CXXTemporaryObjectExpr::getLocStart() const {
+SourceLocation CXXTemporaryObjectExpr::getBeginLoc() const {
   return Type->getTypeLoc().getBeginLoc();
 }
 
@@ -1104,7 +1104,7 @@
   return new (Mem) CXXUnresolvedConstructExpr(Empty, NumArgs);
 }
 
-SourceLocation CXXUnresolvedConstructExpr::getLocStart() const {
+SourceLocation CXXUnresolvedConstructExpr::getBeginLoc() const {
   return Type->getTypeLoc().getBeginLoc();
 }
 
Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -447,7 +447,7 @@
   return new (Mem) DeclRefExpr(EmptyShell());
 }
 
-SourceLocation DeclRefExpr::getLocStart() const {
+SourceLocation DeclRefExpr::getBeginLoc() const {
   if (hasQualifier())
 return getQualifierLoc().getBeginLoc();
   return getNameInfo().getLocStart();
@@ -1358,7 +1358,7 @@
   return FnType->getReturnType();
 }
 
-SourceLocation CallExpr::getLocStart() const {
+SourceLocation CallExpr::getBeginLoc() const {
   if (isa(this))
 return cast(this)->getLocStart();
 
@@ -1529,7 +1529,7 @@
   return E;
 }
 
-SourceLocation MemberExpr::getLocStart() const {
+SourceLocation MemberExpr::getBeginLoc() const {
   if (isImplicitAccess()) {
 if (hasQualifier())
   return getQualifierLoc().getBeginLoc();
@@ -2016,7 +2016,7 @@
   return Lit && Lit->getValue() == 0;
 }
 
-SourceLocation InitListExpr::getLocStart() const {
+SourceLocation InitListExpr::getBeginLoc() const {
   if (InitListExpr *SyntacticForm = getSyntacticForm())
 return SyntacticForm->getLocStart();
   SourceLocation Beg = LBraceLoc;
@@ -3847,7 +3847,7 @@
  DIE->getDesignator(size()-1)->getLocEnd());
 }
 
-SourceLocation DesignatedInitExpr::getLocStart() const {
+SourceLocation DesignatedInitExpr::getBeginLoc() const {
   SourceLocation StartLoc;
   auto *DIE = const_cast(this);
   Designator  = *DIE->getDesignator(0);
@@ -3921,7 +3921,7 @@
   BaseAndUpdaterExprs[1] = ILE;
 }
 
-SourceLocation DesignatedInitUpdateExpr::getLocStart() const {
+SourceLocation 

[PATCH] D49952: Check for NULL Destination-Type when creating ArrayConstant

2018-08-06 Thread Balaji Iyer via Phabricator via cfe-commits
bviyer marked an inline comment as done.
bviyer added a comment.

John, I have updated the test case as you requested (I think). I am a bit new 
to Clang, so apologize if I mistook your request.


https://reviews.llvm.org/D49952



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


[PATCH] D49952: Check for NULL Destination-Type when creating ArrayConstant

2018-08-06 Thread Balaji Iyer via Phabricator via cfe-commits
bviyer updated this revision to Diff 159353.

https://reviews.llvm.org/D49952

Files:
  lib/CodeGen/CGExprConstant.cpp
  test/CodeGenCXX/empty-struct-init-list.cpp


Index: test/CodeGenCXX/empty-struct-init-list.cpp
===
--- /dev/null
+++ test/CodeGenCXX/empty-struct-init-list.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++11 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++14 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++17 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: struct.a
+typedef struct { } a;
+typedef struct {
+  a b[];
+} c;
+
+// CHECK: global %struct.c zeroinitializer, align 1
+c d{ };
Index: lib/CodeGen/CGExprConstant.cpp
===
--- lib/CodeGen/CGExprConstant.cpp
+++ lib/CodeGen/CGExprConstant.cpp
@@ -2119,6 +2119,16 @@
   Elts.push_back(C);
 }
 
+// This means that the array type is probably "IncompleteType" or some
+// type that is not ConstantArray.
+if (CAT == nullptr && CommonElementType == nullptr && !NumInitElts) {
+  const ArrayType *AT = CGM.getContext().getAsArrayType(DestType);
+  CommonElementType = CGM.getTypes().ConvertType(AT->getElementType());
+  llvm::ArrayType *AType = llvm::ArrayType::get(CommonElementType,
+NumElements);
+  return llvm::ConstantAggregateZero::get(AType);
+}
+
 return EmitArrayConstant(CGM, CAT, CommonElementType, NumElements, Elts,
  Filler);
   }


Index: test/CodeGenCXX/empty-struct-init-list.cpp
===
--- /dev/null
+++ test/CodeGenCXX/empty-struct-init-list.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++11 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++14 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++17 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: struct.a
+typedef struct { } a;
+typedef struct {
+  a b[];
+} c;
+
+// CHECK: global %struct.c zeroinitializer, align 1
+c d{ };
Index: lib/CodeGen/CGExprConstant.cpp
===
--- lib/CodeGen/CGExprConstant.cpp
+++ lib/CodeGen/CGExprConstant.cpp
@@ -2119,6 +2119,16 @@
   Elts.push_back(C);
 }
 
+// This means that the array type is probably "IncompleteType" or some
+// type that is not ConstantArray.
+if (CAT == nullptr && CommonElementType == nullptr && !NumInitElts) {
+  const ArrayType *AT = CGM.getContext().getAsArrayType(DestType);
+  CommonElementType = CGM.getTypes().ConvertType(AT->getElementType());
+  llvm::ArrayType *AType = llvm::ArrayType::get(CommonElementType,
+NumElements);
+  return llvm::ConstantAggregateZero::get(AType);
+}
+
 return EmitArrayConstant(CGM, CAT, CommonElementType, NumElements, Elts,
  Filler);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49438: [analyzer][UninitializedObjectChecker] New flag to turn off dereferencing

2018-08-06 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

> I think what pointer chasing should do, is check whether that pointer owns 
> the pointee

But ownership is a convention, and it's not always deducible from a codebase.
I think of those as two separate checks, and I think we should only talk about 
enabling the pointer-chasing after we had established that just checking for 
uninitialized fields finds lots of valid bugs (and we can only do that after it 
gets enabled for many projects)


https://reviews.llvm.org/D49438



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


r339044 - Fix for broken build on clang-hexagon-elf for ambiguous call to

2018-08-06 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Mon Aug  6 12:31:00 2018
New Revision: 339044

URL: http://llvm.org/viewvc/llvm-project?rev=339044=rev
Log:
Fix for broken build on clang-hexagon-elf for ambiguous call to
std::abs.

Modified:
cfe/trunk/lib/Basic/FixedPoint.cpp

Modified: cfe/trunk/lib/Basic/FixedPoint.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FixedPoint.cpp?rev=339044=339043=339044=diff
==
--- cfe/trunk/lib/Basic/FixedPoint.cpp (original)
+++ cfe/trunk/lib/Basic/FixedPoint.cpp Mon Aug  6 12:31:00 2018
@@ -59,7 +59,8 @@ int APFixedPoint::compare(const APFixedP
   unsigned CommonWidth = std::max(Val.getBitWidth(), OtherWidth);
 
   // Prevent overflow in the event the widths are the same but the scales 
differ
-  CommonWidth += std::abs(static_cast(getScale() - OtherScale));
+  CommonWidth += getScale() >= OtherScale ? getScale() - OtherScale
+  : OtherScale - getScale();
 
   ThisVal = ThisVal.extOrTrunc(CommonWidth);
   OtherVal = OtherVal.extOrTrunc(CommonWidth);


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


[PATCH] D49438: [analyzer][UninitializedObjectChecker] New flag to turn off dereferencing

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

I think what pointer chasing should do, is check whether that pointer owns the 
pointee. In that case, it should be fine to analyze it. Do you mind if I put a 
TODO around flag's description stating that this should be implemented and 
pointer chasing should be enabled by default once that's done?


https://reviews.llvm.org/D49438



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


[PATCH] D43357: [Concepts] Function trailing requires clauses

2018-08-06 Thread Saar Raz via Phabricator via cfe-commits
saar.raz updated this revision to Diff 159349.
saar.raz added a comment.
Herald added a subscriber: jfb.

- Fix bad diagnostic detection and suppression


Repository:
  rC Clang

https://reviews.llvm.org/D43357

Files:
  include/clang/AST/Decl.h
  include/clang/AST/DeclCXX.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/DeclSpec.h
  include/clang/Sema/Overload.h
  include/clang/Sema/Sema.h
  lib/AST/ASTDumper.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Decl.cpp
  lib/AST/DeclCXX.cpp
  lib/AST/DeclPrinter.cpp
  lib/AST/DeclTemplate.cpp
  lib/AST/ODRHash.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaConcept.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Sema/SemaTemplateVariadic.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CXX/concepts-ts/class.derived/class.virtual/p6.cpp
  test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp
  test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p2.cpp
  test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp
  test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp
  test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/p7.cpp
  test/CXX/concepts-ts/dcl.dcl/lit.cfg.py
  test/CXX/concepts-ts/dcl/dcl.dcl/dcl.spec/dcl.spec.concept/p1.cpp
  test/CXX/concepts-ts/dcl/dcl.dcl/dcl.spec/dcl.spec.concept/p2.cpp
  test/CXX/concepts-ts/dcl/dcl.dcl/dcl.spec/dcl.spec.concept/p5.cpp
  test/CXX/concepts-ts/dcl/dcl.dcl/dcl.spec/dcl.spec.concept/p6.cpp
  test/CXX/concepts-ts/dcl/dcl.dcl/dcl.spec/dcl.spec.concept/p7.cpp
  test/CXX/concepts-ts/dcl/dcl.dcl/lit.cfg.py
  test/CXX/concepts-ts/dcl/dcl.decl/p3.cpp
  test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/mixed-constraints.cpp
  test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p4.cpp
  test/CXX/concepts-ts/over/over.match/over.match.best/p1.cpp
  test/CXX/concepts-ts/over/over.over/p4.cpp

Index: test/CXX/concepts-ts/over/over.over/p4.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/over/over.over/p4.cpp
@@ -0,0 +1,56 @@
+// RUN:  %clang_cc1 -std=c++2a -fconcepts-ts -verify %s
+
+
+template
+constexpr static bool is_same_v = false;
+
+template
+constexpr static bool is_same_v = true;
+
+template
+concept AtLeast2 = sizeof(T) >= 2;
+
+template
+concept AtMost8 = sizeof(T) <= 8;
+
+int foo() requires AtLeast2 && AtMost8 {
+  return 0;
+}
+
+double foo() requires AtLeast2 {
+  return 0.0;
+}
+
+char bar() requires AtLeast2 { // expected-note {{possible target for call}}
+  return 1.0;
+}
+
+short bar() requires AtLeast2 && AtMost8 { // expected-note {{possible target for call}} expected-note {{candidate function}}
+  return 0.0;
+}
+
+int bar() requires AtMost8 && AtLeast2 { // expected-note {{possible target for call}} expected-note {{candidate function}}
+  return 0.0;
+}
+
+char baz() requires AtLeast2 {
+  return 1.0;
+}
+
+short baz() requires AtLeast2 && AtMost8 {
+  return 0.0;
+}
+
+int baz() requires AtMost8 && AtLeast2 {
+  return 0.0;
+}
+
+long baz() requires AtMost8 && AtLeast2 && AtLeast2 {
+  return 3.0;
+}
+
+void a() {
+  static_assert(is_same_v);
+  static_assert(is_same_v); // expected-error {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} expected-error{{call to 'bar' is ambiguous}}
+  static_assert(is_same_v);
+}
\ No newline at end of file
Index: test/CXX/concepts-ts/over/over.match/over.match.best/p1.cpp
===
--- /dev/null
+++ test/CXX/concepts-ts/over/over.match/over.match.best/p1.cpp
@@ -0,0 +1,65 @@
+// RUN:  %clang_cc1 -std=c++2a -fconcepts-ts -verify %s
+
+
+template
+constexpr static bool is_same_v = false;
+
+template
+constexpr static bool is_same_v = true;
+
+namespace templates
+{
+  template
+  concept AtLeast1 = sizeof(T) >= 1;
+
+  template
+  int foo(T t) requires sizeof(T) == 4 { // expected-note {{candidate function}}
+return 0;
+  }
+
+  template
+  char foo(T t) requires AtLeast1 { // expected-note {{candidate function}}
+return 'a';
+  }
+
+  template
+  double foo(T t) requires AtLeast1 && sizeof(T) <= 2 {
+return 'a';
+  }
+
+  void bar() {
+static_assert(is_same_v); // expected-error {{call to 'foo' is ambiguous}}
+static_assert(is_same_v);
+  }
+}
+
+namespace non_template
+{
+  template
+  concept AtLeast2 = sizeof(T) >= 2;
+
+  template
+  concept AtMost8 = sizeof(T) <= 8;
+
+  int foo() requires AtLeast2 && AtMost8 {
+return 0;
+  }
+
+  double foo() requires AtLeast2 {
+return 0.0;
+  }
+
+  double baz() requires AtLeast2 && AtMost8 { // expected-note {{candidate function}}

[PATCH] D50344: [libc++] Enable aligned allocation based on feature test macro, irrespective of standard

2018-08-06 Thread Louis Dionne via Phabricator via cfe-commits
ldionne created this revision.
ldionne added a reviewer: vsapsai.
Herald added a reviewer: EricWF.
Herald added subscribers: cfe-commits, dexonsmith, christof.

The current code enables aligned allocation functions when compiling in C++17
and later. This is a problem because aligned allocation functions might not
be supported on the target platform, which leads to an error at link time.

Since r338934, Clang knows not to define __cpp_aligned_new when it's not
available on the target platform -- this commit takes advantage of that to
only use aligned allocation functions when they are available.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50344

Files:
  libcxx/include/__config
  libcxx/include/new
  libcxx/test/libcxx/memory/aligned_allocation_macro.pass.cpp


Index: libcxx/test/libcxx/memory/aligned_allocation_macro.pass.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/memory/aligned_allocation_macro.pass.cpp
@@ -0,0 +1,25 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+// XFAIL: with_system_cxx_lib=macosx10.12
+// XFAIL: with_system_cxx_lib=macosx10.11
+// XFAIL: with_system_cxx_lib=macosx10.10
+// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: with_system_cxx_lib=macosx10.8
+// XFAIL: with_system_cxx_lib=macosx10.7
+
+#include 
+
+
+#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
+#   error "libc++ should have aligned allocation in C++17 and up when 
targeting a platform that supports it"
+#endif
+
+int main() { }
Index: libcxx/include/new
===
--- libcxx/include/new
+++ libcxx/include/new
@@ -108,13 +108,6 @@
 # define _LIBCPP_HAS_NO_SIZED_DEALLOCATION
 #endif
 
-#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) && \
-(!(defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_STD_VER > 14 || \
-(defined(__cpp_aligned_new) && __cpp_aligned_new >= 201606)))
-# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
-#endif
-
-
 #if !__has_builtin(__builtin_operator_new) || \
__has_builtin(__builtin_operator_new) < 201802L || \
defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) || \
Index: libcxx/include/__config
===
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -988,6 +988,11 @@
 #  endif
 #endif // defined(__APPLE__)
 
+#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) && \
+!defined(_LIBCPP_BUILDING_LIBRARY) && \
+!defined(__cpp_aligned_new)
+#  define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
+#endif
 
 #if defined(__APPLE__) || defined(__FreeBSD__)
 #define _LIBCPP_HAS_DEFAULTRUNELOCALE


Index: libcxx/test/libcxx/memory/aligned_allocation_macro.pass.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/memory/aligned_allocation_macro.pass.cpp
@@ -0,0 +1,25 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+// XFAIL: with_system_cxx_lib=macosx10.12
+// XFAIL: with_system_cxx_lib=macosx10.11
+// XFAIL: with_system_cxx_lib=macosx10.10
+// XFAIL: with_system_cxx_lib=macosx10.9
+// XFAIL: with_system_cxx_lib=macosx10.8
+// XFAIL: with_system_cxx_lib=macosx10.7
+
+#include 
+
+
+#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
+#   error "libc++ should have aligned allocation in C++17 and up when targeting a platform that supports it"
+#endif
+
+int main() { }
Index: libcxx/include/new
===
--- libcxx/include/new
+++ libcxx/include/new
@@ -108,13 +108,6 @@
 # define _LIBCPP_HAS_NO_SIZED_DEALLOCATION
 #endif
 
-#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) && \
-(!(defined(_LIBCPP_BUILDING_LIBRARY) || _LIBCPP_STD_VER > 14 || \
-(defined(__cpp_aligned_new) && __cpp_aligned_new >= 201606)))
-# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
-#endif
-
-
 #if !__has_builtin(__builtin_operator_new) || \
__has_builtin(__builtin_operator_new) < 201802L || \
defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) || \
Index: libcxx/include/__config
===
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -988,6 +988,11 @@
 #  endif
 #endif // defined(__APPLE__)
 
+#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) && \
+

Re: r338899 - [OpenCL] Always emit alloca in entry block for enqueue_kernel builtin

2018-08-06 Thread via cfe-commits
That's what I was missing; I should have looked more closely at the 
buildbot logs, I see the export there now.


Thanks!
Scott

On 2018-08-06 12:51, Vlad Tsyrklevich wrote:

Have you tried setting detect_stack_use_after_return in ASAN_OPTIONS?
The ASan buildbot sets the following ASAN_OPTIONS prior to running
tests:
export
ASAN_OPTIONS="check_initialization_order=true:detect_stack_use_after_return=1:detect_leaks=1"

On Mon, Aug 6, 2018 at 7:34 AM  wrote:


I can't seem to reproduce the ASan failure locally, even after
building
a clang with the latest compiler-rt, and then rebuilding my patch
with
LLVM_USE_SANITIZER=Address

I am pretty confident the problem should be fixed with a one-line
change
to my patch:

- auto CreateArrayForSizeVar = [=](unsigned First) {
+ auto CreateArrayForSizeVar = [=](unsigned First)
+ -> std::tuple
{

I don't want to commit something and then immediately have to
revert,
though. Can you think of anything I might be missing locally to
reproduce the ASan failure?

Thanks,
Scott

On 2018-08-03 13:48, Vlad Tsyrklevich wrote:

This change is causing ASan failures on the sanitizer bots:




http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/21898/steps/check-clang%20asan/logs/stdio

[1]

[9]

I've reverted it in r338904.

On Fri, Aug 3, 2018 at 8:51 AM Scott Linder via cfe-commits
 wrote:


Author: scott.linder
Date: Fri Aug 3 08:50:52 2018
New Revision: 338899

URL: http://llvm.org/viewvc/llvm-project?rev=338899=rev [2]

[1]

Log:
[OpenCL] Always emit alloca in entry block for enqueue_kernel
builtin

Ensures the statically sized alloca is not converted to
DYNAMIC_STACKALLOC
later because it is not in the entry block.

Differential Revision: https://reviews.llvm.org/D50104 [3] [2]

Added:
cfe/trunk/test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl

[4]

[3]
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl [5] [4]

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL:






http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=338899=338898=338899=diff

[6]

[5]






==

--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Aug 3 08:50:52 2018
@@ -3338,23 +3338,29 @@ RValue CodeGenFunction::EmitBuiltinExpr(
// Create a temporary array to hold the sizes of local pointer
arguments
// for the block. \p First is the position of the first size
argument.
auto CreateArrayForSizeVar = [=](unsigned First) {
- auto *AT = llvm::ArrayType::get(SizeTy, NumArgs - First);
- auto *Arr = Builder.CreateAlloca(AT);
- llvm::Value *Ptr;
+ llvm::APInt ArraySize(32, NumArgs - First);
+ QualType SizeArrayTy = getContext().getConstantArrayType(
+ getContext().getSizeType(), ArraySize, ArrayType::Normal,
+ /*IndexTypeQuals=*/0);
+ auto Tmp = CreateMemTemp(SizeArrayTy, "block_sizes");
+ llvm::Value *TmpPtr = Tmp.getPointer();
+ llvm::Value *TmpSize = EmitLifetimeStart(
+
CGM.getDataLayout().getTypeAllocSize(Tmp.getElementType()),

TmpPtr);

+ llvm::Value *ElemPtr;
// Each of the following arguments specifies the size of the
corresponding
// argument passed to the enqueued block.
auto *Zero = llvm::ConstantInt::get(IntTy, 0);
for (unsigned I = First; I < NumArgs; ++I) {
auto *Index = llvm::ConstantInt::get(IntTy, I - First);
- auto *GEP = Builder.CreateGEP(Arr, {Zero, Index});
+ auto *GEP = Builder.CreateGEP(TmpPtr, {Zero, Index});
if (I == First)
- Ptr = GEP;
+ ElemPtr = GEP;
auto *V =
Builder.CreateZExtOrTrunc(EmitScalarExpr(E->getArg(I)),
SizeTy);
Builder.CreateAlignedStore(
V, GEP,
CGM.getDataLayout().getPrefTypeAlignment(SizeTy));
}
- return Ptr;
+ return std::tie(ElemPtr, TmpSize, TmpPtr);
};

// Could have events and/or varargs.
@@ -3366,24 +3372,27 @@ RValue CodeGenFunction::EmitBuiltinExpr(
llvm::Value *Kernel =
Builder.CreatePointerCast(Info.Kernel, GenericVoidPtrTy);
auto *Block = Builder.CreatePointerCast(Info.BlockArg,
GenericVoidPtrTy);
- auto *PtrToSizeArray = CreateArrayForSizeVar(4);
+ llvm::Value *ElemPtr, *TmpSize, *TmpPtr;
+ std::tie(ElemPtr, TmpSize, TmpPtr) =
CreateArrayForSizeVar(4);

// Create a vector of the arguments, as well as a constant
value to
// express to the runtime the number of variadic arguments.
std::vector Args = {
Queue, Flags, Range,
Kernel, Block, ConstantInt::get(IntTy, NumArgs - 4),
- PtrToSizeArray};
+ ElemPtr};
std::vector ArgTys = {
- QueueTy, IntTy, RangeTy,
- GenericVoidPtrTy, GenericVoidPtrTy, IntTy,
- PtrToSizeArray->getType()};
+ QueueTy, IntTy, RangeTy,
GenericVoidPtrTy,
+ GenericVoidPtrTy, IntTy, ElemPtr->getType()};

llvm::FunctionType *FTy = llvm::FunctionType::get(
Int32Ty, llvm::ArrayRef(ArgTys), false);
- return RValue::get(
- Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name),
- llvm::ArrayRef(Args)));
+ auto Call =
+
RValue::get(Builder.CreateCall(CGM.CreateRuntimeFunction(FTy,

Name),

+ llvm::ArrayRef(Args)));
+ if (TmpSize)
+ 

[PATCH] D50261: [AST] Remove unnecessary indirections in DeclarationNameTable

2018-08-06 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

Yes it would be nice indeed. IIRC it is only needed for
QualType in one of the moved class.

This patch is especially nice since it both cleanup the code and
speed up clang :)


Repository:
  rL LLVM

https://reviews.llvm.org/D50261



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


[PATCH] D49897: [WebAssembly] Force use of lld for test/Driver/wasm-toolchain.c(pp)

2018-08-06 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 added a comment.

But in the CL description you say "..when configuring clang to use a different 
linker by default".  How is this possible?i.e. do you have a config where 
these tests are currently failing?


Repository:
  rC Clang

https://reviews.llvm.org/D49897



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


[PATCH] D50099: [DebugInfo][OpenCL] Address post-commit review of D49930

2018-08-06 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:997
   llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
   unsigned LineNo = 0;
 

echristo wrote:
> scott.linder wrote:
> > echristo wrote:
> > > Just noticed that LineNo is 0... for the entire function.
> > What should it be instead? My understanding is that LineNo=0 indicates 
> > there is no corresponding source, and these fields seem to be 
> > implementation details.
> Could probably just replace it with a constant 0 in the calls rather than 
> having the local?
Oh, I see what you mean; I will make that change, and I am also working out how 
to enable ASan correctly to check the patch, then I will post a new diff.


https://reviews.llvm.org/D50099



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


[PATCH] D50055: Update the coding standard about NFC changes and whitespace

2018-08-06 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In https://reviews.llvm.org/D50055#1188479, @chandlerc wrote:

> Maybe double check with Reid and/or Hal to make sure we've all ended up on 
> the same page before landing though.


lgtm, thanks


https://reviews.llvm.org/D50055



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


[PATCH] D50342: Changed how LLVM IR was generated to increase vectorization

2018-08-06 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added inline comments.



Comment at: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:125
 std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "define void @foo(i32* %a, i32* %b, i32* noalias %c, i64 %s) 
{\n"
-<< "%i = alloca i64\n"
-<< "store i64 0, i64* %i\n"
-<< "br label %loop\n\n"
-<< "loop:\n"
-<< "%ct = load i64, i64* %i\n"
-<< "%comp = icmp eq i64 %ct, %s\n"
-<< "br i1 %comp, label %endloop, label %body\n\n"
-<< "body:\n"
+  return os << "target triple = \"x86_64-pc-linux-gnu\"\n"
+<< "define void @foo(i32*, i32*, i32*, i64) {\n"

What does `pc` mean in this triple?  I'm used to seeing 
`x86_64-unknown-linux-gnu`.



Comment at: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:126
+  return os << "target triple = \"x86_64-pc-linux-gnu\"\n"
+<< "define void @foo(i32*, i32*, i32*, i64) {\n"
+<< "%5 = icmp sgt i64 %3, 0\n"

Does removing the variable names really make this easier to vectorize?



Comment at: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp:129
+<< "br i1 %5, label %6, label %8\n"
+<< "; :6:\n"
+<< "br label %9\n"

Does removing branch names really make this easier to vectorize?


Repository:
  rC Clang

https://reviews.llvm.org/D50342



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


[PATCH] D50099: [DebugInfo][OpenCL] Address post-commit review of D49930

2018-08-06 Thread Eric Christopher via Phabricator via cfe-commits
echristo added a comment.

In https://reviews.llvm.org/D50099#1189667, @scott.linder wrote:

> When I went to mark these as static I noticed they use 
> `CGDebugInfo::CreateMemberType` which uses a couple other non-static member 
> functions, and it starts to become difficult to tease things out into nice 
> clean static functions.


Ah. Fair. No worries then.




Comment at: lib/CodeGen/CGDebugInfo.cpp:997
   llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
   unsigned LineNo = 0;
 

scott.linder wrote:
> echristo wrote:
> > Just noticed that LineNo is 0... for the entire function.
> What should it be instead? My understanding is that LineNo=0 indicates there 
> is no corresponding source, and these fields seem to be implementation 
> details.
Could probably just replace it with a constant 0 in the calls rather than 
having the local?


https://reviews.llvm.org/D50099



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


[PATCH] D50261: [AST] Remove unnecessary indirections in DeclarationNameTable

2018-08-06 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Neat, thanks for the optimization. My only concern would be to find a way to 
avoid including Type.h, but it's already a very popular and very necessary 
header, so I don't think there is any issue here.


Repository:
  rL LLVM

https://reviews.llvm.org/D50261



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


[PATCH] D50099: [DebugInfo][OpenCL] Address post-commit review of D49930

2018-08-06 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

When I went to mark these as static I noticed they use 
`CGDebugInfo::CreateMemberType` which uses a couple other non-static member 
functions, and it starts to become difficult to tease things out into nice 
clean static functions.




Comment at: lib/CodeGen/CGDebugInfo.cpp:997
   llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
   unsigned LineNo = 0;
 

echristo wrote:
> Just noticed that LineNo is 0... for the entire function.
What should it be instead? My understanding is that LineNo=0 indicates there is 
no corresponding source, and these fields seem to be implementation details.


https://reviews.llvm.org/D50099



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


RE: r337005 - [NFC] Rename clang::AttributeList to clang::ParsedAttr

2018-08-06 Thread Keane, Erich via cfe-commits
Good grief... I even made a note to remove this 'TODO' on my whiteboard!

I discussed the name with AaronBallman who preferred ParsedAttr over 
ParsedAttribute (since ParsedAttributes is also a type).

Fixed in r339039.

-Original Message-
From: meiners...@googlemail.com [mailto:meiners...@googlemail.com] On Behalf Of 
Michael Kruse
Sent: Monday, August 6, 2018 11:00 AM
To: Keane, Erich 
Cc: cfe-commits 
Subject: Re: r337005 - [NFC] Rename clang::AttributeList to clang::ParsedAttr

2018-07-13 10:07 GMT-05:00 Erich Keane via cfe-commits
:
> -class AttributeList { // TODO: This should really be called ParsedAttribute
> +class ParsedAttr { // TODO: This should really be called ParsedAttribute

Should this TODO be removed/ParsedAttr really be called ParsedAttribute?

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


  1   2   >