r287088 - [X86][AVX512] Replace lossless i32/u32 to f64 conversion intrinsics with generic IR

2016-11-16 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Wed Nov 16 03:27:40 2016
New Revision: 287088

URL: http://llvm.org/viewvc/llvm-project?rev=287088&view=rev
Log:
[X86][AVX512] Replace lossless i32/u32 to f64 conversion intrinsics with 
generic IR

Both the (V)CVTDQ2PD (i32 to f64) and (V)CVTUDQ2PD (u32 to f64) conversion 
instructions are lossless and can be safely represented as generic 
__builtin_convertvector calls instead of x86 intrinsics without affecting final 
codegen.

This patch removes the clang builtins and their use in the headers - a future 
patch will deal with removing the llvm intrinsics.

This is an extension patch to D20528 which dealt with the equivalent sse/avx 
cases.

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

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/lib/Headers/avx512vlintrin.h
cfe/trunk/test/CodeGen/avx512f-builtins.c
cfe/trunk/test/CodeGen/avx512vl-builtins.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=287088&r1=287087&r2=287088&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Wed Nov 16 03:27:40 2016
@@ -961,8 +961,6 @@ TARGET_BUILTIN(__builtin_ia32_maxps512_m
 TARGET_BUILTIN(__builtin_ia32_maxpd512_mask, "V8dV8dV8dV8dUcIi", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_cvtdq2ps512_mask, "V16fV16iV16fUsIi", "", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_cvtudq2ps512_mask, "V16fV16iV16fUsIi", "", 
"avx512f")
-TARGET_BUILTIN(__builtin_ia32_cvtdq2pd512_mask, "V8dV8iV8dUc", "", "avx512f")
-TARGET_BUILTIN(__builtin_ia32_cvtudq2pd512_mask, "V8dV8iV8dUc", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2ps512_mask, "V8fV8dV8fUcIi", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_vcvtps2ph512_mask, "V16sV16fIiV16sUs", "", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_vcvtph2ps512_mask, "V16fV16sV16fUsIi", "", 
"avx512f")
@@ -1165,8 +1163,6 @@ TARGET_BUILTIN(__builtin_ia32_compressst
 TARGET_BUILTIN(__builtin_ia32_compressstoresf256_mask, "vV8f*V8fUc", "", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_compressstoresi128_mask, "vV4i*V4iUc", "", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_compressstoresi256_mask, "vV8i*V8iUc", "", 
"avx512vl")
-TARGET_BUILTIN(__builtin_ia32_cvtdq2pd128_mask, "V2dV4iV2dUc", "", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_cvtdq2pd256_mask, "V4dV4iV4dUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvtdq2ps128_mask, "V4fV4iV4fUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvtdq2ps256_mask, "V8fV8iV8fUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2dq128_mask, "V4iV2dV4iUc", "", "avx512vl")
@@ -1189,8 +1185,6 @@ TARGET_BUILTIN(__builtin_ia32_cvttps2dq1
 TARGET_BUILTIN(__builtin_ia32_cvttps2dq256_mask, "V8iV8fV8iUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvttps2udq128_mask, "V4iV4fV4iUc", "", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvttps2udq256_mask, "V8iV8fV8iUc", "", 
"avx512vl")
-TARGET_BUILTIN(__builtin_ia32_cvtudq2pd128_mask, "V2dV4iV2dUc", "", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_cvtudq2pd256_mask, "V4dV4iV4dUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvtudq2ps128_mask, "V4fV4iV4fUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvtudq2ps256_mask, "V8fV8iV8fUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_expanddf128_mask, "V2dV2dV2dUc", "", "avx512vl")

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=287088&r1=287087&r2=287088&view=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Wed Nov 16 03:27:40 2016
@@ -3740,26 +3740,23 @@ _mm512_maskz_cvtepu32_ps (__mmask16 __U,
 static __inline __m512d __DEFAULT_FN_ATTRS
 _mm512_cvtepi32_pd(__m256i __A)
 {
-  return (__m512d) __builtin_ia32_cvtdq2pd512_mask ((__v8si) __A,
-(__v8df)
-_mm512_setzero_pd (),
-(__mmask8) -1);
+  return (__m512d)__builtin_convertvector((__v8si)__A, __v8df);
 }
 
 static __inline__ __m512d __DEFAULT_FN_ATTRS
 _mm512_mask_cvtepi32_pd (__m512d __W, __mmask8 __U, __m256i __A)
 {
-  return (__m512d) __builtin_ia32_cvtdq2pd512_mask ((__v8si) __A,
-(__v8df) __W,
-(__mmask8) __U);
+  return (__m512d)__builtin_ia32_selectpd_512((__mmask8) __U,
+  (__v8df)_mm512_cvtepi32_pd(__A),
+  (__v8df)__W);
 }
 
 static __inline__ __m512d __DEFAULT_FN_ATTRS
 _mm512_maskz_cvtepi32_pd (__mmask8 __U, __m256i __A)
 {
-  return (__m512d) __builtin_ia32_cvtdq2pd512_mask ((__v8si) __A,
-(__v8df) _mm512_setzero_pd (),
-(__mmask8) __U);
+  return (

[PATCH] D26686: [X86][AVX512] Replace lossless i32/u32 to f64 conversion intrinsics with generic IR

2016-11-16 Thread Simon Pilgrim via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287088: [X86][AVX512] Replace lossless i32/u32 to f64 
conversion intrinsics with… (authored by RKSimon).

Changed prior to commit:
  https://reviews.llvm.org/D26686?vs=78038&id=78146#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26686

Files:
  cfe/trunk/include/clang/Basic/BuiltinsX86.def
  cfe/trunk/lib/Headers/avx512fintrin.h
  cfe/trunk/lib/Headers/avx512vlintrin.h
  cfe/trunk/test/CodeGen/avx512f-builtins.c
  cfe/trunk/test/CodeGen/avx512vl-builtins.c

Index: cfe/trunk/include/clang/Basic/BuiltinsX86.def
===
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def
@@ -961,8 +961,6 @@
 TARGET_BUILTIN(__builtin_ia32_maxpd512_mask, "V8dV8dV8dV8dUcIi", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_cvtdq2ps512_mask, "V16fV16iV16fUsIi", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_cvtudq2ps512_mask, "V16fV16iV16fUsIi", "", "avx512f")
-TARGET_BUILTIN(__builtin_ia32_cvtdq2pd512_mask, "V8dV8iV8dUc", "", "avx512f")
-TARGET_BUILTIN(__builtin_ia32_cvtudq2pd512_mask, "V8dV8iV8dUc", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2ps512_mask, "V8fV8dV8fUcIi", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_vcvtps2ph512_mask, "V16sV16fIiV16sUs", "", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_vcvtph2ps512_mask, "V16fV16sV16fUsIi", "", "avx512f")
@@ -1165,8 +1163,6 @@
 TARGET_BUILTIN(__builtin_ia32_compressstoresf256_mask, "vV8f*V8fUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_compressstoresi128_mask, "vV4i*V4iUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_compressstoresi256_mask, "vV8i*V8iUc", "", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_cvtdq2pd128_mask, "V2dV4iV2dUc", "", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_cvtdq2pd256_mask, "V4dV4iV4dUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvtdq2ps128_mask, "V4fV4iV4fUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvtdq2ps256_mask, "V8fV8iV8fUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvtpd2dq128_mask, "V4iV2dV4iUc", "", "avx512vl")
@@ -1189,8 +1185,6 @@
 TARGET_BUILTIN(__builtin_ia32_cvttps2dq256_mask, "V8iV8fV8iUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvttps2udq128_mask, "V4iV4fV4iUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvttps2udq256_mask, "V8iV8fV8iUc", "", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_cvtudq2pd128_mask, "V2dV4iV2dUc", "", "avx512vl")
-TARGET_BUILTIN(__builtin_ia32_cvtudq2pd256_mask, "V4dV4iV4dUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvtudq2ps128_mask, "V4fV4iV4fUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_cvtudq2ps256_mask, "V8fV8iV8fUc", "", "avx512vl")
 TARGET_BUILTIN(__builtin_ia32_expanddf128_mask, "V2dV2dV2dUc", "", "avx512vl")
Index: cfe/trunk/test/CodeGen/avx512f-builtins.c
===
--- cfe/trunk/test/CodeGen/avx512f-builtins.c
+++ cfe/trunk/test/CodeGen/avx512f-builtins.c
@@ -6949,33 +6949,43 @@
   return _mm512_maskz_cvtepu32_ps (__U,__A);
 }
 
+__m512d test_mm512_cvtepi32_pd (__m256i __A)
+{
+  // CHECK-LABEL: @test_mm512_cvtepi32_pd
+  // CHECK: sitofp <8 x i32> %{{.*}} to <8 x double>
+  return _mm512_cvtepi32_pd (__A);
+}
+
 __m512d test_mm512_mask_cvtepi32_pd (__m512d __W, __mmask8 __U, __m256i __A)
 {
-  // CHECK-LABEL: @test_mm512_mask_cvtepi32_pd 
-  // CHECK: @llvm.x86.avx512.mask.cvtdq2pd.512
+  // CHECK-LABEL: @test_mm512_mask_cvtepi32_pd
+  // CHECK: sitofp <8 x i32> %{{.*}} to <8 x double>
+  // CHECK: select <8 x i1> {{.*}}, <8 x double> {{.*}}, <8 x double> {{.*}}
   return _mm512_mask_cvtepi32_pd (__W,__U,__A);
 }
 
 __m512d test_mm512_maskz_cvtepi32_pd (__mmask8 __U, __m256i __A)
 {
-  // CHECK-LABEL: @test_mm512_maskz_cvtepi32_pd 
-  // CHECK: @llvm.x86.avx512.mask.cvtdq2pd.512
+  // CHECK-LABEL: @test_mm512_maskz_cvtepi32_pd
+  // CHECK: sitofp <8 x i32> %{{.*}} to <8 x double>
+  // CHECK: select <8 x i1> {{.*}}, <8 x double> {{.*}}, <8 x double> {{.*}}
   return _mm512_maskz_cvtepi32_pd (__U,__A);
 }
 
 __m512d test_mm512_cvtepi32lo_pd (__m512i __A)
 {
   // CHECK-LABEL: @test_mm512_cvtepi32lo_pd
   // CHECK: shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <4 x i32> 
-  // CHECK: @llvm.x86.avx512.mask.cvtdq2pd.512
+  // CHECK: sitofp <8 x i32> %{{.*}} to <8 x double>
   return _mm512_cvtepi32lo_pd (__A);
 }
 
 __m512d test_mm512_mask_cvtepi32lo_pd (__m512d __W, __mmask8 __U, __m512i __A)
 {
   // CHECK-LABEL: @test_mm512_mask_cvtepi32lo_pd
   // CHECK: shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <4 x i32> 
-  // CHECK: @llvm.x86.avx512.mask.cvtdq2pd.512
+  // CHECK: sitofp <8 x i32> %{{.*}} to <8 x double>
+  // CHECK: select <8 x i1> {{.*}}, <8 x double> {{.*}}, <8 x double> {{.*}}
   return _mm512_mask_cvtepi32lo_pd (__W, __U, __A);
 }
 
@@ -7000,33 +7010,43 @@
   return _mm512_maskz_cvtepi32_ps (__U,__A);
 }
 
+__m512d test_mm512_cvtepu32_pd(__m256i __A)
+{
+  // CHECK-LA

[PATCH] D26637: [change-namespace] handle constructor initializer: Derived : Base::Base() {} and added conflict detections

2016-11-16 Thread Eric Liu via cfe-commits
ioeric updated this revision to Diff 78148.
ioeric added a comment.

- Don't fix base class initializers at all.


https://reviews.llvm.org/D26637

Files:
  change-namespace/ChangeNamespace.cpp
  change-namespace/ChangeNamespace.h
  test/change-namespace/lambda-function.cpp
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -43,8 +43,9 @@
 NamespaceTool.registerMatchers(&Finder);
 std::unique_ptr Factory =
 tooling::newFrontendActionFactory(&Finder);
-tooling::runToolOnCodeWithArgs(Factory->create(), Code, {"-std=c++11"},
-   FileName);
+if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, {"-std=c++11"},
+   FileName))
+  return "";
 formatAndApplyAllReplacements(FileToReplacements, Context.Rewrite);
 return format(Context.getRewrittenText(ID));
   }
@@ -330,19 +331,6 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
-TEST_F(ChangeNamespaceTest, DoNotCrashWithLambdaAsParameter) {
-  std::string Code =
-  "#include \n"
-  "void f(std::function func, int param) { func(param); } "
-  "void g() { f([](int x) {}, 1); }";
-
-  std::string Expected =
-  "#include \n"
-  "void f(std::function func, int param) { func(param); } "
-  "void g() { f([](int x) {}, 1); }";
-  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
-}
-
 TEST_F(ChangeNamespaceTest, FixUsingShadowDecl) {
   std::string Code = "class GLOB {};\n"
  "using BLOG = GLOB;\n"
@@ -510,8 +498,8 @@
  "public:\n"
  "static int A1;\n"
  "static int A2;\n"
- "}\n"
- "static int A::A1 = 0;\n"
+ "};\n"
+ "int A::A1 = 0;\n"
  "namespace nb {\n"
  "void f() { int a = A::A1; int b = A::A2; }"
  "} // namespace nb\n"
@@ -522,8 +510,8 @@
  "public:\n"
  "static int A1;\n"
  "static int A2;\n"
- "}\n"
- "static int A::A1 = 0;\n"
+ "};\n"
+ "int A::A1 = 0;\n"
  "\n"
  "} // namespace na\n"
  "namespace x {\n"
@@ -1005,6 +993,93 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, DerivedClassWithConstructors) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) {}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "\n\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) {}\n"
+  "} // namespace y\n"
+  "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, DerivedClassWithQualifiedConstructors) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X::X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X::X(i) {}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "\n\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X::X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X::X(i) {}\n"
+  "} // namespace y\n"
+  "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, DerivedClassWithConstructorsAndTypeRefs) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) { X x(1);}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  

[PATCH] D26582: [clang-tidy] Handle template instantiations in modenize-use-default check

2016-11-16 Thread Malcolm Parsons via cfe-commits
malcolm.parsons added inline comments.



Comment at: test/clang-tidy/modernize-use-default.cpp:142
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use '= default'
+// CHECK-FIXES: TempODef::~TempODef() = default;
+

aaron.ballman wrote:
> malcolm.parsons wrote:
> > aaron.ballman wrote:
> > > Would it be better if the `= default` were on the inline declaration 
> > > rather than the out-of-line definition? If so, that might be a reasonable 
> > > FIXME to add to this test (assuming you don't feel like fixing it as part 
> > > of this patch).
> > > 
> > > Also, does the `= delete` check suffer from the same issue?
> > There are valid reasons for having out-of-line definitions, even when 
> > defaulted.
> > The delete check only triggers if there is no definition. Template 
> > instantiation can't copy a definition that doesn't exist.
> Hmm, I suppose that is true. Thanks!
Scratch that.

The `= delete` check doesn't create conflicting duplicate fixes, but it does 
have an issue.
The fixes for template instantiations are correct for the operators, but not 
for the constructors.
This is because the AST has the wrong source range for the template 
instantiation's constructors.

The template's copy constructor's source range includes the parameters:
`CXXConstructorDecl 0x27bc9c0  col:3 
PositivePrivateTemplate 'void (const PositivePrivateTemplate &)'`

The template instantiation's copy constructor's source range does not:
`CXXConstructorDecl 0x27bd560  col:3 PositivePrivateTemplate 'void 
(const struct PositivePrivateTemplate &)'`

I'll make another patch for this.


https://reviews.llvm.org/D26582



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


[PATCH] D26582: [clang-tidy] Handle template instantiations in modenize-use-default check

2016-11-16 Thread Malcolm Parsons via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287091: [clang-tidy] Handle template instantiations in 
modenize-use-default check (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D26582?vs=77728&id=78151#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26582

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp


Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
@@ -124,6 +124,26 @@
   // CHECK-FIXES: ~Temp() = default;
 };
 
+// Class template out of line with explicit instantiation.
+template 
+class TempODef {
+public:
+  TempODef();
+  ~TempODef();
+};
+
+template 
+TempODef::TempODef() {}
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use '= default'
+// CHECK-FIXES: TempODef::TempODef() = default;
+template 
+TempODef::~TempODef() {}
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use '= default'
+// CHECK-FIXES: TempODef::~TempODef() = default;
+
+template class TempODef;
+template class TempODef;
+
 // Non user-provided constructor/destructor.
 struct Imp {
   int Int;
Index: clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
@@ -241,6 +241,7 @@
   if (SpecialFunctionDecl->isDeleted() ||
   SpecialFunctionDecl->isExplicitlyDefaulted() ||
   SpecialFunctionDecl->isLateTemplateParsed() ||
+  SpecialFunctionDecl->isTemplateInstantiation() ||
   !SpecialFunctionDecl->isUserProvided() || 
!SpecialFunctionDecl->hasBody())
 return;
 


Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
@@ -124,6 +124,26 @@
   // CHECK-FIXES: ~Temp() = default;
 };
 
+// Class template out of line with explicit instantiation.
+template 
+class TempODef {
+public:
+  TempODef();
+  ~TempODef();
+};
+
+template 
+TempODef::TempODef() {}
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use '= default'
+// CHECK-FIXES: TempODef::TempODef() = default;
+template 
+TempODef::~TempODef() {}
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use '= default'
+// CHECK-FIXES: TempODef::~TempODef() = default;
+
+template class TempODef;
+template class TempODef;
+
 // Non user-provided constructor/destructor.
 struct Imp {
   int Int;
Index: clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
@@ -241,6 +241,7 @@
   if (SpecialFunctionDecl->isDeleted() ||
   SpecialFunctionDecl->isExplicitlyDefaulted() ||
   SpecialFunctionDecl->isLateTemplateParsed() ||
+  SpecialFunctionDecl->isTemplateInstantiation() ||
   !SpecialFunctionDecl->isUserProvided() || !SpecialFunctionDecl->hasBody())
 return;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r287091 - [clang-tidy] Handle template instantiations in modenize-use-default check

2016-11-16 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Wed Nov 16 03:51:40 2016
New Revision: 287091

URL: http://llvm.org/viewvc/llvm-project?rev=287091&view=rev
Log:
[clang-tidy] Handle template instantiations in modenize-use-default check

Summary:
Duplicate fixes were being created for explicit template instantiations
of out-of-line constructors or destructors.

Fixes PR30921.

Reviewers: alexfh, aaron.ballman

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp?rev=287091&r1=287090&r2=287091&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultCheck.cpp Wed Nov 16 
03:51:40 2016
@@ -241,6 +241,7 @@ void UseDefaultCheck::check(const MatchF
   if (SpecialFunctionDecl->isDeleted() ||
   SpecialFunctionDecl->isExplicitlyDefaulted() ||
   SpecialFunctionDecl->isLateTemplateParsed() ||
+  SpecialFunctionDecl->isTemplateInstantiation() ||
   !SpecialFunctionDecl->isUserProvided() || 
!SpecialFunctionDecl->hasBody())
 return;
 

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp?rev=287091&r1=287090&r2=287091&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default.cpp Wed Nov 
16 03:51:40 2016
@@ -124,6 +124,26 @@ public:
   // CHECK-FIXES: ~Temp() = default;
 };
 
+// Class template out of line with explicit instantiation.
+template 
+class TempODef {
+public:
+  TempODef();
+  ~TempODef();
+};
+
+template 
+TempODef::TempODef() {}
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use '= default'
+// CHECK-FIXES: TempODef::TempODef() = default;
+template 
+TempODef::~TempODef() {}
+// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use '= default'
+// CHECK-FIXES: TempODef::~TempODef() = default;
+
+template class TempODef;
+template class TempODef;
+
 // Non user-provided constructor/destructor.
 struct Imp {
   int Int;


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


[PATCH] D26665: [clang-move] Support moving function.

2016-11-16 Thread Eric Liu via cfe-commits
ioeric added inline comments.



Comment at: clang-move/ClangMove.cpp:414
+  Optional> InMovedSymbolNames;
   for (StringRef ClassName : Spec.Names) {
 llvm::StringRef GlobalClassName = ClassName.trim().ltrim(':');

s/ClassName/SymbolName/



Comment at: clang-move/ClangMove.cpp:417
 const auto HasName = hasName(("::" + GlobalClassName).str());
-InMovedClassNames =
-InMovedClassNames ? anyOf(*InMovedClassNames, HasName) : HasName;
+InMovedSymbolNames =
+InMovedSymbolNames ? anyOf(*InMovedSymbolNames, HasName) : HasName;

I guess `HasAnySymbolNames` would be better when used in the matchers below.



Comment at: test/clang-move/Inputs/function_test.h:1
+void f();
+

Maybe add a test case where both classes and functions exist.



Comment at: test/clang-move/move-function.cpp:9
+// CHECK-NEW-TEST-H-CASE1: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE1: inline int g() { return 0; }
+// CHECK-NEW-TEST-H-CASE1: #endif // {{.*}}NEW_FUNCTION_TEST_H

Shouldn't there be empty lines around this line?



Comment at: test/clang-move/move-function.cpp:18
+// CHECK-NEW-TEST-H-CASE2: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE2: template  void h(T t) {}
+// CHECK-NEW-TEST-H-CASE2: template <> void h(int t) {}

Why does this become one line after being moved?

Shouldn't it be:
```
template
void h(T t) {}
```


https://reviews.llvm.org/D26665



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


Re: [PATCH] D22955: [MSVC] Improved late parsing of template functions.

2016-11-16 Thread Will Wilson via cfe-commits
A backup ping. Sorry for the noise but this would be a very useful patch to
get done and dusted.

On 10 November 2016 at 08:17, Alexey Bataev via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> ABataev added a comment.
>
> Ping
>
>
> https://reviews.llvm.org/D22955
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>



-- 
*Indefiant *: http://www.indefiant.com
Home of Recode : Runtime C++ Editing for VS
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26665: [clang-move] Support moving function.

2016-11-16 Thread Haojian Wu via cfe-commits
hokein added inline comments.



Comment at: test/clang-move/move-function.cpp:9
+// CHECK-NEW-TEST-H-CASE1: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE1: inline int g() { return 0; }
+// CHECK-NEW-TEST-H-CASE1: #endif // {{.*}}NEW_FUNCTION_TEST_H

ioeric wrote:
> Shouldn't there be empty lines around this line?
There should be. FileCheck will skip  empty lines and try to find next matching 
line here. Have added some `\n` checks.



Comment at: test/clang-move/move-function.cpp:18
+// CHECK-NEW-TEST-H-CASE2: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE2: template  void h(T t) {}
+// CHECK-NEW-TEST-H-CASE2: template <> void h(int t) {}

ioeric wrote:
> Why does this become one line after being moved?
> 
> Shouldn't it be:
> ```
> template
> void h(T t) {}
> ```
`formatAndApplyReplacements` does this for us ,and this is actually LLVM code 
style...


https://reviews.llvm.org/D26665



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


[PATCH] D26665: [clang-move] Support moving function.

2016-11-16 Thread Haojian Wu via cfe-commits
hokein updated this revision to Diff 78160.
hokein marked 4 inline comments as done.
hokein added a comment.

Add one more test and rename variables.


https://reviews.llvm.org/D26665

Files:
  clang-move/ClangMove.cpp
  test/clang-move/Inputs/function_test.cpp
  test/clang-move/Inputs/function_test.h
  test/clang-move/move-function.cpp

Index: test/clang-move/move-function.cpp
===
--- /dev/null
+++ test/clang-move/move-function.cpp
@@ -0,0 +1,67 @@
+// RUN: mkdir -p %T/move-function
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: cd %T/move-function
+// RUN: clang-move -names="g" -new_header=%T/move-function/new_function_test.h -old_header=../move-function/function_test.h %T/move-function/function_test.cpp --
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.h -check-prefix=CHECK-NEW-TEST-H-CASE1 %s
+//
+// CHECK-NEW-TEST-H-CASE1: #ifndef {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE1: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE1: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE1: inline int g() { return 0; }
+// CHECK-NEW-TEST-H-CASE1: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE1: #endif // {{.*}}NEW_FUNCTION_TEST_H
+//
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: clang-move -names="h" -new_header=%T/move-function/new_function_test.h -old_header=../move-function/function_test.h %T/move-function/function_test.cpp --
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.h -check-prefix=CHECK-NEW-TEST-H-CASE2 %s
+//
+// CHECK-NEW-TEST-H-CASE2: #ifndef {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE2: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE2: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE2: template  void h(T t) {}
+// CHECK-NEW-TEST-H-CASE2: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE2: template <> void h(int t) {}
+// CHECK-NEW-TEST-H-CASE2: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE2: #endif // {{.*}}NEW_FUNCTION_TEST_H
+//
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: clang-move -names="f" -new_header=%T/move-function/new_function_test.h -new_cc=%T/move-function/new_function_test.cpp -old_header=../move-function/function_test.h -old_cc=../move-function/function_test.cpp %T/move-function/function_test.cpp --
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.h -check-prefix=CHECK-NEW-TEST-H-CASE3 %s
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.cpp -check-prefix=CHECK-NEW-TEST-CPP-CASE3 %s
+//
+// CHECK-NEW-TEST-H-CASE3: #ifndef {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE3: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE3: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE3: void f();
+// CHECK-NEW-TEST-H-CASE3: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE3: #endif // {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-CPP-CASE3: #include "{{.*}}new_function_test.h"
+// CHECK-NEW-TEST-CPP-CASE3: {{[[:space:]]+}}
+// CHECK-NEW-TEST-CPP-CASE3: void f() {}
+//
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: clang-move -names="A::f" -new_header=%T/move-function/new_function_test.h -new_cc=%T/move-function/new_function_test.cpp -old_header=../move-function/function_test.h -old_cc=../move-function/function_test.cpp %T/move-function/function_test.cpp -dump_result -- | FileCheck %s -check-prefix=CHECK-EMPTY
+//
+// CHECK-EMPTY: [{{[[:space:]]*}}]
+//
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: clang-move -names="f,A" -new_header=%T/move-function/new_function_test.h -new_cc=%T/move-function/new_function_test.cpp -old_header=../move-function/function_test.h -old_cc=../move-function/function_test.cpp %T/move-function/function_test.cpp --
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.h -check-prefix=CHECK-NEW-TEST-H-CASE4 %s
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.cpp -check-prefix=CHECK-NEW-TEST-CPP-CASE4 %s
+
+// CHECK-NEW-TEST-H-CASE4: #ifndef {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE4: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE4: void f();
+// CHECK-NEW-TEST-H-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE4: class A {
+// CHECK-NEW-TEST-H-CASE4: public:
+// CHECK-NEW-TEST-H-CASE4:   void f();
+// CHECK-NEW-TEST-H-CASE4: };
+// CHECK-NEW-TEST-H-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE4: #endif // {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-CPP-CASE4: #include "{{.*}}new_function_test.h"
+// CHECK-NEW-TEST-CPP-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-CPP-CASE4: void f() {}
+// CHECK-NEW-TEST-CPP-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-CPP-CASE4: void A::f() {}
Index: test/clang-move/Inputs/function_test.h
===
--- /dev/null
+++ test/clang-move/Inputs/function_test.h
@@ -0,0 +1,14 @@
+void f();
+
+inline int g() { return 0; }
+
+template
+void h(T t) {}
+
+template<>
+void

[PATCH] D26665: [clang-move] Support moving function.

2016-11-16 Thread Eric Liu via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

Lg with two nits.




Comment at: clang-move/ClangMove.cpp:145
+  void run(const MatchFinder::MatchResult &Result) override {
+auto *SM = &Result.Context->getSourceManager();
+if (const auto *FD =

Maybe just inline this variable since this is only used once.



Comment at: clang-move/ClangMove.cpp:146
+auto *SM = &Result.Context->getSourceManager();
+if (const auto *FD =
+Result.Nodes.getNodeAs("function")) {

I'd `assert(FD)` instead.


https://reviews.llvm.org/D26665



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


r287100 - [OpenCL] Use the semantic spelling of the Access attribute, rather than a string.

2016-11-16 Thread Joey Gouly via cfe-commits
Author: joey
Date: Wed Nov 16 05:34:09 2016
New Revision: 287100

URL: http://llvm.org/viewvc/llvm-project?rev=287100&view=rev
Log:
[OpenCL] Use the semantic spelling of the Access attribute, rather than a 
string.

Also fix a latent bug, due to an incorrect traversal of the AttributeList.

Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCL/invalid-image.cl

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=287100&r1=287099&r2=287100&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Nov 16 05:34:09 2016
@@ -1209,19 +1209,19 @@ TypeResult Sema::actOnObjCTypeArgsAndPro
   return CreateParsedType(Result, ResultTInfo);
 }
 
-static StringRef getImageAccessAttrStr(AttributeList *attrs) {
-  if (attrs) {
-
-AttributeList *Next;
+static OpenCLAccessAttr::Spelling getImageAccess(const AttributeList *Attrs) {
+  if (Attrs) {
+const AttributeList *Next = Attrs;
 do {
-  AttributeList &Attr = *attrs;
+  const AttributeList &Attr = *Next;
   Next = Attr.getNext();
   if (Attr.getKind() == AttributeList::AT_OpenCLAccess) {
-return Attr.getName()->getName();
+return static_cast(
+Attr.getSemanticSpelling());
   }
 } while (Next);
   }
-  return "";
+  return OpenCLAccessAttr::Keyword_read_only;
 }
 
 /// \brief Convert the specified declspec to the appropriate type
@@ -1619,11 +1619,14 @@ static QualType ConvertDeclSpecToType(Ty
 
 #define GENERIC_IMAGE_TYPE(ImgType, Id) \
   case DeclSpec::TST_##ImgType##_t: \
-Result = llvm::StringSwitch( \
- getImageAccessAttrStr(DS.getAttributes().getList())) \
- .Cases("write_only", "__write_only", Context.Id##WOTy) \
- .Cases("read_write", "__read_write", Context.Id##RWTy) \
- .Default(Context.Id##ROTy); \
+switch (getImageAccess(DS.getAttributes().getList())) { \
+case OpenCLAccessAttr::Keyword_write_only: \
+  Result = Context.Id##WOTy; break; \
+case OpenCLAccessAttr::Keyword_read_write: \
+  Result = Context.Id##RWTy; break; \
+case OpenCLAccessAttr::Keyword_read_only: \
+  Result = Context.Id##ROTy; break; \
+} \
 break;
 #include "clang/Basic/OpenCLImageTypes.def"
 

Modified: cfe/trunk/test/SemaOpenCL/invalid-image.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-image.cl?rev=287100&r1=287099&r2=287100&view=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-image.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-image.cl Wed Nov 16 05:34:09 2016
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -D=ATTR_TEST -fms-compatibility %s
 
 void test1(image1d_t *i) {} // expected-error{{pointer to type '__read_only 
image1d_t' is invalid in OpenCL}}
 
@@ -12,3 +13,8 @@ void test2(image1d_t i) {
 }
 
 image1d_t test3() {} // expected-error{{declaring function return value of 
type '__read_only image1d_t' is not allowed}}
+
+#ifdef ATTR_TEST
+// Test case for an infinite loop bug.
+kernel void foob(read_only __ptr32  image2d_t i) { } // 
expected-error{{'__ptr32' attribute only applies to pointer arguments}}
+#endif


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


[PATCH] D26668: [OpenCL] Minor cleanup to access attributes on images

2016-11-16 Thread Joey Gouly via cfe-commits
joey closed this revision.
joey added a comment.

Committed as r287100.




Comment at: test/SemaOpenCL/access-qualifier.cl:71
+
+#if __OPENCL_C_VERSION__ >= 200
+void myPipeWrite(write_only pipe int); // expected-note {{passing argument to 
parameter here}}

This was an unintentional test change, and was not committed.


Repository:
  rL LLVM

https://reviews.llvm.org/D26668



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


[PATCH] D26741: [clang-tidy] Changes to modernize-use-default check

2016-11-16 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added reviewers: aaron.ballman, alexfh.
malcolm.parsons added a subscriber: cfe-commits.

Warn about special member functions that only contain a comment.
Report the location of the special member function, unless it is
defined in a macro.  Reporting the location of the body in a macro is
more helpful as it causes the macro expansion location to be reported too.

Fixes PR30920.


https://reviews.llvm.org/D26741

Files:
  clang-tidy/modernize/UseDefaultCheck.cpp
  test/clang-tidy/modernize-use-default-copy.cpp
  test/clang-tidy/modernize-use-default.cpp

Index: test/clang-tidy/modernize-use-default.cpp
===
--- test/clang-tidy/modernize-use-default.cpp
+++ test/clang-tidy/modernize-use-default.cpp
@@ -8,10 +8,10 @@
 };
 
 OL::OL() {}
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use '= default' to define a trivial default constructor [modernize-use-default]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use '= default' to define a trivial default constructor [modernize-use-default]
 // CHECK-FIXES: OL::OL() = default;
 OL::~OL() {}
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use '= default' to define a trivial destructor [modernize-use-default]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use '= default' to define a trivial destructor [modernize-use-default]
 // CHECK-FIXES: OL::~OL() = default;
 
 // Inline definitions.
@@ -92,10 +92,10 @@
 class KW {
 public:
   explicit KW() {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use '= default'
   // CHECK-FIXES: explicit KW() = default;
   virtual ~KW() {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= default'
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use '= default'
   // CHECK-FIXES: virtual ~KW() = default;
 };
 
@@ -134,11 +134,11 @@
 
 template 
 TempODef::TempODef() {}
-// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use '= default'
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use '= default'
 // CHECK-FIXES: TempODef::TempODef() = default;
 template 
 TempODef::~TempODef() {}
-// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: use '= default'
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: use '= default'
 // CHECK-FIXES: TempODef::~TempODef() = default;
 
 template class TempODef;
@@ -178,9 +178,11 @@
   Comments() {
 // Don't erase comments inside the body.
   }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use '= default'
   ~Comments() {
 // Don't erase comments inside the body.
   }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use '= default'
 };
 
 // Try-catch.
@@ -195,3 +197,13 @@
 };
 OTC::OTC() try {} catch(...) {}
 OTC::~OTC() try {} catch(...) {}
+
+#define STRUCT_WITH_DEFAULT(_base, _type) \
+  struct _type {  \
+_type() {}\
+_base value;  \
+  };
+
+STRUCT_WITH_DEFAULT(unsigned char, Hex8Default)
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use '= default' to define a trivial default constructor
+// CHECK-MESSAGES: :[[@LINE-6]]:13: note:
Index: test/clang-tidy/modernize-use-default-copy.cpp
===
--- test/clang-tidy/modernize-use-default-copy.cpp
+++ test/clang-tidy/modernize-use-default-copy.cpp
@@ -7,13 +7,13 @@
   int Field;
 };
 OL::OL(const OL &Other) : Field(Other.Field) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use '= default' to define a trivial copy constructor [modernize-use-default]
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use '= default' to define a trivial copy constructor [modernize-use-default]
 // CHECK-FIXES: OL::OL(const OL &Other)  = default;
 OL &OL::operator=(const OL &Other) {
   Field = Other.Field;
   return *this;
 }
-// CHECK-MESSAGES: :[[@LINE-4]]:1: warning: use '= default' to define a trivial copy-assignment operator [modernize-use-default]
+// CHECK-MESSAGES: :[[@LINE-4]]:9: warning: use '= default' to define a trivial copy-assignment operator [modernize-use-default]
 // CHECK-FIXES: OL &OL::operator=(const OL &Other) = default;
 
 // Inline.
@@ -25,7 +25,7 @@
 Field = Other.Field;
 return *this;
   }
-  // CHECK-MESSAGES: :[[@LINE-4]]:3: warning: use '= default'
+  // CHECK-MESSAGES: :[[@LINE-4]]:7: warning: use '= default'
   // CHECK-FIXES: IL &operator=(const IL &Other) = default;
   int Field;
 };
@@ -110,7 +110,7 @@
   Empty &operator=(const Empty &);
 };
 Empty &Empty::operator=(const Empty &Other) { return *this; }
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use '= default'
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use '= default'
 // CHECK-FIXES: Empty &Empty::operator=(const Empty &Other) = default;
 
 // Bit fields.
@@ -137,7 +137,7 @@
   Field4 = Other.Field4;
   return *this;
 }
-// CHECK-MESSAGES: :[[@LINE-7]]:1: warning: use '= default'
+// CHECK-MESSAGES: :[[@LINE-7]]:9: warning: use '= default'
 // CHECK-FIXES: BF &BF::operator=(const B

[PATCH] D26742: [RecursiveASTVisitor] Fix post-order traversal of UnaryOperator

2016-11-16 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added reviewers: aaron.ballman, klimek, teemperor, doug.gregor.
malcolm.parsons added a subscriber: cfe-commits.

https://reviews.llvm.org/D26742

Files:
  include/clang/AST/RecursiveASTVisitor.h
  unittests/AST/PostOrderASTVisitor.cpp


Index: unittests/AST/PostOrderASTVisitor.cpp
===
--- unittests/AST/PostOrderASTVisitor.cpp
+++ unittests/AST/PostOrderASTVisitor.cpp
@@ -34,6 +34,11 @@
 
 bool shouldTraversePostOrder() const { return VisitPostOrder; }
 
+bool VisitUnaryOperator(UnaryOperator *Op) {
+  VisitedNodes.push_back(Op->getOpcodeStr(Op->getOpcode()));
+  return true;
+}
+
 bool VisitBinaryOperator(BinaryOperator *Op) {
   VisitedNodes.push_back(Op->getOpcodeStr());
   return true;
@@ -76,7 +81,7 @@
   auto ASTUnit = tooling::buildASTFromCode(
 "class A {"
 "  class B {"
-"int foo() { while(4) { int i = 9; } return (1 + 3) + 2; }"
+"int foo() { while(4) { int i = 9; int j = -i; } return (1 + 3) + 2; }"
 "  };"
 "};"
   );
@@ -87,7 +92,7 @@
   Visitor.TraverseTranslationUnitDecl(TU);
 
   std::vector expected = {
-"4", "9", "i", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A"
+"4", "9", "i", "-", "j", "1", "3", "+", "2", "+", "return", "A::B::foo", 
"A::B", "A"
   };
   // Compare the list of actually visited nodes
   // with the expected list of visited nodes.
Index: include/clang/AST/RecursiveASTVisitor.h
===
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -357,7 +357,8 @@
 #define OPERATOR(NAME) 
\
   bool TraverseUnary##NAME(UnaryOperator *S,   
\
DataRecursionQueue *Queue = nullptr) {  
\
-TRY_TO(WalkUpFromUnary##NAME(S));  
\
+if (!getDerived().shouldTraversePostOrder())   
\
+  TRY_TO(WalkUpFromUnary##NAME(S));
\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr());  
\
 return true;   
\
   }
\


Index: unittests/AST/PostOrderASTVisitor.cpp
===
--- unittests/AST/PostOrderASTVisitor.cpp
+++ unittests/AST/PostOrderASTVisitor.cpp
@@ -34,6 +34,11 @@
 
 bool shouldTraversePostOrder() const { return VisitPostOrder; }
 
+bool VisitUnaryOperator(UnaryOperator *Op) {
+  VisitedNodes.push_back(Op->getOpcodeStr(Op->getOpcode()));
+  return true;
+}
+
 bool VisitBinaryOperator(BinaryOperator *Op) {
   VisitedNodes.push_back(Op->getOpcodeStr());
   return true;
@@ -76,7 +81,7 @@
   auto ASTUnit = tooling::buildASTFromCode(
 "class A {"
 "  class B {"
-"int foo() { while(4) { int i = 9; } return (1 + 3) + 2; }"
+"int foo() { while(4) { int i = 9; int j = -i; } return (1 + 3) + 2; }"
 "  };"
 "};"
   );
@@ -87,7 +92,7 @@
   Visitor.TraverseTranslationUnitDecl(TU);
 
   std::vector expected = {
-"4", "9", "i", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A"
+"4", "9", "i", "-", "j", "1", "3", "+", "2", "+", "return", "A::B::foo", "A::B", "A"
   };
   // Compare the list of actually visited nodes
   // with the expected list of visited nodes.
Index: include/clang/AST/RecursiveASTVisitor.h
===
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -357,7 +357,8 @@
 #define OPERATOR(NAME) \
   bool TraverseUnary##NAME(UnaryOperator *S,   \
DataRecursionQueue *Queue = nullptr) {  \
-TRY_TO(WalkUpFromUnary##NAME(S));  \
+if (!getDerived().shouldTraversePostOrder())   \
+  TRY_TO(WalkUpFromUnary##NAME(S));\
 TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getSubExpr());  \
 return true;   \
   }\
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24933: Enable configuration files in clang

2016-11-16 Thread Serge Pavlov via cfe-commits
sepavloff updated this revision to Diff 78167.
sepavloff added a comment.

Limit the patch by named configuration files only

Follow advice of @mgorny and removed all features from the patch except
named config files. These are files specified explicitly by option
`--config` or encoded in executable name, such as `armv7l-clang`. This
kind of configuration files did not cause objections except that "this
functionality is already available with `@file`". In contrast to `@file`
configuration files have advantages:

- they is searched in well-known places rather than in current directory,
- they may contain comments,
- they may include other files by `@file` and these files are resolved relative 
to the including file.
- they may be encoded in executable name; such encoding is already used by 
clang to specify targets.

Also added section about config files to the user manual.


https://reviews.llvm.org/D24933

Files:
  docs/UsersManual.rst
  include/clang/Driver/Driver.h
  lib/Driver/Driver.cpp
  test/Driver/Inputs/config-1.cfg
  test/Driver/Inputs/config-2.cfg
  test/Driver/config-file.c
  tools/driver/driver.cpp

Index: tools/driver/driver.cpp
===
--- tools/driver/driver.cpp
+++ tools/driver/driver.cpp
@@ -305,6 +305,34 @@
   return 1;
 }
 
+// Directories searched for configuration specified by option '--config'.
+static const char * const SearchDirs[] = { "~/.llvm" };
+
+/// Deduce configuration name if it is encoded in the executable name.
+///
+/// \param ConfigFile [out] Is assigned configuration file path.
+/// \param ProgramName [in] clang executable path.
+/// \return True if configuration file was found.
+///
+/// If clang executable is named e.g. 'armv7l-clang' the function tries to
+/// find config file 'armv7l.cfg'. If it is found, its path is put into
+/// ConfigFile and the function returns true.
+///
+static bool findConfigFileFromProgramName(
+llvm::SmallVectorImpl &ConfigFile, StringRef ProgramName) {
+  ConfigFile.clear();
+  StringRef PName = llvm::sys::path::stem(ProgramName);
+  size_t Pos = PName.find("-clang");
+  if (Pos != StringRef::npos) {
+ConfigFile.append(PName.begin(), PName.begin() + Pos);
+const StringRef Ext(".cfg");
+ConfigFile.append(Ext.begin(), Ext.end());
+StringRef CName(ConfigFile.begin(), ConfigFile.size());
+return llvm::cl::searchForFile(ConfigFile, SearchDirs, ProgramName, CName);
+  }
+  return false;
+}
+
 int main(int argc_, const char **argv_) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv_[0]);
   llvm::PrettyStackTraceProgram X(argc_, argv_);
@@ -330,6 +358,31 @@
   llvm::BumpPtrAllocator A;
   llvm::StringSaver Saver(A);
 
+  // Try reading options from configuration file.
+  llvm::SmallString<128> ConfigFile;
+  llvm::cl::SearchResult SRes;
+
+  // First try config file specified in command line. It has higher priority
+  // than any other way to specify configuration.
+  SRes = llvm::cl::findConfigFileFromArgs(ConfigFile, argv, SearchDirs, true);
+  if (llvm::cl::checkConfigFileSearchResult(SRes, ConfigFile, SearchDirs,
+ProgName))
+return 1;
+
+  // If config file is not specified explicitly, try to determine configuration
+  // implicitly. First try to deduce configuration from executable name. For
+  // instance, a file 'armv7l-clang' applies config file 'armv7l.cfg'. Second,
+  // try to find file 'clang.cfg'.
+  if (SRes == llvm::cl::SearchResult::NotSpecified) {
+if (findConfigFileFromProgramName(ConfigFile, ProgName))
+  SRes = llvm::cl::SearchResult::Successful;
+  }
+
+  if (SRes == llvm::cl::SearchResult::Successful) {
+unsigned NumOpts;
+llvm::cl::readConfigFile(ConfigFile, Saver, argv, NumOpts);
+  }
+
   // Parse response files using the GNU syntax, unless we're in CL mode. There
   // are two ways to put clang in CL compatibility mode: argv[0] is either
   // clang-cl or cl, or --driver-mode=cl is on the command line. The normal
@@ -446,6 +499,8 @@
   ProcessWarningOptions(Diags, *DiagOpts, /*ReportDiags=*/false);
 
   Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags);
+  if (!ConfigFile.empty())
+TheDriver.setConfigFile(ConfigFile.str());
   SetInstallDir(argv, TheDriver, CanonicalPrefixes);
 
   insertTargetAndModeArgs(TargetAndMode.first, TargetAndMode.second, argv,
Index: test/Driver/config-file.c
===
--- /dev/null
+++ test/Driver/config-file.c
@@ -0,0 +1,22 @@
+// RUN: %clang --config %S/Inputs/config-1.cfg -c %s -### 2>&1 | FileCheck %s -check-prefix CHECK-HHH
+// CHECK-HHH: Target: x86_64-apple-darwin
+// CHECK-HHH: Configuration file: {{.*}}/Inputs/config-1.cfg
+// CHECK-HHH: -Werror
+// CHECK-HHH: -std=c99
+
+// RUN: not %clang --config %S/Inputs/inexistent.cfg -c %s -### 2>&1 | FileCheck %s -check-prefix CHECK-INEX
+// CHECK-INEX: Configuration file {{.*}}/Inputs/inexistent.cfg' specified by opt

[PATCH] D26665: [clang-move] Support moving function.

2016-11-16 Thread Haojian Wu via cfe-commits
hokein updated this revision to Diff 78171.
hokein added a comment.

Fix nits.


https://reviews.llvm.org/D26665

Files:
  clang-move/ClangMove.cpp
  test/clang-move/Inputs/function_test.cpp
  test/clang-move/Inputs/function_test.h
  test/clang-move/move-function.cpp

Index: test/clang-move/move-function.cpp
===
--- /dev/null
+++ test/clang-move/move-function.cpp
@@ -0,0 +1,67 @@
+// RUN: mkdir -p %T/move-function
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: cd %T/move-function
+// RUN: clang-move -names="g" -new_header=%T/move-function/new_function_test.h -old_header=../move-function/function_test.h %T/move-function/function_test.cpp --
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.h -check-prefix=CHECK-NEW-TEST-H-CASE1 %s
+//
+// CHECK-NEW-TEST-H-CASE1: #ifndef {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE1: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE1: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE1: inline int g() { return 0; }
+// CHECK-NEW-TEST-H-CASE1: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE1: #endif // {{.*}}NEW_FUNCTION_TEST_H
+//
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: clang-move -names="h" -new_header=%T/move-function/new_function_test.h -old_header=../move-function/function_test.h %T/move-function/function_test.cpp --
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.h -check-prefix=CHECK-NEW-TEST-H-CASE2 %s
+//
+// CHECK-NEW-TEST-H-CASE2: #ifndef {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE2: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE2: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE2: template  void h(T t) {}
+// CHECK-NEW-TEST-H-CASE2: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE2: template <> void h(int t) {}
+// CHECK-NEW-TEST-H-CASE2: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE2: #endif // {{.*}}NEW_FUNCTION_TEST_H
+//
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: clang-move -names="f" -new_header=%T/move-function/new_function_test.h -new_cc=%T/move-function/new_function_test.cpp -old_header=../move-function/function_test.h -old_cc=../move-function/function_test.cpp %T/move-function/function_test.cpp --
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.h -check-prefix=CHECK-NEW-TEST-H-CASE3 %s
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.cpp -check-prefix=CHECK-NEW-TEST-CPP-CASE3 %s
+//
+// CHECK-NEW-TEST-H-CASE3: #ifndef {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE3: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE3: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE3: void f();
+// CHECK-NEW-TEST-H-CASE3: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE3: #endif // {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-CPP-CASE3: #include "{{.*}}new_function_test.h"
+// CHECK-NEW-TEST-CPP-CASE3: {{[[:space:]]+}}
+// CHECK-NEW-TEST-CPP-CASE3: void f() {}
+//
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: clang-move -names="A::f" -new_header=%T/move-function/new_function_test.h -new_cc=%T/move-function/new_function_test.cpp -old_header=../move-function/function_test.h -old_cc=../move-function/function_test.cpp %T/move-function/function_test.cpp -dump_result -- | FileCheck %s -check-prefix=CHECK-EMPTY
+//
+// CHECK-EMPTY: [{{[[:space:]]*}}]
+//
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: clang-move -names="f,A" -new_header=%T/move-function/new_function_test.h -new_cc=%T/move-function/new_function_test.cpp -old_header=../move-function/function_test.h -old_cc=../move-function/function_test.cpp %T/move-function/function_test.cpp --
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.h -check-prefix=CHECK-NEW-TEST-H-CASE4 %s
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.cpp -check-prefix=CHECK-NEW-TEST-CPP-CASE4 %s
+
+// CHECK-NEW-TEST-H-CASE4: #ifndef {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE4: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE4: void f();
+// CHECK-NEW-TEST-H-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE4: class A {
+// CHECK-NEW-TEST-H-CASE4: public:
+// CHECK-NEW-TEST-H-CASE4:   void f();
+// CHECK-NEW-TEST-H-CASE4: };
+// CHECK-NEW-TEST-H-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE4: #endif // {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-CPP-CASE4: #include "{{.*}}new_function_test.h"
+// CHECK-NEW-TEST-CPP-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-CPP-CASE4: void f() {}
+// CHECK-NEW-TEST-CPP-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-CPP-CASE4: void A::f() {}
Index: test/clang-move/Inputs/function_test.h
===
--- /dev/null
+++ test/clang-move/Inputs/function_test.h
@@ -0,0 +1,14 @@
+void f();
+
+inline int g() { return 0; }
+
+template
+void h(T t) {}
+
+template<>
+void h(int t) {}
+
+class A {
+ public:
+  void f();
+};
Index: test/clang-

[clang-tools-extra] r287101 - [clang-move] Support moving function.

2016-11-16 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Nov 16 07:05:19 2016
New Revision: 287101

URL: http://llvm.org/viewvc/llvm-project?rev=287101&view=rev
Log:
[clang-move] Support moving function.

Reviewers: ioeric

Subscribers: cfe-commits

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

Added:
clang-tools-extra/trunk/test/clang-move/Inputs/function_test.cpp
clang-tools-extra/trunk/test/clang-move/Inputs/function_test.h
clang-tools-extra/trunk/test/clang-move/move-function.cpp
Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp

Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=287101&r1=287100&r2=287101&view=diff
==
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Wed Nov 16 07:05:19 2016
@@ -136,6 +136,27 @@ private:
   ClangMoveTool *const MoveTool;
 };
 
+class FunctionDeclarationMatch : public MatchFinder::MatchCallback {
+public:
+  explicit FunctionDeclarationMatch(ClangMoveTool *MoveTool)
+  : MoveTool(MoveTool) {}
+
+  void run(const MatchFinder::MatchResult &Result) override {
+const auto *FD = Result.Nodes.getNodeAs("function");
+assert(FD);
+const clang::NamedDecl *D = FD;
+if (const auto *FTD = FD->getDescribedFunctionTemplate())
+  D = FTD;
+MoveTool->getMovedDecls().emplace_back(D,
+   
&Result.Context->getSourceManager());
+MoveTool->getUnremovedDeclsInOldHeader().erase(D);
+MoveTool->getRemovedDecls().push_back(MoveTool->getMovedDecls().back());
+  }
+
+private:
+  ClangMoveTool *MoveTool;
+};
+
 class ClassDeclarationMatch : public MatchFinder::MatchCallback {
 public:
   explicit ClassDeclarationMatch(ClangMoveTool *MoveTool)
@@ -389,15 +410,15 @@ ClangMoveTool::ClangMoveTool(
 }
 
 void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
-  Optional> InMovedClassNames;
-  for (StringRef ClassName : Spec.Names) {
-llvm::StringRef GlobalClassName = ClassName.trim().ltrim(':');
-const auto HasName = hasName(("::" + GlobalClassName).str());
-InMovedClassNames =
-InMovedClassNames ? anyOf(*InMovedClassNames, HasName) : HasName;
+  Optional> HasAnySymbolNames;
+  for (StringRef SymbolName: Spec.Names) {
+llvm::StringRef GlobalSymbolName = SymbolName.trim().ltrim(':');
+const auto HasName = hasName(("::" + GlobalSymbolName).str());
+HasAnySymbolNames =
+HasAnySymbolNames ? anyOf(*HasAnySymbolNames, HasName) : HasName;
   }
-  if (!InMovedClassNames) {
-llvm::errs() << "No classes being moved.\n";
+  if (!HasAnySymbolNames) {
+llvm::errs() << "No symbols being moved.\n";
 return;
   }
 
@@ -405,7 +426,7 @@ void ClangMoveTool::registerMatchers(ast
   auto InOldCC = isExpansionInFile(makeAbsolutePath(Spec.OldCC));
   auto InOldFiles = anyOf(InOldHeader, InOldCC);
   auto InMovedClass =
-  hasOutermostEnclosingClass(cxxRecordDecl(*InMovedClassNames));
+  hasOutermostEnclosingClass(cxxRecordDecl(*HasAnySymbolNames));
 
   auto ForwardDecls =
   cxxRecordDecl(unless(anyOf(isImplicit(), isDefinition(;
@@ -466,14 +487,14 @@ void ClangMoveTool::registerMatchers(ast
   // Match moved class declarations.
   auto MovedClass =
   cxxRecordDecl(
-  InOldFiles, *InMovedClassNames, isDefinition(),
+  InOldFiles, *HasAnySymbolNames, isDefinition(),
   hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl(
   .bind("moved_class");
   Finder->addMatcher(MovedClass, MatchCallbacks.back().get());
   // Match moved class methods (static methods included) which are defined
   // outside moved class declaration.
   Finder->addMatcher(
-  cxxMethodDecl(InOldFiles, ofOutermostEnclosingClass(*InMovedClassNames),
+  cxxMethodDecl(InOldFiles, ofOutermostEnclosingClass(*HasAnySymbolNames),
 isDefinition())
   .bind("class_method"),
   MatchCallbacks.back().get());
@@ -483,6 +504,12 @@ void ClangMoveTool::registerMatchers(ast
   .bind("class_static_var_decl"),
   MatchCallbacks.back().get());
 
+  MatchCallbacks.push_back(llvm::make_unique(this));
+  Finder->addMatcher(functionDecl(InOldFiles, *HasAnySymbolNames,
+  anyOf(hasDeclContext(namespaceDecl()),
+hasDeclContext(translationUnitDecl(
+ .bind("function"),
+ MatchCallbacks.back().get());
 }
 
 void ClangMoveTool::run(const ast_matchers::MatchFinder::MatchResult &Result) {

Added: clang-tools-extra/trunk/test/clang-move/Inputs/function_test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-move/Inputs/function_test.cpp?rev=287101&view=auto
==
-

[PATCH] D26665: [clang-move] Support moving function.

2016-11-16 Thread Haojian Wu via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287101: [clang-move] Support moving function. (authored by 
hokein).

Changed prior to commit:
  https://reviews.llvm.org/D26665?vs=78171&id=78174#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26665

Files:
  clang-tools-extra/trunk/clang-move/ClangMove.cpp
  clang-tools-extra/trunk/test/clang-move/Inputs/function_test.cpp
  clang-tools-extra/trunk/test/clang-move/Inputs/function_test.h
  clang-tools-extra/trunk/test/clang-move/move-function.cpp

Index: clang-tools-extra/trunk/test/clang-move/move-function.cpp
===
--- clang-tools-extra/trunk/test/clang-move/move-function.cpp
+++ clang-tools-extra/trunk/test/clang-move/move-function.cpp
@@ -0,0 +1,67 @@
+// RUN: mkdir -p %T/move-function
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: cd %T/move-function
+// RUN: clang-move -names="g" -new_header=%T/move-function/new_function_test.h -old_header=../move-function/function_test.h %T/move-function/function_test.cpp --
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.h -check-prefix=CHECK-NEW-TEST-H-CASE1 %s
+//
+// CHECK-NEW-TEST-H-CASE1: #ifndef {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE1: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE1: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE1: inline int g() { return 0; }
+// CHECK-NEW-TEST-H-CASE1: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE1: #endif // {{.*}}NEW_FUNCTION_TEST_H
+//
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: clang-move -names="h" -new_header=%T/move-function/new_function_test.h -old_header=../move-function/function_test.h %T/move-function/function_test.cpp --
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.h -check-prefix=CHECK-NEW-TEST-H-CASE2 %s
+//
+// CHECK-NEW-TEST-H-CASE2: #ifndef {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE2: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE2: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE2: template  void h(T t) {}
+// CHECK-NEW-TEST-H-CASE2: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE2: template <> void h(int t) {}
+// CHECK-NEW-TEST-H-CASE2: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE2: #endif // {{.*}}NEW_FUNCTION_TEST_H
+//
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: clang-move -names="f" -new_header=%T/move-function/new_function_test.h -new_cc=%T/move-function/new_function_test.cpp -old_header=../move-function/function_test.h -old_cc=../move-function/function_test.cpp %T/move-function/function_test.cpp --
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.h -check-prefix=CHECK-NEW-TEST-H-CASE3 %s
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.cpp -check-prefix=CHECK-NEW-TEST-CPP-CASE3 %s
+//
+// CHECK-NEW-TEST-H-CASE3: #ifndef {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE3: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE3: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE3: void f();
+// CHECK-NEW-TEST-H-CASE3: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE3: #endif // {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-CPP-CASE3: #include "{{.*}}new_function_test.h"
+// CHECK-NEW-TEST-CPP-CASE3: {{[[:space:]]+}}
+// CHECK-NEW-TEST-CPP-CASE3: void f() {}
+//
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: clang-move -names="A::f" -new_header=%T/move-function/new_function_test.h -new_cc=%T/move-function/new_function_test.cpp -old_header=../move-function/function_test.h -old_cc=../move-function/function_test.cpp %T/move-function/function_test.cpp -dump_result -- | FileCheck %s -check-prefix=CHECK-EMPTY
+//
+// CHECK-EMPTY: [{{[[:space:]]*}}]
+//
+// RUN: cp %S/Inputs/function_test*  %T/move-function
+// RUN: clang-move -names="f,A" -new_header=%T/move-function/new_function_test.h -new_cc=%T/move-function/new_function_test.cpp -old_header=../move-function/function_test.h -old_cc=../move-function/function_test.cpp %T/move-function/function_test.cpp --
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.h -check-prefix=CHECK-NEW-TEST-H-CASE4 %s
+// RUN: FileCheck -input-file=%T/move-function/new_function_test.cpp -check-prefix=CHECK-NEW-TEST-CPP-CASE4 %s
+
+// CHECK-NEW-TEST-H-CASE4: #ifndef {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE4: #define {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-H-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE4: void f();
+// CHECK-NEW-TEST-H-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE4: class A {
+// CHECK-NEW-TEST-H-CASE4: public:
+// CHECK-NEW-TEST-H-CASE4:   void f();
+// CHECK-NEW-TEST-H-CASE4: };
+// CHECK-NEW-TEST-H-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-H-CASE4: #endif // {{.*}}NEW_FUNCTION_TEST_H
+// CHECK-NEW-TEST-CPP-CASE4: #include "{{.*}}new_function_test.h"
+// CHECK-NEW-TEST-CPP-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-TEST-CPP-CASE4: void f() {}
+// CHECK-NEW-TEST-CPP-CASE4: {{[[:space:]]+}}
+// CHECK-NEW-T

[PATCH] D26744: [clang-tidy] Fix identifier naming for initializer list member initializers.

2016-11-16 Thread Eric Fiselier via cfe-commits
EricWF created this revision.
EricWF added reviewers: alexfh, hokein, aaron.ballman.
EricWF added a subscriber: cfe-commits.

This patch adds handling for member initializers in a constructors initializer 
list. Previously we only handled base-class and delegating initializers, which 
are transformed by the `TypeLoc` matcher. For Example:

  // Style options: All identifiers should start with an upper case letter.
  struct base { ...  }; 
  struct der :  base {
int field;  // FIXES: int Field;
der() : der(42) {} // FIXES: Der() : Der(42) {}
der(int X) : base(), field(X) {} // FIXES: Der(int X) : Base(), field(X)
// Note that `field` doesn't get replaced
  };


https://reviews.llvm.org/D26744

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  test/clang-tidy/readability-identifier-naming.cpp


Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -152,15 +152,20 @@
 class my_class {
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'my_class'
 // CHECK-FIXES: {{^}}class CMyClass {{{$}}
+public:
 my_class();
 // CHECK-FIXES: {{^}}CMyClass();{{$}}
 
+my_class(void*) : my_class() {}
+// CHECK-FIXES: {{^}}CMyClass(void*) : CMyClass() {}{{$}}
+
 ~
   my_class();
 // (space in destructor token test, we could check trigraph but they will be 
deprecated)
 // CHECK-FIXES: {{^}}~{{$}}
 // CHECK-FIXES: {{^}}  CMyClass();{{$}}
 
+private:
   const int MEMBER_one_1 = ConstExpr_variable;
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for constant 
member 'MEMBER_one_1'
 // CHECK-FIXES: {{^}}  const int member_one_1 = const_expr_variable;{{$}}
@@ -211,6 +216,34 @@
 class CMyWellNamedClass {};
 // No warning expected as this class is well named.
 
+template 
+class CMyWellNamedClass2 : public my_class {
+  // CHECK-FIXES: {{^}}class CMyWellNamedClass2 : public CMyClass {{{$}}
+  t_t my_Bad_Member;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private 
member 'my_Bad_Member'
+  // CHECK-FIXES: {{^}}  t_t __my_Bad_Member;{{$}}
+  int my_Other_Bad_Member = 42;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private 
member 'my_Other_Bad_Member'
+  // CHECK-FIXES: {{^}}  int __my_Other_Bad_Member = 42;{{$}}
+public:
+  CMyWellNamedClass2() = default;
+  CMyWellNamedClass2(CMyWellNamedClass2 const&) = default;
+  CMyWellNamedClass2(CMyWellNamedClass2 &&) = default;
+  CMyWellNamedClass2(t_t a_v, void *a_p) : my_class(a_p), my_Bad_Member(a_v) {}
+  // CHECK-FIXES: {{^}}  CMyWellNamedClass2(t_t a_v, void *a_p) : 
CMyClass(a_p), __my_Bad_Member(a_v) {}{{$}}
+
+  CMyWellNamedClass2(t_t a_v) : my_class(), my_Bad_Member(a_v), 
my_Other_Bad_Member(11) {}
+  // CHECK-FIXES: {{^}}  CMyWellNamedClass2(t_t a_v) : CMyClass(), 
__my_Bad_Member(a_v), __my_Other_Bad_Member(11) {}{{$}}
+};
+void InstantiateClassMethods() {
+  // Ensure we trigger the instantiation of each constructor
+  CMyWellNamedClass2 x;
+  CMyWellNamedClass2 x2 = x;
+  CMyWellNamedClass2 x3 = static_cast&&>(x2);
+  CMyWellNamedClass2 x4(42);
+  CMyWellNamedClass2 x5(42, nullptr);
+}
+
 template
 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for type 
template parameter 'T'
 // CHECK-FIXES: {{^}}template{{$}}
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -677,6 +677,15 @@
 
 addUsage(NamingCheckFailures, Decl->getParent(),
  Decl->getNameInfo().getSourceRange());
+
+for (auto Init : Decl->inits()) {
+  if (!Init->isWritten() || Init->isInClassMemberInitializer())
+continue;
+  if (const auto *FD = Init->getAnyMember())
+addUsage(NamingCheckFailures, FD, 
SourceRange(Init->getMemberLocation()));
+  // Note: delegating constructors and base class initializers are handled
+  // via the "typeLoc" matcher.
+}
 return;
   }
 


Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -152,15 +152,20 @@
 class my_class {
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_class'
 // CHECK-FIXES: {{^}}class CMyClass {{{$}}
+public:
 my_class();
 // CHECK-FIXES: {{^}}CMyClass();{{$}}
 
+my_class(void*) : my_class() {}
+// CHECK-FIXES: {{^}}CMyClass(void*) : CMyClass() {}{{$}}
+
 ~
   my_class();
 // (space in destructor token test, we could check trigraph but they will be deprecated)
 // CHECK-FIXES: {{^}}~{{$}}
 // CHECK-FIXES: {{^}}  CMyClass();{{$}}
 
+private:
  

r287102 - Rangify for loop, NFC.

2016-11-16 Thread Yaron Keren via cfe-commits
Author: yrnkrn
Date: Wed Nov 16 07:45:34 2016
New Revision: 287102

URL: http://llvm.org/viewvc/llvm-project?rev=287102&view=rev
Log:
Rangify for loop, NFC.


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

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=287102&r1=287101&r2=287102&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Nov 16 07:45:34 2016
@@ -2990,12 +2990,10 @@ Sema::CheckVarTemplateId(VarTemplateDecl
 << Decl;
 
 // Print the matching partial specializations.
-for (SmallVector::iterator P = Matched.begin(),
-   PEnd = Matched.end();
- P != PEnd; ++P)
-  Diag(P->Partial->getLocation(), diag::note_partial_spec_match)
-  << getTemplateArgumentBindingsText(
- P->Partial->getTemplateParameters(), *P->Args);
+for (MatchResult P : Matched)
+  Diag(P.Partial->getLocation(), diag::note_partial_spec_match)
+  << 
getTemplateArgumentBindingsText(P.Partial->getTemplateParameters(),
+ *P.Args);
 return true;
   }
 


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


[PATCH] D26735: [OpenCL] Disable && (address of label) GNU extension for OpenCL

2016-11-16 Thread Egor Churaev via cfe-commits
echuraev created this revision.
echuraev added a reviewer: cfe-commits.
Herald added a subscriber: yaxunl.

Patch by Guy Benyei


https://reviews.llvm.org/D26735

Files:
  include/clang/Basic/DiagnosticParseKinds.td
  lib/Parse/ParseExpr.cpp
  test/SemaOpenCL/ampamp-gnu.cl


Index: test/SemaOpenCL/ampamp-gnu.cl
===
--- /dev/null
+++ test/SemaOpenCL/ampamp-gnu.cl
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+kernel void foo(global int *in) {
+  int a;
+  void *p = &&a; // expected-error {{OpenCL does not support address of label 
('&&') GNU extension}}
+
+  void *hlbl_tbl[] = { &&label1 }; // expected-error {{OpenCL does not support 
address of label ('&&') GNU extension}}
+label1:
+  a = 0;
+}
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1104,6 +1104,9 @@
 if (Tok.isNot(tok::identifier))
   return ExprError(Diag(Tok, diag::err_expected) << tok::identifier);
 
+if (getLangOpts().OpenCL)
+  return ExprError(Diag(Tok, diag::err_opencl_address_of_label));
+
 if (getCurScope()->getFnParent() == nullptr)
   return ExprError(Diag(Tok, diag::err_address_of_label_outside_fn));
 
Index: include/clang/Basic/DiagnosticParseKinds.td
===
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -972,6 +972,8 @@
   "OpenCL extension %0 is core feature or supported optional core feature - 
ignoring">, InGroup>, DefaultIgnore;
 
 // OpenCL errors.
+def err_opencl_address_of_label : Error<
+  "OpenCL does not support address of label ('&&') GNU extension">;
 def err_opencl_taking_function_address_parser : Error<
   "taking address of function is not allowed">;
 def err_opencl_logical_exclusive_or : Error<


Index: test/SemaOpenCL/ampamp-gnu.cl
===
--- /dev/null
+++ test/SemaOpenCL/ampamp-gnu.cl
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+kernel void foo(global int *in) {
+  int a;
+  void *p = &&a; // expected-error {{OpenCL does not support address of label ('&&') GNU extension}}
+
+  void *hlbl_tbl[] = { &&label1 }; // expected-error {{OpenCL does not support address of label ('&&') GNU extension}}
+label1:
+  a = 0;
+}
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1104,6 +1104,9 @@
 if (Tok.isNot(tok::identifier))
   return ExprError(Diag(Tok, diag::err_expected) << tok::identifier);
 
+if (getLangOpts().OpenCL)
+  return ExprError(Diag(Tok, diag::err_opencl_address_of_label));
+
 if (getCurScope()->getFnParent() == nullptr)
   return ExprError(Diag(Tok, diag::err_address_of_label_outside_fn));
 
Index: include/clang/Basic/DiagnosticParseKinds.td
===
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -972,6 +972,8 @@
   "OpenCL extension %0 is core feature or supported optional core feature - ignoring">, InGroup>, DefaultIgnore;
 
 // OpenCL errors.
+def err_opencl_address_of_label : Error<
+  "OpenCL does not support address of label ('&&') GNU extension">;
 def err_opencl_taking_function_address_parser : Error<
   "taking address of function is not allowed">;
 def err_opencl_logical_exclusive_or : Error<
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26745: [Frontend] Allow attaching an external sema source to compiler instance and extra diags to TypoCorrections

2016-11-16 Thread Benjamin Kramer via cfe-commits
bkramer created this revision.
bkramer added a reviewer: klimek.
bkramer added a subscriber: cfe-commits.

This can be used to append alternative typo corrections to an existing diag.
include-fixer can use it to suggest includes to be added.


https://reviews.llvm.org/D26745

Files:
  include/clang/Frontend/CompilerInstance.h
  include/clang/Sema/TypoCorrection.h
  lib/Sema/SemaLookup.cpp
  unittests/Frontend/FrontendActionTest.cpp

Index: unittests/Frontend/FrontendActionTest.cpp
===
--- unittests/Frontend/FrontendActionTest.cpp
+++ unittests/Frontend/FrontendActionTest.cpp
@@ -13,6 +13,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Sema/Sema.h"
@@ -192,4 +193,66 @@
   ASSERT_TRUE(TestAction.SeenEnd);
 }
 
+class TypoExternalSemaSource : public ExternalSemaSource {
+  CompilerInstance &CI;
+
+public:
+  TypoExternalSemaSource(CompilerInstance &CI) : CI(CI) {}
+
+  TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, int LookupKind,
+ Scope *S, CXXScopeSpec *SS,
+ CorrectionCandidateCallback &CCC,
+ DeclContext *MemberContext, bool EnteringContext,
+ const ObjCObjectPointerType *OPT) override {
+// Generate a fake typo correction with one attached note.
+ASTContext &Ctx = CI.getASTContext();
+TypoCorrection TC(DeclarationName(&Ctx.Idents.get("moo")));
+unsigned DiagID = Ctx.getDiagnostics().getCustomDiagID(
+DiagnosticsEngine::Note, "This is a note");
+TC.addExtraDiagnostic(PartialDiagnostic(DiagID, Ctx.getDiagAllocator()));
+return TC;
+  }
+};
+
+struct TypoDiagnosticConsumer : public DiagnosticConsumer {
+  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+const Diagnostic &Info) override {
+// Capture errors and notes. There should be one of each.
+if (DiagLevel == DiagnosticsEngine::Error) {
+  assert(Error.empty());
+  Info.FormatDiagnostic(Error);
+} else {
+  assert(Note.empty());
+  Info.FormatDiagnostic(Note);
+}
+  }
+  SmallString<32> Error;
+  SmallString<32> Note;
+};
+
+TEST(ASTFrontendAction, ExternalSemaSource) {
+  auto *Invocation = new CompilerInvocation;
+  Invocation->getLangOpts()->CPlusPlus = true;
+  Invocation->getPreprocessorOpts().addRemappedFile(
+  "test.cc", MemoryBuffer::getMemBuffer("void fooo();\n"
+"int main() { foo(); }")
+ .release());
+  Invocation->getFrontendOpts().Inputs.push_back(
+  FrontendInputFile("test.cc", IK_CXX));
+  Invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly;
+  Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu";
+  CompilerInstance Compiler;
+  Compiler.setInvocation(Invocation);
+  auto *TDC = new TypoDiagnosticConsumer;
+  Compiler.createDiagnostics(TDC, /*ShouldOwnClient=*/true);
+  Compiler.setExternalSemaSource(new TypoExternalSemaSource(Compiler));
+
+  SyntaxOnlyAction TestAction;
+  ASSERT_TRUE(Compiler.ExecuteAction(TestAction));
+  // There should be one error correcting to 'moo' and a note attached to it.
+  EXPECT_EQ("use of undeclared identifier 'foo'; did you mean 'moo'?",
+TDC->Error.str().str());
+  EXPECT_EQ("This is a note", TDC->Note.str().str());
+}
+
 } // anonymous namespace
Index: lib/Sema/SemaLookup.cpp
===
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -5082,6 +5082,10 @@
   if (PrevNote.getDiagID() && ChosenDecl)
 Diag(ChosenDecl->getLocation(), PrevNote)
   << CorrectedQuotedStr << (ErrorRecovery ? FixItHint() : FixTypo);
+
+  // Add any extra diagnostics.
+  for (const PartialDiagnostic &PD : Correction.getExtraDiagnostics())
+Diag(Correction.getCorrectionRange().getBegin(), PD);
 }
 
 TypoExpr *Sema::createDelayedTypo(std::unique_ptr TCC,
Index: include/clang/Sema/TypoCorrection.h
===
--- include/clang/Sema/TypoCorrection.h
+++ include/clang/Sema/TypoCorrection.h
@@ -230,6 +230,15 @@
   bool requiresImport() const { return RequiresImport; }
   void setRequiresImport(bool Req) { RequiresImport = Req; }
 
+  /// Extra diagnostics are printed after the first diagnostic for the typo.
+  /// This can be used to attach external notes to the diag.
+  void addExtraDiagnostic(PartialDiagnostic PD) {
+ExtraDiagnostics.push_back(std::move(PD));
+  }
+  ArrayRef getExtraDiagnostics() const {
+return ExtraDiagnostics;
+  }
+
 private:
   bool hasCorrectionDecl() const {
 return (!isKeyword() && !CorrectionDecls.empty());
@@ -245,6 +254,8 @@
   Sour

[PATCH] D26637: [change-namespace] handle constructor initializer: Derived : Base::Base() {} and added conflict detections

2016-11-16 Thread Eric Liu via cfe-commits
ioeric updated this revision to Diff 78180.
ioeric added a comment.

- Minor fix


https://reviews.llvm.org/D26637

Files:
  change-namespace/ChangeNamespace.cpp
  change-namespace/ChangeNamespace.h
  test/change-namespace/lambda-function.cpp
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -43,8 +43,9 @@
 NamespaceTool.registerMatchers(&Finder);
 std::unique_ptr Factory =
 tooling::newFrontendActionFactory(&Finder);
-tooling::runToolOnCodeWithArgs(Factory->create(), Code, {"-std=c++11"},
-   FileName);
+if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, {"-std=c++11"},
+   FileName))
+  return "";
 formatAndApplyAllReplacements(FileToReplacements, Context.Rewrite);
 return format(Context.getRewrittenText(ID));
   }
@@ -330,19 +331,6 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
-TEST_F(ChangeNamespaceTest, DoNotCrashWithLambdaAsParameter) {
-  std::string Code =
-  "#include \n"
-  "void f(std::function func, int param) { func(param); } "
-  "void g() { f([](int x) {}, 1); }";
-
-  std::string Expected =
-  "#include \n"
-  "void f(std::function func, int param) { func(param); } "
-  "void g() { f([](int x) {}, 1); }";
-  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
-}
-
 TEST_F(ChangeNamespaceTest, FixUsingShadowDecl) {
   std::string Code = "class GLOB {};\n"
  "using BLOG = GLOB;\n"
@@ -510,8 +498,8 @@
  "public:\n"
  "static int A1;\n"
  "static int A2;\n"
- "}\n"
- "static int A::A1 = 0;\n"
+ "};\n"
+ "int A::A1 = 0;\n"
  "namespace nb {\n"
  "void f() { int a = A::A1; int b = A::A2; }"
  "} // namespace nb\n"
@@ -522,8 +510,8 @@
  "public:\n"
  "static int A1;\n"
  "static int A2;\n"
- "}\n"
- "static int A::A1 = 0;\n"
+ "};\n"
+ "int A::A1 = 0;\n"
  "\n"
  "} // namespace na\n"
  "namespace x {\n"
@@ -1005,6 +993,93 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, DerivedClassWithConstructors) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) {}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "\n\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) {}\n"
+  "} // namespace y\n"
+  "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, DerivedClassWithQualifiedConstructors) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X::X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X::X(i) {}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "\n\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X::X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X::X(i) {}\n"
+  "} // namespace y\n"
+  "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, DerivedClassWithConstructorsAndTypeRefs) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) { X x(1);}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "namespace nx { namespace ny { c

[PATCH] D23130: [Clang-tidy] Add a check for definitions in the global namespace.

2016-11-16 Thread Benjamin Kramer via cfe-commits
bkramer marked 2 inline comments as done.
bkramer added inline comments.



Comment at: test/clang-tidy/google-global-names.cpp:13-14
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'i' declared in the global 
namespace
+extern int ii = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'ii' declared in the global 
namespace
+

aaron.ballman wrote:
> bkramer wrote:
> > aaron.ballman wrote:
> > > aaron.ballman wrote:
> > > > bkramer wrote:
> > > > > aaron.ballman wrote:
> > > > > > This strikes me as being intentional enough to warrant not 
> > > > > > diagnosing because of the `extern` keyword.
> > > > > The only case I see where this pattern is valuable is interfacing 
> > > > > with C code. Not sure yet if we want to allow that or enforce extern 
> > > > > "C" instead. Ideas?
> > > > > 
> > > > > an extern global in the global namespace still feels like something 
> > > > > we should warn on :|
> > > > Yet externs in the global namespace do happen for valid reasons (such 
> > > > as not breaking ABIs by putting the extern definition into a namespace 
> > > > or changing the language linkage) -- I'm trying to think of ways we can 
> > > > allow the user to silence this diagnostic in those cases. I feel like 
> > > > in cases where the user writes "extern", they're explicitly specifying 
> > > > their intent and that doesn't seem like a case to warn them about, in 
> > > > some regards. It would give us two ways to silence the diagnostic 
> > > > (well, three, but two are morally close enough):
> > > > 
> > > > 1) Put it into a namespace
> > > > 2) Slap `extern` on it if it is global for C++ compatibility (such as 
> > > > ABIs)
> > > > 3) Slap `extern "C"` on it if it global for C compatibility
> > > > 
> > > > I suppose we could require `extern "C++"` instead of `extern`, but I 
> > > > don't think that's a particularly common use of the language linkage 
> > > > specifier?
> > > I still think that a user explicitly writing 'extern' is expecting 
> > > external linkage and all that goes along with it.
> > I disagree. If this is a special variable to be accessed via dlopen it 
> > should be extern "C". If not it should be in a namespace.
> I'm thinking more that it's not a special variable to be accessed via dlopen, 
> but instead is a special implementation detail that doesn't need to be 
> exposed via a header file. For instance, see ClangTidyMain.cpp. Such uses 
> have no way to silence this check, which may be fine since it's in the Google 
> module. I merely wanted to point it out because it does happen for valid 
> reasons, and having a way to silence a diagnostic aside from NOLINT is nice.
That's an example of something that should be in a namespace. Currently it's 
polluting the global namespace which will break anyone who happens to use the 
same name for a symbol anywhere else. I think that flagging those cases is 
useful.


https://reviews.llvm.org/D23130



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


[PATCH] D26637: [change-namespace] handle constructor initializer: Derived : Base::Base() {} and added conflict detections

2016-11-16 Thread Haojian Wu via cfe-commits
hokein added inline comments.



Comment at: change-namespace/ChangeNamespace.cpp:346
+ hasDeclaration(DeclMatcher.bind("from_decl"),
+ 
unless(hasAncestor(typeLoc(loc(qualType(hasDeclaration(
+ decl(equalsBoundNode("from_decl")

Maybe pull this `unless` matcher out and name it to make code more 
understandable.



Comment at: change-namespace/ChangeNamespace.cpp:650
+  // Types of CXXCtorInitializers do not need to be fixed.
+  for (const auto &T : BaseCtorInitializerTypeLocs)
+if (Type == T)

use `std::find`?



Comment at: test/change-namespace/lambda-function.cpp:2
+// RUN: clang-change-namespace -old_namespace "na::nb" -new_namespace "x::y" 
--file_pattern ".*" %s -- -std=c++11 | sed 's,// CHECK.*,,' | FileCheck %s
+#include 
+// CHECK: namespace x {

In practise, we don't use std headers directly in llvm lit test. You need to 
mock it by yourself...



Comment at: unittests/change-namespace/ChangeNamespaceTests.cpp:47
+if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, 
{"-std=c++11"},
+   FileName))
+  return "";

nit: code indentation.


https://reviews.llvm.org/D26637



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


[PATCH] D26637: [change-namespace] handle constructor initializer: Derived : Base::Base() {} and added conflict detections

2016-11-16 Thread Benjamin Kramer via cfe-commits
bkramer added inline comments.



Comment at: change-namespace/ChangeNamespace.cpp:546
+ << llvm::toString(std::move(Err)) << "\n";
+assert(false);
+  }

So is this an error or not? If you can hit this by using the tool it should 
bail out here. If not use llvm_unreachable instead of assert(false).



Comment at: change-namespace/ChangeNamespace.cpp:637
+ << llvm::toString(std::move(Err)) << "\n";
+assert(false);
+  }

same here.



Comment at: change-namespace/ChangeNamespace.cpp:650
+  // Types of CXXCtorInitializers do not need to be fixed.
+  for (const auto &T : BaseCtorInitializerTypeLocs)
+if (Type == T)

llvm::is_contained



Comment at: change-namespace/ChangeNamespace.cpp:707
+ << llvm::toString(std::move(Err)) << "\n";
+assert(false);
+  }

same here.



Comment at: test/change-namespace/lambda-function.cpp:2
+// RUN: clang-change-namespace -old_namespace "na::nb" -new_namespace "x::y" 
--file_pattern ".*" %s -- -std=c++11 | sed 's,// CHECK.*,,' | FileCheck %s
+#include 
+// CHECK: namespace x {

You cannot rely on an STL implementation being around in a test. Unless we have 
a fake  lying around this will fail in some environments. (I know 
this has been around for a while, just bringing it up now)


https://reviews.llvm.org/D26637



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


[PATCH] D26745: [Frontend] Allow attaching an external sema source to compiler instance and extra diags to TypoCorrections

2016-11-16 Thread Manuel Klimek via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D26745



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


[PATCH] D26746: [OpenCL] Split PipeType into ReadPipe/WritePipe

2016-11-16 Thread Joey Gouly via cfe-commits
joey created this revision.
joey added a subscriber: cfe-commits.
joey set the repository for this revision to rL LLVM.
Herald added a subscriber: yaxunl.

Split the PipeType into two derived classes. This allows Sema to diagnose 
passing read_only to write_only and vice versa.


Repository:
  rL LLVM

https://reviews.llvm.org/D26746

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/TypePrinter.cpp
  lib/Sema/SemaType.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/Misc/ast-dump-pipe.cl
  test/SemaOpenCL/access-qualifier.cl
  test/SemaOpenCL/invalid-pipes-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -7,16 +7,16 @@
 void test3(int pipe p) {// expected-error {{cannot combine with previous 'int' declaration specifier}}
 }
 void test4() {
-  pipe int p; // expected-error {{type 'pipe int' can only be used as a function parameter}}
+  pipe int p; // expected-error {{type 'read_only pipe int' can only be used as a function parameter}}
   //TODO: fix parsing of this pipe int (*p);
 }
 
 void test5(pipe int p) {
-  p+p; // expected-error{{invalid operands to binary expression ('pipe int' and 'pipe int')}}
-  p=p; // expected-error{{invalid operands to binary expression ('pipe int' and 'pipe int')}}
-  &p; // expected-error{{invalid argument type 'pipe int' to unary expression}}
-  *p; // expected-error{{invalid argument type 'pipe int' to unary expression}}
+  p+p; // expected-error{{invalid operands to binary expression ('read_only pipe int' and 'read_only pipe int')}}
+  p=p; // expected-error{{invalid operands to binary expression ('read_only pipe int' and 'read_only pipe int')}}
+  &p; // expected-error{{invalid argument type 'read_only pipe int' to unary expression}}
+  *p; // expected-error{{invalid argument type 'read_only pipe int' to unary expression}}
 }
 
 typedef pipe int pipe_int_t;
-pipe_int_t test6() {} // expected-error{{declaring function return value of type 'pipe_int_t' (aka 'pipe int') is not allowed}}
+pipe_int_t test6() {} // expected-error{{declaring function return value of type 'pipe_int_t' (aka 'read_only pipe int') is not allowed}}
Index: test/SemaOpenCL/access-qualifier.cl
===
--- test/SemaOpenCL/access-qualifier.cl
+++ test/SemaOpenCL/access-qualifier.cl
@@ -63,7 +63,14 @@
 kernel void k12(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
 
 #if __OPENCL_C_VERSION__ >= 200
-kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe int'}}
+kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'read_only pipe int'}}
 #else
 kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' prior to OpenCL version 2.0}}
 #endif
+
+#if __OPENCL_C_VERSION__ >= 200
+void myPipeWrite(write_only pipe int); // expected-note {{passing argument to parameter here}}
+kernel void k14(read_only pipe int p) {
+  myPipeWrite(p); // expected-error {{passing 'read_only pipe int' to parameter of incompatible type 'write_only pipe int'}}
+}
+#endif
Index: test/Misc/ast-dump-pipe.cl
===
--- test/Misc/ast-dump-pipe.cl
+++ test/Misc/ast-dump-pipe.cl
@@ -1,4 +1,12 @@
 // RUN: %clang_cc1 -triple spir64 -cl-std=CL2.0 -ast-dump -ast-dump-filter pipetype %s | FileCheck -strict-whitespace %s
 typedef pipe int pipetype;
-// CHECK:  PipeType {{.*}} 'pipe int'
+// CHECK:  PipeType {{.*}} 'read_only pipe int'
+// CHECK-NEXT:   BuiltinType {{.*}} 'int'
+
+typedef read_only pipe int pipetype2;
+// CHECK:  PipeType {{.*}} 'read_only pipe int'
+// CHECK-NEXT:   BuiltinType {{.*}} 'int'
+
+typedef write_only pipe int pipetype3;
+// CHECK:  PipeType {{.*}} 'write_only pipe int'
 // CHECK-NEXT:   BuiltinType {{.*}} 'int'
Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -516,7 +516,10 @@
 void
 ASTTypeWriter::VisitPipeType(const PipeType *T) {
   Record.AddTypeRef(T->getElementType());
-  Code = TYPE_PIPE;
+  if (T->isReadOnly())
+Code = TYPE_READ_PIPE;
+  else
+Code = TYPE_WRITE_PIPE;
 }
 
 namespace {
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -5794,15 +5794,25 @@
 return Context.getAtomicType(ValueType);
   }
 
-  case TYPE_PIPE: {
+  case TYPE

r287105 - [www] Fix spelling error in checker release notes.

2016-11-16 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Wed Nov 16 08:23:41 2016
New Revision: 287105

URL: http://llvm.org/viewvc/llvm-project?rev=287105&view=rev
Log:
[www] Fix spelling error in checker release notes.

Modified:
cfe/trunk/www/analyzer/release_notes.html

Modified: cfe/trunk/www/analyzer/release_notes.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/release_notes.html?rev=287105&r1=287104&r2=287105&view=diff
==
--- cfe/trunk/www/analyzer/release_notes.html (original)
+++ cfe/trunk/www/analyzer/release_notes.html Wed Nov 16 08:23:41 2016
@@ -22,7 +22,7 @@
 The analyzer includes new checks for:
   
 Improper instance cleanup up in Objective-C -dealloc methods under 
manual retain/release.
-Inadvertant comparisons of NSNumber, CFNumberRef, and other number 
object pointers against scalar values.
+Inadvertent comparisons of NSNumber, CFNumberRef, and other number 
object pointers against scalar values.
 Unsafe usage of dispatch_once_t predicates stored in Objective-C 
instance variables and other heap-allocated memory.
 Issues resulting from self-assignment in C++.
 Incorrect usage of MPI APIs in C and C++. This check can be 
enabled by passing the following command to scan-build: 


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


[PATCH] D23130: [Clang-tidy] Add a check for definitions in the global namespace.

2016-11-16 Thread Aaron Ballman via cfe-commits
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added inline comments.



Comment at: clang-tidy/google/GlobalNamesCheck.cpp:62
+Result.SourceManager->getExpansionLoc(D->getLocStart( {
+  // unless that file is a header.
+  if (!utils::isSpellingLocInHeaderFile(

s/unless/Unless



Comment at: clang-tidy/google/GlobalNamesCheck.cpp:84
+  // Ignore decls with internal linkage.
+  if (!D->isExternallyVisible())
+return;

I wonder if this check would have better performance by making this a local AST 
matcher instead? UsingDecl and UsingDirectiveDecl do not have linkage, so it 
may require adjusting the matcher somewhat.



Comment at: clang-tidy/google/GlobalNamesCheck.cpp:96
+// main() should be in the global namespace.
+if (FDecl->isMain())
+  return;

malcolm.parsons wrote:
> Should `isMSVCRTEntryPoint()` be checked too?
Yes, it should.



Comment at: clang-tidy/google/GoogleTidyModule.cpp:68
+CheckFactories.registerCheck(
+"google-global-names");
 CheckFactories.registerCheck(

Given that this was shipped under the old name, I think we need to figure out 
our policy for how to handle this. It also comes up in D26511, so I would like 
us to be consistent with what we do.



Comment at: test/clang-tidy/google-global-names.cpp:13-14
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'i' declared in the global 
namespace
+extern int ii = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: 'ii' declared in the global 
namespace
+

bkramer wrote:
> aaron.ballman wrote:
> > bkramer wrote:
> > > aaron.ballman wrote:
> > > > aaron.ballman wrote:
> > > > > bkramer wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > This strikes me as being intentional enough to warrant not 
> > > > > > > diagnosing because of the `extern` keyword.
> > > > > > The only case I see where this pattern is valuable is interfacing 
> > > > > > with C code. Not sure yet if we want to allow that or enforce 
> > > > > > extern "C" instead. Ideas?
> > > > > > 
> > > > > > an extern global in the global namespace still feels like something 
> > > > > > we should warn on :|
> > > > > Yet externs in the global namespace do happen for valid reasons (such 
> > > > > as not breaking ABIs by putting the extern definition into a 
> > > > > namespace or changing the language linkage) -- I'm trying to think of 
> > > > > ways we can allow the user to silence this diagnostic in those cases. 
> > > > > I feel like in cases where the user writes "extern", they're 
> > > > > explicitly specifying their intent and that doesn't seem like a case 
> > > > > to warn them about, in some regards. It would give us two ways to 
> > > > > silence the diagnostic (well, three, but two are morally close 
> > > > > enough):
> > > > > 
> > > > > 1) Put it into a namespace
> > > > > 2) Slap `extern` on it if it is global for C++ compatibility (such as 
> > > > > ABIs)
> > > > > 3) Slap `extern "C"` on it if it global for C compatibility
> > > > > 
> > > > > I suppose we could require `extern "C++"` instead of `extern`, but I 
> > > > > don't think that's a particularly common use of the language linkage 
> > > > > specifier?
> > > > I still think that a user explicitly writing 'extern' is expecting 
> > > > external linkage and all that goes along with it.
> > > I disagree. If this is a special variable to be accessed via dlopen it 
> > > should be extern "C". If not it should be in a namespace.
> > I'm thinking more that it's not a special variable to be accessed via 
> > dlopen, but instead is a special implementation detail that doesn't need to 
> > be exposed via a header file. For instance, see ClangTidyMain.cpp. Such 
> > uses have no way to silence this check, which may be fine since it's in the 
> > Google module. I merely wanted to point it out because it does happen for 
> > valid reasons, and having a way to silence a diagnostic aside from NOLINT 
> > is nice.
> That's an example of something that should be in a namespace. Currently it's 
> polluting the global namespace which will break anyone who happens to use the 
> same name for a symbol anywhere else. I think that flagging those cases is 
> useful.
Okay, that's fair. I was thinking that since it was in the global namespace, it 
was there for a reason. After looking a bit more closely, I think you're 
correct, this would be a true-positive. You've convinced me and I retract my 
concerns. :-)


https://reviews.llvm.org/D23130



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


[PATCH] D26637: [change-namespace] handle constructor initializer: Derived : Base::Base() {} and added conflict detections

2016-11-16 Thread Eric Liu via cfe-commits
ioeric updated this revision to Diff 78183.
ioeric marked 8 inline comments as done.
ioeric added a comment.

- Addressed comments.


https://reviews.llvm.org/D26637

Files:
  change-namespace/ChangeNamespace.cpp
  change-namespace/ChangeNamespace.h
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -43,8 +43,9 @@
 NamespaceTool.registerMatchers(&Finder);
 std::unique_ptr Factory =
 tooling::newFrontendActionFactory(&Finder);
-tooling::runToolOnCodeWithArgs(Factory->create(), Code, {"-std=c++11"},
-   FileName);
+if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, {"-std=c++11"},
+FileName))
+  return "";
 formatAndApplyAllReplacements(FileToReplacements, Context.Rewrite);
 return format(Context.getRewrittenText(ID));
   }
@@ -330,19 +331,6 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
-TEST_F(ChangeNamespaceTest, DoNotCrashWithLambdaAsParameter) {
-  std::string Code =
-  "#include \n"
-  "void f(std::function func, int param) { func(param); } "
-  "void g() { f([](int x) {}, 1); }";
-
-  std::string Expected =
-  "#include \n"
-  "void f(std::function func, int param) { func(param); } "
-  "void g() { f([](int x) {}, 1); }";
-  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
-}
-
 TEST_F(ChangeNamespaceTest, FixUsingShadowDecl) {
   std::string Code = "class GLOB {};\n"
  "using BLOG = GLOB;\n"
@@ -510,8 +498,8 @@
  "public:\n"
  "static int A1;\n"
  "static int A2;\n"
- "}\n"
- "static int A::A1 = 0;\n"
+ "};\n"
+ "int A::A1 = 0;\n"
  "namespace nb {\n"
  "void f() { int a = A::A1; int b = A::A2; }"
  "} // namespace nb\n"
@@ -522,8 +510,8 @@
  "public:\n"
  "static int A1;\n"
  "static int A2;\n"
- "}\n"
- "static int A::A1 = 0;\n"
+ "};\n"
+ "int A::A1 = 0;\n"
  "\n"
  "} // namespace na\n"
  "namespace x {\n"
@@ -1005,6 +993,93 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, DerivedClassWithConstructors) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) {}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "\n\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) {}\n"
+  "} // namespace y\n"
+  "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, DerivedClassWithQualifiedConstructors) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X::X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X::X(i) {}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "\n\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X::X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X::X(i) {}\n"
+  "} // namespace y\n"
+  "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, DerivedClassWithConstructorsAndTypeRefs) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) { X x(1);}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "namespace nx { name

[clang-tools-extra] r287107 - [clang-tidy] New check to prefer transparent functors to non-transparent ones.

2016-11-16 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Wed Nov 16 08:42:10 2016
New Revision: 287107

URL: http://llvm.org/viewvc/llvm-project?rev=287107&view=rev
Log:
[clang-tidy] New check to prefer transparent functors to non-transparent ones.

Added:
clang-tools-extra/trunk/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseTransparentFunctorsCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-transparent-functors.rst

clang-tools-extra/trunk/test/clang-tidy/modernize-use-transparent-functors.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt?rev=287107&r1=287106&r2=287107&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt Wed Nov 16 
08:42:10 2016
@@ -21,6 +21,7 @@ add_clang_library(clangTidyModernizeModu
   UseEqualsDeleteCheck.cpp
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
+  UseTransparentFunctorsCheck.cpp
   UseUsingCheck.cpp
 
   LINK_LIBS

Modified: clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp?rev=287107&r1=287106&r2=287107&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp Wed 
Nov 16 08:42:10 2016
@@ -27,6 +27,7 @@
 #include "UseEqualsDeleteCheck.h"
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
+#include "UseTransparentFunctorsCheck.h"
 #include "UseUsingCheck.h"
 
 using namespace clang::ast_matchers;
@@ -61,6 +62,8 @@ public:
 "modernize-use-equals-delete");
 CheckFactories.registerCheck("modernize-use-nullptr");
 CheckFactories.registerCheck("modernize-use-override");
+CheckFactories.registerCheck(
+"modernize-use-transparent-functors");
 CheckFactories.registerCheck("modernize-use-using");
   }
 

Added: 
clang-tools-extra/trunk/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp?rev=287107&view=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp 
(added)
+++ 
clang-tools-extra/trunk/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp 
Wed Nov 16 08:42:10 2016
@@ -0,0 +1,131 @@
+//===--- UseTransparentFunctorsCheck.cpp - 
clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "UseTransparentFunctorsCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+UseTransparentFunctorsCheck::UseTransparentFunctorsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), SafeMode(Options.get("SafeMode", 0)) {}
+
+void UseTransparentFunctorsCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "SafeMode", SafeMode ? 1 : 0);
+}
+
+void UseTransparentFunctorsCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus14)
+return;
+
+  const auto TransparentFunctors =
+  classTemplateSpecializationDecl(
+  unless(hasAnyTemplateArgument(refersToType(voidType(,
+  hasAnyName("::std::plus", "::std::minus", "::std::multiplies",
+ "::std::divides", "::std::modulus", "::std::negate",
+ "::std::equal_to", "::std::not_equal_to", 
"::std::greater",
+ "::std::less", "::std::greater_equal", 
"::std::less_equal",
+ "::std::logical_and", "::std::logical_or",
+ "::std::logical_not", "::std::bit_and", "::std::bit_or",
+ "::std::bit_xor", "::std::bit_not"))
+  .bind("FunctorClass");
+
+  // Non-transparent functor mentioned as a template parameter. FIXIT.
+  Finder->addMatcher(
+  loc(qualType(
+  unless(elaboratedType()),
+  hasDeclaration(classTemplateSpecia

[PATCH] D24894: [clang-tidy] Prefer transparent functors to non-transparent one.

2016-11-16 Thread Gábor Horváth via cfe-commits
xazax.hun closed this revision.
xazax.hun marked 2 inline comments as done.
xazax.hun added a comment.

Thanks for the reviews, committed in https://reviews.llvm.org/rL287107 .


https://reviews.llvm.org/D24894



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


[PATCH] D26544: [PPC] support for arithmetic builtins in the FE

2016-11-16 Thread Ehsan Amiri via cfe-commits
amehsan added inline comments.



Comment at: lib/Headers/altivec.h:350
+__tempc = __tempc & 0x0001;
+unsigned long long __longa = (unsigned long long) __tempa;
+unsigned long long __longb = (unsigned long long) __tempb;

kbarton wrote:
> nemanjai wrote:
> > I think it's a little more clear and obvious what is happening if you 
> > actually have just a single cast and mask - i.e.
> > ``` unsigned long long __longa = ((unsigned long long) __a[i]) & 
> > 0x;```
> Is a mask actually needed? This seems to be what is done in the vec_addec 
> function below, without the cast. I agree that is cleaner.
> 
> The other minor nit is to pick a single value for the mask (1, 0x01, 
> 0x0001) and use it consistently. 
To come up with this code pattern I looked at the following pieces of codes:


```
unsigned long long f (int t) {
  return (unsigned long long)  t;
}
```
When compiled with optimization  produces 

```
define i64 @f(i32 signext %t) local_unnamed_addr #0 {
entry:
  %conv = sext i32 %t to i64
  ret i64 %conv
}

```
Which is incorrect. Also 


```
unsigned long long f (int t) {
  return (unsigned long long)(unsigned)  t;
}
~

```

results in 

```
define i64 @f(i32 signext %t) local_unnamed_addr #0 {
entry:
  %conv = zext i32 %t to i64
  ret i64 %conv
}

```

and 


```
.Lfunc_begin0:
# BB#0: # %entry
clrldi   3, 3, 32
blr

```

So I think the code here is optimal and correct and there is no need to change 
it.



Comment at: lib/Headers/altivec.h:10516
+ vector signed __int128 __c) {
+  return __builtin_altivec_vsubecuq(__a, __b, __c);
+}

kbarton wrote:
> Why do we mask the carries for sign/unsigned ints, but not __128 ints?
for quadword, hardware does the masking (implicitly, by only looking at the 
rightmost bit)


https://reviews.llvm.org/D26544



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


[PATCH] D26637: [change-namespace] handle constructor initializer: Derived : Base::Base() {} and added conflict detections

2016-11-16 Thread Haojian Wu via cfe-commits
hokein added inline comments.



Comment at: test/change-namespace/lambda-function.cpp:2
+// RUN: clang-change-namespace -old_namespace "na::nb" -new_namespace "x::y" 
--file_pattern ".*" %s -- -std=c++11 | sed 's,// CHECK.*,,' | FileCheck %s
+#include 
+// CHECK: namespace x {

hokein wrote:
> In practise, we don't use std headers directly in llvm lit test. You need to 
> mock it by yourself...
Hint: here is a simple fake `function code`, should be compiled.

```
template class function;
template class function {
 public:
  template 
  function(Functor f) {}
};

void B(function t) {};

void g() {
  B([](int x){});
}

```


https://reviews.llvm.org/D26637



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


[libcxx] r287109 - Fix -verify tests for older ccache versions

2016-11-16 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Nov 16 08:48:42 2016
New Revision: 287109

URL: http://llvm.org/viewvc/llvm-project?rev=287109&view=rev
Log:
Fix -verify tests for older ccache versions

Modified:
libcxx/trunk/test/libcxx/test/format.py

Modified: libcxx/trunk/test/libcxx/test/format.py
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/test/format.py?rev=287109&r1=287108&r2=287109&view=diff
==
--- libcxx/trunk/test/libcxx/test/format.py (original)
+++ libcxx/trunk/test/libcxx/test/format.py Wed Nov 16 08:48:42 2016
@@ -37,6 +37,11 @@ class LibcxxTestFormat(object):
 self.execute_external = execute_external
 self.executor = executor
 self.exec_env = dict(exec_env)
+self.compile_env = dict(os.environ)
+# 'CCACHE_CPP2' prevents ccache from stripping comments while
+# preprocessing. This is required to prevent stripping of '-verify'
+# comments.
+self.compile_env['CCACHE_CPP2'] = '1'
 
 # TODO: Move this into lit's FileBasedTest
 def getTestsInDirectory(self, testSuite, path_in_suite,
@@ -127,7 +132,7 @@ class LibcxxTestFormat(object):
 # Compile the test
 cmd, out, err, rc = self.cxx.compileLinkTwoSteps(
 source_path, out=exec_path, object_file=object_path,
-cwd=execDir)
+cwd=execDir, env=self.compile_env)
 compile_cmd = cmd
 if rc != 0:
 report = libcxx.util.makeReport(cmd, out, err, rc)
@@ -187,7 +192,8 @@ class LibcxxTestFormat(object):
 cmd, out, err, rc = self.cxx.compile(source_path, out=os.devnull,
  flags=extra_flags,
  disable_ccache=True,
- enable_warnings=False)
+ enable_warnings=False,
+ env=self.compile_env)
 expected_rc = 0 if use_verify else 1
 if rc == expected_rc:
 return lit.Test.PASS, ''


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


[PATCH] D26702: [libc++] Introduce `_LIBCPP_OVERRIDABLE_FUNC_VIS`

2016-11-16 Thread Eric Fiselier via cfe-commits
EricWF accepted this revision.
EricWF added inline comments.
This revision is now accepted and ready to land.



Comment at: src/new.cpp:163
 
-_LIBCPP_WEAK _LIBCPP_NEW_DELETE_VIS
 void*

You should be able to remove the macro on the definitions since they're 
redundant. 


https://reviews.llvm.org/D26702



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


[PATCH] D26702: [libc++] Introduce `_LIBCPP_OVERRIDABLE_FUNC_VIS`

2016-11-16 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

What happens on windows when `operator new` isn't overridden and has to be 
imported from the DLL? Does that work?


https://reviews.llvm.org/D26702



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


[PATCH] D26637: [change-namespace] handle constructor initializer: Derived : Base::Base() {} and added conflict detections

2016-11-16 Thread Eric Liu via cfe-commits
ioeric updated this revision to Diff 78188.
ioeric added a comment.

- Add lambda-function.cpp test back.


https://reviews.llvm.org/D26637

Files:
  change-namespace/ChangeNamespace.cpp
  change-namespace/ChangeNamespace.h
  test/change-namespace/lambda-function.cpp
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -43,8 +43,9 @@
 NamespaceTool.registerMatchers(&Finder);
 std::unique_ptr Factory =
 tooling::newFrontendActionFactory(&Finder);
-tooling::runToolOnCodeWithArgs(Factory->create(), Code, {"-std=c++11"},
-   FileName);
+if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, {"-std=c++11"},
+FileName))
+  return "";
 formatAndApplyAllReplacements(FileToReplacements, Context.Rewrite);
 return format(Context.getRewrittenText(ID));
   }
@@ -330,19 +331,6 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
-TEST_F(ChangeNamespaceTest, DoNotCrashWithLambdaAsParameter) {
-  std::string Code =
-  "#include \n"
-  "void f(std::function func, int param) { func(param); } "
-  "void g() { f([](int x) {}, 1); }";
-
-  std::string Expected =
-  "#include \n"
-  "void f(std::function func, int param) { func(param); } "
-  "void g() { f([](int x) {}, 1); }";
-  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
-}
-
 TEST_F(ChangeNamespaceTest, FixUsingShadowDecl) {
   std::string Code = "class GLOB {};\n"
  "using BLOG = GLOB;\n"
@@ -510,8 +498,8 @@
  "public:\n"
  "static int A1;\n"
  "static int A2;\n"
- "}\n"
- "static int A::A1 = 0;\n"
+ "};\n"
+ "int A::A1 = 0;\n"
  "namespace nb {\n"
  "void f() { int a = A::A1; int b = A::A2; }"
  "} // namespace nb\n"
@@ -522,8 +510,8 @@
  "public:\n"
  "static int A1;\n"
  "static int A2;\n"
- "}\n"
- "static int A::A1 = 0;\n"
+ "};\n"
+ "int A::A1 = 0;\n"
  "\n"
  "} // namespace na\n"
  "namespace x {\n"
@@ -1005,6 +993,93 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, DerivedClassWithConstructors) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) {}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "\n\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) {}\n"
+  "} // namespace y\n"
+  "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, DerivedClassWithQualifiedConstructors) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X::X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X::X(i) {}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "\n\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X::X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X::X(i) {}\n"
+  "} // namespace y\n"
+  "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, DerivedClassWithConstructorsAndTypeRefs) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) { X x(1);}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "n

r287112 - Add a little endian variant of TCE.

2016-11-16 Thread Pekka Jaaskelainen via cfe-commits
Author: pjaaskel
Date: Wed Nov 16 09:22:31 2016
New Revision: 287112

URL: http://llvm.org/viewvc/llvm-project?rev=287112&view=rev
Log:
Add a little endian variant of TCE.

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/ToolChains.h

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=287112&r1=287111&r2=287112&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Nov 16 09:22:31 2016
@@ -7210,8 +7210,11 @@ public:
 FloatFormat = &llvm::APFloat::IEEEsingle;
 DoubleFormat = &llvm::APFloat::IEEEsingle;
 LongDoubleFormat = &llvm::APFloat::IEEEsingle;
-resetDataLayout("E-p:32:32-i8:8:32-i16:16:32-i64:32"
-"-f64:32-v64:32-v128:32-a:0:32-n32");
+resetDataLayout("E-p:32:32:32-i1:8:8-i8:8:32-"
+"i16:16:32-i32:32:32-i64:32:32-"
+"f32:32:32-f64:32:32-v64:32:32-"
+"v128:32:32-v256:32:32-v512:32:32-"
+"v1024:32:32-a0:0:32-n32");
 AddrSpaceMap = &TCEOpenCLAddrSpaceMap;
 UseAddrSpaceMapMangling = true;
   }
@@ -7239,6 +7242,31 @@ public:
   }
 };
 
+class TCELETargetInfo : public TCETargetInfo {
+public:
+  TCELETargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : TCETargetInfo(Triple, Opts) {
+BigEndian = false;
+
+resetDataLayout("e-p:32:32:32-i1:8:8-i8:8:32-"
+"i16:16:32-i32:32:32-i64:32:32-"
+"f32:32:32-f64:32:32-v64:32:32-"
+"v128:32:32-v256:32:32-v512:32:32-"
+"v1024:32:32-a0:0:32-n32");
+
+  }
+
+  virtual void getTargetDefines(const LangOptions &Opts,
+MacroBuilder &Builder) const {
+DefineStd(Builder, "tcele", Opts);
+Builder.defineMacro("__TCE__");
+Builder.defineMacro("__TCE_V1__");
+Builder.defineMacro("__TCELE__");
+Builder.defineMacro("__TCELE_V1__");
+  }
+
+};
+
 class BPFTargetInfo : public TargetInfo {
 public:
   BPFTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
@@ -8627,6 +8655,9 @@ static TargetInfo *AllocateTarget(const
   case llvm::Triple::tce:
 return new TCETargetInfo(Triple, Opts);
 
+  case llvm::Triple::tcele:
+return new TCELETargetInfo(Triple, Opts);
+
   case llvm::Triple::x86:
 if (Triple.isOSDarwin())
   return new DarwinI386TargetInfo(Triple, Opts);

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=287112&r1=287111&r2=287112&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Wed Nov 16 09:22:31 2016
@@ -8251,6 +8251,7 @@ const TargetCodeGenInfo &CodeGenModule::
   }
 
   case llvm::Triple::tce:
+  case llvm::Triple::tcele:
 return SetCGInfo(new TCETargetCodeGenInfo(Types));
 
   case llvm::Triple::x86: {

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=287112&r1=287111&r2=287112&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Wed Nov 16 09:22:31 2016
@@ -3618,6 +3618,9 @@ const ToolChain &Driver::getToolChain(co
   case llvm::Triple::tce:
 TC = new toolchains::TCEToolChain(*this, Target, Args);
 break;
+  case llvm::Triple::tcele:
+TC = new toolchains::TCELEToolChain(*this, Target, Args);
+break;
   case llvm::Triple::hexagon:
 TC = new toolchains::HexagonToolChain(*this, Target, Args);
 break;

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=287112&r1=287111&r2=287112&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Wed Nov 16 09:22:31 2016
@@ -3435,6 +3435,13 @@ bool TCEToolChain::isPIEDefault() const
 
 bool TCEToolChain::isPICDefaultForced() const { return false; }
 
+TCELEToolChain::TCELEToolChain(const Driver &D, const llvm::Triple& Triple,
+   const ArgList &Args)
+  : TCEToolChain(D, Triple, Args) {
+}
+
+TCELEToolChain::~TCELEToolChain() {}
+
 // CloudABI - CloudABI tool chain which can call ld(1) directly.
 
 CloudABI::CloudABI(const Driver &D, const llvm::Triple &Triple,

Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=287112&r1=287111&r2=287112&view=diff

[PATCH] D26637: [change-namespace] handle constructor initializer: Derived : Base::Base() {} and added conflict detections

2016-11-16 Thread Haojian Wu via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM once nits get fixed.




Comment at: change-namespace/ChangeNamespace.cpp:346
+ hasDeclaration(DeclMatcher.bind("from_decl"),
+ 
unless(hasAncestor(typeLoc(loc(qualType(hasDeclaration(
+ decl(equalsBoundNode("from_decl")

hokein wrote:
> Maybe pull this `unless` matcher out and name it to make code more 
> understandable.
Looks like you are missing this one.



Comment at: change-namespace/ChangeNamespace.cpp:543
+  auto Err = FileToReplacements[Deletion.getFilePath()].add(Deletion);
+  if (Err) {
+llvm_unreachable(llvm::toString(std::move(Err)).c_str());

No `{}`.


https://reviews.llvm.org/D26637



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


[PATCH] D26637: [change-namespace] handle constructor initializer: Derived : Base::Base() {} and added conflict detections

2016-11-16 Thread Eric Liu via cfe-commits
ioeric updated this revision to Diff 78190.
ioeric added a comment.

- nits


https://reviews.llvm.org/D26637

Files:
  change-namespace/ChangeNamespace.cpp
  change-namespace/ChangeNamespace.h
  test/change-namespace/lambda-function.cpp
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -43,8 +43,9 @@
 NamespaceTool.registerMatchers(&Finder);
 std::unique_ptr Factory =
 tooling::newFrontendActionFactory(&Finder);
-tooling::runToolOnCodeWithArgs(Factory->create(), Code, {"-std=c++11"},
-   FileName);
+if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, {"-std=c++11"},
+FileName))
+  return "";
 formatAndApplyAllReplacements(FileToReplacements, Context.Rewrite);
 return format(Context.getRewrittenText(ID));
   }
@@ -330,19 +331,6 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
-TEST_F(ChangeNamespaceTest, DoNotCrashWithLambdaAsParameter) {
-  std::string Code =
-  "#include \n"
-  "void f(std::function func, int param) { func(param); } "
-  "void g() { f([](int x) {}, 1); }";
-
-  std::string Expected =
-  "#include \n"
-  "void f(std::function func, int param) { func(param); } "
-  "void g() { f([](int x) {}, 1); }";
-  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
-}
-
 TEST_F(ChangeNamespaceTest, FixUsingShadowDecl) {
   std::string Code = "class GLOB {};\n"
  "using BLOG = GLOB;\n"
@@ -510,8 +498,8 @@
  "public:\n"
  "static int A1;\n"
  "static int A2;\n"
- "}\n"
- "static int A::A1 = 0;\n"
+ "};\n"
+ "int A::A1 = 0;\n"
  "namespace nb {\n"
  "void f() { int a = A::A1; int b = A::A2; }"
  "} // namespace nb\n"
@@ -522,8 +510,8 @@
  "public:\n"
  "static int A1;\n"
  "static int A2;\n"
- "}\n"
- "static int A::A1 = 0;\n"
+ "};\n"
+ "int A::A1 = 0;\n"
  "\n"
  "} // namespace na\n"
  "namespace x {\n"
@@ -1005,6 +993,93 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, DerivedClassWithConstructors) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) {}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "\n\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) {}\n"
+  "} // namespace y\n"
+  "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, DerivedClassWithQualifiedConstructors) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X::X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X::X(i) {}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "\n\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X::X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X::X(i) {}\n"
+  "} // namespace y\n"
+  "} // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, DerivedClassWithConstructorsAndTypeRefs) {
+  std::string Code =
+  "namespace nx { namespace ny { class X { public: X(int i) {} }; } }\n"
+  "namespace na {\n"
+  "namespace nb {\n"
+  "class A : public nx::ny::X {\n"
+  "public:\n"
+  "  A() : X(0) {}\n"
+  "  A(int i);\n"
+  "};\n"
+  "A::A(int i) : X(i) { X x(1);}\n"
+  "} // namespace nb\n"
+  "} // namespace na\n";
+  std::string Expected =
+  "namespace nx { namespace ny { c

[PATCH] D23325: [WIP] Binding of references to packed fields

2016-11-16 Thread Roger Ferrer Ibanez via cfe-commits
rogfer01 added inline comments.



Comment at: include/clang/Basic/Specifiers.h:119-140
   enum ExprObjectKind {
 /// An ordinary object is located at an address in memory.
 OK_Ordinary,
 
 /// A bitfield object is a bitfield on a C or C++ record.
 OK_BitField,
 

rsmith wrote:
> Wait a second, how did this fit into 2 bits before your change?!
It didn't.

I was also really confused when some unrelated Obj-C tests started failing 
after this change.


https://reviews.llvm.org/D23325



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


r287114 - Remove duplicate condition (PR30648). NFCI.

2016-11-16 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Wed Nov 16 10:11:08 2016
New Revision: 287114

URL: http://llvm.org/viewvc/llvm-project?rev=287114&view=rev
Log:
Remove duplicate condition (PR30648). NFCI.

We only need to check that the bitstream entry is a Record.

Modified:
cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=287114&r1=287113&r2=287114&view=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Nov 16 10:11:08 2016
@@ -4189,8 +4189,7 @@ static ASTFileSignature readASTFileSigna
   ASTReader::RecordData Record;
   while (true) {
 llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks();
-if (Entry.Kind == llvm::BitstreamEntry::EndBlock ||
-Entry.Kind != llvm::BitstreamEntry::Record)
+if (Entry.Kind != llvm::BitstreamEntry::Record)
   return 0;
 
 Record.clear();


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


[PATCH] D26750: [clang-tidy] Add modernize-use-default-member-init check

2016-11-16 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added reviewers: aaron.ballman, Eugene.Zelenko, alexfh.
malcolm.parsons added a subscriber: cfe-commits.
Herald added subscribers: modocache, mgorny.

Fixes PR18858


https://reviews.llvm.org/D26750

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
  clang-tidy/modernize/UseDefaultMemberInitCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-default-member-init.rst
  test/clang-tidy/modernize-use-default-member-init-assignment.cpp
  test/clang-tidy/modernize-use-default-member-init.cpp

Index: test/clang-tidy/modernize-use-default-member-init.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-default-member-init.cpp
@@ -0,0 +1,202 @@
+// RUN: %check_clang_tidy %s modernize-use-default-member-init %t -- -- -std=c++11
+
+struct S {
+};
+
+struct PositiveValueInt {
+  PositiveValueInt() : i() {}
+  // CHECK-FIXES: PositiveValueInt()  {}
+  const int i;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use default member initializer for 'i' [modernize-use-default-member-init]
+  // CHECK-FIXES: const int i{};
+};
+
+struct PositiveInt {
+  PositiveInt() : j(1) {}
+  // CHECK-FIXES: PositiveInt()  {}
+  int j;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'j' [modernize-use-default-member-init]
+  // CHECK-FIXES: int j{1};
+};
+
+struct PositiveValueDouble {
+  PositiveValueDouble() : d() {}
+  // CHECK-FIXES: PositiveValueDouble()  {}
+  double d;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'd' [modernize-use-default-member-init]
+  // CHECK-FIXES: double d{};
+};
+
+struct PositiveDouble {
+  PositiveDouble() : f(2.5463e43) {}
+  // CHECK-FIXES: PositiveDouble()  {}
+  double f;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'f' [modernize-use-default-member-init]
+  // CHECK-FIXES: double f{2.5463e43};
+};
+
+struct PositiveValueBool {
+  PositiveValueBool() : b() {}
+  // CHECK-FIXES: PositiveValueBool()  {}
+  bool b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'b' [modernize-use-default-member-init]
+  // CHECK-FIXES: bool b{};
+};
+
+struct PositiveBool {
+  PositiveBool() : a(true) {}
+  // CHECK-FIXES: PositiveBool()  {}
+  bool a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'a' [modernize-use-default-member-init]
+  // CHECK-FIXES: bool a{true};
+};
+
+struct PositiveValuePointer {
+  PositiveValuePointer() : p() {}
+  // CHECK-FIXES: PositiveValuePointer()  {}
+  int *p;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'p' [modernize-use-default-member-init]
+  // CHECK-FIXES: int *p{};
+};
+
+struct PositiveNullPointer {
+  PositiveNullPointer() : q(nullptr) {}
+  // CHECK-FIXES: PositiveNullPointer()  {}
+  int *q;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'q' [modernize-use-default-member-init]
+  // CHECK-FIXES: int *q{nullptr};
+};
+
+enum Enum { Foo, Bar };
+struct PositiveEnum {
+  PositiveEnum() : e(Foo) {}
+  // CHECK-FIXES: PositiveEnum()  {}
+  Enum e;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: use default member initializer for 'e' [modernize-use-default-member-init]
+  // CHECK-FIXES: Enum e{Foo};
+};
+
+struct NegativeMemberInit {
+  NegativeMemberInit() {}
+  int i = 2;
+};
+
+struct NegativeClass : S {
+  NegativeClass() : s() {}
+  S s;
+};
+
+struct NegativeBase : S {
+  NegativeBase() : S() {}
+};
+
+struct NegativeDefaultOtherMember{
+  NegativeDefaultOtherMember() : i(3) {}
+  int i = 4;
+};
+
+struct NegativeUnion {
+  NegativeUnion() : d(5.0) {}
+  union {
+int i;
+double d;
+  };
+};
+
+struct NegativeBitField
+{
+  NegativeBitField() : i(6) {}
+  int i : 5;
+};
+
+struct NegativeNotDefaultInt
+{
+  NegativeNotDefaultInt(int) : i(7) {}
+  int i;
+};
+
+struct ExistingInt {
+  ExistingInt(short) : e1(), e2(), e3(), e4() {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: member initializer for 'e1' is redundant [modernize-use-default-member-init]
+  // CHECK-MESSAGES: :[[@LINE-2]]:30: warning: member initializer for 'e2' is redundant [modernize-use-default-member-init]
+  // CHECK-FIXES: ExistingInt(short) :  e3(), e4() {}
+  ExistingInt(int) : e1(0), e2(0), e3(0), e4(0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: member initializer for 'e1' is redundant [modernize-use-default-member-init]
+  // CHECK-MESSAGES: :[[@LINE-2]]:29: warning: member initializer for 'e2' is redundant [modernize-use-default-member-init]
+  // CHECK-FIXES: ExistingInt(int) :  e3(0), e4(0) {}
+  ExistingInt(long) : e1(5), e2(5), e3(5), e4(5) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: member initializer for 'e3' is redundant [modernize-use-default-member-init

[clang-tools-extra] r287118 - [change-namespace] handle constructor initializer: Derived : Base::Base() {} and added conflict detections

2016-11-16 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Wed Nov 16 10:54:53 2016
New Revision: 287118

URL: http://llvm.org/viewvc/llvm-project?rev=287118&view=rev
Log:
[change-namespace] handle constructor initializer: Derived : Base::Base() {} 
and added conflict detections

Summary:
namespace nx { namespace ny { class Base { public: Base(i) {}} } }
namespace na {
namespace nb {
class X : public nx::ny {
public:
  X() : Base::Base(1) {}
};
}
}

When changing from na::nb to x::y, "Base::Base" will be changed to 
"nx::ny::Base" and
 "Base::" in "Base::Base" will be replaced with "nx::ny::Base" too, which causes
conflict. This conflict should've been detected when adding replacements but 
was hidden by `addOrMergeReplacement`. We now also detect conflict when adding 
replacements where conflict must not happen.

The namespace lookup is tricky here, we simply replace "Base::Base()" with 
"nx::ny::Base()" as a workaround, which compiles but not perfect.

Reviewers: hokein

Subscribers: bkramer, cfe-commits

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

Added:
clang-tools-extra/trunk/test/change-namespace/lambda-function.cpp
Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=287118&r1=287117&r2=287118&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Wed Nov 16 
10:54:53 2016
@@ -9,6 +9,7 @@
 #include "ChangeNamespace.h"
 #include "clang/Format/Format.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/Support/ErrorHandling.h"
 
 using namespace clang::ast_matchers;
 
@@ -336,14 +337,27 @@ void ChangeNamespaceTool::registerMatche
  .bind("using_with_shadow"),
  this);
 
-  // Handle types in nested name specifier.
+  // Handle types in nested name specifier. Specifiers that are in a TypeLoc
+  // matched above are not matched, e.g. "A::" in "A::A" is not matched since
+  // "A::A" would have already been fixed.
   Finder->addMatcher(nestedNameSpecifierLoc(
  hasAncestor(decl(IsInMovedNs).bind("dc")),
  loc(nestedNameSpecifier(specifiesType(
- hasDeclaration(DeclMatcher.bind("from_decl"))
+ hasDeclaration(DeclMatcher.bind("from_decl"),
+ 
unless(hasAncestor(typeLoc(loc(qualType(hasDeclaration(
+ decl(equalsBoundNode("from_decl")
  .bind("nested_specifier_loc"),
  this);
 
+  // Matches base class initializers in constructors. TypeLocs of base class
+  // initializers do not need to be fixed. For example,
+  //class X : public a::b::Y {
+  //  public:
+  //X() : Y::Y() {} // Y::Y do not need namespace specifier.
+  //};
+  Finder->addMatcher(
+  cxxCtorInitializer(isBaseInitializer()).bind("base_initializer"), this);
+
   // Handle function.
   // Only handle functions that are defined in a namespace excluding member
   // function, static methods (qualified by nested specifier), and functions
@@ -393,6 +407,11 @@ void ChangeNamespaceTool::run(
 SourceLocation Start = Specifier->getBeginLoc();
 SourceLocation End = EndLocationForType(Specifier->getTypeLoc());
 fixTypeLoc(Result, Start, End, Specifier->getTypeLoc());
+  } else if (const auto *BaseInitializer =
+ Result.Nodes.getNodeAs(
+ "base_initializer")) {
+BaseCtorInitializerTypeLocs.push_back(
+BaseInitializer->getTypeSourceInfo()->getTypeLoc());
   } else if (const auto *TLoc = Result.Nodes.getNodeAs("type")) {
 fixTypeLoc(Result, startLocationForType(*TLoc), EndLocationForType(*TLoc),
*TLoc);
@@ -520,7 +539,9 @@ void ChangeNamespaceTool::moveClassForwa
   // Delete the forward declaration from the code to be moved.
   const auto Deletion =
   createReplacement(Start, End, "", *Result.SourceManager);
-  addOrMergeReplacement(Deletion, &FileToReplacements[Deletion.getFilePath()]);
+  auto Err = FileToReplacements[Deletion.getFilePath()].add(Deletion);
+  if (Err)
+llvm_unreachable(llvm::toString(std::move(Err)).c_str());
   llvm::StringRef Code = Lexer::getSourceText(
   CharSourceRange::getTokenRange(
   Result.SourceManager->getSpellingLoc(Start),
@@ -606,7 +627,9 @@ void ChangeNamespaceTool::replaceQualifi
   if (NestedName == ReplaceName)
 return;
   auto R = createReplacement(Start, End, ReplaceName, *Result.SourceManager);
-  addOrMergeReplacement(R, &FileToReplacements[R.getFil

[PATCH] D26637: [change-namespace] handle constructor initializer: Derived : Base::Base() {} and added conflict detections

2016-11-16 Thread Eric Liu via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287118: [change-namespace] handle constructor initializer: 
Derived : Base::Base() {}… (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D26637?vs=78190&id=78201#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26637

Files:
  clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
  clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
  clang-tools-extra/trunk/test/change-namespace/lambda-function.cpp
  clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
===
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
@@ -145,6 +145,9 @@
   // Records all using namespace declarations, which can be used to shorten
   // namespace specifiers.
   llvm::SmallPtrSet UsingNamespaceDecls;
+  // TypeLocs of CXXCtorInitializer. Types of CXXCtorInitializers do not need to
+  // be fixed.
+  llvm::SmallVector BaseCtorInitializerTypeLocs;
 };
 
 } // namespace change_namespace
Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
===
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
@@ -9,6 +9,7 @@
 #include "ChangeNamespace.h"
 #include "clang/Format/Format.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/Support/ErrorHandling.h"
 
 using namespace clang::ast_matchers;
 
@@ -336,14 +337,27 @@
  .bind("using_with_shadow"),
  this);
 
-  // Handle types in nested name specifier.
+  // Handle types in nested name specifier. Specifiers that are in a TypeLoc
+  // matched above are not matched, e.g. "A::" in "A::A" is not matched since
+  // "A::A" would have already been fixed.
   Finder->addMatcher(nestedNameSpecifierLoc(
  hasAncestor(decl(IsInMovedNs).bind("dc")),
  loc(nestedNameSpecifier(specifiesType(
- hasDeclaration(DeclMatcher.bind("from_decl"))
+ hasDeclaration(DeclMatcher.bind("from_decl"),
+ unless(hasAncestor(typeLoc(loc(qualType(hasDeclaration(
+ decl(equalsBoundNode("from_decl")
  .bind("nested_specifier_loc"),
  this);
 
+  // Matches base class initializers in constructors. TypeLocs of base class
+  // initializers do not need to be fixed. For example,
+  //class X : public a::b::Y {
+  //  public:
+  //X() : Y::Y() {} // Y::Y do not need namespace specifier.
+  //};
+  Finder->addMatcher(
+  cxxCtorInitializer(isBaseInitializer()).bind("base_initializer"), this);
+
   // Handle function.
   // Only handle functions that are defined in a namespace excluding member
   // function, static methods (qualified by nested specifier), and functions
@@ -393,6 +407,11 @@
 SourceLocation Start = Specifier->getBeginLoc();
 SourceLocation End = EndLocationForType(Specifier->getTypeLoc());
 fixTypeLoc(Result, Start, End, Specifier->getTypeLoc());
+  } else if (const auto *BaseInitializer =
+ Result.Nodes.getNodeAs(
+ "base_initializer")) {
+BaseCtorInitializerTypeLocs.push_back(
+BaseInitializer->getTypeSourceInfo()->getTypeLoc());
   } else if (const auto *TLoc = Result.Nodes.getNodeAs("type")) {
 fixTypeLoc(Result, startLocationForType(*TLoc), EndLocationForType(*TLoc),
*TLoc);
@@ -520,7 +539,9 @@
   // Delete the forward declaration from the code to be moved.
   const auto Deletion =
   createReplacement(Start, End, "", *Result.SourceManager);
-  addOrMergeReplacement(Deletion, &FileToReplacements[Deletion.getFilePath()]);
+  auto Err = FileToReplacements[Deletion.getFilePath()].add(Deletion);
+  if (Err)
+llvm_unreachable(llvm::toString(std::move(Err)).c_str());
   llvm::StringRef Code = Lexer::getSourceText(
   CharSourceRange::getTokenRange(
   Result.SourceManager->getSpellingLoc(Start),
@@ -606,7 +627,9 @@
   if (NestedName == ReplaceName)
 return;
   auto R = createReplacement(Start, End, ReplaceName, *Result.SourceManager);
-  addOrMergeReplacement(R, &FileToReplacements[R.getFilePath()]);
+  auto Err = FileToReplacements[R.getFilePath()].add(R);
+  if (Err)
+llvm_unreachable(llvm::toString(std::move(Err)).c_str());
 }
 
 // Replace the [Start, End] of `Type` with the shortest qualified name when the
@@ -617,6 +640,9 @@
   // FIXME: do not rename template parameter.
   if (Start.isInvalid() || End.isInvalid())
 return;
+  // Types of CXXCtorInitializers do not need to be fixed.
+  if (llvm::is_contained(BaseCtorIniti

r287115 - target-data test update for TCE and TCELE

2016-11-16 Thread Pekka Jaaskelainen via cfe-commits
Author: pjaaskel
Date: Wed Nov 16 10:21:59 2016
New Revision: 287115

URL: http://llvm.org/viewvc/llvm-project?rev=287115&view=rev
Log:
target-data test update for TCE and TCELE

Modified:
cfe/trunk/test/CodeGen/target-data.c

Modified: cfe/trunk/test/CodeGen/target-data.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/target-data.c?rev=287115&r1=287114&r2=287115&view=diff
==
--- cfe/trunk/test/CodeGen/target-data.c (original)
+++ cfe/trunk/test/CodeGen/target-data.c Wed Nov 16 10:21:59 2016
@@ -179,7 +179,11 @@
 
 // RUN: %clang_cc1 -triple tce-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=TCE
-// TCE: target datalayout = 
"E-p:32:32-i8:8:32-i16:16:32-i64:32-f64:32-v64:32-v128:32-a:0:32-n32"
+// TCE: target datalayout = 
"E-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:32-v128:32:32-v256:32:32-v512:32:32-v1024:32:32-a0:0:32-n32"
+
+// RUN: %clang_cc1 -triple tcele-unknown -o - -emit-llvm %s | \
+// RUN: FileCheck %s -check-prefix=TCELE
+// TCELE: target datalayout = 
"e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:32-v128:32:32-v256:32:32-v512:32:32-v1024:32:32-a0:0:32-n32"
 
 // RUN: %clang_cc1 -triple spir-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=SPIR


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


[PATCH] D26751: [clang-tidy] Ignore template instantiations in modernize-use-equals-delete check

2016-11-16 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added reviewers: aaron.ballman, alexfh.
malcolm.parsons added a subscriber: cfe-commits.

Template instantiations were causing misplaced fixits.


https://reviews.llvm.org/D26751

Files:
  clang-tidy/modernize/UseEqualsDeleteCheck.cpp
  test/clang-tidy/modernize-use-equals-delete.cpp


Index: test/clang-tidy/modernize-use-equals-delete.cpp
===
--- test/clang-tidy/modernize-use-equals-delete.cpp
+++ test/clang-tidy/modernize-use-equals-delete.cpp
@@ -22,6 +22,32 @@
   // CHECK-FIXES: ~PositivePrivate() = delete;
 };
 
+template
+struct PositivePrivateTemplate {
+private:
+  PositivePrivateTemplate();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit 
calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate() = delete;
+  PositivePrivateTemplate(const PositivePrivateTemplate &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit 
calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate(const PositivePrivateTemplate &) = 
delete;
+  PositivePrivateTemplate &operator=(const PositivePrivateTemplate &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use '= delete' to prohibit 
calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate &operator=(const 
PositivePrivateTemplate &) = delete;
+  PositivePrivateTemplate(PositivePrivateTemplate &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit 
calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate(PositivePrivateTemplate &&) = delete;
+  PositivePrivateTemplate &operator=(PositivePrivateTemplate &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use '= delete' to prohibit 
calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate &operator=(PositivePrivateTemplate 
&&) = delete;
+  ~PositivePrivateTemplate();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit 
calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: ~PositivePrivateTemplate() = delete;
+};
+
+template struct PositivePrivateTemplate;
+template struct PositivePrivateTemplate;
+
 struct NegativePublic {
   NegativePublic(const NegativePublic &);
 };
Index: clang-tidy/modernize/UseEqualsDeleteCheck.cpp
===
--- clang-tidy/modernize/UseEqualsDeleteCheck.cpp
+++ clang-tidy/modernize/UseEqualsDeleteCheck.cpp
@@ -34,6 +34,7 @@
   cxxMethodDecl(
   PrivateSpecialFn,
   unless(anyOf(hasBody(stmt()), isDefaulted(), isDeleted(),
+   ast_matchers::isTemplateInstantiation(),
// Ensure that all methods except private special member
// functions are defined.
hasParent(cxxRecordDecl(hasMethod(unless(


Index: test/clang-tidy/modernize-use-equals-delete.cpp
===
--- test/clang-tidy/modernize-use-equals-delete.cpp
+++ test/clang-tidy/modernize-use-equals-delete.cpp
@@ -22,6 +22,32 @@
   // CHECK-FIXES: ~PositivePrivate() = delete;
 };
 
+template
+struct PositivePrivateTemplate {
+private:
+  PositivePrivateTemplate();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate() = delete;
+  PositivePrivateTemplate(const PositivePrivateTemplate &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate(const PositivePrivateTemplate &) = delete;
+  PositivePrivateTemplate &operator=(const PositivePrivateTemplate &);
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate &operator=(const PositivePrivateTemplate &) = delete;
+  PositivePrivateTemplate(PositivePrivateTemplate &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate(PositivePrivateTemplate &&) = delete;
+  PositivePrivateTemplate &operator=(PositivePrivateTemplate &&);
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use '= delete' to prohibit calling of a special member function [modernize-use-equals-delete]
+  // CHECK-FIXES: PositivePrivateTemplate &operator=(PositivePrivateTemplate &&) = delete;
+  ~PositivePrivateTemplate();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use '= delete' to prohibit calling of a

[PATCH] D26376: Undef stdatomic.h macro definitions that are defining functions provided in libc++

2016-11-16 Thread Richard Smith via cfe-commits
rsmith added a comment.

Hmm, this won't help when building libc++ as a module, and we don't have a 
wrapper header to hold these undefs since  is not part of c++.

So either that combination of includes gives a broken  or a broken 
, or we do something nonstandard like reimplementing the latter in 
terms of the former in libc++.

Eric, Marshall, what do you think? How / how much should we support this 
non-c++ header?


https://reviews.llvm.org/D26376



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


[PATCH] D26376: Undef stdatomic.h macro definitions that are defining functions provided in libc++

2016-11-16 Thread Marshall Clow via cfe-commits
mclow.lists added a comment.

I'll do some research.


https://reviews.llvm.org/D26376



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


[PATCH] D26657: [Sema] Respect DLL attributes more faithfully

2016-11-16 Thread Hans Wennborg via cfe-commits
hans added a comment.

In https://reviews.llvm.org/D26657#596897, @smeenai wrote:

> In https://reviews.llvm.org/D26657#596759, @hans wrote:
>
> > > On MSVC, if an implicit instantiation already exists and an explicit
> > >  instantiation definition with a DLL attribute is created, the DLL
> > >  attribute still takes effect. Make clang match this behavior.
> >
> > This is scary territory, and behaviour I think might be hard for us to 
> > match.
> >
> > What if we already codegenned the implicit instantiation?
>
>
> Hmm. Under what specific cases would that happen?


Actually maybe I was being overly cautius. I think 
https://reviews.llvm.org/rL225570 might just make this work.

> I can see odd behavior differences occurring for `dllimport`. For example, 
> for the C++ source in https://reviews.llvm.org/P7936, if I compile with clang 
> (even with this patch applied), the `t.f()` call in `g` gets assembled to a 
> call to `?f@?$s@H@@QAEHXZ`. If I hoist the dllimport explicit instantiation 
> definition above `g`, `t.f()` instead assembles to `__imp_?f@?$s@H@@QAEHXZ`.

Yeah, dllimport is interesting here. If you turn on `-O1`, it will call the 
`__imp` one. Fun times :-)

> With cl 19.00.24210, `t.f()` always assembles to `__imp_?f@?$s@H@@QAEHXZ`, 
> regardless of the placement of the explicit instantiation definition.

Presumably they parse and analyze the whole translation unit before emitting 
any code, which makes changing things around later easier for them than for us.

> I'm having a harder time imagining things going awry for `dllexport`. I can 
> limit this patch to only `dllexport`, if that's going to be safer.

Yeah, I think https://reviews.llvm.org/rL225570 makes this work actually.

> To give some context, libc++ uses extern templates extensively, and I ran 
> into an issue with dllexport explicit locale template instantiations 
> .
>  Some of those instantiations are also implicitly instantiated via sizeof 
> calls 
> .
>  Therefore, all instances which make is called on 
> 
>  end up having their `dllexport` attribute ignored.
> 
> We could work around this in libc++ by hoisting the affected instantiations 
> to near the top of the file, but it seemed preferable to make clang match 
> MSVC's behavior instead, at least for `dllexport`. I don't have any 
> particular interest in making `dllimport` semantics match MSVC for this 
> specific case.

Dont' we need `dllimport` to work analogously though? When using libc++, don't 
these template members need to be dllimported? If not, why are they being 
exported in the first place?


https://reviews.llvm.org/D26657



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


[PATCH] D26735: [OpenCL] Disable && (address of label) GNU extension for OpenCL

2016-11-16 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

It seems that this bit is accepted under -std=c99 and the warning is given with 
the -pedantic flag. I am not sure whether it adds much deviating the 
implementation from C here. The OpenCL spec doesn't seem to contain anything on 
this matter? But if we decide to be more strict, could we try to keep it 
consistent with the C implementation (perhaps we could give the same diagnostic 
as C does as an error instead or a warning).

Also this bit gives different error in C:

  int a;
  void *p = &&a;
  error: use of undeclared label 'a' 

It doesn't seem like any of the errors for that code is more logical or 
precise. But if I would have to pick among equivalent approaches I would go for 
keeping it coherent with C.


https://reviews.llvm.org/D26735



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


[PATCH] D26376: Undef stdatomic.h macro definitions that are defining functions provided in libc++

2016-11-16 Thread Marshall Clow via cfe-commits
mclow.lists added a comment.

Ok - looking just at `kill_dependency`, this was added to the C standard in 
C11. It's required to be a macro.
`atomic_is_lock_free` appears to be a function, as does `atomic_load`. Haven't 
checked the rest.

I see that Bionic (sometimes) defines `atomic_is_lock_free` as a macro.


https://reviews.llvm.org/D26376



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


[PATCH] D26750: [clang-tidy] Add modernize-use-default-member-init check

2016-11-16 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/clang-tidy/checks/modernize-use-default-member-init.rst:7
+This check converts a default constructor's member initializers into default
+member initializers.  Other member initializers that match the default
+member initializer are removed.  This can reduce repeated code or allow use of

Please fix double spaces. Same below.


https://reviews.llvm.org/D26750



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


Re: [PATCH] D26376: Undef stdatomic.h macro definitions that are defining functions provided in libc++

2016-11-16 Thread Richard Smith via cfe-commits
On 16 Nov 2016 10:04 am, "Marshall Clow"  wrote:

mclow.lists added a comment.

Ok - looking just at `kill_dependency`, this was added to the C standard in
C11. It's required to be a macro.
`atomic_is_lock_free` appears to be a function, as does `atomic_load`.
Haven't checked the rest.


That's a bug in C11; these are nearly all required to be macros. See
http://www.open-std.org/jtc1/sc22/wg14/www/docs/summary.htm#dr_419

I see that Bionic (sometimes) defines `atomic_is_lock_free` as a macro.


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


[PATCH] D26746: [OpenCL] Split PipeType into ReadPipe/WritePipe

2016-11-16 Thread Anastasia Stulova via cfe-commits
Anastasia added a comment.

Earlier related discussion: https://reviews.llvm.org/D17821


Repository:
  rL LLVM

https://reviews.llvm.org/D26746



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


[PATCH] D23325: [WIP] Binding of references to packed fields

2016-11-16 Thread Roger Ferrer Ibanez via cfe-commits
rogfer01 marked 15 inline comments as done.
rogfer01 added a comment.

I am retaking this, will upload an updated patch soon.




Comment at: lib/AST/Decl.cpp:3523
+  return !isBitField() &&
+ (this->hasAttr() || getParent()->hasAttr()) &&
+ Context.getDeclAlign(this) <

rsmith wrote:
> Does this properly handle anonymous struct/union members:
> 
>   struct A __attribute__((packed)) {
> char a;
> union { int b; };
>   } a;
>   int &r = a.b;
This test (modulo swapping `A` and `__attribute__((packed))`  positions) works. 
Do you think we may be missing some case here?



Comment at: test/SemaCXX/bind-packed-member.cpp:68-73
+struct F
+{
+char c;
+NonTrivialCopy x __attribute__((packed));
+int w __attribute__((packed));
+} f;

rsmith wrote:
> Another interesting case:
> 
> struct __attribute__((packed)) G {
>   char c;
>   NonTrivialCopy x;
> };
> 
> Here, GCC ignores the `packed` attribute entirely (with a warning). For ABI 
> compatibility, we should do the same.
Will do this in a later update of this patch.

I still have to check what is the best place to check this, though I think once 
the class-specifier has been completed.


https://reviews.llvm.org/D23325



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


[PATCH] D23325: [WIP] Binding of references to packed fields

2016-11-16 Thread Roger Ferrer Ibanez via cfe-commits
rogfer01 updated this revision to Diff 78209.
rogfer01 added a comment.

Changes:

- Rebase patch to trunk
- Fixes as pointed out by reviewers

TODO:

- Diagnose and drop the packed attribute of a class with a nontrivially 
constructed data member.


https://reviews.llvm.org/D23325

Files:
  include/clang/AST/Decl.h
  include/clang/AST/Expr.h
  include/clang/AST/Stmt.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/Specifiers.h
  lib/AST/ASTDumper.cpp
  lib/AST/Decl.cpp
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprMember.cpp
  lib/Sema/SemaFixItUtils.cpp
  lib/Sema/SemaInit.cpp
  test/SemaCXX/bind-packed-member.cpp

Index: test/SemaCXX/bind-packed-member.cpp
===
--- test/SemaCXX/bind-packed-member.cpp
+++ test/SemaCXX/bind-packed-member.cpp
@@ -0,0 +1,93 @@
+// RUN: %clang_cc1 -verify %s
+
+struct __attribute__((packed)) A {
+  char x;
+  float y;
+  char z;
+} a;
+
+char &rax = a.x;  // no-error
+float &ray = a.y; // expected-error {{reference cannot bind to packed field}}
+char &raz = a.z;  // no-error
+
+struct __attribute__((packed, aligned(2))) B {
+  // Regardless of aligned(2) the fields are aligned(1) because of packed.
+  // The whole struct is aligned(2), though.
+  short x;
+  float y;
+  short z;
+  char w;
+} b;
+
+const short &crbx = b.x; // no-error
+short &rbx = b.x; // expected-error {{reference cannot bind to packed field}}
+float &rby = b.y; // expected-error {{reference cannot bind to packed field}}
+short &rbz = b.z; // expected-error {{reference cannot bind to packed field}}
+char &rbw = b.w;  // no-error
+
+struct __attribute__((packed)) B2 {
+  short x __attribute__((aligned(2)));
+  float y;
+  short z __attribute__((aligned(4)));
+  char w;
+} b2;
+
+short &rb2x = b2.x; // no-error
+short &rb2z = b2.z; // no-error
+
+struct C {
+  int c;
+};
+
+struct __attribute__((packed)) D {
+  char x;
+  int y;
+  C z;
+} d;
+
+C &rcz = d.z; // expected-error {{reference cannot bind to packed field}}
+int &rczc = d.z.c; // expected-error {{reference cannot bind to packed field}}
+
+struct E {
+int x __attribute__((packed));
+C y __attribute__((packed));
+C z;
+} e;
+
+int& rex = e.x; // expected-error {{reference cannot bind to packed field}}
+C& rey = e.y; // expected-error {{reference cannot bind to packed field}}
+C& rez = e.z;  // no-error
+
+struct NonTrivialCopy
+{
+int w;
+NonTrivialCopy();
+NonTrivialCopy(const NonTrivialCopy&);
+};
+
+struct F
+{
+char c;
+NonTrivialCopy x __attribute__((packed));
+int w __attribute__((packed));
+} f;
+
+
+void fun1(int &);
+void fun2(const int &);
+
+void bar()
+{
+const NonTrivialCopy& rx = f.x; // expected-error {{reference cannot bind to packed field}}
+const int &w = f.w; // no-error
+
+fun1(f.w); // expected-error {{reference cannot bind to packed field}}
+   // expected-note@76 {{passing argument to parameter here}}
+fun2(f.w); // no-error
+}
+
+struct __attribute__((packed)) Z {
+  char z;
+  union { int b; };
+} z;
+int &rzb = z.b; // expected-error {{reference cannot bind to packed field}}
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -4200,6 +4200,7 @@
  Qualifiers T2Quals,
  bool IsLValueRef) {
   bool IsNonAddressableType = Initializer->refersToBitField() ||
+  Initializer->refersToPackedField() ||
   Initializer->refersToVectorElement();
 
   if (IsNonAddressableType) {
@@ -4214,6 +4215,31 @@
   return Initializer->getValueKind();
 }
 
+if (Initializer->refersToPackedField() &&
+Initializer->getType()->getAsCXXRecordDecl()) {
+  auto Record = Initializer->getType()->getAsCXXRecordDecl();
+  /*
+Consider the case below:
+   struct A
+   {
+   char c;
+   std::vector x __attribute__((packed));
+   } a;
+
+   void f()
+   {
+   const std::vector& w = a.x;
+   }
+
+If the class doesn't have a trivial copy constructor, we can't create
+a copy of it for the reference binding because doing so would bind it to
+a reference in the class's own copy/move constructor, so just give up
+and allow the error to be diagnosed.
+  */
+  if (!Record->hasTrivialCopyConstructor())
+return Initializer->getValueKind();
+}
+
 // Force a load so we can materialize a temporary.
 Sequence.AddLValueToRValueStep(cv1T1.getUnqualifiedType());
 return VK_RValue;
@@ -6445,6 +6471,13 @@
 return ExprError();
   }
 
+  if (CurInit.get()->refersToPackedField()) {
+S.Diag(Kind.getLocation(), diag::err_reference_bind_to_packed_field)
+<< CurInit.get()->get

[PATCH] D26752: [include-fixer] Refactor include fixer to be usable as a plugin

2016-11-16 Thread Benjamin Kramer via cfe-commits
bkramer created this revision.
bkramer added reviewers: klimek, hokein, ioeric.
bkramer added a subscriber: cfe-commits.
Herald added a subscriber: mgorny.

- Refactor the external sema source into a visible class
- Add support for emitting FixIts
- Wrap up include fixer as a plugin as I did with clang-tidy

Test case will follow as soon as I wire this up in libclang.


https://reviews.llvm.org/D26752

Files:
  include-fixer/CMakeLists.txt
  include-fixer/IncludeFixer.cpp
  include-fixer/IncludeFixer.h
  include-fixer/plugin/CMakeLists.txt
  include-fixer/plugin/IncludeFixerPlugin.cpp

Index: include-fixer/plugin/IncludeFixerPlugin.cpp
===
--- /dev/null
+++ include-fixer/plugin/IncludeFixerPlugin.cpp
@@ -0,0 +1,96 @@
+//===- ClangTidyPlugin.cpp - clang-tidy as a clang plugin -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../IncludeFixer.h"
+#include "../YamlSymbolIndex.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendPluginRegistry.h"
+#include "clang/Parse/ParseAST.h"
+#include "clang/Sema/Sema.h"
+#include "llvm/Support/Path.h"
+
+namespace clang {
+namespace include_fixer {
+
+/// The core include fixer plugin action. This just provides the AST consumer
+/// and command line flag parsing for using include fixer as a clang plugin.
+class ClangIncludeFixerPluginAction : public PluginASTAction {
+  /// ASTConsumer to keep the symbol index alive. We don't really need an
+  /// ASTConsumer for this plugin (everything is funneled on the side through
+  /// Sema) but we have to keep the symbol index alive until sema is done.
+  struct ASTConsumerManagerWrapper : public ASTConsumer {
+ASTConsumerManagerWrapper(std::shared_ptr SIM)
+: SymbolIndexMgr(std::move(SIM)) {}
+std::shared_ptr SymbolIndexMgr;
+  };
+public:
+  explicit ClangIncludeFixerPluginAction()
+  : SymbolIndexMgr(std::make_shared()),
+SemaSource(new IncludeFixerSemaSource(*SymbolIndexMgr,
+  /*MinimizeIncludePaths=*/true,
+  /*GenerateDiagnostics=*/true)) {}
+
+  std::unique_ptr
+  CreateASTConsumer(clang::CompilerInstance &CI, StringRef InFile) override {
+CI.setExternalSemaSource(SemaSource);
+SemaSource->setFilePath(InFile);
+SemaSource->setCompilerInstance(&CI);
+return llvm::make_unique(SymbolIndexMgr);
+  }
+
+  void ExecuteAction() override {} // Do nothing.
+
+  bool ParseArgs(const CompilerInstance &CI,
+ const std::vector &Args) override {
+StringRef DB = "yaml";
+StringRef Input;
+
+// Parse the extra command line args.
+// FIXME: This is very limited at the moment.
+for (StringRef Arg : Args) {
+  if (Arg.startswith("-db="))
+DB = Arg.substr(strlen("-db="));
+  else if (Arg.startswith("-input="))
+Input = Arg.substr(strlen("-input="));
+}
+
+llvm::ErrorOr> SymbolIdx(
+nullptr);
+if (DB == "yaml") {
+  if (!Input.empty()) {
+SymbolIdx = include_fixer::YamlSymbolIndex::createFromFile(Input);
+  } else {
+// If we don't have any input file, look in the directory of the first
+// file and its parents.
+const FrontendOptions &FO = CI.getFrontendOpts();
+SmallString<128> AbsolutePath(
+tooling::getAbsolutePath(FO.Inputs[0].getFile()));
+StringRef Directory = llvm::sys::path::parent_path(AbsolutePath);
+SymbolIdx = include_fixer::YamlSymbolIndex::createFromDirectory(
+Directory, "find_all_symbols_db.yaml");
+  }
+}
+SymbolIndexMgr->addSymbolIndex(std::move(*SymbolIdx));
+return true;
+  }
+
+private:
+  std::shared_ptr SymbolIndexMgr;
+  IntrusiveRefCntPtr SemaSource;
+};
+} // namespace include_fixer
+} // namespace clang
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the clang-tidy plugin.
+volatile int ClangIncludeFixerPluginAnchorSource = 0;
+
+static clang::FrontendPluginRegistry::Add<
+clang::include_fixer::ClangIncludeFixerPluginAction>
+X("clang-include-fixer", "clang-include-fixer");
Index: include-fixer/plugin/CMakeLists.txt
===
--- /dev/null
+++ include-fixer/plugin/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_clang_library(clangIncludeFixerPlugin
+  IncludeFixerPlugin.cpp
+
+  LINK_LIBS
+  clangAST
+  clangBasic
+  clangFrontend
+  clangIncludeFixer
+  clangParse
+  clangSema
+  clangTooling
+  )
Index: include-fixer/IncludeFixer.h
===
--- include-fixer/IncludeFixer.h
+++ include-fixer/Inclu

[PATCH] D26267: [Modules] Include builtins with #include instead of #import for ObjC

2016-11-16 Thread Bruno Cardoso Lopes via cfe-commits
bruno added a comment.

Ping!


https://reviews.llvm.org/D26267



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


[PATCH] D26753: ASTImporter: improve support for C++ templates

2016-11-16 Thread Aleksei Sidorin via cfe-commits
a.sidorin created this revision.
a.sidorin added reviewers: spyffe, khazem.
a.sidorin added a subscriber: cfe-commits.

- Support template partial specialization
- Avoid infinite recursion in IsStructurallyEquivalent for TemplateArgument 
with implementing IsStructurallyEquivalent for TemplateName


https://reviews.llvm.org/D26753

Files:
  include/clang/AST/TemplateBase.h
  lib/AST/ASTImporter.cpp
  test/ASTMerge/Inputs/class-template-partial-spec1.cpp
  test/ASTMerge/Inputs/class-template-partial-spec2.cpp
  test/ASTMerge/class-template-partial-spec.cpp

Index: test/ASTMerge/class-template-partial-spec.cpp
===
--- /dev/null
+++ test/ASTMerge/class-template-partial-spec.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.1.ast %S/Inputs/class-template-partial-spec1.cpp
+// RUN: %clang_cc1 -emit-pch -std=c++1z -o %t.2.ast %S/Inputs/class-template-partial-spec2.cpp
+// RUN: not %clang_cc1 -std=c++1z -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s
+
+static_assert(sizeof(**SingleSource.member) == sizeof(**SingleDest.member));
+static_assert(sizeof(SecondDoubleSource.member) == sizeof(SecondDoubleDest.member));
+static_assert(NumberSource.val == NumberDest.val);
+
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/Inputs/class-template-partial-spec2.cpp:21:32: error: external variable 'X1' declared with incompatible types in different translation units ('TwoOptionTemplate' vs. 'TwoOptionTemplate')
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/Inputs/class-template-partial-spec1.cpp:21:31: note: declared here with type 'TwoOptionTemplate'
+
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/Inputs/class-template-partial-spec2.cpp:24:29: error: external variable 'X4' declared with incompatible types in different translation units ('TwoOptionTemplate' vs. 'TwoOptionTemplate')
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/Inputs/class-template-partial-spec1.cpp:24:33: note: declared here with type 'TwoOptionTemplate'
+
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/Inputs/class-template-partial-spec1.cpp:38:8: warning: type 'IntTemplateSpec<5, void *>' has incompatible definitions in different translation units
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/Inputs/class-template-partial-spec1.cpp:39:7: note: field 'member' has type 'int' here
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/Inputs/class-template-partial-spec2.cpp:39:10: note: field 'member' has type 'double' here
+
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/Inputs/class-template-partial-spec2.cpp:47:25: error: external variable 'Y3' declared with incompatible types in different translation units ('IntTemplateSpec<2, int>' vs. 'IntTemplateSpec<3, int>')
+// CHECK: /media/build/smrc-llvm/master/llvm/tools/clang/test/ASTMerge/Inputs/class-template-partial-spec1.cpp:47:25: note: declared here with type 'IntTemplateSpec<3, int>'
+
Index: test/ASTMerge/Inputs/class-template-partial-spec2.cpp
===
--- /dev/null
+++ test/ASTMerge/Inputs/class-template-partial-spec2.cpp
@@ -0,0 +1,48 @@
+template
+struct TwoOptionTemplate {};
+
+template
+struct TwoOptionTemplate {
+  int member;
+};
+
+
+template
+struct TwoOptionTemplate {
+  float member;
+};
+
+template
+struct TwoOptionTemplate {
+  T** member;
+};
+
+TwoOptionTemplate X0;
+TwoOptionTemplate X1;
+TwoOptionTemplate X2;
+TwoOptionTemplate X3;
+TwoOptionTemplate X4;
+TwoOptionTemplate SingleDest;
+TwoOptionTemplate SecondDoubleDest;
+
+
+template
+struct IntTemplateSpec {};
+
+template
+struct IntTemplateSpec<4, C> {
+  C member;
+};
+
+template
+struct IntTemplateSpec {
+  double member;
+  const int val = I;
+};
+
+
+IntTemplateSpec<4, wchar_t> Y0;
+IntTemplateSpec<5, void *> Y1;
+IntTemplateSpec<1, int> Y2;
+IntTemplateSpec<2, int> Y3;
+IntTemplateSpec<42, void *> NumberDest;
Index: test/ASTMerge/Inputs/class-template-partial-spec1.cpp
===
--- /dev/null
+++ test/ASTMerge/Inputs/class-template-partial-spec1.cpp
@@ -0,0 +1,48 @@
+template
+struct TwoOptionTemplate {};
+
+template
+struct TwoOptionTemplate {
+  int member;
+};
+
+
+template
+struct TwoOptionTemplate {
+  float member;
+};
+
+template
+struct TwoOptionTemplate {
+  T** member;
+};
+
+TwoOptionTemplate X0;
+TwoOptionTemplate X1;
+TwoOptionTemplate X2;
+TwoOptionTemplate X3;
+TwoOptionTemplate X4;
+TwoOptionTemplate SingleSource;
+TwoOptionTemplate SecondDoubleSource;
+
+
+template
+struct IntTemplateSpec {};
+
+template
+struct IntTemplateSpec<4, C> {
+  C member;
+};
+
+template
+struct IntTemplateSpec {
+  int member;
+  const int val = I;
+};
+
+
+IntTemplateSpec<4, wchar_t> Y0;
+IntTemplateSpec<5, void *> Y1;
+

[PATCH] D26745: [Frontend] Allow attaching an external sema source to compiler instance and extra diags to TypoCorrections

2016-11-16 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL287128: [Frontend] Allow attaching an external sema source 
to compiler instance and… (authored by d0k).

Changed prior to commit:
  https://reviews.llvm.org/D26745?vs=78179&id=78213#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26745

Files:
  cfe/trunk/include/clang/Frontend/CompilerInstance.h
  cfe/trunk/include/clang/Sema/TypoCorrection.h
  cfe/trunk/lib/Frontend/CompilerInstance.cpp
  cfe/trunk/lib/Sema/SemaLookup.cpp
  cfe/trunk/unittests/Frontend/FrontendActionTest.cpp

Index: cfe/trunk/lib/Frontend/CompilerInstance.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp
@@ -538,6 +538,11 @@
   CodeCompleteConsumer *CompletionConsumer) {
   TheSema.reset(new Sema(getPreprocessor(), getASTContext(), getASTConsumer(),
  TUKind, CompletionConsumer));
+  // Attach the external sema source if there is any.
+  if (ExternalSemaSrc) {
+TheSema->addExternalSource(ExternalSemaSrc.get());
+ExternalSemaSrc->InitializeSema(*TheSema);
+  }
 }
 
 // Output Files
@@ -1820,3 +1825,8 @@
   return false;
 }
 void CompilerInstance::resetAndLeakSema() { BuryPointer(takeSema()); }
+
+void CompilerInstance::setExternalSemaSource(
+IntrusiveRefCntPtr ESS) {
+  ExternalSemaSrc = std::move(ESS);
+}
Index: cfe/trunk/lib/Sema/SemaLookup.cpp
===
--- cfe/trunk/lib/Sema/SemaLookup.cpp
+++ cfe/trunk/lib/Sema/SemaLookup.cpp
@@ -5082,6 +5082,10 @@
   if (PrevNote.getDiagID() && ChosenDecl)
 Diag(ChosenDecl->getLocation(), PrevNote)
   << CorrectedQuotedStr << (ErrorRecovery ? FixItHint() : FixTypo);
+
+  // Add any extra diagnostics.
+  for (const PartialDiagnostic &PD : Correction.getExtraDiagnostics())
+Diag(Correction.getCorrectionRange().getBegin(), PD);
 }
 
 TypoExpr *Sema::createDelayedTypo(std::unique_ptr TCC,
Index: cfe/trunk/unittests/Frontend/FrontendActionTest.cpp
===
--- cfe/trunk/unittests/Frontend/FrontendActionTest.cpp
+++ cfe/trunk/unittests/Frontend/FrontendActionTest.cpp
@@ -13,6 +13,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Sema/Sema.h"
@@ -192,4 +193,66 @@
   ASSERT_TRUE(TestAction.SeenEnd);
 }
 
+class TypoExternalSemaSource : public ExternalSemaSource {
+  CompilerInstance &CI;
+
+public:
+  TypoExternalSemaSource(CompilerInstance &CI) : CI(CI) {}
+
+  TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, int LookupKind,
+ Scope *S, CXXScopeSpec *SS,
+ CorrectionCandidateCallback &CCC,
+ DeclContext *MemberContext, bool EnteringContext,
+ const ObjCObjectPointerType *OPT) override {
+// Generate a fake typo correction with one attached note.
+ASTContext &Ctx = CI.getASTContext();
+TypoCorrection TC(DeclarationName(&Ctx.Idents.get("moo")));
+unsigned DiagID = Ctx.getDiagnostics().getCustomDiagID(
+DiagnosticsEngine::Note, "This is a note");
+TC.addExtraDiagnostic(PartialDiagnostic(DiagID, Ctx.getDiagAllocator()));
+return TC;
+  }
+};
+
+struct TypoDiagnosticConsumer : public DiagnosticConsumer {
+  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+const Diagnostic &Info) override {
+// Capture errors and notes. There should be one of each.
+if (DiagLevel == DiagnosticsEngine::Error) {
+  assert(Error.empty());
+  Info.FormatDiagnostic(Error);
+} else {
+  assert(Note.empty());
+  Info.FormatDiagnostic(Note);
+}
+  }
+  SmallString<32> Error;
+  SmallString<32> Note;
+};
+
+TEST(ASTFrontendAction, ExternalSemaSource) {
+  auto *Invocation = new CompilerInvocation;
+  Invocation->getLangOpts()->CPlusPlus = true;
+  Invocation->getPreprocessorOpts().addRemappedFile(
+  "test.cc", MemoryBuffer::getMemBuffer("void fooo();\n"
+"int main() { foo(); }")
+ .release());
+  Invocation->getFrontendOpts().Inputs.push_back(
+  FrontendInputFile("test.cc", IK_CXX));
+  Invocation->getFrontendOpts().ProgramAction = frontend::ParseSyntaxOnly;
+  Invocation->getTargetOpts().Triple = "i386-unknown-linux-gnu";
+  CompilerInstance Compiler;
+  Compiler.setInvocation(Invocation);
+  auto *TDC = new TypoDiagnosticConsumer;
+  Compiler.createDiagnostics(TDC, /*ShouldOwnClient=*/true);
+  Compiler.setExternalSemaSource(new TypoExternalSemaSource(Compiler));
+
+  SyntaxOnlyAction TestAction;
+  ASSERT_

r287128 - [Frontend] Allow attaching an external sema source to compiler instance and extra diags to TypoCorrections

2016-11-16 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Nov 16 12:15:26 2016
New Revision: 287128

URL: http://llvm.org/viewvc/llvm-project?rev=287128&view=rev
Log:
[Frontend] Allow attaching an external sema source to compiler instance and 
extra diags to TypoCorrections

This can be used to append alternative typo corrections to an existing diag.
include-fixer can use it to suggest includes to be added.

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

Modified:
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/include/clang/Sema/TypoCorrection.h
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/unittests/Frontend/FrontendActionTest.cpp

Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=287128&r1=287127&r2=287128&view=diff
==
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Wed Nov 16 12:15:26 2016
@@ -96,6 +96,9 @@ class CompilerInstance : public ModuleLo
   /// The AST context.
   IntrusiveRefCntPtr Context;
 
+  /// An optional sema source that will be attached to sema.
+  IntrusiveRefCntPtr ExternalSemaSrc;
+
   /// The AST consumer.
   std::unique_ptr Consumer;
 
@@ -774,6 +777,8 @@ public:
   void addDependencyCollector(std::shared_ptr Listener) {
 DependencyCollectors.push_back(std::move(Listener));
   }
+
+  void setExternalSemaSource(IntrusiveRefCntPtr ESS);
 };
 
 } // end namespace clang

Modified: cfe/trunk/include/clang/Sema/TypoCorrection.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/TypoCorrection.h?rev=287128&r1=287127&r2=287128&view=diff
==
--- cfe/trunk/include/clang/Sema/TypoCorrection.h (original)
+++ cfe/trunk/include/clang/Sema/TypoCorrection.h Wed Nov 16 12:15:26 2016
@@ -230,6 +230,15 @@ public:
   bool requiresImport() const { return RequiresImport; }
   void setRequiresImport(bool Req) { RequiresImport = Req; }
 
+  /// Extra diagnostics are printed after the first diagnostic for the typo.
+  /// This can be used to attach external notes to the diag.
+  void addExtraDiagnostic(PartialDiagnostic PD) {
+ExtraDiagnostics.push_back(std::move(PD));
+  }
+  ArrayRef getExtraDiagnostics() const {
+return ExtraDiagnostics;
+  }
+
 private:
   bool hasCorrectionDecl() const {
 return (!isKeyword() && !CorrectionDecls.empty());
@@ -245,6 +254,8 @@ private:
   SourceRange CorrectionRange;
   bool ForceSpecifierReplacement;
   bool RequiresImport;
+
+  std::vector ExtraDiagnostics;
 };
 
 /// @brief Base class for callback objects used by Sema::CorrectTypo to check

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=287128&r1=287127&r2=287128&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Wed Nov 16 12:15:26 2016
@@ -538,6 +538,11 @@ void CompilerInstance::createSema(Transl
   CodeCompleteConsumer *CompletionConsumer) {
   TheSema.reset(new Sema(getPreprocessor(), getASTContext(), getASTConsumer(),
  TUKind, CompletionConsumer));
+  // Attach the external sema source if there is any.
+  if (ExternalSemaSrc) {
+TheSema->addExternalSource(ExternalSemaSrc.get());
+ExternalSemaSrc->InitializeSema(*TheSema);
+  }
 }
 
 // Output Files
@@ -1820,3 +1825,8 @@ CompilerInstance::lookupMissingImports(S
   return false;
 }
 void CompilerInstance::resetAndLeakSema() { BuryPointer(takeSema()); }
+
+void CompilerInstance::setExternalSemaSource(
+IntrusiveRefCntPtr ESS) {
+  ExternalSemaSrc = std::move(ESS);
+}

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=287128&r1=287127&r2=287128&view=diff
==
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Nov 16 12:15:26 2016
@@ -5082,6 +5082,10 @@ void Sema::diagnoseTypo(const TypoCorrec
   if (PrevNote.getDiagID() && ChosenDecl)
 Diag(ChosenDecl->getLocation(), PrevNote)
   << CorrectedQuotedStr << (ErrorRecovery ? FixItHint() : FixTypo);
+
+  // Add any extra diagnostics.
+  for (const PartialDiagnostic &PD : Correction.getExtraDiagnostics())
+Diag(Correction.getCorrectionRange().getBegin(), PD);
 }
 
 TypoExpr *Sema::createDelayedTypo(std::unique_ptr TCC,

Modified: cfe/trunk/unittests/Frontend/FrontendActionTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Frontend/FrontendActionTest.cpp?rev=287128&r1=287127&r2=287128&v

r287129 - Fixed layout of test/ASTMerge.

2016-11-16 Thread Sean Callanan via cfe-commits
Author: spyffe
Date: Wed Nov 16 12:21:00 2016
New Revision: 287129

URL: http://llvm.org/viewvc/llvm-project?rev=287129&view=rev
Log:
Fixed layout of test/ASTMerge.

As outlined in a previous RFC, the test/ASTMerge/Inputs folder is getting full 
and the tests are starting to become interdependent. This is undesirable because

- it makes it harder to write new tests
- it makes it harder to figure out at a glance what old tests are doing, and
- it adds the risk of breaking one test while changing a different one, because 
of the interdependencies.

To fix this, according to the conversation in the RFC, I have changed the 
layout from

a.c
Inputs/a1.c
Inputs/a2.c

to

a/test.c
a/Inputs/a1.c
a/Inputs/a2.c
for all existing tests. I have also eliminated interdependencies by replicating 
the input files for each test that uses them.

https://reviews.llvm.org/D26571

Added:
cfe/trunk/test/ASTMerge/anonymous-fields/
cfe/trunk/test/ASTMerge/anonymous-fields/Inputs/
cfe/trunk/test/ASTMerge/anonymous-fields/Inputs/anonymous-fields1.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/anonymous-fields1.cpp
cfe/trunk/test/ASTMerge/anonymous-fields/Inputs/anonymous-fields2.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/anonymous-fields2.cpp
cfe/trunk/test/ASTMerge/anonymous-fields/test.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/anonymous-fields.cpp
cfe/trunk/test/ASTMerge/asm/
cfe/trunk/test/ASTMerge/asm/Inputs/
cfe/trunk/test/ASTMerge/asm/Inputs/asm-function.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/asm-function.cpp
cfe/trunk/test/ASTMerge/asm/test.cpp
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/asm.cpp
cfe/trunk/test/ASTMerge/category/
cfe/trunk/test/ASTMerge/category/Inputs/
cfe/trunk/test/ASTMerge/category/Inputs/category1.m
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/category1.m
cfe/trunk/test/ASTMerge/category/Inputs/category2.m
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/category2.m
cfe/trunk/test/ASTMerge/category/test.m
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/category.m
cfe/trunk/test/ASTMerge/class/
cfe/trunk/test/ASTMerge/class-template/
cfe/trunk/test/ASTMerge/class-template/Inputs/
cfe/trunk/test/ASTMerge/class-template/Inputs/class-template1.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/class-template1.cpp
cfe/trunk/test/ASTMerge/class-template/Inputs/class-template2.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/Inputs/class-template2.cpp
cfe/trunk/test/ASTMerge/class-template/test.cpp
  - copied unchanged from r287128, 
cfe/trunk/test/ASTMerge/class-template.cpp
cfe/trunk/test/ASTMerge/class/Inputs/
cfe/trunk/test/ASTMerge/class/Inputs/class1.cpp
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/class1.cpp
cfe/trunk/test/ASTMerge/class/Inputs/class2.cpp
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/class2.cpp
cfe/trunk/test/ASTMerge/class/test.cpp
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/class.cpp
cfe/trunk/test/ASTMerge/class2/
cfe/trunk/test/ASTMerge/class2/Inputs/
cfe/trunk/test/ASTMerge/class2/Inputs/class3.cpp
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/class3.cpp
cfe/trunk/test/ASTMerge/class2/test.cpp
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/class2.cpp
cfe/trunk/test/ASTMerge/codegen-body/
cfe/trunk/test/ASTMerge/codegen-body/Inputs/
cfe/trunk/test/ASTMerge/codegen-body/Inputs/body1.c
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/body1.c
cfe/trunk/test/ASTMerge/codegen-body/Inputs/body2.c
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/body2.c
cfe/trunk/test/ASTMerge/codegen-body/test.c
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/codegen-body.c
cfe/trunk/test/ASTMerge/codegen-exprs/
cfe/trunk/test/ASTMerge/codegen-exprs/Inputs/
cfe/trunk/test/ASTMerge/codegen-exprs/Inputs/exprs1.c
  - copied unchanged from r286635, cfe/trunk/test/ASTMerge/Inputs/exprs1.c
cfe/trunk/test/ASTMerge/codegen-exprs/Inputs/exprs2.c
  - copied unchanged from r286635, cfe/trunk/test/ASTMerge/Inputs/exprs2.c
cfe/trunk/test/ASTMerge/codegen-exprs/test.c
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/codegen-exprs.c
cfe/trunk/test/ASTMerge/enum/
cfe/trunk/test/ASTMerge/enum/Inputs/
cfe/trunk/test/ASTMerge/enum/Inputs/enum1.c
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/enum1.c
cfe/trunk/test/ASTMerge/enum/Inputs/enum2.c
  - copied unchanged from r287128, cfe/trunk/test/ASTMerge/Inputs/enum2.c
cfe/trunk/test/ASTMerge/enum/test.c
  - copied unchanged from r287128, cfe/trunk/te

[PATCH] D26571: Clean up layout of ASTMerge tests

2016-11-16 Thread Sean Callanan via cfe-commits
spyffe closed this revision.
spyffe added a comment.

Committed r287129


Repository:
  rL LLVM

https://reviews.llvm.org/D26571



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


[PATCH] D26415: [XRay] Support AArch64 in Clang

2016-11-16 Thread Serge Rogatch via cfe-commits
rSerge updated this revision to Diff 78216.
rSerge added a comment.

Rebased to the latest version of LLVM sources.


https://reviews.llvm.org/D26415

Files:
  lib/Driver/Tools.cpp
  test/Driver/XRay/xray-instrument-cpu.c
  test/Driver/XRay/xray-instrument-os.c


Index: test/Driver/XRay/xray-instrument-os.c
===
--- test/Driver/XRay/xray-instrument-os.c
+++ test/Driver/XRay/xray-instrument-os.c
@@ -1,4 +1,4 @@
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
 // XFAIL: -linux-
-// REQUIRES-ANY: amd64, x86_64, x86_64h, arm
+// REQUIRES-ANY: amd64, x86_64, x86_64h, arm, aarch64, arm64
 typedef int a;
Index: test/Driver/XRay/xray-instrument-cpu.c
===
--- test/Driver/XRay/xray-instrument-cpu.c
+++ test/Driver/XRay/xray-instrument-cpu.c
@@ -1,4 +1,4 @@
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: amd64-, x86_64-, x86_64h-, arm
+// XFAIL: amd64-, x86_64-, x86_64h-, arm, aarch64, arm64
 // REQUIRES: linux
 typedef int a;
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4900,14 +4900,20 @@
   if (Args.hasFlag(options::OPT_fxray_instrument,
options::OPT_fnoxray_instrument, false)) {
 const char *const XRayInstrumentOption = "-fxray-instrument";
-if (Triple.getOS() == llvm::Triple::Linux &&
-(Triple.getArch() == llvm::Triple::arm ||
- Triple.getArch() == llvm::Triple::x86_64)) {
-  // Supported.
-} else {
+if (Triple.getOS() == llvm::Triple::Linux)
+  switch (Triple.getArch()) {
+  case llvm::Triple::x86_64:
+  case llvm::Triple::arm:
+  case llvm::Triple::aarch64:
+// Supported.
+break;
+  default:
+D.Diag(diag::err_drv_clang_unsupported)
+<< (std::string(XRayInstrumentOption) + " on " + Triple.str());
+  }
+else
   D.Diag(diag::err_drv_clang_unsupported)
-  << (std::string(XRayInstrumentOption) + " on " + Triple.str());
-}
+  << (std::string(XRayInstrumentOption) + " on non-Linux target OS");
 CmdArgs.push_back(XRayInstrumentOption);
 if (const Arg *A =
 Args.getLastArg(options::OPT_fxray_instruction_threshold_,


Index: test/Driver/XRay/xray-instrument-os.c
===
--- test/Driver/XRay/xray-instrument-os.c
+++ test/Driver/XRay/xray-instrument-os.c
@@ -1,4 +1,4 @@
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
 // XFAIL: -linux-
-// REQUIRES-ANY: amd64, x86_64, x86_64h, arm
+// REQUIRES-ANY: amd64, x86_64, x86_64h, arm, aarch64, arm64
 typedef int a;
Index: test/Driver/XRay/xray-instrument-cpu.c
===
--- test/Driver/XRay/xray-instrument-cpu.c
+++ test/Driver/XRay/xray-instrument-cpu.c
@@ -1,4 +1,4 @@
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: amd64-, x86_64-, x86_64h-, arm
+// XFAIL: amd64-, x86_64-, x86_64h-, arm, aarch64, arm64
 // REQUIRES: linux
 typedef int a;
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4900,14 +4900,20 @@
   if (Args.hasFlag(options::OPT_fxray_instrument,
options::OPT_fnoxray_instrument, false)) {
 const char *const XRayInstrumentOption = "-fxray-instrument";
-if (Triple.getOS() == llvm::Triple::Linux &&
-(Triple.getArch() == llvm::Triple::arm ||
- Triple.getArch() == llvm::Triple::x86_64)) {
-  // Supported.
-} else {
+if (Triple.getOS() == llvm::Triple::Linux)
+  switch (Triple.getArch()) {
+  case llvm::Triple::x86_64:
+  case llvm::Triple::arm:
+  case llvm::Triple::aarch64:
+// Supported.
+break;
+  default:
+D.Diag(diag::err_drv_clang_unsupported)
+<< (std::string(XRayInstrumentOption) + " on " + Triple.str());
+  }
+else
   D.Diag(diag::err_drv_clang_unsupported)
-  << (std::string(XRayInstrumentOption) + " on " + Triple.str());
-}
+  << (std::string(XRayInstrumentOption) + " on non-Linux target OS");
 CmdArgs.push_back(XRayInstrumentOption);
 if (const Arg *A =
 Args.getLastArg(options::OPT_fxray_instruction_threshold_,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26503: [Parser][ObjC] Improve diagnostics and recovery when C++ keywords are used as identifiers in Objective-C++

2016-11-16 Thread Alex Lorenz via cfe-commits
arphaman updated this revision to Diff 78218.
arphaman marked 4 inline comments as done.
arphaman added a comment.

Addressed review comments by renaming the diagnostic and simplifying the name 
and the use of the `expectIdentifier ` method.


Repository:
  rL LLVM

https://reviews.llvm.org/D26503

Files:
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/IdentifierTable.h
  include/clang/Parse/Parser.h
  lib/Basic/IdentifierTable.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseObjc.cpp
  lib/Parse/Parser.cpp
  test/Parser/objc-cxx-keyword-identifiers.mm

Index: test/Parser/objc-cxx-keyword-identifiers.mm
===
--- /dev/null
+++ test/Parser/objc-cxx-keyword-identifiers.mm
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wno-objc-root-class -Wno-incomplete-implementation -triple x86_64-apple-macosx10.10.0 -verify %s
+
+// rdar://20626062
+
+struct S {
+  int throw; // expected-error {{expected member name or ';' after declaration specifiers; 'throw' is a keyword in Objective-C++}}
+};
+
+@interface class // expected-error {{expected identifier; 'class' is a keyword in Objective-C++}}
+@end
+
+@interface Bar: class // expected-error {{expected identifier; 'class' is a keyword in Objective-C++}}
+@end
+
+@protocol P // ok
+@end
+
+@protocol new // expected-error {{expected identifier; 'new' is a keyword in Objective-C++}}
+@end
+
+@protocol P2, delete; // expected-error {{expected identifier; 'delete' is a keyword in Objective-C++}}
+
+@class Foo, try; // expected-error {{expected identifier; 'try' is a keyword in Objective-C++}}
+
+@interface Foo
+
+@property (readwrite, nonatomic) int a, b, throw; // expected-error {{expected member name or ';' after declaration specifiers; 'throw' is a keyword in Objective-C++}}
+
+-foo:(int)class; // expected-error {{expected identifier; 'class' is a keyword in Objective-C++}}
++foo:(int)constexpr; // expected-error {{expected identifier; 'constexpr' is a keyword in Objective-C++}}
+
+@end
+
+@interface Foo ()  // expected-error {{expected identifier; 'new' is a keyword in Objective-C++}}
+@end
+
+@implementation Foo
+
+@synthesize a = _a; // ok
+@synthesize b = virtual; // expected-error {{expected identifier; 'virtual' is a keyword in Objective-C++}}
+
+@dynamic throw; // expected-error {{expected identifier; 'throw' is a keyword in Objective-C++}}
+
+-foo:(int)class { // expected-error {{expected identifier; 'class' is a keyword in Objective-C++}}
+}
+
+@end
+
+@implementation class // expected-error {{expected identifier; 'class' is a keyword in Objective-C++}}
+@end
+
+@implementation Bar: class // expected-error {{expected identifier; 'class' is a keyword in Objective-C++}}
+@end
+
+@compatibility_alias C Foo; // ok
+@compatibility_alias const_cast Bar; // expected-error {{expected identifier; 'const_cast' is a keyword in Objective-C++}}
+@compatibility_alias C2 class; // expected-error {{expected identifier; 'class' is a keyword in Objective-C++}}
+
+void func() {
+  (void)@protocol(P); // ok
+  (void)@protocol(delete); // expected-error {{expected identifier; 'delete' is a keyword in Objective-C++}}
+}
Index: lib/Parse/Parser.cpp
===
--- lib/Parse/Parser.cpp
+++ lib/Parse/Parser.cpp
@@ -232,6 +232,21 @@
   << FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc));
 }
 
+bool Parser::expectIdentifier() {
+  if (Tok.is(tok::identifier))
+return false;
+  if (const auto *II = Tok.getIdentifierInfo()) {
+if (II->isCPlusPlusKeyword(getLangOpts())) {
+  Diag(Tok, diag::err_expected_token_instead_of_objcxx_keyword)
+  << tok::identifier << Tok.getIdentifierInfo();
+  // Objective-C++: Recover by treating this keyword as a valid identifier.
+  return false;
+}
+  }
+  Diag(Tok, diag::err_expected) << tok::identifier;
+  return true;
+}
+
 //===--===//
 // Error recovery.
 //===--===//
Index: lib/Parse/ParseObjc.cpp
===
--- lib/Parse/ParseObjc.cpp
+++ lib/Parse/ParseObjc.cpp
@@ -137,8 +137,7 @@
 
   while (1) {
 MaybeSkipAttributes(tok::objc_class);
-if (Tok.isNot(tok::identifier)) {
-  Diag(Tok, diag::err_expected) << tok::identifier;
+if (expectIdentifier()) {
   SkipUntil(tok::semi);
   return Actions.ConvertDeclToDeclGroup(nullptr);
 }
@@ -229,11 +228,8 @@
 
   MaybeSkipAttributes(tok::objc_interface);
 
-  if (Tok.isNot(tok::identifier)) {
-Diag(Tok, diag::err_expected)
-<< tok::identifier; // missing class or category name.
-return nullptr;
-  }
+  if (expectIdentifier())
+return nullptr; // missing class or category name.
 
   // We have a class or category name - consume it.
   IdentifierInfo *nameId = Tok.getIdentifierInfo();
@@ -3

[PATCH] D26503: [Parser][ObjC] Improve diagnostics and recovery when C++ keywords are used as identifiers in Objective-C++

2016-11-16 Thread Alex Lorenz via cfe-commits
arphaman added inline comments.



Comment at: lib/Parse/ParseDecl.cpp:5405
+  // Objective-C++: Detect C++ keywords and try to prevent further errors 
by
+  // treating these keyword as valid member names.
+  if (getLangOpts().ObjC1 && getLangOpts().CPlusPlus &&

manmanren wrote:
> Does C++ have the same issue? Or is this only needed for Objective-C++?
I suppose it kinda does have it as well, but Objective-C++ has worse error 
recovery for Objective-C declarations in this case, so it's more important for 
it. I wouldn't mind adding a similar diagnostic for C++ though, but I think 
that should be done in a separate patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D26503



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


[PATCH] D26753: ASTImporter: improve support for C++ templates

2016-11-16 Thread Kareem Khazem via cfe-commits
khazem added a comment.

Thanks very much for this patch! It certainly fixes the infinite recursion 
issue on our codebase. It LGTM, but I'd like to add a test case before landing 
it.


https://reviews.llvm.org/D26753



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


[PATCH] D26376: Undef stdatomic.h macro definitions that are defining functions provided in libc++

2016-11-16 Thread Marshall Clow via cfe-commits
mclow.lists added a comment.

More info - The following code:

  #include 
  int main () {}

fails to compile on either gcc 6.2 (locally), gcc 7 head (online compiler) or 
MSVC (online compiler).


https://reviews.llvm.org/D26376



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


r287134 - Fix PR31029 by attaching an artificial debug location to msabi thunks.

2016-11-16 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Wed Nov 16 12:49:47 2016
New Revision: 287134

URL: http://llvm.org/viewvc/llvm-project?rev=287134&view=rev
Log:
Fix PR31029 by attaching an artificial debug location to msabi thunks.
This was a latent bug that was recently uncovered by r286400.

Added:
cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp
Modified:
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=287134&r1=287133&r2=287134&view=diff
==
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Wed Nov 16 12:49:47 2016
@@ -3840,8 +3840,11 @@ MicrosoftCXXABI::getAddrOfCXXCtorClosure
 FunctionArgs.push_back(&IsMostDerived);
 
   // Start defining the function.
+  auto NL = ApplyDebugLocation::CreateEmpty(CGF);
   CGF.StartFunction(GlobalDecl(), FnInfo.getReturnType(), ThunkFn, FnInfo,
 FunctionArgs, CD->getLocation(), SourceLocation());
+  // Create a scope with an artificial location for the body of this function.
+  auto AL = ApplyDebugLocation::CreateArtificial(CGF);
   EmitThisParam(CGF);
   llvm::Value *This = getThisValue(CGF);
 

Added: cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp?rev=287134&view=auto
==
--- cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp Wed Nov 16 12:49:47 
2016
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -triple i386-pc-windows-msvc19.0.0 -emit-obj \
+// RUN: -debug-info-kind=line-tables-only -fms-extensions
+class __declspec(dllexport) A {
+  A(int * = new int) {}
+};
+// CHECK: define {{.*}}void @"\01??_FA@@AAEXXZ"
+// CHECK-SAME: !dbg ![[SP:[0-9]+]]
+// CHECK-NOT: {{ret }}
+// CHECK: call x86_thiscallcc %class.A* @"\01??0A@@AAE@PAH@Z"(%class.A* 
%this1, i32* %0)
+// CHECK-SAME: !dbg ![[DBG:[0-9]+]]
+// CHECK: ret void, !dbg ![[DBG]]
+//
+// CHECK: ![[SP]] = distinct !DISubprogram(
+// CHECK-SAME:  line: 3
+// CHECK-SAME:  isDefinition: true
+// CHECK-SAME:  DIFlagArtificial
+// CHECK-SAME:  ){{$}}
+//
+// CHECK: ![[DBG]] = !DILocation(line: 0


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


[PATCH] D26742: [RecursiveASTVisitor] Fix post-order traversal of UnaryOperator

2016-11-16 Thread Raphael Isemann via cfe-commits
teemperor added a reviewer: rsmith.
teemperor added a comment.

Looks good to me. I'll add Richard because he also merged/approved the original 
post-order patch.


https://reviews.llvm.org/D26742



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


[PATCH] D26753: ASTImporter: improve support for C++ templates

2016-11-16 Thread Sean Callanan via cfe-commits
spyffe requested changes to this revision.
spyffe added a comment.
This revision now requires changes to proceed.

This looks amazing.  I have a few minor quibbles and a testing concern, but 
overall this looks like a great step forward!  Thank you!




Comment at: lib/AST/ASTImporter.cpp:458
+  }
+  return true;
+}

Is this really an appropriate default result?  I would argue for `false` here 
so that an error would propagate, as is typical in ASTImporter.
Note that this does disagree with the original source's `true` but I think that 
was because we knew we didn't handle anything, whereas now the assumption is we 
handle everything.



Comment at: lib/AST/ASTImporter.cpp:496
+return false;
+  if (DN1->isIdentifier())
+return IsStructurallyEquivalent(DN1->getIdentifier(),

We should probably also check whether `DN1->isIdentifier() == 
DN2->isIdentifier()`.



Comment at: lib/AST/ASTImporter.cpp:520
+  }
   return true;
 }

As above, I'd argue for `false` here now that we're flipping to the assumption 
that this code is complete.



Comment at: lib/AST/ASTImporter.cpp:4911
+
+if (D->getTypeAsWritten()) {
+  TypeSourceInfo *TInfo = Importer.Import(D->getTypeAsWritten());

Could you assign this to a variable here, to avoid the redundant call a line 
below?



Comment at: lib/AST/ASTImporter.cpp:4931
 LexicalDC->addDeclInternal(D2);
+
   }

This blank line is probably not needed.



Comment at: lib/AST/ASTImporter.cpp:7035
 
 NestedNameSpecifierLoc ASTImporter::Import(NestedNameSpecifierLoc FromNNS) {
+  // Copied from NestedNameSpecifier mostly.

Is this function properly covered by the test?  I would like to see some 
deeply-neded name specifiers in the test, with entries for all the cases here.
If I'm missing the part of the test that covers this, please let me know.


https://reviews.llvm.org/D26753



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


r287138 - Rangify for loops, NFC.

2016-11-16 Thread Yaron Keren via cfe-commits
Author: yrnkrn
Date: Wed Nov 16 13:24:10 2016
New Revision: 287138

URL: http://llvm.org/viewvc/llvm-project?rev=287138&view=rev
Log:
Rangify for loops, NFC.


Modified:
cfe/trunk/lib/Frontend/DependencyFile.cpp

Modified: cfe/trunk/lib/Frontend/DependencyFile.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DependencyFile.cpp?rev=287138&r1=287137&r2=287138&view=diff
==
--- cfe/trunk/lib/Frontend/DependencyFile.cpp (original)
+++ cfe/trunk/lib/Frontend/DependencyFile.cpp Wed Nov 16 13:24:10 2016
@@ -409,9 +409,8 @@ void DFGImpl::OutputDependencyFile() {
   const unsigned MaxColumns = 75;
   unsigned Columns = 0;
 
-  for (std::vector::iterator
- I = Targets.begin(), E = Targets.end(); I != E; ++I) {
-unsigned N = I->length();
+  for (StringRef Target : Targets) {
+unsigned N = Target.size();
 if (Columns == 0) {
   Columns += N;
 } else if (Columns + N + 2 > MaxColumns) {
@@ -422,7 +421,7 @@ void DFGImpl::OutputDependencyFile() {
   OS << ' ';
 }
 // Targets already quoted as needed.
-OS << *I;
+OS << Target;
   }
 
   OS << ':';
@@ -430,18 +429,17 @@ void DFGImpl::OutputDependencyFile() {
 
   // Now add each dependency in the order it was seen, but avoiding
   // duplicates.
-  for (std::vector::iterator I = Files.begin(),
- E = Files.end(); I != E; ++I) {
+  for (StringRef File : Files) {
 // Start a new line if this would exceed the column limit. Make
 // sure to leave space for a trailing " \" in case we need to
 // break the line on the next iteration.
-unsigned N = I->length();
+unsigned N = File.size();
 if (Columns + (N + 1) + 2 > MaxColumns) {
   OS << " \\\n ";
   Columns = 2;
 }
 OS << ' ';
-PrintFilename(OS, *I, OutputFormat);
+PrintFilename(OS, File, OutputFormat);
 Columns += N + 1;
   }
   OS << '\n';
@@ -449,10 +447,9 @@ void DFGImpl::OutputDependencyFile() {
   // Create phony targets if requested.
   if (PhonyTarget && !Files.empty()) {
 // Skip the first entry, this is always the input file itself.
-for (std::vector::iterator I = Files.begin() + 1,
-   E = Files.end(); I != E; ++I) {
+for (StringRef File : Files) {
   OS << '\n';
-  PrintFilename(OS, *I, OutputFormat);
+  PrintFilename(OS, File, OutputFormat);
   OS << ":\n";
 }
   }


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


r287139 - Add the missing FileCheck invocation to this testcase.

2016-11-16 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Wed Nov 16 13:26:11 2016
New Revision: 287139

URL: http://llvm.org/viewvc/llvm-project?rev=287139&view=rev
Log:
Add the missing FileCheck invocation to this testcase.

Modified:
cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp

Modified: cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp?rev=287139&r1=287138&r2=287139&view=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp Wed Nov 16 13:26:11 
2016
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 %s -triple i386-pc-windows-msvc19.0.0 -emit-obj \
-// RUN: -debug-info-kind=line-tables-only -fms-extensions
+// RUN: %clang_cc1 %s -triple i386-pc-windows-msvc19.0.0 -emit-llvm \
+// RUN: -debug-info-kind=line-tables-only -fms-extensions -o - | FileCheck 
%s
 class __declspec(dllexport) A {
   A(int * = new int) {}
 };
@@ -8,12 +8,13 @@ class __declspec(dllexport) A {
 // CHECK-NOT: {{ret }}
 // CHECK: call x86_thiscallcc %class.A* @"\01??0A@@AAE@PAH@Z"(%class.A* 
%this1, i32* %0)
 // CHECK-SAME: !dbg ![[DBG:[0-9]+]]
-// CHECK: ret void, !dbg ![[DBG]]
+// CHECK: ret void, !dbg ![[DBG1:[0-9]+]]
 //
 // CHECK: ![[SP]] = distinct !DISubprogram(
-// CHECK-SAME:  line: 3
+// CHECK-SAME:  line: 4
 // CHECK-SAME:  isDefinition: true
 // CHECK-SAME:  DIFlagArtificial
 // CHECK-SAME:  ){{$}}
 //
+// CHECK: ![[DBG1]] = !DILocation(line: 0
 // CHECK: ![[DBG]] = !DILocation(line: 0


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


r287141 - Relax testcase.

2016-11-16 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Wed Nov 16 13:31:44 2016
New Revision: 287141

URL: http://llvm.org/viewvc/llvm-project?rev=287141&view=rev
Log:
Relax testcase.
This removes checks that are irrelevant for what is being tested.

Modified:
cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp

Modified: cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp?rev=287141&r1=287140&r2=287141&view=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-thunk-msabi.cpp Wed Nov 16 13:31:44 
2016
@@ -6,9 +6,9 @@ class __declspec(dllexport) A {
 // CHECK: define {{.*}}void @"\01??_FA@@AAEXXZ"
 // CHECK-SAME: !dbg ![[SP:[0-9]+]]
 // CHECK-NOT: {{ret }}
-// CHECK: call x86_thiscallcc %class.A* @"\01??0A@@AAE@PAH@Z"(%class.A* 
%this1, i32* %0)
+// CHECK: call x86_thiscallcc %class.A* @"\01??0A@@AAE@PAH@Z"
 // CHECK-SAME: !dbg ![[DBG:[0-9]+]]
-// CHECK: ret void, !dbg ![[DBG1:[0-9]+]]
+// CHECK: ret void, !dbg
 //
 // CHECK: ![[SP]] = distinct !DISubprogram(
 // CHECK-SAME:  line: 4
@@ -16,5 +16,4 @@ class __declspec(dllexport) A {
 // CHECK-SAME:  DIFlagArtificial
 // CHECK-SAME:  ){{$}}
 //
-// CHECK: ![[DBG1]] = !DILocation(line: 0
 // CHECK: ![[DBG]] = !DILocation(line: 0


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


[PATCH] D24933: Enable configuration files in clang

2016-11-16 Thread Hans Wennborg via cfe-commits
hans added a subscriber: srhines.
hans added a comment.

I'm still skeptical, but I think this is an improvement over the previous patch.

I think your best bet to get this landed is to find someone from the cfe-dev 
thread who is in favour of config files and have them review it.

I'm also cc'ing srhines who might be interested in this since he works on the 
Android toolchains and this patch has configuring cross-compilers as one of its 
motivations.




Comment at: docs/UsersManual.rst:667
+extension `cfg` if it is not specified yet, and the obtained file name is 
searched
+for in the directories: `~/.llvm` and the directory where clang executable 
resides.
+The first found file is used. It is an error if the required file cannot be 
found.

The "add .cfg extension" magic seems a little awkward. It seems this is mixing 
the possibility of taking a filename and taking some other name.

For `clang --config myfile.cfg`, should it also search the current working 
directory?

I'm not keen on it searching in `~/.llvm`.



Comment at: docs/UsersManual.rst:694
+the including file. For instance if a config file `~/.llvm/target.cfg` contains
+directive `os/linux.opts`, the file `linux.opts` is searched for in the 
directory
+`~/.llvm/os`.

I guess you mean directive `@os/linux.opts`?



Comment at: test/Driver/config-file.c:10
+
+// RUN: not %clang --config inexistent.cfg -c %s -### 2>&1 | FileCheck %s 
-check-prefix CHECK-INEX-NOSEARCH
+// CHECK-INEX-NOSEARCH: Configuration {{.*}}inexistent.cfg' specified by 
option '--config' cannot be found in directories:

This test will fail if I have a `~/.llvm/inexistent.cfg` file on my machine.



Comment at: test/Driver/config-file.c:13
+// CHECK-INEX-NOSEARCH: ~/.llvm
+// CHECK-INEX-NOSEARCH: /etc/llvm
+

Where did `/etc/llvm` come from?



Comment at: test/Driver/config-file.c:14
+// CHECK-INEX-NOSEARCH: /etc/llvm
+
+// RUN: %clang --config %S/Inputs/config-2.cfg -### 2>&1 | FileCheck %s 
-check-prefix CHECK-HHH-NOFILE

There is no test checking the functionality that finds a config file based on 
the clang executable name.


https://reviews.llvm.org/D24933



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


[PATCH] D26559: Insert a type check before reading vtable.

2016-11-16 Thread Ivan Krasin via cfe-commits
krasin updated this revision to Diff 78240.
krasin marked an inline comment as done.
krasin added a comment.

Sync to Clang ToT.


https://reviews.llvm.org/D26559

Files:
  lib/CodeGen/CGExprCXX.cpp
  test/CodeGenCXX/ubsan-vtable-checks.cpp

Index: test/CodeGenCXX/ubsan-vtable-checks.cpp
===
--- /dev/null
+++ test/CodeGenCXX/ubsan-vtable-checks.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -emit-llvm -fsanitize=null %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NULL --check-prefix=ITANIUM
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-windows -emit-llvm -fsanitize=null %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NULL --check-prefix=MSABI
+// RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -emit-llvm -fsanitize=vptr %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-VPTR --check-prefix=ITANIUM
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-windows -emit-llvm -fsanitize=vptr %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-VPTR --check-prefix=MSABI
+struct T {
+  virtual ~T() {}
+  virtual int v() { return 1; }
+};
+
+struct U : T {
+  ~U();
+  virtual int v() { return 2; }
+};
+
+U::~U() {}
+
+// ITANIUM: define i32 @_Z5get_vP1T
+// MSABI: define i32 @"\01?get_v
+int get_v(T* t) {
+  // First, we check that vtable is not loaded before a type check.
+  // CHECK-NULL-NOT: load {{.*}} (%struct.T*{{.*}})**, {{.*}} (%struct.T*{{.*}})***
+  // CHECK-NULL: [[UBSAN_CMP_RES:%[0-9]+]] = icmp ne %struct.T* %{{[_a-z0-9]+}}, null
+  // CHECK-NULL-NEXT: br i1 [[UBSAN_CMP_RES]], label %cont, label %handler.type_mismatch
+  // CHECK-NULL: call void @__ubsan_handle_type_mismatch_abort
+  // Second, we check that vtable is actually loaded once the type check is done.
+  // CHECK-NULL: load {{.*}} (%struct.T*{{.*}})**, {{.*}} (%struct.T*{{.*}})***
+  return t->v();
+}
+
+// ITANIUM: define void @_Z9delete_itP1T
+// MSABI: define void @"\01?delete_it
+void delete_it(T *t) {
+  // First, we check that vtable is not loaded before a type check.
+  // CHECK-VPTR-NOT: load {{.*}} (%struct.T*{{.*}})**, {{.*}} (%struct.T*{{.*}})***
+  // CHECK-VPTR: br i1 {{.*}} label %handler.dynamic_type_cache_miss
+  // CHECK-VPTR: call void @__ubsan_handle_dynamic_type_cache_miss_abort
+  // Second, we check that vtable is actually loaded once the type check is done.
+  // CHECK-VPTR: load {{.*}} (%struct.T*{{.*}})**, {{.*}} (%struct.T*{{.*}})***
+  delete t;
+}
Index: lib/CodeGen/CGExprCXX.cpp
===
--- lib/CodeGen/CGExprCXX.cpp
+++ lib/CodeGen/CGExprCXX.cpp
@@ -35,17 +35,6 @@
  "Trying to emit a member or operator call expr on a static method!");
   ASTContext &C = CGF.getContext();
 
-  // C++11 [class.mfct.non-static]p2:
-  //   If a non-static member function of a class X is called for an object that
-  //   is not of type X, or of a type derived from X, the behavior is undefined.
-  SourceLocation CallLoc;
-  if (CE)
-CallLoc = CE->getExprLoc();
-  CGF.EmitTypeCheck(isa(MD)
-? CodeGenFunction::TCK_ConstructorCall
-: CodeGenFunction::TCK_MemberCall,
-CallLoc, This, C.getRecordType(MD->getParent()));
-
   // Push the this ptr.
   const CXXRecordDecl *RD =
   CGF.CGM.getCXXABI().getThisArgumentTypeForMethod(MD);
@@ -293,6 +282,19 @@
 
   llvm::FunctionType *Ty = CGM.getTypes().GetFunctionType(*FInfo);
 
+  // C++11 [class.mfct.non-static]p2:
+  //   If a non-static member function of a class X is called for an object that
+  //   is not of type X, or of a type derived from X, the behavior is undefined.
+  SourceLocation CallLoc;
+  ASTContext &C = getContext();
+  if (CE)
+CallLoc = CE->getExprLoc();
+
+  EmitTypeCheck(isa(CalleeDecl)
+? CodeGenFunction::TCK_ConstructorCall
+: CodeGenFunction::TCK_MemberCall,
+CallLoc, This.getPointer(), C.getRecordType(CalleeDecl->getParent()));
+
   // FIXME: Uses of 'MD' past this point need to be audited. We may need to use
   // 'CalleeDecl' instead.
 
@@ -1763,6 +1765,13 @@
  const CXXDeleteExpr *DE,
  Address Ptr,
  QualType ElementType) {
+  SourceLocation CallLoc;
+  if (DE)
+CallLoc = DE->getExprLoc();
+  CGF.EmitTypeCheck(CodeGenFunction::TCK_MemberCall,
+CallLoc, Ptr.getPointer(),
+ElementType);
+
   // Find the destructor for the type, if applicable.  If the
   // destructor is virtual, we'll just emit the vcall and return.
   const CXXDestructorDecl *Dtor = nullptr;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26760: Add the way to extract SVals of arguments used in a call for a given StackFrameCtx

2016-11-16 Thread Krzysztof Wiśniewski via cfe-commits
k-wisniewski created this revision.
k-wisniewski added reviewers: a.sidorin, NoQ, dcoughlin, zaks.anna.
k-wisniewski added a subscriber: cfe-commits.

This patch adds getArgsSVal method to ProgramState that allows the user to 
obtain SVals of argumetns used in a call that created the given StackFrameCtx. 
I know this isn't perfect (Alexey Sidorin pointed out that there is a problem 
with line 741 - argument values may be overwritten) but wanted to submit it 
separate from other changes that I do and find _the_ right solution.


https://reviews.llvm.org/D26760

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h


Index: include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -294,6 +294,10 @@
   /// Get the lvalue for an array index.
   SVal getLValue(QualType ElementType, SVal Idx, SVal Base) const;
 
+  /// Get the symbolic value of arguments used in a call
+  /// that created the given stack frame
+  SVal getArgSVal(const StackFrameContext *SFC, const unsigned ArgIdx) const;
+
   /// Returns the SVal bound to the statement 'S' in the state's environment.
   SVal getSVal(const Stmt *S, const LocationContext *LCtx) const;
   
@@ -725,6 +729,28 @@
   return UnknownVal();
 }
 
+inline SVal ProgramState::getArgSVal(const StackFrameContext *SFC,
+ const unsigned ArgIdx) const {
+  const FunctionDecl *FunctionDecl = SFC->getDecl()->getAsFunction();
+  unsigned NumArgs = FunctionDecl->getNumParams();
+  assert(ArgIdx < NumArgs && "Arg access out of range!");
+
+  if (SFC->inTopFrame()) {
+// if we are in the top frame we don't have any arguments bound in the 
store
+// because the call wasn't modeled in the first place.
+const VarDecl *ArgDecl = FunctionDecl->parameters()[ArgIdx];
+const Loc ArgLoc = getLValue(ArgDecl, SFC);
+return getSVal(ArgLoc);
+  } else {
+// in this case we need to ask the environment as  the arguments' memory
+// region may have been purged as no longer needed.
+const Stmt *callSite = SFC->getCallSite();
+const CallExpr *callSiteExpr = dyn_cast(callSite);
+const Expr *argExpr = callSiteExpr->getArg(ArgIdx);
+return getSVal(argExpr, SFC->getParent());
+  }
+}
+
 inline SVal ProgramState::getSVal(const Stmt *Ex,
   const LocationContext *LCtx) const{
   return Env.getSVal(EnvironmentEntry(Ex, LCtx),


Index: include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -294,6 +294,10 @@
   /// Get the lvalue for an array index.
   SVal getLValue(QualType ElementType, SVal Idx, SVal Base) const;
 
+  /// Get the symbolic value of arguments used in a call
+  /// that created the given stack frame
+  SVal getArgSVal(const StackFrameContext *SFC, const unsigned ArgIdx) const;
+
   /// Returns the SVal bound to the statement 'S' in the state's environment.
   SVal getSVal(const Stmt *S, const LocationContext *LCtx) const;
   
@@ -725,6 +729,28 @@
   return UnknownVal();
 }
 
+inline SVal ProgramState::getArgSVal(const StackFrameContext *SFC,
+ const unsigned ArgIdx) const {
+  const FunctionDecl *FunctionDecl = SFC->getDecl()->getAsFunction();
+  unsigned NumArgs = FunctionDecl->getNumParams();
+  assert(ArgIdx < NumArgs && "Arg access out of range!");
+
+  if (SFC->inTopFrame()) {
+// if we are in the top frame we don't have any arguments bound in the store
+// because the call wasn't modeled in the first place.
+const VarDecl *ArgDecl = FunctionDecl->parameters()[ArgIdx];
+const Loc ArgLoc = getLValue(ArgDecl, SFC);
+return getSVal(ArgLoc);
+  } else {
+// in this case we need to ask the environment as  the arguments' memory
+// region may have been purged as no longer needed.
+const Stmt *callSite = SFC->getCallSite();
+const CallExpr *callSiteExpr = dyn_cast(callSite);
+const Expr *argExpr = callSiteExpr->getArg(ArgIdx);
+return getSVal(argExpr, SFC->getParent());
+  }
+}
+
 inline SVal ProgramState::getSVal(const Stmt *Ex,
   const LocationContext *LCtx) const{
   return Env.getSVal(EnvironmentEntry(Ex, LCtx),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26759: Remove unused check::RegionChanges::wantsRegionChangeUpdate callback

2016-11-16 Thread Krzysztof Wiśniewski via cfe-commits
k-wisniewski created this revision.
k-wisniewski added reviewers: NoQ, dcoughlin, zaks.anna, a.sidorin.
k-wisniewski added a subscriber: cfe-commits.

Hi!

I've noticed that check::RegionChanges::wantsRegionChangeUpdate is no longer 
used - as far as the discussion went it has been unused at least since 
checkPointerEscape has been added. This patch removes unused code as a part of 
cleanup/improvement in check::RegionChanges that I have undertaken. Let's 
discuss the necessity of such action here and decide upon it asap, because I 
need to know what to do with my another patch that adds LocationContext (or 
CheckerContext) to check::RegionChanges::checkRegionChanges.


https://reviews.llvm.org/D26759

Files:
  include/clang/StaticAnalyzer/Core/Checker.h
  include/clang/StaticAnalyzer/Core/CheckerManager.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
  lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
  lib/StaticAnalyzer/Core/CheckerManager.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp

Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -262,10 +262,6 @@
   return getCheckerManager().runCheckersForEvalAssume(state, cond, assumption);
 }
 
-bool ExprEngine::wantsRegionChangeUpdate(ProgramStateRef state) {
-  return getCheckerManager().wantsRegionChangeUpdate(state);
-}
-
 ProgramStateRef
 ExprEngine::processRegionChanges(ProgramStateRef state,
  const InvalidatedSymbols *invalidated,
Index: lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -518,15 +518,6 @@
   expandGraphWithCheckers(C, Dst, Src);
 }
 
-/// \brief True if at least one checker wants to check region changes.
-bool CheckerManager::wantsRegionChangeUpdate(ProgramStateRef state) {
-  for (unsigned i = 0, e = RegionChangesCheckers.size(); i != e; ++i)
-if (RegionChangesCheckers[i].WantUpdateFn(state))
-  return true;
-
-  return false;
-}
-
 /// \brief Run checkers for region changes.
 ProgramStateRef
 CheckerManager::runCheckersForRegionChanges(ProgramStateRef state,
@@ -539,8 +530,9 @@
 // bail out.
 if (!state)
   return nullptr;
-state = RegionChangesCheckers[i].CheckFn(state, invalidated,
- ExplicitRegions, Regions, Call);
+state = RegionChangesCheckers[i](state, invalidated,
+ ExplicitRegions, Regions,
+ Call, LCtx);
   }
   return state;
 }
@@ -726,10 +718,8 @@
   DeadSymbolsCheckers.push_back(checkfn);
 }
 
-void CheckerManager::_registerForRegionChanges(CheckRegionChangesFunc checkfn,
- WantsRegionChangeUpdateFunc wantUpdateFn) {
-  RegionChangesCheckerInfo info = {checkfn, wantUpdateFn};
-  RegionChangesCheckers.push_back(info);
+void CheckerManager::_registerForRegionChanges(CheckRegionChangesFunc checkfn) {
+  RegionChangesCheckers.push_back(checkfn);
 }
 
 void CheckerManager::_registerForPointerEscape(CheckPointerEscapeFunc checkfn){
Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -2649,10 +2649,6 @@
  ArrayRef Regions,
  const CallEvent *Call) const;
 
-  bool wantsRegionChangeUpdate(ProgramStateRef state) const {
-return true;
-  }
-
   void checkPreStmt(const ReturnStmt *S, CheckerContext &C) const;
   void checkReturnWithRetEffect(const ReturnStmt *S, CheckerContext &C,
 ExplodedNode *Pred, RetEffect RE, RefVal X,
Index: lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -62,7 +62,6 @@
   void checkPreStmt(const DeclStmt *DS, CheckerContext &C) const;
   void checkLiveSymbols(ProgramStateRef state, SymbolReaper &SR) const;
   void checkDeadSymbols(SymbolReaper &SR, CheckerContext &C) const;
-  bool wantsRegionChangeUpdate(ProgramStateRef state) const;
 
   ProgramStateRef
 checkRegionChanges(ProgramStateRef state,
@@ -2112,11 +2111,6 @@
   C.addTransition(state);
 }
 
-bool CStringChecker::wantsRegionChangeUpdate(ProgramStateRef state) const {
-  CStringLengthTy Entries = state->get();
-  return !Entries.isEmpty();
-}
-
 ProgramStateRef
 CStringChecker::checkRegionChanges(ProgramStateRef state,
const Invali

[PATCH] D26762: Add a method to obtain this SVal of a method that created given StackFrameCtx

2016-11-16 Thread Krzysztof Wiśniewski via cfe-commits
k-wisniewski created this revision.
k-wisniewski added reviewers: a.sidorin, zaks.anna, NoQ, dcoughlin.
k-wisniewski added subscribers: cfe-commits, NoQ.

Artem Dergachev (@NoQ ) helped me correctly handle C++ method calls in my 
RecursionChecker (that finds infnite recursion) and this is the method that I 
use to obtain SVal of "this" parameter of a method call represented by 
StackFrameCtx.


https://reviews.llvm.org/D26762

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h


Index: include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATE_H
 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATE_H
 
+#include "clang/AST/ExprCXX.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h"
@@ -298,6 +299,11 @@
   /// that created the given stack frame
   SVal getArgSVal(const StackFrameContext *SFC, const unsigned ArgIdx) const;
 
+  /// Get the symbolic value of the "this" object for a method call
+  /// that created the given stack frame. Returns None if the
+  /// stack frame does not represent a method call.
+  Optional getThisSVal(const StackFrameContext *SFC) const;
+
   /// Returns the SVal bound to the statement 'S' in the state's environment.
   SVal getSVal(const Stmt *S, const LocationContext *LCtx) const;
   
@@ -751,6 +757,29 @@
   }
 }
 
+inline Optional
+ProgramState::getThisSVal(const StackFrameContext *SFC) const {
+  if (SFC->inTopFrame()) {
+const FunctionDecl *FD = SFC->getDecl()->getAsFunction();
+if (!FD)
+  return None;
+const CXXRecordDecl *RD = dyn_cast_or_null(FD->getParent());
+if (!RD)
+  return None;
+Loc ThisLoc = getStateManager().getSValBuilder().getCXXThis(RD, SFC);
+return getSVal(ThisLoc);
+  } else {
+const Stmt *S = SFC->getCallSite();
+if (!S)
+  return None;
+if (const auto *MCE = dyn_cast(S))
+  return getSVal(MCE->getImplicitObjectArgument(), SFC->getParent());
+else if (const auto *CCE = dyn_cast(S))
+  return getSVal(CCE, SFC->getParent());
+return None;
+  }
+}
+
 inline SVal ProgramState::getSVal(const Stmt *Ex,
   const LocationContext *LCtx) const{
   return Env.getSVal(EnvironmentEntry(Ex, LCtx),


Index: include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATE_H
 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATE_H
 
+#include "clang/AST/ExprCXX.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeInfo.h"
@@ -298,6 +299,11 @@
   /// that created the given stack frame
   SVal getArgSVal(const StackFrameContext *SFC, const unsigned ArgIdx) const;
 
+  /// Get the symbolic value of the "this" object for a method call
+  /// that created the given stack frame. Returns None if the
+  /// stack frame does not represent a method call.
+  Optional getThisSVal(const StackFrameContext *SFC) const;
+
   /// Returns the SVal bound to the statement 'S' in the state's environment.
   SVal getSVal(const Stmt *S, const LocationContext *LCtx) const;
   
@@ -751,6 +757,29 @@
   }
 }
 
+inline Optional
+ProgramState::getThisSVal(const StackFrameContext *SFC) const {
+  if (SFC->inTopFrame()) {
+const FunctionDecl *FD = SFC->getDecl()->getAsFunction();
+if (!FD)
+  return None;
+const CXXRecordDecl *RD = dyn_cast_or_null(FD->getParent());
+if (!RD)
+  return None;
+Loc ThisLoc = getStateManager().getSValBuilder().getCXXThis(RD, SFC);
+return getSVal(ThisLoc);
+  } else {
+const Stmt *S = SFC->getCallSite();
+if (!S)
+  return None;
+if (const auto *MCE = dyn_cast(S))
+  return getSVal(MCE->getImplicitObjectArgument(), SFC->getParent());
+else if (const auto *CCE = dyn_cast(S))
+  return getSVal(CCE, SFC->getParent());
+return None;
+  }
+}
+
 inline SVal ProgramState::getSVal(const Stmt *Ex,
   const LocationContext *LCtx) const{
   return Env.getSVal(EnvironmentEntry(Ex, LCtx),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26759: Remove unused check::RegionChanges::wantsRegionChangeUpdate callback

2016-11-16 Thread Anna Zaks via cfe-commits
zaks.anna accepted this revision.
zaks.anna added a comment.
This revision is now accepted and ready to land.

Looks great!


https://reviews.llvm.org/D26759



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


[PATCH] D26759: Remove unused check::RegionChanges::wantsRegionChangeUpdate callback

2016-11-16 Thread Anna Zaks via cfe-commits
zaks.anna added inline comments.



Comment at: lib/StaticAnalyzer/Core/CheckerManager.cpp:535
+ ExplicitRegions, Regions,
+ Call, LCtx);
   }

Looks like the other patch leaked in here: you have LCtx.


https://reviews.llvm.org/D26759



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


[PATCH] D26702: [libc++] Introduce `_LIBCPP_OVERRIDABLE_FUNC_VIS`

2016-11-16 Thread Shoaib Meenai via cfe-commits
smeenai added a comment.

In https://reviews.llvm.org/D26702#597377, @EricWF wrote:

> What happens on windows when `operator new` isn't overridden and has to be 
> imported from the DLL? Does that work?


Yup. If you have a function that isn't marked `dllimport` and it's not found 
locally, the linker will look for it in the libraries being linked to. 
`dllimport` just allows the function call to be more efficient (if a function 
is marked `dllimport`, the compiler can call the imported function directly, 
whereas if it isn't, the linker has to emit a fixup thunk and you end up with 
an extra function call for each call to the imported function). `dllimport` is 
necessary for data symbols though, but fortunately we're not dealing with any 
of those here.




Comment at: src/new.cpp:163
 
-_LIBCPP_WEAK _LIBCPP_NEW_DELETE_VIS
 void*

EricWF wrote:
> You should be able to remove the macro on the definitions since they're 
> redundant. 
Good point. Will do that before committing.


https://reviews.llvm.org/D26702



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


[PATCH] D26763: [compiler-rt] [asan] Use __SSE2__ (rather than __i686__...) for SSE2 test

2016-11-16 Thread Michał Górny via cfe-commits
mgorny created this revision.
mgorny added a reviewer: kcc.
mgorny added a subscriber: cfe-commits.
Herald added subscribers: dberris, kubabrecka.

Use the __SSE2__ to determine whether SSE2 is enabled in the ASAN tests
rather than relying on either of the __i686__ and __x86_64__. The former
is only set with explicit -march=i686, and therefore misses most of
the x86 CPUs that support SSE2. __SSE2__ is in turn defined if
the current settings (-march, -msse2) indicate that SSE2 is supported
which should be more reliable.


https://reviews.llvm.org/D26763

Files:
  lib/asan/tests/asan_test.cc


Index: lib/asan/tests/asan_test.cc
===
--- lib/asan/tests/asan_test.cc
+++ lib/asan/tests/asan_test.cc
@@ -692,7 +692,7 @@
   PTHREAD_JOIN(t, 0);
 }
 
-#if defined(__i686__) || defined(__x86_64__)
+#if defined(__SSE2__)
 #include 
 TEST(AddressSanitizer, Store128Test) {
   char *a = Ident((char*)malloc(Ident(12)));


Index: lib/asan/tests/asan_test.cc
===
--- lib/asan/tests/asan_test.cc
+++ lib/asan/tests/asan_test.cc
@@ -692,7 +692,7 @@
   PTHREAD_JOIN(t, 0);
 }
 
-#if defined(__i686__) || defined(__x86_64__)
+#if defined(__SSE2__)
 #include 
 TEST(AddressSanitizer, Store128Test) {
   char *a = Ident((char*)malloc(Ident(12)));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26762: Add a method to obtain this SVal of a method that created given StackFrameCtx

2016-11-16 Thread Artem Dergachev via cfe-commits
NoQ added a comment.

I think this method, unlike https://reviews.llvm.org/D26760, doesn't have the 
problem with overwriting the location in the top frame, because the location of 
C++ "this" cannot really be assigned to.


https://reviews.llvm.org/D26762



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


[PATCH] D26760: Add the way to extract SVals of arguments used in a call for a given StackFrameCtx

2016-11-16 Thread Artem Dergachev via cfe-commits
NoQ added a comment.

I'm ok with constructing `SymbolRegionValue` for `ArgLoc` manually and adding a 
comment like `FIXME: leaking implementation details of RegionStoreManager`.


https://reviews.llvm.org/D26760



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


[PATCH] D26764: [compiler-rt] [cmake] Remove i686 target that is duplicate to i386

2016-11-16 Thread Michał Górny via cfe-commits
mgorny created this revision.
mgorny added reviewers: samsonov, etienneb, beanz.
mgorny added a subscriber: cfe-commits.
Herald added subscribers: dberris, kubabrecka.

Remove the explicit i686 target that is completely duplicate to
the i386 target, with the latter being used more commonly.

1. The runtime built for i686 will be identical to the one built for

i386.

2. Supporting both -i386 and -i686 suffixes causes unnecessary confusion

on the clang end which has to expect either of them.

3. The checks are based on wrong assumption that __i686__ is defined for

all newer x86 CPUs. In fact, it is only declared when -march=i686 is
explicitly used. It is not available when a more specific (or newer)
-march is used.

Curious enough, if CFLAGS contain -march=i686, the runtime will be built
both for i386 and i686. For any other value, only i386 variant will be
built.


https://reviews.llvm.org/D26764

Files:
  cmake/Modules/CompilerRTUtils.cmake
  cmake/base-config-ix.cmake
  cmake/builtin-config-ix.cmake
  cmake/config-ix.cmake
  lib/asan/CMakeLists.txt
  lib/asan/scripts/asan_device_setup
  lib/builtins/CMakeLists.txt
  lib/ubsan/CMakeLists.txt
  test/asan/CMakeLists.txt
  test/asan/lit.cfg
  test/lit.common.cfg

Index: test/lit.common.cfg
===
--- test/lit.common.cfg
+++ test/lit.common.cfg
@@ -105,7 +105,7 @@
 target_arch = getattr(config, 'target_arch', None)
 if target_arch:
   config.available_features.add(target_arch + '-target-arch')
-  if target_arch in ['x86_64', 'i386', 'i686']:
+  if target_arch in ['x86_64', 'i386']:
 config.available_features.add('x86-target-arch')
   config.available_features.add(target_arch + '-' + config.host_os.lower())
 
Index: test/asan/lit.cfg
===
--- test/asan/lit.cfg
+++ test/asan/lit.cfg
@@ -116,16 +116,11 @@
 def build_invocation(compile_flags):
   return " " + " ".join([clang_wrapper, config.clang] + compile_flags) + " "
 
-# Clang driver link 'x86' (i686) architecture to 'i386'.
-target_arch = config.target_arch
-if (target_arch == "i686"):
-  target_arch = "i386"
-
 config.substitutions.append( ("%clang ", build_invocation(target_cflags)) )
 config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) )
 config.substitutions.append( ("%clang_asan ", build_invocation(clang_asan_cflags)) )
 config.substitutions.append( ("%clangxx_asan ", build_invocation(clang_asan_cxxflags)) )
-config.substitutions.append( ("%shared_libasan", "libclang_rt.asan-%s.so" % target_arch))
+config.substitutions.append( ("%shared_libasan", "libclang_rt.asan-%s.so" % config.target_arch))
 if config.asan_dynamic:
   config.substitutions.append( ("%clang_asan_static ", build_invocation(clang_asan_static_cflags)) )
   config.substitutions.append( ("%clangxx_asan_static ", build_invocation(clang_asan_static_cxxflags)) )
Index: test/asan/CMakeLists.txt
===
--- test/asan/CMakeLists.txt
+++ test/asan/CMakeLists.txt
@@ -10,7 +10,7 @@
 endif()
 
 macro(get_bits_for_arch arch bits)
-  if (${arch} MATCHES "i386|i686|arm|mips|mipsel")
+  if (${arch} MATCHES "i386|arm|mips|mipsel")
 set(${bits} 32)
   elseif (${arch} MATCHES "x86_64|powerpc64|powerpc64le|aarch64|mips64|mips64el|s390x")
 set(${bits} 64)
Index: lib/ubsan/CMakeLists.txt
===
--- lib/ubsan/CMakeLists.txt
+++ lib/ubsan/CMakeLists.txt
@@ -112,7 +112,7 @@
 
 if (UNIX)
   set(ARCHS_FOR_SYMBOLS ${UBSAN_SUPPORTED_ARCH})
-  list(REMOVE_ITEM ARCHS_FOR_SYMBOLS i386 i686)
+  list(REMOVE_ITEM ARCHS_FOR_SYMBOLS i386)
   add_sanitizer_rt_symbols(clang_rt.ubsan_standalone
 ARCHS ${ARCHS_FOR_SYMBOLS}
 PARENT_TARGET ubsan
Index: lib/builtins/CMakeLists.txt
===
--- lib/builtins/CMakeLists.txt
+++ lib/builtins/CMakeLists.txt
@@ -251,9 +251,6 @@
 i386/chkstk.S
 i386/chkstk2.S)
   endif()
-
-  set(i686_SOURCES
-  ${i386_SOURCES})
 else () # MSVC
   # Use C versions of functions when building on MSVC
   # MSVC's assembler takes Intel syntax, not AT&T syntax.
@@ -265,7 +262,6 @@
   ${MSVC_SOURCES})
   set(x86_64h_SOURCES ${x86_64_SOURCES})
   set(i386_SOURCES ${MSVC_SOURCES})
-  set(i686_SOURCES ${i386_SOURCES})
 endif () # if (NOT MSVC)
 
 set(arm_SOURCES
Index: lib/asan/scripts/asan_device_setup
===
--- lib/asan/scripts/asan_device_setup
+++ lib/asan/scripts/asan_device_setup
@@ -95,7 +95,7 @@
 local _ARCH=
 local _ARCH64=
 if [[ $_ABI == x86* ]]; then
-_ARCH=i686
+_ARCH=i386
 elif [[ $_ABI == armeabi* ]]; then
 _ARCH=arm
 elif [[ $_ABI == arm64-v8a* ]]; then
Index: lib/asan/CMakeLists.txt
=

[PATCH] D26741: [clang-tidy] Changes to modernize-use-default check

2016-11-16 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


https://reviews.llvm.org/D26741



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


[PATCH] D26759: Remove unused check::RegionChanges::wantsRegionChangeUpdate callback

2016-11-16 Thread Krzysztof Wiśniewski via cfe-commits
k-wisniewski updated this revision to Diff 78249.
k-wisniewski added a comment.

Removed a line that leaked from another diff - thanks Anna!


https://reviews.llvm.org/D26759

Files:
  include/clang/StaticAnalyzer/Core/Checker.h
  include/clang/StaticAnalyzer/Core/CheckerManager.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
  lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
  lib/StaticAnalyzer/Core/CheckerManager.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp

Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -262,10 +262,6 @@
   return getCheckerManager().runCheckersForEvalAssume(state, cond, assumption);
 }
 
-bool ExprEngine::wantsRegionChangeUpdate(ProgramStateRef state) {
-  return getCheckerManager().wantsRegionChangeUpdate(state);
-}
-
 ProgramStateRef
 ExprEngine::processRegionChanges(ProgramStateRef state,
  const InvalidatedSymbols *invalidated,
Index: lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -518,15 +518,6 @@
   expandGraphWithCheckers(C, Dst, Src);
 }
 
-/// \brief True if at least one checker wants to check region changes.
-bool CheckerManager::wantsRegionChangeUpdate(ProgramStateRef state) {
-  for (unsigned i = 0, e = RegionChangesCheckers.size(); i != e; ++i)
-if (RegionChangesCheckers[i].WantUpdateFn(state))
-  return true;
-
-  return false;
-}
-
 /// \brief Run checkers for region changes.
 ProgramStateRef
 CheckerManager::runCheckersForRegionChanges(ProgramStateRef state,
@@ -539,8 +530,8 @@
 // bail out.
 if (!state)
   return nullptr;
-state = RegionChangesCheckers[i].CheckFn(state, invalidated,
- ExplicitRegions, Regions, Call);
+state = RegionChangesCheckers[i](state, invalidated,
+ ExplicitRegions, Regions, Call);
   }
   return state;
 }
@@ -726,10 +717,8 @@
   DeadSymbolsCheckers.push_back(checkfn);
 }
 
-void CheckerManager::_registerForRegionChanges(CheckRegionChangesFunc checkfn,
- WantsRegionChangeUpdateFunc wantUpdateFn) {
-  RegionChangesCheckerInfo info = {checkfn, wantUpdateFn};
-  RegionChangesCheckers.push_back(info);
+void CheckerManager::_registerForRegionChanges(CheckRegionChangesFunc checkfn) {
+  RegionChangesCheckers.push_back(checkfn);
 }
 
 void CheckerManager::_registerForPointerEscape(CheckPointerEscapeFunc checkfn){
Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -2649,10 +2649,6 @@
  ArrayRef Regions,
  const CallEvent *Call) const;
 
-  bool wantsRegionChangeUpdate(ProgramStateRef state) const {
-return true;
-  }
-
   void checkPreStmt(const ReturnStmt *S, CheckerContext &C) const;
   void checkReturnWithRetEffect(const ReturnStmt *S, CheckerContext &C,
 ExplodedNode *Pred, RetEffect RE, RefVal X,
Index: lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -62,7 +62,6 @@
   void checkPreStmt(const DeclStmt *DS, CheckerContext &C) const;
   void checkLiveSymbols(ProgramStateRef state, SymbolReaper &SR) const;
   void checkDeadSymbols(SymbolReaper &SR, CheckerContext &C) const;
-  bool wantsRegionChangeUpdate(ProgramStateRef state) const;
 
   ProgramStateRef
 checkRegionChanges(ProgramStateRef state,
@@ -2112,11 +2111,6 @@
   C.addTransition(state);
 }
 
-bool CStringChecker::wantsRegionChangeUpdate(ProgramStateRef state) const {
-  CStringLengthTy Entries = state->get();
-  return !Entries.isEmpty();
-}
-
 ProgramStateRef
 CStringChecker::checkRegionChanges(ProgramStateRef state,
const InvalidatedSymbols *,
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
@@ -124,10 +124,6 @@
   virtual ProgramStateRef processAssume(ProgramStateRef state,
SVal cond, bool assumption) = 0;
 
-  /// wantsRegionChangeUpdate - Called by ProgramStateManager to determine if a
-  ///  region change should trigger a processRegionChanges update.
-  virtu

[PATCH] D26657: [Sema] Respect DLL attributes more faithfully

2016-11-16 Thread Shoaib Meenai via cfe-commits
smeenai added a comment.

In https://reviews.llvm.org/D26657#597523, @hans wrote:

> In https://reviews.llvm.org/D26657#596897, @smeenai wrote:
>
> > In https://reviews.llvm.org/D26657#596759, @hans wrote:
> >
> > > > On MSVC, if an implicit instantiation already exists and an explicit
> > > >  instantiation definition with a DLL attribute is created, the DLL
> > > >  attribute still takes effect. Make clang match this behavior.
> > >
> > > This is scary territory, and behaviour I think might be hard for us to 
> > > match.
> > >
> > > What if we already codegenned the implicit instantiation?
> >
> >
> > Hmm. Under what specific cases would that happen?
>
>
> Actually maybe I was being overly cautius. I think 
> https://reviews.llvm.org/rL225570 might just make this work.
>
> > I can see odd behavior differences occurring for `dllimport`. For example, 
> > for the C++ source in https://reviews.llvm.org/P7936, if I compile with 
> > clang (even with this patch applied), the `t.f()` call in `g` gets 
> > assembled to a call to `?f@?$s@H@@QAEHXZ`. If I hoist the dllimport 
> > explicit instantiation definition above `g`, `t.f()` instead assembles to 
> > `__imp_?f@?$s@H@@QAEHXZ`.
>
> Yeah, dllimport is interesting here. If you turn on `-O1`, it will call the 
> `__imp` one. Fun times :-)


Huh. Weird stuff.

> 
> 
>> With cl 19.00.24210, `t.f()` always assembles to `__imp_?f@?$s@H@@QAEHXZ`, 
>> regardless of the placement of the explicit instantiation definition.
> 
> Presumably they parse and analyze the whole translation unit before emitting 
> any code, which makes changing things around later easier for them than for 
> us.
> 
>> I'm having a harder time imagining things going awry for `dllexport`. I can 
>> limit this patch to only `dllexport`, if that's going to be safer.
> 
> Yeah, I think https://reviews.llvm.org/rL225570 makes this work actually.

So is the conclusion that this is probably safe as is, or should I limit it to 
`dllexport` specifically?

>> To give some context, libc++ uses extern templates extensively, and I ran 
>> into an issue with dllexport explicit locale template instantiations 
>> .
>>  Some of those instantiations are also implicitly instantiated via sizeof 
>> calls 
>> .
>>  Therefore, all instances which make is called on 
>> 
>>  end up having their `dllexport` attribute ignored.
>> 
>> We could work around this in libc++ by hoisting the affected instantiations 
>> to near the top of the file, but it seemed preferable to make clang match 
>> MSVC's behavior instead, at least for `dllexport`. I don't have any 
>> particular interest in making `dllimport` semantics match MSVC for this 
>> specific case.
> 
> Dont' we need `dllimport` to work analogously though? When using libc++, 
> don't these template members need to be dllimported? If not, why are they 
> being exported in the first place?

Ah. We put `dllimport` on the explicit template instantiation declarations in 
the header 
 (all 
the instances of `_LIBCPP_EXTERN_TEMPLATE2` in that file). Those get paired 
with the `dllexport` on the corresponding instantiation definitions. If you're 
compiling the library, the declarations have no DLL attribute, and the 
definitions have `dllexport`. If you're referencing the headers from outside 
the library, the declarations get the `dllimport`.


https://reviews.llvm.org/D26657



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


[PATCH] D26744: [clang-tidy] Fix identifier naming for initializer list member initializers.

2016-11-16 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/readability/IdentifierNamingCheck.cpp:681
+
+for (auto Init : Decl->inits()) {
+  if (!Init->isWritten() || Init->isInClassMemberInitializer())

Please use `const auto *` instead of just `auto`.



Comment at: test/clang-tidy/readability-identifier-naming.cpp:155
 // CHECK-FIXES: {{^}}class CMyClass {{{$}}
+public:
 my_class();

Why set the access specifier here (and below)?



Comment at: test/clang-tidy/readability-identifier-naming.cpp:224
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private 
member 'my_Bad_Member'
+  // CHECK-FIXES: {{^}}  t_t __my_Bad_Member;{{$}}
+  int my_Other_Bad_Member = 42;

Wait, our fix is to turn the name into a reserved identifier? That seems 
less-than-ideal (not that you are changing this behavior, mostly just that this 
will generate a new diagnostic on the fixed code).


https://reviews.llvm.org/D26744



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


[PATCH] D26744: [clang-tidy] Fix identifier naming for initializer list member initializers.

2016-11-16 Thread Eric Fiselier via cfe-commits
EricWF marked an inline comment as done.
EricWF added inline comments.



Comment at: test/clang-tidy/readability-identifier-naming.cpp:155
 // CHECK-FIXES: {{^}}class CMyClass {{{$}}
+public:
 my_class();

aaron.ballman wrote:
> Why set the access specifier here (and below)?
The tests below need to call these constructors to test base class initializers.



Comment at: test/clang-tidy/readability-identifier-naming.cpp:224
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private 
member 'my_Bad_Member'
+  // CHECK-FIXES: {{^}}  t_t __my_Bad_Member;{{$}}
+  int my_Other_Bad_Member = 42;

aaron.ballman wrote:
> Wait, our fix is to turn the name into a reserved identifier? That seems 
> less-than-ideal (not that you are changing this behavior, mostly just that 
> this will generate a new diagnostic on the fixed code).
It's just for the test, See the RUN lines:
```
// RUN: {key: readability-identifier-naming.PrivateMemberPrefix, value: 
'__'}, 
```


https://reviews.llvm.org/D26744



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


[PATCH] D26744: [clang-tidy] Fix identifier naming for initializer list member initializers.

2016-11-16 Thread Eric Fiselier via cfe-commits
EricWF updated this revision to Diff 78252.
EricWF added a comment.

Fix `auto` usage.


https://reviews.llvm.org/D26744

Files:
  clang-tidy/readability/IdentifierNamingCheck.cpp
  test/clang-tidy/readability-identifier-naming.cpp


Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -152,15 +152,20 @@
 class my_class {
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'my_class'
 // CHECK-FIXES: {{^}}class CMyClass {{{$}}
+public:
 my_class();
 // CHECK-FIXES: {{^}}CMyClass();{{$}}
 
+my_class(void*) : my_class() {}
+// CHECK-FIXES: {{^}}CMyClass(void*) : CMyClass() {}{{$}}
+
 ~
   my_class();
 // (space in destructor token test, we could check trigraph but they will be 
deprecated)
 // CHECK-FIXES: {{^}}~{{$}}
 // CHECK-FIXES: {{^}}  CMyClass();{{$}}
 
+private:
   const int MEMBER_one_1 = ConstExpr_variable;
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for constant 
member 'MEMBER_one_1'
 // CHECK-FIXES: {{^}}  const int member_one_1 = const_expr_variable;{{$}}
@@ -211,6 +216,34 @@
 class CMyWellNamedClass {};
 // No warning expected as this class is well named.
 
+template 
+class CMyWellNamedClass2 : public my_class {
+  // CHECK-FIXES: {{^}}class CMyWellNamedClass2 : public CMyClass {{{$}}
+  t_t my_Bad_Member;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private 
member 'my_Bad_Member'
+  // CHECK-FIXES: {{^}}  t_t __my_Bad_Member;{{$}}
+  int my_Other_Bad_Member = 42;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private 
member 'my_Other_Bad_Member'
+  // CHECK-FIXES: {{^}}  int __my_Other_Bad_Member = 42;{{$}}
+public:
+  CMyWellNamedClass2() = default;
+  CMyWellNamedClass2(CMyWellNamedClass2 const&) = default;
+  CMyWellNamedClass2(CMyWellNamedClass2 &&) = default;
+  CMyWellNamedClass2(t_t a_v, void *a_p) : my_class(a_p), my_Bad_Member(a_v) {}
+  // CHECK-FIXES: {{^}}  CMyWellNamedClass2(t_t a_v, void *a_p) : 
CMyClass(a_p), __my_Bad_Member(a_v) {}{{$}}
+
+  CMyWellNamedClass2(t_t a_v) : my_class(), my_Bad_Member(a_v), 
my_Other_Bad_Member(11) {}
+  // CHECK-FIXES: {{^}}  CMyWellNamedClass2(t_t a_v) : CMyClass(), 
__my_Bad_Member(a_v), __my_Other_Bad_Member(11) {}{{$}}
+};
+void InstantiateClassMethods() {
+  // Ensure we trigger the instantiation of each constructor
+  CMyWellNamedClass2 x;
+  CMyWellNamedClass2 x2 = x;
+  CMyWellNamedClass2 x3 = static_cast&&>(x2);
+  CMyWellNamedClass2 x4(42);
+  CMyWellNamedClass2 x5(42, nullptr);
+}
+
 template
 // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for type 
template parameter 'T'
 // CHECK-FIXES: {{^}}template{{$}}
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -677,6 +677,15 @@
 
 addUsage(NamingCheckFailures, Decl->getParent(),
  Decl->getNameInfo().getSourceRange());
+
+for (const auto *Init : Decl->inits()) {
+  if (!Init->isWritten() || Init->isInClassMemberInitializer())
+continue;
+  if (const auto *FD = Init->getAnyMember())
+addUsage(NamingCheckFailures, FD, 
SourceRange(Init->getMemberLocation()));
+  // Note: delegating constructors and base class initializers are handled
+  // via the "typeLoc" matcher.
+}
 return;
   }
 


Index: test/clang-tidy/readability-identifier-naming.cpp
===
--- test/clang-tidy/readability-identifier-naming.cpp
+++ test/clang-tidy/readability-identifier-naming.cpp
@@ -152,15 +152,20 @@
 class my_class {
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'my_class'
 // CHECK-FIXES: {{^}}class CMyClass {{{$}}
+public:
 my_class();
 // CHECK-FIXES: {{^}}CMyClass();{{$}}
 
+my_class(void*) : my_class() {}
+// CHECK-FIXES: {{^}}CMyClass(void*) : CMyClass() {}{{$}}
+
 ~
   my_class();
 // (space in destructor token test, we could check trigraph but they will be deprecated)
 // CHECK-FIXES: {{^}}~{{$}}
 // CHECK-FIXES: {{^}}  CMyClass();{{$}}
 
+private:
   const int MEMBER_one_1 = ConstExpr_variable;
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for constant member 'MEMBER_one_1'
 // CHECK-FIXES: {{^}}  const int member_one_1 = const_expr_variable;{{$}}
@@ -211,6 +216,34 @@
 class CMyWellNamedClass {};
 // No warning expected as this class is well named.
 
+template 
+class CMyWellNamedClass2 : public my_class {
+  // CHECK-FIXES: {{^}}class CMyWellNamedClass2 : public CMyClass {{{$}}
+  t_t my_Bad_Member;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'my_Bad_Member'
+  // CHE

[PATCH] D26744: [clang-tidy] Fix identifier naming for initializer list member initializers.

2016-11-16 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: test/clang-tidy/readability-identifier-naming.cpp:155
 // CHECK-FIXES: {{^}}class CMyClass {{{$}}
+public:
 my_class();

EricWF wrote:
> aaron.ballman wrote:
> > Why set the access specifier here (and below)?
> The tests below need to call these constructors to test base class 
> initializers.
Ah, that makes sense, thank you.



Comment at: test/clang-tidy/readability-identifier-naming.cpp:224
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private 
member 'my_Bad_Member'
+  // CHECK-FIXES: {{^}}  t_t __my_Bad_Member;{{$}}
+  int my_Other_Bad_Member = 42;

EricWF wrote:
> aaron.ballman wrote:
> > Wait, our fix is to turn the name into a reserved identifier? That seems 
> > less-than-ideal (not that you are changing this behavior, mostly just that 
> > this will generate a new diagnostic on the fixed code).
> It's just for the test, See the RUN lines:
> ```
> // RUN: {key: readability-identifier-naming.PrivateMemberPrefix, value: 
> '__'}, 
> ```
Oh! Phew! Now I am much less worried. :-D


https://reviews.llvm.org/D26744



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


[clang-tools-extra] r287153 - [clang-tidy] Fix identifier naming for initializer list member initializers.

2016-11-16 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Nov 16 15:15:58 2016
New Revision: 287153

URL: http://llvm.org/viewvc/llvm-project?rev=287153&view=rev
Log:
[clang-tidy] Fix identifier naming for initializer list member initializers.

Summary:
This patch adds handling for member initializers in a constructors initializer 
list. Previously we only handled base-class and delegating initializers, which 
are transformed by the `TypeLoc` matcher. For Example:

```
// Style options: All identifiers should start with an upper case letter.
struct base { ...  }; 
struct der :  base {
  int field;  // FIXES: int Field;
  der() : der(42) {} // FIXES: Der() : Der(42) {}
  der(int X) : base(), field(X) {} // FIXES: Der(int X) : Base(), field(X)
  // Note that `field` doesn't get replaced
};
```

Reviewers: alexfh, hokein, aaron.ballman

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp?rev=287153&r1=287152&r2=287153&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/IdentifierNamingCheck.cpp 
Wed Nov 16 15:15:58 2016
@@ -677,6 +677,15 @@ void IdentifierNamingCheck::check(const
 
 addUsage(NamingCheckFailures, Decl->getParent(),
  Decl->getNameInfo().getSourceRange());
+
+for (const auto *Init : Decl->inits()) {
+  if (!Init->isWritten() || Init->isInClassMemberInitializer())
+continue;
+  if (const auto *FD = Init->getAnyMember())
+addUsage(NamingCheckFailures, FD, 
SourceRange(Init->getMemberLocation()));
+  // Note: delegating constructors and base class initializers are handled
+  // via the "typeLoc" matcher.
+}
 return;
   }
 

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp?rev=287153&r1=287152&r2=287153&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-identifier-naming.cpp 
Wed Nov 16 15:15:58 2016
@@ -152,15 +152,20 @@ constexpr int ConstExpr_variable = MyCon
 class my_class {
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'my_class'
 // CHECK-FIXES: {{^}}class CMyClass {{{$}}
+public:
 my_class();
 // CHECK-FIXES: {{^}}CMyClass();{{$}}
 
+my_class(void*) : my_class() {}
+// CHECK-FIXES: {{^}}CMyClass(void*) : CMyClass() {}{{$}}
+
 ~
   my_class();
 // (space in destructor token test, we could check trigraph but they will be 
deprecated)
 // CHECK-FIXES: {{^}}~{{$}}
 // CHECK-FIXES: {{^}}  CMyClass();{{$}}
 
+private:
   const int MEMBER_one_1 = ConstExpr_variable;
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: invalid case style for constant 
member 'MEMBER_one_1'
 // CHECK-FIXES: {{^}}  const int member_one_1 = const_expr_variable;{{$}}
@@ -211,6 +216,34 @@ class my_derived_class : public virtual
 class CMyWellNamedClass {};
 // No warning expected as this class is well named.
 
+template 
+class CMyWellNamedClass2 : public my_class {
+  // CHECK-FIXES: {{^}}class CMyWellNamedClass2 : public CMyClass {{{$}}
+  t_t my_Bad_Member;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private 
member 'my_Bad_Member'
+  // CHECK-FIXES: {{^}}  t_t __my_Bad_Member;{{$}}
+  int my_Other_Bad_Member = 42;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private 
member 'my_Other_Bad_Member'
+  // CHECK-FIXES: {{^}}  int __my_Other_Bad_Member = 42;{{$}}
+public:
+  CMyWellNamedClass2() = default;
+  CMyWellNamedClass2(CMyWellNamedClass2 const&) = default;
+  CMyWellNamedClass2(CMyWellNamedClass2 &&) = default;
+  CMyWellNamedClass2(t_t a_v, void *a_p) : my_class(a_p), my_Bad_Member(a_v) {}
+  // CHECK-FIXES: {{^}}  CMyWellNamedClass2(t_t a_v, void *a_p) : 
CMyClass(a_p), __my_Bad_Member(a_v) {}{{$}}
+
+  CMyWellNamedClass2(t_t a_v) : my_class(), my_Bad_Member(a_v), 
my_Other_Bad_Member(11) {}
+  // CHECK-FIXES: {{^}}  CMyWellNamedClass2(t_t a_v) : CMyClass(), 
__my_Bad_Member(a_v), __my_Other_Bad_Member(11) {}{{$}}
+};
+void InstantiateClassMethods() {
+  // Ensure we trigger the instantiation of each constructor
+  CMyWellNamedClass2 x;
+  CMyWellNamedClass2 x2 = x;
+  CMyWellNamedClass2 x3 = static_cast&&>(x2);
+  CMyWellNamedClass2 x4(42);
+  CMyWellNamedClass2 x5(42, nullptr);
+}
+
 templ

[PATCH] D26735: [OpenCL] Disable && (address of label) GNU extension for OpenCL

2016-11-16 Thread Richard Smith via cfe-commits
rsmith added a comment.

Please don't ban things just because you can. If there's some reason why this 
doesn't make sense in OpenCL, this may be fine, but generally you shouldn't be 
making this language mode deviate from clang's normal behaviour regarding 
extensions.

(It would be great if we had a flag to turn off gnu extensions other than 
-pedantic-errors, like we have for MS extensions, but that's mostly orthogonal 
to OpenCL.)


https://reviews.llvm.org/D26735



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


[PATCH] D26559: Insert a type check before reading vtable.

2016-11-16 Thread Peter Collingbourne via cfe-commits
pcc added inline comments.



Comment at: lib/CodeGen/CGExprCXX.cpp:1769
+  SourceLocation CallLoc;
+  if (DE)
+CallLoc = DE->getExprLoc();

DE will always be non-null at this point.



Comment at: test/CodeGenCXX/ubsan-vtable-checks.cpp:23
+  // CHECK-NULL: [[UBSAN_CMP_RES:%[0-9]+]] = icmp ne %struct.T* 
%{{[_a-z0-9]+}}, null
+  // CHECK-NULL-NEXT: br i1 [[UBSAN_CMP_RES]], label %cont, label 
%handler.type_mismatch
+  // CHECK-NULL: call void @__ubsan_handle_type_mismatch_abort

Does this test pass in a -Asserts build?


https://reviews.llvm.org/D26559



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


  1   2   >