[PATCH] D29271: Revert r293455, which breaks v8 with a spurious error. Testcase added.

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.

Revert r293455, which breaks v8 with a spurious error. Testcase added.


https://reviews.llvm.org/D29271

Files:
  include/clang/AST/DeclTemplate.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Sema/TreeTransform.h
  test/Parser/cxx1z-class-template-argument-deduction.cpp
  test/SemaCXX/cxx0x-class.cpp

Index: test/SemaCXX/cxx0x-class.cpp
===
--- test/SemaCXX/cxx0x-class.cpp
+++ test/SemaCXX/cxx0x-class.cpp
@@ -45,3 +45,12 @@
   DefaultMemberTemplate t = {};
   int *p = &t.n;
 };
+
+namespace composed_templates {
+  // Regression test -- obtaining the type from composed templates should not
+  // require out-of-line definition.
+  template  struct Foo { static constexpr bool value = true; };
+  template  struct Bar { using type = char; };
+  template  struct Baz { static const typename Bar::value>::type value = 0; };
+  template struct Baz<0>;
+}
Index: test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -verify %s
 
-template struct A {}; // expected-note 35{{declared here}}
+template struct A {}; // expected-note 31{{declared here}}
 
 // Make sure we still correctly parse cases where a template can appear without arguments.
 namespace template_template_arg {
@@ -101,8 +101,6 @@
 (void)reinterpret_cast(&n); // expected-error{{requires template arguments; argument deduction not allowed here}}
 (void)const_cast(n); // expected-error{{requires template arguments; argument deduction not allowed here}}
 (void)*(A*)(&n); // expected-error{{requires template arguments; argument deduction not allowed here}}
-(void)(A)(n); // expected-error{{requires template arguments; argument deduction not allowed here}}
-(void)(A){n}; // expected-error{{requires template arguments; argument deduction not allowed here}}
 
 (void)A(n); // expected-error {{not yet supported}}
 (void)A{n}; // expected-error {{not yet supported}}
@@ -123,66 +121,11 @@
 
   A a; // expected-error {{requires an initializer}}
   A b = 0; // expected-error {{not yet supported}}
-  const A c = 0; // expected-error {{not yet supported}}
   A (parens) = 0; // expected-error {{cannot use parentheses when declaring variable with deduced class template specialization type}}
   A *p = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
   A &r = *p; // expected-error {{cannot form reference to deduced class template specialization type}}
   A arr[3] = 0; // expected-error {{cannot form array of deduced class template specialization type}}
   A F::*pm = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
   A (*fp)() = 0; // expected-error {{cannot form function returning deduced class template specialization type}}
   A [x, y] = 0; // expected-error {{cannot be declared with type 'A'}} expected-error {{not yet supported}}
 }
-
-namespace typename_specifier {
-  struct F {};
-
-  void e() {
-(void) typename ::A(0); // expected-error {{not yet supported}}
-(void) typename ::A{0}; // expected-error {{not yet supported}}
-new typename ::A(0); // expected-error {{not yet supported}}
-new typename ::A{0}; // expected-error {{not yet supported}}
-typename ::A a = 0; // expected-error {{not yet supported}}
-const typename ::A b = 0; // expected-error {{not yet supported}}
-if (typename ::A a = 0) {} // expected-error {{not yet supported}}
-for (typename ::A a = 0; typename ::A b = 0; /**/) {} // expected-error 2{{not yet supported}}
-
-(void)(typename ::A)(0); // expected-error{{requires template arguments; argument deduction not allowed here}}
-(void)(typename ::A){0}; // expected-error{{requires template arguments; argument deduction not allowed here}}
-  }
-  typename ::A a = 0; // expected-error {{not yet supported}}
-  const typename ::A b = 0; // expected-error {{not yet supported}}
-  typename ::A (parens) = 0; // expected-error {{cannot use parentheses when declaring variable with deduced class template specialization type}}
-  typename ::A *p = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
-  typename ::A &r = *p; // expected-error {{cannot form reference to deduced class template specialization type}}
-  typename ::A arr[3] = 0; // expected-error {{cannot form array of deduced class template specialization type}}
-  typename ::A F::*pm = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
-  typename ::A (*fp)() = 0; //

[PATCH] D29271: Revert r293455, which breaks v8 with a spurious error. Testcase added.

2017-01-30 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

Btw, ran into that with the even simpler test case

  template struct S {
  static typename T::t const n = 0;
  };
  struct U { using t = int; };
  int main() { return S::n; }


https://reviews.llvm.org/D29271



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


[PATCH] D29271: Revert r293455, which breaks v8 with a spurious error. Testcase added.

2017-01-30 Thread Manuel Klimek via Phabricator 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/D29271



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


[PATCH] D29271: Revert r293455, which breaks v8 with a spurious error. Testcase added.

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In https://reviews.llvm.org/D29271#660169, @sberg wrote:

> Btw, ran into that with the even simpler test case


Thanks, I stole it :-)


https://reviews.llvm.org/D29271



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


[PATCH] D29271: Revert r293455, which breaks v8 with a spurious error. Testcase added.

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293473: Revert r293455, which breaks v8 with a spurious 
error. Testcase added. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D29271?vs=86257&id=86259#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29271

Files:
  cfe/trunk/include/clang/AST/DeclTemplate.h
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaTemplate.cpp
  cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
  cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
  cfe/trunk/lib/Sema/TreeTransform.h
  cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp
  cfe/trunk/test/SemaCXX/cxx0x-class.cpp

Index: cfe/trunk/include/clang/AST/DeclTemplate.h
===
--- cfe/trunk/include/clang/AST/DeclTemplate.h
+++ cfe/trunk/include/clang/AST/DeclTemplate.h
@@ -2946,16 +2946,6 @@
   return P.get();
 }
 
-inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) {
-  auto *TD = dyn_cast(D);
-  return TD && (isa(TD) ||
-isa(TD) ||
-isa(TD) ||
-isa(TD))
- ? TD
- : nullptr;
-}
-
 } /* end of namespace clang */
 
 #endif
Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -7359,8 +7359,7 @@
 
   TypeSourceInfo *SubstType(TypeSourceInfo *T,
 const MultiLevelTemplateArgumentList &TemplateArgs,
-SourceLocation Loc, DeclarationName Entity,
-bool AllowDeducedTST = false);
+SourceLocation Loc, DeclarationName Entity);
 
   QualType SubstType(QualType T,
  const MultiLevelTemplateArgumentList &TemplateArgs,
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1884,11 +1884,6 @@
   "|in conversion function type|here|in lambda parameter"
   "|in type allocated by 'new'|in K&R-style function parameter"
   "|in template parameter|in friend declaration}1">;
-def err_dependent_deduced_tst : Error<
-  "typename specifier refers to "
-  "%select{class template|function template|variable template|alias template|"
-  "template template parameter|template}0 member in %1; "
-  "argument deduction not allowed here">;
 def err_auto_not_allowed_var_inst : Error<
   "'auto' variable template instantiation is not allowed">;
 def err_auto_var_requires_init : Error<
Index: cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -verify %s
 
-template struct A {}; // expected-note 35{{declared here}}
+template struct A {}; // expected-note 31{{declared here}}
 
 // Make sure we still correctly parse cases where a template can appear without arguments.
 namespace template_template_arg {
@@ -101,8 +101,6 @@
 (void)reinterpret_cast(&n); // expected-error{{requires template arguments; argument deduction not allowed here}}
 (void)const_cast(n); // expected-error{{requires template arguments; argument deduction not allowed here}}
 (void)*(A*)(&n); // expected-error{{requires template arguments; argument deduction not allowed here}}
-(void)(A)(n); // expected-error{{requires template arguments; argument deduction not allowed here}}
-(void)(A){n}; // expected-error{{requires template arguments; argument deduction not allowed here}}
 
 (void)A(n); // expected-error {{not yet supported}}
 (void)A{n}; // expected-error {{not yet supported}}
@@ -123,66 +121,11 @@
 
   A a; // expected-error {{requires an initializer}}
   A b = 0; // expected-error {{not yet supported}}
-  const A c = 0; // expected-error {{not yet supported}}
   A (parens) = 0; // expected-error {{cannot use parentheses when declaring variable with deduced class template specialization type}}
   A *p = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
   A &r = *p; // expected-error {{cannot form reference to deduced class template specialization type}}
   A arr[3] = 0; // expected-error {{cannot form array of deduced class template specialization type}}
   A F::*pm = 0; // expected-error {{cannot form pointer to deduced class template specialization type}}
   A (*fp)() = 0; // expected-error {{cannot form function returning deduced class template specialization type}}
   A

r293475 - Revert "r293343 - [ubsan] Sanity-check shift amounts before truncation

2017-01-30 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Mon Jan 30 05:37:18 2017
New Revision: 293475

URL: http://llvm.org/viewvc/llvm-project?rev=293475&view=rev
Log:
Revert "r293343 - [ubsan] Sanity-check shift amounts before truncation
(fixes PR27271)"

After r293343 clang fails to compile itself with -fsanitize=undefined (
http://lab.llvm.org:8080/green/job/clang-stage2-cmake-RgSan_build/).

rdar://30259929

Removed:
cfe/trunk/test/CodeGen/ubsan-shift.c
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=293475&r1=293474&r2=293475&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Mon Jan 30 05:37:18 2017
@@ -2751,8 +2751,8 @@ Value *ScalarExprEmitter::EmitShl(const
isa(Ops.LHS->getType())) {
 CodeGenFunction::SanitizerScope SanScope(&CGF);
 SmallVector, 2> Checks;
-llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, Ops.RHS);
-llvm::Value *ValidExponent = Builder.CreateICmpULE(Ops.RHS, WidthMinusOne);
+llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, RHS);
+llvm::Value *ValidExponent = Builder.CreateICmpULE(RHS, WidthMinusOne);
 
 if (SanitizeExponent) {
   Checks.push_back(

Removed: cfe/trunk/test/CodeGen/ubsan-shift.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-shift.c?rev=293474&view=auto
==
--- cfe/trunk/test/CodeGen/ubsan-shift.c (original)
+++ cfe/trunk/test/CodeGen/ubsan-shift.c (removed)
@@ -1,29 +0,0 @@
-// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsanitize=shift-exponent 
-emit-llvm %s -o - | FileCheck %s
-
-// CHECK-LABEL: define i32 @f1
-int f1(int c, int shamt) {
-// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
-// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
-  return 1 << (c << shamt);
-}
-
-// CHECK-LABEL: define i32 @f2
-int f2(long c, int shamt) {
-// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
-// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
-  return 1 << (c << shamt);
-}
-
-// CHECK-LABEL: define i32 @f3
-unsigned f3(unsigned c, int shamt) {
-// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
-// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
-  return 1U << (c << shamt);
-}
-
-// CHECK-LABEL: define i32 @f4
-unsigned f4(unsigned long c, int shamt) {
-// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
-// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
-  return 1U << (c << shamt);
-}


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


Re: r293343 - [ubsan] Sanity-check shift amounts before truncation (fixes PR27271)

2017-01-30 Thread Alex L via cfe-commits
Hi Vedant,

This commit has caused a compiler crash in our stage 2 green dragon
ASAN+Ubsan bot (
http://lab.llvm.org:8080/green/job/clang-stage2-cmake-RgSan_build/). I have
reverted it in r293475. The following example reproduces the crash with
-fsanitize=undefined :

  typedef unsigned long long uint64_t;
  typedef signed long long int64_t;

  uint64_t foo(int64_t x, unsigned i) {
   return x << i;
  }

Alex


On 27 January 2017 at 23:02, Vedant Kumar via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: vedantk
> Date: Fri Jan 27 17:02:44 2017
> New Revision: 293343
>
> URL: http://llvm.org/viewvc/llvm-project?rev=293343&view=rev
> Log:
> [ubsan] Sanity-check shift amounts before truncation (fixes PR27271)
>
> Ubsan does not report UB shifts in some cases where the shift exponent
> needs to be truncated to match the type of the shift base. We perform a
> range check on the truncated shift amount, leading to false negatives.
>
> Fix the issue (PR27271) by performing the range check on the original
> shift amount.
>
> Differential Revision: https://reviews.llvm.org/D29234
>
> Added:
> cfe/trunk/test/CodeGen/ubsan-shift.c
> Modified:
> cfe/trunk/lib/CodeGen/CGExprScalar.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/
> CGExprScalar.cpp?rev=293343&r1=293342&r2=293343&view=diff
> 
> ==
> --- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Jan 27 17:02:44 2017
> @@ -2751,8 +2751,8 @@ Value *ScalarExprEmitter::EmitShl(const
> isa(Ops.LHS->getType())) {
>  CodeGenFunction::SanitizerScope SanScope(&CGF);
>  SmallVector, 2> Checks;
> -llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, RHS);
> -llvm::Value *ValidExponent = Builder.CreateICmpULE(RHS,
> WidthMinusOne);
> +llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, Ops.RHS);
> +llvm::Value *ValidExponent = Builder.CreateICmpULE(Ops.RHS,
> WidthMinusOne);
>
>  if (SanitizeExponent) {
>Checks.push_back(
>
> Added: cfe/trunk/test/CodeGen/ubsan-shift.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> CodeGen/ubsan-shift.c?rev=293343&view=auto
> 
> ==
> --- cfe/trunk/test/CodeGen/ubsan-shift.c (added)
> +++ cfe/trunk/test/CodeGen/ubsan-shift.c Fri Jan 27 17:02:44 2017
> @@ -0,0 +1,29 @@
> +// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsanitize=shift-exponent
> -emit-llvm %s -o - | FileCheck %s
> +
> +// CHECK-LABEL: define i32 @f1
> +int f1(int c, int shamt) {
> +// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
> +// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
> +  return 1 << (c << shamt);
> +}
> +
> +// CHECK-LABEL: define i32 @f2
> +int f2(long c, int shamt) {
> +// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
> +// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
> +  return 1 << (c << shamt);
> +}
> +
> +// CHECK-LABEL: define i32 @f3
> +unsigned f3(unsigned c, int shamt) {
> +// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
> +// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
> +  return 1U << (c << shamt);
> +}
> +
> +// CHECK-LABEL: define i32 @f4
> +unsigned f4(unsigned long c, int shamt) {
> +// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
> +// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
> +  return 1U << (c << shamt);
> +}
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r293343 - [ubsan] Sanity-check shift amounts before truncation (fixes PR27271)

2017-01-30 Thread Filipe Cabecinhas via cfe-commits
Another example + possible fix (two WidthMinusOne, one per (possibly
different) bitwidth): (not fully tested)

int f() {
  return 0 << 0L;
}

diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index 40d949dece..5c9055d49a 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -2751,8 +2751,9 @@ Value *ScalarExprEmitter::EmitShl(const BinOpInfo &Ops) {
isa(Ops.LHS->getType())) {
 CodeGenFunction::SanitizerScope SanScope(&CGF);
 SmallVector, 2> Checks;
-llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, Ops.RHS);
-llvm::Value *ValidExponent = Builder.CreateICmpULE(Ops.RHS, WidthMinusOne);
+llvm::Value *WidthMinusOneRHS = GetWidthMinusOneValue(Ops.LHS, Ops.RHS);
+llvm::Value *WidthMinusOneLHS = GetWidthMinusOneValue(Ops.LHS, Ops.LHS);
+llvm::Value *ValidExponent = Builder.CreateICmpULE(Ops.RHS,
WidthMinusOneRHS);

 if (SanitizeExponent) {
   Checks.push_back(
@@ -2768,11 +2769,11 @@ Value *ScalarExprEmitter::EmitShl(const
BinOpInfo &Ops) {
   llvm::BasicBlock *CheckShiftBase = CGF.createBasicBlock("check");
   Builder.CreateCondBr(ValidExponent, CheckShiftBase, Cont);
   CGF.EmitBlock(CheckShiftBase);
-  llvm::Value *BitsShiftedOff =
-Builder.CreateLShr(Ops.LHS,
-   Builder.CreateSub(WidthMinusOne, RHS, "shl.zeros",
- /*NUW*/true, /*NSW*/true),
-   "shl.check");
+  llvm::Value *BitsShiftedOff = Builder.CreateLShr(
+  Ops.LHS,
+  Builder.CreateSub(WidthMinusOneLHS, RHS, "shl.zeros",
+/*NUW*/ true, /*NSW*/ true),
+  "shl.check");
   if (CGF.getLangOpts().CPlusPlus) {
 // In C99, we are not permitted to shift a 1 bit into the sign bit.
 // Under C++11's rules, shifting a 1 bit into the sign bit is
  F


On Mon, Jan 30, 2017 at 11:51 AM, Alex L via cfe-commits
 wrote:
> Hi Vedant,
>
> This commit has caused a compiler crash in our stage 2 green dragon
> ASAN+Ubsan bot
> (http://lab.llvm.org:8080/green/job/clang-stage2-cmake-RgSan_build/). I have
> reverted it in r293475. The following example reproduces the crash with
> -fsanitize=undefined :
>
>   typedef unsigned long long uint64_t;
>   typedef signed long long int64_t;
>
>   uint64_t foo(int64_t x, unsigned i) {
>return x << i;
>   }
>
> Alex
>
>
> On 27 January 2017 at 23:02, Vedant Kumar via cfe-commits
>  wrote:
>>
>> Author: vedantk
>> Date: Fri Jan 27 17:02:44 2017
>> New Revision: 293343
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=293343&view=rev
>> Log:
>> [ubsan] Sanity-check shift amounts before truncation (fixes PR27271)
>>
>> Ubsan does not report UB shifts in some cases where the shift exponent
>> needs to be truncated to match the type of the shift base. We perform a
>> range check on the truncated shift amount, leading to false negatives.
>>
>> Fix the issue (PR27271) by performing the range check on the original
>> shift amount.
>>
>> Differential Revision: https://reviews.llvm.org/D29234
>>
>> Added:
>> cfe/trunk/test/CodeGen/ubsan-shift.c
>> Modified:
>> cfe/trunk/lib/CodeGen/CGExprScalar.cpp
>>
>> Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=293343&r1=293342&r2=293343&view=diff
>>
>> ==
>> --- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Jan 27 17:02:44 2017
>> @@ -2751,8 +2751,8 @@ Value *ScalarExprEmitter::EmitShl(const
>> isa(Ops.LHS->getType())) {
>>  CodeGenFunction::SanitizerScope SanScope(&CGF);
>>  SmallVector, 2> Checks;
>> -llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, RHS);
>> -llvm::Value *ValidExponent = Builder.CreateICmpULE(RHS,
>> WidthMinusOne);
>> +llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, Ops.RHS);
>> +llvm::Value *ValidExponent = Builder.CreateICmpULE(Ops.RHS,
>> WidthMinusOne);
>>
>>  if (SanitizeExponent) {
>>Checks.push_back(
>>
>> Added: cfe/trunk/test/CodeGen/ubsan-shift.c
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-shift.c?rev=293343&view=auto
>>
>> ==
>> --- cfe/trunk/test/CodeGen/ubsan-shift.c (added)
>> +++ cfe/trunk/test/CodeGen/ubsan-shift.c Fri Jan 27 17:02:44 2017
>> @@ -0,0 +1,29 @@
>> +// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsanitize=shift-exponent
>> -emit-llvm %s -o - | FileCheck %s
>> +
>> +// CHECK-LABEL: define i32 @f1
>> +int f1(int c, int shamt) {
>> +// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
>> +// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
>> +  return 1 << (c << shamt);
>> +}
>> +
>> +// CHECK-LABEL: define i32 @f2
>> +int f2(long c, int shamt) {
>> +// CHECK: icmp ul

r293473 - Revert r293455, which breaks v8 with a spurious error. Testcase added.

2017-01-30 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Mon Jan 30 04:44:11 2017
New Revision: 293473

URL: http://llvm.org/viewvc/llvm-project?rev=293473&view=rev
Log:
Revert r293455, which breaks v8 with a spurious error. Testcase added.

Summary: Revert r293455, which breaks v8 with a spurious error. Testcase added.

Reviewers: klimek

Subscribers: cfe-commits, rsmith

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

Modified:
cfe/trunk/include/clang/AST/DeclTemplate.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp
cfe/trunk/test/SemaCXX/cxx0x-class.cpp

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=293473&r1=293472&r2=293473&view=diff
==
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Mon Jan 30 04:44:11 2017
@@ -2946,16 +2946,6 @@ inline NamedDecl *getAsNamedDecl(Templat
   return P.get();
 }
 
-inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) {
-  auto *TD = dyn_cast(D);
-  return TD && (isa(TD) ||
-isa(TD) ||
-isa(TD) ||
-isa(TD))
- ? TD
- : nullptr;
-}
-
 } /* end of namespace clang */
 
 #endif

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=293473&r1=293472&r2=293473&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jan 30 04:44:11 
2017
@@ -1884,11 +1884,6 @@ def err_auto_not_allowed : Error<
   "|in conversion function type|here|in lambda parameter"
   "|in type allocated by 'new'|in K&R-style function parameter"
   "|in template parameter|in friend declaration}1">;
-def err_dependent_deduced_tst : Error<
-  "typename specifier refers to "
-  "%select{class template|function template|variable template|alias template|"
-  "template template parameter|template}0 member in %1; "
-  "argument deduction not allowed here">;
 def err_auto_not_allowed_var_inst : Error<
   "'auto' variable template instantiation is not allowed">;
 def err_auto_var_requires_init : Error<

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=293473&r1=293472&r2=293473&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Jan 30 04:44:11 2017
@@ -7359,8 +7359,7 @@ public:
 
   TypeSourceInfo *SubstType(TypeSourceInfo *T,
 const MultiLevelTemplateArgumentList &TemplateArgs,
-SourceLocation Loc, DeclarationName Entity,
-bool AllowDeducedTST = false);
+SourceLocation Loc, DeclarationName Entity);
 
   QualType SubstType(QualType T,
  const MultiLevelTemplateArgumentList &TemplateArgs,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=293473&r1=293472&r2=293473&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan 30 04:44:11 2017
@@ -60,6 +60,11 @@ Sema::DeclGroupPtrTy Sema::ConvertDeclTo
   return DeclGroupPtrTy::make(DeclGroupRef(Ptr));
 }
 
+static bool isTypeTemplate(NamedDecl *ND) {
+  return isa(ND) || isa(ND) ||
+ isa(ND);
+}
+
 namespace {
 
 class TypeNameValidatorCCC : public CorrectionCandidateCallback {
@@ -76,7 +81,7 @@ class TypeNameValidatorCCC : public Corr
   bool ValidateCandidate(const TypoCorrection &candidate) override {
 if (NamedDecl *ND = candidate.getCorrectionDecl()) {
   bool IsType = isa(ND) || isa(ND);
-  bool AllowedTemplate = AllowTemplates && getAsTypeTemplateDecl(ND);
+  bool AllowedTemplate = AllowTemplates && isTypeTemplate(ND);
   return (IsType || AllowedTemplate) &&
  (AllowInvalidDecl || !ND->isInvalidDecl());
 }
@@ -400,7 +405,7 @@ ParsedType Sema::getTypeName(const Ident
 for (LookupResult::iterator Res = Result.begin(), ResEnd = Result.end();
  Res != ResEnd; ++Res) {
   if (isa(*Res) || isa(*Res) ||
-  (AllowDeducedTemplate && getAsTypeTemplateDecl(*Res))) {
+  (AllowDeducedTemplate && isType

[PATCH] D27985: Add demangling support for C++11 thread_local variables

2017-01-30 Thread Dave Bozier via Phabricator via cfe-commits
davidb added a comment.

In https://reviews.llvm.org/D27985#660029, @mehdi_amini wrote:

> LGTM.
>
> Can you apply the patch in LLVM (libDemangle) as well please?


Thank you Mehdi. I have an LLVM (libDemangle) with an identical change (minus 
the tests) waiting. Would you like my to submit it as a separate patch?

I've just requested commit access so fingers crossed I can apply them both soon.


Repository:
  rL LLVM

https://reviews.llvm.org/D27985



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


r293485 - [IRGen] Make header standalone.

2017-01-30 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Mon Jan 30 09:39:18 2017
New Revision: 293485

URL: http://llvm.org/viewvc/llvm-project?rev=293485&view=rev
Log:
[IRGen] Make header standalone.

Modified:
cfe/trunk/lib/CodeGen/ABIInfo.h

Modified: cfe/trunk/lib/CodeGen/ABIInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ABIInfo.h?rev=293485&r1=293484&r2=293485&view=diff
==
--- cfe/trunk/lib/CodeGen/ABIInfo.h (original)
+++ cfe/trunk/lib/CodeGen/ABIInfo.h Mon Jan 30 09:39:18 2017
@@ -10,6 +10,7 @@
 #ifndef LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
 #define LLVM_CLANG_LIB_CODEGEN_ABIINFO_H
 
+#include "clang/AST/CharUnits.h"
 #include "clang/AST/Type.h"
 #include "llvm/IR/CallingConv.h"
 #include "llvm/IR/Type.h"


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


Re: r293395 - Modules: Clarify ownership of ModuleFile instances in ModuleManager, NFC

2017-01-30 Thread David Blaikie via cfe-commits
Thanks! Always love to see cleanup like this :)

On Sat, Jan 28, 2017 at 2:35 PM Duncan P. N. Exon Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: dexonsmith
> Date: Sat Jan 28 16:24:01 2017
> New Revision: 293395
>
> URL: http://llvm.org/viewvc/llvm-project?rev=293395&view=rev
> Log:
> Modules: Clarify ownership of ModuleFile instances in ModuleManager, NFC
>
> Use std::unique_ptr to clarify the ownership of the ModuleFile instances in
> ModuleManager.
>
> Modified:
> cfe/trunk/include/clang/Serialization/ModuleManager.h
> cfe/trunk/lib/Serialization/ModuleManager.cpp
>
> Modified: cfe/trunk/include/clang/Serialization/ModuleManager.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ModuleManager.h?rev=293395&r1=293394&r2=293395&view=diff
>
> ==
> --- cfe/trunk/include/clang/Serialization/ModuleManager.h (original)
> +++ cfe/trunk/include/clang/Serialization/ModuleManager.h Sat Jan 28
> 16:24:01 2017
> @@ -33,7 +33,7 @@ namespace serialization {
>  class ModuleManager {
>/// \brief The chain of AST files, in the order in which we started to
> load
>/// them (this order isn't really useful for anything).
> -  SmallVector Chain;
> +  SmallVector, 2> Chain;
>
>/// \brief The chain of non-module PCH files. The first entry is the
> one named
>/// by the user, the last one is the one that doesn't depend on anything
> @@ -112,12 +112,14 @@ class ModuleManager {
>void returnVisitState(VisitState *State);
>
>  public:
> -  typedef llvm::pointee_iterator::iterator>
> +  typedef llvm::pointee_iterator<
> +  SmallVectorImpl>::iterator>
>ModuleIterator;
> -  typedef llvm::pointee_iterator *>::const_iterator>
> +  typedef llvm::pointee_iterator<
> +  SmallVectorImpl>::const_iterator>
>ModuleConstIterator;
>typedef llvm::pointee_iterator<
> -  SmallVectorImpl::reverse_iterator>
> +  SmallVectorImpl>::reverse_iterator>
>ModuleReverseIterator;
>typedef std::pair ModuleOffset;
>
>
> Modified: cfe/trunk/lib/Serialization/ModuleManager.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ModuleManager.cpp?rev=293395&r1=293394&r2=293395&view=diff
>
> ==
> --- cfe/trunk/lib/Serialization/ModuleManager.cpp (original)
> +++ cfe/trunk/lib/Serialization/ModuleManager.cpp Sat Jan 28 16:24:01 2017
> @@ -96,30 +96,29 @@ ModuleManager::addModule(StringRef FileN
>
>// Check whether we already loaded this module, before
>ModuleFile *ModuleEntry = Modules[Entry];
> -  bool NewModule = false;
> +  std::unique_ptr NewModule;
>if (!ModuleEntry) {
>  // Allocate a new module.
> -NewModule = true;
> -ModuleEntry = new ModuleFile(Type, Generation);
> -ModuleEntry->Index = Chain.size();
> -ModuleEntry->FileName = FileName.str();
> -ModuleEntry->File = Entry;
> -ModuleEntry->ImportLoc = ImportLoc;
> -ModuleEntry->InputFilesValidationTimestamp = 0;
> +NewModule = llvm::make_unique(Type, Generation);
> +NewModule->Index = Chain.size();
> +NewModule->FileName = FileName.str();
> +NewModule->File = Entry;
> +NewModule->ImportLoc = ImportLoc;
> +NewModule->InputFilesValidationTimestamp = 0;
>
> -if (ModuleEntry->Kind == MK_ImplicitModule) {
> -  std::string TimestampFilename = ModuleEntry->getTimestampFilename();
> +if (NewModule->Kind == MK_ImplicitModule) {
> +  std::string TimestampFilename = NewModule->getTimestampFilename();
>vfs::Status Status;
>// A cached stat value would be fine as well.
>if (!FileMgr.getNoncachedStatValue(TimestampFilename, Status))
> -ModuleEntry->InputFilesValidationTimestamp =
> +NewModule->InputFilesValidationTimestamp =
>  llvm::sys::toTimeT(Status.getLastModificationTime());
>  }
>
>  // Load the contents of the module
>  if (std::unique_ptr Buffer =
> lookupBuffer(FileName)) {
>// The buffer was already provided for us.
> -  ModuleEntry->Buffer = std::move(Buffer);
> +  NewModule->Buffer = std::move(Buffer);
>  } else {
>// Open the AST file.
>llvm::ErrorOr> Buf(
> @@ -131,28 +130,28 @@ ModuleManager::addModule(StringRef FileN
>  // ModuleManager it must be the same underlying file.
>  // FIXME: Because FileManager::getFile() doesn't guarantee that
> it will
>  // give us an open file, this may not be 100% reliable.
> -Buf = FileMgr.getBufferForFile(ModuleEntry->File,
> +Buf = FileMgr.getBufferForFile(NewModule->File,
> /*IsVolatile=*/false,
> /*ShouldClose=*/false);
>}
>
>if (!Buf) {
>  ErrorStr = Buf.getError().message();
> -delete ModuleEntry;
>  return Missing;
>}
>

[PATCH] D29267: [clang-tidy] safety-no-assembler

2017-01-30 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe updated this revision to Diff 86289.
jbcoe added a comment.

Add link to HIC++ website and fix release notes.


https://reviews.llvm.org/D29267

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/safety/CMakeLists.txt
  clang-tools-extra/clang-tidy/safety/NoAssemblerCheck.cpp
  clang-tools-extra/clang-tidy/safety/NoAssemblerCheck.h
  clang-tools-extra/clang-tidy/safety/SafetyTidyModule.cpp
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/safety-no-assembler.rst
  clang-tools-extra/test/clang-tidy/safety-no-assembler.cpp

Index: clang-tools-extra/test/clang-tidy/safety-no-assembler.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/safety-no-assembler.cpp
@@ -0,0 +1,7 @@
+// RUN: %check_clang_tidy %s safety-no-assembler %t
+
+void f() {
+  __asm("mov al, 2");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '__asm("mov al, 2")' is an inline assembler statement [safety-no-assembler]
+}
+
Index: clang-tools-extra/docs/clang-tidy/checks/safety-no-assembler.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/safety-no-assembler.rst
@@ -0,0 +1,10 @@
+.. title:: clang-tidy - safety-no-assembler
+
+safety-no-assembler
+===
+
+Check for assembler statements. No fix is offered.
+
+Inline assembler is forbidden by safety-critical C++ standards like `High
+Intergrity C++ `_ as it restricts the
+portability of code.
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -152,3 +152,5 @@
readability-simplify-boolean-expr
readability-static-definition-in-anonymous-namespace
readability-uniqueptr-delete-release
+   safety-no-assembler
+   safety-no-vector-bool
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -57,7 +57,10 @@
 Improvements to clang-tidy
 --
 
-The improvements are...
+- New `safety-no-assembler
+  `_ check
+
+  Finds uses of inline assembler.
 
 Improvements to include-fixer
 -
Index: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -475,6 +475,11 @@
 static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
 ReadabilityModuleAnchorSource;
 
+// This anchor is used to force the linker to link the SafetyModule.
+extern volatile int SafetyModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED SafetyModuleAnchorDestination =
+SafetyModuleAnchorSource;
+
 } // namespace tidy
 } // namespace clang
 
Index: clang-tools-extra/clang-tidy/tool/CMakeLists.txt
===
--- clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -23,6 +23,7 @@
   clangTidyMPIModule
   clangTidyPerformanceModule
   clangTidyReadabilityModule
+  clangTidySafetyModule
   clangTooling
   )
 
Index: clang-tools-extra/clang-tidy/safety/SafetyTidyModule.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/safety/SafetyTidyModule.cpp
@@ -0,0 +1,38 @@
+//===--- SafetyTidyModule.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 "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "NoAssemblerCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace safety {
+
+class SafetyModule : public ClangTidyModule {
+public:
+  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck(
+"safety-no-assembler");
+  }
+};
+
+// Register the SafetyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add
+X("safety-module", "Adds safety-critical checks.");
+
+} // namespace safety
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register t

r293488 - [AST] Make header standalone.

2017-01-30 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Mon Jan 30 10:00:57 2017
New Revision: 293488

URL: http://llvm.org/viewvc/llvm-project?rev=293488&view=rev
Log:
[AST] Make header standalone.

Most implementations get ptrdiff_t transitively, some don't. Explicitly
include cstddef.

Modified:
cfe/trunk/include/clang/AST/ASTVector.h

Modified: cfe/trunk/include/clang/AST/ASTVector.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTVector.h?rev=293488&r1=293487&r2=293488&view=diff
==
--- cfe/trunk/include/clang/AST/ASTVector.h (original)
+++ cfe/trunk/include/clang/AST/ASTVector.h Mon Jan 30 10:00:57 2017
@@ -22,6 +22,7 @@
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/Support/type_traits.h"
 #include 
+#include 
 #include 
 #include 
 


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


Re: r293416 - [c-index-test] Provide capability for 'c-index-test core' to dump symbol information from a PCH/module file.

2017-01-30 Thread Argyrios Kyrtzidis via cfe-commits
Hi Hans,

Could this go into the stable branch, along with the follow-ups:
r293461
r293463
r293466

> On Jan 28, 2017, at 8:50 PM, Argyrios Kyrtzidis via cfe-commits 
>  wrote:
> 
> Author: akirtzidis
> Date: Sat Jan 28 22:50:35 2017
> New Revision: 293416
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=293416&view=rev
> Log:
> [c-index-test] Provide capability for 'c-index-test core' to dump symbol 
> information from a PCH/module file.
> 
> Added:
>cfe/trunk/test/Index/Core/index-pch.c
> Modified:
>cfe/trunk/tools/c-index-test/CMakeLists.txt
>cfe/trunk/tools/c-index-test/core_main.cpp
> 
> Added: cfe/trunk/test/Index/Core/index-pch.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-pch.c?rev=293416&view=auto
> ==
> --- cfe/trunk/test/Index/Core/index-pch.c (added)
> +++ cfe/trunk/test/Index/Core/index-pch.c Sat Jan 28 22:50:35 2017
> @@ -0,0 +1,13 @@
> +// RUN: c-index-test core -print-source-symbols -- %s | FileCheck %s
> +// RUN: %clang_cc1 -emit-pch %s -o %t.pch
> +// RUN: c-index-test core -print-source-symbols -module-file %t.pch | 
> FileCheck %s
> +
> +// CHECK: [[@LINE+1]]:6 | function/C | test1 | [[TEST1_USR:.*]] | 
> [[TEST1_CG:.*]] | Decl | rel: 0
> +void test1();
> +
> +// CHECK: [[@LINE+1]]:20 | function/C | test2 | [[TEST2_USR:.*]] | {{.*}} | 
> Def | rel: 0
> +static inline void test2() {
> +  // CHECK: [[@LINE+2]]:3 | function/C | test1 | [[TEST1_USR]] | 
> [[TEST1_CG]] | Ref,Call,RelCall,RelCont | rel: 1
> +  // CHECK-NEXT: RelCall,RelCont | test2 | [[TEST2_USR]]
> +  test1();
> +}
> 
> Modified: cfe/trunk/tools/c-index-test/CMakeLists.txt
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/CMakeLists.txt?rev=293416&r1=293415&r2=293416&view=diff
> ==
> --- cfe/trunk/tools/c-index-test/CMakeLists.txt (original)
> +++ cfe/trunk/tools/c-index-test/CMakeLists.txt Sat Jan 28 22:50:35 2017
> @@ -24,6 +24,7 @@ else()
> libclang
> clangAST
> clangBasic
> +clangCodeGen
> clangFrontend
> clangIndex
>   )
> 
> Modified: cfe/trunk/tools/c-index-test/core_main.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/core_main.cpp?rev=293416&r1=293415&r2=293416&view=diff
> ==
> --- cfe/trunk/tools/c-index-test/core_main.cpp (original)
> +++ cfe/trunk/tools/c-index-test/core_main.cpp Sat Jan 28 22:50:35 2017
> @@ -7,6 +7,7 @@
> //
> //===--===//
> 
> +#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
> #include "clang/Frontend/ASTUnit.h"
> #include "clang/Frontend/CompilerInstance.h"
> #include "clang/Frontend/CompilerInvocation.h"
> @@ -49,6 +50,13 @@ static cl::extrahelp MoreHelp(
>   "invocation\n"
> );
> 
> +static cl::opt
> +ModuleFilePath("module-file",
> +   cl::desc("Path to module file to print symbols from"));
> +static cl::opt
> +  ModuleFormat("fmodule-format", cl::init("raw"),
> +cl::desc("Container format for clang modules and PCH, 'raw' or 
> 'obj'"));
> +
> }
> } // anonymous namespace
> 
> @@ -160,6 +168,39 @@ static bool printSourceSymbols(ArrayRef<
>   return false;
> }
> 
> +static bool printSourceSymbolsFromModule(StringRef modulePath,
> + StringRef format) {
> +  FileSystemOptions FileSystemOpts;
> +  auto pchContOps = std::make_shared();
> +  // Register the support for object-file-wrapped Clang modules.
> +  
> pchContOps->registerReader(llvm::make_unique());
> +  auto pchRdr = pchContOps->getReaderOrNull(format);
> +  if (!pchRdr) {
> +errs() << "unknown module format: " << format << '\n';
> +return true;
> +  }
> +
> +  IntrusiveRefCntPtr Diags =
> +  CompilerInstance::createDiagnostics(new DiagnosticOptions());
> +  std::unique_ptr AU = ASTUnit::LoadFromASTFile(
> +  modulePath, *pchRdr, Diags,
> +  FileSystemOpts, /*UseDebugInfo=*/false,
> +  /*OnlyLocalDecls=*/true, None,
> +  /*CaptureDiagnostics=*/false,
> +  /*AllowPCHWithCompilerErrors=*/true,
> +  /*UserFilesAreVolatile=*/false);
> +  if (!AU) {
> +errs() << "failed to create TU for: " << modulePath << '\n';
> +return true;
> +  }
> +
> +  auto DataConsumer = std::make_shared(outs());
> +  IndexingOptions IndexOpts;
> +  indexASTUnit(*AU, DataConsumer, IndexOpts);
> +
> +  return false;
> +}
> +
> //===--===//
> // Helper Utils
> //===--===//
> @@ -219,6 +260,10 @@ int indextest_core_main(int argc, const
>   }
> 
>   if (options::Action == ActionType::PrintSourceSymbols) {
> +if (!options::ModuleFilePath.empty()) {
> +  return printSourceSymbolsFromModule(options::M

Re: [PATCH] D28007: Switch TableGen to emit calls to ASTRecordReader for AttrPCHRead.

2017-01-30 Thread David Blaikie via cfe-commits
This review thread is missing on-list approval. I assume it happened on
Phab & just wasn't reflected here (if the Phab approval has no text it
doesn't send an email, which is unfortunate - not sure if anyone's planning
to fix that/change the settings, but until then it's helpful to include
"LGTM" or something in the comment field when approving)

On Mon, Jan 23, 2017 at 5:16 PM David L. Jones via Phabricator via
cfe-commits  wrote:

> This revision was automatically updated to reflect the committed changes.
> Closed by commit rL292868: Switch TableGen to emit calls to
> ASTRecordReader for AttrPCHRead. (authored by dlj).
>
> Changed prior to commit:
>   https://reviews.llvm.org/D28007?vs=85493&id=85498#toc
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D28007
>
> Files:
>   cfe/trunk/include/clang/Serialization/ASTReader.h
>   cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
>   cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2017-01-30 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh updated this revision to Diff 86292.
danielcdh added a comment.

update


https://reviews.llvm.org/D29205

Files:
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGDebugInfo.cpp


Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -509,7 +509,8 @@
Checksum),
   Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
   CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */,
-  CGM.getCodeGenOpts().SplitDwarfInlining);
+  CGM.getCodeGenOpts().SplitDwarfInlining,
+  CGM.getCodeGenOpts().DebugInfoForProfiling);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -573,7 +573,6 @@
   Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
   Options.CompressDebugSections = CodeGenOpts.CompressDebugSections;
   Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
-  Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling;
 
   // Set EABI version.
   Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion)


Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -509,7 +509,8 @@
Checksum),
   Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
   CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */,
-  CGM.getCodeGenOpts().SplitDwarfInlining);
+  CGM.getCodeGenOpts().SplitDwarfInlining,
+  CGM.getCodeGenOpts().DebugInfoForProfiling);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const BuiltinType *BT) {
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -573,7 +573,6 @@
   Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
   Options.CompressDebugSections = CodeGenOpts.CompressDebugSections;
   Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
-  Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling;
 
   // Set EABI version.
   Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293493 - Adjust tests after folding inlining analysis into missed remarks

2017-01-30 Thread Adam Nemet via cfe-commits
Author: anemet
Date: Mon Jan 30 10:22:50 2017
New Revision: 293493

URL: http://llvm.org/viewvc/llvm-project?rev=293493&view=rev
Log:
Adjust tests after folding inlining analysis into missed remarks

Modified:
cfe/trunk/test/Frontend/optimization-remark-with-hotness.c
cfe/trunk/test/Frontend/optimization-remark.c

Modified: cfe/trunk/test/Frontend/optimization-remark-with-hotness.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/optimization-remark-with-hotness.c?rev=293493&r1=293492&r2=293493&view=diff
==
--- cfe/trunk/test/Frontend/optimization-remark-with-hotness.c (original)
+++ cfe/trunk/test/Frontend/optimization-remark-with-hotness.c Mon Jan 30 
10:22:50 2017
@@ -4,11 +4,13 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
-// RUN: -Rpass-analysis=inline -fdiagnostics-show-hotness -verify
+// RUN: -Rpass-analysis=inline -Rpass-missed=inline \
+// RUN: -fdiagnostics-show-hotness -verify
 // The clang version of the previous test.
 // RUN: %clang -target x86_64-apple-macosx10.9 %s -c -emit-llvm -o /dev/null \
 // RUN: -fprofile-instr-use=%t.profdata -Rpass=inline \
-// RUN: -Rpass-analysis=inline -fdiagnostics-show-hotness -Xclang -verify
+// RUN: -Rpass-analysis=inline -Rpass-missed=inline \
+// RUN: -fdiagnostics-show-hotness -Xclang -verify
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name \
 // RUN: optimization-remark-with-hotness.c %s -emit-llvm-only \
 // RUN: -fprofile-instrument-use-path=%t.profdata -Rpass=inline \
@@ -39,7 +41,7 @@ void bar(int x) {
 
 int main(int argc, const char *argv[]) {
   for (int i = 0; i < 30; i++)
-// expected-remark@+1 {{bar should never be inlined}}
+// expected-remark@+1 {{bar not inlined into main because it should never 
be inlined}}
 bar(argc);
   return sum;
 }

Modified: cfe/trunk/test/Frontend/optimization-remark.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/optimization-remark.c?rev=293493&r1=293492&r2=293493&view=diff
==
--- cfe/trunk/test/Frontend/optimization-remark.c (original)
+++ cfe/trunk/test/Frontend/optimization-remark.c Mon Jan 30 10:22:50 2017
@@ -42,10 +42,8 @@ float foz(int x, int y) { return x * y;
 // twice.
 //
 int bar(int j) {
-// expected-remark@+6 {{foz should never be inlined (cost=never)}}
-// expected-remark@+5 {{foz will not be inlined into bar}}
-// expected-remark@+4 {{foz should never be inlined}}
-// expected-remark@+3 {{foz will not be inlined into bar}}
+// expected-remark@+4 {{foz not inlined into bar because it should never be 
inlined (cost=never)}}
+// expected-remark@+3 {{foz not inlined into bar because it should never be 
inlined (cost=never)}}
 // expected-remark@+2 {{foo should always be inlined}}
 // expected-remark@+1 {{foo inlined into bar}}
   return foo(j, j - 2) * foz(j - 2, j);


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


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

2017-01-30 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Ping?


https://reviews.llvm.org/D29152



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


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

2017-01-30 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D29152



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


[PATCH] D29262: Fixes to modernize-use-using

2017-01-30 Thread Krystyna via Phabricator via cfe-commits
krystyna updated this revision to Diff 86298.
krystyna edited the summary of this revision.
krystyna added a comment.

Style fixes.


https://reviews.llvm.org/D29262

Files:
  clang-tidy/modernize/UseUsingCheck.cpp
  clang-tidy/modernize/UseUsingCheck.h
  test/clang-tidy/modernize-use-using-macros.cpp
  test/clang-tidy/modernize-use-using.cpp

Index: test/clang-tidy/modernize-use-using.cpp
===
--- test/clang-tidy/modernize-use-using.cpp
+++ test/clang-tidy/modernize-use-using.cpp
@@ -89,7 +89,6 @@
 #define CODE typedef int INT
 
 CODE;
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: #define CODE typedef int INT
 // CHECK-FIXES: CODE;
 
@@ -102,7 +101,6 @@
 
 #define TYPEDEF typedef
 TYPEDEF Foo Bak;
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: #define TYPEDEF typedef
 // CHECK-FIXES: TYPEDEF Foo Bak;
 
@@ -148,3 +146,18 @@
 struct { int d; } typedef S4;
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: struct { int d; } typedef S4;
+
+namespace my_space {
+  class my_cclass {};
+  typedef my_cclass FuncType;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using FuncType = my_cclass
+}
+
+#define lol 4
+typedef unsigned Map[lol]; 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+
+typedef void (*fun_type)();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using fun_type = void (*)();
Index: test/clang-tidy/modernize-use-using-macros.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-using-macros.cpp
@@ -0,0 +1,23 @@
+// RUN: %check_clang_tidy %s modernize-use-using %t -- \
+// RUN:   -config="{CheckOptions: [{key: modernize-use-using.MacroWarning, value: 1}]}" \
+// RUN:   -- -std=c++11 -I %S/Inputs/modernize-use-using
+
+#define CODE typedef int INT
+
+CODE;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: #define CODE typedef int INT
+// CHECK-FIXES: CODE;
+
+struct Foo;
+#define Bar Baz
+typedef Foo Bar;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: #define Bar Baz
+// CHECK-FIXES: using Baz = Foo;
+
+#define TYPEDEF typedef
+TYPEDEF Foo Bak;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: #define TYPEDEF typedef
+// CHECK-FIXES: TYPEDEF Foo Bak;
Index: clang-tidy/modernize/UseUsingCheck.h
===
--- clang-tidy/modernize/UseUsingCheck.h
+++ clang-tidy/modernize/UseUsingCheck.h
@@ -21,11 +21,15 @@
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize-use-using.html
 class UseUsingCheck : public ClangTidyCheck {
+
 public:
-  UseUsingCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  UseUsingCheck(StringRef Name, ClangTidyContext *Context);
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  const bool MacroWarning;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/UseUsingCheck.cpp
===
--- clang-tidy/modernize/UseUsingCheck.cpp
+++ clang-tidy/modernize/UseUsingCheck.cpp
@@ -17,12 +17,20 @@
 namespace tidy {
 namespace modernize {
 
+UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  MacroWarning(Options.get("MacroWarning", false)) {}
+
 void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus11)
 return;
   Finder->addMatcher(typedefDecl().bind("typedef"), this);
 }
 
+void UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "MacroWarning", MacroWarning);
+}
+
 // Checks if 'typedef' keyword can be removed - we do it only if
 // it is the only declaration in a declaration chain.
 static bool CheckRemoval(SourceManager &SM, SourceLocation StartLoc,
@@ -80,22 +88,32 @@
   auto &SM = *Result.SourceManager;
 
   if (auto *D = MatchedDecl->getUnderlyingType()->getAsCXXRecordDecl()) {
-//TypeLoc TL = MatchedDecl->getTypeSourceInfo()->getTypeLoc();
+// TypeLoc TL = MatchedDecl->getTypeSourceInfo()->getTypeLoc();
 llvm::errs() << D->getNameAsString() << "\n";
   }
 
+  SourceLocation StartLoc = MatchedDecl->getLocStart();
+
+  if (StartLoc.isMacroID() && !MacroWarning)
+return;
+
   auto Diag =
   diag(MatchedDecl->getLocStart(), "use 'using' instead of 'typedef'");
 
-  SourceLocation StartLoc = MatchedDecl->getLocStart();
- 

[PATCH] D27985: Add demangling support for C++11 thread_local variables

2017-01-30 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

In https://reviews.llvm.org/D27985#660354, @davidb wrote:

> In https://reviews.llvm.org/D27985#660029, @mehdi_amini wrote:
>
> > LGTM.
> >
> > Can you apply the patch in LLVM (libDemangle) as well please?
>
>
> Thank you Mehdi. I have an LLVM (libDemangle) with an identical change (minus 
> the tests) waiting. Would you like my to submit it as a separate patch?


No, just commit it.


Repository:
  rL LLVM

https://reviews.llvm.org/D27985



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


RE: r293457 - Tidy up codegen modules test & make it x86 specific since it relies on Itanium name manglings

2017-01-30 Thread Robinson, Paul via cfe-commits
Use %itanium_abi_triple instead?

> -Original Message-
> From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf Of
> David Blaikie via cfe-commits
> Sent: Sunday, January 29, 2017 9:34 PM
> To: cfe-commits@lists.llvm.org
> Subject: r293457 - Tidy up codegen modules test & make it x86 specific
> since it relies on Itanium name manglings
> 
> Author: dblaikie
> Date: Sun Jan 29 23:33:51 2017
> New Revision: 293457
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=293457&view=rev
> Log:
> Tidy up codegen modules test & make it x86 specific since it relies on
> Itanium name manglings
> 
> Modified:
> cfe/trunk/test/Modules/codegen.test
> 
> Modified: cfe/trunk/test/Modules/codegen.test
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/test/Modules/codegen.test?rev=293457&r1=293456&r2=293457
> &view=diff
> ==
> 
> --- cfe/trunk/test/Modules/codegen.test (original)
> +++ cfe/trunk/test/Modules/codegen.test Sun Jan 29 23:33:51 2017
> @@ -1,15 +1,16 @@
>  RUN: rm -rf %t
> +REQUIRES: x86-registered-target
> 
> -RUN: %clang_cc1 -fmodules-codegen -x c++ -fmodules -emit-module -fmodule-
> name=foo %S/Inputs/codegen/foo.modulemap -o %t/foo.pcm
> -RUN: %clang_cc1 -fmodules-codegen -x c++ -fmodules -emit-module -fmodule-
> name=bar %S/Inputs/codegen/bar.modulemap -o %t/bar.pcm -fmodule-
> file=%t/foo.pcm
> +RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-codegen -x c++ -
> fmodules -emit-module -fmodule-name=foo %S/Inputs/codegen/foo.modulemap -o
> %t/foo.pcm
> +RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-codegen -x c++ -
> fmodules -emit-module -fmodule-name=bar %S/Inputs/codegen/bar.modulemap -o
> %t/bar.pcm -fmodule-file=%t/foo.pcm
> 
> -RUN: %clang_cc1 -emit-llvm %t/foo.pcm -o - | FileCheck --check-prefix=FOO
> %s
> -RUN: %clang_cc1 -emit-llvm %t/bar.pcm -o - -fmodule-file=%t/foo.pcm |
> FileCheck --check-prefix=BAR-CMN --check-prefix=BAR %s
> -RUN: %clang_cc1 -fmodules -fmodule-file=%t/foo.pcm -fmodule-
> file=%t/bar.pcm %S/Inputs/codegen/use.cpp -emit-llvm -o - | FileCheck --
> check-prefix=USE-CMN --check-prefix=USE %s
> +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %t/foo.pcm |
> FileCheck --check-prefix=FOO %s
> +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %t/bar.pcm -
> fmodule-file=%t/foo.pcm | FileCheck --check-prefix=BAR-CMN --check-
> prefix=BAR %s
> +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -fmodules -
> fmodule-file=%t/foo.pcm -fmodule-file=%t/bar.pcm %S/Inputs/codegen/use.cpp
> | FileCheck --check-prefix=USE-CMN --check-prefix=USE %s
> 
> -RUN: %clang_cc1 -O2 -disable-llvm-passes -emit-llvm %t/foo.pcm -o - |
> FileCheck --check-prefix=FOO %s
> -RUN: %clang_cc1 -O2 -disable-llvm-passes -emit-llvm %t/bar.pcm -o - -
> fmodule-file=%t/foo.pcm | FileCheck --check-prefix=BAR-CMN --check-
> prefix=BAR-OPT %s
> -RUN: %clang_cc1 -O2 -disable-llvm-passes -fmodules -fmodule-
> file=%t/foo.pcm -fmodule-file=%t/bar.pcm %S/Inputs/codegen/use.cpp -emit-
> llvm -o - | FileCheck --check-prefix=USE-CMN --check-prefix=USE-OPT %s
> +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-
> llvm-passes %t/foo.pcm | FileCheck --check-prefix=FOO %s
> +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-
> llvm-passes %t/bar.pcm -fmodule-file=%t/foo.pcm | FileCheck --check-
> prefix=BAR-CMN --check-prefix=BAR-OPT %s
> +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-
> llvm-passes -fmodules -fmodule-file=%t/foo.pcm -fmodule-file=%t/bar.pcm
> %S/Inputs/codegen/use.cpp | FileCheck --check-prefix=USE-CMN --check-
> prefix=USE-OPT %s
> 
>  FOO-NOT: comdat
>  FOO: $_Z3foov = comdat any
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r293457 - Tidy up codegen modules test & make it x86 specific since it relies on Itanium name manglings

2017-01-30 Thread David Blaikie via cfe-commits
On reflection itanium wouldn't be sufficient/my comment wasn't sufficiently
descriptive (I realized after I made this change that it would also fix the
MacOS buildbot failure I was seeing & hadn't understood) - Darwin doesn't
use comdats, for example, but is still an itanium ABI.

I could remove the checks for comdats - but I think they're
beneficial/relevant.

Could refactor them to be optional somehow, but not sure it's worth it?

On Mon, Jan 30, 2017 at 9:28 AM Robinson, Paul 
wrote:

> Use %itanium_abi_triple instead?
>
> > -Original Message-
> > From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf
> Of
> > David Blaikie via cfe-commits
> > Sent: Sunday, January 29, 2017 9:34 PM
> > To: cfe-commits@lists.llvm.org
> > Subject: r293457 - Tidy up codegen modules test & make it x86 specific
> > since it relies on Itanium name manglings
> >
> > Author: dblaikie
> > Date: Sun Jan 29 23:33:51 2017
> > New Revision: 293457
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=293457&view=rev
> > Log:
> > Tidy up codegen modules test & make it x86 specific since it relies on
> > Itanium name manglings
> >
> > Modified:
> > cfe/trunk/test/Modules/codegen.test
> >
> > Modified: cfe/trunk/test/Modules/codegen.test
> > URL: http://llvm.org/viewvc/llvm-
> >
> project/cfe/trunk/test/Modules/codegen.test?rev=293457&r1=293456&r2=293457
> > &view=diff
> >
> ==
> > 
> > --- cfe/trunk/test/Modules/codegen.test (original)
> > +++ cfe/trunk/test/Modules/codegen.test Sun Jan 29 23:33:51 2017
> > @@ -1,15 +1,16 @@
> >  RUN: rm -rf %t
> > +REQUIRES: x86-registered-target
> >
> > -RUN: %clang_cc1 -fmodules-codegen -x c++ -fmodules -emit-module
> -fmodule-
> > name=foo %S/Inputs/codegen/foo.modulemap -o %t/foo.pcm
> > -RUN: %clang_cc1 -fmodules-codegen -x c++ -fmodules -emit-module
> -fmodule-
> > name=bar %S/Inputs/codegen/bar.modulemap -o %t/bar.pcm -fmodule-
> > file=%t/foo.pcm
> > +RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-codegen -x c++ -
> > fmodules -emit-module -fmodule-name=foo %S/Inputs/codegen/foo.modulemap
> -o
> > %t/foo.pcm
> > +RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-codegen -x c++ -
> > fmodules -emit-module -fmodule-name=bar %S/Inputs/codegen/bar.modulemap
> -o
> > %t/bar.pcm -fmodule-file=%t/foo.pcm
> >
> > -RUN: %clang_cc1 -emit-llvm %t/foo.pcm -o - | FileCheck
> --check-prefix=FOO
> > %s
> > -RUN: %clang_cc1 -emit-llvm %t/bar.pcm -o - -fmodule-file=%t/foo.pcm |
> > FileCheck --check-prefix=BAR-CMN --check-prefix=BAR %s
> > -RUN: %clang_cc1 -fmodules -fmodule-file=%t/foo.pcm -fmodule-
> > file=%t/bar.pcm %S/Inputs/codegen/use.cpp -emit-llvm -o - | FileCheck --
> > check-prefix=USE-CMN --check-prefix=USE %s
> > +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %t/foo.pcm |
> > FileCheck --check-prefix=FOO %s
> > +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %t/bar.pcm -
> > fmodule-file=%t/foo.pcm | FileCheck --check-prefix=BAR-CMN --check-
> > prefix=BAR %s
> > +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -fmodules -
> > fmodule-file=%t/foo.pcm -fmodule-file=%t/bar.pcm
> %S/Inputs/codegen/use.cpp
> > | FileCheck --check-prefix=USE-CMN --check-prefix=USE %s
> >
> > -RUN: %clang_cc1 -O2 -disable-llvm-passes -emit-llvm %t/foo.pcm -o - |
> > FileCheck --check-prefix=FOO %s
> > -RUN: %clang_cc1 -O2 -disable-llvm-passes -emit-llvm %t/bar.pcm -o - -
> > fmodule-file=%t/foo.pcm | FileCheck --check-prefix=BAR-CMN --check-
> > prefix=BAR-OPT %s
> > -RUN: %clang_cc1 -O2 -disable-llvm-passes -fmodules -fmodule-
> > file=%t/foo.pcm -fmodule-file=%t/bar.pcm %S/Inputs/codegen/use.cpp -emit-
> > llvm -o - | FileCheck --check-prefix=USE-CMN --check-prefix=USE-OPT %s
> > +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-
> > llvm-passes %t/foo.pcm | FileCheck --check-prefix=FOO %s
> > +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-
> > llvm-passes %t/bar.pcm -fmodule-file=%t/foo.pcm | FileCheck --check-
> > prefix=BAR-CMN --check-prefix=BAR-OPT %s
> > +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-
> > llvm-passes -fmodules -fmodule-file=%t/foo.pcm -fmodule-file=%t/bar.pcm
> > %S/Inputs/codegen/use.cpp | FileCheck --check-prefix=USE-CMN --check-
> > prefix=USE-OPT %s
> >
> >  FOO-NOT: comdat
> >  FOO: $_Z3foov = comdat any
> >
> >
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


RE: r293457 - Tidy up codegen modules test & make it x86 specific since it relies on Itanium name manglings

2017-01-30 Thread Robinson, Paul via cfe-commits
Okay as is, then.  Thanks for the explanation.
--paulr

From: David Blaikie [mailto:dblai...@gmail.com]
Sent: Monday, January 30, 2017 9:32 AM
To: Robinson, Paul
Cc: cfe-commits (cfe-commits@lists.llvm.org)
Subject: Re: r293457 - Tidy up codegen modules test & make it x86 specific 
since it relies on Itanium name manglings

On reflection itanium wouldn't be sufficient/my comment wasn't sufficiently 
descriptive (I realized after I made this change that it would also fix the 
MacOS buildbot failure I was seeing & hadn't understood) - Darwin doesn't use 
comdats, for example, but is still an itanium ABI.

I could remove the checks for comdats - but I think they're beneficial/relevant.

Could refactor them to be optional somehow, but not sure it's worth it?

On Mon, Jan 30, 2017 at 9:28 AM Robinson, Paul 
mailto:paul.robin...@sony.com>> wrote:
Use %itanium_abi_triple instead?

> -Original Message-
> From: cfe-commits 
> [mailto:cfe-commits-boun...@lists.llvm.org]
>  On Behalf Of
> David Blaikie via cfe-commits
> Sent: Sunday, January 29, 2017 9:34 PM
> To: cfe-commits@lists.llvm.org
> Subject: r293457 - Tidy up codegen modules test & make it x86 specific
> since it relies on Itanium name manglings
>
> Author: dblaikie
> Date: Sun Jan 29 23:33:51 2017
> New Revision: 293457
>
> URL: http://llvm.org/viewvc/llvm-project?rev=293457&view=rev
> Log:
> Tidy up codegen modules test & make it x86 specific since it relies on
> Itanium name manglings
>
> Modified:
> cfe/trunk/test/Modules/codegen.test
>
> Modified: cfe/trunk/test/Modules/codegen.test
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/test/Modules/codegen.test?rev=293457&r1=293456&r2=293457
> &view=diff
> ==
> 
> --- cfe/trunk/test/Modules/codegen.test (original)
> +++ cfe/trunk/test/Modules/codegen.test Sun Jan 29 23:33:51 2017
> @@ -1,15 +1,16 @@
>  RUN: rm -rf %t
> +REQUIRES: x86-registered-target
>
> -RUN: %clang_cc1 -fmodules-codegen -x c++ -fmodules -emit-module -fmodule-
> name=foo %S/Inputs/codegen/foo.modulemap -o %t/foo.pcm
> -RUN: %clang_cc1 -fmodules-codegen -x c++ -fmodules -emit-module -fmodule-
> name=bar %S/Inputs/codegen/bar.modulemap -o %t/bar.pcm -fmodule-
> file=%t/foo.pcm
> +RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-codegen -x c++ -
> fmodules -emit-module -fmodule-name=foo %S/Inputs/codegen/foo.modulemap -o
> %t/foo.pcm
> +RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-codegen -x c++ -
> fmodules -emit-module -fmodule-name=bar %S/Inputs/codegen/bar.modulemap -o
> %t/bar.pcm -fmodule-file=%t/foo.pcm
>
> -RUN: %clang_cc1 -emit-llvm %t/foo.pcm -o - | FileCheck --check-prefix=FOO
> %s
> -RUN: %clang_cc1 -emit-llvm %t/bar.pcm -o - -fmodule-file=%t/foo.pcm |
> FileCheck --check-prefix=BAR-CMN --check-prefix=BAR %s
> -RUN: %clang_cc1 -fmodules -fmodule-file=%t/foo.pcm -fmodule-
> file=%t/bar.pcm %S/Inputs/codegen/use.cpp -emit-llvm -o - | FileCheck --
> check-prefix=USE-CMN --check-prefix=USE %s
> +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %t/foo.pcm |
> FileCheck --check-prefix=FOO %s
> +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %t/bar.pcm -
> fmodule-file=%t/foo.pcm | FileCheck --check-prefix=BAR-CMN --check-
> prefix=BAR %s
> +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -fmodules -
> fmodule-file=%t/foo.pcm -fmodule-file=%t/bar.pcm %S/Inputs/codegen/use.cpp
> | FileCheck --check-prefix=USE-CMN --check-prefix=USE %s
>
> -RUN: %clang_cc1 -O2 -disable-llvm-passes -emit-llvm %t/foo.pcm -o - |
> FileCheck --check-prefix=FOO %s
> -RUN: %clang_cc1 -O2 -disable-llvm-passes -emit-llvm %t/bar.pcm -o - -
> fmodule-file=%t/foo.pcm | FileCheck --check-prefix=BAR-CMN --check-
> prefix=BAR-OPT %s
> -RUN: %clang_cc1 -O2 -disable-llvm-passes -fmodules -fmodule-
> file=%t/foo.pcm -fmodule-file=%t/bar.pcm %S/Inputs/codegen/use.cpp -emit-
> llvm -o - | FileCheck --check-prefix=USE-CMN --check-prefix=USE-OPT %s
> +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-
> llvm-passes %t/foo.pcm | FileCheck --check-prefix=FOO %s
> +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-
> llvm-passes %t/bar.pcm -fmodule-file=%t/foo.pcm | FileCheck --check-
> prefix=BAR-CMN --check-prefix=BAR-OPT %s
> +RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - -O2 -disable-
> llvm-passes -fmodules -fmodule-file=%t/foo.pcm -fmodule-file=%t/bar.pcm
> %S/Inputs/codegen/use.cpp | FileCheck --check-prefix=USE-CMN --check-
> prefix=USE-OPT %s
>
>  FOO-NOT: comdat
>  FOO: $_Z3foov = comdat any
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/c

[PATCH] D28835: [coroutines] NFC: Refactor Sema::CoroutineBodyStmt construction.

2017-01-30 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov added a comment.

LGTM? Pretty please :)


https://reviews.llvm.org/D28835



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


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

2017-01-30 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Mon Jan 30 12:20:00 2017
New Revision: 293518

URL: http://llvm.org/viewvc/llvm-project?rev=293518&view=rev
Log:
[ASTMatchers] Sprinkle some constexpr on the global matcher constructors.

This dramatically reduces the size of the global constructors we emit
for those variables in debug mode.

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

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


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


r293523 - [AST] Give TemplateArgumentLoc a constexpr ctor.

2017-01-30 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Mon Jan 30 12:32:46 2017
New Revision: 293523

URL: http://llvm.org/viewvc/llvm-project?rev=293523&view=rev
Log:
[AST] Give TemplateArgumentLoc a constexpr ctor.

This removes the thread-safe static from
clang::TemplateTemplateParmDecl::getDefaultArgument() const::None

Modified:
cfe/trunk/include/clang/AST/TemplateBase.h
cfe/trunk/lib/AST/TemplateBase.cpp

Modified: cfe/trunk/include/clang/AST/TemplateBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TemplateBase.h?rev=293523&r1=293522&r2=293523&view=diff
==
--- cfe/trunk/include/clang/AST/TemplateBase.h (original)
+++ cfe/trunk/include/clang/AST/TemplateBase.h Mon Jan 30 12:32:46 2017
@@ -119,10 +119,7 @@ private:
   
 public:
   /// \brief Construct an empty, invalid template argument.
-  TemplateArgument() {
-TypeOrValue.Kind = Null;
-TypeOrValue.V = 0;
-  }
+  constexpr TemplateArgument() : TypeOrValue({Null, 0}) {}
 
   /// \brief Construct a template type argument.
   TemplateArgument(QualType T, bool isNullPtr = false) {
@@ -388,8 +385,8 @@ private:
   };
 
 public:
-  TemplateArgumentLocInfo();
-  
+  constexpr TemplateArgumentLocInfo() : Template({nullptr, nullptr, 0, 0}) {}
+
   TemplateArgumentLocInfo(TypeSourceInfo *TInfo) : Declarator(TInfo) {}
   
   TemplateArgumentLocInfo(Expr *E) : Expression(E) {}
@@ -433,7 +430,7 @@ class TemplateArgumentLoc {
   TemplateArgumentLocInfo LocInfo;
 
 public:
-  TemplateArgumentLoc() {}
+  constexpr TemplateArgumentLoc() {}
 
   TemplateArgumentLoc(const TemplateArgument &Argument,
   TemplateArgumentLocInfo Opaque)

Modified: cfe/trunk/lib/AST/TemplateBase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TemplateBase.cpp?rev=293523&r1=293522&r2=293523&view=diff
==
--- cfe/trunk/lib/AST/TemplateBase.cpp (original)
+++ cfe/trunk/lib/AST/TemplateBase.cpp Mon Jan 30 12:32:46 2017
@@ -453,10 +453,6 @@ LLVM_DUMP_METHOD void TemplateArgument::
 // TemplateArgumentLoc Implementation
 
//===--===//
 
-TemplateArgumentLocInfo::TemplateArgumentLocInfo() {
-  memset((void*)this, 0, sizeof(TemplateArgumentLocInfo));
-}
-
 SourceRange TemplateArgumentLoc::getSourceRange() const {
   switch (Argument.getKind()) {
   case TemplateArgument::Expression:


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


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

2017-01-30 Thread Alexey Bataev via Phabricator via cfe-commits
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


[libcxx] r293530 - experimental: add missing file header

2017-01-30 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Mon Jan 30 12:50:32 2017
New Revision: 293530

URL: http://llvm.org/viewvc/llvm-project?rev=293530&view=rev
Log:
experimental: add missing file header

The directory_iterator implementation file was missing the file header.
Add one.  NFC.

Modified:
libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp

Modified: libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp?rev=293530&r1=293529&r2=293530&view=diff
==
--- libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp (original)
+++ libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp Mon Jan 30 
12:50:32 2017
@@ -1,3 +1,12 @@
+//===-- directory_iterator.cpp 
===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
 #include "experimental/filesystem"
 #include 
 #include 


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


[PATCH] D28050: [Clang][Driver] Clean up Clang::ConstructJob a little bit, NFC

2017-01-30 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

I think this patch is an improvement, but Clang::ConstructJob is still one 
giant function.

Do you have ideas to improve readability of this function or plans to further 
reduce its size?


Repository:
  rL LLVM

https://reviews.llvm.org/D28050



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


[libcxx] r293531 - experimental: port directory_iterator to Windows

2017-01-30 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Mon Jan 30 12:50:34 2017
New Revision: 293531

URL: http://llvm.org/viewvc/llvm-project?rev=293531&view=rev
Log:
experimental: port directory_iterator to Windows

This adds a basic first cut implementation for directory_iterator on
Windows.  It uses the FindFirstFile/FindNextFile which has the same
restrictions as opendir/readdir where there exists a TOCTOU race
condition.

Modified:
libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp

Modified: libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp?rev=293531&r1=293530&r2=293531&view=diff
==
--- libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp (original)
+++ libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp Mon Jan 30 
12:50:34 2017
@@ -8,17 +8,24 @@
 
//===--===//
 
 #include "experimental/filesystem"
+#if defined(_WIN32)
+#define WIN32_LEAN_AND_MEAN
+#include 
+#else
 #include 
+#endif
 #include 
 
 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM
 
 namespace { namespace detail {
 
+#if !defined(_WIN32)
 inline error_code capture_errno() {
 _LIBCPP_ASSERT(errno, "Expected errno to be non-zero");
 return error_code{errno, std::generic_category()};
 }
+#endif
 
 template 
 inline bool set_or_throw(std::error_code& my_ec,
@@ -33,6 +40,7 @@ inline bool set_or_throw(std::error_code
 return false;
 }
 
+#if !defined(_WIN32)
 inline path::string_type posix_readdir(DIR *dir_stream, error_code& ec) {
 struct dirent* dir_entry_ptr = nullptr;
 errno = 0; // zero errno in order to detect errors
@@ -44,11 +52,74 @@ inline path::string_type posix_readdir(D
 return dir_entry_ptr->d_name;
 }
 }
+#endif
 
 }}   // namespace detail
 
 using detail::set_or_throw;
 
+#if defined(_WIN32)
+class __dir_stream {
+public:
+  __dir_stream() = delete;
+  __dir_stream& operator=(const __dir_stream&) = delete;
+
+  __dir_stream(__dir_stream&& __ds) noexcept
+  : __stream_(__ds.__stream_), __root_(std::move(__ds.__root_)),
+__entry_(std::move(__ds.__entry_)) {
+ds.__stream_ = INVALID_HANDLE_VALUE;
+  }
+
+  __dir_stream(const path& root, directory_options opts, error_code& ec)
+  : __stream_(INVALID_HANDLE_VALUE), __root_(root) {
+__stream_ = ::FindFirstFile(root.c_str(), &__data_);
+if (__stream_ == INVALID_HANDLE_VALUE) {
+  ec = error_code(::GetLastError(), std::generic_category());
+  const bool ignore_permission_denied =
+  bool(opts & directory_options::skip_permission_denied);
+  if (ignore_permission_denied && ec.value() == ERROR_ACCESS_DENIED)
+ec.clear();
+  return;
+}
+  }
+
+  ~__dir_stream() noexcept {
+if (__stream_ == INVALID_HANDLE_VALUE)
+  return;
+close();
+  }
+
+  bool good() const noexcept { return __stream_ != INVALID_HANDLE_VALUE; }
+
+  bool advance(error_code& ec) {
+while (::FindNextFile(__stream_, &__data_)) {
+  if (!strcmp(__data_.cFileName, ".") || strcmp(__data_.cFileName, ".."))
+continue;
+  __entry_.assign(__root_ / __data_.cFileName);
+  return true;
+}
+ec = error_code(::GetLastError(), std::generic_category());
+close();
+return false;
+  }
+
+private:
+  std::error_code close() noexcept {
+std::error_code ec;
+if (!::FindClose(__stream_))
+  ec = error_code(::GetLastError(), std::generic_category());
+__stream_ = INVALID_HANDLE_VALUE;
+return ec;
+  }
+
+  HANDLE __stream_{INVALID_HANDLE_VALUE};
+  WIN32_FIND_DATA __data_;
+
+public:
+  path __root_;
+  directory_entry __entry_;
+};
+#else
 class __dir_stream {
 public:
 __dir_stream() = delete;
@@ -110,6 +181,7 @@ public:
 path __root_;
 directory_entry __entry_;
 };
+#endif
 
 // directory_iterator
 


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


[PATCH] D29291: [clang-format] Separate line comment sections after a right brace from comment sections in the scope.

2017-01-30 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Format/UnwrappedLineParser.cpp:2095
+  const FormatToken *MinColumnToken = Line.Tokens.front().Tok;
+  {
+// Scan for '{//'. If found, use the column of '{' as a min column for line

Just remove this. It leaks PreviousToken, but that's ok.


https://reviews.llvm.org/D29291



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


[PATCH] D29291: [clang-format] Separate line comment sections after a right brace from comment sections in the scope.

2017-01-30 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 86316.
krasimir added a comment.

- Remove scope


https://reviews.llvm.org/D29291

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

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1783,6 +1783,64 @@
"0x00, 0x00, 0x00, 0x00};// comment\n");
 }
 
+TEST_F(FormatTest, LineCommentsAfterRightBrace) {
+  EXPECT_EQ("if (true) { // comment about branch\n"
+"  // comment about f\n"
+"  f();\n"
+"}",
+format("if (true) { // comment about branch\n"
+   "  // comment about f\n"
+   "  f();\n"
+   "}",
+   getLLVMStyleWithColumns(80)));
+  EXPECT_EQ("if (1) { // if line 1\n"
+" // if line 2\n"
+" // if line 3\n"
+"  // f line 1\n"
+"  // f line 2\n"
+"  f();\n"
+"} else { // else line 1\n"
+" // else line 2\n"
+" // else line 3\n"
+"  // g line 1\n"
+"  g();\n"
+"}",
+format("if (1) { // if line 1\n"
+   "  // if line 2\n"
+   "// if line 3\n"
+   "  // f line 1\n"
+   "// f line 2\n"
+   "  f();\n"
+   "} else { // else line 1\n"
+   "// else line 2\n"
+   " // else line 3\n"
+   "  // g line 1\n"
+   "  g();\n"
+   "}"));
+  EXPECT_EQ("do { // line 1\n"
+" // line 2\n"
+" // line 3\n"
+"  f();\n"
+"} while (true);",
+format("do { // line 1\n"
+   " // line 2\n"
+   "   // line 3\n"
+   "  f();\n"
+   "} while (true);",
+   getLLVMStyleWithColumns(80)));
+  EXPECT_EQ("while (a < b) { // line 1\n"
+"  // line 2\n"
+"  // line 3\n"
+"  f();\n"
+"}",
+format("while (a < b) {// line 1\n"
+   "  // line 2\n"
+   "  // line 3\n"
+   "  f();\n"
+   "}",
+   getLLVMStyleWithColumns(80)));
+}
+
 TEST_F(FormatTest, ReflowsComments) {
   // Break a long line and reflow with the full next line.
   EXPECT_EQ("// long long long\n"
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -2051,14 +2051,19 @@
  const UnwrappedLine &Line) {
   if (Line.Tokens.empty())
 return false;
-  const FormatToken &FirstLineTok = *Line.Tokens.front().Tok;
+
   // If Line starts with a line comment, then FormatTok continues the comment
-  // section if its original column is greater or equal to the  original start
+  // section if its original column is greater or equal to the original start
   // column of the line.
   //
-  // If Line starts with a a different token, then FormatTok continues the
-  // comment section if its original column greater than the original start
-  // column of the line.
+  // Define the min column token of a line as follows: if a line ends in '{' or
+  // contains a '{' followed by a line comment, then the min column token is
+  // that '{'. Otherwise, the min column token of the line is the first token of
+  // the line.
+  //
+  // If Line starts with a token other than a line comment, then FormatTok
+  // continues the comment section if its original column is greater than the
+  // original start column of the min column token of the line.
   //
   // For example, the second line comment continues the first in these cases:
   // // first line
@@ -2069,16 +2074,43 @@
   // and:
   // int i; // first line
   //  // second line
+  // and:
+  // do { // first line
+  //  // second line
+  //   int i;
+  // } while (true);
   //
   // The second line comment doesn't continue the first in these cases:
   //   // first line
   //  // second line
   // and:
   // int i; // first line
   // // second line
+  // and:
+  // do { // first line
+  //   // second line
+  //   int i;
+  // } while (true);
+  const FormatToken *MinColumnToken = Line.Tokens.front().Tok;
+
+  // Scan for '{//'. If found, use the column of '{' as a min column for line
+  // comment section continuation.
+  const FormatToken *PreviousToken = nullptr;
+  for (const UnwrappedLineNode Node : Line.Tokens) {
+if (PreviousToken && PreviousToken->is(tok::l_brace) &&
+isLineComment(*Node.Tok)) {
+  MinColumnToken = PreviousToken;
+  break;
+}
+Previous

r293539 - [clang-format] Separate line comment sections after a right brace from comment sections in the scope.

2017-01-30 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Mon Jan 30 13:18:55 2017
New Revision: 293539

URL: http://llvm.org/viewvc/llvm-project?rev=293539&view=rev
Log:
[clang-format] Separate line comment sections after a right brace from comment 
sections in the scope.

Summary:
The following two comment lines form a single comment section:
```
if (1) { // line 1
   // line 2
}
```
This is because the break of a comment section was based on the original column
of the first token of the previous line (in this case, the 'if').
This patch splits these two comment lines into different sections by taking into
account the original column of the right brace preceding the first line comment
where applicable.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

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

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=293539&r1=293538&r2=293539&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Jan 30 13:18:55 2017
@@ -2051,14 +2051,19 @@ static bool continuesLineComment(const F
  const UnwrappedLine &Line) {
   if (Line.Tokens.empty())
 return false;
-  const FormatToken &FirstLineTok = *Line.Tokens.front().Tok;
+
   // If Line starts with a line comment, then FormatTok continues the comment
-  // section if its original column is greater or equal to the  original start
+  // section if its original column is greater or equal to the original start
   // column of the line.
   //
-  // If Line starts with a a different token, then FormatTok continues the
-  // comment section if its original column greater than the original start
-  // column of the line.
+  // Define the min column token of a line as follows: if a line ends in '{' or
+  // contains a '{' followed by a line comment, then the min column token is
+  // that '{'. Otherwise, the min column token of the line is the first token 
of
+  // the line.
+  //
+  // If Line starts with a token other than a line comment, then FormatTok
+  // continues the comment section if its original column is greater than the
+  // original start column of the min column token of the line.
   //
   // For example, the second line comment continues the first in these cases:
   // // first line
@@ -2069,6 +2074,11 @@ static bool continuesLineComment(const F
   // and:
   // int i; // first line
   //  // second line
+  // and:
+  // do { // first line
+  //  // second line
+  //   int i;
+  // } while (true);
   //
   // The second line comment doesn't continue the first in these cases:
   //   // first line
@@ -2076,9 +2086,31 @@ static bool continuesLineComment(const F
   // and:
   // int i; // first line
   // // second line
+  // and:
+  // do { // first line
+  //   // second line
+  //   int i;
+  // } while (true);
+  const FormatToken *MinColumnToken = Line.Tokens.front().Tok;
+
+  // Scan for '{//'. If found, use the column of '{' as a min column for line
+  // comment section continuation.
+  const FormatToken *PreviousToken = nullptr;
+  for (const UnwrappedLineNode Node : Line.Tokens) {
+if (PreviousToken && PreviousToken->is(tok::l_brace) &&
+isLineComment(*Node.Tok)) {
+  MinColumnToken = PreviousToken;
+  break;
+}
+PreviousToken = Node.Tok;
+  }
+  if (PreviousToken && PreviousToken->is(tok::l_brace)) {
+MinColumnToken = PreviousToken;
+  }
+
   unsigned MinContinueColumn =
-  FirstLineTok.OriginalColumn +
-  ((isLineComment(FirstLineTok) && !FirstLineTok.Next) ? 0 : 1);
+  MinColumnToken->OriginalColumn +
+  (isLineComment(*MinColumnToken) ? 0 : 1);
   return isLineComment(FormatTok) && FormatTok.NewlinesBefore == 1 &&
  isLineComment(*(Line.Tokens.back().Tok)) &&
  FormatTok.OriginalColumn >= MinContinueColumn;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=293539&r1=293538&r2=293539&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 30 13:18:55 2017
@@ -1783,6 +1783,64 @@ TEST_F(FormatTest, CommentsInStaticIniti
"0x00, 0x00, 0x00, 0x00};// comment\n");
 }
 
+TEST_F(FormatTest, LineCommentsAfterRightBrace) {
+  EXPECT_EQ("if (true) { // comment about branch\n"
+"  // comment about f\n"
+"  f();\n"
+"}",
+format("if (true) { // comment about branch\n"
+   "  // comment about f\n"
+   "  f();\n"
+   "}",
+  

[PATCH] D29291: [clang-format] Separate line comment sections after a right brace from comment sections in the scope.

2017-01-30 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293539: [clang-format] Separate line comment sections after 
a right brace from comment… (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D29291?vs=86316&id=86317#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29291

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

Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -2051,14 +2051,19 @@
  const UnwrappedLine &Line) {
   if (Line.Tokens.empty())
 return false;
-  const FormatToken &FirstLineTok = *Line.Tokens.front().Tok;
+
   // If Line starts with a line comment, then FormatTok continues the comment
-  // section if its original column is greater or equal to the  original start
+  // section if its original column is greater or equal to the original start
   // column of the line.
   //
-  // If Line starts with a a different token, then FormatTok continues the
-  // comment section if its original column greater than the original start
-  // column of the line.
+  // Define the min column token of a line as follows: if a line ends in '{' or
+  // contains a '{' followed by a line comment, then the min column token is
+  // that '{'. Otherwise, the min column token of the line is the first token of
+  // the line.
+  //
+  // If Line starts with a token other than a line comment, then FormatTok
+  // continues the comment section if its original column is greater than the
+  // original start column of the min column token of the line.
   //
   // For example, the second line comment continues the first in these cases:
   // // first line
@@ -2069,16 +2074,43 @@
   // and:
   // int i; // first line
   //  // second line
+  // and:
+  // do { // first line
+  //  // second line
+  //   int i;
+  // } while (true);
   //
   // The second line comment doesn't continue the first in these cases:
   //   // first line
   //  // second line
   // and:
   // int i; // first line
   // // second line
+  // and:
+  // do { // first line
+  //   // second line
+  //   int i;
+  // } while (true);
+  const FormatToken *MinColumnToken = Line.Tokens.front().Tok;
+
+  // Scan for '{//'. If found, use the column of '{' as a min column for line
+  // comment section continuation.
+  const FormatToken *PreviousToken = nullptr;
+  for (const UnwrappedLineNode Node : Line.Tokens) {
+if (PreviousToken && PreviousToken->is(tok::l_brace) &&
+isLineComment(*Node.Tok)) {
+  MinColumnToken = PreviousToken;
+  break;
+}
+PreviousToken = Node.Tok;
+  }
+  if (PreviousToken && PreviousToken->is(tok::l_brace)) {
+MinColumnToken = PreviousToken;
+  }
+
   unsigned MinContinueColumn =
-  FirstLineTok.OriginalColumn +
-  ((isLineComment(FirstLineTok) && !FirstLineTok.Next) ? 0 : 1);
+  MinColumnToken->OriginalColumn +
+  (isLineComment(*MinColumnToken) ? 0 : 1);
   return isLineComment(FormatTok) && FormatTok.NewlinesBefore == 1 &&
  isLineComment(*(Line.Tokens.back().Tok)) &&
  FormatTok.OriginalColumn >= MinContinueColumn;
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -1783,6 +1783,64 @@
"0x00, 0x00, 0x00, 0x00};// comment\n");
 }
 
+TEST_F(FormatTest, LineCommentsAfterRightBrace) {
+  EXPECT_EQ("if (true) { // comment about branch\n"
+"  // comment about f\n"
+"  f();\n"
+"}",
+format("if (true) { // comment about branch\n"
+   "  // comment about f\n"
+   "  f();\n"
+   "}",
+   getLLVMStyleWithColumns(80)));
+  EXPECT_EQ("if (1) { // if line 1\n"
+" // if line 2\n"
+" // if line 3\n"
+"  // f line 1\n"
+"  // f line 2\n"
+"  f();\n"
+"} else { // else line 1\n"
+" // else line 2\n"
+" // else line 3\n"
+"  // g line 1\n"
+"  g();\n"
+"}",
+format("if (1) { // if line 1\n"
+   "  // if line 2\n"
+   "// if line 3\n"
+   "  // f line 1\n"
+   "// f line 2\n"
+   "  f();\n"
+   "} else { // else line 1\n"
+   "// else line 2\n"
+   " // else line 3\n"
+   "  // g line 1\n"
+   "  g();\n"
+   "}"));
+  EXPECT_EQ("do { // line 1\n"
+" // line 2

[PATCH] D28050: [Clang][Driver] Clean up Clang::ConstructJob a little bit, NFC

2017-01-30 Thread Hongbin Zheng via Phabricator via cfe-commits
etherzhhb added a comment.

In https://reviews.llvm.org/D28050#660715, @ahatanak wrote:

> I think this patch is an improvement, but Clang::ConstructJob is still one 
> giant function.
>
> Do you have ideas to improve readability of this function or plans to further 
> reduce its size?


I am trying to identify the self-contained chunks and extra them


Repository:
  rL LLVM

https://reviews.llvm.org/D28050



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


[libcxx] r293543 - experimental: avoid using raw _WIN32 in filesystem

2017-01-30 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Mon Jan 30 13:57:27 2017
New Revision: 293543

URL: http://llvm.org/viewvc/llvm-project?rev=293543&view=rev
Log:
experimental: avoid using raw _WIN32 in filesystem

Use the _LIBCPP_WIN32API macro instead of _WIN32 checks.  Fix a missed
renaming for style conformance.

Modified:
libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp

Modified: libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp?rev=293543&r1=293542&r2=293543&view=diff
==
--- libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp (original)
+++ libcxx/trunk/src/experimental/filesystem/directory_iterator.cpp Mon Jan 30 
13:57:27 2017
@@ -8,7 +8,8 @@
 
//===--===//
 
 #include "experimental/filesystem"
-#if defined(_WIN32)
+#include "__config"
+#if defined(_LIBCPP_WIN32API)
 #define WIN32_LEAN_AND_MEAN
 #include 
 #else
@@ -20,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FIL
 
 namespace { namespace detail {
 
-#if !defined(_WIN32)
+#if !defined(_LIBCPP_WIN32API)
 inline error_code capture_errno() {
 _LIBCPP_ASSERT(errno, "Expected errno to be non-zero");
 return error_code{errno, std::generic_category()};
@@ -40,7 +41,7 @@ inline bool set_or_throw(std::error_code
 return false;
 }
 
-#if !defined(_WIN32)
+#if !defined(_LIBCPP_WIN32API)
 inline path::string_type posix_readdir(DIR *dir_stream, error_code& ec) {
 struct dirent* dir_entry_ptr = nullptr;
 errno = 0; // zero errno in order to detect errors
@@ -58,7 +59,7 @@ inline path::string_type posix_readdir(D
 
 using detail::set_or_throw;
 
-#if defined(_WIN32)
+#if defined(_LIBCPP_WIN32API)
 class __dir_stream {
 public:
   __dir_stream() = delete;
@@ -67,7 +68,7 @@ public:
   __dir_stream(__dir_stream&& __ds) noexcept
   : __stream_(__ds.__stream_), __root_(std::move(__ds.__root_)),
 __entry_(std::move(__ds.__entry_)) {
-ds.__stream_ = INVALID_HANDLE_VALUE;
+__ds.__stream_ = INVALID_HANDLE_VALUE;
   }
 
   __dir_stream(const path& root, directory_options opts, error_code& ec)


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


r293544 - Towards P0091R3: parsing support for class template argument deduction in typename-specifiers.

2017-01-30 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Jan 30 14:39:26 2017
New Revision: 293544

URL: http://llvm.org/viewvc/llvm-project?rev=293544&view=rev
Log:
Towards P0091R3: parsing support for class template argument deduction in 
typename-specifiers.

This reinstates r293455, reverted in r293455, with a fix for cv-qualifier
handling on dependent typename-specifiers.

Modified:
cfe/trunk/include/clang/AST/DeclTemplate.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=293544&r1=293543&r2=293544&view=diff
==
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Mon Jan 30 14:39:26 2017
@@ -2946,6 +2946,16 @@ inline NamedDecl *getAsNamedDecl(Templat
   return P.get();
 }
 
+inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) {
+  auto *TD = dyn_cast(D);
+  return TD && (isa(TD) ||
+isa(TD) ||
+isa(TD) ||
+isa(TD))
+ ? TD
+ : nullptr;
+}
+
 } /* end of namespace clang */
 
 #endif

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=293544&r1=293543&r2=293544&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jan 30 14:39:26 
2017
@@ -1884,6 +1884,11 @@ def err_auto_not_allowed : Error<
   "|in conversion function type|here|in lambda parameter"
   "|in type allocated by 'new'|in K&R-style function parameter"
   "|in template parameter|in friend declaration}1">;
+def err_dependent_deduced_tst : Error<
+  "typename specifier refers to "
+  "%select{class template|function template|variable template|alias template|"
+  "template template parameter|template}0 member in %1; "
+  "argument deduction not allowed here">;
 def err_auto_not_allowed_var_inst : Error<
   "'auto' variable template instantiation is not allowed">;
 def err_auto_var_requires_init : Error<

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=293544&r1=293543&r2=293544&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Jan 30 14:39:26 2017
@@ -7359,7 +7359,8 @@ public:
 
   TypeSourceInfo *SubstType(TypeSourceInfo *T,
 const MultiLevelTemplateArgumentList &TemplateArgs,
-SourceLocation Loc, DeclarationName Entity);
+SourceLocation Loc, DeclarationName Entity,
+bool AllowDeducedTST = false);
 
   QualType SubstType(QualType T,
  const MultiLevelTemplateArgumentList &TemplateArgs,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=293544&r1=293543&r2=293544&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan 30 14:39:26 2017
@@ -60,11 +60,6 @@ Sema::DeclGroupPtrTy Sema::ConvertDeclTo
   return DeclGroupPtrTy::make(DeclGroupRef(Ptr));
 }
 
-static bool isTypeTemplate(NamedDecl *ND) {
-  return isa(ND) || isa(ND) ||
- isa(ND);
-}
-
 namespace {
 
 class TypeNameValidatorCCC : public CorrectionCandidateCallback {
@@ -81,7 +76,7 @@ class TypeNameValidatorCCC : public Corr
   bool ValidateCandidate(const TypoCorrection &candidate) override {
 if (NamedDecl *ND = candidate.getCorrectionDecl()) {
   bool IsType = isa(ND) || isa(ND);
-  bool AllowedTemplate = AllowTemplates && isTypeTemplate(ND);
+  bool AllowedTemplate = AllowTemplates && getAsTypeTemplateDecl(ND);
   return (IsType || AllowedTemplate) &&
  (AllowInvalidDecl || !ND->isInvalidDecl());
 }
@@ -405,7 +400,7 @@ ParsedType Sema::getTypeName(const Ident
 for (LookupResult::iterator Res = Result.begin(), ResEnd = Result.end();
  Res != ResEnd; ++Res) {
   if (isa(*Res) || isa(*Res) ||
-  (AllowDeducedTemplate && isTypeTemplate(*Res))) {
+  (AllowDeducedTemplate && getAsTypeTemplateDecl(*Res))) {
 if (!IIDecl ||
 (*Res)->getLocation().getRawEncoding(

Re: r293473 - Revert r293455, which breaks v8 with a spurious error. Testcase added.

2017-01-30 Thread Richard Smith via cfe-commits
Thanks for the revert; fixed and re-committed as r293544.

On 30 January 2017 at 02:44, Sam McCall via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: sammccall
> Date: Mon Jan 30 04:44:11 2017
> New Revision: 293473
>
> URL: http://llvm.org/viewvc/llvm-project?rev=293473&view=rev
> Log:
> Revert r293455, which breaks v8 with a spurious error. Testcase added.
>
> Summary: Revert r293455, which breaks v8 with a spurious error. Testcase
> added.
>
> Reviewers: klimek
>
> Subscribers: cfe-commits, rsmith
>
> Differential Revision: https://reviews.llvm.org/D29271
>
> Modified:
> cfe/trunk/include/clang/AST/DeclTemplate.h
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/lib/Sema/SemaTemplate.cpp
> cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
> cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
> cfe/trunk/lib/Sema/TreeTransform.h
> cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp
> cfe/trunk/test/SemaCXX/cxx0x-class.cpp
>
> Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/AST/DeclTemplate.h?rev=293473&r1=293472&r2=293473&view=diff
> 
> ==
> --- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
> +++ cfe/trunk/include/clang/AST/DeclTemplate.h Mon Jan 30 04:44:11 2017
> @@ -2946,16 +2946,6 @@ inline NamedDecl *getAsNamedDecl(Templat
>return P.get();
>  }
>
> -inline TemplateDecl *getAsTypeTemplateDecl(Decl *D) {
> -  auto *TD = dyn_cast(D);
> -  return TD && (isa(TD) ||
> -isa(TD) ||
> -isa(TD) ||
> -isa(TD))
> - ? TD
> - : nullptr;
> -}
> -
>  } /* end of namespace clang */
>
>  #endif
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/
> DiagnosticSemaKinds.td?rev=293473&r1=293472&r2=293473&view=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jan 30
> 04:44:11 2017
> @@ -1884,11 +1884,6 @@ def err_auto_not_allowed : Error<
>"|in conversion function type|here|in lambda parameter"
>"|in type allocated by 'new'|in K&R-style function parameter"
>"|in template parameter|in friend declaration}1">;
> -def err_dependent_deduced_tst : Error<
> -  "typename specifier refers to "
> -  "%select{class template|function template|variable template|alias
> template|"
> -  "template template parameter|template}0 member in %1; "
> -  "argument deduction not allowed here">;
>  def err_auto_not_allowed_var_inst : Error<
>"'auto' variable template instantiation is not allowed">;
>  def err_auto_var_requires_init : Error<
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Sema/Sema.h?rev=293473&r1=293472&r2=293473&view=diff
> 
> ==
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Mon Jan 30 04:44:11 2017
> @@ -7359,8 +7359,7 @@ public:
>
>TypeSourceInfo *SubstType(TypeSourceInfo *T,
>  const MultiLevelTemplateArgumentList
> &TemplateArgs,
> -SourceLocation Loc, DeclarationName Entity,
> -bool AllowDeducedTST = false);
> +SourceLocation Loc, DeclarationName Entity);
>
>QualType SubstType(QualType T,
>   const MultiLevelTemplateArgumentList &TemplateArgs,
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaDecl.cpp?rev=293473&r1=293472&r2=293473&view=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan 30 04:44:11 2017
> @@ -60,6 +60,11 @@ Sema::DeclGroupPtrTy Sema::ConvertDeclTo
>return DeclGroupPtrTy::make(DeclGroupRef(Ptr));
>  }
>
> +static bool isTypeTemplate(NamedDecl *ND) {
> +  return isa(ND) || isa(ND) ||
> + isa(ND);
> +}
> +
>  namespace {
>
>  class TypeNameValidatorCCC : public CorrectionCandidateCallback {
> @@ -76,7 +81,7 @@ class TypeNameValidatorCCC : public Corr
>bool ValidateCandidate(const TypoCorrection &candidate) override {
>  if (NamedDecl *ND = candidate.getCorrectionDecl()) {
>bool IsType = isa(ND) || isa(ND);
> -  bool AllowedTemplate = AllowTemplates && getAsTypeTemplateDecl(ND);
> +  bool AllowedTemplate = AllowTemplates && isTypeTemplate(ND);
>return (IsType || AllowedTemplate) &&
>

[PATCH] D29300: [clang-format] Refactor WhitespaceManager and friends

2017-01-30 Thread Daniel Jasper via Phabricator via cfe-commits
djasper created this revision.

The main motivation behind this is to cleanup the WhitespaceManager and make it 
more extensible for future alignment etc. features. Specifically, 
WhitespaceManager has started to copy more and more code that is already 
present in FormatToken. Instead, I think it makes more sense to actually store 
a reference to each FormatToken for each change.

This has as a consequence led to a change in the calculation of indent levels. 
Now, we actually compute them for each Token ahead of time, which should be 
more efficient as it removes an unsigned value for the ParenState, which is 
used during the combinatorial exploration of the solution space.

No functional changes intended.


https://reviews.llvm.org/D29300

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineFormatter.cpp
  lib/Format/UnwrappedLineFormatter.h
  lib/Format/WhitespaceManager.cpp
  lib/Format/WhitespaceManager.h
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -497,6 +497,11 @@
"[];");
 
   verifyFormat("someFunction([], {a: a});");
+
+  verifyFormat("var string = [\n"
+   "  'aa',\n"
+   "  'bb',\n"
+   "].join('+');");
 }
 
 TEST_F(FormatTestJS, ColumnLayoutForArrayLiterals) {
@@ -587,6 +592,11 @@
"  doSomething();\n"
"}, this));");
 
+  verifyFormat("SomeFunction(function() {\n"
+   "  foo();\n"
+   "  bar();\n"
+   "}.bind(this));");
+
   // FIXME: This is bad, we should be wrapping before "function() {".
   verifyFormat("someFunction(function() {\n"
"  doSomething();  // break\n"
Index: lib/Format/WhitespaceManager.h
===
--- lib/Format/WhitespaceManager.h
+++ lib/Format/WhitespaceManager.h
@@ -43,8 +43,7 @@
 
   /// \brief Replaces the whitespace in front of \p Tok. Only call once for
   /// each \c AnnotatedToken.
-  void replaceWhitespace(FormatToken &Tok, unsigned Newlines,
- unsigned IndentLevel, unsigned Spaces,
+  void replaceWhitespace(FormatToken &Tok, unsigned Newlines, unsigned Spaces,
  unsigned StartOfTokenColumn,
  bool InPPDirective = false);
 
@@ -72,8 +71,7 @@
 unsigned ReplaceChars,
 StringRef PreviousPostfix,
 StringRef CurrentPrefix, bool InPPDirective,
-unsigned Newlines, unsigned IndentLevel,
-int Spaces);
+unsigned Newlines, int Spaces);
 
   /// \brief Returns all the \c Replacements created during formatting.
   const tooling::Replacements &generateReplacements();
@@ -91,8 +89,6 @@
   const SourceManager &SourceMgr;
 };
 
-Change() {}
-
 /// \brief Creates a \c Change.
 ///
 /// The generated \c Change will replace the characters at
@@ -102,12 +98,18 @@
 ///
 /// \p StartOfTokenColumn and \p InPPDirective will be used to lay out
 /// trailing comments and escaped newlines.
-Change(bool CreateReplacement, SourceRange OriginalWhitespaceRange,
-   unsigned IndentLevel, int Spaces, unsigned StartOfTokenColumn,
-   unsigned NewlinesBefore, StringRef PreviousLinePostfix,
-   StringRef CurrentLinePrefix, tok::TokenKind Kind,
-   bool ContinuesPPDirective, bool IsStartOfDeclName,
-   bool IsInsideToken);
+Change(const FormatToken &Tok, bool CreateReplacement,
+   SourceRange OriginalWhitespaceRange, int Spaces,
+   unsigned StartOfTokenColumn, unsigned NewlinesBefore,
+   StringRef PreviousLinePostfix, StringRef CurrentLinePrefix,
+   bool ContinuesPPDirective, bool IsInsideToken);
+
+// The kind of the token whose whitespace this change replaces, or in which
+// this change inserts whitespace.
+// FIXME: Currently this is not set correctly for breaks inside comments, as
+// the \c BreakableToken is still doing its own alignment.
+const FormatToken *Tok;
+bool InToken;
 
 bool CreateReplacement;
 // Changes might be in the middle of a token, so we cannot just keep the
@@ -117,18 +119,7 @@
 unsigned NewlinesBefore;
 std::string PreviousLinePostfix;
 std::string CurrentLinePrefix;
-// The kind of the token whose whitespace this change replaces, or in which
-// this change inserts whitespace.
-// FIXME: Currently this is not set correctly for breaks inside comments, as
-// the \c BreakableToken is still doi

r293548 - [clang-format] Fix regression that breaks comments without a comment prefix

2017-01-30 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Mon Jan 30 15:00:01 2017
New Revision: 293548

URL: http://llvm.org/viewvc/llvm-project?rev=293548&view=rev
Log:
[clang-format] Fix regression that breaks comments without a comment prefix

Summary:
Consider formatting the following code fragment with column limit 20:
```
{
  // line 1
  // line 2\
  // long long long line
}
```
Before this fix the output is:
```
{
  // line 1
  // line 2\
  // long long
  long line
}
```
This patch fixes a regression that breaks the last comment line without
adding the '//' prefix.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

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

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=293548&r1=293547&r2=293548&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Mon Jan 30 15:00:01 2017
@@ -642,7 +642,11 @@ BreakableLineCommentSection::BreakableLi
 Prefix.resize(Lines.size());
 OriginalPrefix.resize(Lines.size());
 for (size_t i = FirstLineIndex, e = Lines.size(); i < e; ++i) {
-  StringRef IndentPrefix = getLineCommentIndentPrefix(Lines[i]);
+  // We need to trim the blanks in case this is not the first line in a
+  // multiline comment. Then the indent is included in Lines[i].
+  StringRef IndentPrefix =
+  getLineCommentIndentPrefix(Lines[i].ltrim(Blanks));
+  assert(IndentPrefix.startswith("//"));
   OriginalPrefix[i] = Prefix[i] = IndentPrefix;
   if (Lines[i].size() > Prefix[i].size() &&
   isAlphanumeric(Lines[i][Prefix[i].size()])) {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=293548&r1=293547&r2=293548&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 30 15:00:01 2017
@@ -1386,6 +1386,18 @@ TEST_F(FormatTest, SplitsLongCxxComments
   "#define XXX // q w e r\n"
   "// t y u i",
   format("#define XXX //q w e r t y u i", getLLVMStyleWithColumns(22)));
+  EXPECT_EQ("{\n"
+"  //\n"
+"  //\\\n"
+"  // long 1 2 3 4\n"
+"  // 5\n"
+"}",
+format("{\n"
+   "  //\n"
+   "  //\\\n"
+   "  // long 1 2 3 4 5\n"
+   "}",
+   getLLVMStyleWithColumns(20)));
 }
 
 TEST_F(FormatTest, PreservesHangingIndentInCxxComments) {


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


[PATCH] D29298: [clang-format] Fix regression that breaks comments without a comment prefix

2017-01-30 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293548: [clang-format] Fix regression that breaks comments 
without a comment prefix (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D29298?vs=86328&id=86331#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29298

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


Index: cfe/trunk/lib/Format/BreakableToken.cpp
===
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -642,7 +642,11 @@
 Prefix.resize(Lines.size());
 OriginalPrefix.resize(Lines.size());
 for (size_t i = FirstLineIndex, e = Lines.size(); i < e; ++i) {
-  StringRef IndentPrefix = getLineCommentIndentPrefix(Lines[i]);
+  // We need to trim the blanks in case this is not the first line in a
+  // multiline comment. Then the indent is included in Lines[i].
+  StringRef IndentPrefix =
+  getLineCommentIndentPrefix(Lines[i].ltrim(Blanks));
+  assert(IndentPrefix.startswith("//"));
   OriginalPrefix[i] = Prefix[i] = IndentPrefix;
   if (Lines[i].size() > Prefix[i].size() &&
   isAlphanumeric(Lines[i][Prefix[i].size()])) {
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -1386,6 +1386,18 @@
   "#define XXX // q w e r\n"
   "// t y u i",
   format("#define XXX //q w e r t y u i", getLLVMStyleWithColumns(22)));
+  EXPECT_EQ("{\n"
+"  //\n"
+"  //\\\n"
+"  // long 1 2 3 4\n"
+"  // 5\n"
+"}",
+format("{\n"
+   "  //\n"
+   "  //\\\n"
+   "  // long 1 2 3 4 5\n"
+   "}",
+   getLLVMStyleWithColumns(20)));
 }
 
 TEST_F(FormatTest, PreservesHangingIndentInCxxComments) {


Index: cfe/trunk/lib/Format/BreakableToken.cpp
===
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -642,7 +642,11 @@
 Prefix.resize(Lines.size());
 OriginalPrefix.resize(Lines.size());
 for (size_t i = FirstLineIndex, e = Lines.size(); i < e; ++i) {
-  StringRef IndentPrefix = getLineCommentIndentPrefix(Lines[i]);
+  // We need to trim the blanks in case this is not the first line in a
+  // multiline comment. Then the indent is included in Lines[i].
+  StringRef IndentPrefix =
+  getLineCommentIndentPrefix(Lines[i].ltrim(Blanks));
+  assert(IndentPrefix.startswith("//"));
   OriginalPrefix[i] = Prefix[i] = IndentPrefix;
   if (Lines[i].size() > Prefix[i].size() &&
   isAlphanumeric(Lines[i][Prefix[i].size()])) {
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -1386,6 +1386,18 @@
   "#define XXX // q w e r\n"
   "// t y u i",
   format("#define XXX //q w e r t y u i", getLLVMStyleWithColumns(22)));
+  EXPECT_EQ("{\n"
+"  //\n"
+"  //\\\n"
+"  // long 1 2 3 4\n"
+"  // 5\n"
+"}",
+format("{\n"
+   "  //\n"
+   "  //\\\n"
+   "  // long 1 2 3 4 5\n"
+   "}",
+   getLLVMStyleWithColumns(20)));
 }
 
 TEST_F(FormatTest, PreservesHangingIndentInCxxComments) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.

In VirtualCallChecker, handle indirect calls.

getDirectCallee() can be nullptr, and dyn_cast(nullptr) is UB


https://reviews.llvm.org/D29303

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp

Index: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -1,3 +1,4 @@
+#include 
 //===- VirtualCallChecker.cpp *- C++ -*-==//
 //
 // The LLVM Compiler Infrastructure
@@ -44,7 +45,7 @@
   /// may result in unexpected behavior).
   bool ReportPureOnly = false;
 
-  typedef const CallExpr * WorkListUnit;
+  typedef const CallExpr *WorkListUnit;
   typedef SmallVector DFSWorkList;
 
   /// A vector representing the worklist which has a chain of CallExprs.
@@ -54,12 +55,13 @@
   // body has not been visited yet.
   // PostVisited : A CallExpr to this FunctionDecl is in the worklist, and the
   // body has been visited.
-  enum Kind { NotVisited,
-  PreVisited,  /**< A CallExpr to this FunctionDecl is in the
-worklist, but the body has not yet been
-visited. */
-  PostVisited  /**< A CallExpr to this FunctionDecl is in the
-worklist, and the body has been visited. */
+  enum Kind {
+NotVisited,
+PreVisited, /**< A CallExpr to this FunctionDecl is in the
+ worklist, but the body has not yet been
+ visited. */
+PostVisited /**< A CallExpr to this FunctionDecl is in the
+ worklist, and the body has been visited. */
   };
 
   /// A DenseMap that records visited states of FunctionDecls.
@@ -135,7 +137,6 @@
   void VisitChildren(Stmt *S);
 
   void ReportVirtualCall(const CallExpr *CE, bool isPure);
-
 };
 } // end anonymous namespace
 
@@ -179,7 +180,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() &&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());
@@ -208,8 +210,9 @@
   os << " <-- " << *visitingCallExpr->getDirectCallee();
 // Names of FunctionDecls in worklist with state PostVisited.
 for (SmallVectorImpl::iterator I = WList.end(),
- E = WList.begin(); I != E; --I) {
-  const FunctionDecl *FD = (*(I-1))->getDirectCallee();
+ E = WList.begin();
+ I != E; --I) {
+  const FunctionDecl *FD = (*(I - 1))->getDirectCallee();
   assert(FD);
   if (VisitedFunctions[FD] == PostVisited)
 os << " <-- " << *FD;
@@ -219,7 +222,7 @@
   }
 
   PathDiagnosticLocation CELoc =
-PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);
+  PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC);
   SourceRange R = CE->getCallee()->getSourceRange();
 
   os << "Call to ";
@@ -249,12 +252,12 @@
 //===--===//
 
 namespace {
-class VirtualCallChecker : public Checker > {
+class VirtualCallChecker : public Checker> {
 public:
   DefaultBool isInterprocedural;
   DefaultBool isPureOnly;
 
-  void checkASTDecl(const CXXRecordDecl *RD, AnalysisManager& mgr,
+  void checkASTDecl(const CXXRecordDecl *RD, AnalysisManager &mgr,
 BugReporter &BR) const {
 AnalysisDeclContext *ADC = mgr.getAnalysisDeclContext(RD);
 
@@ -281,11 +284,9 @@
 
 void ento::registerVirtualCallChecker(CheckerManager &mgr) {
   VirtualCallChecker *checker = mgr.registerChecker();
-  checker->isInterprocedural =
-  mgr.getAnalyzerOptions().getBooleanOption("Interprocedural", false,
-checker);
+  checker->isInterprocedural = mgr.getAnalyzerOptions().getBooleanOption(
+  "Interprocedural", false, checker);
 
   checker->isPureOnly =
-  mgr.getAnalyzerOptions().getBooleanOption("PureOnly", false,
-checker);
+  mgr.getAnalyzerOptions().getBooleanOption("PureOnly", false, checker);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 86337.
sammccall added a comment.

Oops, reverted noise :(


https://reviews.llvm.org/D29303

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp


Index: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -179,7 +179,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() 
&&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());


Index: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -179,7 +179,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() &&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I couldn't work out how to add a test for this, advice appreciated.

Closest I could get was adding something like this to 
test/Analysis/virtualcall.cpp:

  class F { public: F(); void foo(); };
  F::F() { void (F::* ptr) = &F::foo; (this->*ptr)(); }

which crashes, but only if I add extra logging :\


https://reviews.llvm.org/D29303



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


[PATCH] D24333: [CleanupInfo] Use cleanupsHaveSideEffects instead of exprNeedsCleanups in assertions

2017-01-30 Thread Richard Smith via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/test/SemaCXX/pr30306.cpp:5
+template 
+void g(T) { int a[f(3)]; } // expected-no-diagnostics
+

Shouldn't we be (somehow) handling the cleanups from the array bound expression 
here -- either discarding them or attaching them to the array bound? Looks like 
`TreeTransform::TransformVariableArrayType` is missing a call to 
`ActOnFinishFullExpr`.

If we modify the test to:

```
struct A { A(int); ~A(); };
int f(const A &);
template void g() { int a[f(3)]; }
int main() { g(); }
```

... we need to register the `~A()` destructor to actually be run at some point.


https://reviews.llvm.org/D24333



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


[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer added a comment.

Your test case is fine, it crashes with assertions enabled.


https://reviews.llvm.org/D29303



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


[PATCH] D29304: [cmake] Hint find_package() to prefer LLVM installed alongside clang

2017-01-30 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.

Include a path hint for find_package() in ClangConfig.cmake to ensure
that CMake prefers LLVM installed alongside clang over the default
search path.

If two versions of LLVM are installed in the system, and one of them is
in PATH, CMake's find_package() magic prefers the CMake directory
alongside that install by default. Adding a relative hint makes it
possible to prioritize to the install from which find_package() is
called.

If you want to build e.g. LLDB against another install of LLVM, you can
pass LLVM_CONFIG override. In this case, LLDB queries the prefix from
llvm-config and uses the CMake files located there. However, when
including ClangConfig, the implicit find_package() nevertheless prefers
PATH-found LLVM over the one used previously by LLDB, and two versions
of LLVMConfig end up being loaded.

This could be fixed on LLDB end up by explicitly forcing custom package
search location. However, it seems simpler and safer to add a hint to
ClangConfig than to track every usage of ClangConfig.


Repository:
  rL LLVM

https://reviews.llvm.org/D29304

Files:
  cmake/modules/CMakeLists.txt
  cmake/modules/ClangConfig.cmake.in


Index: cmake/modules/ClangConfig.cmake.in
===
--- cmake/modules/ClangConfig.cmake.in
+++ cmake/modules/ClangConfig.cmake.in
@@ -1,9 +1,10 @@
 # This file allows users to call find_package(Clang) and pick up our targets.
 
-find_package(LLVM REQUIRED CONFIG)
-
 @CLANG_CONFIG_CODE@
 
+find_package(LLVM REQUIRED CONFIG
+ HINTS "@CLANG_CONFIG_LLVM_CMAKE_DIR@")
+
 set(CLANG_EXPORTED_TARGETS "@CLANG_EXPORTS@")
 set(CLANG_CMAKE_DIR "@CLANG_CONFIG_CMAKE_DIR@")
 
Index: cmake/modules/CMakeLists.txt
===
--- cmake/modules/CMakeLists.txt
+++ cmake/modules/CMakeLists.txt
@@ -4,17 +4,23 @@
 set(CLANG_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/clang)
 set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/${CLANG_INSTALL_PACKAGE_DIR}")
 
+# Keep this in sync with llvm/cmake/CMakeLists.txt!
+set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
+set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
+
 get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS)
 export(TARGETS ${CLANG_EXPORTS} FILE 
${clang_cmake_builddir}/ClangTargets.cmake)
 
 # Generate ClangConfig.cmake for the build tree.
 set(CLANG_CONFIG_CMAKE_DIR "${clang_cmake_builddir}")
+set(CLANG_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
 set(CLANG_CONFIG_EXPORTS_FILE "${clang_cmake_builddir}/ClangTargets.cmake")
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${clang_cmake_builddir}/ClangConfig.cmake
   @ONLY)
 set(CLANG_CONFIG_CMAKE_DIR)
+set(CLANG_CONFIG_LLVM_CMAKE_DIR)
 set(CLANG_CONFIG_EXPORTS_FILE)
 
 # Generate ClangConfig.cmake for the install tree.
@@ -29,6 +35,7 @@
 get_filename_component(CLANG_INSTALL_PREFIX \"\${CLANG_INSTALL_PREFIX}\" 
PATH)")
 endforeach(p)
 set(CLANG_CONFIG_CMAKE_DIR 
"\${CLANG_INSTALL_PREFIX}/${CLANG_INSTALL_PACKAGE_DIR}")
+set(CLANG_CONFIG_LLVM_CMAKE_DIR 
"\${CLANG_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
 set(CLANG_CONFIG_EXPORTS_FILE "\${CLANG_CMAKE_DIR}/ClangTargets.cmake")
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in


Index: cmake/modules/ClangConfig.cmake.in
===
--- cmake/modules/ClangConfig.cmake.in
+++ cmake/modules/ClangConfig.cmake.in
@@ -1,9 +1,10 @@
 # This file allows users to call find_package(Clang) and pick up our targets.
 
-find_package(LLVM REQUIRED CONFIG)
-
 @CLANG_CONFIG_CODE@
 
+find_package(LLVM REQUIRED CONFIG
+ HINTS "@CLANG_CONFIG_LLVM_CMAKE_DIR@")
+
 set(CLANG_EXPORTED_TARGETS "@CLANG_EXPORTS@")
 set(CLANG_CMAKE_DIR "@CLANG_CONFIG_CMAKE_DIR@")
 
Index: cmake/modules/CMakeLists.txt
===
--- cmake/modules/CMakeLists.txt
+++ cmake/modules/CMakeLists.txt
@@ -4,17 +4,23 @@
 set(CLANG_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/clang)
 set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/${CLANG_INSTALL_PACKAGE_DIR}")
 
+# Keep this in sync with llvm/cmake/CMakeLists.txt!
+set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
+set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
+
 get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS)
 export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake)
 
 # Generate ClangConfig.cmake for the build tree.
 set(CLANG_CONFIG_CMAKE_DIR "${clang_cmake_builddir}")
+set(CLANG_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
 set(CLANG_CONFIG_EXPORTS_FILE "${clang_cmake_builddir}/ClangTargets.cmake")
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/ClangConfig.cmake.in
   ${clang_cmake_builddir}/ClangConfig.cmake
   @ONLY)
 set(CLANG_CONFIG_CMAKE_DIR)
+set(CLANG_CONFIG_LLVM_CMAKE_DIR)
 set(CLANG_CONF

[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 86342.
sammccall added a comment.

Add regression test.


https://reviews.llvm.org/D29303

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  test/Analysis/virtualcall.cpp


Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -115,12 +115,23 @@
   int foo() override;
 };
 
+// Regression test: don't crash when there's no direct callee.
+class F {
+public:
+  F() {
+void (F::* ptr)() = &F::foo;
+(this->*ptr)();
+  }
+  void foo();
+};
+
 int main() {
   A *a;
   B *b;
   C *c;
   D *d;
   E *e;
+  F *f;
 }
 
 #include "virtualcall.h"
Index: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -179,7 +179,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() 
&&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());


Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -115,12 +115,23 @@
   int foo() override;
 };
 
+// Regression test: don't crash when there's no direct callee.
+class F {
+public:
+  F() {
+void (F::* ptr)() = &F::foo;
+(this->*ptr)();
+  }
+  void foo();
+};
+
 int main() {
   A *a;
   B *b;
   C *c;
   D *d;
   E *e;
+  F *f;
 }
 
 #include "virtualcall.h"
Index: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -179,7 +179,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() &&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lg


https://reviews.llvm.org/D29303



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


r293556 - Serialization: use range based for loop (NFC)

2017-01-30 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Mon Jan 30 16:25:28 2017
New Revision: 293556

URL: http://llvm.org/viewvc/llvm-project?rev=293556&view=rev
Log:
Serialization: use range based for loop (NFC)

Just a small clean up noticed when doing post-commit review of Duncan's
previous change for ModuleFile memory ownership semantics.  NFC.

Modified:
cfe/trunk/include/clang/Serialization/ASTReader.h

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=293556&r1=293555&r2=293556&view=diff
==
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Mon Jan 30 16:25:28 2017
@@ -1635,11 +1635,8 @@ public:
   /// reader.
   unsigned getTotalNumPreprocessedEntities() const {
 unsigned Result = 0;
-for (ModuleConstIterator I = ModuleMgr.begin(),
-E = ModuleMgr.end(); I != E; ++I) {
-  Result += I->NumPreprocessedEntities;
-}
-
+for (const auto &M : ModuleMgr)
+  Result += M.NumPreprocessedEntities;
 return Result;
   }
 


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


r293568 - PR28739: Check that integer values fit into 64 bits before extracting them as 64 bit values for pointer arithmetic.

2017-01-30 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Jan 30 17:30:26 2017
New Revision: 293568

URL: http://llvm.org/viewvc/llvm-project?rev=293568&view=rev
Log:
PR28739: Check that integer values fit into 64 bits before extracting them as 
64 bit values for pointer arithmetic.

This fixes various ways to tickle an assertion in constant expression
evaluation when using __int128. Longer term, we need to figure out what should
happen here: either any kind of overflow in offset calculation should result in
a non-constant value or we should truncate to 64 bits. In C++11 onwards, we're
effectively already checking for overflow because we strictly enforce array
bounds checks, but even there some forms of overflow can slip past undetected.

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/const-eval.c
cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=293568&r1=293567&r2=293568&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jan 30 17:30:26 2017
@@ -1460,9 +1460,17 @@ static bool EvaluateIgnoredValue(EvalInf
 
 /// Sign- or zero-extend a value to 64 bits. If it's already 64 bits, just
 /// return its existing value.
-static int64_t getExtValue(const APSInt &Value) {
-  return Value.isSigned() ? Value.getSExtValue()
-  : static_cast(Value.getZExtValue());
+static bool getExtValue(EvalInfo &Info, const Expr *E, const APSInt &Value,
+int64_t &Result) {
+  if (Value.isSigned() ? Value.getMinSignedBits() > 64
+   : Value.getActiveBits() > 64) {
+Info.FFDiag(E);
+return false;
+  }
+
+  Result = Value.isSigned() ? Value.getSExtValue()
+: static_cast(Value.getZExtValue());
+  return true;
 }
 
 /// Should this call expression be treated as a string literal?
@@ -3184,7 +3192,9 @@ struct CompoundAssignSubobjectHandler {
   return false;
 }
 
-int64_t Offset = getExtValue(RHS.getInt());
+int64_t Offset;
+if (!getExtValue(Info, E, RHS.getInt(), Offset))
+  return false;
 if (Opcode == BO_Sub)
   Offset = -Offset;
 
@@ -5148,8 +5158,10 @@ bool LValueExprEvaluator::VisitArraySubs
   if (!EvaluateInteger(E->getIdx(), Index, Info))
 return false;
 
-  return HandleLValueArrayAdjustment(Info, E, Result, E->getType(),
- getExtValue(Index));
+  int64_t Offset;
+  if (!getExtValue(Info, E, Index, Offset))
+return false;
+  return HandleLValueArrayAdjustment(Info, E, Result, E->getType(), Offset);
 }
 
 bool LValueExprEvaluator::VisitUnaryDeref(const UnaryOperator *E) {
@@ -5415,7 +5427,9 @@ bool PointerExprEvaluator::VisitBinaryOp
   if (!EvaluateInteger(IExp, Offset, Info) || !EvalPtrOK)
 return false;
 
-  int64_t AdditionalOffset = getExtValue(Offset);
+  int64_t AdditionalOffset;
+  if (!getExtValue(Info, E, Offset, AdditionalOffset))
+return false;
   if (E->getOpcode() == BO_Sub)
 AdditionalOffset = -AdditionalOffset;
 
@@ -5614,14 +5628,14 @@ bool PointerExprEvaluator::VisitBuiltinC
 APSInt Alignment;
 if (!EvaluateInteger(E->getArg(1), Alignment, Info))
   return false;
-CharUnits Align = CharUnits::fromQuantity(getExtValue(Alignment));
+CharUnits Align = CharUnits::fromQuantity(Alignment.getZExtValue());
 
 if (E->getNumArgs() > 2) {
   APSInt Offset;
   if (!EvaluateInteger(E->getArg(2), Offset, Info))
 return false;
 
-  int64_t AdditionalOffset = -getExtValue(Offset);
+  int64_t AdditionalOffset = -Offset.getZExtValue();
   OffsetResult.Offset += CharUnits::fromQuantity(AdditionalOffset);
 }
 
@@ -5638,12 +5652,11 @@ bool PointerExprEvaluator::VisitBuiltinC
 
   if (BaseAlignment < Align) {
 Result.Designator.setInvalid();
-// FIXME: Quantities here cast to integers because the plural modifier
-// does not work on APSInts yet.
+// FIXME: Add support to Diagnostic for long / long long.
 CCEDiag(E->getArg(0),
 diag::note_constexpr_baa_insufficient_alignment) << 0
-  << (int) BaseAlignment.getQuantity()
-  << (unsigned) getExtValue(Alignment);
+  << (unsigned)BaseAlignment.getQuantity()
+  << (unsigned)Align.getQuantity();
 return false;
   }
 }
@@ -5651,18 +5664,14 @@ bool PointerExprEvaluator::VisitBuiltinC
 // The offset must also have the correct alignment.
 if (OffsetResult.Offset.alignTo(Align) != OffsetResult.Offset) {
   Result.Designator.setInvalid();
-  APSInt Offset(64, false);
-  Offset = OffsetResult.Offset.getQuantity();
-
-  if (OffsetResult.Base)
-CCEDiag(E->getArg(0),
-diag::note_constexpr_baa_insufficient_alignment) << 1
-  << (int) getExtValu

r293572 - Re-apply "[ubsan] Sanity-check shift amounts before truncation"

2017-01-30 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Mon Jan 30 17:38:54 2017
New Revision: 293572

URL: http://llvm.org/viewvc/llvm-project?rev=293572&view=rev
Log:
Re-apply "[ubsan] Sanity-check shift amounts before truncation"

This re-applies r293343 (reverts commit r293475) with a fix for an
assertion failure caused by a missing integer cast. I tested this patch
by using the built compiler to compile X86FastISel.cpp.o with ubsan.

Original commit message:

Ubsan does not report UB shifts in some cases where the shift exponent
needs to be truncated to match the type of the shift base. We perform a
range check on the truncated shift amount, leading to false negatives.

Fix the issue (PR27271) by performing the range check on the original
shift amount.

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

Added:
cfe/trunk/test/CodeGen/ubsan-shift.c
Modified:
cfe/trunk/lib/CodeGen/CGExprScalar.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=293572&r1=293571&r2=293572&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Mon Jan 30 17:38:54 2017
@@ -2751,8 +2751,8 @@ Value *ScalarExprEmitter::EmitShl(const
isa(Ops.LHS->getType())) {
 CodeGenFunction::SanitizerScope SanScope(&CGF);
 SmallVector, 2> Checks;
-llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, RHS);
-llvm::Value *ValidExponent = Builder.CreateICmpULE(RHS, WidthMinusOne);
+llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, Ops.RHS);
+llvm::Value *ValidExponent = Builder.CreateICmpULE(Ops.RHS, WidthMinusOne);
 
 if (SanitizeExponent) {
   Checks.push_back(
@@ -2767,12 +2767,14 @@ Value *ScalarExprEmitter::EmitShl(const
   llvm::BasicBlock *Cont = CGF.createBasicBlock("cont");
   llvm::BasicBlock *CheckShiftBase = CGF.createBasicBlock("check");
   Builder.CreateCondBr(ValidExponent, CheckShiftBase, Cont);
+  llvm::Value *PromotedWidthMinusOne =
+  (RHS == Ops.RHS) ? WidthMinusOne
+   : GetWidthMinusOneValue(Ops.LHS, RHS);
   CGF.EmitBlock(CheckShiftBase);
-  llvm::Value *BitsShiftedOff =
-Builder.CreateLShr(Ops.LHS,
-   Builder.CreateSub(WidthMinusOne, RHS, "shl.zeros",
- /*NUW*/true, /*NSW*/true),
-   "shl.check");
+  llvm::Value *BitsShiftedOff = Builder.CreateLShr(
+  Ops.LHS, Builder.CreateSub(PromotedWidthMinusOne, RHS, "shl.zeros",
+ /*NUW*/ true, /*NSW*/ true),
+  "shl.check");
   if (CGF.getLangOpts().CPlusPlus) {
 // In C99, we are not permitted to shift a 1 bit into the sign bit.
 // Under C++11's rules, shifting a 1 bit into the sign bit is

Added: cfe/trunk/test/CodeGen/ubsan-shift.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-shift.c?rev=293572&view=auto
==
--- cfe/trunk/test/CodeGen/ubsan-shift.c (added)
+++ cfe/trunk/test/CodeGen/ubsan-shift.c Mon Jan 30 17:38:54 2017
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin 
-fsanitize=shift-exponent,shift-base -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: define i32 @f1
+int f1(int c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+  return 1 << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f2
+int f2(long c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
+// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
+  return 1 << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f3
+unsigned f3(unsigned c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
+  return 1U << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f4
+unsigned f4(unsigned long c, int shamt) {
+// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
+// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
+  return 1U << (c << shamt);
+}
+
+// CHECK-LABEL: define i32 @f5
+int f5(int c, long long shamt) {
+// CHECK: icmp ule i64 %{{[0-9]+}}, 31, !nosanitize
+//
+// CHECK: sub nuw nsw i32 31, %sh_prom, !nosanitize
+// CHECK: lshr i32 %{{.*}}, %shl.zeros, !nosanitize
+  return c << shamt;
+}
+
+// CHECK-LABEL: define i32 @f6
+int f6(int c, int shamt) {
+// CHECK: icmp ule i32 %[[WIDTH:.*]], 31, !nosanitize
+//
+// CHECK: sub nuw nsw i32 31, %[[WIDTH]], !nosanitize
+// CHECK: lshr i32 %{{.*}}, %shl.zeros, !nosanitize
+  return c << shamt;
+}


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


Re: r293475 - Revert "r293343 - [ubsan] Sanity-check shift amounts before truncation

2017-01-30 Thread Vedant Kumar via cfe-commits
Sorry about that!

I took another shot at it in r293572.

vedant

> On Jan 30, 2017, at 3:37 AM, Alex Lorenz via cfe-commits 
>  wrote:
> 
> Author: arphaman
> Date: Mon Jan 30 05:37:18 2017
> New Revision: 293475
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=293475&view=rev
> Log:
> Revert "r293343 - [ubsan] Sanity-check shift amounts before truncation
> (fixes PR27271)"
> 
> After r293343 clang fails to compile itself with -fsanitize=undefined (
> http://lab.llvm.org:8080/green/job/clang-stage2-cmake-RgSan_build/).
> 
> rdar://30259929
> 
> Removed:
>cfe/trunk/test/CodeGen/ubsan-shift.c
> Modified:
>cfe/trunk/lib/CodeGen/CGExprScalar.cpp
> 
> Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=293475&r1=293474&r2=293475&view=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Mon Jan 30 05:37:18 2017
> @@ -2751,8 +2751,8 @@ Value *ScalarExprEmitter::EmitShl(const
>isa(Ops.LHS->getType())) {
> CodeGenFunction::SanitizerScope SanScope(&CGF);
> SmallVector, 2> Checks;
> -llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, Ops.RHS);
> -llvm::Value *ValidExponent = Builder.CreateICmpULE(Ops.RHS, 
> WidthMinusOne);
> +llvm::Value *WidthMinusOne = GetWidthMinusOneValue(Ops.LHS, RHS);
> +llvm::Value *ValidExponent = Builder.CreateICmpULE(RHS, WidthMinusOne);
> 
> if (SanitizeExponent) {
>   Checks.push_back(
> 
> Removed: cfe/trunk/test/CodeGen/ubsan-shift.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-shift.c?rev=293474&view=auto
> ==
> --- cfe/trunk/test/CodeGen/ubsan-shift.c (original)
> +++ cfe/trunk/test/CodeGen/ubsan-shift.c (removed)
> @@ -1,29 +0,0 @@
> -// RUN: %clang_cc1 -triple=x86_64-apple-darwin -fsanitize=shift-exponent 
> -emit-llvm %s -o - | FileCheck %s
> -
> -// CHECK-LABEL: define i32 @f1
> -int f1(int c, int shamt) {
> -// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
> -// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
> -  return 1 << (c << shamt);
> -}
> -
> -// CHECK-LABEL: define i32 @f2
> -int f2(long c, int shamt) {
> -// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
> -// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
> -  return 1 << (c << shamt);
> -}
> -
> -// CHECK-LABEL: define i32 @f3
> -unsigned f3(unsigned c, int shamt) {
> -// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
> -// CHECK: icmp ule i32 %{{.*}}, 31, !nosanitize
> -  return 1U << (c << shamt);
> -}
> -
> -// CHECK-LABEL: define i32 @f4
> -unsigned f4(unsigned long c, int shamt) {
> -// CHECK: icmp ule i32 %{{.*}}, 63, !nosanitize
> -// CHECK: icmp ule i64 %{{.*}}, 31, !nosanitize
> -  return 1U << (c << shamt);
> -}
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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


[PATCH] D28365: [Driver] Updated for Visual Studio 2017

2017-01-30 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: lib/Driver/MSVCToolChain.cpp:34
+  #if 0
+#define USE_VS_SETUP_CONFIG
+  #endif

hamzasood wrote:
> rnk wrote:
> > What are the outstanding issues preventing you from enabling this by 
> > default?
> Building on Win32 doesn't imply that you'll have the required header;  it 
> currently needs to be installed [[ 
> https://blogs.msdn.microsoft.com/heaths/2016/09/15/changes-to-visual-studio-15-setup/
>  | separately ]] via nuget. While it would be possible to have cmake create a 
> packages.config file when configuring a visual studio project, the API is 
> only at the RC stage and so the distribution method could potentially change 
> between now and the Visual Studio 2017 release (even if that's not a concern, 
> it's probably out of the scope of this patch anyway).
> Although the code looks useless sitting there ifdefed out, it could be useful 
> for someone eager enough to get the package themselves and run a custom Clang 
> build.
> In the meantime, Visual Studio 2017 installations can only be detected when 
> running in the correct developer command prompt, or by putting one of its 
> toolchain's bin directories at the top of PATH.
This patch looks good, so I don't want to block it, but can you add something 
like:
 // FIXME: Use cmake to auto-detect if the necessary headers exist.
I'm assuming we should test for  eventually.


https://reviews.llvm.org/D28365



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


[PATCH] D16135: Macro Debug Info support in Clang

2017-01-30 Thread Michael Kuperstein via Phabricator via cfe-commits
mkuper resigned from this revision.
mkuper added a comment.

I admit it would be nice if someone reviewed this, but I'm really the wrong 
person for this code area. :-)


https://reviews.llvm.org/D16135



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


Re: r289787 - Re-commit r289252 and r289285, and fix PR31374

2017-01-30 Thread Richard Smith via cfe-commits
On 15 December 2016 at 00:09, Yaxun Liu via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: yaxunl
> Date: Thu Dec 15 02:09:08 2016
> New Revision: 289787
>
> URL: http://llvm.org/viewvc/llvm-project?rev=289787&view=rev
> Log:
> Re-commit r289252 and r289285, and fix PR31374
>
> Added:
> cfe/trunk/test/CodeGenOpenCL/amdgpu-nullptr.cl
> Modified:
> cfe/trunk/include/clang/AST/APValue.h
> cfe/trunk/include/clang/AST/ASTContext.h
> cfe/trunk/include/clang/Basic/TargetInfo.h
> cfe/trunk/lib/AST/APValue.cpp
> cfe/trunk/lib/AST/ASTContext.cpp
> cfe/trunk/lib/AST/ExprConstant.cpp
> cfe/trunk/lib/Basic/Targets.cpp
> cfe/trunk/lib/CodeGen/CGDecl.cpp
> cfe/trunk/lib/CodeGen/CGExprAgg.cpp
> cfe/trunk/lib/CodeGen/CGExprConstant.cpp
> cfe/trunk/lib/CodeGen/CGExprScalar.cpp
> cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> cfe/trunk/lib/CodeGen/CodeGenModule.h
> cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
> cfe/trunk/lib/CodeGen/CodeGenTypes.h
> cfe/trunk/lib/CodeGen/TargetInfo.cpp
> cfe/trunk/lib/CodeGen/TargetInfo.h
>
> Modified: cfe/trunk/include/clang/AST/APValue.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/AST/APValue.h?rev=289787&r1=289786&r2=289787&view=diff
> 
> ==
> --- cfe/trunk/include/clang/AST/APValue.h (original)
> +++ cfe/trunk/include/clang/AST/APValue.h Thu Dec 15 02:09:08 2016
> @@ -135,14 +135,15 @@ public:
>}
>APValue(const APValue &RHS);
>APValue(APValue &&RHS) : Kind(Uninitialized) { swap(RHS); }
> -  APValue(LValueBase B, const CharUnits &O, NoLValuePath N, unsigned
> CallIndex)
> +  APValue(LValueBase B, const CharUnits &O, NoLValuePath N, unsigned
> CallIndex,
> +  bool IsNullPtr = false)
>

Rather than tracking nullness with a separate flag, it would fit into the
model better to track null pointer plus offset and all-zeroes pointer plus
offset as having two different kinds of LValueBase in the address spaces
where they're different.


>: Kind(Uninitialized) {
> -MakeLValue(); setLValue(B, O, N, CallIndex);
> +MakeLValue(); setLValue(B, O, N, CallIndex, IsNullPtr);
>}
>APValue(LValueBase B, const CharUnits &O, ArrayRef
> Path,
> -  bool OnePastTheEnd, unsigned CallIndex)
> +  bool OnePastTheEnd, unsigned CallIndex, bool IsNullPtr = false)
>: Kind(Uninitialized) {
> -MakeLValue(); setLValue(B, O, Path, OnePastTheEnd, CallIndex);
> +MakeLValue(); setLValue(B, O, Path, OnePastTheEnd, CallIndex,
> IsNullPtr);
>}
>APValue(UninitArray, unsigned InitElts, unsigned Size) :
> Kind(Uninitialized) {
>  MakeArray(InitElts, Size);
> @@ -254,6 +255,7 @@ public:
>bool hasLValuePath() const;
>ArrayRef getLValuePath() const;
>unsigned getLValueCallIndex() const;
> +  bool isNullPointer() const;
>
>APValue &getVectorElt(unsigned I) {
>  assert(isVector() && "Invalid accessor");
> @@ -374,10 +376,10 @@ public:
>  ((ComplexAPFloat *)(char *)Data.buffer)->Imag = std::move(I);
>}
>void setLValue(LValueBase B, const CharUnits &O, NoLValuePath,
> - unsigned CallIndex);
> + unsigned CallIndex, bool IsNullPtr);
>void setLValue(LValueBase B, const CharUnits &O,
>   ArrayRef Path, bool OnePastTheEnd,
> - unsigned CallIndex);
> + unsigned CallIndex, bool IsNullPtr);
>void setUnion(const FieldDecl *Field, const APValue &Value) {
>  assert(isUnion() && "Invalid accessor");
>  ((UnionData*)(char*)Data.buffer)->Field = Field;
>
> Modified: cfe/trunk/include/clang/AST/ASTContext.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/AST/ASTContext.h?rev=289787&r1=289786&r2=289787&view=diff
> 
> ==
> --- cfe/trunk/include/clang/AST/ASTContext.h (original)
> +++ cfe/trunk/include/clang/AST/ASTContext.h Thu Dec 15 02:09:08 2016
> @@ -2299,6 +2299,10 @@ public:
>return (*AddrSpaceMap)[AS - LangAS::Offset];
>}
>
> +  /// Get target-dependent integer value for null pointer which is used
> for
> +  /// constant folding.
> +  uint64_t getTargetNullPointerValue(QualType QT) const;
> +
>bool addressSpaceMapManglingFor(unsigned AS) const {
>  return AddrSpaceMapMangling ||
> AS < LangAS::Offset ||
>
> Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Basic/TargetInfo.h?rev=289787&r1=289786&r2=289787&view=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
> +++ cfe/trunk/include/clang/Basic/TargetInfo.h Thu Dec 15 02:09:08 2016
> @@ -42,6 +42,7 @@ class DiagnosticsEngine;
>  class LangOptions;
>  class CodeGenOptions;
>  class MacroBuilder;
> +class QualType;
>  cla

[libcxx] r293581 - Revert "Adorn __call_once_proxy with `inline` and `_LIBCPP_INLINE_VISIBILITY`"

2017-01-30 Thread Justin Bogner via cfe-commits
Author: bogner
Date: Mon Jan 30 19:26:09 2017
New Revision: 293581

URL: http://llvm.org/viewvc/llvm-project?rev=293581&view=rev
Log:
Revert "Adorn __call_once_proxy with `inline` and `_LIBCPP_INLINE_VISIBILITY`"

While this change didn't really hurt, it does lead to spurious
warnings about not being able to override weak symbols if you end up
linking objects built with this change to ones built without it.
Furthermore, since __call_once_proxy is called indirectly anyway it
doesn't actually inline ever.

Longer term, it would probably make sense to give this symbol internal
visibility instead.

This reverts r291497

Modified:
libcxx/trunk/include/mutex

Modified: libcxx/trunk/include/mutex
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/mutex?rev=293581&r1=293580&r2=293581&view=diff
==
--- libcxx/trunk/include/mutex (original)
+++ libcxx/trunk/include/mutex Mon Jan 30 19:26:09 2017
@@ -559,7 +559,6 @@ public:
 #endif
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
 void
 __call_once_proxy(void* __vp)
 {


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


[PATCH] D24333: [CleanupInfo] Use cleanupsHaveSideEffects instead of exprNeedsCleanups in assertions

2017-01-30 Thread Tim Shen via Phabricator via cfe-commits
timshen updated this revision to Diff 86375.
timshen added a comment.

Fix in the right way as rsmith pointed out.


https://reviews.llvm.org/D24333

Files:
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/Sema/pr30306.cpp


Index: clang/test/Sema/pr30306.cpp
===
--- /dev/null
+++ clang/test/Sema/pr30306.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -emit-llvm < %s | FileCheck %s
+
+struct A { A(int); ~A(); };
+int f(const A &);
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+template void g() {
+  int a[f(3)];
+  int b[f(3)];
+}
+int main() { g(); }
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4589,12 +4589,18 @@
   if (ElementType.isNull())
 return QualType();
 
-  ExprResult SizeResult
-= getDerived().TransformExpr(T->getSizeExpr());
-  if (SizeResult.isInvalid())
-return QualType();
-
-  Expr *Size = SizeResult.get();
+  Expr *Size;
+  {
+EnterExpressionEvaluationContext Context(SemaRef,
+ Sema::PotentiallyEvaluated);
+ExprResult SizeResult = getDerived().TransformExpr(T->getSizeExpr());
+if (SizeResult.isInvalid())
+  return QualType();
+SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
+if (SizeResult.isInvalid())
+  return QualType();
+Size = SizeResult.get();
+  }
 
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3858,6 +3858,8 @@
 if (Body.isInvalid())
   Function->setInvalidDecl();
 
+// FIXME: Exit expression evaluation context before finishing the function
+// body.
 ActOnFinishFunctionBody(Function, Body.get(),
 /*IsInstantiation=*/true);
 


Index: clang/test/Sema/pr30306.cpp
===
--- /dev/null
+++ clang/test/Sema/pr30306.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -emit-llvm < %s | FileCheck %s
+
+struct A { A(int); ~A(); };
+int f(const A &);
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+template void g() {
+  int a[f(3)];
+  int b[f(3)];
+}
+int main() { g(); }
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4589,12 +4589,18 @@
   if (ElementType.isNull())
 return QualType();
 
-  ExprResult SizeResult
-= getDerived().TransformExpr(T->getSizeExpr());
-  if (SizeResult.isInvalid())
-return QualType();
-
-  Expr *Size = SizeResult.get();
+  Expr *Size;
+  {
+EnterExpressionEvaluationContext Context(SemaRef,
+ Sema::PotentiallyEvaluated);
+ExprResult SizeResult = getDerived().TransformExpr(T->getSizeExpr());
+if (SizeResult.isInvalid())
+  return QualType();
+SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
+if (SizeResult.isInvalid())
+  return QualType();
+Size = SizeResult.get();
+  }
 
   QualType Result = TL.getType();
   if (getDerived().AlwaysRebuild() ||
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3858,6 +3858,8 @@
 if (Body.isInvalid())
   Function->setInvalidDecl();
 
+// FIXME: Exit expression evaluation context before finishing the function
+// body.
 ActOnFinishFunctionBody(Function, Body.get(),
 /*IsInstantiation=*/true);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293585 - Add better ODR checking for modules.

2017-01-30 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Mon Jan 30 19:44:15 2017
New Revision: 293585

URL: http://llvm.org/viewvc/llvm-project?rev=293585&view=rev
Log:
Add better ODR checking for modules.

When objects are imported for modules, there is a chance that a name collision
will cause an ODR violation.  Previously, only a small number of such
violations were detected.  This patch provides a stronger check based on
AST nodes.

The information needed to uniquely identify an object is taked from the AST and
put into a one-dimensional byte stream.  This stream is then hashed to give
a value to represent the object, which is stored with the other object data
in the module.

When modules are loaded, and Decl's are merged, the hash values of the two
Decl's are compared.  Only Decl's with matched hash values will be merged.
Mismatch hashes will generate a module error, and if possible, point to the
first difference between the two objects.

The transform from AST to byte stream is a modified depth first algorithm.
Due to references between some AST nodes, a pure depth first algorithm could
generate loops.  For Stmt nodes, a straight depth first processing occurs.
For Type and Decl nodes, they are replaced with an index number and only on
first visit will these nodes be processed.  As an optimization, boolean
values are saved and stored together in reverse order at the end of the
byte stream to lower the ammount of data that needs to be hashed.

Compile time impact was measured at 1.5-2.0% during module building, and
negligible during builds without module building.

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

Added:
cfe/trunk/include/clang/AST/ODRHash.h
cfe/trunk/lib/AST/ODRHash.cpp
cfe/trunk/test/Modules/odr_hash.cpp
Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
cfe/trunk/lib/AST/CMakeLists.txt
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/Modules/merge-using-decls.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=293585&r1=293584&r2=293585&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Jan 30 19:44:15 2017
@@ -458,6 +458,9 @@ class CXXRecordDecl : public RecordDecl
 /// \brief Whether we are currently parsing base specifiers.
 unsigned IsParsingBaseSpecifiers : 1;
 
+/// \brief A hash of parts of the class to help in ODR checking.
+unsigned ODRHash;
+
 /// \brief The number of base class specifiers in Bases.
 unsigned NumBases;
 
@@ -703,6 +706,9 @@ public:
 return data().IsParsingBaseSpecifiers;
   }
 
+  void computeODRHash();
+  unsigned getODRHash() const { return data().ODRHash; }
+
   /// \brief Sets the base classes of this struct or class.
   void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
 

Added: cfe/trunk/include/clang/AST/ODRHash.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ODRHash.h?rev=293585&view=auto
==
--- cfe/trunk/include/clang/AST/ODRHash.h (added)
+++ cfe/trunk/include/clang/AST/ODRHash.h Mon Jan 30 19:44:15 2017
@@ -0,0 +1,80 @@
+//===-- ODRHash.h - Hashing to diagnose ODR failures *- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+/// This file contains the declaration of the ODRHash class, which calculates
+/// a hash based on AST nodes, which is stable across different runs.
+///
+//===--===//
+
+#include "clang/AST/DeclarationName.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TemplateBase.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/SmallVector.h"
+
+namespace clang {
+
+class Decl;
+class IdentifierInfo;
+class NestedNameSpecifer;
+class Stmt;
+class TemplateParameterList;
+
+// ODRHash is used to calculate a hash based on AST node contents that
+// does not rely on pointer addresses.  This allows the hash to not vary
+// between runs and is usable to detect ODR problems in modules.  To use,
+// construct an ODRHash object, then call Add* methods over the nodes that
+// need to be hashed.  Then call CalculateHash to get the hash value.
+// Typically, only one Add* cal

[PATCH] D21675: New ODR checker for modules

2017-01-30 Thread Richard Trieu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293585: Add better ODR checking for modules. (authored by 
rtrieu).

Changed prior to commit:
  https://reviews.llvm.org/D21675?vs=86142&id=86376#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D21675

Files:
  cfe/trunk/include/clang/AST/DeclCXX.h
  cfe/trunk/include/clang/AST/ODRHash.h
  cfe/trunk/include/clang/AST/Stmt.h
  cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
  cfe/trunk/lib/AST/CMakeLists.txt
  cfe/trunk/lib/AST/DeclCXX.cpp
  cfe/trunk/lib/AST/ODRHash.cpp
  cfe/trunk/lib/AST/StmtProfile.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
  cfe/trunk/lib/Serialization/ASTWriter.cpp
  cfe/trunk/test/Modules/merge-using-decls.cpp
  cfe/trunk/test/Modules/odr_hash.cpp

Index: cfe/trunk/lib/AST/DeclCXX.cpp
===
--- cfe/trunk/lib/AST/DeclCXX.cpp
+++ cfe/trunk/lib/AST/DeclCXX.cpp
@@ -18,6 +18,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
+#include "clang/AST/ODRHash.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "llvm/ADT/STLExtras.h"
@@ -71,8 +72,8 @@
   ImplicitCopyAssignmentHasConstParam(true),
   HasDeclaredCopyConstructorWithConstParam(false),
   HasDeclaredCopyAssignmentWithConstParam(false), IsLambda(false),
-  IsParsingBaseSpecifiers(false), NumBases(0), NumVBases(0), Bases(),
-  VBases(), Definition(D), FirstFriend() {}
+  IsParsingBaseSpecifiers(false), ODRHash(0), NumBases(0), NumVBases(0),
+  Bases(), VBases(), Definition(D), FirstFriend() {}
 
 CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const {
   return Bases.get(Definition->getASTContext().getExternalSource());
@@ -371,6 +372,16 @@
   data().IsParsingBaseSpecifiers = false;
 }
 
+void CXXRecordDecl::computeODRHash() {
+  if (!DefinitionData)
+return;
+
+  ODRHash Hash;
+  Hash.AddCXXRecordDecl(this);
+
+  DefinitionData->ODRHash = Hash.CalculateHash();
+}
+
 void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) {
   // C++11 [class.copy]p11:
   //   A defaulted copy/move constructor for a class X is defined as
Index: cfe/trunk/lib/AST/ODRHash.cpp
===
--- cfe/trunk/lib/AST/ODRHash.cpp
+++ cfe/trunk/lib/AST/ODRHash.cpp
@@ -0,0 +1,892 @@
+//===-- ODRHash.cpp - Hashing to diagnose ODR failures --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+/// This file implements the ODRHash class, which calculates a hash based
+/// on AST nodes, which is stable across different runs.
+///
+//===--===//
+
+#include "clang/AST/ODRHash.h"
+
+#include "clang/AST/DeclVisitor.h"
+#include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/StmtVisitor.h"
+#include "clang/AST/TypeVisitor.h"
+
+using namespace clang;
+
+// This method adds more information that AddDecl does.
+void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) {
+  assert(Record && Record->hasDefinition() &&
+ "Expected non-null record to be a definition.");
+  AddDecl(Record);
+
+  // Additional information that is not needed in AddDecl.  Do not move this
+  // to ODRTypeVisitor.
+  ID.AddInteger(Record->getNumBases());
+  for (auto base : Record->bases()) {
+AddBoolean(base.isVirtual());
+AddQualType(base.getType());
+  }
+
+  const ClassTemplateDecl *TD = Record->getDescribedClassTemplate();
+  AddBoolean(TD);
+  if (TD) {
+AddTemplateParameterList(TD->getTemplateParameters());
+  }
+}
+
+// Hashing for Stmt is with Stmt::Profile, since they derive from the same base
+// class.
+void ODRHash::AddStmt(const Stmt *S) {
+  assert(S && "Expecting non-null pointer.");
+  S->ProcessODRHash(ID, *this);
+}
+
+void ODRHash::AddIdentifierInfo(const IdentifierInfo *II) {
+  assert(II && "Expecting non-null pointer.");
+  ID.AddString(II->getName());
+}
+
+void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
+  assert(NNS && "Expecting non-null pointer.");
+  const auto *Prefix = NNS->getPrefix();
+  AddBoolean(Prefix);
+  if (Prefix) {
+AddNestedNameSpecifier(Prefix);
+  }
+
+  auto Kind = NNS->getKind();
+  ID.AddInteger(Kind);
+  switch (Kind) {
+  case NestedNameSpecifier::Identifier:
+AddIdentifierInfo(NNS->getAsIdentifier());
+break;
+  case NestedNameSpecifier::Namespace:
+AddDecl(NNS->getAsNamespace());
+break;
+  case NestedNameSpecifier::NamespaceAlias:
+AddDecl(NNS->getAsNamespaceAlias());
+break;
+  case NestedNameSpeci

[PATCH] D24333: [CleanupInfo] Use cleanupsHaveSideEffects instead of exprNeedsCleanups in assertions

2017-01-30 Thread Tim Shen via Phabricator via cfe-commits
timshen updated this revision to Diff 86377.
timshen added a comment.

ActOnFinishFullExpr after exiting the expression evaluation context.


https://reviews.llvm.org/D24333

Files:
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/Sema/pr30306.cpp


Index: clang/test/Sema/pr30306.cpp
===
--- /dev/null
+++ clang/test/Sema/pr30306.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -emit-llvm < %s | FileCheck %s
+
+struct A { A(int); ~A(); };
+int f(const A &);
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+template void g() {
+  int a[f(3)];
+  int b[f(3)];
+}
+int main() { g(); }
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4589,8 +4589,15 @@
   if (ElementType.isNull())
 return QualType();
 
-  ExprResult SizeResult
-= getDerived().TransformExpr(T->getSizeExpr());
+  ExprResult SizeResult;
+  {
+EnterExpressionEvaluationContext Context(SemaRef,
+ Sema::PotentiallyEvaluated);
+SizeResult = getDerived().TransformExpr(T->getSizeExpr());
+  }
+  if (SizeResult.isInvalid())
+return QualType();
+  SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
   if (SizeResult.isInvalid())
 return QualType();
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3858,6 +3858,8 @@
 if (Body.isInvalid())
   Function->setInvalidDecl();
 
+// FIXME: finishing the function body while in an expression evaluation
+// context seems wrong. Investigate more.
 ActOnFinishFunctionBody(Function, Body.get(),
 /*IsInstantiation=*/true);
 


Index: clang/test/Sema/pr30306.cpp
===
--- /dev/null
+++ clang/test/Sema/pr30306.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -x c++ -emit-llvm < %s | FileCheck %s
+
+struct A { A(int); ~A(); };
+int f(const A &);
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+// CHECK: call void @_ZN1AC1Ei
+// CHECK-NEXT: call i32 @_Z1fRK1A
+// CHECK-NEXT: call void @_ZN1AD1Ev
+template void g() {
+  int a[f(3)];
+  int b[f(3)];
+}
+int main() { g(); }
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4589,8 +4589,15 @@
   if (ElementType.isNull())
 return QualType();
 
-  ExprResult SizeResult
-= getDerived().TransformExpr(T->getSizeExpr());
+  ExprResult SizeResult;
+  {
+EnterExpressionEvaluationContext Context(SemaRef,
+ Sema::PotentiallyEvaluated);
+SizeResult = getDerived().TransformExpr(T->getSizeExpr());
+  }
+  if (SizeResult.isInvalid())
+return QualType();
+  SizeResult = SemaRef.ActOnFinishFullExpr(SizeResult.get());
   if (SizeResult.isInvalid())
 return QualType();
 
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3858,6 +3858,8 @@
 if (Body.isInvalid())
   Function->setInvalidDecl();
 
+// FIXME: finishing the function body while in an expression evaluation
+// context seems wrong. Investigate more.
 ActOnFinishFunctionBody(Function, Body.get(),
 /*IsInstantiation=*/true);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Add warning for c++ member variable shadowing

2017-01-30 Thread James Sun via cfe-commits
Hi Richard

Sorry for the late reply. Thank you for giving the feedback! The updated 
version is attached. Please let me know if there is anything improper.

Thanks

James

From:  on behalf of Richard Smith 
Date: Friday, January 27, 2017 at 3:03 PM
To: James Sun 
Cc: Saleem Abdulrasool , "cfe-commits@lists.llvm.org" 
, Aaron Ballman 
Subject: Re: Add warning for c++ member variable shadowing

+def warn_shadow_member_variable : Warning<
+  "shadowed variable '%0' in type '%1' inheriting from type '%2'">,

The phrasing of this is incorrect: the things you're warning about are not 
variables, they're non-static data members. Perhaps something like:

  "non-static data member '%0' of '%1' shadows member inherited from type '%2'"

+   InGroup;

Would it make sense to put this in a subgroup of -Wshadow so that it can be 
controlled separately?

+  /// Check if there is a member variable shadowing

Please end comments in a period.

+  void CheckShadowInheritedVariables(const SourceLocation &Loc,

Likewise, 'Variables' is wrong. We would typically use the C term 'Fields' for 
these cases within Clang sources.

+  for (const auto &Base : DC->bases()) {
+if (const auto *TSI = Base.getTypeSourceInfo())
+  if (const auto *BaseClass = TSI->getType()->getAsCXXRecordDecl()) {
+for (const auto *Field : BaseClass->fields())
+  if (Field->getName() == FieldName)
+Diag(Loc, diag::warn_shadow_member_variable)
+  << FieldName << RD->getName() << BaseClass->getName();
+// Search parent's parents
+CheckShadowInheritedVariables(Loc, FieldName, RD, BaseClass);
+  }
+  }

Maybe we should avoid diagnosing shadowing of members that are inaccessible 
from the derived class? What about if the field name is ambiguous? Also, we 
shouldn't recurse if lookup finds something with the given name in this class, 
and ideally we would only visit each class once, even if it appears multiple 
times in a multiple-inheritance scenario. CXXRecordDecl::lookupInBases can 
handle most of these cases for you automatically, and will also let you build a 
set of paths to problematic base classes in case you want to report those.

On 24 January 2017 at 20:52, James Sun 
mailto:james...@fb.com>> wrote:
Thanks for the comments. The new version is attached.
Wrt two of your questions:

(1)  “The description that you have on CheckShadowInheritedVariables isn't 
really the type of comments that we have in doxygen form.  Im not sure if its 
in line with the rest of the code.”
I’ve read through the doxygen wiki; hopefully it’s fixed; let me know if it’s 
still wrong

(2) “Why are you checking that the DeclContext has a definition rather than the 
record itself?”
There are cases like “struct A; struct B : A {};”, where A does not have a 
definition. The compiler will hit an assertion failure if we call A.bases() 
directly.

Thanks

James


From: Saleem Abdulrasool mailto:compn...@compnerd.org>>
Date: Tuesday, January 24, 2017 at 7:10 PM
To: James Sun mailto:james...@fb.com>>
Cc: "cfe-commits@lists.llvm.org" 
mailto:cfe-commits@lists.llvm.org>>, Aaron Ballman 
mailto:aa...@aaronballman.com>>, Richard Smith 
mailto:rich...@metafoo.co.uk>>
Subject: Re: Add warning for c++ member variable shadowing

Some more stylistic comments:

The description that you have on CheckShadowInheritedVariables isn't really the 
type of comments that we have in doxygen form.  Im not sure if its in line with 
the rest of the code.

The ignore warning comments are restating what is in the code, please remove 
them.

Could you make the header and the source file match the name?

Why are you checking that the DeclContext has a definition rather than the 
record itself?

Space after the <<.

Don't use the cast for the check, use isa.  Although, since you use the value 
later, it is probably better to write this as:

if (const auto *RD = cast(CurContext))
  CheckShadowInheritedVariabless(Loc, Name.getAsString(), RD, RD);



On Tue, Jan 24, 2017 at 4:06 PM, James Sun via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Coding style change

From: James Sun mailto:james...@fb.com>>
Date: Tuesday, January 24, 2017 at 2:36 PM
To: "cfe-commits@lists.llvm.org" 
mailto:cfe-commits@lists.llvm.org>>
Subject: Add warning for c++ member variable shadowing

Dear members

Here is a patch (attached) to create warnings where a member variable shadows 
the one in one of its inheriting classes. For cases where we really don't want 
to shadow member variables, e.g.

class a {
  int foo;
}

class b : a {
  int foo; // Generate a warning
}

This patch
(1) adds a member variable shadowing checking, and
(2) incorporates it to the unit tests.


Comments are welcome.

Thanks

James

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

[PATCH] D29304: [cmake] Hint find_package() to prefer LLVM installed alongside clang

2017-01-30 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rL LLVM

https://reviews.llvm.org/D29304



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


r293595 - Improve fix for PR28739

2017-01-30 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Jan 30 20:23:02 2017
New Revision: 293595

URL: http://llvm.org/viewvc/llvm-project?rev=293595&view=rev
Log:
Improve fix for PR28739

Don't try to map an APSInt addend to an int64_t in pointer arithmetic before
bounds-checking it. This gives more consistent behavior (outside C++11, we
consistently use 2s complement semantics for both pointer and integer overflow
in constant expressions) and fixes some cases where in C++11 we would fail to
properly check for out-of-bounds pointer arithmetic (if the 2s complement
64-bit overflow landed us back in-bounds).

In passing, also fix some cases where we'd perform possibly-overflowing
arithmetic on CharUnits (which have a signed underlying type) during constant
expression evaluation.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/const-eval.c
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=293595&r1=293594&r2=293595&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Mon Jan 30 20:23:02 2017
@@ -44,7 +44,8 @@ def note_constexpr_non_global : Note<
 def note_constexpr_uninitialized : Note<
   "%select{|sub}0object of type %1 is not initialized">;
 def note_constexpr_array_index : Note<"cannot refer to element %0 of "
-  "%select{array of %2 elements|non-array object}1 in a constant expression">;
+  "%select{array of %2 element%plural{1:|:s}2|non-array object}1 "
+  "in a constant expression">;
 def note_constexpr_float_arithmetic : Note<
   "floating point arithmetic produces %select{an infinity|a NaN}0">;
 def note_constexpr_pointer_subtraction_not_same_array : Note<

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=293595&r1=293594&r2=293595&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jan 30 20:23:02 2017
@@ -350,36 +350,48 @@ namespace {
   MostDerivedArraySize = 2;
   MostDerivedPathLength = Entries.size();
 }
-void diagnosePointerArithmetic(EvalInfo &Info, const Expr *E, uint64_t N);
+void diagnosePointerArithmetic(EvalInfo &Info, const Expr *E, APSInt N);
 /// Add N to the address of this subobject.
-void adjustIndex(EvalInfo &Info, const Expr *E, uint64_t N) {
-  if (Invalid) return;
+void adjustIndex(EvalInfo &Info, const Expr *E, APSInt N) {
+  if (Invalid || !N) return;
+  uint64_t TruncatedN = N.extOrTrunc(64).getZExtValue();
   if (isMostDerivedAnUnsizedArray()) {
 // Can't verify -- trust that the user is doing the right thing (or if
 // not, trust that the caller will catch the bad behavior).
-Entries.back().ArrayIndex += N;
-return;
-  }
-  if (MostDerivedPathLength == Entries.size() &&
-  MostDerivedIsArrayElement) {
-Entries.back().ArrayIndex += N;
-if (Entries.back().ArrayIndex > getMostDerivedArraySize()) {
-  diagnosePointerArithmetic(Info, E, Entries.back().ArrayIndex);
-  setInvalid();
-}
+// FIXME: Should we reject if this overflows, at least?
+Entries.back().ArrayIndex += TruncatedN;
 return;
   }
+
   // [expr.add]p4: For the purposes of these operators, a pointer to a
   // nonarray object behaves the same as a pointer to the first element of
   // an array of length one with the type of the object as its element 
type.
-  if (IsOnePastTheEnd && N == (uint64_t)-1)
-IsOnePastTheEnd = false;
-  else if (!IsOnePastTheEnd && N == 1)
-IsOnePastTheEnd = true;
-  else if (N != 0) {
-diagnosePointerArithmetic(Info, E, uint64_t(IsOnePastTheEnd) + N);
+  bool IsArray = MostDerivedPathLength == Entries.size() &&
+ MostDerivedIsArrayElement;
+  uint64_t ArrayIndex =
+  IsArray ? Entries.back().ArrayIndex : (uint64_t)IsOnePastTheEnd;
+  uint64_t ArraySize =
+  IsArray ? getMostDerivedArraySize() : (uint64_t)1;
+
+  if (N < -(int64_t)ArrayIndex || N > ArraySize - ArrayIndex) {
+// Calculate the actual index in a wide enough type, so we can include
+// it in the note.
+N = N.extend(std::max(N.getBitWidth() + 1, 65));
+(llvm::APInt&)N += ArrayIndex;
+assert(N.ugt(ArraySize) && "bounds check failed for in-bounds index");
+diagnosePointerArithmetic(Info, E, N);
 setInvalid();
+return;
   }
+
+  ArrayIndex += TruncatedN;
+  assert(

r293596 - Handle ObjCEncodeExpr in extractStringLiteralCharacter.

2017-01-30 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Jan 30 20:31:39 2017
New Revision: 293596

URL: http://llvm.org/viewvc/llvm-project?rev=293596&view=rev
Log:
Handle ObjCEncodeExpr in extractStringLiteralCharacter.

This fixes an assertion failure that occurs later in the function when
an ObjCEncodeExpr is cast to StringLiteral.

rdar://problem/30111207

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/CodeGenObjC/encode-test.m

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=293596&r1=293595&r2=293596&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jan 30 20:31:39 2017
@@ -2394,7 +2394,14 @@ static unsigned getBaseIndex(const CXXRe
 /// Extract the value of a character from a string literal.
 static APSInt extractStringLiteralCharacter(EvalInfo &Info, const Expr *Lit,
 uint64_t Index) {
-  // FIXME: Support ObjCEncodeExpr, MakeStringConstant
+  // FIXME: Support MakeStringConstant
+  if (const auto *ObjCEnc = dyn_cast(Lit)) {
+std::string Str;
+Info.Ctx.getObjCEncodingForType(ObjCEnc->getEncodedType(), Str);
+assert(Index <= Str.size() && "Index too large");
+return APSInt::getUnsigned(Str.c_str()[Index]);
+  }
+
   if (auto PE = dyn_cast(Lit))
 Lit = PE->getFunctionName();
   const StringLiteral *S = cast(Lit);

Modified: cfe/trunk/test/CodeGenObjC/encode-test.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/encode-test.m?rev=293596&r1=293595&r2=293596&view=diff
==
--- cfe/trunk/test/CodeGenObjC/encode-test.m (original)
+++ cfe/trunk/test/CodeGenObjC/encode-test.m Mon Jan 30 20:31:39 2017
@@ -180,3 +180,14 @@ const char g14[] = @encode(__typeof__(*t
 
 // CHECK: @g15 = constant [2 x i8] c":\00"
 const char g15[] = @encode(SEL);
+
+typedef typeof(sizeof(int)) size_t;
+size_t strlen(const char *s);
+
+// CHECK-LABEL: @test_strlen(
+// CHECK: %[[i:.*]] = alloca i32
+// CHECK: store i32 1, i32* %[[i]]
+void test_strlen() {
+  const char array[] = @encode(int);
+  int i = strlen(array);
+}


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


Re: Add warning for c++ member variable shadowing

2017-01-30 Thread Saleem Abdulrasool via cfe-commits
I think that the patch is starting to look pretty good!

Can you add some test cases for the particular cases to diagnose in a
separate test set to ensure that we have proper coverage of the various
cases rather than relying on the existing test cases?  Something to make
sure that we get the simple case right as well as the complex cases (e.g.
we don't print duplicate warnings for multiple paths).


On Mon, Jan 30, 2017 at 5:50 PM, James Sun  wrote:

> Hi Richard
>
>
>
> Sorry for the late reply. Thank you for giving the feedback! The updated
> version is attached. Please let me know if there is anything improper.
>
>
>
> Thanks
>
>
>
> James
>
>
>
> *From: * on behalf of Richard Smith <
> rich...@metafoo.co.uk>
> *Date: *Friday, January 27, 2017 at 3:03 PM
> *To: *James Sun 
> *Cc: *Saleem Abdulrasool , "
> cfe-commits@lists.llvm.org" , Aaron Ballman <
> aa...@aaronballman.com>
>
> *Subject: *Re: Add warning for c++ member variable shadowing
>
>
>
> +def warn_shadow_member_variable : Warning<
>
> +  "shadowed variable '%0' in type '%1' inheriting from type '%2'">,
>
>
>
> The phrasing of this is incorrect: the things you're warning about are not
> variables, they're non-static data members. Perhaps something like:
>
>
>
>   "non-static data member '%0' of '%1' shadows member inherited from type
> '%2'"
>
>
>
> +   InGroup;
>
>
>
> Would it make sense to put this in a subgroup of -Wshadow so that it can
> be controlled separately?
>
>
>
> +  /// Check if there is a member variable shadowing
>
>
>
> Please end comments in a period.
>
>
>
> +  void CheckShadowInheritedVariables(const SourceLocation &Loc,
>
>
>
> Likewise, 'Variables' is wrong. We would typically use the C term 'Fields'
> for these cases within Clang sources.
>
>
>
> +  for (const auto &Base : DC->bases()) {
>
> +if (const auto *TSI = Base.getTypeSourceInfo())
>
> +  if (const auto *BaseClass = TSI->getType()->getAsCXXRecordDecl()) {
>
> +for (const auto *Field : BaseClass->fields())
>
> +  if (Field->getName() == FieldName)
>
> +Diag(Loc, diag::warn_shadow_member_variable)
>
> +  << FieldName << RD->getName() << BaseClass->getName();
>
> +// Search parent's parents
>
> +CheckShadowInheritedVariables(Loc, FieldName, RD, BaseClass);
>
> +  }
>
> +  }
>
>
>
> Maybe we should avoid diagnosing shadowing of members that are
> inaccessible from the derived class? What about if the field name is
> ambiguous? Also, we shouldn't recurse if lookup finds something with the
> given name in this class, and ideally we would only visit each class once,
> even if it appears multiple times in a multiple-inheritance scenario.
> CXXRecordDecl::lookupInBases can handle most of these cases for you
> automatically, and will also let you build a set of paths to problematic
> base classes in case you want to report those.
>
>
>
> On 24 January 2017 at 20:52, James Sun  wrote:
>
> Thanks for the comments. The new version is attached.
>
> Wrt two of your questions:
>
>
>
> (1)  “The description that you have on CheckShadowInheritedVariables
> isn't really the type of comments that we have in doxygen form.  Im not
> sure if its in line with the rest of the code.”
>
> I’ve read through the doxygen wiki; hopefully it’s fixed; let me know if
> it’s still wrong
>
>
>
> (2) “Why are you checking that the DeclContext has a definition rather
> than the record itself?”
>
> There are cases like “struct A; struct B : A {};”, where A does not have a
> definition. The compiler will hit an assertion failure if we call A.bases()
> directly.
>
>
>
> Thanks
>
>
>
> James
>
>
>
>
>
> *From: *Saleem Abdulrasool 
> *Date: *Tuesday, January 24, 2017 at 7:10 PM
> *To: *James Sun 
> *Cc: *"cfe-commits@lists.llvm.org" , Aaron
> Ballman , Richard Smith 
> *Subject: *Re: Add warning for c++ member variable shadowing
>
>
>
> Some more stylistic comments:
>
>
>
> The description that you have on CheckShadowInheritedVariables isn't
> really the type of comments that we have in doxygen form.  Im not sure if
> its in line with the rest of the code.
>
>
>
> The ignore warning comments are restating what is in the code, please
> remove them.
>
>
>
> Could you make the header and the source file match the name?
>
>
>
> Why are you checking that the DeclContext has a definition rather than the
> record itself?
>
>
>
> Space after the <<.
>
>
>
> Don't use the cast for the check, use isa.  Although, since you use the
> value later, it is probably better to write this as:
>
>
>
> if (const auto *RD = cast(CurContext))
>
>   CheckShadowInheritedVariabless(Loc, Name.getAsString(), RD, RD);
>
>
>
>
>
>
>
> On Tue, Jan 24, 2017 at 4:06 PM, James Sun via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> Coding style change
>
>
>
> *From: *James Sun 
> *Date: *Tuesday, January 24, 2017 at 2:36 PM
> *To: *"cfe-commits@lists.llvm.org" 
> *Subject: *Add warning for c++ member variable shadowing
>
>
>
> Dear members
>
>
>
> Here is a 

Re: [libcxx] r293581 - Revert "Adorn __call_once_proxy with `inline` and `_LIBCPP_INLINE_VISIBILITY`"

2017-01-30 Thread Saleem Abdulrasool via cfe-commits
Can you file a PR for changing this to internal visibility please?  I think
that we could probably do that in the unstable ABI versioning in fact.

On Mon, Jan 30, 2017 at 5:26 PM, Justin Bogner via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: bogner
> Date: Mon Jan 30 19:26:09 2017
> New Revision: 293581
>
> URL: http://llvm.org/viewvc/llvm-project?rev=293581&view=rev
> Log:
> Revert "Adorn __call_once_proxy with `inline` and
> `_LIBCPP_INLINE_VISIBILITY`"
>
> While this change didn't really hurt, it does lead to spurious
> warnings about not being able to override weak symbols if you end up
> linking objects built with this change to ones built without it.
> Furthermore, since __call_once_proxy is called indirectly anyway it
> doesn't actually inline ever.
>
> Longer term, it would probably make sense to give this symbol internal
> visibility instead.
>
> This reverts r291497
>
> Modified:
> libcxx/trunk/include/mutex
>
> Modified: libcxx/trunk/include/mutex
> URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/
> mutex?rev=293581&r1=293580&r2=293581&view=diff
> 
> ==
> --- libcxx/trunk/include/mutex (original)
> +++ libcxx/trunk/include/mutex Mon Jan 30 19:26:09 2017
> @@ -559,7 +559,6 @@ public:
>  #endif
>
>  template 
> -inline _LIBCPP_INLINE_VISIBILITY
>  void
>  __call_once_proxy(void* __vp)
>  {
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>



-- 
Saleem Abdulrasool
compnerd (at) compnerd (dot) org
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r293596 - Handle ObjCEncodeExpr in extractStringLiteralCharacter.

2017-01-30 Thread Akira Hatanaka via cfe-commits
Hans, can this be merged to 4.0? This fixes a regression from 3.9 (the part I 
touched was committed a few years ago, but didn’t cause an assert until 
recently). 

> On Jan 30, 2017, at 6:31 PM, Akira Hatanaka via cfe-commits 
>  wrote:
> 
> Author: ahatanak
> Date: Mon Jan 30 20:31:39 2017
> New Revision: 293596
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=293596&view=rev
> Log:
> Handle ObjCEncodeExpr in extractStringLiteralCharacter.
> 
> This fixes an assertion failure that occurs later in the function when
> an ObjCEncodeExpr is cast to StringLiteral.
> 
> rdar://problem/30111207
> 
> Modified:
>cfe/trunk/lib/AST/ExprConstant.cpp
>cfe/trunk/test/CodeGenObjC/encode-test.m
> 
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=293596&r1=293595&r2=293596&view=diff
> ==
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Jan 30 20:31:39 2017
> @@ -2394,7 +2394,14 @@ static unsigned getBaseIndex(const CXXRe
> /// Extract the value of a character from a string literal.
> static APSInt extractStringLiteralCharacter(EvalInfo &Info, const Expr *Lit,
> uint64_t Index) {
> -  // FIXME: Support ObjCEncodeExpr, MakeStringConstant
> +  // FIXME: Support MakeStringConstant
> +  if (const auto *ObjCEnc = dyn_cast(Lit)) {
> +std::string Str;
> +Info.Ctx.getObjCEncodingForType(ObjCEnc->getEncodedType(), Str);
> +assert(Index <= Str.size() && "Index too large");
> +return APSInt::getUnsigned(Str.c_str()[Index]);
> +  }
> +
>   if (auto PE = dyn_cast(Lit))
> Lit = PE->getFunctionName();
>   const StringLiteral *S = cast(Lit);
> 
> Modified: cfe/trunk/test/CodeGenObjC/encode-test.m
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/encode-test.m?rev=293596&r1=293595&r2=293596&view=diff
> ==
> --- cfe/trunk/test/CodeGenObjC/encode-test.m (original)
> +++ cfe/trunk/test/CodeGenObjC/encode-test.m Mon Jan 30 20:31:39 2017
> @@ -180,3 +180,14 @@ const char g14[] = @encode(__typeof__(*t
> 
> // CHECK: @g15 = constant [2 x i8] c":\00"
> const char g15[] = @encode(SEL);
> +
> +typedef typeof(sizeof(int)) size_t;
> +size_t strlen(const char *s);
> +
> +// CHECK-LABEL: @test_strlen(
> +// CHECK: %[[i:.*]] = alloca i32
> +// CHECK: store i32 1, i32* %[[i]]
> +void test_strlen() {
> +  const char array[] = @encode(int);
> +  int i = strlen(array);
> +}
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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


[PATCH] D24933: Enable configuration files in clang

2017-01-30 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added inline comments.



Comment at: lib/Driver/Driver.cpp:172
+NumConfigArgs = static_cast(NumCfgArgs);
+  }
+

sepavloff wrote:
> bruno wrote:
> > If `NumCfgArgs == 0` it would be nice to warn that the config file is empty?
> Not sure if it makes sense. Usually warning are used to attract attention to 
> the things that potentially may be harmful. An empty config file is strange 
> but does not look dangerous. 
I agree. The config files might be automatically generated by wrapper scripts, 
and adding special cases to avoid creating empty files seems like an 
unnecessary complication.



Comment at: lib/Driver/Driver.cpp:2695
 
+  // Clain all arguments that come from a configuration file so that the driver
+  // does not warn on any that are unused.

Clain -> Claim



Comment at: tools/driver/driver.cpp:332
+  StringRef PName = llvm::sys::path::stem(ProgramName);
+  size_t Pos = PName.find("-clang");
+  if (Pos == StringRef::npos)

Looking for "-clang" is too specific; our driver-name suffix processing allows 
more general naming than this. For one thing, it will not pick up armv7l-cpp 
correctly (which would be a problem because the config files likely contain 
options affecting preprocessing). I also have users which use symlinks to clang 
named fooclang.

I think that an easy way to do this is to use the result from 
ToolChain::getTargetAndModeFromProgramName, which we call from the caller of 
this function:

  std::string ProgName = argv[0];
  std::pair TargetAndMode =
  ToolChain::getTargetAndModeFromProgramName(ProgName);

We can use TargetAndMode.first here, instead of looking for the string before 
"-clang", and that should be consistent with the rest of our processing.



https://reviews.llvm.org/D24933



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


[libcxx] r293599 - Fix PR#31779: basic_string::operator= isn't exception safe.

2017-01-30 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Mon Jan 30 21:40:52 2017
New Revision: 293599

URL: http://llvm.org/viewvc/llvm-project?rev=293599&view=rev
Log:
Fix PR#31779: basic_string::operator= isn't exception safe.

Modified:
libcxx/trunk/include/string
libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp

Modified: libcxx/trunk/include/string
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=293599&r1=293598&r2=293599&view=diff
==
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Mon Jan 30 21:40:52 2017
@@ -1367,12 +1367,28 @@ private:
 _LIBCPP_INLINE_VISIBILITY
 void __copy_assign_alloc(const basic_string& __str, true_type)
 {
-if (__alloc() != __str.__alloc())
+if (__alloc() == __str.__alloc())
+__alloc() = __str.__alloc();
+else
 {
-clear();
-shrink_to_fit();
+if (!__str.__is_long())
+{
+clear();
+shrink_to_fit();
+__alloc() = __str.__alloc();
+}
+else
+{
+allocator_type __a = __str.__alloc();
+pointer __p = __alloc_traits::allocate(__a, 
__str.__get_long_cap());
+clear();
+shrink_to_fit();
+__alloc() = _VSTD::move(__a);
+__set_long_pointer(__p);
+__set_long_cap(__str.__get_long_cap());
+__set_long_size(__str.size());
+}
 }
-__alloc() = __str.__alloc();
 }
 
 _LIBCPP_INLINE_VISIBILITY

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp?rev=293599&r1=293598&r2=293599&view=diff
==
--- libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp 
(original)
+++ libcxx/trunk/test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp 
Mon Jan 30 21:40:52 2017
@@ -18,6 +18,55 @@
 #include "test_allocator.h"
 #include "min_allocator.h"
 
+template 
+struct alloc_imp {
+bool active;
+
+alloc_imp() : active(true) {}
+
+T* allocate(std::size_t n)
+{
+if (active)
+return static_cast(std::malloc(n * sizeof(T)));
+else
+throw std::bad_alloc();
+}
+
+void deallocate(T* p, std::size_t) { std::free(p); }
+void activate  ()  { active = true; }
+void deactivate()  { active = false; }
+};
+
+template 
+struct poca_alloc {
+typedef T value_type;
+typedef std::true_type propagate_on_container_copy_assignment;
+
+alloc_imp *imp;
+
+poca_alloc(alloc_imp *imp) : imp (imp) {}
+
+template 
+poca_alloc(const poca_alloc& other) : imp(other.imp) {}
+
+T*   allocate  (std::size_t n)   { return imp->allocate(n);}
+void deallocate(T* p, std::size_t n) { imp->deallocate(p, n); }
+};
+
+template 
+bool operator==(const poca_alloc& lhs, const poca_alloc& rhs)
+{
+return lhs.imp == rhs.imp;
+}
+
+template 
+bool operator!=(const poca_alloc& lhs, const poca_alloc& rhs)
+{
+return lhs.imp != rhs.imp;
+}
+
+
+
 template 
 void
 test(S s1, const typename S::allocator_type& a)
@@ -29,6 +78,16 @@ test(S s1, const typename S::allocator_t
 assert(s2.get_allocator() == a);
 }
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
+template 
+void test_assign(S &s1, const S& s2)
+{
+   try { s1 = s2; }
+   catch ( std::bad_alloc &) { return; }
+   assert(false);
+}
+#endif
+
 int main()
 {
 {
@@ -46,5 +105,27 @@ int main()
 test(S("1"), A());
 
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
 A());
 }
+
+#ifndef TEST_HAS_NO_EXCEPTIONS
+{
+typedef poca_alloc A;
+typedef std::basic_string, A> S;
+   const char * p1 = "This is my first string";
+   const char * p2 = "This is my second string";
+   
+alloc_imp imp1;
+alloc_imp imp2;
+   S s1(p1, A(&imp1));
+   S s2(p2, A(&imp2));
+   
+   assert(s1 == p1);
+   assert(s2 == p2);
+   
+   imp2.deactivate();
+   test_assign(s1, s2);
+   assert(s1 == p1);
+   assert(s2 == p2);
+}
+#endif
 #endif
 }


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


r293600 - AMDGPU: Add builtin for fmed3 intrinsic

2017-01-30 Thread Matt Arsenault via cfe-commits
Author: arsenm
Date: Mon Jan 30 21:42:07 2017
New Revision: 293600

URL: http://llvm.org/viewvc/llvm-project?rev=293600&view=rev
Log:
AMDGPU: Add builtin for fmed3 intrinsic

Modified:
cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl

Modified: cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def?rev=293600&r1=293599&r2=293600&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def Mon Jan 30 21:42:07 2017
@@ -81,6 +81,7 @@ BUILTIN(__builtin_amdgcn_sicmpl, "LUiLiL
 BUILTIN(__builtin_amdgcn_fcmp, "LUiddIi", "nc")
 BUILTIN(__builtin_amdgcn_fcmpf, "LUiffIi", "nc")
 BUILTIN(__builtin_amdgcn_ds_swizzle, "iiIi", "nc")
+BUILTIN(__builtin_amdgcn_fmed3f, "", "nc")
 
 
//===--===//
 // VI+ only builtins.

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=293600&r1=293599&r2=293600&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Jan 30 21:42:07 2017
@@ -8397,7 +8397,8 @@ Value *CodeGenFunction::EmitAMDGPUBuilti
   case AMDGPU::BI__builtin_amdgcn_classf:
   case AMDGPU::BI__builtin_amdgcn_classh:
 return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_class);
-
+  case AMDGPU::BI__builtin_amdgcn_fmed3f:
+return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_fmed3);
   case AMDGPU::BI__builtin_amdgcn_read_exec: {
 CallInst *CI = cast(
   EmitSpecialRegisterBuiltin(*this, E, Int64Ty, Int64Ty, true, "exec"));

Modified: cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl?rev=293600&r1=293599&r2=293600&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl Mon Jan 30 21:42:07 2017
@@ -396,6 +396,13 @@ void test_get_local_id(int d, global int
}
 }
 
+// CHECK-LABEL: @test_fmed3_f32
+// CHECK: call float @llvm.amdgcn.fmed3.f32(
+void test_fmed3_f32(global float* out, float a, float b, float c)
+{
+  *out = __builtin_amdgcn_fmed3f(a, b, c);
+}
+
 // CHECK-DAG: [[WI_RANGE]] = !{i32 0, i32 1024}
 // CHECK-DAG: attributes #[[NOUNWIND_READONLY:[0-9]+]] = { nounwind readonly }
 // CHECK-DAG: attributes #[[READ_EXEC_ATTRS]] = { convergent }


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


[PATCH] D28001: [X86] Teach Clang about -mfentry flag

2017-01-30 Thread Dean Michael Berris via Phabricator via cfe-commits
dberris accepted this revision.
dberris added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D28001



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


r293604 - In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Mon Jan 30 23:23:20 2017
New Revision: 293604

URL: http://llvm.org/viewvc/llvm-project?rev=293604&view=rev
Log:
In VirtualCallChecker, handle indirect calls

Summary:
In VirtualCallChecker, handle indirect calls.

getDirectCallee() can be nullptr, and dyn_cast(nullptr) is UB

Reviewers: bkramer

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
cfe/trunk/test/Analysis/virtualcall.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp?rev=293604&r1=293603&r2=293604&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp Mon Jan 30 
23:23:20 2017
@@ -179,7 +179,8 @@ void WalkAST::VisitCXXMemberCallExpr(Cal
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() 
&&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());

Modified: cfe/trunk/test/Analysis/virtualcall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/virtualcall.cpp?rev=293604&r1=293603&r2=293604&view=diff
==
--- cfe/trunk/test/Analysis/virtualcall.cpp (original)
+++ cfe/trunk/test/Analysis/virtualcall.cpp Mon Jan 30 23:23:20 2017
@@ -115,12 +115,23 @@ public:
   int foo() override;
 };
 
+// Regression test: don't crash when there's no direct callee.
+class F {
+public:
+  F() {
+void (F::* ptr)() = &F::foo;
+(this->*ptr)();
+  }
+  void foo();
+};
+
 int main() {
   A *a;
   B *b;
   C *c;
   D *d;
   E *e;
+  F *f;
 }
 
 #include "virtualcall.h"


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


[PATCH] D29303: In VirtualCallChecker, handle indirect calls

2017-01-30 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293604: In VirtualCallChecker, handle indirect calls 
(authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D29303?vs=86342&id=86385#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29303

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  cfe/trunk/test/Analysis/virtualcall.cpp


Index: cfe/trunk/test/Analysis/virtualcall.cpp
===
--- cfe/trunk/test/Analysis/virtualcall.cpp
+++ cfe/trunk/test/Analysis/virtualcall.cpp
@@ -115,12 +115,23 @@
   int foo() override;
 };
 
+// Regression test: don't crash when there's no direct callee.
+class F {
+public:
+  F() {
+void (F::* ptr)() = &F::foo;
+(this->*ptr)();
+  }
+  void foo();
+};
+
 int main() {
   A *a;
   B *b;
   C *c;
   D *d;
   E *e;
+  F *f;
 }
 
 #include "virtualcall.h"
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -179,7 +179,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() 
&&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());


Index: cfe/trunk/test/Analysis/virtualcall.cpp
===
--- cfe/trunk/test/Analysis/virtualcall.cpp
+++ cfe/trunk/test/Analysis/virtualcall.cpp
@@ -115,12 +115,23 @@
   int foo() override;
 };
 
+// Regression test: don't crash when there's no direct callee.
+class F {
+public:
+  F() {
+void (F::* ptr)() = &F::foo;
+(this->*ptr)();
+  }
+  void foo();
+};
+
 int main() {
   A *a;
   B *b;
   C *c;
   D *d;
   E *e;
+  F *f;
 }
 
 #include "virtualcall.h"
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
@@ -179,7 +179,8 @@
   }
 
   // Get the callee.
-  const CXXMethodDecl *MD = dyn_cast(CE->getDirectCallee());
+  const CXXMethodDecl *MD =
+  dyn_cast_or_null(CE->getDirectCallee());
   if (MD && MD->isVirtual() && !callIsNonVirtual && !MD->hasAttr() &&
   !MD->getParent()->hasAttr())
 ReportVirtualCall(CE, MD->isPure());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D29077: [lsan] Enable LSan for x86 Linux.

2017-01-30 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL293609: [lsan] Enable LSan for x86 Linux (authored by 
chefmax).

Changed prior to commit:
  https://reviews.llvm.org/D29077?vs=85756&id=86387#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29077

Files:
  cfe/trunk/lib/Driver/ToolChains.cpp
  cfe/trunk/test/Driver/fsanitize.c


Index: cfe/trunk/test/Driver/fsanitize.c
===
--- cfe/trunk/test/Driver/fsanitize.c
+++ cfe/trunk/test/Driver/fsanitize.c
@@ -231,6 +231,12 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address,leak 
-fno-sanitize=address %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANA-SANL-NO-SANA
 // CHECK-SANA-SANL-NO-SANA: "-fsanitize=leak"
 
+// RUN: %clang -target i686-linux-gnu -fsanitize=leak %s -### 2>&1 | FileCheck 
%s --check-prefix=CHECK-SANL-X86
+// CHECK-SANL-X86: "-fsanitize=leak"
+
+// RUN: %clang -target i686-linux-gnu -fsanitize=address,leak 
-fno-sanitize=address %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANA-SANL-NO-SANA-X86
+// CHECK-SANA-SANL-NO-SANA-X86: "-fsanitize=leak"
+
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-MSAN
 // CHECK-MSAN: "-fno-assume-sane-operator-new"
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ASAN
Index: cfe/trunk/lib/Driver/ToolChains.cpp
===
--- cfe/trunk/lib/Driver/ToolChains.cpp
+++ cfe/trunk/lib/Driver/ToolChains.cpp
@@ -4728,7 +4728,7 @@
   Res |= SanitizerKind::SafeStack;
   if (IsX86_64 || IsMIPS64 || IsAArch64)
 Res |= SanitizerKind::DataFlow;
-  if (IsX86_64 || IsMIPS64 || IsAArch64)
+  if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86)
 Res |= SanitizerKind::Leak;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64)
 Res |= SanitizerKind::Thread;


Index: cfe/trunk/test/Driver/fsanitize.c
===
--- cfe/trunk/test/Driver/fsanitize.c
+++ cfe/trunk/test/Driver/fsanitize.c
@@ -231,6 +231,12 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address,leak -fno-sanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANA-SANL-NO-SANA
 // CHECK-SANA-SANL-NO-SANA: "-fsanitize=leak"
 
+// RUN: %clang -target i686-linux-gnu -fsanitize=leak %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANL-X86
+// CHECK-SANL-X86: "-fsanitize=leak"
+
+// RUN: %clang -target i686-linux-gnu -fsanitize=address,leak -fno-sanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANA-SANL-NO-SANA-X86
+// CHECK-SANA-SANL-NO-SANA-X86: "-fsanitize=leak"
+
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN
 // CHECK-MSAN: "-fno-assume-sane-operator-new"
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN
Index: cfe/trunk/lib/Driver/ToolChains.cpp
===
--- cfe/trunk/lib/Driver/ToolChains.cpp
+++ cfe/trunk/lib/Driver/ToolChains.cpp
@@ -4728,7 +4728,7 @@
   Res |= SanitizerKind::SafeStack;
   if (IsX86_64 || IsMIPS64 || IsAArch64)
 Res |= SanitizerKind::DataFlow;
-  if (IsX86_64 || IsMIPS64 || IsAArch64)
+  if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86)
 Res |= SanitizerKind::Leak;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64)
 Res |= SanitizerKind::Thread;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26546: [PPC] Add vec_insert4b/vec_extract4b to altivec.h

2017-01-30 Thread Eric Christopher via Phabricator via cfe-commits
echristo closed this revision.
echristo added a comment.

This was committed:

commit d65cd1f9424369c4ae7f945fac7fd9e4357451b2
Author: Sean Fertile 
Date:   Thu Jan 5 21:43:30 2017 +

  Add vec_insert4b and vec_extract4b functions to altivec.h
  
  Add builtins for the functions and custom codegen mapping the builtins to 
their
  corresponding intrinsics and handling the endian related swapping.
  
  https://reviews.llvm.org/D26546
  
  git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291179 
91177308-0d34-0410-b5e6-96231b3b80d8


Repository:
  rL LLVM

https://reviews.llvm.org/D26546



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