Re: r360974 - Refactor constant evaluation of typeid(T) to track a symbolic type_info

2019-05-16 Thread Kristina Brooks via cfe-commits
It seems to have been causing asserts to trip on 64-bit hosts while running
tests (ppc64be, ppc64le and x86_64 were all affected), ie:

http://lab.llvm.org:8011/builders/clang-cmake-x86_64-avx2-linux/builds/9528/steps/test-suite/logs/test.log


On Fri, May 17, 2019 at 6:51 AM via cfe-commits 
wrote:

> I'm not sure that is problem. Our internal linux build bot also hit the
> same problem and it has a 64-bit CPU.
>
> Douglas Yung
>
> -Original Message-
> From: cfe-commits  On Behalf Of Chris
> Bieneman via cfe-commits
> Sent: Thursday, May 16, 2019 22:45
> To: Chris Bieneman 
> Cc: Richard Smith ; cfe-commits@lists.llvm.org
> Subject: Re: r360974 - Refactor constant evaluation of typeid(T) to track
> a symbolic type_info
>
> I did some digging before reverting. The bots your patch is failing on are
> 32-bit CPUs. It looks like your static_assert is assuming 8-byte aligned
> pointers, so it always fails on the 32-bit builders.
>
> -Chris
>
> > On May 16, 2019, at 10:14 PM, Chris Bieneman 
> wrote:
> >
> > Sorry to do this, but I'm also reverting r360977, because it seems to be
> on top of this one.
> >
> > -Chris
> >
> >> On May 16, 2019, at 9:58 PM, Chris Bieneman via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >>
> >> Hey Richard,
> >>
> >> This change is tripping up a bunch of the bots:
> >>
> >> http://lab.llvm.org:8011/builders/clang-cmake-armv8-lld/builds/1397
> >>
> >> I'm going to revert it so that we don't leave the bots broken overnight.
> >>
> >> -Chris
> >>
> >>> On May 16, 2019, at 6:46 PM, Richard Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >>>
> >>> Author: rsmith
> >>> Date: Thu May 16 18:46:05 2019
> >>> New Revision: 360974
> >>>
> >>> URL: http://llvm.org/viewvc/llvm-project?rev=360974=rev
> >>> Log:
> >>> Refactor constant evaluation of typeid(T) to track a symbolic
> >>> type_info object rather than tracking the originating expression.
> >>>
> >>> This is groundwork for supporting polymorphic typeid expressions.
> >>> (Note that this somewhat regresses our support for DR1968, but it
> >>> turns out that that never actually worked anyway, at least in
> >>> non-trivial cases.)
> >>>
> >>> Modified:
> >>>  cfe/trunk/include/clang/AST/APValue.h
> >>>  cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
> >>>  cfe/trunk/lib/AST/APValue.cpp
> >>>  cfe/trunk/lib/AST/ExprConstant.cpp
> >>>  cfe/trunk/lib/CodeGen/CGExprConstant.cpp
> >>>  cfe/trunk/lib/Sema/SemaTemplate.cpp
> >>>  cfe/trunk/test/CXX/drs/dr19xx.cpp
> >>>  cfe/trunk/test/Parser/MicrosoftExtensions.cpp
> >>>  cfe/trunk/test/SemaCXX/builtin-constant-p.cpp
> >>>  cfe/trunk/test/SemaCXX/typeid.cpp
> >>>  cfe/trunk/www/cxx_dr_status.html
> >>>
> >>> Modified: cfe/trunk/include/clang/AST/APValue.h
> >>> URL:
> >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APVa
> >>> lue.h?rev=360974=360973=360974=diff
> >>> 
> >>> ==
> >>> --- cfe/trunk/include/clang/AST/APValue.h (original)
> >>> +++ cfe/trunk/include/clang/AST/APValue.h Thu May 16 18:46:05 2019
> >>> @@ -24,14 +24,52 @@ namespace clang { class AddrLabelExpr; class
> >>> ASTContext; class CharUnits;
> >>> +  class CXXRecordDecl;
> >>> +  class Decl;
> >>> class DiagnosticBuilder;
> >>> class Expr;
> >>> class FieldDecl;
> >>> -  class Decl;
> >>> +  struct PrintingPolicy;
> >>> +  class Type;
> >>> class ValueDecl;
> >>> -  class CXXRecordDecl;
> >>> -  class QualType;
> >>>
> >>> +/// Symbolic representation of typeid(T) for some type T.
> >>> +class TypeInfoLValue {
> >>> +  const Type *T;
> >>> +
> >>> +public:
> >>> +  TypeInfoLValue() : T() {}
> >>> +  explicit TypeInfoLValue(const Type *T);
> >>> +
> >>> +  const Type *getType() const { return T; }  explicit operator
> >>> + bool() const { return T; }
> >>> +
> >>> +  void *getOpaqueValue() { return const_cast(T); }  static
> >>> + TypeInfoLValue getFromOpaqueValue(void *Value) {
> >>> +TypeInfoLValue V;
> >>> +V.T = reinterpret_cast(Value);
> >>> +return V;
> >>> +  }
> >>> +
> >>> +  void print(llvm::raw_ostream , const PrintingPolicy )
> >>> +const; }; }
> >>> +
> >>> +namespace llvm {
> >>> +template<> struct PointerLikeTypeTraits {
> >>> +  static void *getAsVoidPointer(clang::TypeInfoLValue V) {
> >>> +return V.getOpaqueValue();
> >>> +  }
> >>> +  static clang::TypeInfoLValue getFromVoidPointer(void *P) {
> >>> +return clang::TypeInfoLValue::getFromOpaqueValue(P);
> >>> +  }
> >>> +  // Validated by static_assert in APValue.cpp; hardcoded to avoid
> >>> +needing
> >>> +  // to include Type.h.
> >>> +  static constexpr int NumLowBitsAvailable = 3; }; }
> >>> +
> >>> +namespace clang {
> >>> /// APValue - This class implements a discriminated union of
> >>> [uninitialized] /// [APSInt] [APFloat], [Complex APSInt] [Complex
> >>> APFloat], [Expr + Offset], /// [Vector: N * APValue], [Array: N *
> >>> APValue] @@ -57,13 +95,18 @@ public:
> >>>
> >>> class LValueBase {
> >>> 

Re: r360974 - Refactor constant evaluation of typeid(T) to track a symbolic type_info

2019-05-16 Thread Richard Smith via cfe-commits
I'm looking into this; feel free to revert, or I will if I don't find
what's up shortly. Sorry for the problems!

On Thu, 16 May 2019 at 22:51, via cfe-commits
 wrote:
>
> I'm not sure that is problem. Our internal linux build bot also hit the same 
> problem and it has a 64-bit CPU.
>
> Douglas Yung
>
> -Original Message-
> From: cfe-commits  On Behalf Of Chris 
> Bieneman via cfe-commits
> Sent: Thursday, May 16, 2019 22:45
> To: Chris Bieneman 
> Cc: Richard Smith ; cfe-commits@lists.llvm.org
> Subject: Re: r360974 - Refactor constant evaluation of typeid(T) to track a 
> symbolic type_info
>
> I did some digging before reverting. The bots your patch is failing on are 
> 32-bit CPUs. It looks like your static_assert is assuming 8-byte aligned 
> pointers, so it always fails on the 32-bit builders.
>
> -Chris
>
> > On May 16, 2019, at 10:14 PM, Chris Bieneman  wrote:
> >
> > Sorry to do this, but I'm also reverting r360977, because it seems to be on 
> > top of this one.
> >
> > -Chris
> >
> >> On May 16, 2019, at 9:58 PM, Chris Bieneman via cfe-commits 
> >>  wrote:
> >>
> >> Hey Richard,
> >>
> >> This change is tripping up a bunch of the bots:
> >>
> >> http://lab.llvm.org:8011/builders/clang-cmake-armv8-lld/builds/1397
> >>
> >> I'm going to revert it so that we don't leave the bots broken overnight.
> >>
> >> -Chris
> >>
> >>> On May 16, 2019, at 6:46 PM, Richard Smith via cfe-commits 
> >>>  wrote:
> >>>
> >>> Author: rsmith
> >>> Date: Thu May 16 18:46:05 2019
> >>> New Revision: 360974
> >>>
> >>> URL: http://llvm.org/viewvc/llvm-project?rev=360974=rev
> >>> Log:
> >>> Refactor constant evaluation of typeid(T) to track a symbolic
> >>> type_info object rather than tracking the originating expression.
> >>>
> >>> This is groundwork for supporting polymorphic typeid expressions.
> >>> (Note that this somewhat regresses our support for DR1968, but it
> >>> turns out that that never actually worked anyway, at least in
> >>> non-trivial cases.)
> >>>
> >>> Modified:
> >>>  cfe/trunk/include/clang/AST/APValue.h
> >>>  cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
> >>>  cfe/trunk/lib/AST/APValue.cpp
> >>>  cfe/trunk/lib/AST/ExprConstant.cpp
> >>>  cfe/trunk/lib/CodeGen/CGExprConstant.cpp
> >>>  cfe/trunk/lib/Sema/SemaTemplate.cpp
> >>>  cfe/trunk/test/CXX/drs/dr19xx.cpp
> >>>  cfe/trunk/test/Parser/MicrosoftExtensions.cpp
> >>>  cfe/trunk/test/SemaCXX/builtin-constant-p.cpp
> >>>  cfe/trunk/test/SemaCXX/typeid.cpp
> >>>  cfe/trunk/www/cxx_dr_status.html
> >>>
> >>> Modified: cfe/trunk/include/clang/AST/APValue.h
> >>> URL:
> >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APVa
> >>> lue.h?rev=360974=360973=360974=diff
> >>> 
> >>> ==
> >>> --- cfe/trunk/include/clang/AST/APValue.h (original)
> >>> +++ cfe/trunk/include/clang/AST/APValue.h Thu May 16 18:46:05 2019
> >>> @@ -24,14 +24,52 @@ namespace clang { class AddrLabelExpr; class
> >>> ASTContext; class CharUnits;
> >>> +  class CXXRecordDecl;
> >>> +  class Decl;
> >>> class DiagnosticBuilder;
> >>> class Expr;
> >>> class FieldDecl;
> >>> -  class Decl;
> >>> +  struct PrintingPolicy;
> >>> +  class Type;
> >>> class ValueDecl;
> >>> -  class CXXRecordDecl;
> >>> -  class QualType;
> >>>
> >>> +/// Symbolic representation of typeid(T) for some type T.
> >>> +class TypeInfoLValue {
> >>> +  const Type *T;
> >>> +
> >>> +public:
> >>> +  TypeInfoLValue() : T() {}
> >>> +  explicit TypeInfoLValue(const Type *T);
> >>> +
> >>> +  const Type *getType() const { return T; }  explicit operator
> >>> + bool() const { return T; }
> >>> +
> >>> +  void *getOpaqueValue() { return const_cast(T); }  static
> >>> + TypeInfoLValue getFromOpaqueValue(void *Value) {
> >>> +TypeInfoLValue V;
> >>> +V.T = reinterpret_cast(Value);
> >>> +return V;
> >>> +  }
> >>> +
> >>> +  void print(llvm::raw_ostream , const PrintingPolicy )
> >>> +const; }; }
> >>> +
> >>> +namespace llvm {
> >>> +template<> struct PointerLikeTypeTraits {
> >>> +  static void *getAsVoidPointer(clang::TypeInfoLValue V) {
> >>> +return V.getOpaqueValue();
> >>> +  }
> >>> +  static clang::TypeInfoLValue getFromVoidPointer(void *P) {
> >>> +return clang::TypeInfoLValue::getFromOpaqueValue(P);
> >>> +  }
> >>> +  // Validated by static_assert in APValue.cpp; hardcoded to avoid
> >>> +needing
> >>> +  // to include Type.h.
> >>> +  static constexpr int NumLowBitsAvailable = 3; }; }
> >>> +
> >>> +namespace clang {
> >>> /// APValue - This class implements a discriminated union of
> >>> [uninitialized] /// [APSInt] [APFloat], [Complex APSInt] [Complex
> >>> APFloat], [Expr + Offset], /// [Vector: N * APValue], [Array: N *
> >>> APValue] @@ -57,13 +95,18 @@ public:
> >>>
> >>> class LValueBase {
> >>> public:
> >>> -typedef llvm::PointerUnion PtrTy;
> >>> +typedef llvm::PointerUnion >>> TypeInfoLValue>
> >>> +PtrTy;
> >>>
> >>> -LValueBase() : 

RE: r360974 - Refactor constant evaluation of typeid(T) to track a symbolic type_info

2019-05-16 Thread via cfe-commits
I'm not sure that is problem. Our internal linux build bot also hit the same 
problem and it has a 64-bit CPU.

Douglas Yung

-Original Message-
From: cfe-commits  On Behalf Of Chris 
Bieneman via cfe-commits
Sent: Thursday, May 16, 2019 22:45
To: Chris Bieneman 
Cc: Richard Smith ; cfe-commits@lists.llvm.org
Subject: Re: r360974 - Refactor constant evaluation of typeid(T) to track a 
symbolic type_info

I did some digging before reverting. The bots your patch is failing on are 
32-bit CPUs. It looks like your static_assert is assuming 8-byte aligned 
pointers, so it always fails on the 32-bit builders.

-Chris

> On May 16, 2019, at 10:14 PM, Chris Bieneman  wrote:
> 
> Sorry to do this, but I'm also reverting r360977, because it seems to be on 
> top of this one.
> 
> -Chris
> 
>> On May 16, 2019, at 9:58 PM, Chris Bieneman via cfe-commits 
>>  wrote:
>> 
>> Hey Richard,
>> 
>> This change is tripping up a bunch of the bots:
>> 
>> http://lab.llvm.org:8011/builders/clang-cmake-armv8-lld/builds/1397
>> 
>> I'm going to revert it so that we don't leave the bots broken overnight.
>> 
>> -Chris
>> 
>>> On May 16, 2019, at 6:46 PM, Richard Smith via cfe-commits 
>>>  wrote:
>>> 
>>> Author: rsmith
>>> Date: Thu May 16 18:46:05 2019
>>> New Revision: 360974
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=360974=rev
>>> Log:
>>> Refactor constant evaluation of typeid(T) to track a symbolic 
>>> type_info object rather than tracking the originating expression.
>>> 
>>> This is groundwork for supporting polymorphic typeid expressions. 
>>> (Note that this somewhat regresses our support for DR1968, but it 
>>> turns out that that never actually worked anyway, at least in 
>>> non-trivial cases.)
>>> 
>>> Modified:
>>>  cfe/trunk/include/clang/AST/APValue.h
>>>  cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
>>>  cfe/trunk/lib/AST/APValue.cpp
>>>  cfe/trunk/lib/AST/ExprConstant.cpp
>>>  cfe/trunk/lib/CodeGen/CGExprConstant.cpp
>>>  cfe/trunk/lib/Sema/SemaTemplate.cpp
>>>  cfe/trunk/test/CXX/drs/dr19xx.cpp
>>>  cfe/trunk/test/Parser/MicrosoftExtensions.cpp
>>>  cfe/trunk/test/SemaCXX/builtin-constant-p.cpp
>>>  cfe/trunk/test/SemaCXX/typeid.cpp
>>>  cfe/trunk/www/cxx_dr_status.html
>>> 
>>> Modified: cfe/trunk/include/clang/AST/APValue.h
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APVa
>>> lue.h?rev=360974=360973=360974=diff
>>> 
>>> ==
>>> --- cfe/trunk/include/clang/AST/APValue.h (original)
>>> +++ cfe/trunk/include/clang/AST/APValue.h Thu May 16 18:46:05 2019
>>> @@ -24,14 +24,52 @@ namespace clang { class AddrLabelExpr; class 
>>> ASTContext; class CharUnits;
>>> +  class CXXRecordDecl;
>>> +  class Decl;
>>> class DiagnosticBuilder;
>>> class Expr;
>>> class FieldDecl;
>>> -  class Decl;
>>> +  struct PrintingPolicy;
>>> +  class Type;
>>> class ValueDecl;
>>> -  class CXXRecordDecl;
>>> -  class QualType;
>>> 
>>> +/// Symbolic representation of typeid(T) for some type T.
>>> +class TypeInfoLValue {
>>> +  const Type *T;
>>> +
>>> +public:
>>> +  TypeInfoLValue() : T() {}
>>> +  explicit TypeInfoLValue(const Type *T);
>>> +
>>> +  const Type *getType() const { return T; }  explicit operator 
>>> + bool() const { return T; }
>>> +
>>> +  void *getOpaqueValue() { return const_cast(T); }  static 
>>> + TypeInfoLValue getFromOpaqueValue(void *Value) {
>>> +TypeInfoLValue V;
>>> +V.T = reinterpret_cast(Value);
>>> +return V;
>>> +  }
>>> +
>>> +  void print(llvm::raw_ostream , const PrintingPolicy ) 
>>> +const; }; }
>>> +
>>> +namespace llvm {
>>> +template<> struct PointerLikeTypeTraits {
>>> +  static void *getAsVoidPointer(clang::TypeInfoLValue V) {
>>> +return V.getOpaqueValue();
>>> +  }
>>> +  static clang::TypeInfoLValue getFromVoidPointer(void *P) {
>>> +return clang::TypeInfoLValue::getFromOpaqueValue(P);
>>> +  }
>>> +  // Validated by static_assert in APValue.cpp; hardcoded to avoid 
>>> +needing
>>> +  // to include Type.h.
>>> +  static constexpr int NumLowBitsAvailable = 3; }; }
>>> +
>>> +namespace clang {
>>> /// APValue - This class implements a discriminated union of 
>>> [uninitialized] /// [APSInt] [APFloat], [Complex APSInt] [Complex 
>>> APFloat], [Expr + Offset], /// [Vector: N * APValue], [Array: N * 
>>> APValue] @@ -57,13 +95,18 @@ public:
>>> 
>>> class LValueBase {
>>> public:
>>> -typedef llvm::PointerUnion PtrTy;
>>> +typedef llvm::PointerUnion>> TypeInfoLValue>
>>> +PtrTy;
>>> 
>>> -LValueBase() : CallIndex(0), Version(0) {}
>>> +LValueBase() : Local{} {}
>>> 
>>>   template 
>>> -LValueBase(T P, unsigned I = 0, unsigned V = 0)
>>> -: Ptr(P), CallIndex(I), Version(V) {}
>>> +LValueBase(T P, unsigned I = 0, unsigned V = 0) : Ptr(P), Local{I, V} {
>>> +  assert(!is() &&
>>> + "don't use this constructor to form a type_info lvalue");
>>> +}
>>> +
>>> +static LValueBase 

Re: r360974 - Refactor constant evaluation of typeid(T) to track a symbolic type_info

2019-05-16 Thread Chris Bieneman via cfe-commits
I did some digging before reverting. The bots your patch is failing on are 
32-bit CPUs. It looks like your static_assert is assuming 8-byte aligned 
pointers, so it always fails on the 32-bit builders.

-Chris

> On May 16, 2019, at 10:14 PM, Chris Bieneman  wrote:
> 
> Sorry to do this, but I'm also reverting r360977, because it seems to be on 
> top of this one.
> 
> -Chris
> 
>> On May 16, 2019, at 9:58 PM, Chris Bieneman via cfe-commits 
>>  wrote:
>> 
>> Hey Richard,
>> 
>> This change is tripping up a bunch of the bots:
>> 
>> http://lab.llvm.org:8011/builders/clang-cmake-armv8-lld/builds/1397
>> 
>> I'm going to revert it so that we don't leave the bots broken overnight.
>> 
>> -Chris
>> 
>>> On May 16, 2019, at 6:46 PM, Richard Smith via cfe-commits 
>>>  wrote:
>>> 
>>> Author: rsmith
>>> Date: Thu May 16 18:46:05 2019
>>> New Revision: 360974
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=360974=rev
>>> Log:
>>> Refactor constant evaluation of typeid(T) to track a symbolic type_info
>>> object rather than tracking the originating expression.
>>> 
>>> This is groundwork for supporting polymorphic typeid expressions. (Note
>>> that this somewhat regresses our support for DR1968, but it turns out
>>> that that never actually worked anyway, at least in non-trivial cases.)
>>> 
>>> Modified:
>>>  cfe/trunk/include/clang/AST/APValue.h
>>>  cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
>>>  cfe/trunk/lib/AST/APValue.cpp
>>>  cfe/trunk/lib/AST/ExprConstant.cpp
>>>  cfe/trunk/lib/CodeGen/CGExprConstant.cpp
>>>  cfe/trunk/lib/Sema/SemaTemplate.cpp
>>>  cfe/trunk/test/CXX/drs/dr19xx.cpp
>>>  cfe/trunk/test/Parser/MicrosoftExtensions.cpp
>>>  cfe/trunk/test/SemaCXX/builtin-constant-p.cpp
>>>  cfe/trunk/test/SemaCXX/typeid.cpp
>>>  cfe/trunk/www/cxx_dr_status.html
>>> 
>>> Modified: cfe/trunk/include/clang/AST/APValue.h
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=360974=360973=360974=diff
>>> ==
>>> --- cfe/trunk/include/clang/AST/APValue.h (original)
>>> +++ cfe/trunk/include/clang/AST/APValue.h Thu May 16 18:46:05 2019
>>> @@ -24,14 +24,52 @@ namespace clang {
>>> class AddrLabelExpr;
>>> class ASTContext;
>>> class CharUnits;
>>> +  class CXXRecordDecl;
>>> +  class Decl;
>>> class DiagnosticBuilder;
>>> class Expr;
>>> class FieldDecl;
>>> -  class Decl;
>>> +  struct PrintingPolicy;
>>> +  class Type;
>>> class ValueDecl;
>>> -  class CXXRecordDecl;
>>> -  class QualType;
>>> 
>>> +/// Symbolic representation of typeid(T) for some type T.
>>> +class TypeInfoLValue {
>>> +  const Type *T;
>>> +
>>> +public:
>>> +  TypeInfoLValue() : T() {}
>>> +  explicit TypeInfoLValue(const Type *T);
>>> +
>>> +  const Type *getType() const { return T; }
>>> +  explicit operator bool() const { return T; }
>>> +
>>> +  void *getOpaqueValue() { return const_cast(T); }
>>> +  static TypeInfoLValue getFromOpaqueValue(void *Value) {
>>> +TypeInfoLValue V;
>>> +V.T = reinterpret_cast(Value);
>>> +return V;
>>> +  }
>>> +
>>> +  void print(llvm::raw_ostream , const PrintingPolicy ) const;
>>> +};
>>> +}
>>> +
>>> +namespace llvm {
>>> +template<> struct PointerLikeTypeTraits {
>>> +  static void *getAsVoidPointer(clang::TypeInfoLValue V) {
>>> +return V.getOpaqueValue();
>>> +  }
>>> +  static clang::TypeInfoLValue getFromVoidPointer(void *P) {
>>> +return clang::TypeInfoLValue::getFromOpaqueValue(P);
>>> +  }
>>> +  // Validated by static_assert in APValue.cpp; hardcoded to avoid needing
>>> +  // to include Type.h.
>>> +  static constexpr int NumLowBitsAvailable = 3;
>>> +};
>>> +}
>>> +
>>> +namespace clang {
>>> /// APValue - This class implements a discriminated union of [uninitialized]
>>> /// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
>>> /// [Vector: N * APValue], [Array: N * APValue]
>>> @@ -57,13 +95,18 @@ public:
>>> 
>>> class LValueBase {
>>> public:
>>> -typedef llvm::PointerUnion PtrTy;
>>> +typedef llvm::PointerUnion>> TypeInfoLValue>
>>> +PtrTy;
>>> 
>>> -LValueBase() : CallIndex(0), Version(0) {}
>>> +LValueBase() : Local{} {}
>>> 
>>>   template 
>>> -LValueBase(T P, unsigned I = 0, unsigned V = 0)
>>> -: Ptr(P), CallIndex(I), Version(V) {}
>>> +LValueBase(T P, unsigned I = 0, unsigned V = 0) : Ptr(P), Local{I, V} {
>>> +  assert(!is() &&
>>> + "don't use this constructor to form a type_info lvalue");
>>> +}
>>> +
>>> +static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo);
>>> 
>>>   template 
>>>   bool is() const { return Ptr.is(); }
>>> @@ -78,28 +121,15 @@ public:
>>> 
>>>   bool isNull() const;
>>> 
>>> -explicit operator bool () const;
>>> +explicit operator bool() const;
>>> 
>>> -PtrTy getPointer() const {
>>> -  return Ptr;
>>> -}
>>> +PtrTy getPointer() const { return Ptr; }
>>> 
>>> -unsigned getCallIndex() 

r360988 - Revert Refactor constant evaluation of typeid(T) to track a symbolic type_info object rather than tracking the originating expression.

2019-05-16 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Thu May 16 22:46:03 2019
New Revision: 360988

URL: http://llvm.org/viewvc/llvm-project?rev=360988=rev
Log:
Revert Refactor constant evaluation of typeid(T) to track a symbolic type_info 
object rather than tracking the originating expression.

This reverts r360974 (git commit 7ee4307bd4450022c3c8777f43a40cc4f0ccc009)

Modified:
cfe/trunk/include/clang/AST/APValue.h
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/lib/AST/APValue.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/CXX/drs/dr19xx.cpp
cfe/trunk/test/Parser/MicrosoftExtensions.cpp
cfe/trunk/test/SemaCXX/builtin-constant-p.cpp
cfe/trunk/test/SemaCXX/typeid.cpp
cfe/trunk/www/cxx_dr_status.html

Modified: cfe/trunk/include/clang/AST/APValue.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=360988=360987=360988=diff
==
--- cfe/trunk/include/clang/AST/APValue.h (original)
+++ cfe/trunk/include/clang/AST/APValue.h Thu May 16 22:46:03 2019
@@ -24,52 +24,14 @@ namespace clang {
   class AddrLabelExpr;
   class ASTContext;
   class CharUnits;
-  class CXXRecordDecl;
-  class Decl;
   class DiagnosticBuilder;
   class Expr;
   class FieldDecl;
-  struct PrintingPolicy;
-  class Type;
+  class Decl;
   class ValueDecl;
+  class CXXRecordDecl;
+  class QualType;
 
-/// Symbolic representation of typeid(T) for some type T.
-class TypeInfoLValue {
-  const Type *T;
-
-public:
-  TypeInfoLValue() : T() {}
-  explicit TypeInfoLValue(const Type *T);
-
-  const Type *getType() const { return T; }
-  explicit operator bool() const { return T; }
-
-  void *getOpaqueValue() { return const_cast(T); }
-  static TypeInfoLValue getFromOpaqueValue(void *Value) {
-TypeInfoLValue V;
-V.T = reinterpret_cast(Value);
-return V;
-  }
-
-  void print(llvm::raw_ostream , const PrintingPolicy ) const;
-};
-}
-
-namespace llvm {
-template<> struct PointerLikeTypeTraits {
-  static void *getAsVoidPointer(clang::TypeInfoLValue V) {
-return V.getOpaqueValue();
-  }
-  static clang::TypeInfoLValue getFromVoidPointer(void *P) {
-return clang::TypeInfoLValue::getFromOpaqueValue(P);
-  }
-  // Validated by static_assert in APValue.cpp; hardcoded to avoid needing
-  // to include Type.h.
-  static constexpr int NumLowBitsAvailable = 3;
-};
-}
-
-namespace clang {
 /// APValue - This class implements a discriminated union of [uninitialized]
 /// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
 /// [Vector: N * APValue], [Array: N * APValue]
@@ -95,18 +57,13 @@ public:
 
   class LValueBase {
   public:
-typedef llvm::PointerUnion
-PtrTy;
+typedef llvm::PointerUnion PtrTy;
 
-LValueBase() : Local{} {}
+LValueBase() : CallIndex(0), Version(0) {}
 
 template 
-LValueBase(T P, unsigned I = 0, unsigned V = 0) : Ptr(P), Local{I, V} {
-  assert(!is() &&
- "don't use this constructor to form a type_info lvalue");
-}
-
-static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo);
+LValueBase(T P, unsigned I = 0, unsigned V = 0)
+: Ptr(P), CallIndex(I), Version(V) {}
 
 template 
 bool is() const { return Ptr.is(); }
@@ -121,15 +78,28 @@ public:
 
 bool isNull() const;
 
-explicit operator bool() const;
+explicit operator bool () const;
 
-PtrTy getPointer() const { return Ptr; }
+PtrTy getPointer() const {
+  return Ptr;
+}
 
-unsigned getCallIndex() const;
-unsigned getVersion() const;
-QualType getTypeInfoType() const;
+unsigned getCallIndex() const {
+  return CallIndex;
+}
 
-friend bool operator==(const LValueBase , const LValueBase );
+void setCallIndex(unsigned Index) {
+  CallIndex = Index;
+}
+
+unsigned getVersion() const {
+  return Version;
+}
+
+friend bool operator==(const LValueBase , const LValueBase ) {
+  return LHS.Ptr == RHS.Ptr && LHS.CallIndex == RHS.CallIndex &&
+ LHS.Version == RHS.Version;
+}
 friend bool operator!=(const LValueBase , const LValueBase ) {
   return !(LHS == RHS);
 }
@@ -137,14 +107,7 @@ public:
 
   private:
 PtrTy Ptr;
-struct LocalState {
-  unsigned CallIndex, Version;
-};
-union {
-  LocalState Local;
-  /// The type std::type_info, if this is a TypeInfoLValue.
-  void *TypeInfoType;
-};
+unsigned CallIndex, Version;
   };
 
   /// A FieldDecl or CXXRecordDecl, along with a flag indicating whether we

Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=360988=360987=360988=diff
==
--- 

r360987 - Revert [c++20] P1327R1: Support for typeid applied to objects of polymorphic class type in constant evaluation.

2019-05-16 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Thu May 16 22:45:57 2019
New Revision: 360987

URL: http://llvm.org/viewvc/llvm-project?rev=360987=rev
Log:
Revert [c++20] P1327R1: Support for typeid applied to objects of polymorphic 
class type in constant evaluation.

This reverts r360977 (git commit f51dc8d2f98f4029247552bc45ef53628ab3b6b9)

Modified:
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp
cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=360987=360986=360987=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Thu May 16 22:45:57 2019
@@ -12,8 +12,7 @@ let Component = "AST" in {
 def note_expr_divide_by_zero : Note<"division by zero">;
 def note_constexpr_invalid_cast : Note<
   "%select{reinterpret_cast|dynamic_cast|cast that performs the conversions of"
-  " a reinterpret_cast|cast from %1}0 is not allowed in a constant expression"
-  "%select{| in C++ standards before C++2a||}0">;
+  " a reinterpret_cast|cast from %1}0 is not allowed in a constant 
expression">;
 def note_constexpr_invalid_downcast : Note<
   "cannot cast object of dynamic type %0 to type %1">;
 def note_constexpr_overflow : Note<
@@ -32,13 +31,12 @@ def note_constexpr_invalid_inhctor : Not
 def note_constexpr_no_return : Note<
   "control reached end of constexpr function">;
 def note_constexpr_virtual_call : Note<
-  "cannot evaluate call to virtual function in a constant expression "
-  "in C++ standards before C++2a">;
+  "cannot evaluate call to virtual function in a constant expression">;
 def note_constexpr_pure_virtual_call : Note<
   "pure virtual function %q0 called">;
 def note_constexpr_polymorphic_unknown_dynamic_type : Note<
-  "%select{virtual function called on|dynamic_cast applied to|"
-  "typeid applied to}0 object '%1' whose dynamic type is not constant">;
+  "%select{virtual function called on|dynamic_cast applied to}0 "
+  "object '%1' whose dynamic type is not constant">;
 def note_constexpr_dynamic_cast_to_reference_failed : Note<
   "reference dynamic_cast failed: %select{"
   "static type %1 of operand is a non-public base class of dynamic type %2|"
@@ -92,7 +90,7 @@ def note_constexpr_var_init_non_constant
   "initializer of %0 is not a constant expression">;
 def note_constexpr_typeid_polymorphic : Note<
   "typeid applied to expression of polymorphic type %0 is "
-  "not allowed in a constant expression in C++ standards before C++2a">;
+  "not allowed in a constant expression">;
 def note_constexpr_void_comparison : Note<
   "comparison between unequal pointers to void has unspecified result">;
 def note_constexpr_temporary_here : Note<"temporary created here">;
@@ -110,11 +108,11 @@ def note_constexpr_this : Note<
   "evaluation of a call to a 'constexpr' member function">;
 def note_constexpr_lifetime_ended : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of|typeid applied to}0 "
+  "dynamic_cast of}0 "
   "%select{temporary|variable}1 whose lifetime has ended">;
 def note_constexpr_access_uninit : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of|typeid applied to}0 "
+  "dynamic_cast of}0 "
   "object outside its lifetime is not allowed in a constant expression">;
 def note_constexpr_use_uninit_reference : Note<
   "use of reference outside its lifetime "
@@ -141,30 +139,30 @@ def note_constexpr_ltor_incomplete_type
   "read of incomplete type %0 is not allowed in a constant expression">;
 def note_constexpr_access_null : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of|typeid applied to}0 "
+  "dynamic_cast of}0 "
   "dereferenced null pointer is not allowed in a constant expression">;
 def note_constexpr_access_past_end : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of|typeid applied to}0 "
+  "dynamic_cast of}0 "
   "dereferenced one-past-the-end pointer is not allowed in a constant 
expression">;
 def note_constexpr_access_unsized_array : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of|typeid applied to}0 "
+  "dynamic_cast of}0 "
   "element of array without known bound "
   "is not allowed in a constant expression">;
 def note_constexpr_access_inactive_union_member : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of|typeid applied to}0 "
+  "dynamic_cast of}0 "
   "member %1 of union with %select{active member %3|no active member}2 "
   "is not allowed in a constant expression">;
 def 

[PATCH] D62050: [Analysis] Only run plugins tests if plugins are actually enabled

2019-05-16 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

Thank you so much! :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62050



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


Re: r360974 - Refactor constant evaluation of typeid(T) to track a symbolic type_info

2019-05-16 Thread Chris Bieneman via cfe-commits
Sorry to do this, but I'm also reverting r360977, because it seems to be on top 
of this one.

-Chris

> On May 16, 2019, at 9:58 PM, Chris Bieneman via cfe-commits 
>  wrote:
> 
> Hey Richard,
> 
> This change is tripping up a bunch of the bots:
> 
> http://lab.llvm.org:8011/builders/clang-cmake-armv8-lld/builds/1397
> 
> I'm going to revert it so that we don't leave the bots broken overnight.
> 
> -Chris
> 
>> On May 16, 2019, at 6:46 PM, Richard Smith via cfe-commits 
>>  wrote:
>> 
>> Author: rsmith
>> Date: Thu May 16 18:46:05 2019
>> New Revision: 360974
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=360974=rev
>> Log:
>> Refactor constant evaluation of typeid(T) to track a symbolic type_info
>> object rather than tracking the originating expression.
>> 
>> This is groundwork for supporting polymorphic typeid expressions. (Note
>> that this somewhat regresses our support for DR1968, but it turns out
>> that that never actually worked anyway, at least in non-trivial cases.)
>> 
>> Modified:
>>   cfe/trunk/include/clang/AST/APValue.h
>>   cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
>>   cfe/trunk/lib/AST/APValue.cpp
>>   cfe/trunk/lib/AST/ExprConstant.cpp
>>   cfe/trunk/lib/CodeGen/CGExprConstant.cpp
>>   cfe/trunk/lib/Sema/SemaTemplate.cpp
>>   cfe/trunk/test/CXX/drs/dr19xx.cpp
>>   cfe/trunk/test/Parser/MicrosoftExtensions.cpp
>>   cfe/trunk/test/SemaCXX/builtin-constant-p.cpp
>>   cfe/trunk/test/SemaCXX/typeid.cpp
>>   cfe/trunk/www/cxx_dr_status.html
>> 
>> Modified: cfe/trunk/include/clang/AST/APValue.h
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=360974=360973=360974=diff
>> ==
>> --- cfe/trunk/include/clang/AST/APValue.h (original)
>> +++ cfe/trunk/include/clang/AST/APValue.h Thu May 16 18:46:05 2019
>> @@ -24,14 +24,52 @@ namespace clang {
>>  class AddrLabelExpr;
>>  class ASTContext;
>>  class CharUnits;
>> +  class CXXRecordDecl;
>> +  class Decl;
>>  class DiagnosticBuilder;
>>  class Expr;
>>  class FieldDecl;
>> -  class Decl;
>> +  struct PrintingPolicy;
>> +  class Type;
>>  class ValueDecl;
>> -  class CXXRecordDecl;
>> -  class QualType;
>> 
>> +/// Symbolic representation of typeid(T) for some type T.
>> +class TypeInfoLValue {
>> +  const Type *T;
>> +
>> +public:
>> +  TypeInfoLValue() : T() {}
>> +  explicit TypeInfoLValue(const Type *T);
>> +
>> +  const Type *getType() const { return T; }
>> +  explicit operator bool() const { return T; }
>> +
>> +  void *getOpaqueValue() { return const_cast(T); }
>> +  static TypeInfoLValue getFromOpaqueValue(void *Value) {
>> +TypeInfoLValue V;
>> +V.T = reinterpret_cast(Value);
>> +return V;
>> +  }
>> +
>> +  void print(llvm::raw_ostream , const PrintingPolicy ) const;
>> +};
>> +}
>> +
>> +namespace llvm {
>> +template<> struct PointerLikeTypeTraits {
>> +  static void *getAsVoidPointer(clang::TypeInfoLValue V) {
>> +return V.getOpaqueValue();
>> +  }
>> +  static clang::TypeInfoLValue getFromVoidPointer(void *P) {
>> +return clang::TypeInfoLValue::getFromOpaqueValue(P);
>> +  }
>> +  // Validated by static_assert in APValue.cpp; hardcoded to avoid needing
>> +  // to include Type.h.
>> +  static constexpr int NumLowBitsAvailable = 3;
>> +};
>> +}
>> +
>> +namespace clang {
>> /// APValue - This class implements a discriminated union of [uninitialized]
>> /// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
>> /// [Vector: N * APValue], [Array: N * APValue]
>> @@ -57,13 +95,18 @@ public:
>> 
>>  class LValueBase {
>>  public:
>> -typedef llvm::PointerUnion PtrTy;
>> +typedef llvm::PointerUnion> TypeInfoLValue>
>> +PtrTy;
>> 
>> -LValueBase() : CallIndex(0), Version(0) {}
>> +LValueBase() : Local{} {}
>> 
>>template 
>> -LValueBase(T P, unsigned I = 0, unsigned V = 0)
>> -: Ptr(P), CallIndex(I), Version(V) {}
>> +LValueBase(T P, unsigned I = 0, unsigned V = 0) : Ptr(P), Local{I, V} {
>> +  assert(!is() &&
>> + "don't use this constructor to form a type_info lvalue");
>> +}
>> +
>> +static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo);
>> 
>>template 
>>bool is() const { return Ptr.is(); }
>> @@ -78,28 +121,15 @@ public:
>> 
>>bool isNull() const;
>> 
>> -explicit operator bool () const;
>> +explicit operator bool() const;
>> 
>> -PtrTy getPointer() const {
>> -  return Ptr;
>> -}
>> +PtrTy getPointer() const { return Ptr; }
>> 
>> -unsigned getCallIndex() const {
>> -  return CallIndex;
>> -}
>> +unsigned getCallIndex() const;
>> +unsigned getVersion() const;
>> +QualType getTypeInfoType() const;
>> 
>> -void setCallIndex(unsigned Index) {
>> -  CallIndex = Index;
>> -}
>> -
>> -unsigned getVersion() const {
>> -  return Version;
>> -}
>> -
>> -friend bool operator==(const LValueBase , const 

Re: r360974 - Refactor constant evaluation of typeid(T) to track a symbolic type_info

2019-05-16 Thread Chris Bieneman via cfe-commits
Hey Richard,

This change is tripping up a bunch of the bots:

http://lab.llvm.org:8011/builders/clang-cmake-armv8-lld/builds/1397

I'm going to revert it so that we don't leave the bots broken overnight.

-Chris

> On May 16, 2019, at 6:46 PM, Richard Smith via cfe-commits 
>  wrote:
> 
> Author: rsmith
> Date: Thu May 16 18:46:05 2019
> New Revision: 360974
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=360974=rev
> Log:
> Refactor constant evaluation of typeid(T) to track a symbolic type_info
> object rather than tracking the originating expression.
> 
> This is groundwork for supporting polymorphic typeid expressions. (Note
> that this somewhat regresses our support for DR1968, but it turns out
> that that never actually worked anyway, at least in non-trivial cases.)
> 
> Modified:
>cfe/trunk/include/clang/AST/APValue.h
>cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
>cfe/trunk/lib/AST/APValue.cpp
>cfe/trunk/lib/AST/ExprConstant.cpp
>cfe/trunk/lib/CodeGen/CGExprConstant.cpp
>cfe/trunk/lib/Sema/SemaTemplate.cpp
>cfe/trunk/test/CXX/drs/dr19xx.cpp
>cfe/trunk/test/Parser/MicrosoftExtensions.cpp
>cfe/trunk/test/SemaCXX/builtin-constant-p.cpp
>cfe/trunk/test/SemaCXX/typeid.cpp
>cfe/trunk/www/cxx_dr_status.html
> 
> Modified: cfe/trunk/include/clang/AST/APValue.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=360974=360973=360974=diff
> ==
> --- cfe/trunk/include/clang/AST/APValue.h (original)
> +++ cfe/trunk/include/clang/AST/APValue.h Thu May 16 18:46:05 2019
> @@ -24,14 +24,52 @@ namespace clang {
>   class AddrLabelExpr;
>   class ASTContext;
>   class CharUnits;
> +  class CXXRecordDecl;
> +  class Decl;
>   class DiagnosticBuilder;
>   class Expr;
>   class FieldDecl;
> -  class Decl;
> +  struct PrintingPolicy;
> +  class Type;
>   class ValueDecl;
> -  class CXXRecordDecl;
> -  class QualType;
> 
> +/// Symbolic representation of typeid(T) for some type T.
> +class TypeInfoLValue {
> +  const Type *T;
> +
> +public:
> +  TypeInfoLValue() : T() {}
> +  explicit TypeInfoLValue(const Type *T);
> +
> +  const Type *getType() const { return T; }
> +  explicit operator bool() const { return T; }
> +
> +  void *getOpaqueValue() { return const_cast(T); }
> +  static TypeInfoLValue getFromOpaqueValue(void *Value) {
> +TypeInfoLValue V;
> +V.T = reinterpret_cast(Value);
> +return V;
> +  }
> +
> +  void print(llvm::raw_ostream , const PrintingPolicy ) const;
> +};
> +}
> +
> +namespace llvm {
> +template<> struct PointerLikeTypeTraits {
> +  static void *getAsVoidPointer(clang::TypeInfoLValue V) {
> +return V.getOpaqueValue();
> +  }
> +  static clang::TypeInfoLValue getFromVoidPointer(void *P) {
> +return clang::TypeInfoLValue::getFromOpaqueValue(P);
> +  }
> +  // Validated by static_assert in APValue.cpp; hardcoded to avoid needing
> +  // to include Type.h.
> +  static constexpr int NumLowBitsAvailable = 3;
> +};
> +}
> +
> +namespace clang {
> /// APValue - This class implements a discriminated union of [uninitialized]
> /// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
> /// [Vector: N * APValue], [Array: N * APValue]
> @@ -57,13 +95,18 @@ public:
> 
>   class LValueBase {
>   public:
> -typedef llvm::PointerUnion PtrTy;
> +typedef llvm::PointerUnion TypeInfoLValue>
> +PtrTy;
> 
> -LValueBase() : CallIndex(0), Version(0) {}
> +LValueBase() : Local{} {}
> 
> template 
> -LValueBase(T P, unsigned I = 0, unsigned V = 0)
> -: Ptr(P), CallIndex(I), Version(V) {}
> +LValueBase(T P, unsigned I = 0, unsigned V = 0) : Ptr(P), Local{I, V} {
> +  assert(!is() &&
> + "don't use this constructor to form a type_info lvalue");
> +}
> +
> +static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo);
> 
> template 
> bool is() const { return Ptr.is(); }
> @@ -78,28 +121,15 @@ public:
> 
> bool isNull() const;
> 
> -explicit operator bool () const;
> +explicit operator bool() const;
> 
> -PtrTy getPointer() const {
> -  return Ptr;
> -}
> +PtrTy getPointer() const { return Ptr; }
> 
> -unsigned getCallIndex() const {
> -  return CallIndex;
> -}
> +unsigned getCallIndex() const;
> +unsigned getVersion() const;
> +QualType getTypeInfoType() const;
> 
> -void setCallIndex(unsigned Index) {
> -  CallIndex = Index;
> -}
> -
> -unsigned getVersion() const {
> -  return Version;
> -}
> -
> -friend bool operator==(const LValueBase , const LValueBase ) {
> -  return LHS.Ptr == RHS.Ptr && LHS.CallIndex == RHS.CallIndex &&
> - LHS.Version == RHS.Version;
> -}
> +friend bool operator==(const LValueBase , const LValueBase );
> friend bool operator!=(const LValueBase , const LValueBase ) {
>   return !(LHS == RHS);
> }
> @@ 

[PATCH] D62046: [OpenMP][bugfix] Add missing math functions variants for log and abs.

2019-05-16 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: lib/Headers/__clang_cuda_cmath.h:55-56
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ const float abs(const float __x) { return ::fabsf((float)__x); }
+__DEVICE__ const double abs(const double __x) { return ::fabs((double)__x); }
+#endif

efriedma wrote:
> gtbercea wrote:
> > tra wrote:
> > > Where do these functions come from?  
> > > https://en.cppreference.com/w/cpp/numeric/math/fabs does not seem to show 
> > > any `abs` functions with const args.
> > What's happening is that when including the random header file, this header 
> > file uses abs with const arguments:
> > 
> > 
> > ```
> > const double __n = _M_nd(__urng);
> > const double __y = -std::abs(__n) * __param._M_sm - 1;
> > ```
> > 
> > And without there functions here the error I get is:
> > 
> > 
> > ```
> > In file included from test.c:8:
> > In file included from 
> > /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/random:52:
> > /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/bits/random.tcc:1476:27:
> >  error: call to 'abs' is ambiguous
> > const double __y = -std::abs(__n) * __param._M_sm - 1;
> > ^~~~
> > /usr/include/stdlib.h:770:12: note: candidate function
> > extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
> >^
> > /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:166:3:
> >  note: candidate function
> >   abs(long __i) { return __builtin_labs(__i); }
> >   ^
> > /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:174:3:
> >  note: candidate function
> >   abs(long long __x) { return __builtin_llabs (__x); }
> >   ^
> > /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:179:3:
> >  note: candidate function
> >   abs(__int128 __x) { return __x >= 0 ? __x : -__x; }
> >   ^
> > ```
> Overloading ignores the "const"; `float abs(float)` is the same thing.  So 
> probably clearer to declare it without the extra "const" modifiers, and then 
> clean up the redundant definitions.
> 
> That said, I'm not sure how you managed to pick up the declarations from 
> cstdlib, but not cmath. What files are getting included when this fails?
> 
> (Actually, in C++17, both cmath and cstdlib are supposed to declare all the 
> float and integer overloads of abs, but that's only implemented in newer 
> versions of libstdc++.)
> That said, I'm not sure how you managed to pick up the declarations from 
> cstdlib, but not cmath. What files are getting included when this fails?

Until we get support for OpenMP `omp declare variant begin/end` support in 
clang (X), we will only provide the CUDA declarations & definitions for math 
functions, not the host ones. It is one of these problems that arises when the 
single source language needs both, device and host definitions. (In CUDA the 
`__device__` overload is the way out, in OpenMP it will be `variant` with an 
appropriate device context.)

(X) I'm right now working on integrating this into OpenMP 5.1 but we can 
implement it as soon as the design is decided on.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62046



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


r360985 - Re-land: Add Clang shared library with C++ exports

2019-05-16 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Thu May 16 21:20:01 2019
New Revision: 360985

URL: http://llvm.org/viewvc/llvm-project?rev=360985=rev
Log:
Re-land: Add Clang shared library with C++ exports

Summary:
This patch adds a libClang_shared library on *nix systems which exports the 
entire C++ API. In order to support this on Windows we should really refactor 
llvm-shlib and share code between the two.

This also uses a slightly different method for generating the shared library, 
which I should back-port to llvm-shlib. Instead of linking the static archives 
and passing linker flags to force loading the whole libraries, this patch 
creates object libraries for every library (which has no cost in the build 
system), and link the object libraries.

Added:
cfe/trunk/tools/clang-shlib/
cfe/trunk/tools/clang-shlib/CMakeLists.txt
cfe/trunk/tools/clang-shlib/clang-shlib.cpp
Modified:
cfe/trunk/cmake/modules/AddClang.cmake
cfe/trunk/tools/CMakeLists.txt

Modified: cfe/trunk/cmake/modules/AddClang.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=360985=360984=360985=diff
==
--- cfe/trunk/cmake/modules/AddClang.cmake (original)
+++ cfe/trunk/cmake/modules/AddClang.cmake Thu May 16 21:20:01 2019
@@ -81,9 +81,12 @@ macro(add_clang_library name)
   )
   endif()
   if(ARG_SHARED)
-set(ARG_ENABLE_SHARED SHARED)
+set(LIBTYPE SHARED)
+  else()
+set(LIBTYPE STATIC OBJECT)
+set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
   endif()
-  llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} 
${srcs})
+  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
 
   if(TARGET ${name})
 target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})

Modified: cfe/trunk/tools/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=360985=360984=360985=diff
==
--- cfe/trunk/tools/CMakeLists.txt (original)
+++ cfe/trunk/tools/CMakeLists.txt Thu May 16 21:20:01 2019
@@ -13,6 +13,9 @@ add_clang_subdirectory(c-index-test)
 
 add_clang_subdirectory(clang-rename)
 add_clang_subdirectory(clang-refactor)
+if(UNIX)
+  add_clang_subdirectory(clang-shlib)
+endif()
 
 if(CLANG_ENABLE_ARCMT)
   add_clang_subdirectory(arcmt-test)

Added: cfe/trunk/tools/clang-shlib/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/CMakeLists.txt?rev=360985=auto
==
--- cfe/trunk/tools/clang-shlib/CMakeLists.txt (added)
+++ cfe/trunk/tools/clang-shlib/CMakeLists.txt Thu May 16 21:20:01 2019
@@ -0,0 +1,18 @@
+# Building libclang_shared.so fails if LLVM_ENABLE_PIC=Off
+if (NOT LLVM_ENABLE_PIC)
+  return()
+endif()
+
+get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)
+
+foreach (lib ${clang_libs})
+  list(APPEND _OBJECTS $)
+  list(APPEND _DEPS $)
+endforeach ()
+
+add_clang_library(clang_shared
+  SHARED
+  clang-shlib.cpp
+  ${_OBJECTS}
+  LINK_LIBS
+  ${_DEPS})

Added: cfe/trunk/tools/clang-shlib/clang-shlib.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/clang-shlib.cpp?rev=360985=auto
==
--- cfe/trunk/tools/clang-shlib/clang-shlib.cpp (added)
+++ cfe/trunk/tools/clang-shlib/clang-shlib.cpp Thu May 16 21:20:01 2019
@@ -0,0 +1 @@
+// Intentionally empty source file to make CMake happy


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


[PATCH] D60274: [ELF] Implement Dependent Libraries Feature

2019-05-16 Thread ben via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD360984: [ELF] Implement Dependent Libraries Feature 
(authored by bd1976llvm, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60274?vs=195495=199972#toc

Repository:
  rLLD LLVM Linker

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

https://reviews.llvm.org/D60274

Files:
  ELF/Config.h
  ELF/Driver.cpp
  ELF/Driver.h
  ELF/DriverUtils.cpp
  ELF/InputFiles.cpp
  ELF/Options.td
  test/ELF/Inputs/deplibs-lib_bar.s
  test/ELF/Inputs/deplibs-lib_foo.s
  test/ELF/deplibs-colon-prefix.s
  test/ELF/deplibs-corrupt.s
  test/ELF/deplibs.s
  test/ELF/lto/deplibs.s

Index: ELF/Config.h
===
--- ELF/Config.h
+++ ELF/Config.h
@@ -137,6 +137,7 @@
   bool Cref;
   bool DefineCommon;
   bool Demangle = true;
+  bool DependentLibraries;
   bool DisableVerify;
   bool EhFrameHdr;
   bool EmitLLVM;
Index: ELF/Driver.cpp
===
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -790,6 +790,7 @@
   Config->DefineCommon = Args.hasFlag(OPT_define_common, OPT_no_define_common,
   !Args.hasArg(OPT_relocatable));
   Config->Demangle = Args.hasFlag(OPT_demangle, OPT_no_demangle, true);
+  Config->DependentLibraries = Args.hasFlag(OPT_dependent_libraries, OPT_no_dependent_libraries, true);
   Config->DisableVerify = Args.hasArg(OPT_disable_verify);
   Config->Discard = getDiscard(Args);
   Config->DwoDir = Args.getLastArgValue(OPT_plugin_opt_dwo_dir_eq);
@@ -1548,9 +1549,11 @@
 Symtab->trace(Arg->getValue());
 
   // Add all files to the symbol table. This will add almost all
-  // symbols that we need to the symbol table.
-  for (InputFile *F : Files)
-parseFile(F);
+  // symbols that we need to the symbol table. This process might
+  // add files to the link, via autolinking, these files are always
+  // appended to the Files vector.
+  for (size_t I = 0; I < Files.size(); ++I)
+parseFile(Files[I]);
 
   // Now that we have every file, we can decide if we will need a
   // dynamic symbol table.
Index: ELF/InputFiles.cpp
===
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "InputFiles.h"
+#include "Driver.h"
 #include "InputSection.h"
 #include "LinkerScript.h"
 #include "SymbolTable.h"
@@ -499,6 +500,27 @@
   }
 }
 
+// An ELF object file may contain a `.deplibs` section. If it exists, the
+// section contains a list of library specifiers such as `m` for libm. This
+// function resolves a given name by finding the first matching library checking
+// the various ways that a library can be specified to LLD. This ELF extension
+// is a form of autolinking and is called `dependent libraries`. It is currently
+// unique to LLVM and lld.
+static void addDependentLibrary(StringRef Specifier, const InputFile *F) {
+  if (!Config->DependentLibraries)
+return;
+  if (fs::exists(Specifier))
+Driver->addFile(Specifier, /*WithLOption=*/false);
+  else if (Optional S = findFromSearchPaths(Specifier))
+Driver->addFile(*S, /*WithLOption=*/true);
+  else if (Optional S = searchLibraryBaseName(Specifier))
+Driver->addFile(*S, /*WithLOption=*/true);
+  else
+error(toString(F) +
+  ": unable to find library from dependent library specifier: " +
+  Specifier);
+}
+
 template 
 void ObjFile::initializeSections(
 DenseSet ) {
@@ -740,6 +762,24 @@
 }
 return ::Discarded;
   }
+  case SHT_LLVM_DEPENDENT_LIBRARIES: {
+if (Config->Relocatable)
+  break;
+ArrayRef Data =
+CHECK(this->getObj().template getSectionContentsAsArray(), this);
+if (!Data.empty() && Data.back() != '\0') {
+  error(toString(this) +
+": corrupted dependent libraries section (unterminated string): " +
+Name);
+  return ::Discarded;
+}
+for (const char *D = Data.begin(), *E = Data.end(); D < E;) {
+  StringRef S(D);
+  addDependentLibrary(S, this);
+  D += S.size() + 1;
+}
+return ::Discarded;
+  }
   case SHT_RELA:
   case SHT_REL: {
 // Find a relocation target section and associate this section with that.
@@ -1302,6 +1342,9 @@
 
   for (const lto::InputFile::Symbol  : Obj->symbols())
 Symbols.push_back(createBitcodeSymbol(KeptComdats, ObjSym, *this));
+
+  for (auto L : Obj->getDependentLibraries())
+addDependentLibrary(L, this);
 }
 
 static ELFKind getELFKind(MemoryBufferRef MB, StringRef ArchiveName) {
Index: ELF/Options.td
===
--- ELF/Options.td
+++ ELF/Options.td
@@ -71,6 +71,10 @@
 "Apply link-time values for dynamic relocations",
 "Do not apply link-time values for dynamic relocations (default)">;
 
+defm 

Re: r360946 - Add Clang shared library with C++ exports

2019-05-16 Thread Chris Bieneman via cfe-commits
I’ll re-land disabling if PIC is off.

This doesn’t replace the static libraries with object libraries, it just 
creates an object library target (named obj.${name}) for each static library. 
That allows the objects to be referenced separately from the archives, so we 
don’t have to do the -load-all/—whole-archive stuff we do for libLLVM.

-Chris

> On May 16, 2019, at 6:40 PM, Nico Weber  wrote:
> 
> To not keep the build broken over night, and since it's a small change that 
> should be easy to reland, I've reverted this for now in r360973.
> 
>> On Thu, May 16, 2019 at 8:52 PM Nico Weber  wrote:
>> Hello,
>> 
>> this breaks building with -DLLVM_ENABLE_PIC=OFF. Maybe the new target 
>> shouldn't be build in those builds?
>> 
>> 
>> Also, if I read this right, this makes static libraries for clang always be 
>> object libraries. Is that correct? If so, this likely makes the normal clang 
>> binary larger and less efficient than before: Normal static libraries only 
>> get referenced .o files in them loaded, while all files in object libraries 
>> are loaded by the linker. In theory, --gc-sections should drop the ones that 
>> aren't needed, but due to static initializers and so on that doesn't always 
>> work. (When we moved Chrome's build to GN, the thinking was for a long time 
>> that we'd use object libraries instead of static libraries everywhere. Turns 
>> out that made the binary 10% larger and slower and we had to paddle back.)
>> 
>> 
>> 
>> [2523/2887] Linking CXX shared library lib/libclang_shared.so.9svn
>> FAILED: lib/libclang_shared.so.9svn 
>> ...
>> /usr/bin/ld: 
>> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o: 
>> relocation R_X86_64_32 against 
>> `.rodata._ZZNR4llvm15optional_detail15OptionalStorageIiLb1EE8getValueEvE19__PRETTY_FUNCTION__'
>>  can not be used when making a shared object; recompile with -fPIC
>> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o: error 
>> adding symbols: Bad value
>> collect2: error: ld returned 1 exit status
>> 
>>> On Thu, May 16, 2019 at 6:03 PM Chris Bieneman via cfe-commits 
>>>  wrote:
>>> Author: cbieneman
>>> Date: Thu May 16 15:06:07 2019
>>> New Revision: 360946
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=360946=rev
>>> Log:
>>> Add Clang shared library with C++ exports
>>> 
>>> Summary:
>>> This patch adds a libClang_shared library on *nix systems which exports the 
>>> entire C++ API. In order to support this on Windows we should really 
>>> refactor llvm-shlib and share code between the two.
>>> 
>>> This also uses a slightly different method for generating the shared 
>>> library, which I should back-port to llvm-shlib. Instead of linking the 
>>> static archives and passing linker flags to force loading the whole 
>>> libraries, this patch creates object libraries for every library (which has 
>>> no cost in the build system), and link the object libraries.
>>> 
>>> Reviewers: tstellar, winksaville
>>> 
>>> Subscribers: mgorny, cfe-commits
>>> 
>>> Tags: #clang
>>> 
>>> Differential Revision: https://reviews.llvm.org/D61909
>>> 
>>> Added:
>>> cfe/trunk/tools/clang-shlib/
>>> cfe/trunk/tools/clang-shlib/CMakeLists.txt
>>> cfe/trunk/tools/clang-shlib/clang-shlib.cpp
>>> Modified:
>>> cfe/trunk/cmake/modules/AddClang.cmake
>>> cfe/trunk/tools/CMakeLists.txt
>>> 
>>> Modified: cfe/trunk/cmake/modules/AddClang.cmake
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=360946=360945=360946=diff
>>> ==
>>> --- cfe/trunk/cmake/modules/AddClang.cmake (original)
>>> +++ cfe/trunk/cmake/modules/AddClang.cmake Thu May 16 15:06:07 2019
>>> @@ -81,9 +81,12 @@ macro(add_clang_library name)
>>>)
>>>endif()
>>>if(ARG_SHARED)
>>> -set(ARG_ENABLE_SHARED SHARED)
>>> +set(LIBTYPE SHARED)
>>> +  else()
>>> +set(LIBTYPE STATIC OBJECT)
>>> +set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
>>>endif()
>>> -  llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} 
>>> ${srcs})
>>> +  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
>>> 
>>>if(TARGET ${name})
>>>  target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
>>> 
>>> Modified: cfe/trunk/tools/CMakeLists.txt
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=360946=360945=360946=diff
>>> ==
>>> --- cfe/trunk/tools/CMakeLists.txt (original)
>>> +++ cfe/trunk/tools/CMakeLists.txt Thu May 16 15:06:07 2019
>>> @@ -13,6 +13,9 @@ add_clang_subdirectory(c-index-test)
>>> 
>>>  add_clang_subdirectory(clang-rename)
>>>  add_clang_subdirectory(clang-refactor)
>>> +if(UNIX)
>>> +  add_clang_subdirectory(clang-shlib)
>>> +endif()
>>> 
>>>  if(CLANG_ENABLE_ARCMT)
>>>add_clang_subdirectory(arcmt-test)
>>> 
>>> Added: 

[libclc] r360979 - Creating release candidate rc1 from release_801 branch

2019-05-16 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Thu May 16 19:26:13 2019
New Revision: 360979

URL: http://llvm.org/viewvc/llvm-project?rev=360979=rev
Log:
Creating release candidate rc1 from release_801 branch

Added:
libclc/tags/RELEASE_801/
libclc/tags/RELEASE_801/rc1/
  - copied from r360978, libclc/branches/release_80/

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


[libunwind] r360979 - Creating release candidate rc1 from release_801 branch

2019-05-16 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Thu May 16 19:26:13 2019
New Revision: 360979

URL: http://llvm.org/viewvc/llvm-project?rev=360979=rev
Log:
Creating release candidate rc1 from release_801 branch

Added:
libunwind/tags/RELEASE_801/
libunwind/tags/RELEASE_801/rc1/
  - copied from r360978, libunwind/branches/release_80/

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


[PATCH] D60274: [ELF] Implement Dependent Libraries Feature

2019-05-16 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

@bd1976llvm do you plan on landing this? We'd really like to start using this 
feature.


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

https://reviews.llvm.org/D60274



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


r360977 - [c++20] P1327R1: Support for typeid applied to objects of polymorphic

2019-05-16 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu May 16 19:16:45 2019
New Revision: 360977

URL: http://llvm.org/viewvc/llvm-project?rev=360977=rev
Log:
[c++20] P1327R1: Support for typeid applied to objects of polymorphic
class type in constant evaluation.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx2a.cpp
cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=360977=360976=360977=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Thu May 16 19:16:45 2019
@@ -12,7 +12,8 @@ let Component = "AST" in {
 def note_expr_divide_by_zero : Note<"division by zero">;
 def note_constexpr_invalid_cast : Note<
   "%select{reinterpret_cast|dynamic_cast|cast that performs the conversions of"
-  " a reinterpret_cast|cast from %1}0 is not allowed in a constant 
expression">;
+  " a reinterpret_cast|cast from %1}0 is not allowed in a constant expression"
+  "%select{| in C++ standards before C++2a||}0">;
 def note_constexpr_invalid_downcast : Note<
   "cannot cast object of dynamic type %0 to type %1">;
 def note_constexpr_overflow : Note<
@@ -31,12 +32,13 @@ def note_constexpr_invalid_inhctor : Not
 def note_constexpr_no_return : Note<
   "control reached end of constexpr function">;
 def note_constexpr_virtual_call : Note<
-  "cannot evaluate call to virtual function in a constant expression">;
+  "cannot evaluate call to virtual function in a constant expression "
+  "in C++ standards before C++2a">;
 def note_constexpr_pure_virtual_call : Note<
   "pure virtual function %q0 called">;
 def note_constexpr_polymorphic_unknown_dynamic_type : Note<
-  "%select{virtual function called on|dynamic_cast applied to}0 "
-  "object '%1' whose dynamic type is not constant">;
+  "%select{virtual function called on|dynamic_cast applied to|"
+  "typeid applied to}0 object '%1' whose dynamic type is not constant">;
 def note_constexpr_dynamic_cast_to_reference_failed : Note<
   "reference dynamic_cast failed: %select{"
   "static type %1 of operand is a non-public base class of dynamic type %2|"
@@ -90,7 +92,7 @@ def note_constexpr_var_init_non_constant
   "initializer of %0 is not a constant expression">;
 def note_constexpr_typeid_polymorphic : Note<
   "typeid applied to expression of polymorphic type %0 is "
-  "not allowed in a constant expression">;
+  "not allowed in a constant expression in C++ standards before C++2a">;
 def note_constexpr_void_comparison : Note<
   "comparison between unequal pointers to void has unspecified result">;
 def note_constexpr_temporary_here : Note<"temporary created here">;
@@ -108,11 +110,11 @@ def note_constexpr_this : Note<
   "evaluation of a call to a 'constexpr' member function">;
 def note_constexpr_lifetime_ended : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of}0 "
+  "dynamic_cast of|typeid applied to}0 "
   "%select{temporary|variable}1 whose lifetime has ended">;
 def note_constexpr_access_uninit : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of}0 "
+  "dynamic_cast of|typeid applied to}0 "
   "object outside its lifetime is not allowed in a constant expression">;
 def note_constexpr_use_uninit_reference : Note<
   "use of reference outside its lifetime "
@@ -139,30 +141,30 @@ def note_constexpr_ltor_incomplete_type
   "read of incomplete type %0 is not allowed in a constant expression">;
 def note_constexpr_access_null : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of}0 "
+  "dynamic_cast of|typeid applied to}0 "
   "dereferenced null pointer is not allowed in a constant expression">;
 def note_constexpr_access_past_end : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of}0 "
+  "dynamic_cast of|typeid applied to}0 "
   "dereferenced one-past-the-end pointer is not allowed in a constant 
expression">;
 def note_constexpr_access_unsized_array : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of}0 "
+  "dynamic_cast of|typeid applied to}0 "
   "element of array without known bound "
   "is not allowed in a constant expression">;
 def note_constexpr_access_inactive_union_member : Note<
   "%select{read of|assignment to|increment of|decrement of|member call on|"
-  "dynamic_cast of}0 "
+  "dynamic_cast of|typeid applied to}0 "
   "member %1 of union with %select{active member %3|no active member}2 "
   "is not allowed in a constant expression">;
 def note_constexpr_access_static_temporary : Note<
   "%select{read of|assignment to|increment 

[PATCH] D61747: [clang-tidy] remove default header-filter for run-clang-tidy

2019-05-16 Thread Don Hinton via Phabricator via cfe-commits
hintonda added a comment.

After thinking about it, I agree with this change -- there's no way to provide 
an appropriate default at this level.

So, LGTM, but wait for @alexfh's okay.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61747



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


[PATCH] D61841: [clangd] Respect WarningsAsErrors configuration for clang-tidy

2019-05-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge edited reviewers, added: sammccall; removed: ilya-biryukov.
nridge added a subscriber: sammccall.
nridge added a comment.
Herald added a subscriber: ilya-biryukov.

Changing reviewer to @sammccall as the updates to the patch are closely related 
to the discussion in D60953 .

Also added a couple of test cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61841



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


[PATCH] D61841: [clangd] Respect WarningsAsErrors configuration for clang-tidy

2019-05-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 199956.
nridge added a comment.

Update as per changes to dependent patch D60953 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61841

Files:
  clang-tools-extra/clangd/ClangdUnit.cpp
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/TestTU.cpp
  clang-tools-extra/clangd/unittests/TestTU.h

Index: clang-tools-extra/clangd/unittests/TestTU.h
===
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -57,6 +57,7 @@
   std::vector ExtraArgs;
 
   llvm::Optional ClangTidyChecks;
+  llvm::Optional ClangTidyWarningsAsErrors;
   // Index to use when building AST.
   const SymbolIndex *ExternalIndex = nullptr;
 
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -48,6 +48,7 @@
   Inputs.FS = buildTestFS(Files);
   Inputs.Opts = ParseOptions();
   Inputs.Opts.ClangTidyOpts.Checks = ClangTidyChecks;
+  Inputs.Opts.ClangTidyOpts.WarningsAsErrors = ClangTidyWarningsAsErrors;
   Inputs.Index = ExternalIndex;
   if (Inputs.Index)
 Inputs.Opts.SuggestMissingIncludes = true;
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -73,6 +73,7 @@
 
 MATCHER_P(DiagSource, S, "") { return arg.Source == S; }
 MATCHER_P(DiagName, N, "") { return arg.Name == N; }
+MATCHER_P(DiagSeverity, S, "") { return arg.Severity == S; }
 
 MATCHER_P(EqualToFix, Fix, "LSP fix " + llvm::to_string(Fix)) {
   if (arg.Message != Fix.Message)
@@ -227,6 +228,44 @@
   DiagSource(Diag::ClangTidy), DiagName("bugprone-integer-division";
 }
 
+TEST(DiagnosticTest, ClangTidyWarningAsError) {
+  Annotations Main(R"cpp(
+int main() {
+  int i = 3;
+  double f = [[8]] / i;
+}
+  )cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.ClangTidyChecks = "bugprone-integer-division";
+  TU.ClangTidyWarningsAsErrors = "bugprone-integer-division";
+  EXPECT_THAT(
+  TU.build().getDiagnostics(),
+  UnorderedElementsAre(::testing::AllOf(
+  Diag(Main.range(), "result of integer division used in a floating "
+ "point context; possible loss of precision"),
+  DiagSource(Diag::ClangTidy), DiagName("bugprone-integer-division"),
+  DiagSeverity(DiagnosticsEngine::Error;
+}
+
+TEST(DiagnosticTest, ClangTidyWarningAsErrorTrumpsSuppressionComment) {
+  Annotations Main(R"cpp(
+int main() {
+  int i = 3;
+  double f = [[8]] / i;  // NOLINT
+}
+  )cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.ClangTidyChecks = "bugprone-integer-division";
+  TU.ClangTidyWarningsAsErrors = "bugprone-integer-division";
+  EXPECT_THAT(
+  TU.build().getDiagnostics(),
+  UnorderedElementsAre(::testing::AllOf(
+  Diag(Main.range(), "result of integer division used in a floating "
+ "point context; possible loss of precision"),
+  DiagSource(Diag::ClangTidy), DiagName("bugprone-integer-division"),
+  DiagSeverity(DiagnosticsEngine::Error;
+}
+
 TEST(DiagnosticsTest, Preprocessor) {
   // This looks like a preamble, but there's an #else in the middle!
   // Check that:
Index: clang-tools-extra/clangd/Diagnostics.h
===
--- clang-tools-extra/clangd/Diagnostics.h
+++ clang-tools-extra/clangd/Diagnostics.h
@@ -128,20 +128,20 @@
 
   using DiagFixer = std::function(DiagnosticsEngine::Level,
const clang::Diagnostic &)>;
-  using DiagFilter =
-  std::function;
+  using LevelAdjuster = std::function;
   /// If set, possibly adds fixes for diagnostics using \p Fixer.
   void contributeFixes(DiagFixer Fixer) { this->Fixer = Fixer; }
-  /// If set, ignore diagnostics for which \p SuppressionFilter returns true.
-  void suppressDiagnostics(DiagFilter SuppressionFilter) {
-this->SuppressionFilter = SuppressionFilter;
-  }
+  /// If set, this allows the client of this class to adjust the level of
+  /// diagnostics, such as promoting warnings to errors, or ignoring
+  /// diagnostics.
+  void setLevelAdjuster(LevelAdjuster Adjuster) { this->Adjuster = Adjuster; }
 
 private:
   void flushLastDiag();
 
   DiagFixer Fixer = nullptr;
-  DiagFilter SuppressionFilter = nullptr;
+  LevelAdjuster Adjuster = nullptr;
   std::vector Output;
   llvm::Optional 

[PATCH] D62050: [Analysis] Only run plugins tests if plugins are actually enabled

2019-05-16 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: smeenai, Szelethus, NoQ.
Herald added subscribers: llvm-commits, cfe-commits, mgorny.
Herald added projects: clang, LLVM.

When plugins aren't enabled, don't try to run plugins tests. Don't
enable plugins unconditionally based on the platform, instead check
if LLVM shared library is actually being built which may not be the
case for every host configuration, even if the host itself supports
plugins.

This addresses test failures introduced by r360891/D59464 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62050

Files:
  clang/test/Analysis/checker-plugins.c
  clang/test/CMakeLists.txt
  clang/test/lit.cfg.py
  clang/test/lit.site.cfg.py.in
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -920,14 +920,10 @@
 
 # Plugin support
 # FIXME: Make this configurable.
-if(WIN32 OR CYGWIN)
-  if(BUILD_SHARED_LIBS OR LLVM_BUILD_LLVM_DYLIB)
-set(LLVM_ENABLE_PLUGINS ON)
-  else()
-set(LLVM_ENABLE_PLUGINS OFF)
-  endif()
-else()
+if(BUILD_SHARED_LIBS OR LLVM_BUILD_LLVM_DYLIB)
   set(LLVM_ENABLE_PLUGINS ON)
+else()
+  set(LLVM_ENABLE_PLUGINS OFF)
 endif()
 
 # By default we should enable LLVM_ENABLE_IDE only for multi-configuration
Index: clang/test/lit.site.cfg.py.in
===
--- clang/test/lit.site.cfg.py.in
+++ clang/test/lit.site.cfg.py.in
@@ -27,6 +27,7 @@
 config.host_arch = "@HOST_ARCH@"
 config.python_executable = "@PYTHON_EXECUTABLE@"
 config.use_z3_solver = lit_config.params.get('USE_Z3_SOLVER', 
"@USE_Z3_SOLVER@")
+config.has_plugins = @LLVM_ENABLE_PLUGINS@
 
 # Support substitution of the tools and libs dirs with user parameters. This is
 # used when we can't determine the tool dir at configuration time.
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -85,13 +85,7 @@
  os.path.join(config.clang_tools_dir, 
'hmaptool'
 
 # Plugins (loadable modules)
-# TODO: This should be supplied by Makefile or autoconf.
-if sys.platform in ['win32', 'cygwin']:
-has_plugins = config.enable_shared
-else:
-has_plugins = True
-
-if has_plugins and config.llvm_plugin_ext:
+if config.has_plugins and config.llvm_plugin_ext:
 config.available_features.add('plugins')
 
 # Set available features we allow tests to conditionalize on.
Index: clang/test/CMakeLists.txt
===
--- clang/test/CMakeLists.txt
+++ clang/test/CMakeLists.txt
@@ -24,7 +24,8 @@
   CLANG_ENABLE_STATIC_ANALYZER
   ENABLE_BACKTRACES
   HAVE_LIBZ
-  LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
+  LLVM_ENABLE_PER_TARGET_RUNTIME_DIR
+  LLVM_ENABLE_PLUGINS)
 
 configure_lit_site_cfg(
   ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
Index: clang/test/Analysis/checker-plugins.c
===
--- clang/test/Analysis/checker-plugins.c
+++ clang/test/Analysis/checker-plugins.c
@@ -1,9 +1,9 @@
+// REQUIRES: plugins
+
 // RUN: %clang_analyze_cc1 -verify %s \
 // RUN:   -load %llvmshlibdir/SampleAnalyzerPlugin%pluginext \
 // RUN:   -analyzer-checker='example.MainCallChecker'
 
-// REQUIRES: plugins
-
 // Test that the MainCallChecker example analyzer plugin loads and runs.
 
 int main();


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -920,14 +920,10 @@
 
 # Plugin support
 # FIXME: Make this configurable.
-if(WIN32 OR CYGWIN)
-  if(BUILD_SHARED_LIBS OR LLVM_BUILD_LLVM_DYLIB)
-set(LLVM_ENABLE_PLUGINS ON)
-  else()
-set(LLVM_ENABLE_PLUGINS OFF)
-  endif()
-else()
+if(BUILD_SHARED_LIBS OR LLVM_BUILD_LLVM_DYLIB)
   set(LLVM_ENABLE_PLUGINS ON)
+else()
+  set(LLVM_ENABLE_PLUGINS OFF)
 endif()
 
 # By default we should enable LLVM_ENABLE_IDE only for multi-configuration
Index: clang/test/lit.site.cfg.py.in
===
--- clang/test/lit.site.cfg.py.in
+++ clang/test/lit.site.cfg.py.in
@@ -27,6 +27,7 @@
 config.host_arch = "@HOST_ARCH@"
 config.python_executable = "@PYTHON_EXECUTABLE@"
 config.use_z3_solver = lit_config.params.get('USE_Z3_SOLVER', "@USE_Z3_SOLVER@")
+config.has_plugins = @LLVM_ENABLE_PLUGINS@
 
 # Support substitution of the tools and libs dirs with user parameters. This is
 # used when we can't determine the tool dir at configuration time.
Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -85,13 +85,7 @@
  

[PATCH] D60953: [clangd] Respect clang-tidy suppression comments

2019-05-16 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 199954.
nridge marked 5 inline comments as done.
nridge added a comment.

Address latest review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60953

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clangd/ClangdUnit.cpp
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/Diagnostics.h
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -207,6 +207,26 @@
"multiple unsequenced modifications to 'y'")));
 }
 
+TEST(DiagnosticTest, ClangTidySuppressionComment) {
+  Annotations Main(R"cpp(
+int main() {
+  int i = 3;
+  double d = 8 / i;  // NOLINT
+  // NOLINTNEXTLINE
+  double e = 8 / i;
+  double f = [[8]] / i;
+}
+  )cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.ClangTidyChecks = "bugprone-integer-division";
+  EXPECT_THAT(
+  TU.build().getDiagnostics(),
+  UnorderedElementsAre(::testing::AllOf(
+  Diag(Main.range(), "result of integer division used in a floating "
+ "point context; possible loss of precision"),
+  DiagSource(Diag::ClangTidy), DiagName("bugprone-integer-division";
+}
+
 TEST(DiagnosticsTest, Preprocessor) {
   // This looks like a preamble, but there's an #else in the middle!
   // Check that:
@@ -767,6 +787,7 @@
  "a type specifier for all declarations"),
   WithNote(Diag(Header.range(), "error occurred here");
 }
+
 } // namespace
 
 } // namespace clangd
Index: clang-tools-extra/clangd/Diagnostics.h
===
--- clang-tools-extra/clangd/Diagnostics.h
+++ clang-tools-extra/clangd/Diagnostics.h
@@ -128,17 +128,25 @@
 
   using DiagFixer = std::function(DiagnosticsEngine::Level,
const clang::Diagnostic &)>;
+  using DiagFilter =
+  std::function;
   /// If set, possibly adds fixes for diagnostics using \p Fixer.
   void contributeFixes(DiagFixer Fixer) { this->Fixer = Fixer; }
+  /// If set, ignore diagnostics for which \p SuppressionFilter returns true.
+  void suppressDiagnostics(DiagFilter SuppressionFilter) {
+this->SuppressionFilter = SuppressionFilter;
+  }
 
 private:
   void flushLastDiag();
 
   DiagFixer Fixer = nullptr;
+  DiagFilter SuppressionFilter = nullptr;
   std::vector Output;
   llvm::Optional LangOpts;
   llvm::Optional LastDiag;
   llvm::DenseSet IncludeLinesWithErrors;
+  bool LastPrimaryDiagnosticWasSuppressed = false;
 };
 
 } // namespace clangd
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -514,6 +514,12 @@
 // Handle the new main diagnostic.
 flushLastDiag();
 
+if (SuppressionFilter && SuppressionFilter(DiagLevel, Info)) {
+  LastPrimaryDiagnosticWasSuppressed = true;
+  return;
+}
+LastPrimaryDiagnosticWasSuppressed = false;
+
 LastDiag = Diag();
 LastDiag->ID = Info.getID();
 FillDiagBase(*LastDiag);
@@ -528,6 +534,13 @@
 }
   } else {
 // Handle a note to an existing diagnostic.
+
+// If a diagnostic was suppressed due to the suppression filter,
+// also suppress notes associated with it.
+if (LastPrimaryDiagnosticWasSuppressed) {
+  return;
+}
+
 if (!LastDiag) {
   assert(false && "Adding a note without main diagnostic");
   IgnoreDiagnostics::log(DiagLevel, Info);
Index: clang-tools-extra/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/clangd/ClangdUnit.cpp
+++ clang-tools-extra/clangd/ClangdUnit.cpp
@@ -113,12 +113,12 @@
   }
 
   void EndOfMainFile() {
-for (const auto& Entry : MainFileMacros)
+for (const auto  : MainFileMacros)
   Out->push_back(Entry.getKey());
 llvm::sort(*Out);
   }
 
- private:
+private:
   const SourceManager 
   bool InMainFile = true;
   llvm::StringSet<> MainFileMacros;
@@ -332,6 +332,30 @@
 CTContext->setASTContext(>getASTContext());
 CTContext->setCurrentFile(MainInput.getFile());
 CTFactories.createChecks(CTContext.getPointer(), CTChecks);
+ASTDiags.suppressDiagnostics([](
+ DiagnosticsEngine::Level DiagLevel,
+ const clang::Diagnostic ) {
+  if (CTContext) {
+bool IsClangTidyDiag = 

r360974 - Refactor constant evaluation of typeid(T) to track a symbolic type_info

2019-05-16 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu May 16 18:46:05 2019
New Revision: 360974

URL: http://llvm.org/viewvc/llvm-project?rev=360974=rev
Log:
Refactor constant evaluation of typeid(T) to track a symbolic type_info
object rather than tracking the originating expression.

This is groundwork for supporting polymorphic typeid expressions. (Note
that this somewhat regresses our support for DR1968, but it turns out
that that never actually worked anyway, at least in non-trivial cases.)

Modified:
cfe/trunk/include/clang/AST/APValue.h
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/lib/AST/APValue.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/CXX/drs/dr19xx.cpp
cfe/trunk/test/Parser/MicrosoftExtensions.cpp
cfe/trunk/test/SemaCXX/builtin-constant-p.cpp
cfe/trunk/test/SemaCXX/typeid.cpp
cfe/trunk/www/cxx_dr_status.html

Modified: cfe/trunk/include/clang/AST/APValue.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=360974=360973=360974=diff
==
--- cfe/trunk/include/clang/AST/APValue.h (original)
+++ cfe/trunk/include/clang/AST/APValue.h Thu May 16 18:46:05 2019
@@ -24,14 +24,52 @@ namespace clang {
   class AddrLabelExpr;
   class ASTContext;
   class CharUnits;
+  class CXXRecordDecl;
+  class Decl;
   class DiagnosticBuilder;
   class Expr;
   class FieldDecl;
-  class Decl;
+  struct PrintingPolicy;
+  class Type;
   class ValueDecl;
-  class CXXRecordDecl;
-  class QualType;
 
+/// Symbolic representation of typeid(T) for some type T.
+class TypeInfoLValue {
+  const Type *T;
+
+public:
+  TypeInfoLValue() : T() {}
+  explicit TypeInfoLValue(const Type *T);
+
+  const Type *getType() const { return T; }
+  explicit operator bool() const { return T; }
+
+  void *getOpaqueValue() { return const_cast(T); }
+  static TypeInfoLValue getFromOpaqueValue(void *Value) {
+TypeInfoLValue V;
+V.T = reinterpret_cast(Value);
+return V;
+  }
+
+  void print(llvm::raw_ostream , const PrintingPolicy ) const;
+};
+}
+
+namespace llvm {
+template<> struct PointerLikeTypeTraits {
+  static void *getAsVoidPointer(clang::TypeInfoLValue V) {
+return V.getOpaqueValue();
+  }
+  static clang::TypeInfoLValue getFromVoidPointer(void *P) {
+return clang::TypeInfoLValue::getFromOpaqueValue(P);
+  }
+  // Validated by static_assert in APValue.cpp; hardcoded to avoid needing
+  // to include Type.h.
+  static constexpr int NumLowBitsAvailable = 3;
+};
+}
+
+namespace clang {
 /// APValue - This class implements a discriminated union of [uninitialized]
 /// [APSInt] [APFloat], [Complex APSInt] [Complex APFloat], [Expr + Offset],
 /// [Vector: N * APValue], [Array: N * APValue]
@@ -57,13 +95,18 @@ public:
 
   class LValueBase {
   public:
-typedef llvm::PointerUnion PtrTy;
+typedef llvm::PointerUnion
+PtrTy;
 
-LValueBase() : CallIndex(0), Version(0) {}
+LValueBase() : Local{} {}
 
 template 
-LValueBase(T P, unsigned I = 0, unsigned V = 0)
-: Ptr(P), CallIndex(I), Version(V) {}
+LValueBase(T P, unsigned I = 0, unsigned V = 0) : Ptr(P), Local{I, V} {
+  assert(!is() &&
+ "don't use this constructor to form a type_info lvalue");
+}
+
+static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo);
 
 template 
 bool is() const { return Ptr.is(); }
@@ -78,28 +121,15 @@ public:
 
 bool isNull() const;
 
-explicit operator bool () const;
+explicit operator bool() const;
 
-PtrTy getPointer() const {
-  return Ptr;
-}
+PtrTy getPointer() const { return Ptr; }
 
-unsigned getCallIndex() const {
-  return CallIndex;
-}
+unsigned getCallIndex() const;
+unsigned getVersion() const;
+QualType getTypeInfoType() const;
 
-void setCallIndex(unsigned Index) {
-  CallIndex = Index;
-}
-
-unsigned getVersion() const {
-  return Version;
-}
-
-friend bool operator==(const LValueBase , const LValueBase ) {
-  return LHS.Ptr == RHS.Ptr && LHS.CallIndex == RHS.CallIndex &&
- LHS.Version == RHS.Version;
-}
+friend bool operator==(const LValueBase , const LValueBase );
 friend bool operator!=(const LValueBase , const LValueBase ) {
   return !(LHS == RHS);
 }
@@ -107,7 +137,14 @@ public:
 
   private:
 PtrTy Ptr;
-unsigned CallIndex, Version;
+struct LocalState {
+  unsigned CallIndex, Version;
+};
+union {
+  LocalState Local;
+  /// The type std::type_info, if this is a TypeInfoLValue.
+  void *TypeInfoType;
+};
   };
 
   /// A FieldDecl or CXXRecordDecl, along with a flag indicating whether we

Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: 

Re: r360946 - Add Clang shared library with C++ exports

2019-05-16 Thread Nico Weber via cfe-commits
To not keep the build broken over night, and since it's a small change that
should be easy to reland, I've reverted this for now in r360973.

On Thu, May 16, 2019 at 8:52 PM Nico Weber  wrote:

> Hello,
>
> this breaks building with -DLLVM_ENABLE_PIC=OFF. Maybe the new target
> shouldn't be build in those builds?
>
>
> Also, if I read this right, this makes static libraries for clang always
> be object libraries. Is that correct? If so, this likely makes the normal
> clang binary larger and less efficient than before: Normal static libraries
> only get referenced .o files in them loaded, while all files in object
> libraries are loaded by the linker. In theory, --gc-sections should drop
> the ones that aren't needed, but due to static initializers and so on that
> doesn't always work. (When we moved Chrome's build to GN, the thinking was
> for a long time that we'd use object libraries instead of static libraries
> everywhere. Turns out that made the binary 10% larger and slower and we had
> to paddle back.)
>
>
>
> [2523/2887] Linking CXX shared library lib/libclang_shared.so.9svn
> FAILED: lib/libclang_shared.so.9svn
> ...
> /usr/bin/ld:
> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o:
> relocation R_X86_64_32 against
> `.rodata._ZZNR4llvm15optional_detail15OptionalStorageIiLb1EE8getValueEvE19__PRETTY_FUNCTION__'
> can not be used when making a shared object; recompile with -fPIC
> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o:
> error adding symbols: Bad value
> collect2: error: ld returned 1 exit status
>
> On Thu, May 16, 2019 at 6:03 PM Chris Bieneman via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: cbieneman
>> Date: Thu May 16 15:06:07 2019
>> New Revision: 360946
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=360946=rev
>> Log:
>> Add Clang shared library with C++ exports
>>
>> Summary:
>> This patch adds a libClang_shared library on *nix systems which exports
>> the entire C++ API. In order to support this on Windows we should really
>> refactor llvm-shlib and share code between the two.
>>
>> This also uses a slightly different method for generating the shared
>> library, which I should back-port to llvm-shlib. Instead of linking the
>> static archives and passing linker flags to force loading the whole
>> libraries, this patch creates object libraries for every library (which has
>> no cost in the build system), and link the object libraries.
>>
>> Reviewers: tstellar, winksaville
>>
>> Subscribers: mgorny, cfe-commits
>>
>> Tags: #clang
>>
>> Differential Revision: https://reviews.llvm.org/D61909
>>
>> Added:
>> cfe/trunk/tools/clang-shlib/
>> cfe/trunk/tools/clang-shlib/CMakeLists.txt
>> cfe/trunk/tools/clang-shlib/clang-shlib.cpp
>> Modified:
>> cfe/trunk/cmake/modules/AddClang.cmake
>> cfe/trunk/tools/CMakeLists.txt
>>
>> Modified: cfe/trunk/cmake/modules/AddClang.cmake
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=360946=360945=360946=diff
>>
>> ==
>> --- cfe/trunk/cmake/modules/AddClang.cmake (original)
>> +++ cfe/trunk/cmake/modules/AddClang.cmake Thu May 16 15:06:07 2019
>> @@ -81,9 +81,12 @@ macro(add_clang_library name)
>>)
>>endif()
>>if(ARG_SHARED)
>> -set(ARG_ENABLE_SHARED SHARED)
>> +set(LIBTYPE SHARED)
>> +  else()
>> +set(LIBTYPE STATIC OBJECT)
>> +set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
>>endif()
>> -  llvm_add_library(${name} ${ARG_ENABLE_SHARED}
>> ${ARG_UNPARSED_ARGUMENTS} ${srcs})
>> +  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
>>
>>if(TARGET ${name})
>>  target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
>>
>> Modified: cfe/trunk/tools/CMakeLists.txt
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=360946=360945=360946=diff
>>
>> ==
>> --- cfe/trunk/tools/CMakeLists.txt (original)
>> +++ cfe/trunk/tools/CMakeLists.txt Thu May 16 15:06:07 2019
>> @@ -13,6 +13,9 @@ add_clang_subdirectory(c-index-test)
>>
>>  add_clang_subdirectory(clang-rename)
>>  add_clang_subdirectory(clang-refactor)
>> +if(UNIX)
>> +  add_clang_subdirectory(clang-shlib)
>> +endif()
>>
>>  if(CLANG_ENABLE_ARCMT)
>>add_clang_subdirectory(arcmt-test)
>>
>> Added: cfe/trunk/tools/clang-shlib/CMakeLists.txt
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/CMakeLists.txt?rev=360946=auto
>>
>> ==
>> --- cfe/trunk/tools/clang-shlib/CMakeLists.txt (added)
>> +++ cfe/trunk/tools/clang-shlib/CMakeLists.txt Thu May 16 15:06:07 2019
>> @@ -0,0 +1,13 @@
>> +get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)
>> +
>> +foreach (lib ${clang_libs})
>> +  list(APPEND _OBJECTS $)
>> +  

r360973 - Revert r360946 "Add Clang shared library with C++ exports"

2019-05-16 Thread Nico Weber via cfe-commits
Author: nico
Date: Thu May 16 18:42:37 2019
New Revision: 360973

URL: http://llvm.org/viewvc/llvm-project?rev=360973=rev
Log:
Revert r360946 "Add Clang shared library with C++ exports"

It breaks LLVM_ENABLE_PIC=OFF builds, and it's not clear
if the object library approach doesn't impact the normal
clang binary.

Removed:
cfe/trunk/tools/clang-shlib/
Modified:
cfe/trunk/cmake/modules/AddClang.cmake
cfe/trunk/tools/CMakeLists.txt

Modified: cfe/trunk/cmake/modules/AddClang.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=360973=360972=360973=diff
==
--- cfe/trunk/cmake/modules/AddClang.cmake (original)
+++ cfe/trunk/cmake/modules/AddClang.cmake Thu May 16 18:42:37 2019
@@ -81,12 +81,9 @@ macro(add_clang_library name)
   )
   endif()
   if(ARG_SHARED)
-set(LIBTYPE SHARED)
-  else()
-set(LIBTYPE STATIC OBJECT)
-set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
+set(ARG_ENABLE_SHARED SHARED)
   endif()
-  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
+  llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} 
${srcs})
 
   if(TARGET ${name})
 target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})

Modified: cfe/trunk/tools/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=360973=360972=360973=diff
==
--- cfe/trunk/tools/CMakeLists.txt (original)
+++ cfe/trunk/tools/CMakeLists.txt Thu May 16 18:42:37 2019
@@ -13,9 +13,6 @@ add_clang_subdirectory(c-index-test)
 
 add_clang_subdirectory(clang-rename)
 add_clang_subdirectory(clang-refactor)
-if(UNIX)
-  add_clang_subdirectory(clang-shlib)
-endif()
 
 if(CLANG_ENABLE_ARCMT)
   add_clang_subdirectory(arcmt-test)


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


[PATCH] D61967: [clang-tidy] Add a close-on-exec check on pipe() in Android module.

2019-05-16 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h:1
+//===--- CloexecPipeCheck.h - clang-tidy---*- C++ -*-===//
+//

Please extend to 80 characters. Same in source file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61967



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


[PATCH] D62049: [clang-tidy] Add a close-on-exec check on pipe2() in Android module.

2019-05-16 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h:1
+//===--- CloexecPipe2Check.h - clang-tidy--*- C++ -*-===//
+//

Please extend to 80 characters. Same in source file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62049



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


[PATCH] D62046: [OpenMP][bugfix] Add missing math functions variants for log and abs.

2019-05-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: lib/Headers/__clang_cuda_cmath.h:55-56
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ const float abs(const float __x) { return ::fabsf((float)__x); }
+__DEVICE__ const double abs(const double __x) { return ::fabs((double)__x); }
+#endif

gtbercea wrote:
> tra wrote:
> > Where do these functions come from?  
> > https://en.cppreference.com/w/cpp/numeric/math/fabs does not seem to show 
> > any `abs` functions with const args.
> What's happening is that when including the random header file, this header 
> file uses abs with const arguments:
> 
> 
> ```
> const double __n = _M_nd(__urng);
> const double __y = -std::abs(__n) * __param._M_sm - 1;
> ```
> 
> And without there functions here the error I get is:
> 
> 
> ```
> In file included from test.c:8:
> In file included from 
> /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/random:52:
> /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/bits/random.tcc:1476:27:
>  error: call to 'abs' is ambiguous
> const double __y = -std::abs(__n) * __param._M_sm - 1;
> ^~~~
> /usr/include/stdlib.h:770:12: note: candidate function
> extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
>^
> /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:166:3:
>  note: candidate function
>   abs(long __i) { return __builtin_labs(__i); }
>   ^
> /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:174:3:
>  note: candidate function
>   abs(long long __x) { return __builtin_llabs (__x); }
>   ^
> /usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:179:3:
>  note: candidate function
>   abs(__int128 __x) { return __x >= 0 ? __x : -__x; }
>   ^
> ```
Overloading ignores the "const"; `float abs(float)` is the same thing.  So 
probably clearer to declare it without the extra "const" modifiers, and then 
clean up the redundant definitions.

That said, I'm not sure how you managed to pick up the declarations from 
cstdlib, but not cmath. What files are getting included when this fails?

(Actually, in C++17, both cmath and cstdlib are supposed to declare all the 
float and integer overloads of abs, but that's only implemented in newer 
versions of libstdc++.)


Repository:
  rC Clang

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

https://reviews.llvm.org/D62046



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


[PATCH] D62049: [clang-tidy] Add a close-on-exec check on pipe2() in Android module.

2019-05-16 Thread Jian Cai via Phabricator via cfe-commits
jcai19 created this revision.
Herald added subscribers: cfe-commits, xazax.hun, mgorny, srhines.
Herald added a project: clang.

pipe2() is better to set O_CLOEXEC flag to avoid file descriptor leakage.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62049

Files:
  clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/clang-tidy/android/CloexecPipe2Check.cpp
  clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe2.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp

Index: clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp
@@ -0,0 +1,68 @@
+// RUN: %check_clang_tidy %s android-cloexec-pipe2 %t
+
+#define O_NONBLOCK 1
+#define __O_CLOEXEC 3
+#define O_CLOEXEC __O_CLOEXEC
+#define TEMP_FAILURE_RETRY(exp) \
+  ({\
+int _rc;\
+do {\
+  _rc = (exp);  \
+} while (_rc == -1);\
+  })
+#define NULL 0
+
+extern "C" int pipe2(int pipefd[2], int flags);
+
+void a() {
+  int pipefd[2];
+  pipe2(pipefd, O_NONBLOCK);
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'pipe2' should use O_CLOEXEC where possible [android-cloexec-pipe2]
+  // CHECK-FIXES: pipe2(pipefd, O_NONBLOCK | O_CLOEXEC);
+  TEMP_FAILURE_RETRY(pipe2(pipefd, O_NONBLOCK));
+  // CHECK-MESSAGES: :[[@LINE-1]]:46: warning: 'pipe2'
+  // CHECK-FIXES: TEMP_FAILURE_RETRY(pipe2(pipefd, O_NONBLOCK | O_CLOEXEC));
+}
+
+void f() {
+  int pipefd[2];
+  pipe2(pipefd, 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'pipe2'
+  // CHECK-FIXES: pipe2(pipefd, 3 | O_CLOEXEC);
+  TEMP_FAILURE_RETRY(pipe2(pipefd, 3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: 'pipe2'
+  // CHECK-FIXES: TEMP_FAILURE_RETRY(pipe2(pipefd, 3 | O_CLOEXEC));
+
+  int flag = O_NONBLOCK;
+  pipe2(pipefd, flag);
+  TEMP_FAILURE_RETRY(pipe2(pipefd, flag));
+}
+
+namespace i {
+int pipe2(int pipefd[2], int flags);
+
+void d() {
+  int pipefd[2];
+  pipe2(pipefd, O_NONBLOCK);
+  TEMP_FAILURE_RETRY(pipe2(pipefd, O_NONBLOCK));
+}
+
+} // namespace i
+
+void e() {
+  int pipefd[2];
+  pipe2(pipefd, O_CLOEXEC);
+  TEMP_FAILURE_RETRY(pipe2(pipefd, O_CLOEXEC));
+  pipe2(pipefd, O_NONBLOCK | O_CLOEXEC);
+  TEMP_FAILURE_RETRY(pipe2(pipefd, O_NONBLOCK | O_CLOEXEC));
+}
+
+class G {
+public:
+  int pipe2(int pipefd[2], int flags);
+  void d() {
+int pipefd[2];
+pipe2(pipefd, O_NONBLOCK);
+TEMP_FAILURE_RETRY(pipe2(pipefd, O_NONBLOCK));
+  }
+};
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
@@ -32,6 +32,7 @@
android-cloexec-inotify-init1
android-cloexec-memfd-create
android-cloexec-open
+   android-cloexec-pipe2
android-cloexec-socket
android-comparison-in-temp-failure-retry
boost-use-to-string
Index: clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe2.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe2.rst
@@ -0,0 +1,19 @@
+.. title:: clang-tidy - android-cloexec-pipe2
+
+android-cloexec-pipe2
+=
+
+Checks if the required file flag ``O_CLOEXEC`` is present in the argument of
+``pipe2()``. ``pipe2()`` should include ``O_CLOEXEC`` in its type argument to
+avoid the file descriptor leakage. Without this flag, an opened sensitive file
+would remain open across a ``fork``+``exec`` to a lower-privileged SELinux domain.
+
+Examples:
+
+.. code-block:: c++
+
+  pipe2(pipefd, O_NONBLOCK);
+
+  // becomes
+
+  pipe2(pipefd, O_CLOEXEC);
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -101,6 +101,12 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`android-cloexec-pipe
+  ` check.
+
+  Checks if the required file flag ``O_CLOEXEC`` is present in the argument of
+  ``pipe2()``.
+
 - New :doc:`bugprone-unhandled-self-assignment
   ` check.
 
Index: clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h
@@ -0,0 +1,34 @@
+//===--- CloexecPipe2Check.h - clang-tidy--*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache 

Re: r360946 - Add Clang shared library with C++ exports

2019-05-16 Thread Nico Weber via cfe-commits
Hello,

this breaks building with -DLLVM_ENABLE_PIC=OFF. Maybe the new target
shouldn't be build in those builds?


Also, if I read this right, this makes static libraries for clang always be
object libraries. Is that correct? If so, this likely makes the normal
clang binary larger and less efficient than before: Normal static libraries
only get referenced .o files in them loaded, while all files in object
libraries are loaded by the linker. In theory, --gc-sections should drop
the ones that aren't needed, but due to static initializers and so on that
doesn't always work. (When we moved Chrome's build to GN, the thinking was
for a long time that we'd use object libraries instead of static libraries
everywhere. Turns out that made the binary 10% larger and slower and we had
to paddle back.)



[2523/2887] Linking CXX shared library lib/libclang_shared.so.9svn
FAILED: lib/libclang_shared.so.9svn
...
/usr/bin/ld:
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o:
relocation R_X86_64_32 against
`.rodata._ZZNR4llvm15optional_detail15OptionalStorageIiLb1EE8getValueEvE19__PRETTY_FUNCTION__'
can not be used when making a shared object; recompile with -fPIC
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o: error
adding symbols: Bad value
collect2: error: ld returned 1 exit status

On Thu, May 16, 2019 at 6:03 PM Chris Bieneman via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: cbieneman
> Date: Thu May 16 15:06:07 2019
> New Revision: 360946
>
> URL: http://llvm.org/viewvc/llvm-project?rev=360946=rev
> Log:
> Add Clang shared library with C++ exports
>
> Summary:
> This patch adds a libClang_shared library on *nix systems which exports
> the entire C++ API. In order to support this on Windows we should really
> refactor llvm-shlib and share code between the two.
>
> This also uses a slightly different method for generating the shared
> library, which I should back-port to llvm-shlib. Instead of linking the
> static archives and passing linker flags to force loading the whole
> libraries, this patch creates object libraries for every library (which has
> no cost in the build system), and link the object libraries.
>
> Reviewers: tstellar, winksaville
>
> Subscribers: mgorny, cfe-commits
>
> Tags: #clang
>
> Differential Revision: https://reviews.llvm.org/D61909
>
> Added:
> cfe/trunk/tools/clang-shlib/
> cfe/trunk/tools/clang-shlib/CMakeLists.txt
> cfe/trunk/tools/clang-shlib/clang-shlib.cpp
> Modified:
> cfe/trunk/cmake/modules/AddClang.cmake
> cfe/trunk/tools/CMakeLists.txt
>
> Modified: cfe/trunk/cmake/modules/AddClang.cmake
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=360946=360945=360946=diff
>
> ==
> --- cfe/trunk/cmake/modules/AddClang.cmake (original)
> +++ cfe/trunk/cmake/modules/AddClang.cmake Thu May 16 15:06:07 2019
> @@ -81,9 +81,12 @@ macro(add_clang_library name)
>)
>endif()
>if(ARG_SHARED)
> -set(ARG_ENABLE_SHARED SHARED)
> +set(LIBTYPE SHARED)
> +  else()
> +set(LIBTYPE STATIC OBJECT)
> +set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
>endif()
> -  llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS}
> ${srcs})
> +  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
>
>if(TARGET ${name})
>  target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
>
> Modified: cfe/trunk/tools/CMakeLists.txt
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=360946=360945=360946=diff
>
> ==
> --- cfe/trunk/tools/CMakeLists.txt (original)
> +++ cfe/trunk/tools/CMakeLists.txt Thu May 16 15:06:07 2019
> @@ -13,6 +13,9 @@ add_clang_subdirectory(c-index-test)
>
>  add_clang_subdirectory(clang-rename)
>  add_clang_subdirectory(clang-refactor)
> +if(UNIX)
> +  add_clang_subdirectory(clang-shlib)
> +endif()
>
>  if(CLANG_ENABLE_ARCMT)
>add_clang_subdirectory(arcmt-test)
>
> Added: cfe/trunk/tools/clang-shlib/CMakeLists.txt
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/CMakeLists.txt?rev=360946=auto
>
> ==
> --- cfe/trunk/tools/clang-shlib/CMakeLists.txt (added)
> +++ cfe/trunk/tools/clang-shlib/CMakeLists.txt Thu May 16 15:06:07 2019
> @@ -0,0 +1,13 @@
> +get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)
> +
> +foreach (lib ${clang_libs})
> +  list(APPEND _OBJECTS $)
> +  list(APPEND _DEPS $)
> +endforeach ()
> +
> +add_clang_library(clang_shared
> +  SHARED
> +  clang-shlib.cpp
> +  ${_OBJECTS}
> +  LINK_LIBS
> +  ${_DEPS})
>
> Added: cfe/trunk/tools/clang-shlib/clang-shlib.cpp
> URL:
> 

[PATCH] D62047: [WebAssembly] Add multivalue and tail-call target features

2019-05-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added a comment.

In D62047#1505838 , @sbc100 wrote:

> Does it make sense to support the flags before we support the feature?
>
> Otherwise lgtm.


I think this is OK; flags anyway should be added before actual feature 
implementation starts in order to add tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62047



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


[PATCH] D62047: [WebAssembly] Add multivalue and tail-call target features

2019-05-16 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin accepted this revision.
aheejin added a comment.
This revision is now accepted and ready to land.

How about using `multi-value`/`MultiValue`/`MULTI-VALUE` (depending on 
positions)? The repo name is also multi-value. 
https://github.com/WebAssembly/multi-value
Otherwise LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62047



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


[PATCH] D62046: [OpenMP][bugfix] Add missing math functions variants for log and abs.

2019-05-16 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea marked an inline comment as done.
gtbercea added inline comments.



Comment at: lib/Headers/__clang_cuda_device_functions.h:1604
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ double log(long double __a) { return __nv_log((double)__a); }
+#endif

tra wrote:
> Should the return type also be `long double` ?
> In general long double is not supported by CUDA. I'd provide a declaration 
> here, if it's absolutely needed, but no definition, so if someone  attempts 
> to actually use it, the application will fail to link.
> 
> Silently reducing precision by falling back to double is the wrong thing to 
> do, IMO.
Agreed.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62046



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


[PATCH] D62046: [OpenMP][bugfix] Add missing math functions variants for log and abs.

2019-05-16 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea marked an inline comment as done.
gtbercea added inline comments.



Comment at: lib/Headers/__clang_cuda_cmath.h:55-56
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ const float abs(const float __x) { return ::fabsf((float)__x); }
+__DEVICE__ const double abs(const double __x) { return ::fabs((double)__x); }
+#endif

tra wrote:
> Where do these functions come from?  
> https://en.cppreference.com/w/cpp/numeric/math/fabs does not seem to show any 
> `abs` functions with const args.
What's happening is that when including the random header file, this header 
file uses abs with const arguments:


```
const double __n = _M_nd(__urng);
const double __y = -std::abs(__n) * __param._M_sm - 1;
```

And without there functions here the error I get is:


```
In file included from test.c:8:
In file included from 
/usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/random:52:
/usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/bits/random.tcc:1476:27:
 error: call to 'abs' is ambiguous
const double __y = -std::abs(__n) * __param._M_sm - 1;
^~~~
/usr/include/stdlib.h:770:12: note: candidate function
extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
   ^
/usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:166:3:
 note: candidate function
  abs(long __i) { return __builtin_labs(__i); }
  ^
/usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:174:3:
 note: candidate function
  abs(long long __x) { return __builtin_llabs (__x); }
  ^
/usr/lib/gcc/ppc64le-redhat-linux/4.8.5/../../../../include/c++/4.8.5/cstdlib:179:3:
 note: candidate function
  abs(__int128 __x) { return __x >= 0 ? __x : -__x; }
  ^
```


Repository:
  rC Clang

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

https://reviews.llvm.org/D62046



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


[PATCH] D62045: Modified global variable declaration to fit updated objc guide.

2019-05-16 Thread Yaqi Ji via Phabricator via cfe-commits
yaqiji updated this revision to Diff 199944.
yaqiji added a comment.

Changes matcher, test and removed fix it hint for global constants


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62045

Files:
  clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m

Index: clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
===
--- clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
+++ clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
@@ -1,49 +1,49 @@
 // RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
 
 @class NSString;
-static NSString* const myConstString = @"hello";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* const kMyConstString = @"hello";
 
-static NSString* MyString = @"hi";
+static NSString *MyString = @"hi";
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'MyString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* gMyString = @"hi";
+// CHECK-FIXES: static NSString *gMyString = @"hi";
 
-NSString* globalString = @"test";
+NSString *globalString = @"test";
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: non-const global variable 'globalString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
-// CHECK-FIXES: NSString* gGlobalString = @"test";
+// CHECK-FIXES: NSString *gGlobalString = @"test";
 
-static NSString* a = @"too simple";
+static NSString *a = @"too simple";
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'a' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* a = @"too simple";
+// CHECK-FIXES: static NSString *a = @"too simple";
 
-static NSString* noDef;
+static NSString *noDef;
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'noDef' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* gNoDef;
+// CHECK-FIXES: static NSString *gNoDef;
 
-static NSString* const _notAlpha = @"NotBeginWithAlpha";
+static NSString *const _notAlpha = @"NotBeginWithAlpha";
 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable '_notAlpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* const _notAlpha = @"NotBeginWithAlpha";
 
-static NSString* const k_Alpha = @"SecondNotAlpha";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'k_Alpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";
+static NSString *const notCap = @"NotBeginWithCap";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'notCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
 
-static NSString* const kGood = @"hello";
-static NSString* const XYGood = @"hello";
-static NSString* gMyIntGood = 0;
+static NSString *const A_Alpha = @"SecondNotAlpha";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'A_Alpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
 
-extern NSString* const GTLServiceErrorDomain;
+static NSString *const SecondNotCap = @"SecondNotCapOrNumber";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'SecondNotCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+
+static NSString *const XYGood = @"hello";
+static NSString *gMyIntGood = 0;
+
+extern NSString *const GTLServiceErrorDomain;
 
 enum GTLServiceError {
   GTLServiceErrorQueryResultMissing = -3000,
-  GTLServiceErrorWaitTimedOut   = -3001,
+  GTLServiceErrorWaitTimedOut = -3001,
 };
 
 @implementation Foo
 - (void)f {
-int x = 0;
-static int bar;
-static const int baz = 42;
+  int x = 0;
+  static int bar;
+  static const int baz = 42;
 }
 @end
Index: clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -23,34 +23,39 @@
 
 namespace {
 
-AST_MATCHER(VarDecl, isLocalVariable) {
-  return Node.isLocalVarDecl();
-}
+AST_MATCHER(VarDecl, isLocalVariable) { return Node.isLocalVarDecl(); }

[PATCH] D61838: [Sema] Suppress additional warnings for C's zero initializer

2019-05-16 Thread Peter Wu via Phabricator via cfe-commits
Lekensteyn accepted this revision.
Lekensteyn added a comment.
This revision is now accepted and ready to land.

Thanks, I have also verified this patch against the above test case.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61838



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


[PATCH] D62047: [WebAssembly] Add multivalue and tail-call target features

2019-05-16 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 added a comment.

Does it make sense to support the flags before we support the feature?

Otherwise lgtm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62047



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


[PATCH] D61989: [clang-tidy] enable modernize-concat-nested-namespaces on header files

2019-05-16 Thread Xiao Shi via Phabricator via cfe-commits
shixiao updated this revision to Diff 199942.
shixiao added a subscriber: Eugene.Zelenko.
shixiao added a comment.

edit doc, add note in release notes, extend unit test to test transitive header 
includes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61989

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-concat-nested-namespaces.rst
  clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.cpp
  clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.h
  clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces2.h

Index: clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces2.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces2.h
@@ -0,0 +1,9 @@
+#pragma once
+
+namespace foo {
+namespace bar {
+namespace baz {
+struct S2 {};
+} // namespace baz
+} // namespace bar
+} // namespace foo
Index: clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "modernize-concat-nested-namespaces2.h"
+
+namespace foo {
+namespace bar {
+namespace baz {
+struct S {};
+} // namespace baz
+} // namespace bar
+} // namespace foo
Index: clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.cpp
@@ -1,4 +1,7 @@
-// RUN: %check_clang_tidy %s modernize-concat-nested-namespaces %t -- -- -std=c++17
+// RUN: cp %S/modernize-concat-nested-namespaces*.h %T
+// RUN: %check_clang_tidy %s modernize-concat-nested-namespaces %t -- -header-filter="concat" -- -std=c++17 -I %T
+
+#include "modernize-concat-nested-namespaces.h"
 
 namespace n1 {}
 
@@ -159,3 +162,8 @@
 
   return 0;
 }
+
+// Checks for header file:
+
+// CHECK-MESSAGES: modernize-concat-nested-namespaces.h:{{.*}} warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-MESSAGES: modernize-concat-nested-namespaces2.h:{{.*}} warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
Index: clang-tools-extra/docs/clang-tidy/checks/modernize-concat-nested-namespaces.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize-concat-nested-namespaces.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize-concat-nested-namespaces.rst
@@ -47,3 +47,13 @@
   }
   }
 
+Options
+---
+
+.. option:: HeaderFileExtensions
+
+   A comma-separated list of filename extensions of header files (the filename
+   extensions should not contain "." prefix). Default is `h,hh,hpp,hxx`.
+   For header files without an extension, use an empty string (if there are no
+   other desired extensions) or leave an empty element in the list. e.g.,
+   `h,hh,hpp,hxx,` (note the trailing comma).
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -138,6 +138,11 @@
   :doc:`objc-property-declaration `
   check have been removed.
 
+- The :doc:`modernize-concat-nested-namespaces
+  ` now supports
+  `HeaderFileExtensions` option and issues warnings for transitively included
+  header files that passes the header filter.
+
 - The :doc:`modernize-use-override
   ` now supports `OverrideSpelling`
   and `FinalSpelling` options.
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_CONCATNESTEDNAMESPACESCHECK_H
 
 #include "../ClangTidyCheck.h"
+#include "../utils/HeaderFileExtensionsUtils.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 
@@ -17,10 +18,16 @@
 namespace tidy {
 namespace modernize {
 
+/// The check supports these options:
+///   - `HeaderFileExtensions`: a comma-separated list of filename extensions of
+/// header files (The filename extensions should not contain "." prefix).
+/// "h,hh,hpp,hxx" by default.
+/// For extension-less header files, using an empty string or leaving an
+/// empty string 

[PATCH] D62047: [WebAssembly] Add multivalue and tail-call target features

2019-05-16 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added a reviewer: aheejin.
Herald added subscribers: llvm-commits, cfe-commits, sunfish, hiraditya, 
jgravelle-google, sbc100, dschuff.
Herald added projects: clang, LLVM.

These features will both be implemented soon, so I thought I would
save time by adding the boilerplate for both of them at the same time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62047

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/WebAssembly.cpp
  clang/lib/Basic/Targets/WebAssembly.h
  clang/test/Preprocessor/wasm-target-features.c
  llvm/lib/Target/WebAssembly/WebAssembly.td
  llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
  llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
  llvm/test/CodeGen/WebAssembly/multivalue.ll
  llvm/test/CodeGen/WebAssembly/tailcall.ll

Index: llvm/test/CodeGen/WebAssembly/tailcall.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/tailcall.ll
@@ -0,0 +1,21 @@
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+tail-call | FileCheck %s
+
+; Test that the tail-call attribute is accepted
+; TODO(tlively): implement tail call
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+; CHECK-LABEL: recursive_tail:
+; CHECK:  i32.call $push[[L0:[0-9]+]]=, recursive_tail{{$}}
+; CHECK-NEXT: return $pop[[L0]]{{$}}
+define i32 @recursive_tail() {
+  %v = tail call i32 @recursive_tail()
+  ret i32 %v
+}
+
+; CHECK-LABEL: .section .custom_section.target_features
+; CHECK-NEXT: .int8 1
+; CHECK-NEXT: .int8 43
+; CHECK-NEXT: .int8 9
+; CHECK-NEXT: .ascii "tail-call"
Index: llvm/test/CodeGen/WebAssembly/multivalue.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/multivalue.ll
@@ -0,0 +1,28 @@
+; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+multivalue | FileCheck %s
+
+; Test that the multivalue attribute is accepted
+; TODO(tlively): implement multivalue
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+%pair = type { i32, i32 }
+%packed_pair = type <{ i32, i32 }>
+
+; CHECK-LABEL: sret:
+; CHECK-NEXT: sret (i32, i32, i32) -> ()
+define %pair @sret(%pair %p) {
+  ret %pair %p
+}
+
+; CHECK-LABEL: packed_sret:
+; CHECK-NEXT: packed_sret (i32, i32, i32) -> ()
+define %packed_pair @packed_sret(%packed_pair %p) {
+  ret %packed_pair %p
+}
+
+; CHECK-LABEL: .section .custom_section.target_features
+; CHECK-NEXT: .int8 1
+; CHECK-NEXT: .int8 43
+; CHECK-NEXT: .int8 10
+; CHECK-NEXT: .ascii "multivalue"
Index: llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
===
--- llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
+++ llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
@@ -44,7 +44,9 @@
   bool HasSignExt = false;
   bool HasExceptionHandling = false;
   bool HasBulkMemory = false;
+  bool HasMultivalue = false;
   bool HasMutableGlobals = false;
+  bool HasTailCall = false;
 
   /// String name of used CPU.
   std::string CPUString;
@@ -98,7 +100,9 @@
   bool hasSignExt() const { return HasSignExt; }
   bool hasExceptionHandling() const { return HasExceptionHandling; }
   bool hasBulkMemory() const { return HasBulkMemory; }
+  bool hasMultivalue() const { return HasMultivalue; }
   bool hasMutableGlobals() const { return HasMutableGlobals; }
+  bool hasTailCall() const { return HasTailCall; }
 
   /// Parses features string setting specified subtarget options. Definition of
   /// function is auto generated by tblgen.
Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
===
--- llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
+++ llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td
@@ -34,6 +34,10 @@
 Predicate<"Subtarget->hasAtomics()">,
 AssemblerPredicate<"FeatureAtomics", "atomics">;
 
+def HasMultivalue :
+Predicate<"Subtarget->hasMultivalue()">,
+AssemblerPredicate<"FeatureMultivalue", "multivalue">;
+
 def HasNontrappingFPToInt :
 Predicate<"Subtarget->hasNontrappingFPToInt()">,
 AssemblerPredicate<"FeatureNontrappingFPToInt", "nontrapping-fptoint">;
@@ -46,18 +50,14 @@
 Predicate<"Subtarget->hasSignExt()">,
 AssemblerPredicate<"FeatureSignExt", "sign-ext">;
 
-def NotHasSignExt :
-Predicate<"!Subtarget->hasSignExt()">,
-AssemblerPredicate<"!FeatureSignExt", "sign-ext">;
+def HasTailCall :
+Predicate<"Subtarget->hasTailCall()">,
+AssemblerPredicate<"FeatureTailCall", "tail-call">;
 
 def HasExceptionHandling :
 Predicate<"Subtarget->hasExceptionHandling()">,
 

[PATCH] D62045: Modified global variable declaration to fit updated objc guide.

2019-05-16 Thread Yaqi Ji via Phabricator via cfe-commits
yaqiji updated this revision to Diff 199939.
yaqiji added a comment.

Modified code to make it more readable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62045

Files:
  clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m

Index: clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
===
--- clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
+++ clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
@@ -1,49 +1,57 @@
 // RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
 
 @class NSString;
-static NSString* const myConstString = @"hello";
+static NSString *const myConstString = @"hello";
 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const kMyConstString = @"hello";
 
-static NSString* MyString = @"hi";
+static NSString *MyString = @"hi";
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'MyString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* gMyString = @"hi";
 
-NSString* globalString = @"test";
+NSString *globalString = @"test";
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: non-const global variable 'globalString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: NSString* gGlobalString = @"test";
 
-static NSString* a = @"too simple";
+static NSString *a = @"too simple";
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'a' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* a = @"too simple";
 
-static NSString* noDef;
+static NSString *noDef;
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'noDef' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* gNoDef;
 
-static NSString* const _notAlpha = @"NotBeginWithAlpha";
+static NSString *const _notAlpha = @"NotBeginWithAlpha";
 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable '_notAlpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const _notAlpha = @"NotBeginWithAlpha";
 
-static NSString* const k_Alpha = @"SecondNotAlpha";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'k_Alpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";
+static NSString *const notCap = @"NotBeginWithCap";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'notCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const notCap = @"NotBeginWithCap";
 
-static NSString* const kGood = @"hello";
-static NSString* const XYGood = @"hello";
-static NSString* gMyIntGood = 0;
+static NSString *const A_Alpha = @"SecondNotAlpha";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'A_Alpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const A_Alpha = @"SecondNotAlpha";
 
-extern NSString* const GTLServiceErrorDomain;
+static NSString *const SecondNotCap = @"SecondNotCapOrNumber";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'SecondNotCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const SecondNotCap = @"SecondNotCapOrNumber";
+
+static NSString *const kGood = @"hello";
+static NSString *const XYGood = @"hello";
+static NSString *gMyIntGood = 0;
+
+extern NSString *const GTLServiceErrorDomain;
 
 enum GTLServiceError {
   GTLServiceErrorQueryResultMissing = -3000,
-  GTLServiceErrorWaitTimedOut   = -3001,
+  GTLServiceErrorWaitTimedOut = -3001,
 };
 
 @implementation Foo
 - (void)f {
-int x = 0;
-static int bar;
-static const int baz = 42;
+  int x = 0;
+  static int bar;
+  static const int baz = 42;
 }
 @end
Index: clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -23,34 +23,35 @@
 
 namespace {
 
-AST_MATCHER(VarDecl, isLocalVariable) {
-  return 

[PATCH] D61989: [clang-tidy] enable modernize-concat-nested-namespaces on header files

2019-05-16 Thread Xiao Shi via Phabricator via cfe-commits
shixiao updated this revision to Diff 199940.
shixiao marked 2 inline comments as done.
shixiao edited the summary of this revision.
shixiao removed a subscriber: Eugene.Zelenko.
shixiao removed a project: clang-tools-extra.
shixiao added a comment.

elide braces for single-stmt if-s, extend unit test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61989

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  
clang-tools-extra/docs/clang-tidy/checks/modernize-concat-nested-namespaces.rst
  clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.cpp
  clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.h

Index: clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.h
@@ -0,0 +1,9 @@
+#pragma once
+
+namespace foo {
+namespace bar {
+namespace baz {
+struct S {};
+} // namespace baz
+} // namespace bar
+} // namespace foo
Index: clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.cpp
@@ -1,4 +1,7 @@
-// RUN: %check_clang_tidy %s modernize-concat-nested-namespaces %t -- -- -std=c++17
+// RUN: cp %S/modernize-concat-nested-namespaces.h %T/modernize-concat-nested-namespaces.h
+// RUN: %check_clang_tidy %s modernize-concat-nested-namespaces %t -- -header-filter="concat" -- -std=c++17 -I %T
+
+#include "modernize-concat-nested-namespaces.h"
 
 namespace n1 {}
 
@@ -159,3 +162,7 @@
 
   return 0;
 }
+
+// Checks for header file:
+
+// CHECK-MESSAGES: modernize-concat-nested-namespaces.h:{{.*}} warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
Index: clang-tools-extra/docs/clang-tidy/checks/modernize-concat-nested-namespaces.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize-concat-nested-namespaces.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize-concat-nested-namespaces.rst
@@ -47,3 +47,13 @@
   }
   }
 
+Options
+---
+
+.. option:: HeaderFileExtensions
+
+   A comma-separated list of filename extensions of header files (the filename
+   extensions should not contain "." prefix). Default is "h,hh,hpp,hxx".
+   For header files without an extension, use an empty string (if there are no
+   other desired extensions) or leave an empty element in the list. e.g.,
+   "h,hh,hpp,hxx," (note the trailing comma).
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_CONCATNESTEDNAMESPACESCHECK_H
 
 #include "../ClangTidyCheck.h"
+#include "../utils/HeaderFileExtensionsUtils.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 
@@ -17,10 +18,16 @@
 namespace tidy {
 namespace modernize {
 
+/// The check supports these options:
+///   - `HeaderFileExtensions`: a comma-separated list of filename extensions of
+/// header files (The filename extensions should not contain "." prefix).
+/// "h,hh,hpp,hxx" by default.
+/// For extension-less header files, using an empty string or leaving an
+/// empty string between "," if there are other filename extensions.
 class ConcatNestedNamespacesCheck : public ClangTidyCheck {
 public:
-  ConcatNestedNamespacesCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  ConcatNestedNamespacesCheck(StringRef Name, ClangTidyContext *Context);
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 
@@ -32,6 +39,8 @@
 const SourceRange );
   NamespaceString concatNamespaces();
   NamespaceContextVec Namespaces;
+  const std::string RawStringHeaderFileExtensions;
+  utils::HeaderFileExtensionsSet HeaderFileExtensions;
 };
 } // namespace modernize
 } // namespace tidy
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -61,6 +61,22 @@
   return Result;
 }
 

[PATCH] D62046: [OpenMP][bugfix] Add missing math functions variants for log and abs.

2019-05-16 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: lib/Headers/__clang_cuda_cmath.h:55-56
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ const float abs(const float __x) { return ::fabsf((float)__x); }
+__DEVICE__ const double abs(const double __x) { return ::fabs((double)__x); }
+#endif

Where do these functions come from?  
https://en.cppreference.com/w/cpp/numeric/math/fabs does not seem to show any 
`abs` functions with const args.



Comment at: lib/Headers/__clang_cuda_device_functions.h:1604
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ double log(long double __a) { return __nv_log((double)__a); }
+#endif

Should the return type also be `long double` ?
In general long double is not supported by CUDA. I'd provide a declaration 
here, if it's absolutely needed, but no definition, so if someone  attempts to 
actually use it, the application will fail to link.

Silently reducing precision by falling back to double is the wrong thing to do, 
IMO.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62046



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


[PATCH] D62046: [OpenMP][bugfix] Add missing math functions variants for log and abs.

2019-05-16 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea created this revision.
gtbercea added reviewers: jdoerfert, hfinkel, tra, caomhin.
Herald added subscribers: cfe-commits, guansong.
Herald added a project: clang.

When including the random header in C++, some of the math functions it relies 
on are not present in the CUDA headers. We include this variants in this case.


Repository:
  rC Clang

https://reviews.llvm.org/D62046

Files:
  lib/Headers/__clang_cuda_cmath.h
  lib/Headers/__clang_cuda_device_functions.h
  lib/Headers/__clang_cuda_math_forward_declares.h


Index: lib/Headers/__clang_cuda_math_forward_declares.h
===
--- lib/Headers/__clang_cuda_math_forward_declares.h
+++ lib/Headers/__clang_cuda_math_forward_declares.h
@@ -42,6 +42,10 @@
 __DEVICE__ double abs(double);
 __DEVICE__ float abs(float);
 #endif
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ const double abs(const double);
+__DEVICE__ const float abs(const float);
+#endif
 __DEVICE__ int abs(int) __NOEXCEPT;
 __DEVICE__ double acos(double);
 __DEVICE__ float acos(float);
@@ -144,6 +148,9 @@
 __DEVICE__ float log2(float);
 __DEVICE__ double logb(double);
 __DEVICE__ float logb(float);
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ double log(long double);
+#endif
 __DEVICE__ double log(double);
 __DEVICE__ float log(float);
 __DEVICE__ long lrint(double);
Index: lib/Headers/__clang_cuda_device_functions.h
===
--- lib/Headers/__clang_cuda_device_functions.h
+++ lib/Headers/__clang_cuda_device_functions.h
@@ -1600,6 +1600,9 @@
 __DEVICE__ long long llrintf(float __a) { return __nv_llrintf(__a); }
 __DEVICE__ long long llround(double __a) { return __nv_llround(__a); }
 __DEVICE__ long long llroundf(float __a) { return __nv_llroundf(__a); }
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ double log(long double __a) { return __nv_log((double)__a); }
+#endif
 __DEVICE__ double log(double __a) { return __nv_log(__a); }
 __DEVICE__ double log10(double __a) { return __nv_log10(__a); }
 __DEVICE__ float log10f(float __a) { return __nv_log10f(__a); }
Index: lib/Headers/__clang_cuda_cmath.h
===
--- lib/Headers/__clang_cuda_cmath.h
+++ lib/Headers/__clang_cuda_cmath.h
@@ -51,6 +51,10 @@
 __DEVICE__ float abs(float __x) { return ::fabsf(__x); }
 __DEVICE__ double abs(double __x) { return ::fabs(__x); }
 #endif
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ const float abs(const float __x) { return ::fabsf((float)__x); }
+__DEVICE__ const double abs(const double __x) { return ::fabs((double)__x); }
+#endif
 __DEVICE__ float acos(float __x) { return ::acosf(__x); }
 __DEVICE__ float asin(float __x) { return ::asinf(__x); }
 __DEVICE__ float atan(float __x) { return ::atanf(__x); }


Index: lib/Headers/__clang_cuda_math_forward_declares.h
===
--- lib/Headers/__clang_cuda_math_forward_declares.h
+++ lib/Headers/__clang_cuda_math_forward_declares.h
@@ -42,6 +42,10 @@
 __DEVICE__ double abs(double);
 __DEVICE__ float abs(float);
 #endif
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ const double abs(const double);
+__DEVICE__ const float abs(const float);
+#endif
 __DEVICE__ int abs(int) __NOEXCEPT;
 __DEVICE__ double acos(double);
 __DEVICE__ float acos(float);
@@ -144,6 +148,9 @@
 __DEVICE__ float log2(float);
 __DEVICE__ double logb(double);
 __DEVICE__ float logb(float);
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ double log(long double);
+#endif
 __DEVICE__ double log(double);
 __DEVICE__ float log(float);
 __DEVICE__ long lrint(double);
Index: lib/Headers/__clang_cuda_device_functions.h
===
--- lib/Headers/__clang_cuda_device_functions.h
+++ lib/Headers/__clang_cuda_device_functions.h
@@ -1600,6 +1600,9 @@
 __DEVICE__ long long llrintf(float __a) { return __nv_llrintf(__a); }
 __DEVICE__ long long llround(double __a) { return __nv_llround(__a); }
 __DEVICE__ long long llroundf(float __a) { return __nv_llroundf(__a); }
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ double log(long double __a) { return __nv_log((double)__a); }
+#endif
 __DEVICE__ double log(double __a) { return __nv_log(__a); }
 __DEVICE__ double log10(double __a) { return __nv_log10(__a); }
 __DEVICE__ float log10f(float __a) { return __nv_log10f(__a); }
Index: lib/Headers/__clang_cuda_cmath.h
===
--- lib/Headers/__clang_cuda_cmath.h
+++ lib/Headers/__clang_cuda_cmath.h
@@ -51,6 +51,10 @@
 __DEVICE__ float abs(float __x) { return ::fabsf(__x); }
 __DEVICE__ double abs(double __x) { return ::fabs(__x); }
 #endif
+#if defined(_OPENMP) && defined(__cplusplus)
+__DEVICE__ const float abs(const float __x) { return ::fabsf((float)__x); }
+__DEVICE__ const double abs(const 

[PATCH] D62045: Modified global variable declaraction to fit updated objc guide.

2019-05-16 Thread Yaqi Ji via Phabricator via cfe-commits
yaqiji updated this revision to Diff 199931.
yaqiji added a comment.

removed unnecessary lines


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62045

Files:
  clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m

Index: clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
===
--- clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
+++ clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
@@ -1,49 +1,57 @@
 // RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
 
 @class NSString;
-static NSString* const myConstString = @"hello";
+static NSString *const myConstString = @"hello";
 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const kMyConstString = @"hello";
 
-static NSString* MyString = @"hi";
+static NSString *MyString = @"hi";
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'MyString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* gMyString = @"hi";
 
-NSString* globalString = @"test";
+NSString *globalString = @"test";
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: non-const global variable 'globalString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: NSString* gGlobalString = @"test";
 
-static NSString* a = @"too simple";
+static NSString *a = @"too simple";
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'a' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* a = @"too simple";
 
-static NSString* noDef;
+static NSString *noDef;
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'noDef' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* gNoDef;
 
-static NSString* const _notAlpha = @"NotBeginWithAlpha";
+static NSString *const _notAlpha = @"NotBeginWithAlpha";
 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable '_notAlpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const _notAlpha = @"NotBeginWithAlpha";
 
-static NSString* const k_Alpha = @"SecondNotAlpha";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'k_Alpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";
+static NSString *const notCap = @"NotBeginWithCap";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'notCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const notCap = @"NotBeginWithCap";
 
-static NSString* const kGood = @"hello";
-static NSString* const XYGood = @"hello";
-static NSString* gMyIntGood = 0;
+static NSString *const A_Alpha = @"SecondNotAlpha";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'A_Alpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const A_Alpha = @"SecondNotAlpha";
 
-extern NSString* const GTLServiceErrorDomain;
+static NSString *const SecondNotCap = @"SecondNotCapOrNumber";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'SecondNotCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const SecondNotCap = @"SecondNotCapOrNumber";
+
+static NSString *const kGood = @"hello";
+static NSString *const XYGood = @"hello";
+static NSString *gMyIntGood = 0;
+
+extern NSString *const GTLServiceErrorDomain;
 
 enum GTLServiceError {
   GTLServiceErrorQueryResultMissing = -3000,
-  GTLServiceErrorWaitTimedOut   = -3001,
+  GTLServiceErrorWaitTimedOut = -3001,
 };
 
 @implementation Foo
 - (void)f {
-int x = 0;
-static int bar;
-static const int baz = 42;
+  int x = 0;
+  static int bar;
+  static const int baz = 42;
 }
 @end
Index: clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -23,34 +23,36 @@
 
 namespace {
 
-AST_MATCHER(VarDecl, isLocalVariable) {
-  return Node.isLocalVarDecl();
-}

[PATCH] D62045: Modified global variable declaraction to fit updated objc guide.

2019-05-16 Thread Yaqi Ji via Phabricator via cfe-commits
yaqiji updated this revision to Diff 199932.
yaqiji added a comment.

Removed unncessary comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62045

Files:
  clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m

Index: clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
===
--- clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
+++ clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
@@ -1,49 +1,57 @@
 // RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
 
 @class NSString;
-static NSString* const myConstString = @"hello";
+static NSString *const myConstString = @"hello";
 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const kMyConstString = @"hello";
 
-static NSString* MyString = @"hi";
+static NSString *MyString = @"hi";
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'MyString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* gMyString = @"hi";
 
-NSString* globalString = @"test";
+NSString *globalString = @"test";
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: non-const global variable 'globalString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: NSString* gGlobalString = @"test";
 
-static NSString* a = @"too simple";
+static NSString *a = @"too simple";
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'a' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* a = @"too simple";
 
-static NSString* noDef;
+static NSString *noDef;
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'noDef' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* gNoDef;
 
-static NSString* const _notAlpha = @"NotBeginWithAlpha";
+static NSString *const _notAlpha = @"NotBeginWithAlpha";
 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable '_notAlpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const _notAlpha = @"NotBeginWithAlpha";
 
-static NSString* const k_Alpha = @"SecondNotAlpha";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'k_Alpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";
+static NSString *const notCap = @"NotBeginWithCap";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'notCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const notCap = @"NotBeginWithCap";
 
-static NSString* const kGood = @"hello";
-static NSString* const XYGood = @"hello";
-static NSString* gMyIntGood = 0;
+static NSString *const A_Alpha = @"SecondNotAlpha";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'A_Alpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const A_Alpha = @"SecondNotAlpha";
 
-extern NSString* const GTLServiceErrorDomain;
+static NSString *const SecondNotCap = @"SecondNotCapOrNumber";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'SecondNotCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const SecondNotCap = @"SecondNotCapOrNumber";
+
+static NSString *const kGood = @"hello";
+static NSString *const XYGood = @"hello";
+static NSString *gMyIntGood = 0;
+
+extern NSString *const GTLServiceErrorDomain;
 
 enum GTLServiceError {
   GTLServiceErrorQueryResultMissing = -3000,
-  GTLServiceErrorWaitTimedOut   = -3001,
+  GTLServiceErrorWaitTimedOut = -3001,
 };
 
 @implementation Foo
 - (void)f {
-int x = 0;
-static int bar;
-static const int baz = 42;
+  int x = 0;
+  static int bar;
+  static const int baz = 42;
 }
 @end
Index: clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -23,34 +23,35 @@
 
 namespace {
 
-AST_MATCHER(VarDecl, isLocalVariable) {
-  return Node.isLocalVarDecl();
-}

[PATCH] D62045: Modified global variable declaraction to fit updated objc guide.

2019-05-16 Thread Yaqi Ji via Phabricator via cfe-commits
yaqiji created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
yaqiji updated this revision to Diff 199931.
yaqiji added a comment.
yaqiji updated this revision to Diff 199932.

removed unnecessary lines


yaqiji added a comment.

Removed unncessary comments.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D62045

Files:
  clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m

Index: clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
===
--- clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
+++ clang-tools-extra/test/clang-tidy/google-objc-global-variable-declaration.m
@@ -1,49 +1,57 @@
 // RUN: %check_clang_tidy %s google-objc-global-variable-declaration %t
 
 @class NSString;
-static NSString* const myConstString = @"hello";
+static NSString *const myConstString = @"hello";
 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'myConstString' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const kMyConstString = @"hello";
 
-static NSString* MyString = @"hi";
+static NSString *MyString = @"hi";
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'MyString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* gMyString = @"hi";
 
-NSString* globalString = @"test";
+NSString *globalString = @"test";
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: non-const global variable 'globalString' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: NSString* gGlobalString = @"test";
 
-static NSString* a = @"too simple";
+static NSString *a = @"too simple";
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'a' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* a = @"too simple";
 
-static NSString* noDef;
+static NSString *noDef;
 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: non-const global variable 'noDef' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* gNoDef;
 
-static NSString* const _notAlpha = @"NotBeginWithAlpha";
+static NSString *const _notAlpha = @"NotBeginWithAlpha";
 // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable '_notAlpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
 // CHECK-FIXES: static NSString* const _notAlpha = @"NotBeginWithAlpha";
 
-static NSString* const k_Alpha = @"SecondNotAlpha";
-// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'k_Alpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
-// CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";
+static NSString *const notCap = @"NotBeginWithCap";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'notCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const notCap = @"NotBeginWithCap";
 
-static NSString* const kGood = @"hello";
-static NSString* const XYGood = @"hello";
-static NSString* gMyIntGood = 0;
+static NSString *const A_Alpha = @"SecondNotAlpha";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'A_Alpha' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const A_Alpha = @"SecondNotAlpha";
 
-extern NSString* const GTLServiceErrorDomain;
+static NSString *const SecondNotCap = @"SecondNotCapOrNumber";
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: const global variable 'SecondNotCap' must have a name which starts with an appropriate prefix [google-objc-global-variable-declaration]
+// CHECK-FIXES: static NSString* const SecondNotCap = @"SecondNotCapOrNumber";
+
+static NSString *const kGood = @"hello";
+static NSString *const XYGood = @"hello";
+static NSString *gMyIntGood = 0;
+
+extern NSString *const GTLServiceErrorDomain;
 
 enum GTLServiceError {
   GTLServiceErrorQueryResultMissing = -3000,
-  GTLServiceErrorWaitTimedOut   = -3001,
+  GTLServiceErrorWaitTimedOut = -3001,
 };
 
 @implementation Foo
 - (void)f {
-int x = 0;
-static int bar;
-static const int baz = 42;
+  int x = 0;
+  static int bar;
+  static const int baz = 42;
 }
 @end
Index: clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tools-extra/clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ 

[PATCH] D61967: [clang-tidy] Add a close-on-exec check on pipe() in Android module.

2019-05-16 Thread Jian Cai via Phabricator via cfe-commits
jcai19 marked 2 inline comments as done.
jcai19 added inline comments.



Comment at: clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp:27
+void CloexecPipeCheck::check(const MatchFinder::MatchResult ) {
+  const std::string  =
+  (Twine("pipe2(") + getSpellingArg(Result, 0) + ", O_CLOEXEC)").str();

george.burgess.iv wrote:
> jcai19 wrote:
> > george.burgess.iv wrote:
> > > simplicity nit: can this be a `std::string`?
> > replaceFunc takes a llvm::StringRef as the third parameter. StringRef is 
> > "expected to be used in situations where the character data resides in some 
> > other buffer, whose lifetime extends past that of the StringRef", which is 
> > true in this case, so I think it should be fine.
> Both should be functionally equivalent in this code. My point was that it's 
> not common to rely on temporary lifetime extension when writing the 
> non-`const&` type would be equivalent (barring maybe cases with `auto`, but 
> that's not applicable), and I don't see why we should break with that here.
Make sense.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61967



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


[PATCH] D61967: [clang-tidy] Add a close-on-exec check on pipe() in Android module.

2019-05-16 Thread Jian Cai via Phabricator via cfe-commits
jcai19 updated this revision to Diff 199926.
jcai19 added a comment.

Use non-const& type for readbility.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61967

Files:
  clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp
  clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/android-cloexec-pipe.cpp

Index: clang-tools-extra/test/clang-tidy/android-cloexec-pipe.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/android-cloexec-pipe.cpp
@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s android-cloexec-pipe %t
+
+extern "C" int pipe(int pipefd[2]);
+
+void f() {
+  int pipefd[2];
+  pipe(pipefd);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer pipe2() to pipe() because pipe2() allows O_CLOEXEC [android-cloexec-pipe]
+  // CHECK-FIXES: pipe2(pipefd, O_CLOEXEC);
+}
+
+namespace i {
+int pipe(int pipefd[2]);
+void g() {
+  int pipefd[2];
+  pipe(pipefd);
+}
+} // namespace i
+
+class C {
+public:
+  int pipe(int pipefd[2]);
+  void h() {
+int pipefd[2];
+pipe(pipefd);
+  }
+};
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
@@ -32,6 +32,7 @@
android-cloexec-inotify-init1
android-cloexec-memfd-create
android-cloexec-open
+   android-cloexec-pipe
android-cloexec-socket
android-comparison-in-temp-failure-retry
boost-use-to-string
Index: clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - android-cloexec-pipe
+
+android-cloexec-pipe
+
+
+Detects usage of ``pipe()``. The usage of ``pipe()`` is not recommended, it's better to use ``pipe2()``.
+Without this flag, an opened sensitive file descriptor would remain open across
+a ``fork``+``exec`` to a lower-privileged SELinux domain.
+
+Examples:
+
+.. code-block:: c++
+
+  pipe(pipefd);
+
+  // becomes
+
+  pipe2(pipefd, O_CLOEXEC);
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -101,6 +101,11 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`android-cloexec-pipe
+  ` check.
+
+  Detects usage of ``pipe()``.
+
 - New :doc:`bugprone-unhandled-self-assignment
   ` check.
 
Index: clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h
@@ -0,0 +1,34 @@
+//===--- CloexecPipeCheck.h - clang-tidy---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// pipe() is better to be replaced by pipe2().
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-pipe.html
+class CloexecPipeCheck : public CloexecCheck {
+public:
+  CloexecPipeCheck(StringRef Name, ClangTidyContext *Context)
+  : CloexecCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
Index: clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp
@@ -0,0 +1,37 @@
+//===--- CloexecPipeCheck.cpp - clang-tidy---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for 

r360951 - Remove unneeded alignment spec from builtin_FUNCTION.cpp test

2019-05-16 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu May 16 16:07:45 2019
New Revision: 360951

URL: http://llvm.org/viewvc/llvm-project?rev=360951=rev
Log:
Remove unneeded alignment spec from builtin_FUNCTION.cpp test

Modified:
cfe/trunk/test/CodeGenCXX/builtin_FUNCTION.cpp

Modified: cfe/trunk/test/CodeGenCXX/builtin_FUNCTION.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/builtin_FUNCTION.cpp?rev=360951=360950=360951=diff
==
--- cfe/trunk/test/CodeGenCXX/builtin_FUNCTION.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/builtin_FUNCTION.cpp Thu May 16 16:07:45 2019
@@ -8,10 +8,10 @@ constexpr const char *test_default_arg(c
 }
 // CHECK: @[[EMPTY_STR:.+]] = private unnamed_addr constant [1 x i8] 
zeroinitializer, align 1
 
-// CHECK: @_ZN9test_func6globalE = {{(dso_local )?}}global i8* getelementptr 
inbounds ([1 x i8], [1 x i8]* @[[EMPTY_STR]], i32 0, i32 0), align 8
+// CHECK: @_ZN9test_func6globalE = {{(dso_local )?}}global i8* getelementptr 
inbounds ([1 x i8], [1 x i8]* @[[EMPTY_STR]], i32 0, i32 0)
 const char *global = test_default_arg();
 
-// CHECK: @_ZN9test_func10global_twoE = {{(dso_local )?}}global i8* 
getelementptr inbounds ([1 x i8], [1 x i8]* @[[EMPTY_STR]], i32 0, i32 0), 
align 8
+// CHECK: @_ZN9test_func10global_twoE = {{(dso_local )?}}global i8* 
getelementptr inbounds ([1 x i8], [1 x i8]* @[[EMPTY_STR]], i32 0, i32 0)
 const char *global_two = __builtin_FUNCTION();
 
 const char * const global_three = test_default_arg();


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


[PATCH] D61974: [ObjC] Fix encoding of ObjC pointer types that are pointers to typedefs

2019-05-16 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked an inline comment as done.
ahatanak added inline comments.



Comment at: lib/AST/ASTContext.cpp:6973
 QualType PointeeTy = OPT->getPointeeType();
-if (!Options.EncodingProperty() &&
+if (getLangOpts().ObjCRuntime.isGNUFamily() &&
+!Options.EncodingProperty() &&

theraven wrote:
> Please can we at least make this check just for the GCC runtime?  I'm not 
> sure it's even needed there.  I've previously had to write code that works 
> around this and have always considered it a bug in GCC, rather than a feature 
> that I'd like us to copy, so I'd also be happy with just deleting this code 
> path entirely.
> 
Are we allowed to delete the code path entirely? That would clean up the code a 
bit, but I assume it would also break GCC runtime users' code.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61974



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


[PATCH] D59464: [analyzer] Add an example plugin for checker dependency handling

2019-05-16 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D59464#1505682 , @Szelethus wrote:

> In that case, feel free to revert this. If around 11:00 CET time I tried to 
> recommit with a possible fix (while watching your bots), would that be an 
> issue?


I managed to reproduce this locally so I'm going to see if there's an easy way 
to fix this.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59464



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


[PATCH] D61834: Add a Visit overload for DynTypedNode to ASTNodeTraverser

2019-05-16 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 199922.
steveire added a comment.
Herald added a subscriber: mgorny.

Add basic traverser test


Repository:
  rC Clang

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

https://reviews.llvm.org/D61834

Files:
  include/clang/AST/ASTNodeTraverser.h
  unittests/AST/ASTTraverserTest.cpp
  unittests/AST/CMakeLists.txt

Index: unittests/AST/CMakeLists.txt
===
--- unittests/AST/CMakeLists.txt
+++ unittests/AST/CMakeLists.txt
@@ -12,6 +12,7 @@
   ASTImporterTest.cpp
   ASTImporterGenericRedeclTest.cpp
   ASTImporterVisibilityTest.cpp
+  ASTTraverserTest.cpp
   ASTTypeTraitsTest.cpp
   ASTVectorTest.cpp
   CommentLexer.cpp
Index: unittests/AST/ASTTraverserTest.cpp
===
--- /dev/null
+++ unittests/AST/ASTTraverserTest.cpp
@@ -0,0 +1,220 @@
+//===- unittests/AST/ASTTraverserTest.h===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTNodeTraverser.h"
+#include "clang/AST/TextNodeDumper.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang::tooling;
+using namespace clang::ast_matchers;
+
+namespace clang {
+
+class NodeTreePrinter : public TextTreeStructure {
+  llvm::raw_ostream 
+
+public:
+  NodeTreePrinter(llvm::raw_ostream )
+  : TextTreeStructure(OS, /* showColors */ false), OS(OS) {}
+
+  void Visit(const Decl *D) { OS << D->getDeclKindName() << "Decl"; }
+
+  void Visit(const Stmt *S) { OS << S->getStmtClassName(); }
+
+  void Visit(QualType QT) {
+OS << "QualType " << QT.split().Quals.getAsString();
+  }
+
+  void Visit(const Type *T) { OS << T->getTypeClassName() << "Type"; }
+
+  void Visit(const comments::Comment *C, const comments::FullComment *FC) {
+OS << C->getCommentKindName();
+  }
+
+  void Visit(const CXXCtorInitializer *Init) { OS << "CXXCtorInitializer"; }
+
+  void Visit(const Attr *A) {
+switch (A->getKind()) {
+#define ATTR(X)\
+  case attr::X:\
+OS << #X;  \
+break;
+#include "clang/Basic/AttrList.inc"
+}
+OS << "Attr";
+  }
+
+  void Visit(const OMPClause *C) { OS << "OMPClause"; }
+  void Visit(const TemplateArgument , SourceRange R = {},
+ const Decl *From = nullptr, const char *Label = nullptr) {
+OS << "TemplateArgument";
+  }
+
+  template  void Visit(T...) {}
+};
+
+class TestASTDumper : public ASTNodeTraverser {
+
+  NodeTreePrinter MyNodeRecorder;
+
+public:
+  TestASTDumper(llvm::raw_ostream ) : MyNodeRecorder(OS) {}
+  NodeTreePrinter () { return MyNodeRecorder; }
+};
+
+template  std::string dumpASTString(NodeType &&... N) {
+  std::string Buffer;
+  llvm::raw_string_ostream OS(Buffer);
+
+  TestASTDumper Dumper(OS);
+
+  OS << "\n";
+
+  Dumper.Visit(std::forward(N)...);
+
+  return OS.str();
+}
+
+const FunctionDecl *getFunctionNode(clang::ASTUnit *AST,
+const std::string ) {
+  auto Result = ast_matchers::match(functionDecl(hasName(name)).bind("fn"),
+AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("fn");
+}
+
+template  struct Verifier {
+  static void withDynNode(T Node, const std::string ) {
+EXPECT_EQ(dumpASTString(ast_type_traits::DynTypedNode::create(Node)),
+  dumpString);
+  }
+};
+
+template  struct Verifier {
+  static void withDynNode(T *Node, const std::string ) {
+EXPECT_EQ(dumpASTString(ast_type_traits::DynTypedNode::create(*Node)),
+  dumpString);
+  }
+};
+
+template 
+void verifyWithDynNode(T Node, const std::string ) {
+  EXPECT_EQ(dumpASTString(Node), dumpString);
+
+  Verifier::withDynNode(Node, dumpString);
+}
+
+TEST(Traverse, Dump) {
+
+  auto AST = buildASTFromCode(R"cpp(
+struct A {
+  int m_number;
+
+  /// CTor
+  A() : m_number(42) {}
+
+  [[nodiscard]] const int func() {
+return 42;
+  }
+
+};
+
+template
+struct templ
+{ 
+};
+
+template<>
+struct templ
+{ 
+};
+
+)cpp");
+
+  const FunctionDecl *Func = getFunctionNode(AST.get(), "func");
+
+  verifyWithDynNode(Func,
+R"cpp(
+CXXMethodDecl
+|-CompoundStmt
+| `-ReturnStmt
+|   `-IntegerLiteral
+`-WarnUnusedResultAttr
+)cpp");
+
+  Stmt *Body = Func->getBody();
+
+  verifyWithDynNode(Body,
+R"cpp(
+CompoundStmt

[PATCH] D59464: [analyzer] Add an example plugin for checker dependency handling

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

In that case, feel free to revert this. If around 11:00 CET time I tried to 
recommit with a possible fix (while watching your bots), would that be an issue?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59464



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


[PATCH] D59464: [analyzer] Add an example plugin for checker dependency handling

2019-05-16 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: 
cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt:4
+
+if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
+  target_link_libraries(CheckerDependencyHandlingAnalyzerPlugin PRIVATE

Szelethus wrote:
> Szelethus wrote:
> > ```
> > if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN OR FUCHSIA))
> > ```
> (the `FUCHSIA` is a placeholder here, not sure if we have a variable for it)
I don't think that's the problem, the build is failing when compiling Clang for 
Linux, not for Fuchsia.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59464



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


[PATCH] D59464: [analyzer] Add an example plugin for checker dependency handling

2019-05-16 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked an inline comment as done.
Szelethus added inline comments.



Comment at: 
cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt:4
+
+if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
+  target_link_libraries(CheckerDependencyHandlingAnalyzerPlugin PRIVATE

Szelethus wrote:
> ```
> if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN OR FUCHSIA))
> ```
(the `FUCHSIA` is a placeholder here, not sure if we have a variable for it)


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59464



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


[PATCH] D59464: [analyzer] Add an example plugin for checker dependency handling

2019-05-16 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked 2 inline comments as done.
Szelethus added a comment.

If there's a cmake variable for fuchsia, Could you please try to add them here? 
(see inlines) I don't have access to that particular platform.




Comment at: 
cfe/trunk/test/Analysis/plugins/CheckerDependencyHandling/CMakeLists.txt:4
+
+if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
+  target_link_libraries(CheckerDependencyHandlingAnalyzerPlugin PRIVATE

```
if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN OR FUCHSIA))
```



Comment at: cfe/trunk/test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt:4
+
+if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
+  target_link_libraries(SampleAnalyzerPlugin PRIVATE

Szelethus wrote:
> Is it possible that if we tweaked this line the error would go away?
```
if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN OR FUCHSIA))
```


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59464



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


[PATCH] D58035: [clang/DIVar] Emit flag for params that have unchanged values

2019-05-16 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.cpp:4537
+  CGM.getLangOpts().Optimize) {
+for (auto  : DeclCache) {
+  auto *D = SP.first;

djtodoro wrote:
> aprantl wrote:
> > Just looking at the type declarations in CGDebugInfo.h: Why not iterate 
> > over the `SPCache`  directly? Shouldn't that contain all Function 
> > declarations only?
> I tried it, but `SPCache` is empty at this point.
Where is it emptied? Just grepping through CGDebugInfo did not make this 
obvious to me.



Comment at: lib/CodeGen/CGDebugInfo.cpp:3885
+  if (CGM.getCodeGenOpts().EnableDebugEntryValues &&
+  CGM.getLangOpts().Optimize && ArgNo) {
+if (auto *PD = dyn_cast(VD))

We shouldn't query CGM.getLangOpts().Optimize. If we don't want this to happen 
at -O0, we shouldn't set EnableDebugEntryValues at a higher level (Driver, 
CompilerInvocation, ...) ..Otherwise inevitably someone will query one but not 
the other and things will go out of sync.



Comment at: lib/CodeGen/CGDebugInfo.cpp:4535
   DBuilder.retainType(cast(MD));
 
+  if (CGM.getCodeGenOpts().EnableDebugEntryValues &&

Please add either a top-level comment about what this block is doing or perhaps 
factor this out into a descriptively named static function.


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

https://reviews.llvm.org/D58035



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


r360947 - Fix failing source location test on Windows

2019-05-16 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu May 16 15:21:42 2019
New Revision: 360947

URL: http://llvm.org/viewvc/llvm-project?rev=360947=rev
Log:
Fix failing source location test on Windows

Modified:
cfe/trunk/test/CodeGenCXX/builtin_FUNCTION.cpp

Modified: cfe/trunk/test/CodeGenCXX/builtin_FUNCTION.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/builtin_FUNCTION.cpp?rev=360947=360946=360947=diff
==
--- cfe/trunk/test/CodeGenCXX/builtin_FUNCTION.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/builtin_FUNCTION.cpp Thu May 16 15:21:42 2019
@@ -8,10 +8,10 @@ constexpr const char *test_default_arg(c
 }
 // CHECK: @[[EMPTY_STR:.+]] = private unnamed_addr constant [1 x i8] 
zeroinitializer, align 1
 
-// CHECK: @_ZN9test_func6globalE = global i8* getelementptr inbounds ([1 x 
i8], [1 x i8]* @[[EMPTY_STR]], i32 0, i32 0), align 8
+// CHECK: @_ZN9test_func6globalE = {{(dso_local )?}}global i8* getelementptr 
inbounds ([1 x i8], [1 x i8]* @[[EMPTY_STR]], i32 0, i32 0), align 8
 const char *global = test_default_arg();
 
-// CHECK: @_ZN9test_func10global_twoE = global i8* getelementptr inbounds ([1 
x i8], [1 x i8]* @[[EMPTY_STR]], i32 0, i32 0), align 8
+// CHECK: @_ZN9test_func10global_twoE = {{(dso_local )?}}global i8* 
getelementptr inbounds ([1 x i8], [1 x i8]* @[[EMPTY_STR]], i32 0, i32 0), 
align 8
 const char *global_two = __builtin_FUNCTION();
 
 const char * const global_three = test_default_arg();
@@ -20,19 +20,19 @@ const char * const global_three = test_d
 // CHECK: @[[STR_TWO:.+]] = private unnamed_addr constant [14 x i8] 
c"test_func_two\00", align 1
 // CHECK: @[[STR_THREE:.+]] = private unnamed_addr constant [20 x i8] 
c"do_default_arg_test\00", align 1
 
-// CHECK: define i8* @_ZN9test_func13test_func_oneEv()
+// CHECK: define {{(dso_local )?}}i8* @_ZN9test_func13test_func_oneEv()
 // CHECK: ret i8* getelementptr inbounds ([14 x i8], [14 x i8]* @[[STR_ONE]], 
i32 0, i32 0)
 const char *test_func_one() {
   return __builtin_FUNCTION();
 }
 
-// CHECK: define i8* @_ZN9test_func13test_func_twoEv()
+// CHECK: define {{(dso_local )?}}i8* @_ZN9test_func13test_func_twoEv()
 // CHECK: ret i8* getelementptr inbounds ([14 x i8], [14 x i8]* @[[STR_TWO]], 
i32 0, i32 0)
 const char *test_func_two() {
   return __builtin_FUNCTION();
 }
 
-// CHECK: define void @_ZN9test_func19do_default_arg_testEv()
+// CHECK: define {{(dso_local )?}}void @_ZN9test_func19do_default_arg_testEv()
 // CHECK: %call = call i8* @_ZN9test_func16test_default_argEPKc(i8* 
getelementptr inbounds ([20 x i8], [20 x i8]* @[[STR_THREE]], i32 0, i32 0))
 void do_default_arg_test() {
   test_default_arg();


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


[PATCH] D61970: [CodeGen][ObjC] Call objc_autoreleaseReturnValue and objc_retainAutoreleasedReturnValue instead of objc_autorelease and objc_retain in MRR

2019-05-16 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked an inline comment as done.
ahatanak added inline comments.



Comment at: lib/CodeGen/CGObjC.cpp:2611
+  if (!CGM.getCodeGenOpts().ObjCNoBuiltinRetainRelease && !getInvokeDest())
+return EmitARCRetainAutoreleasedReturnValue(value, returnType);
   return emitObjCValueOperation(

ahatanak wrote:
> rjmccall wrote:
> > Same question: won't this make it significantly more difficult to detect 
> > when we're generating bad code?  And the overhead here (on every retain in 
> > MRC!) is pretty significant; shouldn't this at least be restricted to 
> > situations where it's plausible that it might be reclaiming something, like 
> > when the receiver expression is a function call of some sort?
> As I mentioned in my response to David's question, I was thinking the ARC 
> optimizer would be able to convert an `objc_retainAutoreleasedReturnValue` 
> call to an `objc_retain` call. However, after reading your comment in 
> https://reviews.llvm.org/D61970, I don't think it's okay to use the ARC 
> optimizer to transform code that was compiled in MRR mode.
I meant the comment in https://reviews.llvm.org/D61808.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61970



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


[PATCH] D61838: [Sema] Suppress additional warnings for C's zero initializer

2019-05-16 Thread Alex James via Phabricator via cfe-commits
al3xtjames added a comment.

Such nested structures work fine (no warnings generated).


Repository:
  rC Clang

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

https://reviews.llvm.org/D61838



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


[PATCH] D61970: [CodeGen][ObjC] Call objc_autoreleaseReturnValue and objc_retainAutoreleasedReturnValue instead of objc_autorelease and objc_retain in MRR

2019-05-16 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked an inline comment as done.
ahatanak added inline comments.



Comment at: lib/CodeGen/CGObjC.cpp:2611
+  if (!CGM.getCodeGenOpts().ObjCNoBuiltinRetainRelease && !getInvokeDest())
+return EmitARCRetainAutoreleasedReturnValue(value, returnType);
   return emitObjCValueOperation(

rjmccall wrote:
> Same question: won't this make it significantly more difficult to detect when 
> we're generating bad code?  And the overhead here (on every retain in MRC!) 
> is pretty significant; shouldn't this at least be restricted to situations 
> where it's plausible that it might be reclaiming something, like when the 
> receiver expression is a function call of some sort?
As I mentioned in my response to David's question, I was thinking the ARC 
optimizer would be able to convert an `objc_retainAutoreleasedReturnValue` call 
to an `objc_retain` call. However, after reading your comment in 
https://reviews.llvm.org/D61970, I don't think it's okay to use the ARC 
optimizer to transform code that was compiled in MRR mode.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61970



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


[PATCH] D61909: Add Clang shared library with C++ exports

2019-05-16 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC360946: Add Clang shared library with C++ exports (authored 
by cbieneman, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D61909?vs=199508=199912#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D61909

Files:
  cmake/modules/AddClang.cmake
  tools/CMakeLists.txt
  tools/clang-shlib/CMakeLists.txt
  tools/clang-shlib/clang-shlib.cpp


Index: tools/clang-shlib/CMakeLists.txt
===
--- tools/clang-shlib/CMakeLists.txt
+++ tools/clang-shlib/CMakeLists.txt
@@ -0,0 +1,13 @@
+get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)
+
+foreach (lib ${clang_libs})
+  list(APPEND _OBJECTS $)
+  list(APPEND _DEPS $)
+endforeach ()
+
+add_clang_library(clang_shared
+  SHARED
+  clang-shlib.cpp
+  ${_OBJECTS}
+  LINK_LIBS
+  ${_DEPS})
Index: tools/clang-shlib/clang-shlib.cpp
===
--- tools/clang-shlib/clang-shlib.cpp
+++ tools/clang-shlib/clang-shlib.cpp
@@ -0,0 +1 @@
+// Intentionally empty source file to make CMake happy
Index: tools/CMakeLists.txt
===
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -13,6 +13,9 @@
 
 add_clang_subdirectory(clang-rename)
 add_clang_subdirectory(clang-refactor)
+if(UNIX)
+  add_clang_subdirectory(clang-shlib)
+endif()
 
 if(CLANG_ENABLE_ARCMT)
   add_clang_subdirectory(arcmt-test)
Index: cmake/modules/AddClang.cmake
===
--- cmake/modules/AddClang.cmake
+++ cmake/modules/AddClang.cmake
@@ -81,9 +81,12 @@
   )
   endif()
   if(ARG_SHARED)
-set(ARG_ENABLE_SHARED SHARED)
+set(LIBTYPE SHARED)
+  else()
+set(LIBTYPE STATIC OBJECT)
+set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
   endif()
-  llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} 
${srcs})
+  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
 
   if(TARGET ${name})
 target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})


Index: tools/clang-shlib/CMakeLists.txt
===
--- tools/clang-shlib/CMakeLists.txt
+++ tools/clang-shlib/CMakeLists.txt
@@ -0,0 +1,13 @@
+get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)
+
+foreach (lib ${clang_libs})
+  list(APPEND _OBJECTS $)
+  list(APPEND _DEPS $)
+endforeach ()
+
+add_clang_library(clang_shared
+  SHARED
+  clang-shlib.cpp
+  ${_OBJECTS}
+  LINK_LIBS
+  ${_DEPS})
Index: tools/clang-shlib/clang-shlib.cpp
===
--- tools/clang-shlib/clang-shlib.cpp
+++ tools/clang-shlib/clang-shlib.cpp
@@ -0,0 +1 @@
+// Intentionally empty source file to make CMake happy
Index: tools/CMakeLists.txt
===
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -13,6 +13,9 @@
 
 add_clang_subdirectory(clang-rename)
 add_clang_subdirectory(clang-refactor)
+if(UNIX)
+  add_clang_subdirectory(clang-shlib)
+endif()
 
 if(CLANG_ENABLE_ARCMT)
   add_clang_subdirectory(arcmt-test)
Index: cmake/modules/AddClang.cmake
===
--- cmake/modules/AddClang.cmake
+++ cmake/modules/AddClang.cmake
@@ -81,9 +81,12 @@
   )
   endif()
   if(ARG_SHARED)
-set(ARG_ENABLE_SHARED SHARED)
+set(LIBTYPE SHARED)
+  else()
+set(LIBTYPE STATIC OBJECT)
+set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
   endif()
-  llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
+  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
 
   if(TARGET ${name})
 target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r360946 - Add Clang shared library with C++ exports

2019-05-16 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Thu May 16 15:06:07 2019
New Revision: 360946

URL: http://llvm.org/viewvc/llvm-project?rev=360946=rev
Log:
Add Clang shared library with C++ exports

Summary:
This patch adds a libClang_shared library on *nix systems which exports the 
entire C++ API. In order to support this on Windows we should really refactor 
llvm-shlib and share code between the two.

This also uses a slightly different method for generating the shared library, 
which I should back-port to llvm-shlib. Instead of linking the static archives 
and passing linker flags to force loading the whole libraries, this patch 
creates object libraries for every library (which has no cost in the build 
system), and link the object libraries.

Reviewers: tstellar, winksaville

Subscribers: mgorny, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/tools/clang-shlib/
cfe/trunk/tools/clang-shlib/CMakeLists.txt
cfe/trunk/tools/clang-shlib/clang-shlib.cpp
Modified:
cfe/trunk/cmake/modules/AddClang.cmake
cfe/trunk/tools/CMakeLists.txt

Modified: cfe/trunk/cmake/modules/AddClang.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=360946=360945=360946=diff
==
--- cfe/trunk/cmake/modules/AddClang.cmake (original)
+++ cfe/trunk/cmake/modules/AddClang.cmake Thu May 16 15:06:07 2019
@@ -81,9 +81,12 @@ macro(add_clang_library name)
   )
   endif()
   if(ARG_SHARED)
-set(ARG_ENABLE_SHARED SHARED)
+set(LIBTYPE SHARED)
+  else()
+set(LIBTYPE STATIC OBJECT)
+set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
   endif()
-  llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} 
${srcs})
+  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
 
   if(TARGET ${name})
 target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})

Modified: cfe/trunk/tools/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=360946=360945=360946=diff
==
--- cfe/trunk/tools/CMakeLists.txt (original)
+++ cfe/trunk/tools/CMakeLists.txt Thu May 16 15:06:07 2019
@@ -13,6 +13,9 @@ add_clang_subdirectory(c-index-test)
 
 add_clang_subdirectory(clang-rename)
 add_clang_subdirectory(clang-refactor)
+if(UNIX)
+  add_clang_subdirectory(clang-shlib)
+endif()
 
 if(CLANG_ENABLE_ARCMT)
   add_clang_subdirectory(arcmt-test)

Added: cfe/trunk/tools/clang-shlib/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/CMakeLists.txt?rev=360946=auto
==
--- cfe/trunk/tools/clang-shlib/CMakeLists.txt (added)
+++ cfe/trunk/tools/clang-shlib/CMakeLists.txt Thu May 16 15:06:07 2019
@@ -0,0 +1,13 @@
+get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)
+
+foreach (lib ${clang_libs})
+  list(APPEND _OBJECTS $)
+  list(APPEND _DEPS $)
+endforeach ()
+
+add_clang_library(clang_shared
+  SHARED
+  clang-shlib.cpp
+  ${_OBJECTS}
+  LINK_LIBS
+  ${_DEPS})

Added: cfe/trunk/tools/clang-shlib/clang-shlib.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/clang-shlib.cpp?rev=360946=auto
==
--- cfe/trunk/tools/clang-shlib/clang-shlib.cpp (added)
+++ cfe/trunk/tools/clang-shlib/clang-shlib.cpp Thu May 16 15:06:07 2019
@@ -0,0 +1 @@
+// Intentionally empty source file to make CMake happy


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


[PATCH] D61909: Add Clang shared library with C++ exports

2019-05-16 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

I will land this patch as-is today. I'll try and get a doc patch out for review 
today or tomorrow. @winksaville, I'm going to add a section to the document 
about building LLVM as a shared library for inclusion with tool distributions.

That still shouldn't be done with `BUILD_SHARED_LIBS`, we do have mechanisms in 
LLVM to allow people to control which parts of LLVM get included in libLLVM, 
and we should add similar mechanisms to this new functionality if needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61909



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


[PATCH] D59464: [analyzer] Add an example plugin for checker dependency handling

2019-05-16 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D59464#1505463 , @NoQ wrote:

> Can we have a full build log?


The full build log is here: 
https://luci-milo.appspot.com/p/fuchsia/builders/ci/clang-x64-linux/b8913271285442739696


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59464



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


r360943 - Fix PCC test failures for source location builtins

2019-05-16 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu May 16 14:51:39 2019
New Revision: 360943

URL: http://llvm.org/viewvc/llvm-project?rev=360943=rev
Log:
Fix PCC test failures for source location builtins

Modified:
cfe/trunk/test/CodeGenCXX/builtin-source-location.cpp
cfe/trunk/test/CodeGenCXX/builtin_LINE.cpp
cfe/trunk/test/CodeGenCXX/debug-info-line.cpp

Modified: cfe/trunk/test/CodeGenCXX/builtin-source-location.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/builtin-source-location.cpp?rev=360943=360942=360943=diff
==
--- cfe/trunk/test/CodeGenCXX/builtin-source-location.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/builtin-source-location.cpp Thu May 16 14:51:39 
2019
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++2a -fblocks %s -triple %itanium_abi_triple 
-emit-llvm -o %t.ll
+// RUN: %clang_cc1 -std=c++2a -fblocks %s -triple x86_64-unknown-unknown 
-emit-llvm -o %t.ll
 
 #line 8 "builtin-source-location.cpp"
 

Modified: cfe/trunk/test/CodeGenCXX/builtin_LINE.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/builtin_LINE.cpp?rev=360943=360942=360943=diff
==
--- cfe/trunk/test/CodeGenCXX/builtin_LINE.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/builtin_LINE.cpp Thu May 16 14:51:39 2019
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++1z -fblocks %s -triple %itanium_abi_triple 
-emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++1z -fblocks %s -triple x86_64-unknown-unknown 
-emit-llvm -o - | FileCheck %s
 
 extern "C" int sink;
 extern "C" const volatile void* volatile ptr_sink = nullptr;

Modified: cfe/trunk/test/CodeGenCXX/debug-info-line.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-line.cpp?rev=360943=360942=360943=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-line.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-line.cpp Thu May 16 14:51:39 2019
@@ -296,7 +296,7 @@ void f24() {
 // CHECK-LABEL: define
 void f25_a(int x = __builtin_LINE()) {}
 void f25() {
-  // CHECK: call void @_Z5f25_ai(i32 2700)
+  // CHECK: call void @_Z5f25_ai(i32 {{(signext )?}}2700)
 #line 2700
   f25_a();
 }


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


[PATCH] D62035: [AST] const-ify ObjC inherited class search

2019-05-16 Thread Brian Gesiak via Phabricator via cfe-commits
modocache created this revision.
modocache added a reviewer: rjmccall.
Herald added a project: clang.

When writing an AST matcher to find inherited Objective-C classes, I
noticed the returned `ObjCInterfaceDecl*` was mutable. It doesn't seem
like it needs to be mutable, so this patch makes it const.

Patch by Adam Ernst.


Repository:
  rC Clang

https://reviews.llvm.org/D62035

Files:
  include/clang/AST/DeclObjC.h
  lib/AST/DeclObjC.cpp
  lib/Sema/SemaDeclObjC.cpp


Index: lib/Sema/SemaDeclObjC.cpp
===
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -2685,7 +2685,7 @@
   assert (IDecl && "CheckProtocolMethodDefs - IDecl is null");
 
   ObjCInterfaceDecl *Super = IDecl->getSuperClass();
-  ObjCInterfaceDecl *NSIDecl = nullptr;
+  const ObjCInterfaceDecl *NSIDecl = nullptr;
 
   // If this protocol is marked 
'objc_protocol_requires_explicit_implementation'
   // then we should check if any class in the super class hierarchy also
Index: lib/AST/DeclObjC.cpp
===
--- lib/AST/DeclObjC.cpp
+++ lib/AST/DeclObjC.cpp
@@ -646,10 +646,10 @@
 }
 
 /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
-/// class whose name is passed as argument. If it is not one of the super 
classes
-/// the it returns NULL.
-ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
-const IdentifierInfo*ICName) {
+/// class whose name is passed as argument. If it is not one of the super
+/// classes then it returns NULL.
+const ObjCInterfaceDecl *
+ObjCInterfaceDecl::lookupInheritedClass(const IdentifierInfo *ICName) const {
   // FIXME: Should make sure no callers ever do this.
   if (!hasDefinition())
 return nullptr;
@@ -657,7 +657,7 @@
   if (data().ExternallyCompleted)
 LoadExternalDefinition();
 
-  ObjCInterfaceDecl* ClassDecl = this;
+  auto *ClassDecl = this;
   while (ClassDecl != nullptr) {
 if (ClassDecl->getIdentifier() == ICName)
   return ClassDecl;
Index: include/clang/AST/DeclObjC.h
===
--- include/clang/AST/DeclObjC.h
+++ include/clang/AST/DeclObjC.h
@@ -1852,7 +1852,8 @@
 return lookupMethod(Sel, false/*isInstance*/);
   }
 
-  ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
+  const ObjCInterfaceDecl *
+  lookupInheritedClass(const IdentifierInfo *ICName) const;
 
   /// Lookup a method in the classes implementation hierarchy.
   ObjCMethodDecl *lookupPrivateMethod(const Selector ,


Index: lib/Sema/SemaDeclObjC.cpp
===
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -2685,7 +2685,7 @@
   assert (IDecl && "CheckProtocolMethodDefs - IDecl is null");
 
   ObjCInterfaceDecl *Super = IDecl->getSuperClass();
-  ObjCInterfaceDecl *NSIDecl = nullptr;
+  const ObjCInterfaceDecl *NSIDecl = nullptr;
 
   // If this protocol is marked 'objc_protocol_requires_explicit_implementation'
   // then we should check if any class in the super class hierarchy also
Index: lib/AST/DeclObjC.cpp
===
--- lib/AST/DeclObjC.cpp
+++ lib/AST/DeclObjC.cpp
@@ -646,10 +646,10 @@
 }
 
 /// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
-/// class whose name is passed as argument. If it is not one of the super classes
-/// the it returns NULL.
-ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
-const IdentifierInfo*ICName) {
+/// class whose name is passed as argument. If it is not one of the super
+/// classes then it returns NULL.
+const ObjCInterfaceDecl *
+ObjCInterfaceDecl::lookupInheritedClass(const IdentifierInfo *ICName) const {
   // FIXME: Should make sure no callers ever do this.
   if (!hasDefinition())
 return nullptr;
@@ -657,7 +657,7 @@
   if (data().ExternallyCompleted)
 LoadExternalDefinition();
 
-  ObjCInterfaceDecl* ClassDecl = this;
+  auto *ClassDecl = this;
   while (ClassDecl != nullptr) {
 if (ClassDecl->getIdentifier() == ICName)
   return ClassDecl;
Index: include/clang/AST/DeclObjC.h
===
--- include/clang/AST/DeclObjC.h
+++ include/clang/AST/DeclObjC.h
@@ -1852,7 +1852,8 @@
 return lookupMethod(Sel, false/*isInstance*/);
   }
 
-  ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
+  const ObjCInterfaceDecl *
+  lookupInheritedClass(const IdentifierInfo *ICName) const;
 
   /// Lookup a method in the classes implementation hierarchy.
   ObjCMethodDecl *lookupPrivateMethod(const Selector ,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59628: Add support for __attribute__((objc_class_stub))

2019-05-16 Thread Slava Pestov via Phabricator via cfe-commits
slavapestov updated this revision to Diff 199905.

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

https://reviews.llvm.org/D59628

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/ObjCRuntime.h
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/test/CodeGenObjC/class-stubs.m
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaObjC/class-stub-attr-unsupported.m
  clang/test/SemaObjC/class-stub-attr.m
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1922,6 +1922,30 @@
   return true;
 }
 
+static std::string GenerateTestExpression(ArrayRef LangOpts) {
+  std::string Test;
+
+  for (auto *E : LangOpts) {
+if (!Test.empty())
+  Test += " || ";
+
+const StringRef Code = E->getValueAsString("CustomCode");
+if (!Code.empty()) {
+  Test += "(";
+  Test += Code;
+  Test += ")";
+} else {
+  Test += "LangOpts.";
+  Test += E->getValueAsString("Name");
+}
+  }
+
+  if (Test.empty())
+return "true";
+
+  return Test;
+}
+
 std::string
 PragmaClangAttributeSupport::generateStrictConformsTo(const Record ,
   raw_ostream ) {
@@ -1948,19 +1972,8 @@
   // rules if the specific language options are specified.
   std::vector LangOpts = Rule.getLangOpts();
   OS << "  MatchRules.push_back(std::make_pair(" << Rule.getEnumValue()
- << ", /*IsSupported=*/";
-  if (!LangOpts.empty()) {
-for (auto I = LangOpts.begin(), E = LangOpts.end(); I != E; ++I) {
-  const StringRef Part = (*I)->getValueAsString("Name");
-  if ((*I)->getValueAsBit("Negated"))
-OS << "!";
-  OS << "LangOpts." << Part;
-  if (I + 1 != E)
-OS << " || ";
-}
-  } else
-OS << "true";
-  OS << "));\n";
+ << ", /*IsSupported=*/" << GenerateTestExpression(LangOpts)
+ << "));\n";
 }
   }
   OS << "}\n\n";
@@ -3431,23 +3444,12 @@
   if (LangOpts.empty())
 return "defaultDiagnoseLangOpts";
 
-  // Generate the test condition, as well as a unique function name for the
-  // diagnostic test. The list of options should usually be short (one or two
-  // options), and the uniqueness isn't strictly necessary (it is just for
-  // codegen efficiency).
-  std::string FnName = "check", Test;
-  for (auto I = LangOpts.begin(), E = LangOpts.end(); I != E; ++I) {
-const StringRef Part = (*I)->getValueAsString("Name");
-if ((*I)->getValueAsBit("Negated")) {
-  FnName += "Not";
-  Test += "!";
-}
-Test += "S.LangOpts.";
-Test +=  Part;
-if (I + 1 != E)
-  Test += " || ";
-FnName += Part;
-  }
+  // Generate a unique function name for the diagnostic test. The list of
+  // options should usually be short (one or two options), and the
+  // uniqueness isn't strictly necessary (it is just for codegen efficiency).
+  std::string FnName = "check";
+  for (auto I = LangOpts.begin(), E = LangOpts.end(); I != E; ++I)
+FnName += (*I)->getValueAsString("Name");
   FnName += "LangOpts";
 
   // If this code has already been generated, simply return the previous
@@ -3458,7 +3460,8 @@
 return *I;
 
   OS << "static bool " << FnName << "(Sema , const ParsedAttr ) {\n";
-  OS << "  if (" << Test << ")\n";
+  OS << "  auto  = S.LangOpts;\n";
+  OS << "  if (" << GenerateTestExpression(LangOpts) << ")\n";
   OS << "return true;\n\n";
   OS << "  S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) ";
   OS << "<< Attr.getName();\n";
Index: clang/test/SemaObjC/class-stub-attr.m
===
--- /dev/null
+++ clang/test/SemaObjC/class-stub-attr.m
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-apple-darwin -fsyntax-only -Xclang -verify %s
+// RUN: %clang -target x86_64-apple-darwin -x objective-c++ -fsyntax-only -Xclang -verify %s
+
+@interface NSObject
+@end
+
+__attribute__((objc_class_stub))
+@interface MissingSubclassingRestrictedAttribute : NSObject // expected-error {{'objc_class_stub' attribute cannot be specified on a class that does not have the 'objc_subclassing_restricted' attribute}}
+@end
+
+__attribute__((objc_class_stub))
+__attribute__((objc_subclassing_restricted))
+@interface ValidClassStubAttribute : NSObject
+@end
+
+@implementation ValidClassStubAttribute // expected-error {{cannot declare implementation of a class declared with the 'objc_class_stub' attribute}}
+@end
+
+@implementation ValidClassStubAttribute (MyCategory)
+@end
+
+__attribute__((objc_class_stub(123))) // expected-error {{'objc_class_stub' attribute takes 

r360939 - [clang/test] Add missing dependency on llvm-cxxfilt.

2019-05-16 Thread David L. Jones via cfe-commits
Author: dlj
Date: Thu May 16 14:13:59 2019
New Revision: 360939

URL: http://llvm.org/viewvc/llvm-project?rev=360939=rev
Log:
[clang/test] Add missing dependency on llvm-cxxfilt.

This tool is needed by clang/test/CodeGen/Output/ppc-mmintrin.c.

Modified:
cfe/trunk/test/CMakeLists.txt

Modified: cfe/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=360939=360938=360939=diff
==
--- cfe/trunk/test/CMakeLists.txt (original)
+++ cfe/trunk/test/CMakeLists.txt Thu May 16 14:13:59 2019
@@ -107,6 +107,7 @@ if( NOT CLANG_BUILT_STANDALONE )
 llvm-as
 llvm-bcanalyzer
 llvm-cat
+llvm-cxxfilt
 llvm-dis
 llvm-lto2
 llvm-modextract


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


r360938 - Reland "[Clang][PP] Add the __FILE_NAME__ builtin macro"

2019-05-16 Thread Kristina Brooks via cfe-commits
Author: kristina
Date: Thu May 16 14:13:49 2019
New Revision: 360938

URL: http://llvm.org/viewvc/llvm-project?rev=360938=rev
Log:
Reland "[Clang][PP] Add the __FILE_NAME__ builtin macro"

This relands commit rL360833 which caused issues on Win32
bots due to path handling/normalization differences. Now
this uses `sys::path::filename` which should handle
additional edge cases on Win32.

Original commit:

"[Clang][PP] Add the __FILE_NAME__ builtin macro" 

This patch adds the __FILE_NAME__ macro that expands to the
last component of the path, similar to __FILE__ except with
a guarantee that only the last path component (without the
separator) will be rendered.

I intend to follow through with discussion of this with WG14
as a potential inclusion in the C standard or failing that,
try to discuss this with GCC developers since this extension
is desired by GCC and Clang users/developers alike.

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


Added:
cfe/trunk/test/Preprocessor/Inputs/include-subdir/
cfe/trunk/test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h
cfe/trunk/test/Preprocessor/Inputs/include-subdir/h
cfe/trunk/test/Preprocessor/Inputs/include-subdir/subdir1/
cfe/trunk/test/Preprocessor/Inputs/include-subdir/subdir1/hdr1.h
cfe/trunk/test/Preprocessor/Inputs/include-subdir/subdir1/hdr2.h
cfe/trunk/test/Preprocessor/file_name_macro.c
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/PPMacroExpansion.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=360938=360937=360938=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Thu May 16 14:13:49 2019
@@ -147,6 +147,7 @@ class Preprocessor {
   IdentifierInfo *Ident__DATE__, *Ident__TIME__;   // __DATE__, __TIME__
   IdentifierInfo *Ident__INCLUDE_LEVEL__;  // __INCLUDE_LEVEL__
   IdentifierInfo *Ident__BASE_FILE__;  // __BASE_FILE__
+  IdentifierInfo *Ident__FILE_NAME__;  // __FILE_NAME__
   IdentifierInfo *Ident__TIMESTAMP__;  // __TIMESTAMP__
   IdentifierInfo *Ident__COUNTER__;// __COUNTER__
   IdentifierInfo *Ident_Pragma, *Ident__pragma;// _Pragma, __pragma

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=360938=360937=360938=diff
==
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Thu May 16 14:13:49 2019
@@ -43,6 +43,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -363,6 +364,7 @@ void Preprocessor::RegisterBuiltinMacros
   }
 
   // Clang Extensions.
+  Ident__FILE_NAME__  = RegisterBuiltinMacro(*this, "__FILE_NAME__");
   Ident__has_feature  = RegisterBuiltinMacro(*this, "__has_feature");
   Ident__has_extension= RegisterBuiltinMacro(*this, "__has_extension");
   Ident__has_builtin  = RegisterBuiltinMacro(*this, "__has_builtin");
@@ -1474,7 +1476,8 @@ void Preprocessor::ExpandBuiltinMacro(To
 // __LINE__ expands to a simple numeric value.
 OS << (PLoc.isValid()? PLoc.getLine() : 1);
 Tok.setKind(tok::numeric_constant);
-  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
+  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__ ||
+ II == Ident__FILE_NAME__) {
 // C99 6.10.8: "__FILE__: The presumed name of the current source file (a
 // character string literal)". This can be affected by #line.
 PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
@@ -1495,7 +1498,19 @@ void Preprocessor::ExpandBuiltinMacro(To
 // Escape this filename.  Turn '\' -> '\\' '"' -> '\"'
 SmallString<128> FN;
 if (PLoc.isValid()) {
-  FN += PLoc.getFilename();
+  // __FILE_NAME__ is a Clang-specific extension that expands to the
+  // the last part of __FILE__.
+  if (II == Ident__FILE_NAME__) {
+// Try to get the last path component, failing that return the original
+// presumed location.
+StringRef PLFileName = llvm::sys::path::filename(PLoc.getFilename());
+if (PLFileName != "")
+  FN += PLFileName;
+else
+  FN += PLoc.getFilename();
+  } else {
+FN += PLoc.getFilename();
+  }
   Lexer::Stringify(FN);
   OS << '"' << FN << '"';
 }

Added: 
cfe/trunk/test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h?rev=360938=auto

[PATCH] D61756: Add a __FILE_NAME__ macro.

2019-05-16 Thread Kristina Brooks via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC360938: Reland [Clang][PP] Add the __FILE_NAME__ 
builtin macro (authored by kristina, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D61756

Files:
  include/clang/Lex/Preprocessor.h
  lib/Lex/PPMacroExpansion.cpp
  test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h
  test/Preprocessor/Inputs/include-subdir/h
  test/Preprocessor/Inputs/include-subdir/subdir1/hdr1.h
  test/Preprocessor/Inputs/include-subdir/subdir1/hdr2.h
  test/Preprocessor/file_name_macro.c

Index: include/clang/Lex/Preprocessor.h
===
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -147,6 +147,7 @@
   IdentifierInfo *Ident__DATE__, *Ident__TIME__;   // __DATE__, __TIME__
   IdentifierInfo *Ident__INCLUDE_LEVEL__;  // __INCLUDE_LEVEL__
   IdentifierInfo *Ident__BASE_FILE__;  // __BASE_FILE__
+  IdentifierInfo *Ident__FILE_NAME__;  // __FILE_NAME__
   IdentifierInfo *Ident__TIMESTAMP__;  // __TIMESTAMP__
   IdentifierInfo *Ident__COUNTER__;// __COUNTER__
   IdentifierInfo *Ident_Pragma, *Ident__pragma;// _Pragma, __pragma
Index: test/Preprocessor/Inputs/include-subdir/subdir1/hdr2.h
===
--- test/Preprocessor/Inputs/include-subdir/subdir1/hdr2.h
+++ test/Preprocessor/Inputs/include-subdir/subdir1/hdr2.h
@@ -0,0 +1 @@
+8: __FILE_NAME__
Index: test/Preprocessor/Inputs/include-subdir/subdir1/hdr1.h
===
--- test/Preprocessor/Inputs/include-subdir/subdir1/hdr1.h
+++ test/Preprocessor/Inputs/include-subdir/subdir1/hdr1.h
@@ -0,0 +1 @@
+7: __FILE_NAME__
Index: test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h
===
--- test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h
+++ test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h
@@ -0,0 +1,6 @@
+3: __FILE_NAME__
+4: "file_name_macro_include.h"
+#ifdef MS
+// Should be the same even when included with backslash.
+5: __FILE_NAME__
+#endif
Index: test/Preprocessor/Inputs/include-subdir/h
===
--- test/Preprocessor/Inputs/include-subdir/h
+++ test/Preprocessor/Inputs/include-subdir/h
@@ -0,0 +1 @@
+6: __FILE_NAME__
Index: test/Preprocessor/file_name_macro.c
===
--- test/Preprocessor/file_name_macro.c
+++ test/Preprocessor/file_name_macro.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -E %s -I%S/Inputs | FileCheck -strict-whitespace %s
+// RUN: %clang_cc1 -fms-compatibility -DMS -E %s -I%S/Inputs | FileCheck -check-prefix=CHECK-MS -strict-whitespace %s 
+// RUN: %clang_cc1 -E %s -I%S/Inputs -DBADINC -verify
+
+#ifdef BADINC
+
+// Paranoia.
+
+__FILE_NAME__
+#include  // expected-error {{file not found}}
+__FILE_NAME__
+
+#else
+
+// Reference.
+1: "file_name_macro.c"
+
+// Ensure it expands correctly for this file.
+2: __FILE_NAME__
+
+// CHECK: {{^}}1: "file_name_macro.c"
+// CHECK: {{^}}2: "file_name_macro.c"
+
+// Test if inclusion works right.
+#ifdef MS
+#include 
+// MS compatibility allows for mixed separators in paths.
+#include 
+#include 
+#else
+#include 
+#endif
+
+#include 
+
+// CHECK: {{^}}3: "file_name_macro_include.h"
+// CHECK: {{^}}4: "file_name_macro_include.h"
+// CHECK-NOT: {{^}}5: "file_name_macro_include.h"
+// CHECK-MS: {{^}}5: "file_name_macro_include.h"
+// CHECK: {{^}}6: "h"
+// CHECK-MS: {{^}}7: "hdr1.h"
+// CHECK-MS: {{^}}8: "hdr2.h"
+
+#endif
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -43,6 +43,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -363,6 +364,7 @@
   }
 
   // Clang Extensions.
+  Ident__FILE_NAME__  = RegisterBuiltinMacro(*this, "__FILE_NAME__");
   Ident__has_feature  = RegisterBuiltinMacro(*this, "__has_feature");
   Ident__has_extension= RegisterBuiltinMacro(*this, "__has_extension");
   Ident__has_builtin  = RegisterBuiltinMacro(*this, "__has_builtin");
@@ -1474,7 +1476,8 @@
 // __LINE__ expands to a simple numeric value.
 OS << (PLoc.isValid()? PLoc.getLine() : 1);
 Tok.setKind(tok::numeric_constant);
-  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
+  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__ ||
+ II == Ident__FILE_NAME__) {
 // C99 6.10.8: "__FILE__: The presumed name of the current source file (a
 

[PATCH] D37035: Implement __builtin_LINE() et. al. to support source location capture.

2019-05-16 Thread Eric Fiselier via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC360937: Implement __builtin_LINE() et. al. to support source 
location capture. (authored by EricWF, committed by ).
Herald added a subscriber: kristina.
Herald added a project: clang.

Repository:
  rC Clang

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

https://reviews.llvm.org/D37035

Files:
  docs/LanguageExtensions.rst
  include/clang/AST/ASTContext.h
  include/clang/AST/CurrentSourceLocExprScope.h
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/Stmt.h
  include/clang/Basic/StmtNodes.td
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprConstant.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprObjC.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/CodeGenCXX/builtin-source-location.cpp
  test/CodeGenCXX/builtin_FUNCTION.cpp
  test/CodeGenCXX/builtin_LINE.cpp
  test/CodeGenCXX/debug-info-line.cpp
  test/Parser/builtin_source_location.c
  test/Sema/source_location.c
  test/SemaCXX/Inputs/source-location-file.h
  test/SemaCXX/source_location.cpp
  tools/libclang/CXCursor.cpp

Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1315,11 +1315,15 @@
 return LV;
   }
 
-  case Expr::CXXDefaultArgExprClass:
-return EmitLValue(cast(E)->getExpr());
+  case Expr::CXXDefaultArgExprClass: {
+auto *DAE = cast(E);
+CXXDefaultArgExprScope Scope(*this, DAE);
+return EmitLValue(DAE->getExpr());
+  }
   case Expr::CXXDefaultInitExprClass: {
-CXXDefaultInitExprScope Scope(*this);
-return EmitLValue(cast(E)->getExpr());
+auto *DIE = cast(E);
+CXXDefaultInitExprScope Scope(*this, DIE);
+return EmitLValue(DIE->getExpr());
   }
   case Expr::CXXTypeidExprClass:
 return EmitCXXTypeidLValue(cast(E));
Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -16,6 +16,7 @@
 #include "CGObjCRuntime.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
+#include "ConstantEmitter.h"
 #include "TargetInfo.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclObjC.h"
@@ -640,12 +641,20 @@
   Value *VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E) {
 return EmitLoadOfLValue(E);
   }
+  Value *VisitSourceLocExpr(SourceLocExpr *SLE) {
+auto  = CGF.getContext();
+APValue Evaluated =
+SLE->EvaluateInContext(Ctx, CGF.CurSourceLocExprScope.getDefaultExpr());
+return ConstantEmitter(CGF.CGM, )
+.emitAbstract(SLE->getLocation(), Evaluated, SLE->getType());
+  }
 
   Value *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) {
+CodeGenFunction::CXXDefaultArgExprScope Scope(CGF, DAE);
 return Visit(DAE->getExpr());
   }
   Value *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {
-CodeGenFunction::CXXDefaultInitExprScope Scope(CGF);
+CodeGenFunction::CXXDefaultInitExprScope Scope(CGF, DIE);
 return Visit(DIE->getExpr());
   }
   Value *VisitCXXThisExpr(CXXThisExpr *TE) {
Index: lib/CodeGen/CGExprConstant.cpp
===
--- lib/CodeGen/CGExprConstant.cpp
+++ lib/CodeGen/CGExprConstant.cpp
@@ -884,10 +884,6 @@
 llvm_unreachable("Invalid CastKind");
   }
 
-  llvm::Constant *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE, QualType T) {
-return Visit(DAE->getExpr(), T);
-  }
-
   llvm::Constant *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE, QualType T) {
 // No need for a DefaultInitExprScope: we don't handle 'this' in a
 // constant expression.
Index: lib/CodeGen/CGExprAgg.cpp
===
--- lib/CodeGen/CGExprAgg.cpp
+++ lib/CodeGen/CGExprAgg.cpp
@@ -165,10 +165,11 @@
   void VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
   void VisitNoInitExpr(NoInitExpr *E) { } // Do nothing.
   void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) {
+CodeGenFunction::CXXDefaultArgExprScope Scope(CGF, DAE);
 Visit(DAE->getExpr());
   }
   void VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {
-CodeGenFunction::CXXDefaultInitExprScope Scope(CGF);
+

r360937 - Implement __builtin_LINE() et. al. to support source location capture.

2019-05-16 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu May 16 14:04:15 2019
New Revision: 360937

URL: http://llvm.org/viewvc/llvm-project?rev=360937=rev
Log:
Implement __builtin_LINE() et. al. to support source location capture.

Summary:
This patch implements the source location builtins `__builtin_LINE(), 
`__builtin_FUNCTION()`, `__builtin_FILE()` and `__builtin_COLUMN()`. These 
builtins are needed to implement 
[`std::experimental::source_location`](https://rawgit.com/cplusplus/fundamentals-ts/v2/main.html#reflection.src_loc.creation).

With the exception of `__builtin_COLUMN`, GCC also implements these builtins, 
and Clangs behavior is intended to match as closely as possible. 

Reviewers: rsmith, joerg, aaron.ballman, bogner, majnemer, shafik, martong

Reviewed By: rsmith

Subscribers: rnkovacs, loskutov, riccibruno, mgorny, kunitoki, alexr, majnemer, 
hfinkel, cfe-commits

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

Added:
cfe/trunk/include/clang/AST/CurrentSourceLocExprScope.h
cfe/trunk/test/CodeGenCXX/builtin-source-location.cpp
cfe/trunk/test/CodeGenCXX/builtin_FUNCTION.cpp
cfe/trunk/test/CodeGenCXX/builtin_LINE.cpp
cfe/trunk/test/Parser/builtin_source_location.c
cfe/trunk/test/Sema/source_location.c
cfe/trunk/test/SemaCXX/Inputs/source-location-file.h
cfe/trunk/test/SemaCXX/source_location.cpp
Modified:
cfe/trunk/docs/LanguageExtensions.rst
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/Basic/StmtNodes.td
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/AST/ExprClassification.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprComplex.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/CodeGenCXX/debug-info-line.cpp
cfe/trunk/tools/libclang/CXCursor.cpp

Modified: cfe/trunk/docs/LanguageExtensions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.rst?rev=360937=360936=360937=diff
==
--- cfe/trunk/docs/LanguageExtensions.rst (original)
+++ cfe/trunk/docs/LanguageExtensions.rst Thu May 16 14:04:15 2019
@@ -2300,6 +2300,61 @@ automatically will insert one if the fir
 token `none`. If a user calls `__builin_suspend`, clang will insert `token 
none`
 as the first argument to the intrinsic.
 
+Source location builtins
+
+
+Clang provides experimental builtins to support C++ standard library 
implementation
+of ``std::experimental::source_location`` as specified in  
http://wg21.link/N4600.
+With the exception of ``__builtin_COLUMN``, these builtins are also 
implemented by
+GCC.
+
+**Syntax**:
+
+.. code-block:: c
+
+  const char *__builtin_FILE();
+  const char *__builtin_FUNCTION();
+  unsigned__builtin_LINE();
+  unsigned__builtin_COLUMN(); // Clang only
+
+**Example of use**:
+
+.. code-block:: c++
+
+  void my_assert(bool pred, int line = __builtin_LINE(), // Captures line of 
caller
+ const char* file = __builtin_FILE(),
+ const char* function = __builtin_FUNCTION()) {
+if (pred) return;
+printf("%s:%d assertion failed in function %s\n", file, line, function);
+std::abort();
+  }
+
+  struct MyAggregateType {
+int x;
+int line = __builtin_LINE(); // captures line where aggregate 
initialization occurs
+  };
+  static_assert(MyAggregateType{42}.line == __LINE__);
+
+  struct MyClassType {
+int line = __builtin_LINE(); // captures line of the constructor used 
during initialization
+constexpr MyClassType(int) { assert(line == __LINE__); }
+  };
+
+**Description**:
+
+The builtins ``__builtin_LINE``, ``__builtin_FUNCTION``, and 
``__builtin_FILE`` return
+the values, at the "invocation point", for ``__LINE__``, ``__FUNCTION__``, and
+``__FILE__`` respectively. These builtins are constant expressions.
+
+When the builtins appear as part of 

[PATCH] D61838: [Sema] Suppress additional warnings for C's zero initializer

2019-05-16 Thread Peter Wu via Phabricator via cfe-commits
Lekensteyn added a comment.

This looks reasonable to fix the problem at hand, but would it handle nested 
structures too?

  struct s1 {
 short f1;  // "int f1" is fine.
  };
  struct s2 {
 struct s1 f2;
 int x;
  };
  struct s3 {
 struct s2 f3;
 int x;
  };
  struct s2 x1 = {0};
  struct s3 x2 = {0};

produces this AST (`clang-check -ast-dump x.c --`):

  |-VarDecl 0x55e7bbc60390  col:11 x1 'struct s2':'struct 
s2' cinit
  | `-InitListExpr 0x55e7bbc60498  'struct s2':'struct s2'
  |   |-InitListExpr 0x55e7bbc604e8  'struct s1':'struct s1'
  |   | `-ImplicitCastExpr 0x55e7bbc60530  'short' 
  |   |   `-IntegerLiteral 0x55e7bbc60430  'int' 0
  |   `-ImplicitValueInitExpr 0x55e7bbc60548 <> 'int'
  |-VarDecl 0x55e7bbc605b0  col:11 x2 'struct s3':'struct 
s3' cinit
  | `-InitListExpr 0x55e7bbc60678  'struct s3':'struct s3'
  |   |-InitListExpr 0x55e7bbc606c8  'struct s2':'struct s2'
  |   | |-InitListExpr 0x55e7bbc60718  'struct s1':'struct s1'
  |   | | `-ImplicitCastExpr 0x55e7bbc60760  'short' 
  |   | |   `-IntegerLiteral 0x55e7bbc60610  'int' 0
  |   | `-ImplicitValueInitExpr 0x55e7bbc60778 <> 'int'
  |   `-ImplicitValueInitExpr 0x55e7bbc60788 <> 'int'


Repository:
  rC Clang

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

https://reviews.llvm.org/D61838



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


[PATCH] D59464: [analyzer] Add an example plugin for checker dependency handling

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

In D59464#1505435 , @phosek wrote:

> In D59464#1505323 , @Szelethus wrote:
>
> > I started to land other patches as well that depend on this one -- I won't 
> > object, but I'd prefer to find a solution, mostly because I don't even know 
> > how I could reproduce this error. The thing is, I merely moved some files 
> > from one directory to the other, which makes me scratch my head even more. 
> > That being said -- (see inlines)
>
>
> Which other changes have been landed that depend on this one?


rC360910 

> Our builders always perform a clean build to avoid any dirty state from 
> previous builds. Have you tried doing a clean build with your change?

Yes, I did clean, check-clang-analysis, clean, check-all, clean, check-clang.

> 
> 
>> If it's urgent, feel free to revert, I won't be near a computer until 
>> tomorrow.
> 
> If that's the case I'd prefer to revert it to avoid having the build broken 
> for another day.

Could you please take a look at my inline first? Could the fix be that simple? 
I'm really unsure as to how I could reproduce the error locally.

> In D59464#1505347 , @Szelethus wrote:
> 
>> Also, am I supposed to receive a mail from your buildbots? I unfortunately 
>> received none.
> 
> 
> We have builders on the silent master but they aren't stable enough yet to 
> promote to the stable master.




Repository:
  rL LLVM

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

https://reviews.llvm.org/D59464



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


[PATCH] D59464: [analyzer] Add an example plugin for checker dependency handling

2019-05-16 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Can we have a full build log?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59464



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


[PATCH] D61774: [LibTooling] Add RangeSelector library for defining source ranges based on bound AST nodes.

2019-05-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked 3 inline comments as done and an inline comment as not done.
ymandel added a comment.

Thanks for the review. Added the tests and undid changes to SourceCode.




Comment at: clang/include/clang/Tooling/Refactoring/RangeSelector.h:29
+
+namespace range_selector {
+inline RangeSelector charRange(CharSourceRange R) {

ilya-biryukov wrote:
> Maybe try putting it into the tooling namespace directly?
> Or are there immediate and unfortunate conflicts with existing names?
> 
> 
No conflicts. Was just being cautious.



Comment at: clang/include/clang/Tooling/Refactoring/RangeSelector.h:36
+/// \returns the range corresponding to the identified node.
+RangeSelector node(StringRef Id);
+/// Variant of \c node() that identifies the node as a statement, for purposes

ilya-biryukov wrote:
> NIT: I believe LLVM naming rules would mandate to name it  `ID`
here and throughout.



Comment at: clang/include/clang/Tooling/Refactoring/RangeSelector.h:53
+/// token of the relevant name, not including qualifiers.
+RangeSelector name(StringRef Id);
+

ilya-biryukov wrote:
> NIT: this is super-specialized, but has a very generic name, therefore might 
> cause confusion. Maybe call it `ctorInitializerName`?
It works with others as well, particularly NamedDecl. This is one place where 
typed node ids would be nice, b/c that would allow us to make this interface 
typed, like the matchers.

I kept the name but tried to clarify the comments.  WDYT?



Comment at: clang/include/clang/Tooling/Refactoring/RangeSelector.h:57
+// arguments (all source between the call's parentheses).
+RangeSelector args(StringRef Id);
+

ilya-biryukov wrote:
> Same thing, maybe rename to `callExprArgs`?
> And other nodes too
i'd like to keep these as lightweight as possible. Compromised on callArgs?



Comment at: clang/include/clang/Tooling/Refactoring/RangeSelector.h:74
+/// `SourceManager::getExpansionRange`.
+RangeSelector contraction(RangeSelector S);
+} // namespace range_selector

ilya-biryukov wrote:
> NIT: maybe call it `expansion`? 
> 
> `contraction` is a new term, might be confusing to use.
> 
> 
Sigh. You're right. Its just that the existing terminology is confusing.  that 
said, anyone using this combinator is already doing advanced work, so 
consistency is probably more important than clarity.



Comment at: clang/include/clang/Tooling/Refactoring/SourceCode.h:76
+
+SourceLocation findPreviousTokenStart(SourceLocation Start,
+  const SourceManager ,

ilya-biryukov wrote:
> Not sure this should be a public API. Maybe keep it private to the use-site?
Good point. Originally, we needed these in two different files -- but the range 
selectors actually obviate that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61774



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


[PATCH] D61774: [LibTooling] Add RangeSelector library for defining source ranges based on bound AST nodes.

2019-05-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 199896.
ymandel marked 9 inline comments as done.
ymandel added a comment.

comment tweak


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61774

Files:
  clang/include/clang/Tooling/Refactoring/RangeSelector.h
  clang/lib/Tooling/Refactoring/CMakeLists.txt
  clang/lib/Tooling/Refactoring/RangeSelector.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/RangeSelectorTest.cpp

Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -0,0 +1,466 @@
+//===- unittest/Tooling/RangeSelectorTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Refactoring/RangeSelector.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/FixIt.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace tooling;
+using namespace ast_matchers;
+
+namespace {
+using ::testing::AllOf;
+using ::testing::Eq;
+using ::testing::HasSubstr;
+using MatchResult = MatchFinder::MatchResult;
+using ::llvm::Expected;
+using ::llvm::Optional;
+
+struct TestMatch {
+  // The AST unit from which `result` is built. We bundle it because it backs
+  // the result. Users are not expected to access it.
+  std::unique_ptr AstUnit;
+  // The result to use in the test. References `ast_unit`.
+  MatchResult Result;
+};
+
+template 
+llvm::Optional matchAny(StringRef Code, M Matcher) {
+  auto AstUnit = buildASTFromCode(Code);
+  if (AstUnit == nullptr) {
+ADD_FAILURE() << "AST construction failed";
+return llvm::None;
+  }
+  ASTContext  = AstUnit->getASTContext();
+  if (Context.getDiagnostics().hasErrorOccurred()) {
+ADD_FAILURE() << "Compilation error";
+return llvm::None;
+  }
+  auto Matches = ast_matchers::match(Matcher, Context);
+  // We expect a single, exact match.
+  if (Matches.size() != 1) {
+ADD_FAILURE() << "Wrong number of matches: " << Matches.size();
+return llvm::None;
+  }
+  return TestMatch{std::move(AstUnit), MatchResult(Matches[0], )};
+}
+
+template 
+void test(M Matcher, RangeSelector Selector, StringRef Code,
+  StringRef Selected) {
+  Optional Match = matchAny(Code, Matcher);
+  ASSERT_TRUE(Match);
+  MatchResult  = Match->Result;
+  if (Expected Range = Selector(Result))
+EXPECT_EQ(fixit::internal::getText(*Range, *Result.Context), Selected);
+  else
+ADD_FAILURE() << llvm::toString(Range.takeError());
+}
+
+// Verifies that \c Selector fails when evaluated on \c Code.
+template 
+void testError(M Matcher, const RangeSelector , StringRef Code,
+   ::testing::Matcher ErrorMatcher) {
+  Optional Match = matchAny(Code, Matcher);
+  ASSERT_TRUE(Match);
+  auto Range = Selector(Match->Result);
+  if (Range) {
+ADD_FAILURE() << "Expected failure but succeeded";
+return;
+  }
+  auto Err = llvm::handleErrors(Range.takeError(),
+[](const llvm::StringError ) {
+  EXPECT_THAT(Err.getMessage(), ErrorMatcher);
+});
+  if (Err)
+ADD_FAILURE() << "Unhandled error: " << llvm::toString(std::move(Err));
+}
+
+// Tests failures caused by references to unbound nodes. `UnboundID` is the ID
+// that will cause the failure.
+void testUnboundNodeError(const RangeSelector , llvm::StringRef UnboundID) {
+  // We need to bind the result to something, or the match will fail. Create an
+  // ID from UnboundID to ensure they are different.
+  std::string BoundID = (UnboundID + "_").str();
+  testError(varDecl().bind(BoundID), S, "static int x = 0;",
+AllOf(HasSubstr(UnboundID), HasSubstr("not bound")));
+}
+
+// Tests failures caused by operations applied to nodes of the wrong type. For
+// convenience, binds a statement to "stmt", a (non-member) ctor-initializer to
+// "init", an expression to "expr" and a (nameless) declaration to "decl".
+void testTypeError(const RangeSelector , llvm::StringRef NodeID) {
+  StringRef Code = R"cc(
+  struct A {};
+  class F : public A {
+   public:
+F(int) {}
+  };
+  void g() { F f(1); }
+)cc";
+
+  auto Matcher =
+  compoundStmt(
+  hasDescendant(
+  cxxConstructExpr(
+  hasDeclaration(
+  decl(hasDescendant(cxxCtorInitializer(isBaseInitializer())
+ .bind("init")))
+  .bind("decl")))
+   

[PATCH] D61774: [LibTooling] Add RangeSelector library for defining source ranges based on bound AST nodes.

2019-05-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 199894.
ymandel marked 3 inline comments as done.
ymandel added a comment.

Add tests and back out changes to SourceCode.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61774

Files:
  clang/include/clang/Tooling/Refactoring/RangeSelector.h
  clang/lib/Tooling/Refactoring/CMakeLists.txt
  clang/lib/Tooling/Refactoring/RangeSelector.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/RangeSelectorTest.cpp

Index: clang/unittests/Tooling/RangeSelectorTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/RangeSelectorTest.cpp
@@ -0,0 +1,466 @@
+//===- unittest/Tooling/RangeSelectorTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Refactoring/RangeSelector.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/FixIt.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace tooling;
+using namespace ast_matchers;
+
+namespace {
+using ::testing::AllOf;
+using ::testing::Eq;
+using ::testing::HasSubstr;
+using MatchResult = MatchFinder::MatchResult;
+using ::llvm::Expected;
+using ::llvm::Optional;
+
+struct TestMatch {
+  // The AST unit from which `result` is built. We bundle it because it backs
+  // the result. Users are not expected to access it.
+  std::unique_ptr AstUnit;
+  // The result to use in the test. References `ast_unit`.
+  MatchResult Result;
+};
+
+template 
+llvm::Optional matchAny(StringRef Code, M Matcher) {
+  auto AstUnit = buildASTFromCode(Code);
+  if (AstUnit == nullptr) {
+ADD_FAILURE() << "AST construction failed";
+return llvm::None;
+  }
+  ASTContext  = AstUnit->getASTContext();
+  if (Context.getDiagnostics().hasErrorOccurred()) {
+ADD_FAILURE() << "Compilation error";
+return llvm::None;
+  }
+  auto Matches = ast_matchers::match(Matcher, Context);
+  // We expect a single, exact match.
+  if (Matches.size() != 1) {
+ADD_FAILURE() << "Wrong number of matches: " << Matches.size();
+return llvm::None;
+  }
+  return TestMatch{std::move(AstUnit), MatchResult(Matches[0], )};
+}
+
+template 
+void test(M Matcher, RangeSelector Selector, StringRef Code,
+  StringRef Selected) {
+  Optional Match = matchAny(Code, Matcher);
+  ASSERT_TRUE(Match);
+  MatchResult  = Match->Result;
+  if (Expected Range = Selector(Result))
+EXPECT_EQ(fixit::internal::getText(*Range, *Result.Context), Selected);
+  else
+ADD_FAILURE() << llvm::toString(Range.takeError());
+}
+
+// Verifies that \c Selector fails when evaluated on \c Code.
+template 
+void testError(M Matcher, const RangeSelector , StringRef Code,
+   ::testing::Matcher ErrorMatcher) {
+  Optional Match = matchAny(Code, Matcher);
+  ASSERT_TRUE(Match);
+  auto Range = Selector(Match->Result);
+  if (Range) {
+ADD_FAILURE() << "Expected failure but succeeded";
+return;
+  }
+  auto Err = llvm::handleErrors(Range.takeError(),
+[](const llvm::StringError ) {
+  EXPECT_THAT(Err.getMessage(), ErrorMatcher);
+});
+  if (Err)
+ADD_FAILURE() << "Unhandled error: " << llvm::toString(std::move(Err));
+}
+
+// Tests failures caused by references to unbound nodes. `UnboundID` is the ID
+// that will cause the failure.
+void testUnboundNodeError(const RangeSelector , llvm::StringRef UnboundID) {
+  // We need to bind the result to something, or the match will fail. Create an
+  // ID from UnboundID to ensure they are different.
+  std::string BoundID = (UnboundID + "_").str();
+  testError(varDecl().bind(BoundID), S, "static int x = 0;",
+AllOf(HasSubstr(UnboundID), HasSubstr("not bound")));
+}
+
+// Tests failures caused by operations applied to nodes of the wrong type. For
+// convenience, binds a statement to "stmt", a (non-member) ctor-initializer to
+// "init", an expression to "expr" and a (nameless) declaration to "decl".
+void testTypeError(const RangeSelector , llvm::StringRef NodeID) {
+  StringRef Code = R"cc(
+  struct A {};
+  class F : public A {
+   public:
+F(int) {}
+  };
+  void g() { F f(1); }
+)cc";
+
+  auto Matcher =
+  compoundStmt(
+  hasDescendant(
+  cxxConstructExpr(
+  hasDeclaration(
+  decl(hasDescendant(cxxCtorInitializer(isBaseInitializer())
+ .bind("init")))
+  

[PATCH] D37035: Implement __builtin_LINE() et. al. to support source location capture.

2019-05-16 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 199893.
EricWF marked an inline comment as done.
EricWF added a comment.

Merge with upstream.


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

https://reviews.llvm.org/D37035

Files:
  docs/LanguageExtensions.rst
  include/clang/AST/ASTContext.h
  include/clang/AST/CurrentSourceLocExprScope.h
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/Stmt.h
  include/clang/Basic/StmtNodes.td
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprConstant.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprObjC.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/CodeGenCXX/builtin-source-location.cpp
  test/CodeGenCXX/builtin_FUNCTION.cpp
  test/CodeGenCXX/builtin_LINE.cpp
  test/CodeGenCXX/debug-info-line.cpp
  test/Parser/builtin_source_location.c
  test/Sema/source_location.c
  test/SemaCXX/Inputs/source-location-file.h
  test/SemaCXX/source_location.cpp
  tools/libclang/CXCursor.cpp

Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -282,6 +282,7 @@
   case Stmt::ParenListExprClass:
   case Stmt::PredefinedExprClass:
   case Stmt::ShuffleVectorExprClass:
+  case Stmt::SourceLocExprClass:
   case Stmt::ConvertVectorExprClass:
   case Stmt::VAArgExprClass:
   case Stmt::ObjCArrayLiteralClass:
Index: test/SemaCXX/source_location.cpp
===
--- /dev/null
+++ test/SemaCXX/source_location.cpp
@@ -0,0 +1,590 @@
+// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
+// expected-no-diagnostics
+
+#define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42)
+#define CURRENT_FROM_MACRO() SL::current()
+#define FORWARD(...) __VA_ARGS__
+
+template 
+struct Printer;
+
+namespace std {
+namespace experimental {
+struct source_location {
+private:
+  unsigned int __m_line = 0;
+  unsigned int __m_col = 0;
+  const char *__m_file = nullptr;
+  const char *__m_func = nullptr;
+public:
+  static constexpr source_location current(
+  const char *__file = __builtin_FILE(),
+  const char *__func = __builtin_FUNCTION(),
+  unsigned int __line = __builtin_LINE(),
+  unsigned int __col = __builtin_COLUMN()) noexcept {
+source_location __loc;
+__loc.__m_line = __line;
+__loc.__m_col = __col;
+__loc.__m_file = __file;
+__loc.__m_func = __func;
+return __loc;
+  }
+  constexpr source_location() = default;
+  constexpr source_location(source_location const &) = default;
+  constexpr unsigned int line() const noexcept { return __m_line; }
+  constexpr unsigned int column() const noexcept { return __m_col; }
+  constexpr const char *file() const noexcept { return __m_file; }
+  constexpr const char *function() const noexcept { return __m_func; }
+};
+} // namespace experimental
+} // namespace std
+
+using SL = std::experimental::source_location;
+
+#include "Inputs/source-location-file.h"
+namespace SLF = source_location_file;
+
+constexpr bool is_equal(const char *LHS, const char *RHS) {
+  while (*LHS != 0 && *RHS != 0) {
+if (*LHS != *RHS)
+  return false;
+++LHS;
+++RHS;
+  }
+  return *LHS == 0 && *RHS == 0;
+}
+
+template 
+constexpr T identity(T t) {
+  return t;
+}
+
+template 
+struct Pair {
+  T first;
+  U second;
+};
+
+template 
+constexpr bool is_same = false;
+template 
+constexpr bool is_same = true;
+
+// test types
+static_assert(is_same);
+static_assert(is_same);
+static_assert(is_same);
+static_assert(is_same);
+
+// test noexcept
+static_assert(noexcept(__builtin_LINE()));
+static_assert(noexcept(__builtin_COLUMN()));
+static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FUNCTION()));
+
+//===--===//
+//__builtin_LINE()
+//===--===//
+
+namespace test_line {
+static_assert(SL::current().line() == __LINE__);
+static_assert(SL::current().line() == CURRENT_FROM_MACRO().line());
+
+static constexpr SL GlobalS = SL::current();
+
+static_assert(GlobalS.line() == __LINE__ - 2);
+
+// clang-format off
+constexpr bool test_line_fn() {
+  

[PATCH] D59464: [analyzer] Add an example plugin for checker dependency handling

2019-05-16 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D59464#1505323 , @Szelethus wrote:

> I started to land other patches as well that depend on this one -- I won't 
> object, but I'd prefer to find a solution, mostly because I don't even know 
> how I could reproduce this error. The thing is, I merely moved some files 
> from one directory to the other, which makes me scratch my head even more. 
> That being said -- (see inlines)


Which other changes have been landed that depend on this one?

Our builders always perform a clean build to avoid any dirty state from 
previous builds. Have you tried doing a clean build with your change?

> If it's urgent, feel free to revert, I won't be near a computer until 
> tomorrow.

If that's the case I'd prefer to revert it to avoid having the build broken for 
another day.

In D59464#1505347 , @Szelethus wrote:

> Also, am I supposed to receive a mail from your buildbots? I unfortunately 
> received none.


We have builders on the silent master but they aren't stable enough yet to 
promote to the stable master.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59464



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


[PATCH] D37035: Implement __builtin_LINE() et. al. to support source location capture.

2019-05-16 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF marked 14 inline comments as done.
EricWF added a comment.

Address review comments.




Comment at: lib/AST/ExprConstant.cpp:3370-3371
+
+  assert((!Base || !isa(Base)) &&
+ "Base should have already been transformed into a StringLiteral");
+

rsmith wrote:
> EricWF wrote:
> > rsmith wrote:
> > > There are lots of forms of expression that cannot be the base of an 
> > > `LValue` (see the list above `LValueExprEvaluator` for the expression 
> > > forms that *can* be the base of an `LValue`); is it important to give 
> > > this one special treatment?
> > Because a `SourceLocExpr` *can* be the base of an `LValue`. But the way 
> > that's supported is by transforming the `SourceLocExpr` into a 
> > `StringLiteral`. 
> I don't agree: a `SourceLocExpr` cannot be the base of an `LValue`. It is 
> evaluated into something else that can be (a `StringLiteral`), but it itself 
> cannot be (and this is in no way unusual; that's probably true of most `Expr` 
> nodes). I think this is a remnant of an earlier design?
Seems like it. Removed.


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

https://reviews.llvm.org/D37035



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


[PATCH] D61967: [clang-tidy] Add a close-on-exec check on pipe() in Android module.

2019-05-16 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv added inline comments.



Comment at: clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp:27
+void CloexecPipeCheck::check(const MatchFinder::MatchResult ) {
+  const std::string  =
+  (Twine("pipe2(") + getSpellingArg(Result, 0) + ", O_CLOEXEC)").str();

jcai19 wrote:
> george.burgess.iv wrote:
> > simplicity nit: can this be a `std::string`?
> replaceFunc takes a llvm::StringRef as the third parameter. StringRef is 
> "expected to be used in situations where the character data resides in some 
> other buffer, whose lifetime extends past that of the StringRef", which is 
> true in this case, so I think it should be fine.
Both should be functionally equivalent in this code. My point was that it's not 
common to rely on temporary lifetime extension when writing the non-`const&` 
type would be equivalent (barring maybe cases with `auto`, but that's not 
applicable), and I don't see why we should break with that here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61967



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


[PATCH] D61834: Add a Visit overload for DynTypedNode to ASTNodeTraverser

2019-05-16 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

In D61834#1505124 , @aaron.ballman 
wrote:

> In D61834#1505056 , @steveire wrote:
>
> > In D61834#1504665 , @aaron.ballman 
> > wrote:
> >
> > > What will be making use of/testing this new functionality?
> >
> >
> > Any code which has a `DynTypedNode` and wishes to traverse it.
> >
> > I envisage this as a more-flexible `DynTypedNode::dump` that the user does 
> > not have to implement themselves in order to use the `ASTNodeTraverser`.
>
>
> Do we currently have any such code that's using this functionality, though? 
> I'm mostly concerned that this is dead code with no testing, currently. The 
> functionality itself seems reasonable enough and the code looks correct 
> enough, so if this is part of a series of planned changes, that'd be good 
> information to have for the review.


Ah, yes. This is supposed to be 'useful public API' like the other Visit 
methods for use inside and outside the codebase. A follow-up patch will use it, 
but it's provided for external use too anyway.

I'll add a unit test.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61834



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


[PATCH] D61809: [BPF] Preserve debuginfo array/union/struct type name/access index

2019-05-16 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song marked an inline comment as done.
yonghong-song added inline comments.



Comment at: lib/CodeGen/CGExpr.cpp:3359
+// Remember the original array subscript for bpf target
+unsigned idx = cast(indices.back())->getZExtValue();
+eltPtr = CGF.Builder.CreatePreserveArrayAccessIndex(addr.getPointer(),

efriedma wrote:
> I don't think there's any reason to expect the array subscript is a 
> ConstantInt here?
right.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61809



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


[PATCH] D61835: Extract ASTDumper to a header file

2019-05-16 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

In D61835#1505314 , @aaron.ballman 
wrote:

> In D61835#1505280 , @steveire wrote:
>
> > In D61835#1505228 , @aaron.ballman 
> > wrote:
> >
> > > In D61835#1505202 , @steveire 
> > > wrote:
> > >
> > > > 3. Anyone who wants traversal in the same way that dumping is done and 
> > > > who needs to call API on the instance which is provided by 
> > > > ASTNodeTraverser (which ASTDumper inherits) needs to use ASTDumper. For 
> > > > example my UI. See my EuroLLVM talk for more: 
> > > > https://steveire.wordpress.com/2019/04/30/the-future-of-ast-matching-refactoring-tools-eurollvm-and-accu/
> > >
> > >
> > > Do they? Why is the `ASTNodeTraverser` insufficient?
> >
> >
> > It doesn't have the same behavior as `ASTDumper`, because `ASTDumper` 
> > "overrides" some `Visit` metthods.
>
>
> I'm aware that they're different, but I may not have been sufficiently clear. 
> I'm saying that the only public APIs I think a user should be calling are 
> inherited from `ASTNodeTraverser` and not `ASTDumper`, so it is not required 
> to expose `ASTDumper` directly, only a way to get an `ASTNodeTraverser` 
> reference/pointer to an `ASTDumper` instance so that you get the correct 
> virtual dispatch. e.g., `ASTNodeTraverser 
> *getSomethingThatActsLikeAnASTDumper() { return new ASTDumper; }`


Perhaps. One way to implement the 'less noise' version of AST output (ie 
removing pointer addresses etc http://ce.steveire.com/z/HaCLeO ) is to make it 
an API on the `TextNodeDumper`. Then `ASTDumper` would need a forwarding API 
for it.

Anyway, your argument also applies to `JSONNodeDumper`, but you put that in a 
header file. That was sane. We should move `ASTDumper` to a header similarly. 
(Perhaps a rename of the class would help though?)


Repository:
  rC Clang

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

https://reviews.llvm.org/D61835



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


[PATCH] D59628: Add support for __attribute__((objc_class_stub))

2019-05-16 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Thanks!  Down to minor stuff now.




Comment at: clang/include/clang/Basic/Attr.td:291
+  string CustomCode = customCode;
 }
 def MicrosoftExt : LangOpt<"MicrosoftExt">;

Please add a comment here explaining how to use `CustomCode`.

Can we just remove `Negated` and define `COnly` as `!LangOpts.CPlusPlus`?


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

https://reviews.llvm.org/D59628



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


[PATCH] D62009: [clang] perform semantic checking in constant context

2019-05-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D62009#1505263 , @Tyker wrote:

> i added this bit because when we eventually store the result of evaluation in 
> ConstantExpr we will probably want to trail-allocate the APValue's possible 
> representations separately to limit memory consumption. but if we do this the 
> ConstantExpr node will need to be created after evaluation of the value to 
> allocate the right space and we will need an other way to mark that the 
> expression should be evaluated in constant context.


Even if we want to tail-allocate (which does seem like a nice idea in the long 
term), we don't need to mark the expression for that: we can pass a flag into 
the constant evaluator to indicate that we're evaluating an expression with the 
intent of forming a `ConstantExpr`. (We already do that for `EvaluateAsRValue`; 
we'll need to do the same for other entry points that could be evaluating at 
the top level in a constant context.)


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

https://reviews.llvm.org/D62009



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


[PATCH] D59464: [analyzer] Add an example plugin for checker dependency handling

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

Also, am I supposed to receive a mail from your buildbots? I unfortunately 
received none.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59464



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


[PATCH] D61837: Make it possible control matcher traversal kind with ASTContext

2019-05-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/ASTMatchers/ASTMatchers.h:718
+template 
+internal::Matcher traverse(ast_type_traits::TraversalKind TK,
+  const internal::Matcher ) {

steveire wrote:
> aaron.ballman wrote:
> > steveire wrote:
> > > aaron.ballman wrote:
> > > > Is this an API we should be exposing to clang-query as well? Will those 
> > > > users be able to use a string literal for the traversal kind, like they 
> > > > already do for attribute kinds (etc)?
> > > Yes, I thought about that, but in a follow-up patch. First, I aim to 
> > > extend the `TraversalKind` enum with `TK_IgnoreInvisble`.
> > This is new functionality, so why do you want to wait for a follow-up patch 
> > (is it somehow more involved)? We typically add support for dynamic 
> > matchers at the same time we add support for the static matchers because 
> > otherwise the two get frustratingly out of sync.
> Perhaps I can add the support in DynamicASTMatchers. Can you give some 
> direction on that? I don't recall where the attr strings are handled.
> 
> A corresponding change to `clang-query` will be in another patch anyway 
> because it's a different repo.
> Perhaps I can add the support in DynamicASTMatchers. Can you give some 
> direction on that? I don't recall where the attr strings are handled.

I always wind up having to use svn blame to figure it out, so you're not alone 
in your recollections. ;-) You add a new specialization of `ArgTypeTraits` to 
Marshallers.h for the enumeration type. See around line 123 or so for how it's 
done for `attr::Kind`.

> A corresponding change to clang-query will be in another patch anyway because 
> it's a different repo.

Once you have the enumeration being marshaled, I believe all you have to do is 
expose the new API via Registry.cpp like any other matcher, though I'd also 
request tests be added to Dynamic/RegistryTest.cpp since this is adding a small 
amount of new marshaling code.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61837



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


[PATCH] D59628: Add support for __attribute__((objc_class_stub))

2019-05-16 Thread Slava Pestov via Phabricator via cfe-commits
slavapestov updated this revision to Diff 199885.
slavapestov added a comment.

Updated patch to address review feedback.


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

https://reviews.llvm.org/D59628

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/ObjCRuntime.h
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclObjC.cpp
  clang/test/CodeGenObjC/class-stubs.m
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaObjC/class-stub-attr-unsupported.m
  clang/test/SemaObjC/class-stub-attr.m
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1922,6 +1922,34 @@
   return true;
 }
 
+static std::string GenerateTestExpression(ArrayRef LangOpts) {
+  std::string Test;
+
+  for (auto *E : LangOpts) {
+if (!Test.empty())
+  Test += " || ";
+
+if (E->getValueAsBit("Negated")) {
+  Test += "!";
+}
+
+const StringRef Code = E->getValueAsString("CustomCode");
+if (!Code.empty()) {
+  Test += "(";
+  Test += Code;
+  Test += ")";
+} else {
+  Test += "LangOpts.";
+  Test += E->getValueAsString("Name");
+}
+  }
+
+  if (Test.empty())
+return "true";
+
+  return Test;
+}
+
 std::string
 PragmaClangAttributeSupport::generateStrictConformsTo(const Record ,
   raw_ostream ) {
@@ -1948,19 +1976,8 @@
   // rules if the specific language options are specified.
   std::vector LangOpts = Rule.getLangOpts();
   OS << "  MatchRules.push_back(std::make_pair(" << Rule.getEnumValue()
- << ", /*IsSupported=*/";
-  if (!LangOpts.empty()) {
-for (auto I = LangOpts.begin(), E = LangOpts.end(); I != E; ++I) {
-  const StringRef Part = (*I)->getValueAsString("Name");
-  if ((*I)->getValueAsBit("Negated"))
-OS << "!";
-  OS << "LangOpts." << Part;
-  if (I + 1 != E)
-OS << " || ";
-}
-  } else
-OS << "true";
-  OS << "));\n";
+ << ", /*IsSupported=*/" << GenerateTestExpression(LangOpts)
+ << "));\n";
 }
   }
   OS << "}\n\n";
@@ -3431,22 +3448,14 @@
   if (LangOpts.empty())
 return "defaultDiagnoseLangOpts";
 
-  // Generate the test condition, as well as a unique function name for the
-  // diagnostic test. The list of options should usually be short (one or two
-  // options), and the uniqueness isn't strictly necessary (it is just for
-  // codegen efficiency).
-  std::string FnName = "check", Test;
+  // Generate a unique function name for the diagnostic test. The list of
+  // options should usually be short (one or two options), and the
+  // uniqueness isn't strictly necessary (it is just for codegen efficiency).
+  std::string FnName = "check";
   for (auto I = LangOpts.begin(), E = LangOpts.end(); I != E; ++I) {
-const StringRef Part = (*I)->getValueAsString("Name");
-if ((*I)->getValueAsBit("Negated")) {
+if ((*I)->getValueAsBit("Negated"))
   FnName += "Not";
-  Test += "!";
-}
-Test += "S.LangOpts.";
-Test +=  Part;
-if (I + 1 != E)
-  Test += " || ";
-FnName += Part;
+FnName += (*I)->getValueAsString("Name");
   }
   FnName += "LangOpts";
 
@@ -3458,7 +3467,8 @@
 return *I;
 
   OS << "static bool " << FnName << "(Sema , const ParsedAttr ) {\n";
-  OS << "  if (" << Test << ")\n";
+  OS << "  auto  = S.LangOpts;\n";
+  OS << "  if (" << GenerateTestExpression(LangOpts) << ")\n";
   OS << "return true;\n\n";
   OS << "  S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) ";
   OS << "<< Attr.getName();\n";
Index: clang/test/SemaObjC/class-stub-attr.m
===
--- /dev/null
+++ clang/test/SemaObjC/class-stub-attr.m
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-apple-darwin -fsyntax-only -Xclang -verify %s
+// RUN: %clang -target x86_64-apple-darwin -x objective-c++ -fsyntax-only -Xclang -verify %s
+
+@interface NSObject
+@end
+
+__attribute__((objc_class_stub))
+@interface MissingSubclassingRestrictedAttribute : NSObject // expected-error {{'objc_class_stub' attribute cannot be specified on a class that does not have the 'objc_subclassing_restricted' attribute}}
+@end
+
+__attribute__((objc_class_stub))
+__attribute__((objc_subclassing_restricted))
+@interface ValidClassStubAttribute : NSObject
+@end
+
+@implementation ValidClassStubAttribute // expected-error {{cannot declare implementation of a class declared with the 'objc_class_stub' attribute}}
+@end
+
+@implementation ValidClassStubAttribute (MyCategory)
+@end
+
+__attribute__((objc_class_stub(123))) // 

[PATCH] D59464: [analyzer] Add an example plugin for checker dependency handling

2019-05-16 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked an inline comment as done.
Szelethus added a comment.

In D59464#1505200 , @phosek wrote:

> All our bots are failing which seems to have been caused by the latest reland:
>
>   FAIL: Clang :: Analysis/checker-plugins.c (297 of 14793)
>    TEST 'Clang :: Analysis/checker-plugins.c' FAILED 
> 
>   Script:
>   --
>   : 'RUN: at line 1';   
> /b/s/w/ir/k/recipe_cleanup/clangsCGbgY/llvm_build_dir/bin/clang -cc1 
> -internal-isystem 
> /b/s/w/ir/k/recipe_cleanup/clangsCGbgY/llvm_build_dir/lib/clang/9.0.0/include 
> -nostdsysteminc -analyze -analyzer-constraints=range -verify 
> /b/s/w/ir/k/llvm-project/clang/test/Analysis/checker-plugins.c-load 
> /b/s/w/ir/k/recipe_cleanup/clangsCGbgY/llvm_build_dir/./lib/SampleAnalyzerPlugin.so
> -analyzer-checker='example.MainCallChecker'
>   : 'RUN: at line 15';   
> /b/s/w/ir/k/recipe_cleanup/clangsCGbgY/llvm_build_dir/bin/clang -cc1 
> -internal-isystem 
> /b/s/w/ir/k/recipe_cleanup/clangsCGbgY/llvm_build_dir/lib/clang/9.0.0/include 
> -nostdsysteminc -analyze -analyzer-constraints=range 
> /b/s/w/ir/k/llvm-project/clang/test/Analysis/checker-plugins.c-load 
> /b/s/w/ir/k/recipe_cleanup/clangsCGbgY/llvm_build_dir/./lib/CheckerDependencyHandlingAnalyzerPlugin.so
>-analyzer-checker=example.DependendentChecker
> -analyzer-list-enabled-checkers2>&1 | 
> /b/s/w/ir/k/recipe_cleanup/clangsCGbgY/llvm_build_dir/bin/FileCheck 
> /b/s/w/ir/k/llvm-project/clang/test/Analysis/checker-plugins.c 
> -check-prefix=CHECK-IMPLICITLY-ENABLED
>   : 'RUN: at line 24';   
> /b/s/w/ir/k/recipe_cleanup/clangsCGbgY/llvm_build_dir/bin/clang -cc1 
> -internal-isystem 
> /b/s/w/ir/k/recipe_cleanup/clangsCGbgY/llvm_build_dir/lib/clang/9.0.0/include 
> -nostdsysteminc -analyze -analyzer-constraints=range 
> /b/s/w/ir/k/llvm-project/clang/test/Analysis/checker-plugins.c-load 
> /b/s/w/ir/k/recipe_cleanup/clangsCGbgY/llvm_build_dir/./lib/CheckerDependencyHandlingAnalyzerPlugin.so
>-analyzer-checker=example.DependendentChecker
> -analyzer-disable-checker=example.Dependency
> -analyzer-list-enabled-checkers2>&1 | 
> /b/s/w/ir/k/recipe_cleanup/clangsCGbgY/llvm_build_dir/bin/FileCheck 
> /b/s/w/ir/k/llvm-project/clang/test/Analysis/checker-plugins.c 
> -check-prefix=CHECK-IMPLICITLY-DISABLED
>   --
>   Exit Code: 1
>  
>   Command Output (stderr):
>   --
>   error: 'error' diagnostics seen but not expected: 
> (frontend): unable to load plugin 
> '/b/s/w/ir/k/recipe_cleanup/clangsCGbgY/llvm_build_dir/./lib/SampleAnalyzerPlugin.so':
>  
> '/b/s/w/ir/k/recipe_cleanup/clangsCGbgY/llvm_build_dir/./lib/SampleAnalyzerPlugin.so:
>  undefined symbol: _ZN4llvm14FoldingSetBase6anchorEv'
>  
>   --
>  
>   
>   Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
>   Testing Time: 77.86s
>   
>   Failing Tests (1):
>   Clang :: Analysis/checker-plugins.c
>
>
> Is it possible to revert this change again?


I started to land other patches as well that depend on this one -- I won't 
object, but I'd prefer to find a solution, mostly because I don't even know how 
I could reproduce this error. The thing is, I merely moved some files from one 
directory to the other, which makes me scratch my head even more. That being 
said -- (see inlines)

If it's urgent, feel free to revert, I won't be near a computer until tomorrow.




Comment at: cfe/trunk/test/Analysis/plugins/SampleAnalyzer/CMakeLists.txt:4
+
+if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
+  target_link_libraries(SampleAnalyzerPlugin PRIVATE

Is it possible that if we tweaked this line the error would go away?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59464



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


[PATCH] D61837: Make it possible control matcher traversal kind with ASTContext

2019-05-16 Thread Stephen Kelly via Phabricator via cfe-commits
steveire marked 2 inline comments as done.
steveire added inline comments.



Comment at: include/clang/ASTMatchers/ASTMatchers.h:718
+template 
+internal::Matcher traverse(ast_type_traits::TraversalKind TK,
+  const internal::Matcher ) {

aaron.ballman wrote:
> steveire wrote:
> > aaron.ballman wrote:
> > > Is this an API we should be exposing to clang-query as well? Will those 
> > > users be able to use a string literal for the traversal kind, like they 
> > > already do for attribute kinds (etc)?
> > Yes, I thought about that, but in a follow-up patch. First, I aim to extend 
> > the `TraversalKind` enum with `TK_IgnoreInvisble`.
> This is new functionality, so why do you want to wait for a follow-up patch 
> (is it somehow more involved)? We typically add support for dynamic matchers 
> at the same time we add support for the static matchers because otherwise the 
> two get frustratingly out of sync.
Perhaps I can add the support in DynamicASTMatchers. Can you give some 
direction on that? I don't recall where the attr strings are handled.

A corresponding change to `clang-query` will be in another patch anyway because 
it's a different repo.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61837



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


[PATCH] D61809: [BPF] Preserve debuginfo array/union/struct type name/access index

2019-05-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: lib/CodeGen/CGExpr.cpp:3359
+// Remember the original array subscript for bpf target
+unsigned idx = cast(indices.back())->getZExtValue();
+eltPtr = CGF.Builder.CreatePreserveArrayAccessIndex(addr.getPointer(),

I don't think there's any reason to expect the array subscript is a ConstantInt 
here?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61809



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


[PATCH] D61835: Extract ASTDumper to a header file

2019-05-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D61835#1505280 , @steveire wrote:

> In D61835#1505228 , @aaron.ballman 
> wrote:
>
> > In D61835#1505202 , @steveire 
> > wrote:
> >
> > > 3. Anyone who wants traversal in the same way that dumping is done and 
> > > who needs to call API on the instance which is provided by 
> > > ASTNodeTraverser (which ASTDumper inherits) needs to use ASTDumper. For 
> > > example my UI. See my EuroLLVM talk for more: 
> > > https://steveire.wordpress.com/2019/04/30/the-future-of-ast-matching-refactoring-tools-eurollvm-and-accu/
> >
> >
> > Do they? Why is the `ASTNodeTraverser` insufficient?
>
>
> It doesn't have the same behavior as `ASTDumper`, because `ASTDumper` 
> "overrides" some `Visit` metthods.


I'm aware that they're different, but I may not have been sufficiently clear. 
I'm saying that the only public APIs I think a user should be calling are 
inherited from `ASTNodeTraverser` and not `ASTDumper`, so it is not required to 
expose `ASTDumper` directly, only a way to get an `ASTNodeTraverser` 
reference/pointer to an `ASTDumper` instance so that you get the correct 
virtual dispatch. e.g., `ASTNodeTraverser 
*getSomethingThatActsLikeAnASTDumper() { return new ASTDumper; }`


Repository:
  rC Clang

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

https://reviews.llvm.org/D61835



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


[PATCH] D61837: Make it possible control matcher traversal kind with ASTContext

2019-05-16 Thread Stephen Kelly via Phabricator via cfe-commits
steveire updated this revision to Diff 199884.
steveire added a comment.

Update


Repository:
  rC Clang

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

https://reviews.llvm.org/D61837

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/ASTNodeTraverser.h
  include/clang/ASTMatchers/ASTMatchers.h
  include/clang/ASTMatchers/ASTMatchersInternal.h
  lib/AST/ASTContext.cpp
  lib/ASTMatchers/ASTMatchFinder.cpp
  lib/ASTMatchers/ASTMatchersInternal.cpp
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1510,6 +1510,72 @@
   notMatches("class C {}; C a = C();", varDecl(has(cxxConstructExpr();
 }
 
+TEST(Traversal, traverseMatcher) {
+
+  StringRef VarDeclCode = R"cpp(
+void foo()
+{
+  int i = 3.0;
+}
+)cpp";
+
+  auto Matcher = varDecl(hasInitializer(floatLiteral()));
+
+  EXPECT_TRUE(
+  notMatches(VarDeclCode, traverse(ast_type_traits::TK_AsIs, Matcher)));
+  EXPECT_TRUE(
+  matches(VarDeclCode,
+  traverse(ast_type_traits::TK_IgnoreImplicitCastsAndParentheses,
+   Matcher)));
+}
+
+TEST(Traversal, traverseMatcherNesting) {
+
+  StringRef Code = R"cpp(
+float bar(int i)
+{
+  return i;
+}
+
+void foo()
+{
+  bar(bar(3.0));
+}
+)cpp";
+
+  EXPECT_TRUE(matches(
+  Code,
+  traverse(ast_type_traits::TK_IgnoreImplicitCastsAndParentheses,
+   callExpr(has(callExpr(traverse(
+   ast_type_traits::TK_AsIs,
+   callExpr(has(implicitCastExpr(has(floatLiteral(;
+}
+
+TEST(Traversal, traverseMatcherThroughMemoization) {
+
+  StringRef Code = R"cpp(
+void foo()
+{
+  int i = 3.0;
+}
+  )cpp";
+
+  auto Matcher = varDecl(hasInitializer(floatLiteral()));
+
+  // Matchers such as hasDescendant memoize their result regarding AST
+  // nodes. In the matcher below, the first use of hasDescendant(Matcher)
+  // fails, and the use of it inside the traverse() matcher should pass
+  // causing the overall matcher to be a true match.
+  // This test verifies that the first false result is not re-used, which
+  // would cause the overall matcher to be incorrectly false.
+
+  EXPECT_TRUE(matches(
+  Code, functionDecl(anyOf(
+hasDescendant(Matcher),
+traverse(ast_type_traits::TK_IgnoreImplicitCastsAndParentheses,
+ functionDecl(hasDescendant(Matcher)));
+}
+
 TEST(IgnoringImpCasts, MatchesImpCasts) {
   // This test checks that ignoringImpCasts matches when implicit casts are
   // present and its inner matcher alone does not match.
Index: lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- lib/ASTMatchers/ASTMatchersInternal.cpp
+++ lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -211,10 +211,19 @@
 bool DynTypedMatcher::matches(const ast_type_traits::DynTypedNode ,
   ASTMatchFinder *Finder,
   BoundNodesTreeBuilder *Builder) const {
-  if (RestrictKind.isBaseOf(DynNode.getNodeKind()) &&
-  Implementation->dynMatches(DynNode, Finder, Builder)) {
+  auto PreviousTraversalKind = Finder->getASTContext().GetTraversalKind();
+  auto OptTK = Implementation->TraversalKind();
+  if (OptTK)
+Finder->getASTContext().SetTraversalKind(*OptTK);
+  auto N = Finder->getASTContext().TraverseIgnored(DynNode);
+  auto NodeKind = N.getNodeKind();
+
+  if (RestrictKind.isBaseOf(NodeKind) &&
+  Implementation->dynMatches(N, Finder, Builder)) {
+Finder->getASTContext().SetTraversalKind(PreviousTraversalKind);
 return true;
   }
+  Finder->getASTContext().SetTraversalKind(PreviousTraversalKind);
   // Delete all bindings when a matcher does not match.
   // This prevents unexpected exposure of bound nodes in unmatches
   // branches of the match tree.
@@ -225,8 +234,11 @@
 bool DynTypedMatcher::matchesNoKindCheck(
 const ast_type_traits::DynTypedNode , ASTMatchFinder *Finder,
 BoundNodesTreeBuilder *Builder) const {
-  assert(RestrictKind.isBaseOf(DynNode.getNodeKind()));
-  if (Implementation->dynMatches(DynNode, Finder, Builder)) {
+  auto N = Finder->getASTContext().TraverseIgnored(DynNode);
+  auto NodeKind = N.getNodeKind();
+
+  assert(RestrictKind.isBaseOf(NodeKind));
+  if (Implementation->dynMatches(N, Finder, Builder)) {
 return true;
   }
   // Delete all bindings when a matcher does not match.
Index: lib/ASTMatchers/ASTMatchFinder.cpp
===
--- lib/ASTMatchers/ASTMatchFinder.cpp
+++ lib/ASTMatchers/ASTMatchFinder.cpp
@@ -59,10 +59,12 @@
   DynTypedMatcher::MatcherIDType MatcherID;
   ast_type_traits::DynTypedNode Node;
   BoundNodesTreeBuilder BoundNodes;
+  ast_type_traits::TraversalKind Traversal = 

[PATCH] D61835: Extract ASTDumper to a header file

2019-05-16 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

In D61835#1505228 , @aaron.ballman 
wrote:

> In D61835#1505202 , @steveire wrote:
>
> > 3. Anyone who wants traversal in the same way that dumping is done and who 
> > needs to call API on the instance which is provided by ASTNodeTraverser 
> > (which ASTDumper inherits) needs to use ASTDumper. For example my UI. See 
> > my EuroLLVM talk for more: 
> > https://steveire.wordpress.com/2019/04/30/the-future-of-ast-matching-refactoring-tools-eurollvm-and-accu/
>
>
> Do they? Why is the `ASTNodeTraverser` insufficient?


It doesn't have the same behavior as `ASTDumper`, because `ASTDumper` 
"overrides" some `Visit` metthods.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61835



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


[PATCH] D61756: Add a __FILE_NAME__ macro.

2019-05-16 Thread Kristina Brooks via Phabricator via cfe-commits
kristina updated this revision to Diff 199882.
kristina edited the summary of this revision.
kristina added a comment.

Revised to use `llvm::sys::path::filename` to avoid issues on Windows hosts.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61756

Files:
  include/clang/Lex/Preprocessor.h
  lib/Lex/PPMacroExpansion.cpp
  test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h
  test/Preprocessor/Inputs/include-subdir/h
  test/Preprocessor/Inputs/include-subdir/subdir1/hdr1.h
  test/Preprocessor/Inputs/include-subdir/subdir1/hdr2.h
  test/Preprocessor/file_name_macro.c

Index: test/Preprocessor/file_name_macro.c
===
--- test/Preprocessor/file_name_macro.c
+++ test/Preprocessor/file_name_macro.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -E %s -I%S/Inputs | FileCheck -strict-whitespace %s
+// RUN: %clang_cc1 -fms-compatibility -DMS -E %s -I%S/Inputs | FileCheck -check-prefix=CHECK-MS -strict-whitespace %s 
+// RUN: %clang_cc1 -E %s -I%S/Inputs -DBADINC -verify
+
+#ifdef BADINC
+
+// Paranoia.
+
+__FILE_NAME__
+#include  // expected-error {{file not found}}
+__FILE_NAME__
+
+#else
+
+// Reference.
+1: "file_name_macro.c"
+
+// Ensure it expands correctly for this file.
+2: __FILE_NAME__
+
+// CHECK: {{^}}1: "file_name_macro.c"
+// CHECK: {{^}}2: "file_name_macro.c"
+
+// Test if inclusion works right.
+#ifdef MS
+#include 
+// MS compatibility allows for mixed separators in paths.
+#include 
+#include 
+#else
+#include 
+#endif
+
+#include 
+
+// CHECK: {{^}}3: "file_name_macro_include.h"
+// CHECK: {{^}}4: "file_name_macro_include.h"
+// CHECK-NOT: {{^}}5: "file_name_macro_include.h"
+// CHECK-MS: {{^}}5: "file_name_macro_include.h"
+// CHECK: {{^}}6: "h"
+// CHECK-MS: {{^}}7: "hdr1.h"
+// CHECK-MS: {{^}}8: "hdr2.h"
+
+#endif
Index: test/Preprocessor/Inputs/include-subdir/subdir1/hdr2.h
===
--- test/Preprocessor/Inputs/include-subdir/subdir1/hdr2.h
+++ test/Preprocessor/Inputs/include-subdir/subdir1/hdr2.h
@@ -0,0 +1 @@
+8: __FILE_NAME__
Index: test/Preprocessor/Inputs/include-subdir/subdir1/hdr1.h
===
--- test/Preprocessor/Inputs/include-subdir/subdir1/hdr1.h
+++ test/Preprocessor/Inputs/include-subdir/subdir1/hdr1.h
@@ -0,0 +1 @@
+7: __FILE_NAME__
Index: test/Preprocessor/Inputs/include-subdir/h
===
--- test/Preprocessor/Inputs/include-subdir/h
+++ test/Preprocessor/Inputs/include-subdir/h
@@ -0,0 +1 @@
+6: __FILE_NAME__
Index: test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h
===
--- test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h
+++ test/Preprocessor/Inputs/include-subdir/file_name_macro_include.h
@@ -0,0 +1,6 @@
+3: __FILE_NAME__
+4: "file_name_macro_include.h"
+#ifdef MS
+// Should be the same even when included with backslash.
+5: __FILE_NAME__
+#endif
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -43,6 +43,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -363,6 +364,7 @@
   }
 
   // Clang Extensions.
+  Ident__FILE_NAME__  = RegisterBuiltinMacro(*this, "__FILE_NAME__");
   Ident__has_feature  = RegisterBuiltinMacro(*this, "__has_feature");
   Ident__has_extension= RegisterBuiltinMacro(*this, "__has_extension");
   Ident__has_builtin  = RegisterBuiltinMacro(*this, "__has_builtin");
@@ -1474,7 +1476,8 @@
 // __LINE__ expands to a simple numeric value.
 OS << (PLoc.isValid()? PLoc.getLine() : 1);
 Tok.setKind(tok::numeric_constant);
-  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
+  } else if (II == Ident__FILE__ || II == Ident__BASE_FILE__ ||
+ II == Ident__FILE_NAME__) {
 // C99 6.10.8: "__FILE__: The presumed name of the current source file (a
 // character string literal)". This can be affected by #line.
 PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
@@ -1495,7 +1498,19 @@
 // Escape this filename.  Turn '\' -> '\\' '"' -> '\"'
 SmallString<128> FN;
 if (PLoc.isValid()) {
-  FN += PLoc.getFilename();
+  // __FILE_NAME__ is a Clang-specific extension that expands to the
+  // the last part of __FILE__.
+  if (II == Ident__FILE_NAME__) {
+// Try to get the last path component, failing that return the original
+// presumed location.
+StringRef PLFileName = llvm::sys::path::filename(PLoc.getFilename());
+if (PLFileName != "")
+  FN += 

[PATCH] D62009: [clang] perform semantic checking in constant context

2019-05-16 Thread Tyker via Phabricator via cfe-commits
Tyker added a comment.

i added this bit because when we eventually store the result of evaluation in 
ConstantExpr we will probably want to trail-allocate the APValue's possible 
representations separately to limit memory consumption. but if we do this the 
ConstantExpr node will need to be created after evaluation of the value, so we 
cannot use it to mark that the expression should be evaluated in constant 
context.
if we won't store APValue's possible representations separately in 
trail-allocate space, wrapping the expression in a ConstantExpr is the right 
solution.


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

https://reviews.llvm.org/D62009



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


[PATCH] D61967: [clang-tidy] Add a close-on-exec check on pipe() in Android module.

2019-05-16 Thread Jian Cai via Phabricator via cfe-commits
jcai19 marked 2 inline comments as done.
jcai19 added inline comments.



Comment at: clang-tools-extra/test/clang-tidy/android-cloexec-pipe.cpp:9
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer pipe2() to pipe() because 
pipe2() allows O_CLOEXEC [android-cloexec-pipe]
+  // CHECK-FIXES: pipe2(pipefd, O_CLOEXEC);
+}

george.burgess.iv wrote:
> (Do we have a CHECK-FIXES-NOT or CHECK-MESSAGES-NOT to apply to the things 
> below? Or are the CHECKs here meant to be complete like clang's `-verify`?)
Based on Testing Checks 
https://clang.llvm.org/extra/clang-tidy/Contributing.html, CHECK-MASSAGES and 
CHECK-FIXES are sufficient for clang-tidy checks. I have double checked the 
tests for similar checks and they don't seem to have additional FileCheck 
invocations other than these two.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61967



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


  1   2   3   >