[PATCH] D55552: [Sema] Better static assert diagnostics for expressions involving temporaries.

2018-12-19 Thread Clement Courbet via Phabricator via cfe-commits
courbet updated this revision to Diff 179018.
courbet marked 3 inline comments as done.
courbet added a comment.

address review comments


Repository:
  rC Clang

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

https://reviews.llvm.org/D2

Files:
  include/clang/AST/PrettyPrinter.h
  include/clang/AST/Type.h
  lib/AST/TypePrinter.cpp
  lib/Sema/SemaTemplate.cpp
  test/SemaCXX/static-assert-cxx17.cpp
  test/SemaCXX/static-assert.cpp

Index: test/SemaCXX/static-assert.cpp
===
--- test/SemaCXX/static-assert.cpp
+++ test/SemaCXX/static-assert.cpp
@@ -76,6 +76,8 @@
   static const Tp value = v;
   typedef Tp value_type;
   typedef integral_constant type;
+  constexpr operator value_type() const noexcept { return value; }
+  constexpr value_type operator()() const noexcept { return value; }
 };
 
 template 
@@ -103,6 +105,7 @@
 } // namespace std
 
 struct ExampleTypes {
+  explicit ExampleTypes(int);
   using T = int;
   using U = float;
 };
@@ -119,6 +122,18 @@
 // expected-error@-1{{static_assert failed due to requirement 'std::is_const::value == false' "message"}}
 static_assert(!(std::is_const::value == true), "message");
 // expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value == true)' "message"}}
+static_assert(std::is_const(), "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const()' "message"}}
+static_assert(!(std::is_const()()), "message");
+// expected-error@-1{{static_assert failed due to requirement '!(std::is_const()())' "message"}}
+static_assert(std::is_same()), int>::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_same, int>::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
 
 struct BI_tag {};
 struct RAI_tag : BI_tag {};
Index: test/SemaCXX/static-assert-cxx17.cpp
===
--- test/SemaCXX/static-assert-cxx17.cpp
+++ test/SemaCXX/static-assert-cxx17.cpp
@@ -54,3 +54,44 @@
 }
 template void foo5();
 // expected-note@-1{{in instantiation of function template specialization 'foo5' requested here}}
+
+struct ExampleTypes {
+  explicit ExampleTypes(int);
+  using T = int;
+  using U = float;
+};
+
+template 
+struct X {
+  int i = 0;
+  int j = 0;
+  constexpr operator bool() const { return false; }
+};
+
+template 
+void foo6() {
+  static_assert(X());
+  // expected-error@-1{{static_assert failed due to requirement 'X()'}}
+  static_assert(X{});
+  // expected-error@-1{{static_assert failed due to requirement 'X{}'}}
+  static_assert(X{1, 2});
+  // expected-error@-1{{static_assert failed due to requirement 'X{1, 2}'}}
+  static_assert(X({1, 2}));
+  // expected-error@-1{{static_assert failed due to requirement 'X({1, 2})'}}
+  static_assert(typename T::T{0});
+  // expected-error@-1{{static_assert failed due to requirement 'int{0}'}}
+  static_assert(typename T::T(0));
+  // expected-error@-1{{static_assert failed due to requirement 'int(0)'}}
+  static_assert(sizeof(X) == 0);
+  // expected-error@-1{{static_assert failed due to requirement 'sizeof(X) == 0'}}
+  static_assert((const X *)nullptr);
+  // expected-error@-1{{static_assert failed due to requirement '(const X *)nullptr'}}
+  static_assert(static_cast *>(nullptr));
+  // expected-error@-1{{static_assert failed due to requirement 'static_cast *>(nullptr)'}}
+  static_assert((const X[]){} == nullptr);
+  // expected-error@-1{{static_assert failed due to requirement '(X const[0]){} == nullptr'}}
+  static_assert(sizeof(X().X::~X())>) == 0);
+  // expected-error@-1{{static_assert failed due to requirement 'sizeof(X) == 0'}}
+}
+template void foo6();
+// expected-note@-1{{in instantiation of function template specialization 'foo6' requested here}}
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -3122,8 +3122,10 @@
   std::string Description;
   {
 llvm::raw_string_ostream Out(Description);
-FailedBooleanConditionPrinterHelper Helper(getPrintingPolicy());
-FailedCond->printPretty(Out, &Helper, getPrintingPolicy());
+PrintingPolicy Policy = getPrintingPolicy();
+Policy.PrintCanonicalTypes = true;
+FailedBooleanConditionPrinterHelper Helper(Policy);
+FailedCond->printPretty(Out, &Helper, Policy, 0, "\n", nullptr);
   }
   return { FailedCond, Description };
 }
Index: lib/AST/TypePrinter.cpp
==

[PATCH] D55869: Convert some ObjC retain/release msgSends to runtime calls

2018-12-19 Thread Pete Cooper via Phabricator via cfe-commits
pete updated this revision to Diff 179017.

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

https://reviews.llvm.org/D55869

Files:
  include/clang/Basic/ObjCRuntime.h
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  test/CodeGenObjC/convert-messages-to-runtime-calls.m

Index: test/CodeGenObjC/convert-messages-to-runtime-calls.m
===
--- test/CodeGenObjC/convert-messages-to-runtime-calls.m
+++ test/CodeGenObjC/convert-messages-to-runtime-calls.m
@@ -14,16 +14,28 @@
 + (id)alloc;
 + (id)allocWithZone:(void*)zone;
 + (id)alloc2;
+- (id)retain;
+- (void)release;
+- (id)autorelease;
 @end
 
 // CHECK-LABEL: define {{.*}}void @test1
 void test1(id x) {
+  // MSGS: {{call.*@objc_msgSend}}
+  // MSGS: {{call.*@objc_msgSend}}
+  // MSGS: {{call.*@objc_msgSend}}
   // MSGS: {{call.*@objc_msgSend}}
   // MSGS: {{call.*@objc_msgSend}}
   // CALLS: {{call.*@objc_alloc}}
   // CALLS: {{call.*@objc_allocWithZone}}
+  // CALLS: {{call.*@objc_retain}}
+  // CALLS: {{call.*@objc_release}}
+  // CALLS: {{call.*@objc_autorelease}}
   [NSObject alloc];
   [NSObject allocWithZone:nil];
+  [x retain];
+  [x release];
+  [x autorelease];
 }
 
 // CHECK-LABEL: define {{.*}}void @test2
@@ -43,6 +55,8 @@
 @interface B
 + (A*) alloc;
 + (A*)allocWithZone:(void*)zone;
+- (A*) retain;
+- (A*) autorelease;
 @end
 
 // Make sure we get a bitcast on the return type as the
@@ -65,9 +79,30 @@
   return [B allocWithZone:nil];
 }
 
+// Make sure we get a bitcast on the return type as the
+// call will return i8* which we have to cast to A*
+// CHECK-LABEL: define {{.*}}void @test_retain_class_ptr
+A* test_retain_class_ptr(B *b) {
+  // CALLS: {{call.*@objc_retain}}
+  // CALLS-NEXT: bitcast i8*
+  // CALLS-NEXT: ret
+  return [b retain];
+}
+
+// Make sure we get a bitcast on the return type as the
+// call will return i8* which we have to cast to A*
+// CHECK-LABEL: define {{.*}}void @test_autorelease_class_ptr
+A* test_autorelease_class_ptr(B *b) {
+  // CALLS: {{call.*@objc_autorelease}}
+  // CALLS-NEXT: bitcast i8*
+  // CALLS-NEXT: ret
+  return [b autorelease];
+}
+
 
 @interface C
 + (id)allocWithZone:(int)intArg;
+- (float) retain;
 @end
 
 // Make sure we only accept pointer types
@@ -78,3 +113,37 @@
   return [C allocWithZone:3];
 }
 
+// Make sure we use a message and not a call as the return type is
+// not a pointer type.
+// CHECK-LABEL: define {{.*}}void @test_cannot_message_return_float
+float test_cannot_message_return_float(C *c) {
+  // MSGS: {{call.*@objc_msgSend}}
+  // CALLS: {{call.*@objc_msgSend}}
+  return [c retain];
+}
+
+@interface NSString : NSObject
++ (void)retain_self;
+- (void)retain_super;
+@end
+
+@implementation NSString
+
+// Make sure we can convert a message to a dynamic receiver to a call
+// CHECK-LABEL: define {{.*}}void @retain_self
++ (void)retain_self {
+  // MSGS: {{call.*@objc_msgSend}}
+  // CALLS: {{call.*@objc_retain}}
+  [self retain];
+}
+
+// Make sure we never convert a message to super to a call
+// CHECK-LABEL: define {{.*}}void @retain_super
+- (void)retain_super {
+  // MSGS: {{call.*@objc_msgSend}}
+  // CALLS: {{call.*@objc_msgSend}}
+  [super retain];
+}
+
+@end
+
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -138,6 +138,10 @@
   /// id objc_autorelease(id);
   llvm::Constant *objc_autorelease;
 
+  /// id objc_autorelease(id);
+  /// Note this is the runtime method not the intrinsic.
+  llvm::Constant *objc_autoreleaseRuntimeFunction;
+
   /// id objc_autoreleaseReturnValue(id);
   llvm::Constant *objc_autoreleaseReturnValue;
 
@@ -162,6 +166,10 @@
   /// id objc_retain(id);
   llvm::Constant *objc_retain;
 
+  /// id objc_retain(id);
+  /// Note this is the runtime method not the intrinsic.
+  llvm::Constant *objc_retainRuntimeFunction;
+
   /// id objc_retainAutorelease(id);
   llvm::Constant *objc_retainAutorelease;
 
@@ -177,6 +185,10 @@
   /// void objc_release(id);
   llvm::Constant *objc_release;
 
+  /// void objc_release(id);
+  /// Note this is the runtime method not the intrinsic.
+  llvm::Constant *objc_releaseRuntimeFunction;
+
   /// void objc_storeStrong(id*, id);
   llvm::Constant *objc_storeStrong;
 
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -3798,6 +3798,11 @@
   llvm::Value *EmitARCRetainAutoreleasedReturnValue(llvm::Value *value);
   llvm::Value *EmitARCUnsafeClaimAutoreleasedReturnValue(llvm::Value *value);
 
+  llvm::Value *EmitObjCAutorelease(llvm::Value *value, llvm::Type *returnType);
+  llvm::Value *EmitObjCRetainNonBlock(llvm::Value *value,
+  llvm::Type *returnType);
+  void EmitObjCRelease(llvm::Value *value, ARCPreciseLifetime_t precise);
+
  

[PATCH] D55869: Convert some ObjC retain/release msgSends to runtime calls

2018-12-19 Thread Pete Cooper via Phabricator via cfe-commits
pete marked 3 inline comments as done.
pete added a comment.

In D55869#1335783 , @rjmccall wrote:

> So, once upon a time this was a problem because we were rewriting the method 
> calls in the runtime itself.  Can you explain how that's not a problem now?  
> Do we just expect the runtime to be compiled with the right switch?


Ah yeah, good point.

In the patch for rewriting objc_alloc messages (r348687) I added a new option 
(-fno-objc-convert-messages-to-runtime-calls) which the objc runtime will need 
to adopt.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55869



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


Re: [PATCH] D55828: [clang] [Driver] Disable -faddrsig by default on NetBSD

2018-12-19 Thread Kamil Rytarowski via cfe-commits
On 19.12.2018 22:03, Michał Górny wrote:
> On Wed, 2018-12-19 at 21:51 +0100, Joerg Sonnenberger wrote:
>> On Tue, Dec 18, 2018 at 04:35:54PM +, Michał Górny via Phabricator via 
>> cfe-commits wrote:
>>> mgorny created this revision.
>>> mgorny added reviewers: krytarowski, pcc.
>>>
>>> Avoid passing -faddrsig by default on NetBSD.  This platform is still
>>> using old GNU binutils that crashes on executables containing those
>>> sections.
>>
>> I find that a strange claim, given that many Linux distributions in the
>> wild have much older GNU binutils.
>>
> 
> It only meant that newer versions don't crash, or so I have been told. 
> Nothing more.
> 

GNU strip(1) from NetBSD HEAD (2.27) is randomly affected by this:

http://netbsd.org/~kamil/llvm/strip.txt

GNU strip(1) 2.30 is reported to only output warnings.

This patch should be pulled to older versions.



signature.asc
Description: OpenPGP digital signature
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55915: [Driver] Make -fno-omit-frame-pointer imply -mno-omit-leaf-frame-pointerand make -fomit-frame-pointer imply -momit-leaf-frame-pointer.This matches GCC's behavior.

2018-12-19 Thread Yuanfang Chen via Phabricator via cfe-commits
tabloid.adroit created this revision.
Herald added a subscriber: cfe-commits.

llvm.org/PR9825


Repository:
  rC Clang

https://reviews.llvm.org/D55915

Files:
  lib/CodeGen/CGCall.cpp
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/cl-options.c
  test/Driver/frame-pointer-elim.c


Index: test/Driver/frame-pointer-elim.c
===
--- test/Driver/frame-pointer-elim.c
+++ test/Driver/frame-pointer-elim.c
@@ -69,5 +69,20 @@
 // RUN: %clang -### -target x86_64-scei-ps4 -S -O2 %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=OMIT_LEAF %s
 
+// RUN: %clang -### -S -Os -fno-omit-frame-pointer %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=NO-OMIT-ALL %s
+// NO-OMIT-ALL: "-mdisable-fp-elim"
+// NO-OMIT-ALL-NOT: "-momit-leaf-frame-pointer"
+
+// RUN: %clang -### -S -Os -fno-omit-frame-pointer -momit-leaf-frame-pointer 
%s 2>&1 | \
+// RUN:   FileCheck --check-prefix=NO-OMIT-NONLEAF %s
+// NO-OMIT-NONLEAF: "-mdisable-fp-elim"
+// NO-OMIT-NONLEAF: "-momit-leaf-frame-pointer"
+
+// RUN: %clang -### -S -Os -fomit-frame-pointer %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=OMIT-ALL %s
+// OMIT-ALL-NOT: "-mdisable-fp-elim"
+// OMIT-ALL: "-momit-leaf-frame-pointer"
+
 void f0() {}
 void f1() { f0(); }
Index: test/Driver/cl-options.c
===
--- test/Driver/cl-options.c
+++ test/Driver/cl-options.c
@@ -171,11 +171,10 @@
 
 // RUN: %clang_cl --target=i686-pc-win32 /O2sy- -### -- %s 2>&1 | FileCheck 
-check-prefix=PR24003 %s
 // PR24003: -mdisable-fp-elim
-// PR24003: -momit-leaf-frame-pointer
 // PR24003: -Os
 
 // RUN: %clang_cl --target=i686-pc-win32 -Werror /Oy- /O2 -### -- %s 2>&1 | 
FileCheck -check-prefix=Oy_2 %s
-// Oy_2: -momit-leaf-frame-pointer
+// Oy_2: -mdisable-fp-elim
 // Oy_2: -O2
 
 // RUN: %clang_cl --target=i686-pc-win32 -Werror /O2 /O2 -### -- %s 2>&1 | 
FileCheck -check-prefix=O2O2 %s
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -498,7 +498,7 @@
   return codegenoptions::LimitedDebugInfo;
 }
 
-static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
+static bool mustUseFramePointerForTarget(const llvm::Triple &Triple) {
   switch (Triple.getArch()){
   default:
 return false;
@@ -575,7 +575,7 @@
   if (Arg *A = Args.getLastArg(options::OPT_fno_omit_frame_pointer,
options::OPT_fomit_frame_pointer))
 return A->getOption().matches(options::OPT_fno_omit_frame_pointer) ||
-   mustUseNonLeafFramePointerForTarget(Triple);
+   mustUseFramePointerForTarget(Triple);
 
   if (Args.hasArg(options::OPT_pg))
 return true;
@@ -589,6 +589,11 @@
options::OPT_momit_leaf_frame_pointer))
 return A->getOption().matches(options::OPT_mno_omit_leaf_frame_pointer);
 
+  if (Arg *A = Args.getLastArg(options::OPT_fno_omit_frame_pointer,
+   options::OPT_fomit_frame_pointer))
+return A->getOption().matches(options::OPT_fno_omit_frame_pointer) ||
+   mustUseFramePointerForTarget(Triple);
+
   if (Args.hasArg(options::OPT_pg))
 return true;
 
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1736,7 +1736,6 @@
   FuncAttrs.addAttribute("no-frame-pointer-elim-non-leaf");
 } else {
   FuncAttrs.addAttribute("no-frame-pointer-elim", "true");
-  FuncAttrs.addAttribute("no-frame-pointer-elim-non-leaf");
 }
 
 FuncAttrs.addAttribute("less-precise-fpmad",


Index: test/Driver/frame-pointer-elim.c
===
--- test/Driver/frame-pointer-elim.c
+++ test/Driver/frame-pointer-elim.c
@@ -69,5 +69,20 @@
 // RUN: %clang -### -target x86_64-scei-ps4 -S -O2 %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=OMIT_LEAF %s
 
+// RUN: %clang -### -S -Os -fno-omit-frame-pointer %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=NO-OMIT-ALL %s
+// NO-OMIT-ALL: "-mdisable-fp-elim"
+// NO-OMIT-ALL-NOT: "-momit-leaf-frame-pointer"
+
+// RUN: %clang -### -S -Os -fno-omit-frame-pointer -momit-leaf-frame-pointer %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=NO-OMIT-NONLEAF %s
+// NO-OMIT-NONLEAF: "-mdisable-fp-elim"
+// NO-OMIT-NONLEAF: "-momit-leaf-frame-pointer"
+
+// RUN: %clang -### -S -Os -fomit-frame-pointer %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=OMIT-ALL %s
+// OMIT-ALL-NOT: "-mdisable-fp-elim"
+// OMIT-ALL: "-momit-leaf-frame-pointer"
+
 void f0() {}
 void f1() { f0(); }
Index: test/Driver/cl-options.c
===
--- test/Driver/cl-options.c
+++ test/Driver/cl-options.c
@@ -171,11 +171,10 @@
 
 // RUN: %clang_cl --target=i686-pc-win32 /O2sy- -### -- %s 2>&1 | FileCheck -check-prefix=PR24003 %s
 /

[PATCH] D55844: [Fixed Point Arithmetic] Fixed Point Subtraction

2018-12-19 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:3397
   Value *Result;
-  if (ResultFixedSema.isSaturated()) {
-llvm::Intrinsic::ID IID = ResultFixedSema.isSigned()
-  ? llvm::Intrinsic::sadd_sat
-  : llvm::Intrinsic::uadd_sat;
-Result = Builder.CreateBinaryIntrinsic(IID, FullLHS, FullRHS);
+  if (BinOp->getOpcode() == BO_Add) {
+if (ResultFixedSema.isSaturated()) {

Please go ahead and make this a covered `switch` with a bunch of unimplemented 
cases.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55844



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


[PATCH] D55662: [Sema][ObjC] Do not warn about repeated uses of weak variables when the variables are accessed in an unevaluated context.

2018-12-19 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D55662#1336835 , @ahatanak wrote:

> In D55662#1335773 , @rjmccall wrote:
>
> > Okay.  You may need to push an unevaluated context when doing that.
>
>
> Since I'm just moving the call to `CheckPlaceholderExpr` to the call site, I 
> don't think I have to push an unevaluated context there?


Hmm.  Right, for the `auto` inference specifically it's fine because the 
expression is in fact evaluated: we're not just eliminating placeholders in 
order to resolve `decltype`, we're eliminating placeholders to actually figure 
out what's going on with the initialization.

> Also, it looks like I can just change the check 
> `Init->getType()->isNonOverloadPlaceholderType()`  at the beginning of 
> `Sema::DeduceAutoType` to `Init->getType()->getAsPlaceholderType()` instead 
> of inserting the call to `CheckPlaceholderExpr` right before the call to 
> `BuildDecltypeType`.

The reason it's specifically checking for a non-overload placeholder is that 
normal `auto` can have additional structure in the declarator that could 
potentially resolve an overload set without picking a single template 
specialization.  So you can only check for an arbitrary placeholder if this is 
the `decltype(auto)` case.  But I agree that it still makes sense to only do 
this once up front, yeah.




Comment at: lib/Sema/SemaType.cpp:8043
 QualType Sema::BuildTypeofExprType(Expr *E, SourceLocation Loc) {
-  ExprResult ER = CheckPlaceholderExpr(E);
-  if (ER.isInvalid()) return QualType();
-  E = ER.get();
+  assert(!E->getType()->getAsPlaceholderType() && "unexpected placeholder");
 

There is a `isPlaceholderType()` method that looks a little cleaner than a 
`getAs` call.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55662



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


[PATCH] D55913: [gn build] Add build files for clang/lib/{Analysis, Edit, Sema}

2018-12-19 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D55913



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


[PATCH] D55913: [gn build] Add build files for clang/lib/{Analysis, Edit, Sema}

2018-12-19 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: phosek.

Nothing interesting.


https://reviews.llvm.org/D55913

Files:
  llvm/utils/gn/secondary/BUILD.gn
  llvm/utils/gn/secondary/clang/include/clang/Sema/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/Analysis/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/Edit/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
@@ -0,0 +1,66 @@
+static_library("Sema") {
+  output_name = "clangSema"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/include/clang/Sema:AttrParsedAttrImpl",
+"//clang/include/clang/Sema:AttrParsedAttrKinds",
+"//clang/include/clang/Sema:AttrParsedAttrList",
+"//clang/include/clang/Sema:AttrSpellingListIndex",
+"//clang/include/clang/Sema:AttrTemplateInstantiate",
+"//clang/lib/AST",
+"//clang/lib/Analysis",
+"//clang/lib/Basic",
+"//clang/lib/Edit",
+"//clang/lib/Lex",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"AnalysisBasedWarnings.cpp",
+"CodeCompleteConsumer.cpp",
+"DeclSpec.cpp",
+"DelayedDiagnostic.cpp",
+"IdentifierResolver.cpp",
+"JumpDiagnostics.cpp",
+"MultiplexExternalSemaSource.cpp",
+"ParsedAttr.cpp",
+"Scope.cpp",
+"ScopeInfo.cpp",
+"Sema.cpp",
+"SemaAccess.cpp",
+"SemaAttr.cpp",
+"SemaCUDA.cpp",
+"SemaCXXScopeSpec.cpp",
+"SemaCast.cpp",
+"SemaChecking.cpp",
+"SemaCodeComplete.cpp",
+"SemaConsumer.cpp",
+"SemaCoroutine.cpp",
+"SemaDecl.cpp",
+"SemaDeclAttr.cpp",
+"SemaDeclCXX.cpp",
+"SemaDeclObjC.cpp",
+"SemaExceptionSpec.cpp",
+"SemaExpr.cpp",
+"SemaExprCXX.cpp",
+"SemaExprMember.cpp",
+"SemaExprObjC.cpp",
+"SemaFixItUtils.cpp",
+"SemaInit.cpp",
+"SemaLambda.cpp",
+"SemaLookup.cpp",
+"SemaObjCProperty.cpp",
+"SemaOpenMP.cpp",
+"SemaOverload.cpp",
+"SemaPseudoObject.cpp",
+"SemaStmt.cpp",
+"SemaStmtAsm.cpp",
+"SemaStmtAttr.cpp",
+"SemaTemplate.cpp",
+"SemaTemplateDeduction.cpp",
+"SemaTemplateInstantiate.cpp",
+"SemaTemplateInstantiateDecl.cpp",
+"SemaTemplateVariadic.cpp",
+"SemaType.cpp",
+"TypeLocBuilder.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/clang/lib/Edit/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/lib/Edit/BUILD.gn
@@ -0,0 +1,15 @@
+static_library("Edit") {
+  output_name = "clangEdit"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/lib/AST",
+"//clang/lib/Basic",
+"//clang/lib/Lex",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"Commit.cpp",
+"EditedSource.cpp",
+"RewriteObjCFoundationAPI.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/clang/lib/Analysis/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/lib/Analysis/BUILD.gn
@@ -0,0 +1,36 @@
+static_library("Analysis") {
+  output_name = "clangAnalysis"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/include/clang/AST:StmtDataCollectors",
+"//clang/lib/AST",
+"//clang/lib/Basic",
+"//clang/lib/Lex",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"AnalysisDeclContext.cpp",
+"BodyFarm.cpp",
+"CFG.cpp",
+"CFGReachabilityAnalysis.cpp",
+"CFGStmtMap.cpp",
+"CallGraph.cpp",
+"CloneDetection.cpp",
+"CocoaConventions.cpp",
+"CodeInjector.cpp",
+"ConstructionContext.cpp",
+"Consumed.cpp",
+"Dominators.cpp",
+"ExprMutationAnalyzer.cpp",
+"LiveVariables.cpp",
+"ObjCNoReturn.cpp",
+"PostOrderCFGView.cpp",
+"ProgramPoint.cpp",
+"ReachableCode.cpp",
+"ThreadSafety.cpp",
+"ThreadSafetyCommon.cpp",
+"ThreadSafetyLogical.cpp",
+"ThreadSafetyTIL.cpp",
+"UninitializedValues.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/clang/include/clang/Sema/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/include/clang/Sema/BUILD.gn
@@ -0,0 +1,46 @@
+import("//clang/utils/TableGen/clang_tablegen.gni")
+
+clang_tablegen("AttrTemplateInstantiate") {
+  args = [
+"-gen-clang-attr-template-instantiate",
+"-I",
+rebase_path("../..", root_out_dir),
+  ]
+  td_file = "../Basic/Attr.td"
+}
+
+clang_tablegen("AttrParsedAttrList") {
+  args = [
+"-gen-clang-attr-parsed-attr-list",
+"-I",
+rebase_path("../..", root_out_dir),
+  ]
+  td_file = "../Basic/Attr.td"
+}
+
+clang_tablegen("AttrParsedAttrKinds") {
+  args = [
+"-gen-clang-attr-parsed-attr-kinds",
+"-I",
+rebase_path("../..", root_out_dir),
+  ]
+  td_file = "../Basic/Attr.td"
+}
+
+clang_tablegen("AttrSpellingListIndex") {
+  args = [
+"-gen-clang-attr-

[PATCH] D55912: [gn build] Add build files for clang/lib/Lex and clang/lib/AST

2018-12-19 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D55912



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


[PATCH] D55912: [gn build] Add build files for clang/lib/Lex and clang/lib/AST

2018-12-19 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: phosek.

Nothing interesting.


https://reviews.llvm.org/D55912

Files:
  llvm/utils/gn/secondary/BUILD.gn
  llvm/utils/gn/secondary/clang/include/clang/AST/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/AST/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/Lex/BUILD.gn
  llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn
@@ -39,9 +39,13 @@
 l = "-l"
 lib = ""
   }
+
   # Windows doesn't use any of libxml2,terminfo, zlib by default.
   # Make GN not warn about these variables being unused.
-  not_needed(["l", "lib"])
+  not_needed([
+   "l",
+   "lib",
+ ])
 
   system_libs = ""
   if (host_os == "win") {
Index: llvm/utils/gn/secondary/clang/lib/Lex/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/lib/Lex/BUILD.gn
@@ -0,0 +1,31 @@
+static_library("Lex") {
+  output_name = "clangLex"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/lib/Basic",
+"//llvm/lib/Support",
+  ]
+  sources = [
+"HeaderMap.cpp",
+"HeaderSearch.cpp",
+"Lexer.cpp",
+"LiteralSupport.cpp",
+"MacroArgs.cpp",
+"MacroInfo.cpp",
+"ModuleMap.cpp",
+"PPCaching.cpp",
+"PPCallbacks.cpp",
+"PPConditionalDirectiveRecord.cpp",
+"PPDirectives.cpp",
+"PPExpressions.cpp",
+"PPLexerChange.cpp",
+"PPMacroExpansion.cpp",
+"Pragma.cpp",
+"PreprocessingRecord.cpp",
+"Preprocessor.cpp",
+"PreprocessorLexer.cpp",
+"ScratchBuffer.cpp",
+"TokenConcatenation.cpp",
+"TokenLexer.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/clang/lib/AST/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang/lib/AST/BUILD.gn
@@ -0,0 +1,101 @@
+static_library("AST") {
+  output_name = "clangAST"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang/include/clang/AST:AttrDump",
+"//clang/include/clang/AST:AttrImpl",
+"//clang/include/clang/AST:CommentCommandInfo",
+"//clang/include/clang/AST:CommentHTMLNamedCharacterReferences",
+"//clang/include/clang/AST:CommentHTMLTags",
+"//clang/include/clang/AST:CommentHTMLTagsProperties",
+"//clang/include/clang/AST:DeclNodes",
+"//clang/lib/Basic",
+"//clang/lib/Lex",
+"//llvm/lib/BinaryFormat",
+"//llvm/lib/Support",
+  ]
+
+  # Generated files used in public headers should be in public_deps, the rest
+  # in regular deps.
+  public_deps = [
+"//clang/include/clang/AST:AttrVisitor",
+"//clang/include/clang/AST:Attrs",
+"//clang/include/clang/AST:CommentCommandList",
+"//clang/include/clang/AST:CommentNodes",
+"//clang/include/clang/AST:StmtNodes",
+  ]
+  sources = [
+"APValue.cpp",
+"ASTConsumer.cpp",
+"ASTContext.cpp",
+"ASTDiagnostic.cpp",
+"ASTDumper.cpp",
+"ASTImporter.cpp",
+"ASTImporterLookupTable.cpp",
+"ASTStructuralEquivalence.cpp",
+"ASTTypeTraits.cpp",
+"AttrImpl.cpp",
+"CXXInheritance.cpp",
+"Comment.cpp",
+"CommentBriefParser.cpp",
+"CommentCommandTraits.cpp",
+"CommentLexer.cpp",
+"CommentParser.cpp",
+"CommentSema.cpp",
+"ComparisonCategories.cpp",
+"DataCollection.cpp",
+"Decl.cpp",
+"DeclBase.cpp",
+"DeclCXX.cpp",
+"DeclFriend.cpp",
+"DeclGroup.cpp",
+"DeclObjC.cpp",
+"DeclOpenMP.cpp",
+"DeclPrinter.cpp",
+"DeclTemplate.cpp",
+"DeclarationName.cpp",
+"Expr.cpp",
+"ExprCXX.cpp",
+"ExprClassification.cpp",
+"ExprConstant.cpp",
+"ExprObjC.cpp",
+"ExternalASTMerger.cpp",
+"ExternalASTSource.cpp",
+"FormatString.cpp",
+"InheritViz.cpp",
+"ItaniumCXXABI.cpp",
+"ItaniumMangle.cpp",
+"Mangle.cpp",
+"MicrosoftCXXABI.cpp",
+"MicrosoftMangle.cpp",
+"NSAPI.cpp",
+"NestedNameSpecifier.cpp",
+"ODRHash.cpp",
+"OSLog.cpp",
+"OpenMPClause.cpp",
+"ParentMap.cpp",
+"PrintfFormatString.cpp",
+"QualTypeNames.cpp",
+"RawCommentList.cpp",
+"RecordLayout.cpp",
+"RecordLayoutBuilder.cpp",
+"ScanfFormatString.cpp",
+"SelectorLocationsKind.cpp",
+"Stmt.cpp",
+"StmtCXX.cpp",
+"StmtIterator.cpp",
+"StmtObjC.cpp",
+"StmtOpenMP.cpp",
+"StmtPrinter.cpp",
+"StmtProfile.cpp",
+"StmtViz.cpp",
+"TemplateBase.cpp",
+"TemplateName.cpp",
+"TextNodeDumper.cpp",
+"Type.cpp",
+"TypeLoc.cpp",
+"TypePrinter.cpp",
+"VTTBuilder.cpp",
+"VTableBuilder.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/clang/include/clang/AST/BUILD.gn
===
--- /de

[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

2018-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:3700
+  // through them.
+  for (size_t Index = 0; Index < Args.size(); ++Index) {
+if (StringRef(Args.getArgString(Index)).contains("-analyzer-config")) {

Needs an LLVM-style loop!~ :)


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

https://reviews.llvm.org/D55823



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


[PATCH] D55907: [analyzer] RetainCount: Bluntly suppress the CFRetain detection heuristic on a couple of CM functions.

2018-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 178995.
NoQ added a comment.

Improve comments.


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

https://reviews.llvm.org/D55907

Files:
  lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
  test/Analysis/retain-release.m


Index: test/Analysis/retain-release.m
===
--- test/Analysis/retain-release.m
+++ test/Analysis/retain-release.m
@@ -1,9 +1,20 @@
 // RUN: rm -f %t.objc.plist %t.objcpp.plist
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount
 -analyzer-store=region -fblocks -verify -Wno-objc-root-class %s 
-analyzer-output=plist -o %t.objc.plist
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount
 -analyzer-store=region -fblocks -verify -x objective-c++ -std=gnu++98 
-Wno-objc-root-class %s -analyzer-output=plist -o %t.objcpp.plist
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10\
+// RUN: -analyzer-checker=core,osx.coreFoundation.CFRetainRelease\
+// RUN: -analyzer-checker=osx.cocoa.ClassRelease,osx.cocoa.RetainCount\
+// RUN: -analyzer-checker=debug.ExprInspection -fblocks -verify %s\
+// RUN: -Wno-objc-root-class -analyzer-output=plist -o %t.objcpp.plist
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10\
+// RUN: -analyzer-checker=core,osx.coreFoundation.CFRetainRelease\
+// RUN: -analyzer-checker=osx.cocoa.ClassRelease,osx.cocoa.RetainCount\
+// RUN: -analyzer-checker=debug.ExprInspection -fblocks -verify %s\
+// RUN: -Wno-objc-root-class -analyzer-output=plist -o %t.objcpp.plist\
+// RUN: -x objective-c++ -std=gnu++98
 // FIXLATER: cat %t.objc.plist ; FileCheck --input-file=%t.objc.plist %s
 // FIXLATER: cat %t.objcpp.plist ; FileCheck --input-file=%t.objcpp.plist %s
 
+void clang_analyzer_eval(int);
+
 #if __has_feature(attribute_ns_returns_retained)
 #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
 #endif
@@ -495,6 +506,21 @@
   // status is returned.
 }
 
+typedef CFTypeRef CMBufferRef;
+
+typedef CFTypeRef *CMBufferQueueRef;
+
+CMBufferRef CMBufferQueueDequeueAndRetain(CMBufferQueueRef);
+
+void testCMBufferQueueDequeueAndRetain(CMBufferQueueRef queue) {
+  CMBufferRef buffer = CMBufferQueueDequeueAndRetain(queue); // 
expected-warning{{Potential leak of an object stored into 'buffer'}}
+  // There's a state split due to the eagerly-assume behavior.
+  // The point here is that we don't treat CMBufferQueueDequeueAndRetain
+  // as some sort of CFRetain() that returns its argument.
+  clang_analyzer_eval((CMFooRef)buffer == (CMFooRef)queue); // 
expected-warning{{TRUE}}
+// 
expected-warning@-1{{FALSE}}
+}
+
 // Test retain/release checker with CFString and CFMutableArray.
 void f11() {
   // Create the array.
Index: lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
===
--- lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
+++ lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
@@ -204,6 +204,11 @@
 AllowAnnotations = false;
 return RetTy->isObjCIdType() ? getUnarySummary(FT, cfmakecollectable)
  : getPersistentStopSummary();
+  } else if (FName == "CMBufferQueueDequeueAndRetain" ||
+ FName == "CMBufferQueueDequeueIfDataReadyAndRetain") {
+// Part of: .
+return getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF), DoNothing,
+DoNothing);
   } else if (FName == "CFPlugInInstanceCreate") {
 return getPersistentSummary(RetEffect::MakeNoRet());
   } else if (FName == "IORegistryEntrySearchCFProperty" ||
@@ -591,6 +596,12 @@
 // Handle: (CF|CG|CV)Retain
 // CFAutorelease
 // It's okay to be a little sloppy here.
+if (FName == "CMBufferQueueDequeueAndRetain" ||
+FName == "CMBufferQueueDequeueIfDataReadyAndRetain") {
+  // Part of: .
+  // These are not retain. They just return something and retain it.
+  return None;
+}
 if (cocoa::isRefType(ResultTy, "CF", FName) ||
 cocoa::isRefType(ResultTy, "CG", FName) ||
 cocoa::isRefType(ResultTy, "CV", FName))


Index: test/Analysis/retain-release.m
===
--- test/Analysis/retain-release.m
+++ test/Analysis/retain-release.m
@@ -1,9 +1,20 @@
 // RUN: rm -f %t.objc.plist %t.objcpp.plist
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount -analyzer-store=region -fblocks -verify -Wno-objc-root-class %s -analyzer-output=plist -o %t.objc.plist
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker

[PATCH] D55907: [analyzer] RetainCount: Bluntly suppress the CFRetain detection heuristic on a couple of CM functions.

2018-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, george.karpenkov.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.

If it ends with "Retain" like `CFRetain` and returns a `CFTypeRef` like 
`CFRetain`, then it is not necessarily a `CFRetain`.


Repository:
  rC Clang

https://reviews.llvm.org/D55907

Files:
  lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
  test/Analysis/retain-release.m


Index: test/Analysis/retain-release.m
===
--- test/Analysis/retain-release.m
+++ test/Analysis/retain-release.m
@@ -1,9 +1,20 @@
 // RUN: rm -f %t.objc.plist %t.objcpp.plist
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount
 -analyzer-store=region -fblocks -verify -Wno-objc-root-class %s 
-analyzer-output=plist -o %t.objc.plist
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 
-analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount
 -analyzer-store=region -fblocks -verify -x objective-c++ -std=gnu++98 
-Wno-objc-root-class %s -analyzer-output=plist -o %t.objcpp.plist
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10\
+// RUN: -analyzer-checker=core,osx.coreFoundation.CFRetainRelease\
+// RUN: -analyzer-checker=osx.cocoa.ClassRelease,osx.cocoa.RetainCount\
+// RUN: -analyzer-checker=debug.ExprInspection -fblocks -verify %s\
+// RUN: -Wno-objc-root-class -analyzer-output=plist -o %t.objcpp.plist
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10\
+// RUN: -analyzer-checker=core,osx.coreFoundation.CFRetainRelease\
+// RUN: -analyzer-checker=osx.cocoa.ClassRelease,osx.cocoa.RetainCount\
+// RUN: -analyzer-checker=debug.ExprInspection -fblocks -verify %s\
+// RUN: -Wno-objc-root-class -analyzer-output=plist -o %t.objcpp.plist\
+// RUN: -x objective-c++ -std=gnu++98
 // FIXLATER: cat %t.objc.plist ; FileCheck --input-file=%t.objc.plist %s
 // FIXLATER: cat %t.objcpp.plist ; FileCheck --input-file=%t.objcpp.plist %s
 
+void clang_analyzer_eval(int);
+
 #if __has_feature(attribute_ns_returns_retained)
 #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
 #endif
@@ -495,6 +506,21 @@
   // status is returned.
 }
 
+typedef CFTypeRef CMBufferRef;
+
+typedef CFTypeRef *CMBufferQueueRef;
+
+CMBufferRef CMBufferQueueDequeueAndRetain(CMBufferQueueRef);
+
+void testCMBufferQueueDequeueAndRetain(CMBufferQueueRef queue) {
+  CMBufferRef buffer = CMBufferQueueDequeueAndRetain(queue); // 
expected-warning{{Potential leak of an object stored into 'buffer'}}
+  // There's a state split due to the eagerly-assume behavior.
+  // The point here is that we don't treat CMBufferQueueDequeueAndRetain
+  // as some sort of CFRetain() that returns its argument.
+  clang_analyzer_eval((CMFooRef)buffer == (CMFooRef)queue); // 
expected-warning{{TRUE}}
+// 
expected-warning@-1{{FALSE}}
+}
+
 // Test retain/release checker with CFString and CFMutableArray.
 void f11() {
   // Create the array.
Index: lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
===
--- lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
+++ lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
@@ -204,6 +204,11 @@
 AllowAnnotations = false;
 return RetTy->isObjCIdType() ? getUnarySummary(FT, cfmakecollectable)
  : getPersistentStopSummary();
+  } else if (FName == "CMBufferQueueDequeueAndRetain" ||
+ FName == "CMBufferQueueDequeueIfDataReadyAndRetain") {
+// Part of: .
+return getPersistentSummary(RetEffect::MakeOwned(RetEffect::CF), DoNothing,
+DoNothing);
   } else if (FName == "CFPlugInInstanceCreate") {
 return getPersistentSummary(RetEffect::MakeNoRet());
   } else if (FName == "IORegistryEntrySearchCFProperty" ||
@@ -591,6 +596,11 @@
 // Handle: (CF|CG|CV)Retain
 // CFAutorelease
 // It's okay to be a little sloppy here.
+if (FName == "CMBufferQueueDequeueAndRetain" ||
+FName == "CMBufferQueueDequeueIfDataReadyAndRetain") {
+  // These are not retain. They just return something and retain it.
+  return None;
+}
 if (cocoa::isRefType(ResultTy, "CF", FName) ||
 cocoa::isRefType(ResultTy, "CG", FName) ||
 cocoa::isRefType(ResultTy, "CV", FName))


Index: test/Analysis/retain-release.m
===
--- test/Analysis/retain-release.m
+++ test/Analysis/retain-release.m
@@ -1,9 +1,20 @@
 // RUN: rm -f %t.objc.plist %t.objcpp.plist
-// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.

[PATCH] D55875: [analyzer] pr38668: RegionStore: Do not attempt to cast loaded values of non-scalar types.

2018-12-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349701: [analyzer] pr38668: Do not attempt to cast loaded 
values of non-scalar types. (authored by dergachev, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D55875

Files:
  lib/StaticAnalyzer/Core/Store.cpp
  test/Analysis/casts.c
  test/Analysis/pointer-to-member.cpp


Index: test/Analysis/pointer-to-member.cpp
===
--- test/Analysis/pointer-to-member.cpp
+++ test/Analysis/pointer-to-member.cpp
@@ -253,11 +253,10 @@
   clang_analyzer_eval(&A::y); // expected-warning{{TRUE}}
   clang_analyzer_eval(&A::z); // expected-warning{{TRUE}}
 
-  // FIXME: These should be true.
   int A::*l = &A::x, A::*m = &A::y, A::*n = &A::z;
-  clang_analyzer_eval(l); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(m); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(n); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l); // expected-warning{{TRUE}}
+  clang_analyzer_eval(m); // expected-warning{{TRUE}}
+  clang_analyzer_eval(n); // expected-warning{{TRUE}}
 
   // FIXME: These should be true as well.
   A a;
Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -213,3 +213,14 @@
 }
 
 #endif
+
+char no_crash_SymbolCast_of_float_type_aux(int *p) {
+  *p += 1;
+  return *p;
+}
+
+void no_crash_SymbolCast_of_float_type() {
+  extern float x;
+  char (*f)() = no_crash_SymbolCast_of_float_type_aux;
+  f(&x);
+}
Index: lib/StaticAnalyzer/Core/Store.cpp
===
--- lib/StaticAnalyzer/Core/Store.cpp
+++ lib/StaticAnalyzer/Core/Store.cpp
@@ -394,14 +394,28 @@
   return UnknownVal();
 }
 
+static bool isScalarEnoughToAttemptACast(QualType T) {
+  return T->isIntegralOrEnumerationType() || T->isAnyPointerType() ||
+ T->isReferenceType();
+}
+
 /// CastRetrievedVal - Used by subclasses of StoreManager to implement
 ///  implicit casts that arise from loads from regions that are reinterpreted
 ///  as another region.
 SVal StoreManager::CastRetrievedVal(SVal V, const TypedValueRegion *R,
-QualType castTy) {
-  if (castTy.isNull() || V.isUnknownOrUndef())
+QualType CastTy) {
+  if (CastTy.isNull() || V.isUnknownOrUndef())
 return V;
 
+  QualType OrigTy = R->getValueType();
+
+  if (!isScalarEnoughToAttemptACast(OrigTy) ||
+  !isScalarEnoughToAttemptACast(CastTy)) {
+if (OrigTy.getUnqualifiedType() == CastTy.getUnqualifiedType())
+  return V;
+return UnknownVal();
+  }
+
   // When retrieving symbolic pointer and expecting a non-void pointer,
   // wrap them into element regions of the expected type if necessary.
   // SValBuilder::dispatchCast() doesn't do that, but it is necessary to
@@ -410,13 +424,13 @@
   // We might need to do that for non-void pointers as well.
   // FIXME: We really need a single good function to perform casts for us
   // correctly every time we need it.
-  if (castTy->isPointerType() && !castTy->isVoidPointerType())
+  if (CastTy->isPointerType() && !CastTy->isVoidPointerType())
 if (const auto *SR = dyn_cast_or_null(V.getAsRegion()))
   if (SR->getSymbol()->getType().getCanonicalType() !=
-  castTy.getCanonicalType())
-return loc::MemRegionVal(castRegion(SR, castTy));
+  CastTy.getCanonicalType())
+return loc::MemRegionVal(castRegion(SR, CastTy));
 
-  return svalBuilder.dispatchCast(V, castTy);
+  return svalBuilder.dispatchCast(V, CastTy);
 }
 
 SVal StoreManager::getLValueFieldOrIvar(const Decl *D, SVal Base) {


Index: test/Analysis/pointer-to-member.cpp
===
--- test/Analysis/pointer-to-member.cpp
+++ test/Analysis/pointer-to-member.cpp
@@ -253,11 +253,10 @@
   clang_analyzer_eval(&A::y); // expected-warning{{TRUE}}
   clang_analyzer_eval(&A::z); // expected-warning{{TRUE}}
 
-  // FIXME: These should be true.
   int A::*l = &A::x, A::*m = &A::y, A::*n = &A::z;
-  clang_analyzer_eval(l); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(m); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(n); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l); // expected-warning{{TRUE}}
+  clang_analyzer_eval(m); // expected-warning{{TRUE}}
+  clang_analyzer_eval(n); // expected-warning{{TRUE}}
 
   // FIXME: These should be true as well.
   A a;
Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -213,3 +213,14 @@
 }
 
 #endif
+
+char no_crash_SymbolCast_of_float_type_aux(int *p) {
+  *p += 1;
+  return *p;
+}
+
+void no_crash_SymbolCast_of_float_type() {
+  extern float x;
+  char (*f)() = no_crash_S

r349701 - [analyzer] pr38668: Do not attempt to cast loaded values of non-scalar types.

2018-12-19 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Dec 19 15:48:44 2018
New Revision: 349701

URL: http://llvm.org/viewvc/llvm-project?rev=349701&view=rev
Log:
[analyzer] pr38668: Do not attempt to cast loaded values of non-scalar types.

It is expected to have the same object (memory region) treated as if it has
different types in different program points. The correct behavior for
RegionStore when an object is stored as an object of type T1 but loaded as
an object of type T2 is to store the object as if it has type T1 but cast it
to T2 during load.

Note that the cast here is some sort of a "reinterpret_cast" (even in C). For
instance, if you store a float and load an integer, you won't have your float
rounded to an integer; instead, you will have garbage.

Admit that we cannot perform the cast as long as types we're dealing with are
non-trivial (neither integers, nor pointers).

Of course, if the cast is not necessary (eg, T1 == T2), we can still load the
value just fine.

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

rdar://problem/45062567

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
cfe/trunk/test/Analysis/casts.c
cfe/trunk/test/Analysis/pointer-to-member.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp?rev=349701&r1=349700&r2=349701&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Store.cpp Wed Dec 19 15:48:44 2018
@@ -394,14 +394,28 @@ SVal StoreManager::attemptDownCast(SVal
   return UnknownVal();
 }
 
+static bool isScalarEnoughToAttemptACast(QualType T) {
+  return T->isIntegralOrEnumerationType() || T->isAnyPointerType() ||
+ T->isReferenceType();
+}
+
 /// CastRetrievedVal - Used by subclasses of StoreManager to implement
 ///  implicit casts that arise from loads from regions that are reinterpreted
 ///  as another region.
 SVal StoreManager::CastRetrievedVal(SVal V, const TypedValueRegion *R,
-QualType castTy) {
-  if (castTy.isNull() || V.isUnknownOrUndef())
+QualType CastTy) {
+  if (CastTy.isNull() || V.isUnknownOrUndef())
 return V;
 
+  QualType OrigTy = R->getValueType();
+
+  if (!isScalarEnoughToAttemptACast(OrigTy) ||
+  !isScalarEnoughToAttemptACast(CastTy)) {
+if (OrigTy.getUnqualifiedType() == CastTy.getUnqualifiedType())
+  return V;
+return UnknownVal();
+  }
+
   // When retrieving symbolic pointer and expecting a non-void pointer,
   // wrap them into element regions of the expected type if necessary.
   // SValBuilder::dispatchCast() doesn't do that, but it is necessary to
@@ -410,13 +424,13 @@ SVal StoreManager::CastRetrievedVal(SVal
   // We might need to do that for non-void pointers as well.
   // FIXME: We really need a single good function to perform casts for us
   // correctly every time we need it.
-  if (castTy->isPointerType() && !castTy->isVoidPointerType())
+  if (CastTy->isPointerType() && !CastTy->isVoidPointerType())
 if (const auto *SR = dyn_cast_or_null(V.getAsRegion()))
   if (SR->getSymbol()->getType().getCanonicalType() !=
-  castTy.getCanonicalType())
-return loc::MemRegionVal(castRegion(SR, castTy));
+  CastTy.getCanonicalType())
+return loc::MemRegionVal(castRegion(SR, CastTy));
 
-  return svalBuilder.dispatchCast(V, castTy);
+  return svalBuilder.dispatchCast(V, CastTy);
 }
 
 SVal StoreManager::getLValueFieldOrIvar(const Decl *D, SVal Base) {

Modified: cfe/trunk/test/Analysis/casts.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/casts.c?rev=349701&r1=349700&r2=349701&view=diff
==
--- cfe/trunk/test/Analysis/casts.c (original)
+++ cfe/trunk/test/Analysis/casts.c Wed Dec 19 15:48:44 2018
@@ -213,3 +213,14 @@ void no_crash_on_symsym_cast_to_long() {
 }
 
 #endif
+
+char no_crash_SymbolCast_of_float_type_aux(int *p) {
+  *p += 1;
+  return *p;
+}
+
+void no_crash_SymbolCast_of_float_type() {
+  extern float x;
+  char (*f)() = no_crash_SymbolCast_of_float_type_aux;
+  f(&x);
+}

Modified: cfe/trunk/test/Analysis/pointer-to-member.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/pointer-to-member.cpp?rev=349701&r1=349700&r2=349701&view=diff
==
--- cfe/trunk/test/Analysis/pointer-to-member.cpp (original)
+++ cfe/trunk/test/Analysis/pointer-to-member.cpp Wed Dec 19 15:48:44 2018
@@ -253,11 +253,10 @@ void test() {
   clang_analyzer_eval(&A::y); // expected-warning{{TRUE}}
   clang_analyzer_eval(&A::z); // expected-warning{{TRUE}}
 
-  // FIXME: These should be true.
   int A::*l = &A::x, A::*m = &A::y, A::*n = &A::z;
-  clang_analyzer_eval(l); // expected-warning{{UNKNOWN}}
-  clang_analyzer

[PATCH] D55875: [analyzer] pr38668: RegionStore: Do not attempt to cast loaded values of non-scalar types.

2018-12-19 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

Looks good to me.


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

https://reviews.llvm.org/D55875



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


[PATCH] D54918: [analyzer] Apply clang-format to GenericTaintChecker.cpp

2018-12-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349698: [analyzer] GenericTaint: Fix formatting to prepare 
for incoming improvements. (authored by dergachev, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D54918

Files:
  lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp

Index: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -28,10 +28,13 @@
 using namespace ento;
 
 namespace {
-class GenericTaintChecker : public Checker< check::PostStmt,
-check::PreStmt > {
+class GenericTaintChecker
+: public Checker, check::PreStmt> {
 public:
-  static void *getTag() { static int Tag; return &Tag; }
+  static void *getTag() {
+static int Tag;
+return &Tag;
+  }
 
   void checkPostStmt(const CallExpr *CE, CheckerContext &C) const;
 
@@ -69,8 +72,8 @@
   static Optional getPointedToSVal(CheckerContext &C, const Expr *Arg);
 
   /// Functions defining the attack surface.
-  typedef ProgramStateRef (GenericTaintChecker::*FnCheck)(const CallExpr *,
-   CheckerContext &C) const;
+  typedef ProgramStateRef (GenericTaintChecker::*FnCheck)(
+  const CallExpr *, CheckerContext &C) const;
   ProgramStateRef postScanf(const CallExpr *CE, CheckerContext &C) const;
   ProgramStateRef postSocket(const CallExpr *CE, CheckerContext &C) const;
   ProgramStateRef postRetTaint(const CallExpr *CE, CheckerContext &C) const;
@@ -120,16 +123,15 @@
 
 TaintPropagationRule() {}
 
-TaintPropagationRule(unsigned SArg,
- unsigned DArg, bool TaintRet = false) {
+TaintPropagationRule(unsigned SArg, unsigned DArg, bool TaintRet = false) {
   SrcArgs.push_back(SArg);
   DstArgs.push_back(DArg);
   if (TaintRet)
 DstArgs.push_back(ReturnValueIndex);
 }
 
-TaintPropagationRule(unsigned SArg1, unsigned SArg2,
- unsigned DArg, bool TaintRet = false) {
+TaintPropagationRule(unsigned SArg1, unsigned SArg2, unsigned DArg,
+ bool TaintRet = false) {
   SrcArgs.push_back(SArg1);
   SrcArgs.push_back(SArg2);
   DstArgs.push_back(DArg);
@@ -139,18 +141,17 @@
 
 /// Get the propagation rule for a given function.
 static TaintPropagationRule
-  getTaintPropagationRule(const FunctionDecl *FDecl,
-  StringRef Name,
-  CheckerContext &C);
+getTaintPropagationRule(const FunctionDecl *FDecl, StringRef Name,
+CheckerContext &C);
 
 inline void addSrcArg(unsigned A) { SrcArgs.push_back(A); }
-inline void addDstArg(unsigned A)  { DstArgs.push_back(A); }
+inline void addDstArg(unsigned A) { DstArgs.push_back(A); }
 
 inline bool isNull() const { return SrcArgs.empty(); }
 
 inline bool isDestinationArgument(unsigned ArgNum) const {
-  return (std::find(DstArgs.begin(),
-DstArgs.end(), ArgNum) != DstArgs.end());
+  return (std::find(DstArgs.begin(), DstArgs.end(), ArgNum) !=
+  DstArgs.end());
 }
 
 static inline bool isTaintedOrPointsToTainted(const Expr *E,
@@ -169,7 +170,6 @@
 /// Pre-process a function which propagates taint according to the
 /// taint rule.
 ProgramStateRef process(const CallExpr *CE, CheckerContext &C) const;
-
   };
 };
 
@@ -177,17 +177,18 @@
 const unsigned GenericTaintChecker::InvalidArgIndex;
 
 const char GenericTaintChecker::MsgUncontrolledFormatString[] =
-  "Untrusted data is used as a format string "
-  "(CWE-134: Uncontrolled Format String)";
+"Untrusted data is used as a format string "
+"(CWE-134: Uncontrolled Format String)";
 
 const char GenericTaintChecker::MsgSanitizeSystemArgs[] =
-  "Untrusted data is passed to a system call "
-  "(CERT/STR02-C. Sanitize data passed to complex subsystems)";
+"Untrusted data is passed to a system call "
+"(CERT/STR02-C. Sanitize data passed to complex subsystems)";
 
 const char GenericTaintChecker::MsgTaintedBufferSize[] =
-  "Untrusted data is used to specify the buffer size "
-  "(CERT/STR31-C. Guarantee that storage for strings has sufficient space for "
-  "character data and the null terminator)";
+"Untrusted data is used to specify the buffer size "
+"(CERT/STR31-C. Guarantee that storage for strings has sufficient space "
+"for "
+"character data and the null terminator)";
 
 } // end of anonymous namespace
 
@@ -199,33 +200,32 @@
 
 GenericTaintChecker::TaintPropagationRule
 GenericTaintChecker::TaintPropagationRule::getTaintPropagationRule(
- const FunctionDecl *FDecl,
- 

r349698 - [analyzer] GenericTaint: Fix formatting to prepare for incoming improvements.

2018-12-19 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Dec 19 15:35:08 2018
New Revision: 349698

URL: http://llvm.org/viewvc/llvm-project?rev=349698&view=rev
Log:
[analyzer] GenericTaint: Fix formatting to prepare for incoming improvements.

Patch by Gábor Borsik!

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp?rev=349698&r1=349697&r2=349698&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp Wed Dec 19 
15:35:08 2018
@@ -28,10 +28,13 @@ using namespace clang;
 using namespace ento;
 
 namespace {
-class GenericTaintChecker : public Checker< check::PostStmt,
-check::PreStmt > {
+class GenericTaintChecker
+: public Checker, check::PreStmt> {
 public:
-  static void *getTag() { static int Tag; return &Tag; }
+  static void *getTag() {
+static int Tag;
+return &Tag;
+  }
 
   void checkPostStmt(const CallExpr *CE, CheckerContext &C) const;
 
@@ -69,8 +72,8 @@ private:
   static Optional getPointedToSVal(CheckerContext &C, const Expr *Arg);
 
   /// Functions defining the attack surface.
-  typedef ProgramStateRef (GenericTaintChecker::*FnCheck)(const CallExpr *,
-   CheckerContext &C) 
const;
+  typedef ProgramStateRef (GenericTaintChecker::*FnCheck)(
+  const CallExpr *, CheckerContext &C) const;
   ProgramStateRef postScanf(const CallExpr *CE, CheckerContext &C) const;
   ProgramStateRef postSocket(const CallExpr *CE, CheckerContext &C) const;
   ProgramStateRef postRetTaint(const CallExpr *CE, CheckerContext &C) const;
@@ -120,16 +123,15 @@ private:
 
 TaintPropagationRule() {}
 
-TaintPropagationRule(unsigned SArg,
- unsigned DArg, bool TaintRet = false) {
+TaintPropagationRule(unsigned SArg, unsigned DArg, bool TaintRet = false) {
   SrcArgs.push_back(SArg);
   DstArgs.push_back(DArg);
   if (TaintRet)
 DstArgs.push_back(ReturnValueIndex);
 }
 
-TaintPropagationRule(unsigned SArg1, unsigned SArg2,
- unsigned DArg, bool TaintRet = false) {
+TaintPropagationRule(unsigned SArg1, unsigned SArg2, unsigned DArg,
+ bool TaintRet = false) {
   SrcArgs.push_back(SArg1);
   SrcArgs.push_back(SArg2);
   DstArgs.push_back(DArg);
@@ -139,18 +141,17 @@ private:
 
 /// Get the propagation rule for a given function.
 static TaintPropagationRule
-  getTaintPropagationRule(const FunctionDecl *FDecl,
-  StringRef Name,
-  CheckerContext &C);
+getTaintPropagationRule(const FunctionDecl *FDecl, StringRef Name,
+CheckerContext &C);
 
 inline void addSrcArg(unsigned A) { SrcArgs.push_back(A); }
-inline void addDstArg(unsigned A)  { DstArgs.push_back(A); }
+inline void addDstArg(unsigned A) { DstArgs.push_back(A); }
 
 inline bool isNull() const { return SrcArgs.empty(); }
 
 inline bool isDestinationArgument(unsigned ArgNum) const {
-  return (std::find(DstArgs.begin(),
-DstArgs.end(), ArgNum) != DstArgs.end());
+  return (std::find(DstArgs.begin(), DstArgs.end(), ArgNum) !=
+  DstArgs.end());
 }
 
 static inline bool isTaintedOrPointsToTainted(const Expr *E,
@@ -169,7 +170,6 @@ private:
 /// Pre-process a function which propagates taint according to the
 /// taint rule.
 ProgramStateRef process(const CallExpr *CE, CheckerContext &C) const;
-
   };
 };
 
@@ -177,17 +177,18 @@ const unsigned GenericTaintChecker::Retu
 const unsigned GenericTaintChecker::InvalidArgIndex;
 
 const char GenericTaintChecker::MsgUncontrolledFormatString[] =
-  "Untrusted data is used as a format string "
-  "(CWE-134: Uncontrolled Format String)";
+"Untrusted data is used as a format string "
+"(CWE-134: Uncontrolled Format String)";
 
 const char GenericTaintChecker::MsgSanitizeSystemArgs[] =
-  "Untrusted data is passed to a system call "
-  "(CERT/STR02-C. Sanitize data passed to complex subsystems)";
+"Untrusted data is passed to a system call "
+"(CERT/STR02-C. Sanitize data passed to complex subsystems)";
 
 const char GenericTaintChecker::MsgTaintedBufferSize[] =
-  "Untrusted data is used to specify the buffer size "
-  "(CERT/STR31-C. Guarantee that storage for strings has sufficient space for "
-  "character data and the null terminator)";
+"Untrusted data is used to specify the buffer size "
+"(CERT/STR31-C. Guarantee that storage for strings has sufficient space "
+"for "
+"characte

r349696 - [analyzer] Improve modeling for returning an object from the top frame with RVO.

2018-12-19 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Dec 19 15:14:06 2018
New Revision: 349696

URL: http://llvm.org/viewvc/llvm-project?rev=349696&view=rev
Log:
[analyzer] Improve modeling for returning an object from the top frame with RVO.

Static Analyzer processes the program function-by-function, sometimes diving
into other functions ("inlining" them). When an object is returned from an
inlined function, Return Value Optimization is modeled, and the returned object
is constructed at its return location directly.

When an object is returned from the function from which the analysis has started
(the top stack frame of the analysis), the return location is unknown. Model it
with a SymbolicRegion based on a conjured symbol that is specifically tagged for
that purpose, because this is generally the correct way to symbolicate
unknown locations in Static Analyzer.

Fixes leak false positives when an object is returned from top frame in C++17:
objects that are put into a SymbolicRegion-based memory region automatically
"escape" and no longer get reported as leaks. This only applies to C++17 return
values with destructors, because it produces a redundant CXXBindTemporaryExpr
in the call site, which confuses our liveness analysis. The actual fix
for liveness analysis is still pending, but it is no longer causing problems.

Additionally, re-enable temporary destructor tests in C++17.

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

rdar://problem/46217550

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
cfe/trunk/test/Analysis/temporaries.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp?rev=349696&r1=349695&r2=349696&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp Wed Dec 19 15:14:06 2018
@@ -113,7 +113,9 @@ SVal ExprEngine::makeZeroElementRegion(P
 std::pair ExprEngine::prepareForObjectConstruction(
 const Expr *E, ProgramStateRef State, const LocationContext *LCtx,
 const ConstructionContext *CC, EvalCallOptions &CallOpts) {
-  MemRegionManager &MRMgr = getSValBuilder().getRegionManager();
+  SValBuilder &SVB = getSValBuilder();
+  MemRegionManager &MRMgr = SVB.getRegionManager();
+  ASTContext &ACtx = SVB.getContext();
 
   // See if we're constructing an existing region by looking at the
   // current construction context.
@@ -139,7 +141,7 @@ std::pair ExprEng
   assert(Init->isAnyMemberInitializer());
   const CXXMethodDecl *CurCtor = cast(LCtx->getDecl());
   Loc ThisPtr =
-  getSValBuilder().getCXXThis(CurCtor, LCtx->getStackFrame());
+  SVB.getCXXThis(CurCtor, LCtx->getStackFrame());
   SVal ThisVal = State->getSVal(ThisPtr);
 
   const ValueDecl *Field;
@@ -199,12 +201,25 @@ std::pair ExprEng
 cast(SFC->getCallSite()), State, CallerLCtx,
 RTC->getConstructionContext(), CallOpts);
   } else {
-// We are on the top frame of the analysis.
-// TODO: What exactly happens when we are? Does the temporary object
-// live long enough in the region store in this case? Would checkers
-// think that this object immediately goes out of scope?
-CallOpts.IsTemporaryCtorOrDtor = true;
-SVal V = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx));
+// We are on the top frame of the analysis. We do not know where is the
+// object returned to. Conjure a symbolic region for the return value.
+// TODO: We probably need a new MemRegion kind to represent the storage
+// of that SymbolicRegion, so that we cound produce a fancy symbol
+// instead of an anonymous conjured symbol.
+// TODO: Do we need to track the region to avoid having it dead
+// too early? It does die too early, at least in C++17, but because
+// putting anything into a SymbolicRegion causes an immediate escape,
+// it doesn't cause any leak false positives.
+const auto *RCC = cast(CC);
+// Make sure that this doesn't coincide with any other symbol
+// conjured for the returned expression.
+static const int TopLevelSymRegionTag = 0;
+const Expr *RetE = RCC->getReturnStmt()->getRetValue();
+assert(RetE && "Void returns should not have a construction context");
+QualType ReturnTy = RetE->getType();
+QualType RegionTy = ACtx.getPointerType(ReturnTy);
+SVal V = SVB.conjureSymbolVal(&TopLevelSymRegionTag, RetE, SFC,
+  RegionTy, currBldrCtx->blockCount());
 return std::make_pair(State, V);
   }
   llvm_unreachable("Unhandled return value construction context!");

Modified: cfe/trunk/test/Analysis/temporaries.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/tem

[PATCH] D55804: [analyzer] C++17: Fix leak false positives when an object with destructor is returned from the top frame.

2018-12-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349696: [analyzer] Improve modeling for returning an object 
from the top frame with RVO. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55804?vs=178936&id=178975#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55804

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  cfe/trunk/test/Analysis/temporaries.cpp

Index: cfe/trunk/test/Analysis/temporaries.cpp
===
--- cfe/trunk/test/Analysis/temporaries.cpp
+++ cfe/trunk/test/Analysis/temporaries.cpp
@@ -1,9 +1,25 @@
-// RUN: %clang_analyze_cc1 -Wno-non-pod-varargs -analyzer-checker=core,cplusplus,debug.ExprInspection -analyzer-config cfg-temporary-dtors=false -verify -w -std=c++03 -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -Wno-non-pod-varargs -analyzer-checker=core,cplusplus,debug.ExprInspection -analyzer-config cfg-temporary-dtors=false -verify -w -std=c++11 -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -Wno-non-pod-varargs -analyzer-checker=core,cplusplus,debug.ExprInspection -DTEMPORARY_DTORS -verify -w -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true -analyzer-config eagerly-assume=false %s -std=c++11
-// RUN: %clang_analyze_cc1 -Wno-non-pod-varargs -analyzer-checker=core,cplusplus,debug.ExprInspection -DTEMPORARY_DTORS -w -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true -analyzer-config eagerly-assume=false %s -std=c++17
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,cplusplus\
+// RUN: -analyzer-checker debug.ExprInspection -Wno-non-pod-varargs\
+// RUN: -analyzer-config eagerly-assume=false -verify %s\
+// RUN: -std=c++03 -analyzer-config cfg-temporary-dtors=false
+
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,cplusplus\
+// RUN: -analyzer-checker debug.ExprInspection -Wno-non-pod-varargs\
+// RUN: -analyzer-config eagerly-assume=false -verify %s\
+// RUN: -std=c++11 -analyzer-config cfg-temporary-dtors=false
+
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,cplusplus\
+// RUN: -analyzer-checker debug.ExprInspection -Wno-non-pod-varargs\
+// RUN: -analyzer-config eagerly-assume=false -verify %s\
+// RUN: -std=c++11 -analyzer-config cfg-temporary-dtors=true\
+// RUN: -DTEMPORARY_DTORS
+
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,cplusplus\
+// RUN: -analyzer-checker debug.ExprInspection -Wno-non-pod-varargs\
+// RUN: -analyzer-config eagerly-assume=false -verify %s\
+// RUN: -std=c++17 -analyzer-config cfg-temporary-dtors=true\
+// RUN: -DTEMPORARY_DTORS
 
-// Note: The C++17 run-line doesn't -verify yet - it is a no-crash test.
 
 extern bool clang_analyzer_eval(bool);
 extern bool clang_analyzer_warnIfReached();
@@ -450,7 +466,16 @@
   }
 
 #if __cplusplus >= 201103L
-  CtorWithNoReturnDtor returnNoReturnDtor() {
+  struct CtorWithNoReturnDtor2 {
+CtorWithNoReturnDtor2() = default;
+
+CtorWithNoReturnDtor2(int x) {
+  clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
+}
+
+~CtorWithNoReturnDtor2() __attribute__((noreturn));
+  };
+  CtorWithNoReturnDtor2 returnNoReturnDtor() {
 return {1}; // no-crash
   }
 #endif
@@ -805,7 +830,12 @@
   // On each branch the variable is constructed directly.
   if (coin) {
 clang_analyzer_eval(x == 1); // expected-warning{{TRUE}}
+#if __cplusplus < 201703L
 clang_analyzer_eval(y == 1); // expected-warning{{TRUE}}
+#else
+// FIXME: Destructor called twice in C++17?
+clang_analyzer_eval(y == 2); // expected-warning{{TRUE}}
+#endif
 clang_analyzer_eval(z == 0); // expected-warning{{TRUE}}
 clang_analyzer_eval(w == 0); // expected-warning{{TRUE}}
 
@@ -813,7 +843,12 @@
 clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
 clang_analyzer_eval(y == 0); // expected-warning{{TRUE}}
 clang_analyzer_eval(z == 1); // expected-warning{{TRUE}}
+#if __cplusplus < 201703L
 clang_analyzer_eval(w == 1); // expected-warning{{TRUE}}
+#else
+// FIXME: Destructor called twice in C++17?
+clang_analyzer_eval(w == 2); // expected-warning{{TRUE}}
+#endif
   }
 }
 } // namespace test_match_constructors_and_destructors
@@ -865,9 +900,12 @@
 public:
   ~C() {
 glob = 1;
+// FIXME: Why is destructor not inlined in C++17
 clang_analyzer_checkInlined(true);
 #ifdef TEMPORARY_DTORS
-// expected-warning@-2{{TRUE}}
+#if __cplusplus < 201703L
+// expected-warning@-3{{TRUE}}
+#endif
 #endif
   }
 };
@@ -886,11 +924,16 @@
   // temporaries returned from functions, so we took the wrong branch.
   coin && is(get()); // no-crash
   if (coin) {
+// FIXME: Why is destructor not inlined in C++17
 clang_analyzer_eval(glob);
 #ifdef TEMPORARY_DTOR

r349691 - Disable -faddsig by default for PS4 target.

2018-12-19 Thread Douglas Yung via cfe-commits
Author: dyung
Date: Wed Dec 19 14:45:26 2018
New Revision: 349691

URL: http://llvm.org/viewvc/llvm-project?rev=349691&view=rev
Log:
Disable -faddsig by default for PS4 target.

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

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=349691&r1=349690&r2=349691&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Dec 19 14:45:26 2018
@@ -5273,6 +5273,7 @@ void Clang::ConstructJob(Compilation &C,
   if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
(TC.getTriple().isOSBinFormatELF() ||
 TC.getTriple().isOSBinFormatCOFF()) &&
+  !TC.getTriple().isPS4() &&
TC.useIntegratedAs() &&
RawTriple.getOS() != llvm::Triple::NetBSD))
 CmdArgs.push_back("-faddrsig");

Modified: cfe/trunk/test/Driver/addrsig.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/addrsig.c?rev=349691&r1=349690&r2=349691&view=diff
==
--- cfe/trunk/test/Driver/addrsig.c (original)
+++ cfe/trunk/test/Driver/addrsig.c Wed Dec 19 14:45:26 2018
@@ -4,6 +4,7 @@
 // RUN: %clang -### -target x86_64-unknown-linux -fno-integrated-as -faddrsig 
-c %s 2>&1 | FileCheck -check-prefix=ADDRSIG %s
 // RUN: %clang -### -target x86_64-unknown-linux -fno-addrsig -c %s 2>&1 | 
FileCheck -check-prefix=NO-ADDRSIG %s
 // RUN: %clang -### -target x86_64-apple-darwin -c %s 2>&1 | FileCheck 
-check-prefix=NO-ADDRSIG %s
+// RUN: %clang -### -target x86_64-scei-ps4 -c %s 2>&1 | FileCheck 
-check-prefix=NO-ADDRSIG %s
 
 // ADDRSIG: -faddrsig
 // NO-ADDRSIG-NOT: -faddrsig


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


[PATCH] D54724: [Driver] Automatically include C++ library dependencies

2018-12-19 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D54724#1304986 , @dim wrote:

> I think I understand the motivation, it's just that the toolchain classes 
> were split up specifically to avoid `if(OS==foo) ... else if(OS==bar) ... 
> else if(OS==baz)` mazes.  So this feels a little like a regression in that 
> sense, putting back the OS-specific ifs in a common function.  But I guess it 
> is a pattern that pops up more often.


I considered both options, the reason I went with conditionals is because we 
seem to use the same approach for other runtimes like compoler-rt builtins, 
sanitizers or XRay, but also because in this case there's likely going to be 
more duplication, e.g. the `switch` to handle either libstdc++ or libc++ would 
have to be duplicated in FreeBSD, NetBSD and OpenBSD drivers (unless we 
introduce a common base class for *BSD drivers). I could try implementing it 
the other way for comparison.

> We've been using libc++ by default since FreeBSD 10.x, and all older versions 
> are now EOLed.  That said, we have always used a linker script to link in 
> libc++.so:
> 
>   $ cat /usr/lib/libc++.so
>   /* $FreeBSD: projects/clang700-import/lib/libc++/libc++.ldscript 305102 
> 2016-08-31 00:11:35Z bapt $ */
>   GROUP ( /usr/lib/libc++.so.1 /usr/lib/libcxxrt.so )

I'm specifically focusing on static case, for shared case this is not relevant 
since libc++.so.1 already dynamically links all the dependencies.

> and for the static case, we've always just added the relevant .o files from 
> libcxxrt into libc++.a:
> 
>   $ ar tv /usr/lib/libc++.a
>   rw-r--r--   0/0 21720 Jan  1 01:00 1970 variant.o
>   rw-r--r--   0/0 61648 Jan  1 01:00 1970 valarray.o
>   rw-r--r--   0/0 18224 Jan  1 01:00 1970 utility.o
>   rw-r--r--   0/0 10656 Jan  1 01:00 1970 typeinfo.o
>   rw-r--r--   0/0198080 Jan  1 01:00 1970 strstream.o
>   rw-r--r--   0/0 59264 Jan  1 01:00 1970 shared_mutex.o
>   rw-r--r--   0/0231552 Jan  1 01:00 1970 regex.o
>   rw-r--r--   0/0 96200 Jan  1 01:00 1970 random.o
>   rw-r--r--   0/0 25240 Jan  1 01:00 1970 optional.o
>   rw-r--r--   0/0239552 Jan  1 01:00 1970 iostream.o
>   rw-r--r--   0/0 17728 Jan  1 01:00 1970 functional.o
>   rw-r--r--   0/0219984 Jan  1 01:00 1970 debug.o
>   rw-r--r--   0/0 58256 Jan  1 01:00 1970 chrono.o
>   rw-r--r--   0/0 35672 Jan  1 01:00 1970 charconv.o
>   rw-r--r--   0/0 21280 Jan  1 01:00 1970 bind.o
>   rw-r--r--   0/0 24312 Jan  1 01:00 1970 any.o
>   rw-r--r--   0/0   1010288 Jan  1 01:00 1970 algorithm.o
>   rw-r--r--   0/0 42944 Jan  1 01:00 1970 hash.o
>   rw-r--r--   0/0 45152 Jan  1 01:00 1970 cxxrt_typeinfo.o
>   rw-r--r--   0/0278784 Jan  1 01:00 1970 
> cxxrt_libelftc_dem_gnu3.o
>   rw-r--r--   0/0 17704 Jan  1 01:00 1970 cxxrt_stdexcept.o
>   rw-r--r--   0/0224664 Jan  1 01:00 1970 thread.o
>   rw-r--r--   0/0218392 Jan  1 01:00 1970 future.o
>   rw-r--r--   0/0 31456 Jan  1 01:00 1970 exception.o
>   rw-r--r--   0/0   4604424 Jan  1 01:00 1970 locale.o
>   rw-r--r--   0/0 27216 Jan  1 01:00 1970 vector.o
>   rw-r--r--   0/0102712 Jan  1 01:00 1970 mutex.o
>   rw-r--r--   0/0 63872 Jan  1 01:00 1970 memory.o
>   rw-r--r--   0/0   1261888 Jan  1 01:00 1970 ios.o
>   rw-r--r--   0/0 69528 Jan  1 01:00 1970 condition_variable.o
>   rw-r--r--   0/0181368 Jan  1 01:00 1970 system_error.o
>   rw-r--r--   0/0   2006648 Jan  1 01:00 1970 string.o
>   rw-r--r--   0/0105408 Jan  1 01:00 1970 stdexcept.o
>   rw-r--r--   0/0 37552 Jan  1 01:00 1970 new.o
>   rw-r--r--   0/0 10280 Jan  1 01:00 1970 cxxrt_memory.o
>   rw-r--r--   0/0  4880 Jan  1 01:00 1970 cxxrt_auxhelper.o
>   rw-r--r--   0/0  2872 Jan  1 01:00 1970 cxxrt_terminate.o
>   rw-r--r--   0/0123504 Jan  1 01:00 1970 cxxrt_exception.o
>   rw-r--r--   0/0 18136 Jan  1 01:00 1970 cxxrt_dynamic_cast.o
>   rw-r--r--   0/0  5696 Jan  1 01:00 1970 cxxrt_guard.o

We use that solution for libc++abi as well but that doesn't handle other 
dependencies.

> But I can link almost all C++ programs statically without having to add 
> `-lpthread`.  I guess you only really need it if you start using the 
> multithreading primitives?  I'm sort of hesitant to always add if, if it is 
> not always needed.  @emaste, what's your opinion on this?

Correct, on other platforms you also need `-ldl`, but on *BSD this is part of 
libc AFAIK. We could also consider surrounding these dependencies with 
`--push-state --as-needed` and `--pop-state` to avoid linking them in if 
they're not needed.


Repository:
  rC Clang

CHANGES SINCE LAST ACTIO

[PATCH] D55710: add pragmas to control Software Pipelining optimisation

2018-12-19 Thread Alexey Lapshin via Phabricator via cfe-commits
alexey.lapshin updated this revision to Diff 178956.
alexey.lapshin edited the summary of this revision.
alexey.lapshin added a comment.

Please consider this change:

1. addressed style issues and formatted patch with clang-format
2. renamed pragma pipeline_ii_count to pipeline_initiation_interval
3. left LoopAttributes inclass initializers refactoring for some another fix :-)
4. added more tests


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

https://reviews.llvm.org/D55710

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticParseKinds.td
  lib/CodeGen/CGLoopInfo.cpp
  lib/CodeGen/CGLoopInfo.h
  lib/Parse/ParsePragma.cpp
  lib/Sema/SemaStmtAttr.cpp
  test/CodeGenCXX/pragma-pipeline.cpp
  test/Parser/pragma-loop.cpp
  test/Parser/pragma-pipeline.cpp
  test/Parser/pragma-unroll-and-jam.cpp

Index: test/Parser/pragma-unroll-and-jam.cpp
===
--- test/Parser/pragma-unroll-and-jam.cpp
+++ test/Parser/pragma-unroll-and-jam.cpp
@@ -67,7 +67,7 @@
   }
 
 // pragma clang unroll_and_jam is disabled for the moment
-/* expected-error {{invalid option 'unroll_and_jam'; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, or distribute}} */ #pragma clang loop unroll_and_jam(4)
+/* expected-error {{invalid option 'unroll_and_jam'; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval or distribute}} */ #pragma clang loop unroll_and_jam(4)
   for (int i = 0; i < Length; i++) {
 for (int j = 0; j < Length; j++) {
   List[i * Length + j] = Value;
Index: test/Parser/pragma-pipeline.cpp
===
--- /dev/null
+++ test/Parser/pragma-pipeline.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+
+// Note that this puts the expected lines before the directives to work around
+// limitations in the -verify mode.
+
+void test(int *List, int Length, int Value) {
+  int i = 0;
+
+#pragma clang loop pipeline(disable)
+  for (int i = 0; i < Length; i++) {
+List[i] = Value;
+  }
+
+#pragma clang loop pipeline_initiation_interval(10)
+  for (int i = 0; i < Length; i++) {
+List[i] = Value;
+  }
+
+/* expected-error {{expected ')'}} */ #pragma clang loop pipeline(disable
+/* expected-error {{invalid argument; expected 'disable'}} */ #pragma clang loop pipeline(enable)
+/* expected-error {{invalid argument; expected 'disable'}} */ #pragma clang loop pipeline(error)
+/* expected-error {{expected '('}} */ #pragma clang loop pipeline disable
+/* expected-error {{missing argument; expected an integer value}} */ #pragma clang loop pipeline_initiation_interval()
+/* expected-error {{use of undeclared identifier 'error'}} */ #pragma clang loop pipeline_initiation_interval(error)
+/* expected-error {{expected '('}} */ #pragma clang loop pipeline_initiation_interval 1 2
+/* expected-error {{expected ')'}} */ #pragma clang loop pipeline_initiation_interval(1
+/* expected-error {{invalid argument of type 'double'; expected an integer type}} */ #pragma clang loop pipeline_initiation_interval(1.0)
+/* expected-error {{invalid value '0'; must be positive}} */ #pragma clang loop pipeline_initiation_interval(0)
+  for (int i = 0; i < Length; i++) {
+for (int j = 0; j < Length; j++) {
+  List[i * Length + j] = Value;
+}
+  }
+
+#pragma clang loop pipeline(disable) 
+/* expected-error {{expected a for, while, or do-while loop to follow '#pragma clang loop'}} */ int j = Length;
+#pragma clang loop pipeline_initiation_interval(4)
+/* expected-error {{expected a for, while, or do-while loop to follow '#pragma clang loop'}} */ int k = Length;
+
+#pragma clang loop pipeline(disable)
+#pragma clang loop pipeline_initiation_interval(4) /* expected-error {{incompatible directives 'pipeline(disable)' and 'pipeline_initiation_interval(4)'}} */
+  for (int i = 0; i < Length; i++) {
+List[i] = Value;
+  }
+
+#pragma clang loop pipeline(disable)
+/* expected-error {{expected statement}} */ }
Index: test/Parser/pragma-loop.cpp
===
--- test/Parser/pragma-loop.cpp
+++ test/Parser/pragma-loop.cpp
@@ -147,7 +147,7 @@
 /* expected-error {{missing argument; expected 'enable', 'full' or 'disable'}} */ #pragma clang loop unroll()
 /* expected-error {{missing argument; expected 'enable' or 'disable'}} */ #pragma clang loop distribute()
 
-/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, or distribute}} */ #pragma clang loop
+/* expected-error {{missing option; expected vectorize, vectorize_width, interleave, interleave_count, unroll, unroll_count, pipeline, pipeline_initiation_interval or distribute}} */ #pragma clang loop
 /* expected-error {{invalid option 'badkeyword'}} */ #pragma clang loop badkey

[PATCH] D55875: [analyzer] pr38668: RegionStore: Do not attempt to cast loaded values of non-scalar types.

2018-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 178963.
NoQ added a comment.

Remove the test change that wasn't caused by this patch.


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

https://reviews.llvm.org/D55875

Files:
  lib/StaticAnalyzer/Core/Store.cpp
  test/Analysis/casts.c
  test/Analysis/pointer-to-member.cpp


Index: test/Analysis/pointer-to-member.cpp
===
--- test/Analysis/pointer-to-member.cpp
+++ test/Analysis/pointer-to-member.cpp
@@ -253,11 +253,10 @@
   clang_analyzer_eval(&A::y); // expected-warning{{TRUE}}
   clang_analyzer_eval(&A::z); // expected-warning{{TRUE}}
 
-  // FIXME: These should be true.
   int A::*l = &A::x, A::*m = &A::y, A::*n = &A::z;
-  clang_analyzer_eval(l); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(m); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(n); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l); // expected-warning{{TRUE}}
+  clang_analyzer_eval(m); // expected-warning{{TRUE}}
+  clang_analyzer_eval(n); // expected-warning{{TRUE}}
 
   // FIXME: These should be true as well.
   A a;
Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -213,3 +213,14 @@
 }
 
 #endif
+
+char no_crash_SymbolCast_of_float_type_aux(int *p) {
+  *p += 1;
+  return *p;
+}
+
+void no_crash_SymbolCast_of_float_type() {
+  extern float x;
+  char (*f)() = no_crash_SymbolCast_of_float_type_aux;
+  f(&x);
+}
Index: lib/StaticAnalyzer/Core/Store.cpp
===
--- lib/StaticAnalyzer/Core/Store.cpp
+++ lib/StaticAnalyzer/Core/Store.cpp
@@ -394,14 +394,28 @@
   return UnknownVal();
 }
 
+static bool isScalarEnoughToAttemptACast(QualType T) {
+  return T->isIntegralOrEnumerationType() || T->isAnyPointerType() ||
+ T->isReferenceType();
+}
+
 /// CastRetrievedVal - Used by subclasses of StoreManager to implement
 ///  implicit casts that arise from loads from regions that are reinterpreted
 ///  as another region.
 SVal StoreManager::CastRetrievedVal(SVal V, const TypedValueRegion *R,
-QualType castTy) {
-  if (castTy.isNull() || V.isUnknownOrUndef())
+QualType CastTy) {
+  if (CastTy.isNull() || V.isUnknownOrUndef())
 return V;
 
+  QualType OrigTy = R->getValueType();
+
+  if (!isScalarEnoughToAttemptACast(OrigTy) ||
+  !isScalarEnoughToAttemptACast(CastTy)) {
+if (OrigTy.getUnqualifiedType() == CastTy.getUnqualifiedType())
+  return V;
+return UnknownVal();
+  }
+
   // When retrieving symbolic pointer and expecting a non-void pointer,
   // wrap them into element regions of the expected type if necessary.
   // SValBuilder::dispatchCast() doesn't do that, but it is necessary to
@@ -410,13 +424,13 @@
   // We might need to do that for non-void pointers as well.
   // FIXME: We really need a single good function to perform casts for us
   // correctly every time we need it.
-  if (castTy->isPointerType() && !castTy->isVoidPointerType())
+  if (CastTy->isPointerType() && !CastTy->isVoidPointerType())
 if (const auto *SR = dyn_cast_or_null(V.getAsRegion()))
   if (SR->getSymbol()->getType().getCanonicalType() !=
-  castTy.getCanonicalType())
-return loc::MemRegionVal(castRegion(SR, castTy));
+  CastTy.getCanonicalType())
+return loc::MemRegionVal(castRegion(SR, CastTy));
 
-  return svalBuilder.dispatchCast(V, castTy);
+  return svalBuilder.dispatchCast(V, CastTy);
 }
 
 SVal StoreManager::getLValueFieldOrIvar(const Decl *D, SVal Base) {


Index: test/Analysis/pointer-to-member.cpp
===
--- test/Analysis/pointer-to-member.cpp
+++ test/Analysis/pointer-to-member.cpp
@@ -253,11 +253,10 @@
   clang_analyzer_eval(&A::y); // expected-warning{{TRUE}}
   clang_analyzer_eval(&A::z); // expected-warning{{TRUE}}
 
-  // FIXME: These should be true.
   int A::*l = &A::x, A::*m = &A::y, A::*n = &A::z;
-  clang_analyzer_eval(l); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(m); // expected-warning{{UNKNOWN}}
-  clang_analyzer_eval(n); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l); // expected-warning{{TRUE}}
+  clang_analyzer_eval(m); // expected-warning{{TRUE}}
+  clang_analyzer_eval(n); // expected-warning{{TRUE}}
 
   // FIXME: These should be true as well.
   A a;
Index: test/Analysis/casts.c
===
--- test/Analysis/casts.c
+++ test/Analysis/casts.c
@@ -213,3 +213,14 @@
 }
 
 #endif
+
+char no_crash_SymbolCast_of_float_type_aux(int *p) {
+  *p += 1;
+  return *p;
+}
+
+void no_crash_SymbolCast_of_float_type() {
+  extern float x;
+  char (*f)() = no_crash_SymbolCast_of_float_type_aux;
+  f(&x);
+}
Index: lib/StaticAnalyzer/Core/Store.cpp
===

r349683 - [analyzer] CStringChecker: Add the forgotten test file.

2018-12-19 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Dec 19 13:51:59 2018
New Revision: 349683

URL: http://llvm.org/viewvc/llvm-project?rev=349683&view=rev
Log:
[analyzer] CStringChecker: Add the forgotten test file.

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

rdar://problem/45366551

Added:
cfe/trunk/test/Analysis/string.cpp

Added: cfe/trunk/test/Analysis/string.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/string.cpp?rev=349683&view=auto
==
--- cfe/trunk/test/Analysis/string.cpp (added)
+++ cfe/trunk/test/Analysis/string.cpp Wed Dec 19 13:51:59 2018
@@ -0,0 +1,28 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -verify %s
+
+// expected-no-diagnostics
+
+// Test functions that are called "memcpy" but aren't the memcpy
+// we're looking for. Unfortunately, this test cannot be put into
+// a namespace. The out-of-class weird memcpy needs to be recognized
+// as a normal C function for the test to make sense.
+typedef __typeof(sizeof(int)) size_t;
+void *memcpy(void *, const void *, size_t);
+
+struct S {
+  static S s1, s2;
+
+  // A weird overload within the class that accepts a structure reference
+  // instead of a pointer.
+  void memcpy(void *, const S &, size_t);
+  void test_in_class_weird_memcpy() {
+memcpy(this, s2, 1); // no-crash
+  }
+};
+
+// A similarly weird overload outside of the class.
+void *memcpy(void *, const S &, size_t);
+
+void test_out_of_class_weird_memcpy() {
+  memcpy(&S::s1, S::s2, 1); // no-crash
+}


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


[PATCH] D55873: [analyzer] CStringChecker: Fix a crash when an argument of a weird type is encountered.

2018-12-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349682: [analyzer] CStringChecker: Fix a crash on C++ 
overloads of standard functions. (authored by dergachev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55873?vs=178959&id=178961#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D55873

Files:
  lib/StaticAnalyzer/Checkers/CStringChecker.cpp

Index: lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -188,7 +188,7 @@
 const Expr *Buf,
 const char *message = nullptr,
 bool WarnAboutSize = false) const {
-// This is a convenience override.
+// This is a convenience overload.
 return CheckBufferAccess(C, state, Size, Buf, nullptr, message, nullptr,
  WarnAboutSize);
   }
@@ -2254,64 +2254,86 @@
 // The driver method, and other Checker callbacks.
 //===--===//
 
-bool CStringChecker::evalCall(const CallExpr *CE, CheckerContext &C) const {
+static CStringChecker::FnCheck identifyCall(const CallExpr *CE,
+CheckerContext &C) {
   const FunctionDecl *FDecl = C.getCalleeDecl(CE);
-
   if (!FDecl)
-return false;
+return nullptr;
+
+  // Pro-actively check that argument types are safe to do arithmetic upon.
+  // We do not want to crash if someone accidentally passes a structure
+  // into, say, a C++ overload of any of these functions.
+  if (isCPPStdLibraryFunction(FDecl, "copy")) {
+if (CE->getNumArgs() < 3 || !CE->getArg(2)->getType()->isPointerType())
+  return nullptr;
+return &CStringChecker::evalStdCopy;
+  } else if (isCPPStdLibraryFunction(FDecl, "copy_backward")) {
+if (CE->getNumArgs() < 3 || !CE->getArg(2)->getType()->isPointerType())
+  return nullptr;
+return &CStringChecker::evalStdCopyBackward;
+  } else {
+// An umbrella check for all C library functions.
+for (auto I: CE->arguments()) {
+  QualType T = I->getType();
+  if (!T->isIntegralOrEnumerationType() && !T->isPointerType())
+return nullptr;
+}
+  }
 
   // FIXME: Poorly-factored string switches are slow.
-  FnCheck evalFunction = nullptr;
   if (C.isCLibraryFunction(FDecl, "memcpy"))
-evalFunction =  &CStringChecker::evalMemcpy;
+return &CStringChecker::evalMemcpy;
   else if (C.isCLibraryFunction(FDecl, "mempcpy"))
-evalFunction =  &CStringChecker::evalMempcpy;
+return &CStringChecker::evalMempcpy;
   else if (C.isCLibraryFunction(FDecl, "memcmp"))
-evalFunction =  &CStringChecker::evalMemcmp;
+return &CStringChecker::evalMemcmp;
   else if (C.isCLibraryFunction(FDecl, "memmove"))
-evalFunction =  &CStringChecker::evalMemmove;
-  else if (C.isCLibraryFunction(FDecl, "memset") || 
-C.isCLibraryFunction(FDecl, "explicit_memset"))
-evalFunction =  &CStringChecker::evalMemset;
+return &CStringChecker::evalMemmove;
+  else if (C.isCLibraryFunction(FDecl, "memset") ||
+   C.isCLibraryFunction(FDecl, "explicit_memset"))
+return &CStringChecker::evalMemset;
   else if (C.isCLibraryFunction(FDecl, "strcpy"))
-evalFunction =  &CStringChecker::evalStrcpy;
+return &CStringChecker::evalStrcpy;
   else if (C.isCLibraryFunction(FDecl, "strncpy"))
-evalFunction =  &CStringChecker::evalStrncpy;
+return &CStringChecker::evalStrncpy;
   else if (C.isCLibraryFunction(FDecl, "stpcpy"))
-evalFunction =  &CStringChecker::evalStpcpy;
+return &CStringChecker::evalStpcpy;
   else if (C.isCLibraryFunction(FDecl, "strlcpy"))
-evalFunction =  &CStringChecker::evalStrlcpy;
+return &CStringChecker::evalStrlcpy;
   else if (C.isCLibraryFunction(FDecl, "strcat"))
-evalFunction =  &CStringChecker::evalStrcat;
+return &CStringChecker::evalStrcat;
   else if (C.isCLibraryFunction(FDecl, "strncat"))
-evalFunction =  &CStringChecker::evalStrncat;
+return &CStringChecker::evalStrncat;
   else if (C.isCLibraryFunction(FDecl, "strlcat"))
-evalFunction =  &CStringChecker::evalStrlcat;
+return &CStringChecker::evalStrlcat;
   else if (C.isCLibraryFunction(FDecl, "strlen"))
-evalFunction =  &CStringChecker::evalstrLength;
+return &CStringChecker::evalstrLength;
   else if (C.isCLibraryFunction(FDecl, "strnlen"))
-evalFunction =  &CStringChecker::evalstrnLength;
+return &CStringChecker::evalstrnLength;
   else if (C.isCLibraryFunction(FDecl, "strcmp"))
-evalFunction =  &CStringChecker::evalStrcmp;
+return &CStringChecker::evalStrcmp;
   else if (C.isCLibraryFunction(FDecl, "strncmp"))
-evalFunction =  &CStringChecker::evalS

[PATCH] D55662: [Sema][ObjC] Do not warn about repeated uses of weak variables when the variables are accessed in an unevaluated context.

2018-12-19 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

In D55662#1335773 , @rjmccall wrote:

> Okay.  You may need to push an unevaluated context when doing that.


Since I'm just moving the call to `CheckPlaceholderExpr` to the call site, I 
don't think I have to push an unevaluated context there?

Also, it looks like I can just change the check 
`Init->getType()->isNonOverloadPlaceholderType()`  at the beginning of 
`Sema::DeduceAutoType` to `Init->getType()->getAsPlaceholderType()` instead of 
inserting the call to `CheckPlaceholderExpr` right before the call to 
`BuildDecltypeType`.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55662



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


r349682 - [analyzer] CStringChecker: Fix a crash on C++ overloads of standard functions.

2018-12-19 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Dec 19 13:50:46 2018
New Revision: 349682

URL: http://llvm.org/viewvc/llvm-project?rev=349682&view=rev
Log:
[analyzer] CStringChecker: Fix a crash on C++ overloads of standard functions.

It turns out that it's not all that uncommon to have a C++ override of, say,
memcpy that receives a structure (or two) by reference (or by value, if it's
being copied from) and copies memory from it (or into it, if it's passed
by reference). In this case the argument will be of structure type (recall that
expressions of reference type do not exist: instead, C++ classifies expressions
into prvalues and lvalues and xvalues).

In this scenario we crash because we are trying to assume that, say,
a memory region is equal to an empty CompoundValue (the non-lazy one; this is
what makeZeroVal() return for compound types and it represents prvalue of
an object that is initialized with an empty initializer list).

Add defensive checks.

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

rdar://problem/45366551

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp?rev=349682&r1=349681&r2=349682&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Wed Dec 19 
13:50:46 2018
@@ -188,7 +188,7 @@ public:
 const Expr *Buf,
 const char *message = nullptr,
 bool WarnAboutSize = false) const {
-// This is a convenience override.
+// This is a convenience overload.
 return CheckBufferAccess(C, state, Size, Buf, nullptr, message, nullptr,
  WarnAboutSize);
   }
@@ -2254,64 +2254,86 @@ static bool isCPPStdLibraryFunction(cons
 // The driver method, and other Checker callbacks.
 
//===--===//
 
-bool CStringChecker::evalCall(const CallExpr *CE, CheckerContext &C) const {
+static CStringChecker::FnCheck identifyCall(const CallExpr *CE,
+CheckerContext &C) {
   const FunctionDecl *FDecl = C.getCalleeDecl(CE);
-
   if (!FDecl)
-return false;
+return nullptr;
+
+  // Pro-actively check that argument types are safe to do arithmetic upon.
+  // We do not want to crash if someone accidentally passes a structure
+  // into, say, a C++ overload of any of these functions.
+  if (isCPPStdLibraryFunction(FDecl, "copy")) {
+if (CE->getNumArgs() < 3 || !CE->getArg(2)->getType()->isPointerType())
+  return nullptr;
+return &CStringChecker::evalStdCopy;
+  } else if (isCPPStdLibraryFunction(FDecl, "copy_backward")) {
+if (CE->getNumArgs() < 3 || !CE->getArg(2)->getType()->isPointerType())
+  return nullptr;
+return &CStringChecker::evalStdCopyBackward;
+  } else {
+// An umbrella check for all C library functions.
+for (auto I: CE->arguments()) {
+  QualType T = I->getType();
+  if (!T->isIntegralOrEnumerationType() && !T->isPointerType())
+return nullptr;
+}
+  }
 
   // FIXME: Poorly-factored string switches are slow.
-  FnCheck evalFunction = nullptr;
   if (C.isCLibraryFunction(FDecl, "memcpy"))
-evalFunction =  &CStringChecker::evalMemcpy;
+return &CStringChecker::evalMemcpy;
   else if (C.isCLibraryFunction(FDecl, "mempcpy"))
-evalFunction =  &CStringChecker::evalMempcpy;
+return &CStringChecker::evalMempcpy;
   else if (C.isCLibraryFunction(FDecl, "memcmp"))
-evalFunction =  &CStringChecker::evalMemcmp;
+return &CStringChecker::evalMemcmp;
   else if (C.isCLibraryFunction(FDecl, "memmove"))
-evalFunction =  &CStringChecker::evalMemmove;
-  else if (C.isCLibraryFunction(FDecl, "memset") || 
-C.isCLibraryFunction(FDecl, "explicit_memset"))
-evalFunction =  &CStringChecker::evalMemset;
+return &CStringChecker::evalMemmove;
+  else if (C.isCLibraryFunction(FDecl, "memset") ||
+   C.isCLibraryFunction(FDecl, "explicit_memset"))
+return &CStringChecker::evalMemset;
   else if (C.isCLibraryFunction(FDecl, "strcpy"))
-evalFunction =  &CStringChecker::evalStrcpy;
+return &CStringChecker::evalStrcpy;
   else if (C.isCLibraryFunction(FDecl, "strncpy"))
-evalFunction =  &CStringChecker::evalStrncpy;
+return &CStringChecker::evalStrncpy;
   else if (C.isCLibraryFunction(FDecl, "stpcpy"))
-evalFunction =  &CStringChecker::evalStpcpy;
+return &CStringChecker::evalStpcpy;
   else if (C.isCLibraryFunction(FDecl, "strlcpy"))
-evalFunction =  &CStringChecker::evalStrlcpy;
+return &CStringChecker::evalStrlcpy;
   else if (C.isCLibraryFunction(FDecl, "strcat"))
-evalFunction =  &CStr

[PATCH] D55853: Ignore ConstantExpr in IgnoreParenNoopCasts

2018-12-19 Thread Reid Kleckner via Phabricator via cfe-commits
rnk marked an inline comment as done.
rnk added inline comments.



Comment at: clang/lib/AST/Expr.cpp:2694
   while (true) {
 E = E->IgnoreParens();
 

rsmith wrote:
> Maybe `IgnoreParens` should be doing this itself?
I can do that, it passes tests.


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

https://reviews.llvm.org/D55853



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


[PATCH] D55853: Ignore ConstantExpr in IgnoreParenNoopCasts

2018-12-19 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 178960.
rnk added a comment.

- move to IgnoreParens


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

https://reviews.llvm.org/D55853

Files:
  clang/lib/AST/Expr.cpp
  clang/test/CodeGenCXX/mangle-ms-templates.cpp


Index: clang/test/CodeGenCXX/mangle-ms-templates.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-templates.cpp
+++ clang/test/CodeGenCXX/mangle-ms-templates.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++11 -fms-compatibility-version=19 -emit-llvm %s -o - 
-fms-extensions -fdelayed-template-parsing -triple=i386-pc-win32 | FileCheck %s
 // RUN: %clang_cc1 -std=c++11 -fms-compatibility-version=19 -emit-llvm %s -o - 
-fms-extensions -fdelayed-template-parsing -triple=x86_64-pc-win32 | FileCheck 
-check-prefix X64 %s
+// RUN: %clang_cc1 -std=c++17 -fms-compatibility-version=19 -emit-llvm %s -o - 
-fms-extensions -fdelayed-template-parsing -triple=i386-pc-win32 | FileCheck %s
+// RUN: %clang_cc1 -std=c++17 -fms-compatibility-version=19 -emit-llvm %s -o - 
-fms-extensions -fdelayed-template-parsing -triple=x86_64-pc-win32 | FileCheck 
-check-prefix X64 %s
 
 template
 class Class {
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -2547,6 +2547,10 @@
 continue;
   }
 }
+if (ConstantExpr *CE = dyn_cast(E)) {
+  E = CE->getSubExpr();
+  continue;
+}
 return E;
   }
 }
@@ -2669,10 +2673,6 @@
   E = NTTP->getReplacement();
   continue;
 }
-if (ConstantExpr *CE = dyn_cast(E)) {
-  E = CE->getSubExpr();
-  continue;
-}
 return E;
   }
 }


Index: clang/test/CodeGenCXX/mangle-ms-templates.cpp
===
--- clang/test/CodeGenCXX/mangle-ms-templates.cpp
+++ clang/test/CodeGenCXX/mangle-ms-templates.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++11 -fms-compatibility-version=19 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=i386-pc-win32 | FileCheck %s
 // RUN: %clang_cc1 -std=c++11 -fms-compatibility-version=19 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=x86_64-pc-win32 | FileCheck -check-prefix X64 %s
+// RUN: %clang_cc1 -std=c++17 -fms-compatibility-version=19 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=i386-pc-win32 | FileCheck %s
+// RUN: %clang_cc1 -std=c++17 -fms-compatibility-version=19 -emit-llvm %s -o - -fms-extensions -fdelayed-template-parsing -triple=x86_64-pc-win32 | FileCheck -check-prefix X64 %s
 
 template
 class Class {
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -2547,6 +2547,10 @@
 continue;
   }
 }
+if (ConstantExpr *CE = dyn_cast(E)) {
+  E = CE->getSubExpr();
+  continue;
+}
 return E;
   }
 }
@@ -2669,10 +2673,6 @@
   E = NTTP->getReplacement();
   continue;
 }
-if (ConstantExpr *CE = dyn_cast(E)) {
-  E = CE->getSubExpr();
-  continue;
-}
 return E;
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55873: [analyzer] CStringChecker: Fix a crash when an argument of a weird type is encountered.

2018-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 178959.
NoQ added a comment.

Fxd.


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

https://reviews.llvm.org/D55873

Files:
  lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  test/Analysis/string.cpp

Index: test/Analysis/string.cpp
===
--- /dev/null
+++ test/Analysis/string.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -verify %s
+
+// expected-no-diagnostics
+
+// Test functions that are called "memcpy" but aren't the memcpy
+// we're looking for. Unfortunately, this test cannot be put into
+// a namespace. The out-of-class weird memcpy needs to be recognized
+// as a normal C function for the test to make sense.
+typedef __typeof(sizeof(int)) size_t;
+void *memcpy(void *, const void *, size_t);
+
+struct S {
+  static S s1, s2;
+
+  // A weird overload within the class that accepts a structure reference
+  // instead of a pointer.
+  void memcpy(void *, const S &, size_t);
+  void test_in_class_weird_memcpy() {
+memcpy(this, s2, 1); // no-crash
+  }
+};
+
+// A similarly weird overload outside of the class.
+void *memcpy(void *, const S &, size_t);
+
+void test_out_of_class_weird_memcpy() {
+  memcpy(&S::s1, S::s2, 1); // no-crash
+}
Index: lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -188,7 +188,7 @@
 const Expr *Buf,
 const char *message = nullptr,
 bool WarnAboutSize = false) const {
-// This is a convenience override.
+// This is a convenience overload.
 return CheckBufferAccess(C, state, Size, Buf, nullptr, message, nullptr,
  WarnAboutSize);
   }
@@ -2254,64 +2254,86 @@
 // The driver method, and other Checker callbacks.
 //===--===//
 
-bool CStringChecker::evalCall(const CallExpr *CE, CheckerContext &C) const {
+static CStringChecker::FnCheck identifyCall(const CallExpr *CE,
+CheckerContext &C) {
   const FunctionDecl *FDecl = C.getCalleeDecl(CE);
-
   if (!FDecl)
-return false;
+return nullptr;
+
+  // Pro-actively check that argument types are safe to do arithmetic upon.
+  // We do not want to crash if someone accidentally passes a structure
+  // into, say, a C++ overload of any of these functions.
+  if (isCPPStdLibraryFunction(FDecl, "copy")) {
+if (CE->getNumArgs() < 3 || !CE->getArg(2)->getType()->isPointerType())
+  return nullptr;
+return &CStringChecker::evalStdCopy;
+  } else if (isCPPStdLibraryFunction(FDecl, "copy_backward")) {
+if (CE->getNumArgs() < 3 || !CE->getArg(2)->getType()->isPointerType())
+  return nullptr;
+return &CStringChecker::evalStdCopyBackward;
+  } else {
+// An umbrella check for all C library functions.
+for (auto I: CE->arguments()) {
+  QualType T = I->getType();
+  if (!T->isIntegralOrEnumerationType() && !T->isPointerType())
+return nullptr;
+}
+  }
 
   // FIXME: Poorly-factored string switches are slow.
-  FnCheck evalFunction = nullptr;
   if (C.isCLibraryFunction(FDecl, "memcpy"))
-evalFunction =  &CStringChecker::evalMemcpy;
+return &CStringChecker::evalMemcpy;
   else if (C.isCLibraryFunction(FDecl, "mempcpy"))
-evalFunction =  &CStringChecker::evalMempcpy;
+return &CStringChecker::evalMempcpy;
   else if (C.isCLibraryFunction(FDecl, "memcmp"))
-evalFunction =  &CStringChecker::evalMemcmp;
+return &CStringChecker::evalMemcmp;
   else if (C.isCLibraryFunction(FDecl, "memmove"))
-evalFunction =  &CStringChecker::evalMemmove;
-  else if (C.isCLibraryFunction(FDecl, "memset") || 
-C.isCLibraryFunction(FDecl, "explicit_memset"))
-evalFunction =  &CStringChecker::evalMemset;
+return &CStringChecker::evalMemmove;
+  else if (C.isCLibraryFunction(FDecl, "memset") ||
+   C.isCLibraryFunction(FDecl, "explicit_memset"))
+return &CStringChecker::evalMemset;
   else if (C.isCLibraryFunction(FDecl, "strcpy"))
-evalFunction =  &CStringChecker::evalStrcpy;
+return &CStringChecker::evalStrcpy;
   else if (C.isCLibraryFunction(FDecl, "strncpy"))
-evalFunction =  &CStringChecker::evalStrncpy;
+return &CStringChecker::evalStrncpy;
   else if (C.isCLibraryFunction(FDecl, "stpcpy"))
-evalFunction =  &CStringChecker::evalStpcpy;
+return &CStringChecker::evalStpcpy;
   else if (C.isCLibraryFunction(FDecl, "strlcpy"))
-evalFunction =  &CStringChecker::evalStrlcpy;
+return &CStringChecker::evalStrlcpy;
   else if (C.isCLibraryFunction(FDecl, "strcat"))
-evalFunction =  &CStringChecker::evalStrcat;
+return &CStringChecker::evalStrcat;
   el

[PATCH] D55662: [Sema][ObjC] Do not warn about repeated uses of weak variables when the variables are accessed in an unevaluated context.

2018-12-19 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 178957.
ahatanak added a comment.

Remove the call to `CheckPlaceholderExpr` in `Sema::BuildDecltypeType` and move 
it to `Sema::DeduceAutoType`. Assert that the expression that is passed to 
`Sema::BuildDecltypeType` isn't a placeholder.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55662

Files:
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Sema/SemaExprObjC.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaType.cpp
  test/SemaObjC/arc-repeated-weak.mm


Index: test/SemaObjC/arc-repeated-weak.mm
===
--- test/SemaObjC/arc-repeated-weak.mm
+++ test/SemaObjC/arc-repeated-weak.mm
@@ -462,6 +462,9 @@
   NSString * t2 = NSBundle.foo2.prop;
   use(NSBundle.foo2.weakProp); // expected-warning{{weak property 'weakProp' 
may be accessed multiple times}}
   use(NSBundle2.foo2.weakProp); // expected-note{{also accessed here}}
+  decltype([NSBundle2.foo2 weakProp]) t3;
+  decltype(NSBundle2.foo2.weakProp) t4;
+  __typeof__(NSBundle2.foo2.weakProp) t5;
 }
 
 // This used to crash in the constructor of WeakObjectProfileTy when a
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -8040,9 +8040,7 @@
 }
 
 QualType Sema::BuildTypeofExprType(Expr *E, SourceLocation Loc) {
-  ExprResult ER = CheckPlaceholderExpr(E);
-  if (ER.isInvalid()) return QualType();
-  E = ER.get();
+  assert(!E->getType()->getAsPlaceholderType() && "unexpected placeholder");
 
   if (!getLangOpts().CPlusPlus && E->refersToBitField())
 Diag(E->getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) << 2;
@@ -8127,9 +8125,7 @@
 
 QualType Sema::BuildDecltypeType(Expr *E, SourceLocation Loc,
  bool AsUnevaluated) {
-  ExprResult ER = CheckPlaceholderExpr(E);
-  if (ER.isInvalid()) return QualType();
-  E = ER.get();
+  assert(!E->getType()->getAsPlaceholderType() && "unexpected placeholder");
 
   if (AsUnevaluated && CodeSynthesisContexts.empty() &&
   E->HasSideEffects(Context, false)) {
Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -4429,6 +4429,10 @@
 return DAR_FailedAlreadyDiagnosed;
   }
 
+  ExprResult ER = CheckPlaceholderExpr(Init);
+  if (ER.isInvalid())
+return DAR_FailedAlreadyDiagnosed;
+  Init = ER.get();
   QualType Deduced = BuildDecltypeType(Init, Init->getBeginLoc(), false);
   if (Deduced.isNull())
 return DAR_FailedAlreadyDiagnosed;
Index: lib/Sema/SemaExprObjC.cpp
===
--- lib/Sema/SemaExprObjC.cpp
+++ lib/Sema/SemaExprObjC.cpp
@@ -3140,7 +3140,7 @@
   Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak;
 if (!IsWeak && Sel.isUnarySelector())
   IsWeak = ReturnType.getObjCLifetime() & Qualifiers::OCL_Weak;
-if (IsWeak &&
+if (IsWeak && !isUnevaluatedContext() &&
 !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, LBracLoc))
   getCurFunction()->recordUseOfWeak(Result, Prop);
   }
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -6539,6 +6539,11 @@
  ExpressionEvaluationContextRecord::EK_Decltype &&
  "not in a decltype expression");
 
+  ExprResult Result = CheckPlaceholderExpr(E);
+  if (Result.isInvalid())
+return ExprError();
+  E = Result.get();
+
   // C++11 [expr.call]p11:
   //   If a function call is a prvalue of object type,
   // -- if the function call is either
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14552,6 +14552,10 @@
 }
 
 ExprResult Sema::HandleExprEvaluationContextForTypeof(Expr *E) {
+  ExprResult Result = CheckPlaceholderExpr(E);
+  if (Result.isInvalid())
+return ExprError();
+  E = Result.get();
   if (!E->getType()->isVariablyModifiedType())
 return E;
   return TransformToPotentiallyEvaluated(E);


Index: test/SemaObjC/arc-repeated-weak.mm
===
--- test/SemaObjC/arc-repeated-weak.mm
+++ test/SemaObjC/arc-repeated-weak.mm
@@ -462,6 +462,9 @@
   NSString * t2 = NSBundle.foo2.prop;
   use(NSBundle.foo2.weakProp); // expected-warning{{weak property 'weakProp' may be accessed multiple times}}
   use(NSBundle2.foo2.weakProp); // expected-note{{also accessed here}}
+  decltype([NSBundle2.foo2 weakProp]) t3;
+  decltype(NSBundle2.foo2.weakProp) t4;
+  __typeof__(NSBundle2.foo2.weakProp) t5;
 }
 
 // This used to crash in the constructor of WeakOb

[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

2018-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

It works! :D

I guess, please commit this if you don't find anything better.




Comment at: test/Analysis/invalid-analyzer-config-value.c:72
+// even if -analyze isn't specified.
+// RUN: %clang --analyze -Xclang -analyzer-config -Xclang remember=TheVasa %s
+

Szelethus wrote:
> Szelethus wrote:
> > NoQ wrote:
> > > This run-line *does* have `-analyze` specified, because that's what 
> > > `--analyze` expands to. I guess the test that we need would be along the 
> > > lines of `clang -Xclang -analyzer-config ...` without `--analyze`.
> >  U sorry about that.
> I checked this against a completely different file, and it works.
Given that we stepped on this, i guess it's still worth it to rename the test 
file.


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

https://reviews.llvm.org/D55823



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


[PATCH] D55628: Add support for "labels" on push/pop directives in #pragma clang attribute

2018-12-19 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: clang/lib/Parse/ParsePragma.cpp:3161
+  if (!Tok.is(tok::period)) {
+PP.Diag(Tok.getLocation(), diag::err_pragma_attribute_expected_period)
+<< II;

aaron.ballman wrote:
> Can you reuse `diag::err_expected_after` instead of making a new diagnostic?
I was kinda concerned about how we would diagnose a case like this:
```
#pragma clang attribute add (...) // add isn't a thing!
```
A generic diagnostic about the missing `.` would be pretty unhelpful. The 
custom diagnostic reads as "expected '.' after pragma attribute namespace 
'add'", which makes how the parser interpreted the code a lot more clear.


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

https://reviews.llvm.org/D55628



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


[PATCH] D55628: Add support for "labels" on push/pop directives in #pragma clang attribute

2018-12-19 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 178952.
erik.pilkington marked 4 inline comments as done.
erik.pilkington added a comment.

Add Aaron's testcase, improve the documentation a bit.


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

https://reviews.llvm.org/D55628

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/test/Parser/pragma-attribute.cpp
  clang/test/Sema/pragma-attribute-namespace.c

Index: clang/test/Sema/pragma-attribute-namespace.c
===
--- /dev/null
+++ clang/test/Sema/pragma-attribute-namespace.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#pragma clang attribute MyNamespace.push (__attribute__((annotate)), apply_to=function) // expected-error 2 {{'annotate' attribute}}
+
+int some_func(); // expected-note{{when applied to this declaration}}
+
+#pragma clang attribute pop // expected-error{{'#pragma clang attribute pop' with no matching '#pragma clang attribute push'}}
+#pragma clang attribute NotMyNamespace.pop // expected-error{{'#pragma clang attribute NotMyNamespace.pop' with no matching '#pragma clang attribute NotMyNamespace.push'}}
+
+#pragma clang attribute MyOtherNamespace.push (__attribute__((annotate)), apply_to=function) // expected-error 2 {{'annotate' attribute}}
+
+int some_other_func(); // expected-note 2 {{when applied to this declaration}}
+
+// Out of order!
+#pragma clang attribute MyNamespace.pop
+
+int some_other_other_func(); // expected-note 1 {{when applied to this declaration}}
+
+#pragma clang attribute MyOtherNamespace.pop
+
+#pragma clang attribute Misc. () // expected-error{{namespace can only apply to 'push' or 'pop' directives}} expected-note {{omit the namespace to add attributes to the most-recently pushed attribute group}}
+
+#pragma clang attribute Misc push // expected-error{{expected '.' after pragma attribute namespace 'Misc'}}
+
+// Test how pushes with namespaces interact with pushes without namespaces.
+
+#pragma clang attribute Merp.push (__attribute__((annotate)), apply_to=function) // expected-error{{'annotate' attribute}}
+#pragma clang attribute push (__attribute__((annotate)), apply_to=function) // expected-warning {{unused attribute}}
+#pragma clang attribute pop // expected-note{{ends here}}
+int test(); // expected-note{{when applied to this declaration}}
+#pragma clang attribute Merp.pop
+
+#pragma clang attribute push (__attribute__((annotate)), apply_to=function) // expected-warning {{unused attribute}}
+#pragma clang attribute Merp.push (__attribute__((annotate)), apply_to=function) // expected-error{{'annotate' attribute}}
+#pragma clang attribute pop // expected-note{{ends here}}
+int test2(); // expected-note{{when applied to this declaration}}
+#pragma clang attribute Merp.pop
Index: clang/test/Parser/pragma-attribute.cpp
===
--- clang/test/Parser/pragma-attribute.cpp
+++ clang/test/Parser/pragma-attribute.cpp
@@ -102,7 +102,7 @@
 
 #pragma clang attribute // expected-error {{expected 'push', 'pop', or '(' after '#pragma clang attribute'}}
 #pragma clang attribute 42 // expected-error {{expected 'push', 'pop', or '(' after '#pragma clang attribute'}}
-#pragma clang attribute pushpop // expected-error {{unexpected argument 'pushpop' to '#pragma clang attribute'; expected 'push' or 'pop'}}
+#pragma clang attribute pushpop // expected-error {{expected '.' after pragma attribute namespace 'pushpop'}}
 
 #pragma clang attribute push
 #pragma clang attribute pop
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -631,28 +631,46 @@
   {PragmaLoc, &Attribute, std::move(SubjectMatchRules), /*IsUsed=*/false});
 }
 
-void Sema::ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc) {
+void Sema::ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc,
+ const IdentifierInfo *Namespace) {
   PragmaAttributeStack.emplace_back();
   PragmaAttributeStack.back().Loc = PragmaLoc;
+  PragmaAttributeStack.back().Namespace = Namespace;
 }
 
-void Sema::ActOnPragmaAttributePop(SourceLocation PragmaLoc) {
+void Sema::ActOnPragmaAttributePop(SourceLocation PragmaLoc,
+   const IdentifierInfo *Namespace) {
   if (PragmaAttributeStack.empty()) {
-Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch);
+Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
 return;
   }
 
-  for (const PragmaAttributeEntry &Entry :
-   PragmaAttributeStack.back().Entries) {
-if (!Entry.IsUsed) {
-  assert(Entry.Attribute && "Expected an attribute");
-  Diag(Entry.Attribut

[PATCH] D55895: NFC: simplify Darwin environment handling

2018-12-19 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

I think we might need to run it past the internal builds to see if anything 
breaks.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55895



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


[PATCH] D55873: [analyzer] CStringChecker: Fix a crash when an argument of a weird type is encountered.

2018-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/CStringChecker.cpp:2317-2320
   else if (isCPPStdLibraryFunction(FDecl, "copy"))
 evalFunction =  &CStringChecker::evalStdCopy;
   else if (isCPPStdLibraryFunction(FDecl, "copy_backward"))
 evalFunction =  &CStringChecker::evalStdCopyBackward;

Yes, indeed, this patch does [[ https://reviews.llvm.org/D55875#1336686 | break 
]] modeling of `std::copy`, because, well, we *did* have explicit modeling of 
`std::copy`.


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

https://reviews.llvm.org/D55873



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


Re: [PATCH] D55828: [clang] [Driver] Disable -faddrsig by default on NetBSD

2018-12-19 Thread Michał Górny via cfe-commits
On Wed, 2018-12-19 at 21:51 +0100, Joerg Sonnenberger wrote:
> On Tue, Dec 18, 2018 at 04:35:54PM +, Michał Górny via Phabricator via 
> cfe-commits wrote:
> > mgorny created this revision.
> > mgorny added reviewers: krytarowski, pcc.
> > 
> > Avoid passing -faddrsig by default on NetBSD.  This platform is still
> > using old GNU binutils that crashes on executables containing those
> > sections.
> 
> I find that a strange claim, given that many Linux distributions in the
> wild have much older GNU binutils.
> 

It only meant that newer versions don't crash, or so I have been told. 
Nothing more.

-- 
Best regards,
Michał Górny


signature.asc
Description: This is a digitally signed message part
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55890: [X86][SSE] Auto upgrade PADDS/PSUBS intrinsics to SADD_SAT/SSUB_SAT generic intrinsics (clang)

2018-12-19 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rL LLVM

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

https://reviews.llvm.org/D55890



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


[PATCH] D55890: [X86][SSE] Auto upgrade PADDS/PSUBS intrinsics to SADD_SAT/SSUB_SAT generic intrinsics (clang)

2018-12-19 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon updated this revision to Diff 178946.
RKSimon added a comment.

Use ArrayRef


Repository:
  rL LLVM

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

https://reviews.llvm.org/D55890

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/avx2-builtins.c
  test/CodeGen/avx512bw-builtins.c
  test/CodeGen/avx512vlbw-builtins.c
  test/CodeGen/sse2-builtins.c

Index: test/CodeGen/sse2-builtins.c
===
--- test/CodeGen/sse2-builtins.c
+++ test/CodeGen/sse2-builtins.c
@@ -47,13 +47,13 @@
 
 __m128i test_mm_adds_epi8(__m128i A, __m128i B) {
   // CHECK-LABEL: test_mm_adds_epi8
-  // CHECK: call <16 x i8> @llvm.x86.sse2.padds.b(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call <16 x i8> @llvm.sadd.sat.v16i8(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   return _mm_adds_epi8(A, B);
 }
 
 __m128i test_mm_adds_epi16(__m128i A, __m128i B) {
   // CHECK-LABEL: test_mm_adds_epi16
-  // CHECK: call <8 x i16> @llvm.x86.sse2.padds.w(<8 x i16> %{{.*}}, <8 x i16> %{{.*}})
+  // CHECK: call <8 x i16> @llvm.sadd.sat.v8i16(<8 x i16> %{{.*}}, <8 x i16> %{{.*}})
   return _mm_adds_epi16(A, B);
 }
 
@@ -1460,13 +1460,13 @@
 
 __m128i test_mm_subs_epi8(__m128i A, __m128i B) {
   // CHECK-LABEL: test_mm_subs_epi8
-  // CHECK: call <16 x i8> @llvm.x86.sse2.psubs.b(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call <16 x i8> @llvm.ssub.sat.v16i8(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   return _mm_subs_epi8(A, B);
 }
 
 __m128i test_mm_subs_epi16(__m128i A, __m128i B) {
   // CHECK-LABEL: test_mm_subs_epi16
-  // CHECK: call <8 x i16> @llvm.x86.sse2.psubs.w(<8 x i16> %{{.*}}, <8 x i16> %{{.*}})
+  // CHECK: call <8 x i16> @llvm.ssub.sat.v8i16(<8 x i16> %{{.*}}, <8 x i16> %{{.*}})
   return _mm_subs_epi16(A, B);
 }
 
Index: test/CodeGen/avx512vlbw-builtins.c
===
--- test/CodeGen/avx512vlbw-builtins.c
+++ test/CodeGen/avx512vlbw-builtins.c
@@ -1075,49 +1075,49 @@
 
 __m128i test_mm_mask_adds_epi8(__m128i __W, __mmask16 __U, __m128i __A, __m128i __B) {
   // CHECK-LABEL: @test_mm_mask_adds_epi8
-  // CHECK: @llvm.x86.sse2.padds.b
+  // CHECK: @llvm.sadd.sat.v16i8
   // CHECK: select <16 x i1> %{{.*}}, <16 x i8> %{{.*}}, <16 x i8> %{{.*}}
   return _mm_mask_adds_epi8(__W,__U,__A,__B); 
 }
 __m128i test_mm_maskz_adds_epi8(__mmask16 __U, __m128i __A, __m128i __B) {
   // CHECK-LABEL: @test_mm_maskz_adds_epi8
-  // CHECK: @llvm.x86.sse2.padds.b
+  // CHECK: @llvm.sadd.sat.v16i8
   // CHECK: select <16 x i1> %{{.*}}, <16 x i8> %{{.*}}, <16 x i8> %{{.*}}
   return _mm_maskz_adds_epi8(__U,__A,__B); 
 }
 __m256i test_mm256_mask_adds_epi8(__m256i __W, __mmask32 __U, __m256i __A, __m256i __B) {
   // CHECK-LABEL: @test_mm256_mask_adds_epi8
-  // CHECK: @llvm.x86.avx2.padds.b
+  // CHECK: @llvm.sadd.sat.v32i8
   // CHECK: select <32 x i1> %{{.*}}, <32 x i8> %{{.*}}, <32 x i8> %{{.*}}
   return _mm256_mask_adds_epi8(__W,__U,__A,__B); 
 }
 __m256i test_mm256_maskz_adds_epi8(__mmask32 __U, __m256i __A, __m256i __B) {
   // CHECK-LABEL: @test_mm256_maskz_adds_epi8
-  // CHECK: @llvm.x86.avx2.padds.b
+  // CHECK: @llvm.sadd.sat.v32i8
   // CHECK: select <32 x i1> %{{.*}}, <32 x i8> %{{.*}}, <32 x i8> %{{.*}}
   return _mm256_maskz_adds_epi8(__U,__A,__B); 
 }
 __m128i test_mm_mask_adds_epi16(__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) {
   // CHECK-LABEL: @test_mm_mask_adds_epi16
-  // CHECK: @llvm.x86.sse2.padds.w
+  // CHECK: @llvm.sadd.sat.v8i16
   // CHECK: select <8 x i1> %{{.*}}, <8 x i16> %{{.*}}, <8 x i16> %{{.*}}
   return _mm_mask_adds_epi16(__W,__U,__A,__B); 
 }
 __m128i test_mm_maskz_adds_epi16(__mmask8 __U, __m128i __A, __m128i __B) {
   // CHECK-LABEL: @test_mm_maskz_adds_epi16
-  // CHECK: @llvm.x86.sse2.padds.w
+  // CHECK: @llvm.sadd.sat.v8i16
   // CHECK: select <8 x i1> %{{.*}}, <8 x i16> %{{.*}}, <8 x i16> %{{.*}}
   return _mm_maskz_adds_epi16(__U,__A,__B); 
 }
 __m256i test_mm256_mask_adds_epi16(__m256i __W, __mmask16 __U, __m256i __A, __m256i __B) {
   // CHECK-LABEL: @test_mm256_mask_adds_epi16
-  // CHECK: @llvm.x86.avx2.padds.w
+  // CHECK: @llvm.sadd.sat.v16i16
   // CHECK: select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> %{{.*}}
   return _mm256_mask_adds_epi16(__W,__U,__A,__B); 
 }
 __m256i test_mm256_maskz_adds_epi16(__mmask16 __U, __m256i __A, __m256i __B) {
   // CHECK-LABEL: @test_mm256_maskz_adds_epi16
-  // CHECK: @llvm.x86.avx2.padds.w
+  // CHECK: @llvm.sadd.sat.v16i16
   // CHECK: select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> %{{.*}}
   return _mm256_maskz_adds_epi16(__U,__A,__B); 
 }
@@ -1527,49 +1527,49 @@
 }
 __m128i test_mm_mask_subs_epi8(__m128i __W, __mmask16 __U, __m128i __A, __m128i __B) {
   // CHECK-LABEL: @test_mm_mask_subs_epi8
-  // CHECK: @llvm.x86.sse2.psubs.b
+  // CHECK: @llvm.ssub.sat.v16i8
   // CHECK: select <16 x i1> %{{.*}}, <16 x i8> %{{.*}}, <16 x i8> %{{.*}}
   return _mm_mask_subs_epi8(__W,__U,__A,__B); 
 }
 __m128i 

Re: [PATCH] D55828: [clang] [Driver] Disable -faddrsig by default on NetBSD

2018-12-19 Thread Joerg Sonnenberger via cfe-commits
On Tue, Dec 18, 2018 at 04:35:54PM +, Michał Górny via Phabricator via 
cfe-commits wrote:
> mgorny created this revision.
> mgorny added reviewers: krytarowski, pcc.
> 
> Avoid passing -faddrsig by default on NetBSD.  This platform is still
> using old GNU binutils that crashes on executables containing those
> sections.

I find that a strange claim, given that many Linux distributions in the
wild have much older GNU binutils.

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


[PATCH] D55865: [ObjC] Add a new attribute to opt-out of implicit callee retain/release in ARC

2018-12-19 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3492
+def warn_ignored_objc_externally_retained : Warning<
+  "'objc_externally_retained' can only be applied to strong retainable "
+  "object pointer types with automatic storage">, InGroup;

erik.pilkington wrote:
> aaron.ballman wrote:
> > This wording isn't quite right -- it doesn't apply to types, it applies to 
> > variables of those types. How about: `... to local variables or parameters 
> > of strong, retainable object pointer type`? or something along those lines?
> Sure, that is a bit more clear.
I'd split this into two diagnostics:
- "...can only be applied to local variables and parameters of retainable type" 
(if the type or decl kind is wrong)
- "...can only be applied to variables with strong ownership" (if the qualifier 
is wrong)



Comment at: clang/lib/CodeGen/CGDecl.cpp:806
+// If D is pseudo-strong, omit the retain.
+LLVM_FALLTHROUGH;
+  }

`EmitARCUnsafeUnretainedScalarExpr` doesn't just not retain the value, it 
actually triggers different handling, e.g. causing non-autoreleased return 
values to be immediately released.  Now I think we arguably want that behavior 
here, but you should be explicit about it in the comment.



Comment at: clang/lib/CodeGen/CGDecl.cpp:2340
+}
   }
 

Most of this code is there to support an assertion that's no longer true.  Just 
keep the parts about `lt == OCL_Strong` and `qs.hasConst()`.



Comment at: clang/lib/CodeGen/CGExpr.cpp:1946
+if (isInit && isPseudoStrong)
+  Lifetime = Qualifiers::OCL_ExplicitNone;
+

Where are we allowing assignments into pseudo-strong variables?


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

https://reviews.llvm.org/D55865



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


[PATCH] D55865: [ObjC] Add a new attribute to opt-out of implicit callee retain/release in ARC

2018-12-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6117
+  // to ensure that the variable is 'const' so that we can error on
+  // modification, which can otherwise overrelease.
+  VD->setType(Ty.withConst());

erik.pilkington wrote:
> aaron.ballman wrote:
> > overrelease -> over-release
> > 
> > Btw, this isn't a bit of a hack, it's a huge hack, IMO. Instead, can we 
> > simply err if the user hasn't specified `const` explicitly? I'm not a fan 
> > of "we're hiding this rather important language detail behind an attribute 
> > that can be ignored". This is especially worrisome because it means the 
> > variable is const only when ARC is enabled, which seems like surprising 
> > behavioral differences for that compiler flag.
> An important part of this feature is that it could applied to parameters with 
> `#pragma clang attribute` over code that has been audited to be safe. If we 
> require adding `const` to every parameter, then that falls apart :/. 
> 
> For better or for worse, this is also consistent with other cases of 
> pseudo-strong in the language, i.e.:
> ```
> void f(NSArray *A) {
>   for (id Elem in A)
> Elem = nil; // fine in -fno-objc-arc, error in -fobjc-arc because Elem is 
> implicitly const.
> }
> ```
> An important part of this feature is that it could applied to parameters with 
> #pragma clang attribute over code that has been audited to be safe. If we 
> require adding const to every parameter, then that falls apart :/.

Thanks for letting me know about that use case; it adds some helpful context. 
However, I don't see why this falls apart -- if you're auditing the code, you 
could add the `const` qualifiers at that time, couldn't you? 

Alternatively, if we warned instead of erred on the absence of `const`, then 
this could be automated through clang-tidy by checking declarations that are 
marked with the attribute but are not marked `const` and use the fix-it 
machinery to update the code.

> For better or for worse, this is also consistent with other cases of 
> pseudo-strong in the language,

Yes, but it's weird behavior for an attribute. The attribute is applied to the 
*declaration* but then it silently modifies the *type* as well, but only for 
that one declaration (which is at odds with the usual rules for double-square 
bracket attributes and what they appertain to based on syntactic location). 
Sometimes, this will lead to good behavior (such as semantic checks and when 
doing AST matching over const-qualified types) and sometimes it will lead to 
confusing behavior (pretty-printing the code is going to stick const qualifers 
where none are written, diagnostics will talk about const qualifiers that 
aren't written in the source, etc).

Also, doesn't this cause ABI issues? If you write the attribute on a parameter, 
the presence or absence of that attribute is now part of the ABI for the 
function call because the parameter type will be mangled as being 
const-qualified. (Perhaps that's more of a feature than a bug -- I imagine you 
want both sides of the ABI to agree whether ARC is enabled or not?)

I'm wondering if this is weird enough that it should be using a keyword 
spelling instead of an attribute spelling? However, I'm not certain if that 
works with `#pragma clang attribute`.


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

https://reviews.llvm.org/D55865



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


[PATCH] D52117: Generate llvm.loop.parallel_accesses instead of llvm.mem.parallel_loop_access metadata.

2018-12-19 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur updated this revision to Diff 178944.
Meinersbur added a comment.

- Fix typo


Repository:
  rC Clang

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

https://reviews.llvm.org/D52117

Files:
  lib/CodeGen/CGLoopInfo.cpp
  lib/CodeGen/CGLoopInfo.h
  test/CodeGenCXX/pragma-loop-safety-imperfectly_nested.cpp
  test/CodeGenCXX/pragma-loop-safety-nested.cpp
  test/CodeGenCXX/pragma-loop-safety-outer.cpp
  test/CodeGenCXX/pragma-loop-safety.cpp
  test/OpenMP/for_codegen.cpp
  test/OpenMP/for_simd_codegen.cpp
  test/OpenMP/loops_explicit_clauses_codegen.cpp
  test/OpenMP/ordered_codegen.cpp
  test/OpenMP/parallel_for_simd_codegen.cpp
  test/OpenMP/schedule_codegen.cpp
  test/OpenMP/simd_codegen.cpp
  test/OpenMP/simd_metadata.c
  test/OpenMP/target_parallel_for_simd_codegen.cpp
  test/OpenMP/target_simd_codegen.cpp
  test/OpenMP/taskloop_simd_codegen.cpp

Index: test/OpenMP/taskloop_simd_codegen.cpp
===
--- test/OpenMP/taskloop_simd_codegen.cpp
+++ test/OpenMP/taskloop_simd_codegen.cpp
@@ -83,17 +83,17 @@
 // CHECK: [[LB_I32:%.+]] = trunc i64 [[LB_VAL]] to i32
 // CHECK: store i32 [[LB_I32]], i32* [[CNT:%.+]],
 // CHECK: br label
-// CHECK: [[VAL:%.+]] = load i32, i32* [[CNT]],{{.*}}!llvm.mem.parallel_loop_access [[LOOP1:!.+]]
+// CHECK: [[VAL:%.+]] = load i32, i32* [[CNT]],{{.*}}!llvm.access.group
 // CHECK: [[VAL_I64:%.+]] = sext i32 [[VAL]] to i64
-// CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],{{.*}}!llvm.mem.parallel_loop_access [[LOOP1]]
+// CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],{{.*}}!llvm.access.group
 // CHECK: [[CMP:%.+]] = icmp ule i64 [[VAL_I64]], [[UB_VAL]]
 // CHECK: br i1 [[CMP]], label %{{.+}}, label %{{.+}}
-// CHECK: load i32, i32* %{{.*}}!llvm.mem.parallel_loop_access [[LOOP1]]
-// CHECK: store i32 %{{.*}}!llvm.mem.parallel_loop_access [[LOOP1]]
-// CHECK: load i32, i32* %{{.*}}!llvm.mem.parallel_loop_access [[LOOP1]]
+// CHECK: load i32, i32* %{{.*}}!llvm.access.group
+// CHECK: store i32 %{{.*}}!llvm.access.group
+// CHECK: load i32, i32* %{{.*}}!llvm.access.group
 // CHECK: add nsw i32 %{{.+}}, 1
-// CHECK: store i32 %{{.+}}, i32* %{{.*}}!llvm.mem.parallel_loop_access [[LOOP1]]
-// CHECK: br label %{{.*}}!llvm.loop [[LOOP1]]
+// CHECK: store i32 %{{.+}}, i32* %{{.*}}!llvm.access.group
+// CHECK: br label %{{.*}}!llvm.loop
 // CHECK: ret i32 0
 
 // CHECK: define internal i32 [[TASK2]](
@@ -113,17 +113,17 @@
 // CHECK: [[LB_I32:%.+]] = trunc i64 [[LB_VAL]] to i32
 // CHECK: store i32 [[LB_I32]], i32* [[CNT:%.+]],
 // CHECK: br label
-// CHECK: [[VAL:%.+]] = load i32, i32* [[CNT]],{{.*}}!llvm.mem.parallel_loop_access [[LOOP2:!.+]]
+// CHECK: [[VAL:%.+]] = load i32, i32* [[CNT]],{{.*}}!llvm.access.group
 // CHECK: [[VAL_I64:%.+]] = sext i32 [[VAL]] to i64
-// CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],{{.*}}!llvm.mem.parallel_loop_access [[LOOP2]]
+// CHECK: [[UB_VAL:%.+]] = load i64, i64* [[UB]],{{.*}}!llvm.access.group
 // CHECK: [[CMP:%.+]] = icmp ule i64 [[VAL_I64]], [[UB_VAL]]
 // CHECK: br i1 [[CMP]], label %{{.+}}, label %{{.+}}
-// CHECK: load i32, i32* %{{.*}}!llvm.mem.parallel_loop_access [[LOOP2]]
-// CHECK: store i32 %{{.*}}!llvm.mem.parallel_loop_access [[LOOP2]]
-// CHECK: load i32, i32* %{{.*}}!llvm.mem.parallel_loop_access [[LOOP2]]
+// CHECK: load i32, i32* %{{.*}}!llvm.access.group
+// CHECK: store i32 %{{.*}}!llvm.access.group
+// CHECK: load i32, i32* %{{.*}}!llvm.access.group
 // CHECK: add nsw i32 %{{.+}}, 1
-// CHECK: store i32 %{{.+}}, i32* %{{.*}}!llvm.mem.parallel_loop_access [[LOOP2]]
-// CHECK: br label %{{.*}}!llvm.loop [[LOOP2]]
+// CHECK: store i32 %{{.+}}, i32* %{{.*}}!llvm.access.group
+// CHECK: br label %{{.*}}!llvm.loop
 // CHECK: ret i32 0
 
 // CHECK: define internal i32 [[TASK3]](
@@ -142,7 +142,7 @@
 // CHECK: [[LB_VAL:%.+]] = load i64, i64* [[LB]],
 // CHECK: store i64 [[LB_VAL]], i64* [[CNT:%.+]],
 // CHECK: br label
-// CHECK-NOT: !llvm.mem.parallel_loop_access
+// CHECK-NOT: !llvm.access.group
 // CHECK: br label %{{.*}}!llvm.loop
 // CHECK: ret i32 0
 
@@ -192,14 +192,14 @@
 // CHECK: [[CMP:%.+]] = icmp ule i64 [[VAL_I64]], [[UB_VAL]]
 // CHECK: br i1 [[CMP]], label %{{.+}}, label %{{.+}}
 // CHECK: load i32, i32* %
-// CHECK-NOT: !llvm.mem.parallel_loop_access
+// CHECK-NOT: !llvm.access.group
 // CHECK: store i32 %
-// CHECK-NOT: !llvm.mem.parallel_loop_access
+// CHECK-NOT: !llvm.access.group
 // CHECK: load i32, i32* %
-// CHECK-NOT: !llvm.mem.parallel_loop_access
+// CHECK-NOT: !llvm.access.group
 // CHECK: add nsw i32 %{{.+}}, 1
 // CHECK: store i32 %{{.+}}, i32* %
-// CHECK-NOT: !llvm.mem.parallel_loop_access
+// CHECK-NOT: !llvm.access.group
 // CHECK: br label %{{.*}}!llvm.loop
 // CHECK: ret i32 0
 
Index: test/OpenMP/target_simd_codegen.cpp
===
--- test/OpenMP/target_simd_codegen.cpp
+++ test/OpenMP/target_simd_codegen.cpp
@@ -342,7 +342,7 @@
 // CHECK-64:[[AA_CADDR:%

[PATCH] D55847: [gn build] Add build file for clang/lib/Basic and dependencies

2018-12-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349677: [gn build] Add build file for clang/lib/Basic and 
dependencies (authored by nico, committed by ).
Herald added subscribers: llvm-commits, delcypher, mgorny.

Changed prior to commit:
  https://reviews.llvm.org/D55847?vs=178753&id=178942#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55847

Files:
  llvm/trunk/tools/llvm-ar/CMakeLists.txt
  llvm/trunk/tools/llvm-bcanalyzer/CMakeLists.txt
  llvm/trunk/tools/llvm-demangle-fuzzer/llvm-demangle-fuzzer.cpp
  llvm/trunk/utils/gn/secondary/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/include/clang/Basic/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/lib/ARCMigrate/enable.gni
  llvm/trunk/utils/gn/secondary/clang/lib/Basic/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/lib/StaticAnalyzer/Frontend/enable.gni
  llvm/trunk/utils/gn/secondary/clang/utils/TableGen/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang/utils/TableGen/clang_tablegen.gni
  llvm/trunk/utils/gn/secondary/lld/include/lld/Common/BUILD.gn
  llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni
  llvm/trunk/utils/lit/lit/TestRunner.py
  llvm/trunk/utils/lit/lit/run.py

Index: llvm/trunk/tools/llvm-ar/CMakeLists.txt
===
--- llvm/trunk/tools/llvm-ar/CMakeLists.txt
+++ llvm/trunk/tools/llvm-ar/CMakeLists.txt
@@ -10,9 +10,6 @@
 
 add_llvm_tool(llvm-ar
   llvm-ar.cpp
-
-  DEPENDS
-  intrinsics_gen
   )
 
 add_llvm_tool_symlink(llvm-ranlib llvm-ar)
Index: llvm/trunk/tools/llvm-demangle-fuzzer/llvm-demangle-fuzzer.cpp
===
--- llvm/trunk/tools/llvm-demangle-fuzzer/llvm-demangle-fuzzer.cpp
+++ llvm/trunk/tools/llvm-demangle-fuzzer/llvm-demangle-fuzzer.cpp
@@ -14,11 +14,19 @@
 #include 
 
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
-  std::string NullTerminatedString((const char *)Data, Size);
-  int status = 0;
-  if (char *demangle = llvm::itaniumDemangle(NullTerminatedString.c_str(), nullptr,
- nullptr, &status))
-free(demangle);
+  if (Size == 0)
+return 0;
+
+  bool UseItanium = Data[0] < 128;
+  std::string NullTerminatedString((const char *)Data + 1, Size - 1);
+
+  if (UseItanium) {
+free(llvm::itaniumDemangle(NullTerminatedString.c_str(), nullptr, nullptr,
+   nullptr));
+  } else {
+free(llvm::microsoftDemangle(NullTerminatedString.c_str(), nullptr, nullptr,
+ nullptr));
+  }
 
   return 0;
 }
Index: llvm/trunk/tools/llvm-bcanalyzer/CMakeLists.txt
===
--- llvm/trunk/tools/llvm-bcanalyzer/CMakeLists.txt
+++ llvm/trunk/tools/llvm-bcanalyzer/CMakeLists.txt
@@ -5,7 +5,4 @@
 
 add_llvm_tool(llvm-bcanalyzer
   llvm-bcanalyzer.cpp
-
-  DEPENDS
-  intrinsics_gen
   )
Index: llvm/trunk/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
@@ -0,0 +1,84 @@
+import("//clang/lib/ARCMigrate/enable.gni")
+import("//clang/lib/StaticAnalyzer/Frontend/enable.gni")
+import("//llvm/utils/gn/build/libs/xml/enable.gni")
+import("//llvm/version.gni")
+
+config("Config_config") {
+  visibility = [ ":Config" ]
+  include_dirs = [ "$target_gen_dir/clang/include" ]
+}
+
+action("Config") {
+  script = "//llvm/utils/gn/build/write_cmake_config.py"
+
+  sources = [
+"config.h.cmake",
+  ]
+  outputs = [
+"$target_gen_dir/config.h",
+  ]
+  args = [
+"-o",
+rebase_path(outputs[0], root_out_dir),
+rebase_path(sources[0], root_out_dir),
+
+"BUG_REPORT_URL=https://bugs.llvm.org/";,
+"CLANG_DEFAULT_LINKER=",
+"CLANG_DEFAULT_STD_C=",
+"CLANG_DEFAULT_STD_CXX=",
+"CLANG_DEFAULT_CXX_STDLIB=",
+"CLANG_DEFAULT_RTLIB=",
+"CLANG_DEFAULT_OBJCOPY=objcopy",
+"CLANG_DEFAULT_OPENMP_RUNTIME=libomp",
+"CLANG_OPENMP_NVPTX_DEFAULT_ARCH=sm_35",
+"CLANG_LIBDIR_SUFFIX=",
+"CLANG_RESOURCE_DIR=",
+"C_INCLUDE_DIRS=",
+"CLANG_CONFIG_FILE_SYSTEM_DIR=",
+"CLANG_CONFIG_FILE_USER_DIR=",
+"DEFAULT_SYSROOT=",
+"GCC_INSTALL_PREFIX=",
+"CLANG_ANALYZER_WITH_Z3=",
+"BACKEND_PACKAGE_STRING=LLVM ${llvm_version}svn",
+"ENABLE_LINKER_BUILD_ID=",
+"ENABLE_X86_RELAX_RELOCATIONS=",
+"ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER=",
+"CLANG_ENABLE_OBJC_REWRITER=1",  # FIXME: flag?
+  ]
+
+  if (clang_enable_arcmt) {
+args += [ "CLANG_ENABLE_ARCMT=1" ]
+  } else {
+args += [ "CLANG_ENABLE_ARCMT=" ]
+  }
+
+  if (clang_enable_static_analyzer) {
+args += [ "CLANG_ENABLE_STATIC_ANALYZE

[PATCH] D55875: [analyzer] pr38668: RegionStore: Do not attempt to cast loaded values of non-scalar types.

2018-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ marked an inline comment as done.
NoQ added inline comments.



Comment at: test/Analysis/bstring.cpp:47
 
+  // The TRUE warning shows up on the path on which the vector is empty.
   clang_analyzer_eval(i == 66); // expected-warning {{UNKNOWN}}

dcoughlin wrote:
> This seems like it will be a big analysis policy change from the user's 
> perspective and is likely to generate a bunch of new reports.
> 
> Can the user add an assertion that v.size() > 0 to tell the analyzer that the 
> path on which the vector is empty is not feasible?
> 
> What are the diagnostic notes look like? Can the user tell that the the 
> analyzer is assuming that begin() == end() on that path?
> 
Ugh! This change is actually due to D55873, i just didn't run the tests 
properly. Will re-think  :o


Repository:
  rC Clang

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

https://reviews.llvm.org/D55875



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


[PATCH] D55878: [Driver] Use --hash-style=gnu instead of both on FreeBSD

2018-12-19 Thread Simon Dardis via Phabricator via cfe-commits
sdardis added a comment.

> I can't find rationale behind the MIPS discrepancy in the original commit. I 
> can add the if branch back if you tell me why...

From my recollections, the gnu-hash style isn't supported in ld.bfd for MIPS. A 
patch was posted to the binutils list 
(https://sourceware.org/ml/binutils/2015-10/msg00057.html) to support this, but 
there was an issue with FSF copyright assignment. As the patch is non-trivial, 
it would have to be independently re-developed for submission to binutils and 
later lld.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55878



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


[PATCH] D48753: [libcxx] Use custom allocator's `construct` in C++03 when available.

2018-12-19 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349676: [libcxx] Use custom allocator's `construct` in 
C++03 when available. (authored by vsapsai, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48753?vs=177803&id=178939#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D48753

Files:
  libcxx/trunk/include/memory
  
libcxx/trunk/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
  
libcxx/trunk/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
  
libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp
  libcxx/trunk/test/support/min_allocator.h

Index: libcxx/trunk/test/support/min_allocator.h
===
--- libcxx/trunk/test/support/min_allocator.h
+++ libcxx/trunk/test/support/min_allocator.h
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "test_macros.h"
 
@@ -131,6 +132,59 @@
 friend bool operator!=(malloc_allocator x, malloc_allocator y) {return !(x == y);}
 };
 
+template 
+struct cpp03_allocator : bare_allocator
+{
+typedef T value_type;
+typedef value_type* pointer;
+
+static bool construct_called;
+
+// Returned value is not used but it's not prohibited.
+pointer construct(pointer p, const value_type& val)
+{
+::new(p) value_type(val);
+construct_called = true;
+return p;
+}
+
+std::size_t max_size() const
+{
+return UINT_MAX / sizeof(T);
+}
+};
+template  bool cpp03_allocator::construct_called = false;
+
+template 
+struct cpp03_overload_allocator : bare_allocator
+{
+typedef T value_type;
+typedef value_type* pointer;
+
+static bool construct_called;
+
+void construct(pointer p, const value_type& val)
+{
+construct(p, val, std::is_class());
+}
+void construct(pointer p, const value_type& val, std::true_type)
+{
+::new(p) value_type(val);
+construct_called = true;
+}
+void construct(pointer p, const value_type& val, std::false_type)
+{
+::new(p) value_type(val);
+construct_called = true;
+}
+
+std::size_t max_size() const
+{
+return UINT_MAX / sizeof(T);
+}
+};
+template  bool cpp03_overload_allocator::construct_called = false;
+
 
 #if TEST_STD_VER >= 11
 
Index: libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp
===
--- libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp
+++ libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp
@@ -73,7 +73,7 @@
   std::aligned_storage::type store;
   std::allocator_traits::destroy(a, (VT*)&store);
 }
-#if TEST_STD_VER >= 11
+#if defined(_LIBCPP_VERSION) || TEST_STD_VER >= 11
 {
 A0::count = 0;
 b_destroy = 0;
Index: libcxx/trunk/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
===
--- libcxx/trunk/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
+++ libcxx/trunk/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
@@ -0,0 +1,54 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  vector(InputIter first, InputIter last);
+
+#include 
+#include 
+
+#include "min_allocator.h"
+
+void test_ctor_under_alloc() {
+  int arr1[] = {42};
+  int arr2[] = {1, 101, 42};
+  {
+typedef std::vector > C;
+typedef C::allocator_type Alloc;
+{
+  Alloc::construct_called = false;
+  C v(arr1, arr1 + 1);
+  assert(Alloc::construct_called);
+}
+{
+  Alloc::construct_called = false;
+  C v(arr2, arr2 + 3);
+  assert(Alloc::construct_called);
+}
+  }
+  {
+typedef std::vector > C;
+typedef C::allocator_type Alloc;
+{
+  Alloc::construct_called = false;
+  C v(arr1, arr1 + 1);
+  assert(Alloc::construct_called);
+}
+{
+  Alloc::construct_called = false;
+  C v(arr2, arr2 + 3);
+  assert(Alloc::construct_called);
+}
+  }
+}
+
+int main() {
+  test_ctor_under_alloc();
+}
Index: libcxx/trunk/test/libcxx/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
==

[PATCH] D55873: [analyzer] CStringChecker: Fix a crash when an argument of a weird type is encountered.

2018-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 178938.
NoQ marked an inline comment as done.
NoQ added a comment.

Indeed :)


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

https://reviews.llvm.org/D55873

Files:
  lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  test/Analysis/string.cpp


Index: test/Analysis/string.cpp
===
--- /dev/null
+++ test/Analysis/string.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -verify %s
+
+// expected-no-diagnostics
+
+// Test functions that are called "memcpy" but aren't the memcpy
+// we're looking for. Unfortunately, this test cannot be put into
+// a namespace. The out-of-class weird memcpy needs to be recognized
+// as a normal C function for the test to make sense.
+typedef __typeof(sizeof(int)) size_t;
+void *memcpy(void *, const void *, size_t);
+
+struct S {
+  static S s1, s2;
+
+  // A weird overload within the class that accepts a structure reference
+  // instead of a pointer.
+  void memcpy(void *, const S &, size_t);
+  void test_in_class_weird_memcpy() {
+memcpy(this, s2, 1); // no-crash
+  }
+};
+
+// A similarly weird overload outside of the class.
+void *memcpy(void *, const S &, size_t);
+
+void test_out_of_class_weird_memcpy() {
+  memcpy(&S::s1, S::s2, 1); // no-crash
+}
Index: lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -188,7 +188,7 @@
 const Expr *Buf,
 const char *message = nullptr,
 bool WarnAboutSize = false) const {
-// This is a convenience override.
+// This is a convenience overload.
 return CheckBufferAccess(C, state, Size, Buf, nullptr, message, nullptr,
  WarnAboutSize);
   }
@@ -2255,11 +2255,20 @@
 
//===--===//
 
 bool CStringChecker::evalCall(const CallExpr *CE, CheckerContext &C) const {
-  const FunctionDecl *FDecl = C.getCalleeDecl(CE);
 
+  const FunctionDecl *FDecl = C.getCalleeDecl(CE);
   if (!FDecl)
 return false;
 
+  // Pro-actively check that argument types are safe to do arithmetic upon.
+  // We do not want to crash if someone accidentally passes a structure
+  // into, say, a C++ overload of any of these functions.
+  for (auto I: CE->arguments()) {
+QualType T = I->getType();
+if (!T->isIntegralOrEnumerationType() && !T->isPointerType())
+  return false;
+  }
+
   // FIXME: Poorly-factored string switches are slow.
   FnCheck evalFunction = nullptr;
   if (C.isCLibraryFunction(FDecl, "memcpy"))


Index: test/Analysis/string.cpp
===
--- /dev/null
+++ test/Analysis/string.cpp
@@ -0,0 +1,28 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -verify %s
+
+// expected-no-diagnostics
+
+// Test functions that are called "memcpy" but aren't the memcpy
+// we're looking for. Unfortunately, this test cannot be put into
+// a namespace. The out-of-class weird memcpy needs to be recognized
+// as a normal C function for the test to make sense.
+typedef __typeof(sizeof(int)) size_t;
+void *memcpy(void *, const void *, size_t);
+
+struct S {
+  static S s1, s2;
+
+  // A weird overload within the class that accepts a structure reference
+  // instead of a pointer.
+  void memcpy(void *, const S &, size_t);
+  void test_in_class_weird_memcpy() {
+memcpy(this, s2, 1); // no-crash
+  }
+};
+
+// A similarly weird overload outside of the class.
+void *memcpy(void *, const S &, size_t);
+
+void test_out_of_class_weird_memcpy() {
+  memcpy(&S::s1, S::s2, 1); // no-crash
+}
Index: lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -188,7 +188,7 @@
 const Expr *Buf,
 const char *message = nullptr,
 bool WarnAboutSize = false) const {
-// This is a convenience override.
+// This is a convenience overload.
 return CheckBufferAccess(C, state, Size, Buf, nullptr, message, nullptr,
  WarnAboutSize);
   }
@@ -2255,11 +2255,20 @@
 //===--===//
 
 bool CStringChecker::evalCall(const CallExpr *CE, CheckerContext &C) const {
-  const FunctionDecl *FDecl = C.getCalleeDecl(CE);
 
+  const FunctionDecl *FDecl = C.getCalleeDecl(CE);
   if (!FDecl)
 return false;
 
+  // Pro-actively check that argument types are safe to do arithmetic upon.
+  // We do not want to crash if

[PATCH] D55804: [analyzer] C++17: Fix leak false positives when an object with destructor is returned from the top frame.

2018-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp:224
+bool IsArray = false;
+V = makeZeroElementRegion(State, V, ReturnTy, IsArray);
+assert(!IsArray && "Returning array from a function!");

dcoughlin wrote:
> I don't understand why you are using makeZeroElementRegion() here. Doesn't 
> the assertion of !IsArray mean it must just return 'V'?
Hmm. Right. I mis-remembered that it's also modeling a cast.


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

https://reviews.llvm.org/D55804



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


[PATCH] D55804: [analyzer] C++17: Fix leak false positives when an object with destructor is returned from the top frame.

2018-12-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 178936.
NoQ marked 2 inline comments as done.
NoQ added a comment.

Fxd!


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

https://reviews.llvm.org/D55804

Files:
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/temporaries.cpp

Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -1,9 +1,25 @@
-// RUN: %clang_analyze_cc1 -Wno-non-pod-varargs -analyzer-checker=core,cplusplus,debug.ExprInspection -analyzer-config cfg-temporary-dtors=false -verify -w -std=c++03 -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -Wno-non-pod-varargs -analyzer-checker=core,cplusplus,debug.ExprInspection -analyzer-config cfg-temporary-dtors=false -verify -w -std=c++11 -analyzer-config eagerly-assume=false %s
-// RUN: %clang_analyze_cc1 -Wno-non-pod-varargs -analyzer-checker=core,cplusplus,debug.ExprInspection -DTEMPORARY_DTORS -verify -w -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true -analyzer-config eagerly-assume=false %s -std=c++11
-// RUN: %clang_analyze_cc1 -Wno-non-pod-varargs -analyzer-checker=core,cplusplus,debug.ExprInspection -DTEMPORARY_DTORS -w -analyzer-config cfg-temporary-dtors=true,c++-temp-dtor-inlining=true -analyzer-config eagerly-assume=false %s -std=c++17
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,cplusplus\
+// RUN: -analyzer-checker debug.ExprInspection -Wno-non-pod-varargs\
+// RUN: -analyzer-config eagerly-assume=false -verify %s\
+// RUN: -std=c++03 -analyzer-config cfg-temporary-dtors=false
+
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,cplusplus\
+// RUN: -analyzer-checker debug.ExprInspection -Wno-non-pod-varargs\
+// RUN: -analyzer-config eagerly-assume=false -verify %s\
+// RUN: -std=c++11 -analyzer-config cfg-temporary-dtors=false
+
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,cplusplus\
+// RUN: -analyzer-checker debug.ExprInspection -Wno-non-pod-varargs\
+// RUN: -analyzer-config eagerly-assume=false -verify %s\
+// RUN: -std=c++11 -analyzer-config cfg-temporary-dtors=true\
+// RUN: -DTEMPORARY_DTORS
+
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,cplusplus\
+// RUN: -analyzer-checker debug.ExprInspection -Wno-non-pod-varargs\
+// RUN: -analyzer-config eagerly-assume=false -verify %s\
+// RUN: -std=c++17 -analyzer-config cfg-temporary-dtors=true\
+// RUN: -DTEMPORARY_DTORS
 
-// Note: The C++17 run-line doesn't -verify yet - it is a no-crash test.
 
 extern bool clang_analyzer_eval(bool);
 extern bool clang_analyzer_warnIfReached();
@@ -450,7 +466,16 @@
   }
 
 #if __cplusplus >= 201103L
-  CtorWithNoReturnDtor returnNoReturnDtor() {
+  struct CtorWithNoReturnDtor2 {
+CtorWithNoReturnDtor2() = default;
+
+CtorWithNoReturnDtor2(int x) {
+  clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
+}
+
+~CtorWithNoReturnDtor2() __attribute__((noreturn));
+  };
+  CtorWithNoReturnDtor2 returnNoReturnDtor() {
 return {1}; // no-crash
   }
 #endif
@@ -805,7 +830,12 @@
   // On each branch the variable is constructed directly.
   if (coin) {
 clang_analyzer_eval(x == 1); // expected-warning{{TRUE}}
+#if __cplusplus < 201703L
 clang_analyzer_eval(y == 1); // expected-warning{{TRUE}}
+#else
+// FIXME: Destructor called twice in C++17?
+clang_analyzer_eval(y == 2); // expected-warning{{TRUE}}
+#endif
 clang_analyzer_eval(z == 0); // expected-warning{{TRUE}}
 clang_analyzer_eval(w == 0); // expected-warning{{TRUE}}
 
@@ -813,7 +843,12 @@
 clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
 clang_analyzer_eval(y == 0); // expected-warning{{TRUE}}
 clang_analyzer_eval(z == 1); // expected-warning{{TRUE}}
+#if __cplusplus < 201703L
 clang_analyzer_eval(w == 1); // expected-warning{{TRUE}}
+#else
+// FIXME: Destructor called twice in C++17?
+clang_analyzer_eval(w == 2); // expected-warning{{TRUE}}
+#endif
   }
 }
 } // namespace test_match_constructors_and_destructors
@@ -865,9 +900,12 @@
 public:
   ~C() {
 glob = 1;
+// FIXME: Why is destructor not inlined in C++17
 clang_analyzer_checkInlined(true);
 #ifdef TEMPORARY_DTORS
-// expected-warning@-2{{TRUE}}
+#if __cplusplus < 201703L
+// expected-warning@-3{{TRUE}}
+#endif
 #endif
   }
 };
@@ -886,11 +924,16 @@
   // temporaries returned from functions, so we took the wrong branch.
   coin && is(get()); // no-crash
   if (coin) {
+// FIXME: Why is destructor not inlined in C++17
 clang_analyzer_eval(glob);
 #ifdef TEMPORARY_DTORS
-// expected-warning@-2{{TRUE}}
+#if __cplusplus < 201703L
+// expected-warning@-3{{TRUE}}
+#else
+// expected-warning@-5{{UNKNOWN}}
+#endif
 #else
-// expected-warning@-4{{UNKNOWN}}
+// expected-warning@-8{{UNKNOWN}}
 #endif
   } else {
 // The destructor is not called on this branch.

[PATCH] D55862: [Sema] Don't try to account for the size of an incomplete type in CheckArrayAccess

2018-12-19 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: lib/Sema/SemaChecking.cpp:12357
+  Context.getAsConstantArrayType(BaseExpr->getType());
+  const Type *BaseType = BaseExpr->getType()->getPointeeOrArrayElementType();
+

Using getPointeeOrArrayElementType here is kind of confusing; instead, we can 
just call `ArrayTy->getElementType()`.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55862



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


[PATCH] D55543: [CodeGen] Fix assertion on throwing object with inlined inherited constructor and non-trivial destructor.

2018-12-19 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Thanks, LGTM.  Somewhat surprised that we don't have an implicit copy of the 
`Strong` argument, but it's not a bad thing that we don't.


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

https://reviews.llvm.org/D55543



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


r349669 - PR40096: Forwards-compatible with C++20 rule regarding aggregates not having user-declared ctors

2018-12-19 Thread David Blaikie via cfe-commits
Author: dblaikie
Date: Wed Dec 19 11:33:35 2018
New Revision: 349669

URL: http://llvm.org/viewvc/llvm-project?rev=349669&view=rev
Log:
PR40096: Forwards-compatible with C++20 rule regarding aggregates not having 
user-declared ctors

Looks like these were in place to make these types move-only. That's
generally not a feature that the type should prescribe (unless it's an
inherent limitation) - instead leaving it up to the users of a type.

Modified:
cfe/trunk/lib/Tooling/Refactoring/ASTSelection.cpp
cfe/trunk/tools/clang-refactor/TestSupport.h

Modified: cfe/trunk/lib/Tooling/Refactoring/ASTSelection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/ASTSelection.cpp?rev=349669&r1=349668&r2=349669&view=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/ASTSelection.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/ASTSelection.cpp Wed Dec 19 11:33:35 2018
@@ -250,8 +250,6 @@ static bool hasAnyDirectChildrenWithKind
 
 namespace {
 struct SelectedNodeWithParents {
-  SelectedNodeWithParents(SelectedNodeWithParents &&) = default;
-  SelectedNodeWithParents &operator=(SelectedNodeWithParents &&) = default;
   SelectedASTNode::ReferenceType Node;
   llvm::SmallVector Parents;
 

Modified: cfe/trunk/tools/clang-refactor/TestSupport.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-refactor/TestSupport.h?rev=349669&r1=349668&r2=349669&view=diff
==
--- cfe/trunk/tools/clang-refactor/TestSupport.h (original)
+++ cfe/trunk/tools/clang-refactor/TestSupport.h Wed Dec 19 11:33:35 2018
@@ -59,9 +59,6 @@ struct TestSelectionRangesInFile {
   };
   std::vector GroupedRanges;
 
-  TestSelectionRangesInFile(TestSelectionRangesInFile &&) = default;
-  TestSelectionRangesInFile &operator=(TestSelectionRangesInFile &&) = default;
-
   bool foreachRange(const SourceManager &SM,
 llvm::function_ref Callback) const;
 


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


[PATCH] D55890: [X86][SSE] Auto upgrade PADDS/PSUBS intrinsics to SADD_SAT/SSUB_SAT generic intrinsics (clang)

2018-12-19 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:9492
 static Value *EmitX86AddSubSatExpr(CodeGenFunction &CGF,
-   SmallVectorImpl &Ops,
+   SmallVectorImpl &Ops, bool 
IsSigned,
bool IsAddition) {

While you're touching this line, can we just make that an ArrayRef instead of a 
SmallVectorImpl?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D55890



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


[PATCH] D55865: [ObjC] Add a new attribute to opt-out of implicit callee retain/release in ARC

2018-12-19 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 178928.
erik.pilkington marked 10 inline comments as done.
erik.pilkington added a comment.

Address @aaron.ballman comments, rebase onto r349535. Thanks!


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

https://reviews.llvm.org/D55865

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/CodeGenObjC/externally-retained.m
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaObjC/externally-retained.m

Index: clang/test/SemaObjC/externally-retained.m
===
--- /dev/null
+++ clang/test/SemaObjC/externally-retained.m
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-runtime=macosx-10.13.0 -fblocks -fobjc-arc %s -verify
+
+#define EXT_RET __attribute__((objc_externally_retained))
+
+@interface ObjCTy
+@end
+
+void test1() {
+  EXT_RET int a; // expected-warning{{'objc_externally_retained' can only be applied to}}
+  EXT_RET __weak ObjCTy *b; // expected-warning{{'objc_externally_retained' can only be applied to}}
+  EXT_RET __weak int (^c)(); // expected-warning{{'objc_externally_retained' can only be applied to}}
+
+  EXT_RET int (^d)();
+  EXT_RET ObjCTy *e;
+  EXT_RET __strong ObjCTy *f;
+
+  e = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+  f = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+  d = ^{ return 0; }; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+}
+
+void test2(ObjCTy *a);
+
+void test2(EXT_RET ObjCTy *a) {
+  a = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+}
+
+EXT_RET ObjCTy *test3; // expected-warning{{'objc_externally_retained' can only be applied to}}
+
+@interface X // expected-warning{{defined without specifying a base class}} expected-note{{add a super class}}
+-(void)m: (ObjCTy *) p;
+@end
+@implementation X
+-(void)m: (ObjCTy *) EXT_RET p {
+  p = 0; // expected-error{{variable declared with 'objc_externally_retained' cannot be modified in ARC}}
+}
+@end
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -94,6 +94,7 @@
 // CHECK-NEXT: ObjCBridgeRelated (SubjectMatchRule_record)
 // CHECK-NEXT: ObjCException (SubjectMatchRule_objc_interface)
 // CHECK-NEXT: ObjCExplicitProtocolImpl (SubjectMatchRule_objc_protocol)
+// CHECK-NEXT: ObjCExternallyRetained (SubjectMatchRule_variable)
 // CHECK-NEXT: ObjCMethodFamily (SubjectMatchRule_objc_method)
 // CHECK-NEXT: ObjCPreciseLifetime (SubjectMatchRule_variable)
 // CHECK-NEXT: ObjCRequiresPropertyDefs (SubjectMatchRule_objc_interface)
Index: clang/test/CodeGenObjC/externally-retained.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/externally-retained.m
@@ -0,0 +1,121 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-arc -fblocks -O0 %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fobjc-arc -fblocks -O0 -xobjective-c++ -std=c++11 %s -S -emit-llvm -o - | FileCheck %s --check-prefix CHECKXX
+
+#define EXT_RET __attribute__((objc_externally_retained))
+
+@interface ObjTy @end
+
+ObjTy *global;
+
+#if __cplusplus
+// Suppress name mangling in C++ mode for the sake of check lines.
+extern "C" void param(ObjTy *p);
+extern "C" void local();
+extern "C" void in_init();
+extern "C" void anchor();
+extern "C" void block_capture();
+extern "C" void esc(void (^)());
+extern "C" void escp(void (^)(ObjTy *));
+extern "C" void block_param();
+#endif
+
+void param(EXT_RET ObjTy *p) {
+  // CHECK-LABEL: define void @param
+  // CHECK-NOT: llvm.objc.
+  // CHECK ret
+}
+
+void local() {
+  EXT_RET ObjTy *local = global;
+  // CHECK-LABEL: define void @local
+  // CHECK-NOT: llvm.objc.
+  // CHECK: ret
+}
+
+void in_init() {
+  // Test that we do the right thing when a variable appears in it's own
+  // initializer. Here, we release the value stored in 'wat' after overwriting
+  // it, in case it was somehow set to point to a non-null object while it's
+  // initializer is being evaluated.
+  EXT_RET ObjTy *wat = 0 ? wat : global;
+
+  // CHECK-LABEL: define void @in_init
+  // CHECK: [[WAT:%.*]] = alloca
+  // CHECK-NEXT: store {{.*}} null, {{.*}

[PATCH] D55865: [ObjC] Add a new attribute to opt-out of implicit callee retain/release in ARC

2018-12-19 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3492
+def warn_ignored_objc_externally_retained : Warning<
+  "'objc_externally_retained' can only be applied to strong retainable "
+  "object pointer types with automatic storage">, InGroup;

aaron.ballman wrote:
> This wording isn't quite right -- it doesn't apply to types, it applies to 
> variables of those types. How about: `... to local variables or parameters of 
> strong, retainable object pointer type`? or something along those lines?
Sure, that is a bit more clear.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6086-6087
+  // This attribute is a no-op without -fobjc-arc.
+  if (!S.getLangOpts().ObjCAutoRefCount)
+return;
+

aaron.ballman wrote:
> I think we should warn that the attribute is ignored in this case (because 
> we're dropping the attribute from things like pretty printing, ast dumps, 
> etc).
> 
> Instead of handling this semantically, you can do it declaratively by using 
> the `LangOpts` field in Attr.td. Something like `let LangOpts = 
> [ObjCAutoRefCount];`
Sure, good point.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6117
+  // to ensure that the variable is 'const' so that we can error on
+  // modification, which can otherwise overrelease.
+  VD->setType(Ty.withConst());

aaron.ballman wrote:
> overrelease -> over-release
> 
> Btw, this isn't a bit of a hack, it's a huge hack, IMO. Instead, can we 
> simply err if the user hasn't specified `const` explicitly? I'm not a fan of 
> "we're hiding this rather important language detail behind an attribute that 
> can be ignored". This is especially worrisome because it means the variable 
> is const only when ARC is enabled, which seems like surprising behavioral 
> differences for that compiler flag.
An important part of this feature is that it could applied to parameters with 
`#pragma clang attribute` over code that has been audited to be safe. If we 
require adding `const` to every parameter, then that falls apart :/. 

For better or for worse, this is also consistent with other cases of 
pseudo-strong in the language, i.e.:
```
void f(NSArray *A) {
  for (id Elem in A)
Elem = nil; // fine in -fno-objc-arc, error in -fobjc-arc because Elem is 
implicitly const.
}
```


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

https://reviews.llvm.org/D55865



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


[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

2018-12-19 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked 2 inline comments as done.
Szelethus added inline comments.



Comment at: test/Analysis/invalid-analyzer-config-value.c:72
+// even if -analyze isn't specified.
+// RUN: %clang --analyze -Xclang -analyzer-config -Xclang remember=TheVasa %s
+

Szelethus wrote:
> NoQ wrote:
> > This run-line *does* have `-analyze` specified, because that's what 
> > `--analyze` expands to. I guess the test that we need would be along the 
> > lines of `clang -Xclang -analyzer-config ...` without `--analyze`.
>  U sorry about that.
I checked this against a completely different file, and it works.


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

https://reviews.llvm.org/D55823



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


[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

2018-12-19 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus updated this revision to Diff 178927.
Szelethus added a comment.

I'm still looking for a sensible solution, but I'll at least share a patch that 
actually works.


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

https://reviews.llvm.org/D55823

Files:
  lib/Driver/ToolChains/Clang.cpp
  test/Analysis/invalid-analyzer-config-value.c


Index: test/Analysis/invalid-analyzer-config-value.c
===
--- test/Analysis/invalid-analyzer-config-value.c
+++ test/Analysis/invalid-analyzer-config-value.c
@@ -66,6 +66,10 @@
 
 // CHECK-NO-COMPAT: error: unknown analyzer-config 'no-false-positives'
 
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// even if -analyze isn't specified.
+// RUN: %clang -Xclang -analyzer-config -Xclang remember=TheVasa %s
+
 // expected-no-diagnostics
 
 int main() {}
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3694,6 +3694,16 @@
   if (isa(JA))
 RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
 
+  // Enable compatilibily mode to avoid analyzer-config related errors.
+  // Since we can't access frontend flags through hasArg, let's manually 
iterate
+  // through them.
+  for (size_t Index = 0; Index < Args.size(); ++Index) {
+if (StringRef(Args.getArgString(Index)).contains("-analyzer-config")) {
+  CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
+  break;
+}
+  }
+
   CheckCodeGenerationOptions(D, Args);
 
   unsigned FunctionAlignment = ParseFunctionAlignment(TC, Args);


Index: test/Analysis/invalid-analyzer-config-value.c
===
--- test/Analysis/invalid-analyzer-config-value.c
+++ test/Analysis/invalid-analyzer-config-value.c
@@ -66,6 +66,10 @@
 
 // CHECK-NO-COMPAT: error: unknown analyzer-config 'no-false-positives'
 
+// Test the driver properly using "analyzer-config-compatibility-mode=true",
+// even if -analyze isn't specified.
+// RUN: %clang -Xclang -analyzer-config -Xclang remember=TheVasa %s
+
 // expected-no-diagnostics
 
 int main() {}
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3694,6 +3694,16 @@
   if (isa(JA))
 RenderAnalyzerOptions(Args, CmdArgs, Triple, Input);
 
+  // Enable compatilibily mode to avoid analyzer-config related errors.
+  // Since we can't access frontend flags through hasArg, let's manually iterate
+  // through them.
+  for (size_t Index = 0; Index < Args.size(); ++Index) {
+if (StringRef(Args.getArgString(Index)).contains("-analyzer-config")) {
+  CmdArgs.push_back("-analyzer-config-compatibility-mode=true");
+  break;
+}
+  }
+
   CheckCodeGenerationOptions(D, Args);
 
   unsigned FunctionAlignment = ParseFunctionAlignment(TC, Args);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55895: NFC: simplify Darwin environment handling

2018-12-19 Thread JF Bastien via Phabricator via cfe-commits
jfb created this revision.
jfb added reviewers: dexonsmith, arphaman.
Herald added subscribers: cfe-commits, jkorous.

The previous code detected conflicts through copy-pasta, this versions
uses a 'loop'.


Repository:
  rC Clang

https://reviews.llvm.org/D55895

Files:
  lib/Driver/ToolChains/Darwin.cpp


Index: lib/Driver/ToolChains/Darwin.cpp
===
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -1392,22 +1392,6 @@
   Targets[I.index()] = Env;
   }
 
-  // Do not allow conflicts with the watchOS target.
-  if (!Targets[Darwin::WatchOS].empty() &&
-  (!Targets[Darwin::IPhoneOS].empty() || !Targets[Darwin::TvOS].empty())) {
-TheDriver.Diag(diag::err_drv_conflicting_deployment_targets)
-<< "WATCHOS_DEPLOYMENT_TARGET"
-<< (!Targets[Darwin::IPhoneOS].empty() ? "IPHONEOS_DEPLOYMENT_TARGET"
-   : "TVOS_DEPLOYMENT_TARGET");
-  }
-
-  // Do not allow conflicts with the tvOS target.
-  if (!Targets[Darwin::TvOS].empty() && !Targets[Darwin::IPhoneOS].empty()) {
-TheDriver.Diag(diag::err_drv_conflicting_deployment_targets)
-<< "TVOS_DEPLOYMENT_TARGET"
-<< "IPHONEOS_DEPLOYMENT_TARGET";
-  }
-
   // Allow conflicts among OSX and iOS for historical reasons, but choose the
   // default platform.
   if (!Targets[Darwin::MacOS].empty() &&
@@ -1420,6 +1404,18 @@
 else
   Targets[Darwin::IPhoneOS] = Targets[Darwin::WatchOS] =
   Targets[Darwin::TvOS] = "";
+  } else {
+// Don't allow conflicts in any other platform.
+int FirstTarget = llvm::array_lengthof(Targets);
+for (int I = 0; I != llvm::array_lengthof(Targets); ++I) {
+  if (Targets[I].empty())
+continue;
+  if (FirstTarget == llvm::array_lengthof(Targets))
+FirstTarget = I;
+  else
+TheDriver.Diag(diag::err_drv_conflicting_deployment_targets)
+<< Targets[FirstTarget] << Targets[I];
+}
   }
 
   for (const auto &Target : llvm::enumerate(llvm::makeArrayRef(Targets))) {


Index: lib/Driver/ToolChains/Darwin.cpp
===
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -1392,22 +1392,6 @@
   Targets[I.index()] = Env;
   }
 
-  // Do not allow conflicts with the watchOS target.
-  if (!Targets[Darwin::WatchOS].empty() &&
-  (!Targets[Darwin::IPhoneOS].empty() || !Targets[Darwin::TvOS].empty())) {
-TheDriver.Diag(diag::err_drv_conflicting_deployment_targets)
-<< "WATCHOS_DEPLOYMENT_TARGET"
-<< (!Targets[Darwin::IPhoneOS].empty() ? "IPHONEOS_DEPLOYMENT_TARGET"
-   : "TVOS_DEPLOYMENT_TARGET");
-  }
-
-  // Do not allow conflicts with the tvOS target.
-  if (!Targets[Darwin::TvOS].empty() && !Targets[Darwin::IPhoneOS].empty()) {
-TheDriver.Diag(diag::err_drv_conflicting_deployment_targets)
-<< "TVOS_DEPLOYMENT_TARGET"
-<< "IPHONEOS_DEPLOYMENT_TARGET";
-  }
-
   // Allow conflicts among OSX and iOS for historical reasons, but choose the
   // default platform.
   if (!Targets[Darwin::MacOS].empty() &&
@@ -1420,6 +1404,18 @@
 else
   Targets[Darwin::IPhoneOS] = Targets[Darwin::WatchOS] =
   Targets[Darwin::TvOS] = "";
+  } else {
+// Don't allow conflicts in any other platform.
+int FirstTarget = llvm::array_lengthof(Targets);
+for (int I = 0; I != llvm::array_lengthof(Targets); ++I) {
+  if (Targets[I].empty())
+continue;
+  if (FirstTarget == llvm::array_lengthof(Targets))
+FirstTarget = I;
+  else
+TheDriver.Diag(diag::err_drv_conflicting_deployment_targets)
+<< Targets[FirstTarget] << Targets[I];
+}
   }
 
   for (const auto &Target : llvm::enumerate(llvm::makeArrayRef(Targets))) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48753: [libcxx] Use custom allocator's `construct` in C++03 when available.

2018-12-19 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Ping.


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

https://reviews.llvm.org/D48753



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


[PATCH] D55823: [analyzer] Fix backward compatibility issue after D53280 'Emit an error for invalid -analyzer-config inputs'

2018-12-19 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked an inline comment as done.
Szelethus added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:3694
 
+  {
+auto AnalyzerConfigArg =

When I dump `Args` for the following invocation, I get this:

`clang -c dummie.cpp -Xclang -analyzer-config -Xclang blahblah=haha`
```
* < Opt:">
>
 Index:0 Values: []>
* < Opt:">
 Index:1 Values: ['test/Analysis/cxx-uninitialized-object.cpp']>
* < Opt:">
>
 Index:2 Values: ['-analyzer-config']>
* < Opt:">
>
 Index:4 Values: ['blahblah=haha']>

```

so there should be a way to retrieve it. For `Args.getArgString(/*index*/3)` it 
also prints `"-analyzer-config"` -- but I'm still looking for a "proper" way.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55823



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


[PATCH] D55543: [CodeGen] Fix assertion on throwing object with inlined inherited constructor and non-trivial destructor.

2018-12-19 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 178921.
vsapsai added a comment.

- [ObjC++] Verify there are no unexpected calls.

`--implicit-check-not` seems reasonable approach in this case. It causes adding
`Inheritor` destructors but gives higher confidence there are no unexpected
calls in unexpected places.

Escaping a space after check-not pattern to avoid matching attribute
`disable-tail-calls`.


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

https://reviews.llvm.org/D55543

Files:
  clang/lib/CodeGen/CGClass.cpp
  clang/test/CodeGenCXX/inheriting-constructor-cleanup.cpp
  clang/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm

Index: clang/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
===
--- /dev/null
+++ clang/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple x86_64-darwin -std=c++11 -fobjc-arc -emit-llvm -o - %s | FileCheck %s --implicit-check-not "call\ "
+// rdar://problem/45805151
+
+struct Strong {
+  __strong id x;
+};
+
+struct Base {
+  // Use variadic args to cause inlining the inherited constructor.
+  Base(Strong s, ...) {}
+};
+
+struct NonTrivialDtor {
+  ~NonTrivialDtor() {}
+};
+struct Inheritor : public NonTrivialDtor, public Base {
+  using Base::Base;
+};
+
+id g(void);
+void f() {
+  Inheritor({g()});
+}
+// CHECK-LABEL: define void @_Z1fv
+// CHECK:   %[[TMP:.*]] = call i8* @_Z1gv()
+// CHECK:   {{.*}} = call i8* @objc_retainAutoreleasedReturnValue(i8* %[[TMP]])
+// CHECK:   call void (%struct.Base*, i8*, ...) @_ZN4BaseC2E6Strongz(%struct.Base* {{.*}}, i8* {{.*}})
+// CHECK-NEXT:  call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
+
+// CHECK-LABEL: define linkonce_odr void @_ZN4BaseC2E6Strongz(%struct.Base* {{.*}}, i8* {{.*}}, ...)
+// CHECK:   call void @_ZN6StrongD1Ev(%struct.Strong* {{.*}})
+
+// CHECK-LABEL: define linkonce_odr void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
+// CHECK:   call void @_ZN9InheritorD2Ev(%struct.Inheritor* {{.*}})
+
+// CHECK-LABEL: define linkonce_odr void @_ZN6StrongD1Ev(%struct.Strong* {{.*}})
+// CHECK:   call void @_ZN6StrongD2Ev(%struct.Strong* {{.*}})
+
+// CHECK-LABEL: define linkonce_odr void @_ZN6StrongD2Ev(%struct.Strong* {{.*}})
+// CHECK:   call void @objc_storeStrong(i8** {{.*}}, i8* null)
+
+// CHECK-LABEL: define linkonce_odr void @_ZN9InheritorD2Ev(%struct.Inheritor* {{.*}})
+// CHECK:   call void @_ZN14NonTrivialDtorD2Ev(%struct.NonTrivialDtor* {{.*}})
Index: clang/test/CodeGenCXX/inheriting-constructor-cleanup.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/inheriting-constructor-cleanup.cpp
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -triple x86_64-darwin -std=c++11 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-darwin -std=c++11 -fcxx-exceptions -fexceptions -emit-llvm -o - %s | FileCheck %s --check-prefix=EXCEPTIONS
+
+// PR36748
+// rdar://problem/45805151
+
+// Classes to verify order of destroying function parameters.
+struct S1 {
+  ~S1();
+};
+struct S2 {
+  ~S2();
+};
+
+struct Base {
+  // Use variadic args to cause inlining the inherited constructor.
+  Base(const S1&, const S2&, const char *fmt, ...) {}
+};
+
+struct NonTrivialDtor {
+  ~NonTrivialDtor() {}
+};
+struct Inheritor : public NonTrivialDtor, public Base {
+  using Base::Base;
+};
+
+void f() {
+  Inheritor(S1(), S2(), "foo");
+  // CHECK-LABEL: define void @_Z1fv
+  // CHECK: %[[TMP1:.*]] = alloca %struct.S1
+  // CHECK: %[[TMP2:.*]] = alloca %struct.S2
+  // CHECK: call void (%struct.Base*, %struct.S1*, %struct.S2*, i8*, ...) @_ZN4BaseC2ERK2S1RK2S2PKcz(%struct.Base* {{.*}}, %struct.S1* dereferenceable(1) %[[TMP1]], %struct.S2* dereferenceable(1) %[[TMP2]], i8* {{.*}})
+  // CHECK-NEXT: call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
+  // CHECK-NEXT: call void @_ZN2S2D1Ev(%struct.S2* %[[TMP2]])
+  // CHECK-NEXT: call void @_ZN2S1D1Ev(%struct.S1* %[[TMP1]])
+
+  // EXCEPTIONS-LABEL: define void @_Z1fv
+  // EXCEPTIONS: %[[TMP1:.*]] = alloca %struct.S1
+  // EXCEPTIONS: %[[TMP2:.*]] = alloca %struct.S2
+  // EXCEPTIONS: invoke void (%struct.Base*, %struct.S1*, %struct.S2*, i8*, ...) @_ZN4BaseC2ERK2S1RK2S2PKcz(%struct.Base* {{.*}}, %struct.S1* dereferenceable(1) %[[TMP1]], %struct.S2* dereferenceable(1) %[[TMP2]], i8* {{.*}})
+  // EXCEPTIONS-NEXT: to label %[[CONT:.*]] unwind label %[[LPAD:.*]]
+
+  // EXCEPTIONS: [[CONT]]:
+  // EXCEPTIONS-NEXT: call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
+  // EXCEPTIONS-NEXT: call void @_ZN2S2D1Ev(%struct.S2* %[[TMP2]])
+  // EXCEPTIONS-NEXT: call void @_ZN2S1D1Ev(%struct.S1* %[[TMP1]])
+
+  // EXCEPTIONS: [[LPAD]]:
+  // EXCEPTIONS: call void @_ZN14NonTrivialDtorD2Ev(%struct.NonTrivialDtor* {{.*}})
+  // EXCEPTIONS-NEXT: call void @_ZN2S2D1Ev(%struct.S2* %[[TMP2]])
+  // EXCEPTIONS-NEXT: call void @_ZN2S1D1Ev(%struct.S1* %[[TMP1]])
+}
Index: clan

LLVM lab maintenance works in the nearest hour

2018-12-19 Thread Galina Kistanova via cfe-commits
Hello everyone,



LLVM lab could be unavailable for very short time in about next half hour
due to maintenance works in llvm lab.



Thank you for understanding.



Thanks



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


[PATCH] D55850: [OpenCL] Allow address spaces as method qualifiers

2018-12-19 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Parse/ParseDecl.cpp:6162
+}
+  }
+

Anastasia wrote:
> rjmccall wrote:
> > This is enforcing a restriction that users write `const __private`, which 
> > seems unreasonable.  It looks like `ParseTypeQualifierList` takes a flag 
> > saying not to parse attributes; try adding a new option to that enum 
> > allowing address-space attributes.
> > 
> > Collecting the attributes on the type-qualifiers `DeclSpec` rather than 
> > adding them as function attributes seems correct.
> Do you mean `ParseTypeQualifierListOpt`? That already parses the address 
> spaces unconditionally. The problem is however that we are using local 
> `DeclSpec` - `DS` variable here during the function qualifiers parsing 
> because the `DeclSpec` member of the `Declarator` corresponds to the return 
> type as far as I understand it. Therefore I am propagating missing address 
> space attributes from the local `DS` variable into `FnAttrs` to be used in 
> the function type info.
> 
> With current patch both of the following two forms:
>   struct C {
> void foo() __local const;
>   };
> and 
>   struct C {
> void foo() const __local;
>   };
> would be parsed correctly generating identical IR
>   declare void @_ZNU3AS3K1C3fooEv(%struct.C addrspace(3)*)
> 
> 
> 
Oh, I see, sorry.  Why filter on attributes at all, then?  We should *only* be 
parsing qualifier attributes in that list.

I actually think it would be reasonable to change 
`DeclaratorChunk::FunctionTypeInfo` to just store a `DeclSpec` for all the 
qualifiers; we're already duplicating an unfortunate amount of the logic from 
`DeclSpec`, like remembering `SourceLocation`s for all the qualifiers.  You'll 
have to store it out-of-line, but we already store e.g. parameters out of line, 
so the machinery for allocating and destroying it already exists.  Just make 
sure we don't actually allocate anything in the common case where there aren't 
any qualifiers (i.e. for C and non-member C++ functions).

Also, I suspect that the use of `CXXThisScopeRAII` below this needs to be 
updated to pull *all* the qualifiers out of `DS`.  Maybe Sema should have a 
function for that.



Comment at: lib/Sema/SemaOverload.cpp:2828
 
   // FIXME: OpenCL: Need to consider address spaces
   unsigned FromQuals = FromFunction->getTypeQuals().getCVRUQualifiers();

Anastasia wrote:
> I am still missing something here.
Well, at least the failure here is just to fall into the generic diagnostic.

Getting this diagnostic right probably requires some minor work to the 
diagnostics engine.  If you look at `err_init_conversion_failed`, which is (I 
think) the diagnostic that's always being used here, it matches every possible 
CVR mask so that it can pretty-print them.  This is already a problem because 
the input is actually a CVRU mask!  A better option would be to teach 
`DiagnosticEngine` how to store and format a `Qualifiers` value, and then you 
can just stream the original `Qualifiers` into the diagnostic here.

But that's obviously work for a separate patch.



Comment at: lib/Sema/SemaOverload.cpp:9279
+(CandAS1 != LangAS::opencl_generic && CandAS1 != LangAS::Default))
+  return true;
+  }

rjmccall wrote:
> This at least needs a comment explaining the rule you're trying to implement.
Okay, thanks for the clarification.  I think this should just be part of 
`CompareImplicitConversionSequence`, right?  It seems to me that you should 
prefer e.g. `int __private *` -> `int __private *` over `int __generic *`  as a 
normal argument conversion as well.

Also, can this be written in terms of `isAddressSpaceSupersetOf`?  I don't 
remember how `LangAS::Default` works in OpenCL C++ enough to understand how it 
fits in here.


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

https://reviews.llvm.org/D55850



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


[PATCH] D55847: [gn build] Add build file for clang/lib/Basic and dependencies

2018-12-19 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D55847



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


[PATCH] D55892: [OpenMP] 'close' map-type-modifier code generation

2018-12-19 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rC Clang

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

https://reviews.llvm.org/D55892



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


[PATCH] D55892: [OpenMP] 'close' map-type-modifier code generation

2018-12-19 Thread Ahsan Saghir via Phabricator via cfe-commits
saghir created this revision.
saghir added reviewers: ABataev, kkwli0, Hahnfeld, RaviNarayanaswamy, mikerice, 
hfinkel, gtbercea.
saghir added a project: OpenMP.
Herald added subscribers: cfe-commits, guansong.

This patch provides codegen support for close map-type-modifier in map clause.

A map clause with the close map-type-modifier is a hint to prefer that the 
variables are mapped using a copy into faster memory.

[NOTE: This will be committed to trunk after support for close 
map-type-modifier is added in libomptarget. This revision is being created to 
avoid duplication of work by other people.]


Repository:
  rC Clang

https://reviews.llvm.org/D55892

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_enter_data_codegen.cpp
  clang/test/OpenMP/target_exit_data_codegen.cpp
  clang/test/OpenMP/target_map_codegen.cpp

Index: clang/test/OpenMP/target_map_codegen.cpp
===
--- clang/test/OpenMP/target_map_codegen.cpp
+++ clang/test/OpenMP/target_map_codegen.cpp
@@ -5258,4 +5258,76 @@
 }
 
 #endif
+///==///
+// RUN: %clang_cc1 -DCK31 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CK31 --check-prefix CK31-64
+// RUN: %clang_cc1 -DCK31 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  %s  --check-prefix CK31 --check-prefix CK31-64
+// RUN: %clang_cc1 -DCK31 -verify -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s  --check-prefix CK31 --check-prefix CK31-32
+// RUN: %clang_cc1 -DCK31 -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ -std=c++11 -triple i386-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  %s  --check-prefix CK31 --check-prefix CK31-32
+
+// RUN: %clang_cc1 -DCK31 -verify -fopenmp-simd -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY18 %s
+// RUN: %clang_cc1 -DCK31 -fopenmp-simd -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY18 %s
+// RUN: %clang_cc1 -DCK31 -verify -fopenmp-simd -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY18 %s
+// RUN: %clang_cc1 -DCK31 -fopenmp-simd -fopenmp-targets=i386-pc-linux-gnu -x c++ -std=c++11 -triple i386-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY18 %s
+// SIMD-ONLY18-NOT: {{__kmpc|__tgt}}
+#ifdef CK31
+
+// CK31-LABEL: @.__omp_offloading_{{.*}}explicit_maps_single{{.*}}_l5305.region_id = weak constant i8 0
+// CK31: [[SIZE00:@.+]] = private {{.*}}constant [1 x i[[Z:64|32]]] [i[[Z:64|32]] 4]
+// CK31: [[MTYPE00:@.+]] = private {{.*}}constant [1 x i64] [i64 1059]
+
+// CK31-LABEL: @.__omp_offloading_{{.*}}explicit_maps_single{{.*}}_l5324.region_id = weak constant i8 0
+// CK31: [[SIZE01:@.+]] = private {{.*}}constant [1 x i[[Z:64|32]]] [i[[Z:64|32]] 4]
+// CK31: [[MTYPE01:@.+]] = private {{.*}}constant [1 x i64] [i64 1063]
+
+// CK31-LABEL: explicit_maps_single{{.*}}(
+void explicit_maps_single (int ii){
+  // Map of a scalar.
+  int a = ii;
+
+  // Close.
+  // Region 00
+  // CK31-DAG: call i32 @__tgt_target(i64 {{[^,]+}}, i8* {{[^,]+}}, i32 1, i8** [[GEPBP:%.+]], i8** [[GEPP:%.+]], {{.+}}getelementptr {{.+}}[1 x i{{.+}}]* [[SIZE00]], {{.+}}getelementptr {{.+}}[1 x i{{.+}}]* [[MTYPE00]]{{.+}})
+  // CK31-DAG: [[GEPBP]] = getelementptr inbounds {{.+}}[[BP:%[^,]+]]
+  // CK31-DAG: [[GEPP]] = getelementptr inbounds {{.+}}[[P:%[^,]+]]
+
+  // CK31-DAG: [[BP0:%.+]] = getelementptr inbounds {{.+}}[[BP]], i{{.+}} 0, i{{.+}} 0
+  // CK31-DAG: [[P0:%.+]] = getelementptr inbounds {{.+}}[[P]], i{{.+}} 0, i{{.+}} 0
+  // CK31-DAG: [[CBP0

r349657 - [OPENMP]Mark the loop as started when initialized.

2018-12-19 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Dec 19 10:16:37 2018
New Revision: 349657

URL: http://llvm.org/viewvc/llvm-project?rev=349657&view=rev
Log:
[OPENMP]Mark the loop as started when initialized.

Need to mark the loop as started when the initialization statement is
found. It is required to prevent possible incorrect loop iteraton
variable detection during template instantiation and fix the compiler
crash during the codegen.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=349657&r1=349656&r2=349657&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Dec 19 10:16:37 2018
@@ -4649,6 +4649,7 @@ void Sema::ActOnOpenMPLoopInitialization
   unsigned AssociatedLoops = DSAStack->getAssociatedLoops();
   if (AssociatedLoops > 0 &&
   isOpenMPLoopDirective(DSAStack->getCurrentDirective())) {
+DSAStack->loopStart();
 OpenMPIterationSpaceChecker ISC(*this, ForLoc);
 if (!ISC.checkAndSetInit(Init, /*EmitDiags=*/false)) {
   if (ValueDecl *D = ISC.getLoopDecl()) {

Modified: 
cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp?rev=349657&r1=349656&r2=349657&view=diff
==
--- 
cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp 
(original)
+++ 
cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp 
Wed Dec 19 10:16:37 2018
@@ -53,6 +53,13 @@ tx ftemplate(int n) {
 }
   }
 
+#pragma omp target teams distribute parallel for collapse(2)
+  for(int i = 0; i < n; i++) {
+for(int j = 0; j < n; j++) {
+  c[i][j] = i + j;
+}
+  }
+
 #pragma omp target teams distribute parallel for map(a, v[:N])
   for(int i = 0; i < n; i++)
 a[i] = v[i];
@@ -212,7 +219,11 @@ int bar(int n){
 // CHECK: call void @__kmpc_for_static_fini(
 // CHECK: ret void
 
-// CHECK: define weak void @__omp_offloading_{{.*}}_l56(i[[SZ:64|32]] 
%{{[^,]+}}, [1000 x i32]* dereferenceable{{.*}}, i32* %{{[^)]+}})
+// CHECK: define weak void @__omp_offloading_{{.*}}_l56(i[[SZ:64|32]] 
%{{[^,]+}}, [10 x [10 x i32]]* dereferenceable{{.*}})
+// CHECK: call void [[OUTLINED:@__omp_outlined.*]](i32* %{{.+}}, i32* %{{.+}}, 
i[[SZ]] %{{.*}}, i[[SZ]] %{{.*}}, i[[SZ]] %{{.*}}, [10 x [10 x i32]]* %{{.*}})
+// CHECK: define internal void [[OUTLINED]](i32* noalias %{{.*}}, i32* noalias 
%{{.*}} i[[SZ]] %{{.+}}, i[[SZ]] %{{.+}}, i[[SZ]] %{{.+}}, [10 x [10 x i32]]* 
dereferenceable{{.*}})
+
+// CHECK: define weak void @__omp_offloading_{{.*}}_l63(i[[SZ:64|32]] 
%{{[^,]+}}, [1000 x i32]* dereferenceable{{.*}}, i32* %{{[^)]+}})
 // CHECK: call void [[OUTLINED:@__omp_outlined.*]](i32* %{{.+}}, i32* %{{.+}}, 
i[[SZ]] %{{.*}}, i[[SZ]] %{{.*}}, i[[SZ]] %{{.*}}, [1000 x i32]* %{{.*}}, i32* 
%{{.*}})
 // CHECK: define internal void [[OUTLINED]](i32* noalias %{{.*}}, i32* noalias 
%{{.*}} i[[SZ]] %{{.+}}, i[[SZ]] %{{.+}}, i[[SZ]] %{{.+}}, [1000 x i32]* 
dereferenceable{{.*}}, i32* %{{.*}})
 


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


[PATCH] D55878: [Driver] Use --hash-style=gnu instead of both on FreeBSD

2018-12-19 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 178908.
MaskRay edited the summary of this revision.
MaskRay added a comment.

Bring back MIPS special case


Repository:
  rC Clang

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

https://reviews.llvm.org/D55878

Files:
  lib/Driver/ToolChains/FreeBSD.cpp
  test/Driver/freebsd.c


Index: test/Driver/freebsd.c
===
--- test/Driver/freebsd.c
+++ test/Driver/freebsd.c
@@ -73,9 +73,9 @@
 // RUN: %clang -no-canonical-prefixes -target x86_64-pc-freebsd10.0 -m32 %s \
 // RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LDFLAGS9 %s
-// CHECK-LDFLAGS8-NOT: --hash-style=both
+// CHECK-LDFLAGS8-NOT: --hash-style=gnu
 // CHECK-LDFLAGS8: --enable-new-dtags
-// CHECK-LDFLAGS9: --hash-style=both
+// CHECK-LDFLAGS9: --hash-style=gnu
 // CHECK-LDFLAGS9: --enable-new-dtags
 //
 // Check that we do not pass --hash-style=gnu and --hash-style=both to linker
Index: lib/Driver/ToolChains/FreeBSD.cpp
===
--- lib/Driver/ToolChains/FreeBSD.cpp
+++ lib/Driver/ToolChains/FreeBSD.cpp
@@ -156,12 +156,9 @@
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-if (ToolChain.getTriple().getOSMajorVersion() >= 9) {
-  if (Arch == llvm::Triple::arm || Arch == llvm::Triple::sparc ||
-  Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
-CmdArgs.push_back("--hash-style=both");
-  }
-}
+if (ToolChain.getTriple().getOSMajorVersion() >= 9 &&
+!ToolChain.getTriple().isMIPS())
+  CmdArgs.push_back("--hash-style=gnu");
 CmdArgs.push_back("--enable-new-dtags");
   }
 


Index: test/Driver/freebsd.c
===
--- test/Driver/freebsd.c
+++ test/Driver/freebsd.c
@@ -73,9 +73,9 @@
 // RUN: %clang -no-canonical-prefixes -target x86_64-pc-freebsd10.0 -m32 %s \
 // RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LDFLAGS9 %s
-// CHECK-LDFLAGS8-NOT: --hash-style=both
+// CHECK-LDFLAGS8-NOT: --hash-style=gnu
 // CHECK-LDFLAGS8: --enable-new-dtags
-// CHECK-LDFLAGS9: --hash-style=both
+// CHECK-LDFLAGS9: --hash-style=gnu
 // CHECK-LDFLAGS9: --enable-new-dtags
 //
 // Check that we do not pass --hash-style=gnu and --hash-style=both to linker
Index: lib/Driver/ToolChains/FreeBSD.cpp
===
--- lib/Driver/ToolChains/FreeBSD.cpp
+++ lib/Driver/ToolChains/FreeBSD.cpp
@@ -156,12 +156,9 @@
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-if (ToolChain.getTriple().getOSMajorVersion() >= 9) {
-  if (Arch == llvm::Triple::arm || Arch == llvm::Triple::sparc ||
-  Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
-CmdArgs.push_back("--hash-style=both");
-  }
-}
+if (ToolChain.getTriple().getOSMajorVersion() >= 9 &&
+!ToolChain.getTriple().isMIPS())
+  CmdArgs.push_back("--hash-style=gnu");
 CmdArgs.push_back("--enable-new-dtags");
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55885: [CodeComplete] Properly determine qualifiers of 'this' in a lambda

2018-12-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349655: [CodeComplete] Properly determine qualifiers of 
'this' in a lambda (authored by ibiryukov, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55885

Files:
  cfe/trunk/lib/Sema/SemaCodeComplete.cpp
  cfe/trunk/test/CodeCompletion/this-quals.cpp


Index: cfe/trunk/test/CodeCompletion/this-quals.cpp
===
--- cfe/trunk/test/CodeCompletion/this-quals.cpp
+++ cfe/trunk/test/CodeCompletion/this-quals.cpp
@@ -0,0 +1,21 @@
+class foo {
+  void mut_func() {
+[this]() {
+
+}();
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:4:1 %s -o - | 
FileCheck -check-prefix=CHECK-CC1 %s
+// CHECK-CC1: const_func
+// CHECK-CC1: mut_func
+  }
+
+  void const_func() const {
+[this]() {
+
+}();
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:13:1 %s -o - | 
FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2-NOT: mut_func
+// CHECK-CC2: const_func
+  };
+};
+
+
Index: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
===
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp
@@ -3737,11 +3737,9 @@
 
   // If we are in a C++ non-static member function, check the qualifiers on
   // the member function to filter/prioritize the results list.
-  if (CXXMethodDecl *CurMethod = dyn_cast(CurContext)) {
-if (CurMethod->isInstance()) {
-  Results.setObjectTypeQualifiers(CurMethod->getTypeQualifiers());
-}
-  }
+  auto ThisType = getCurrentThisType();
+  if (!ThisType.isNull())
+
Results.setObjectTypeQualifiers(ThisType->getPointeeType().getQualifiers());
 
   CodeCompletionDeclConsumer Consumer(Results, CurContext);
   LookupVisibleDecls(S, LookupOrdinaryName, Consumer,


Index: cfe/trunk/test/CodeCompletion/this-quals.cpp
===
--- cfe/trunk/test/CodeCompletion/this-quals.cpp
+++ cfe/trunk/test/CodeCompletion/this-quals.cpp
@@ -0,0 +1,21 @@
+class foo {
+  void mut_func() {
+[this]() {
+
+}();
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:4:1 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+// CHECK-CC1: const_func
+// CHECK-CC1: mut_func
+  }
+
+  void const_func() const {
+[this]() {
+
+}();
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:13:1 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2-NOT: mut_func
+// CHECK-CC2: const_func
+  };
+};
+
+
Index: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
===
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp
@@ -3737,11 +3737,9 @@
 
   // If we are in a C++ non-static member function, check the qualifiers on
   // the member function to filter/prioritize the results list.
-  if (CXXMethodDecl *CurMethod = dyn_cast(CurContext)) {
-if (CurMethod->isInstance()) {
-  Results.setObjectTypeQualifiers(CurMethod->getTypeQualifiers());
-}
-  }
+  auto ThisType = getCurrentThisType();
+  if (!ThisType.isNull())
+Results.setObjectTypeQualifiers(ThisType->getPointeeType().getQualifiers());
 
   CodeCompletionDeclConsumer Consumer(Results, CurContext);
   LookupVisibleDecls(S, LookupOrdinaryName, Consumer,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r349655 - [CodeComplete] Properly determine qualifiers of 'this' in a lambda

2018-12-19 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Dec 19 10:01:24 2018
New Revision: 349655

URL: http://llvm.org/viewvc/llvm-project?rev=349655&view=rev
Log:
[CodeComplete] Properly determine qualifiers of 'this' in a lambda

Summary:
The clang used to pick up the qualifiers of the lamba's call operator
(which is always const) and fail to show non-const methods of 'this' in
completion results.

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/CodeCompletion/this-quals.cpp
Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=349655&r1=349654&r2=349655&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Dec 19 10:01:24 2018
@@ -3737,11 +3737,9 @@ void Sema::CodeCompleteOrdinaryName(Scop
 
   // If we are in a C++ non-static member function, check the qualifiers on
   // the member function to filter/prioritize the results list.
-  if (CXXMethodDecl *CurMethod = dyn_cast(CurContext)) {
-if (CurMethod->isInstance()) {
-  Results.setObjectTypeQualifiers(CurMethod->getTypeQualifiers());
-}
-  }
+  auto ThisType = getCurrentThisType();
+  if (!ThisType.isNull())
+
Results.setObjectTypeQualifiers(ThisType->getPointeeType().getQualifiers());
 
   CodeCompletionDeclConsumer Consumer(Results, CurContext);
   LookupVisibleDecls(S, LookupOrdinaryName, Consumer,

Added: cfe/trunk/test/CodeCompletion/this-quals.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/this-quals.cpp?rev=349655&view=auto
==
--- cfe/trunk/test/CodeCompletion/this-quals.cpp (added)
+++ cfe/trunk/test/CodeCompletion/this-quals.cpp Wed Dec 19 10:01:24 2018
@@ -0,0 +1,21 @@
+class foo {
+  void mut_func() {
+[this]() {
+
+}();
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:4:1 %s -o - | 
FileCheck -check-prefix=CHECK-CC1 %s
+// CHECK-CC1: const_func
+// CHECK-CC1: mut_func
+  }
+
+  void const_func() const {
+[this]() {
+
+}();
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:13:1 %s -o - | 
FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2-NOT: mut_func
+// CHECK-CC2: const_func
+  };
+};
+
+


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


[PATCH] D55850: [OpenCL] Allow address spaces as method qualifiers

2018-12-19 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D55850#1335826 , @rjmccall wrote:

> You're gating on OpenCL C++ in several places in this patch, but I don't 
> think you need to.  This extension should be available to anyone using 
> address spaces and C++.


Ok, I am happy to generalize it to C++. There are some slight differences in 
the address space attribute representation for C/C++ as I am now figuring out. 
So I would prefer to put a separate patch if it's ok with you.


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

https://reviews.llvm.org/D55850



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


[PATCH] D55850: [OpenCL] Allow address spaces as method qualifiers

2018-12-19 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/Parse/ParseDecl.cpp:6162
+}
+  }
+

rjmccall wrote:
> This is enforcing a restriction that users write `const __private`, which 
> seems unreasonable.  It looks like `ParseTypeQualifierList` takes a flag 
> saying not to parse attributes; try adding a new option to that enum allowing 
> address-space attributes.
> 
> Collecting the attributes on the type-qualifiers `DeclSpec` rather than 
> adding them as function attributes seems correct.
Do you mean `ParseTypeQualifierListOpt`? That already parses the address spaces 
unconditionally. The problem is however that we are using local `DeclSpec` - 
`DS` variable here during the function qualifiers parsing because the 
`DeclSpec` member of the `Declarator` corresponds to the return type as far as 
I understand it. Therefore I am propagating missing address space attributes 
from the local `DS` variable into `FnAttrs` to be used in the function type 
info.

With current patch both of the following two forms:
  struct C {
void foo() __local const;
  };
and 
  struct C {
void foo() const __local;
  };
would be parsed correctly generating identical IR
  declare void @_ZNU3AS3K1C3fooEv(%struct.C addrspace(3)*)





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

https://reviews.llvm.org/D55850



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


[PATCH] D55850: [OpenCL] Allow address spaces as method qualifiers

2018-12-19 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 178904.
Anastasia marked an inline comment as done.
Anastasia added a comment.

Address review comments.


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

https://reviews.llvm.org/D55850

Files:
  lib/Parse/ParseDecl.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCLCXX/method-overload-address-space.cl
  test/SemaOpenCLCXX/method-overload-address-space.cl

Index: test/SemaOpenCLCXX/method-overload-address-space.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/method-overload-address-space.cl
@@ -0,0 +1,20 @@
+//RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -pedantic -verify
+
+struct C {
+  void m1() __local __local; //expected-warning{{multiple identical address spaces specified for type}}
+  //expected-note@-1{{candidate function}}
+  void m1() __global;
+  //expected-note@-1{{candidate function}}
+  void m2() __global __local; //expected-error{{multiple address spaces specified for type}}
+};
+
+__global C c_glob;
+
+__kernel void bar() {
+  __local C c_loc;
+  C c_priv;
+
+  c_glob.m1();
+  c_loc.m1();
+  c_priv.m1(); //expected-error{{no matching member function for call to 'm1'}}
+}
Index: test/CodeGenOpenCLCXX/method-overload-address-space.cl
===
--- /dev/null
+++ test/CodeGenOpenCLCXX/method-overload-address-space.cl
@@ -0,0 +1,35 @@
+//RUN: %clang_cc1 %s -triple spir-unknown-unknown -cl-std=c++ -emit-llvm -O0 -o - | FileCheck %s
+
+struct C {
+  void foo() __local;
+  void foo() __global;
+  void foo();
+  void bar();
+};
+
+__global C c1;
+
+__kernel void k() {
+  __local C c2;
+  C c3;
+  __global C &c_ref = c1;
+  __global C *c_ptr;
+
+  // CHECK: call void @_ZNU3AS11C3fooEv(%struct.C addrspace(1)*
+  c1.foo();
+  // CHECK: call void @_ZNU3AS31C3fooEv(%struct.C addrspace(3)*
+  c2.foo();
+  // CHECK: call void @_ZNU3AS41C3fooEv(%struct.C addrspace(4)*
+  c3.foo();
+  // CHECK: call void @_ZNU3AS11C3fooEv(%struct.C addrspace(1)*
+  c_ptr->foo();
+  // CHECK: void @_ZNU3AS11C3fooEv(%struct.C addrspace(1)*
+  c_ref.foo();
+
+  // CHECK: call void @_ZNU3AS41C3barEv(%struct.C addrspace(4)* addrspacecast (%struct.C addrspace(1)* @c1 to %struct.C addrspace(4)*))
+  c1.bar();
+  //FIXME: Doesn't compile yet
+  //c_ptr->bar();
+  // CHECK: call void @_ZNU3AS41C3barEv(%struct.C addrspace(4)* addrspacecast (%struct.C addrspace(1)* @c1 to %struct.C addrspace(4)*))
+  c_ref.bar();
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -3921,6 +3921,14 @@
   llvm_unreachable("unknown NullabilityKind");
 }
 
+/// IsClassMember - Determines whether a state belongs to a class member.
+static bool IsClassMember(TypeProcessingState &State) {
+  return (!State.getDeclarator().getCXXScopeSpec().isEmpty() &&
+  State.getDeclarator().getCXXScopeSpec().getScopeRep()->getKind() ==
+  NestedNameSpecifier::TypeSpec) ||
+ State.getDeclarator().getContext() == DeclaratorContext::MemberContext;
+}
+
 static TypeSourceInfo *
 GetTypeSourceInfoForDeclarator(TypeProcessingState &State,
QualType T, TypeSourceInfo *ReturnTypeInfo);
@@ -4825,18 +4833,45 @@
   Exceptions,
   EPI.ExceptionSpec);
 
-const auto &Spec = D.getCXXScopeSpec();
+// FIXME: Set address space from attrs for C++ mode here.
 // OpenCLCPlusPlus: A class member function has an address space.
 if (state.getSema().getLangOpts().OpenCLCPlusPlus &&
-((!Spec.isEmpty() &&
-  Spec.getScopeRep()->getKind() == NestedNameSpecifier::TypeSpec) ||
- state.getDeclarator().getContext() ==
- DeclaratorContext::MemberContext)) {
-  LangAS CurAS = EPI.TypeQuals.getAddressSpace();
+IsClassMember(state)) {
+  LangAS ASIdx = LangAS::Default;
+  // Take address space attr if any and mark as invalid to avoid adding
+  // them later while creating QualType.
+  for (ParsedAttr &attr : DeclType.getAttrs()) {
+switch (attr.getKind()) {
+case ParsedAttr::AT_OpenCLConstantAddressSpace:
+  ASIdx = LangAS::opencl_constant;
+  attr.setInvalid();
+  break;
+case ParsedAttr::AT_OpenCLLocalAddressSpace:
+  ASIdx = LangAS::opencl_local;
+  attr.setInvalid();
+  break;
+case ParsedAttr::AT_OpenCLGlobalAddressSpace:
+  ASIdx = LangAS::opencl_global;
+  attr.setInvalid();
+  break;
+case ParsedAttr::AT_OpenCLPrivateAddressSpace:
+  ASIdx = LangAS::opencl_private;
+  attr.setInvalid();
+  break;
+case ParsedAttr

[PATCH] D55654: [clang] [Driver] [NetBSD] Add -D_REENTRANT when using sanitizers

2018-12-19 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
mgorny marked an inline comment as done.
Closed by commit rL349650: [Driver] [NetBSD] Add -D_REENTRANT when using 
sanitizers (authored by mgorny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55654?vs=178701&id=178902#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55654

Files:
  cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
  cfe/trunk/lib/Driver/ToolChains/NetBSD.h


Index: cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
+++ cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
@@ -457,3 +457,11 @@
   }
   return Res;
 }
+
+void NetBSD::addClangTargetOptions(const ArgList &,
+   ArgStringList &CC1Args,
+   Action::OffloadKind) const {
+  const SanitizerArgs &SanArgs = getSanitizerArgs();
+  if (SanArgs.hasAnySanitizer())
+CC1Args.push_back("-D_REENTRANT");
+}
Index: cfe/trunk/lib/Driver/ToolChains/NetBSD.h
===
--- cfe/trunk/lib/Driver/ToolChains/NetBSD.h
+++ cfe/trunk/lib/Driver/ToolChains/NetBSD.h
@@ -76,6 +76,10 @@
 
   SanitizerMask getSupportedSanitizers() const override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ Action::OffloadKind DeviceOffloadKind) const 
override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;


Index: cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
+++ cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
@@ -457,3 +457,11 @@
   }
   return Res;
 }
+
+void NetBSD::addClangTargetOptions(const ArgList &,
+   ArgStringList &CC1Args,
+   Action::OffloadKind) const {
+  const SanitizerArgs &SanArgs = getSanitizerArgs();
+  if (SanArgs.hasAnySanitizer())
+CC1Args.push_back("-D_REENTRANT");
+}
Index: cfe/trunk/lib/Driver/ToolChains/NetBSD.h
===
--- cfe/trunk/lib/Driver/ToolChains/NetBSD.h
+++ cfe/trunk/lib/Driver/ToolChains/NetBSD.h
@@ -76,6 +76,10 @@
 
   SanitizerMask getSupportedSanitizers() const override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ Action::OffloadKind DeviceOffloadKind) const override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55832: [clang] [Driver] Add .hasAnySanitizer() to SanitizerArgs

2018-12-19 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349649: [Driver] Add .hasAnySanitizer() to SanitizerArgs 
(authored by mgorny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55832?vs=178699&id=178901#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55832

Files:
  cfe/trunk/include/clang/Driver/SanitizerArgs.h


Index: cfe/trunk/include/clang/Driver/SanitizerArgs.h
===
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h
@@ -82,6 +82,7 @@
   bool needsUnwindTables() const;
   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
   bool hasCrossDsoCfi() const { return CfiCrossDso; }
+  bool hasAnySanitizer() const { return !Sanitizers.empty(); }
   void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
 };


Index: cfe/trunk/include/clang/Driver/SanitizerArgs.h
===
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h
@@ -82,6 +82,7 @@
   bool needsUnwindTables() const;
   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
   bool hasCrossDsoCfi() const { return CfiCrossDso; }
+  bool hasAnySanitizer() const { return !Sanitizers.empty(); }
   void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55830: [clang] [Basic] Correct description of SanitizerSet.empty()

2018-12-19 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349648: [Basic] Correct description of SanitizerSet.empty() 
(authored by mgorny, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55830?vs=178694&id=178900#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55830

Files:
  cfe/trunk/include/clang/Basic/Sanitizers.h


Index: cfe/trunk/include/clang/Basic/Sanitizers.h
===
--- cfe/trunk/include/clang/Basic/Sanitizers.h
+++ cfe/trunk/include/clang/Basic/Sanitizers.h
@@ -66,7 +66,7 @@
   /// Disable the sanitizers specified in \p K.
   void clear(SanitizerMask K = SanitizerKind::All) { Mask &= ~K; }
 
-  /// Returns true if at least one sanitizer is enabled.
+  /// Returns true if no sanitizers are enabled.
   bool empty() const { return Mask == 0; }
 
   /// Bitmask of enabled sanitizers.


Index: cfe/trunk/include/clang/Basic/Sanitizers.h
===
--- cfe/trunk/include/clang/Basic/Sanitizers.h
+++ cfe/trunk/include/clang/Basic/Sanitizers.h
@@ -66,7 +66,7 @@
   /// Disable the sanitizers specified in \p K.
   void clear(SanitizerMask K = SanitizerKind::All) { Mask &= ~K; }
 
-  /// Returns true if at least one sanitizer is enabled.
+  /// Returns true if no sanitizers are enabled.
   bool empty() const { return Mask == 0; }
 
   /// Bitmask of enabled sanitizers.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r349650 - [Driver] [NetBSD] Add -D_REENTRANT when using sanitizers

2018-12-19 Thread Michal Gorny via cfe-commits
Author: mgorny
Date: Wed Dec 19 09:25:59 2018
New Revision: 349650

URL: http://llvm.org/viewvc/llvm-project?rev=349650&view=rev
Log:
[Driver] [NetBSD] Add -D_REENTRANT when using sanitizers

NetBSD intends to support only reentrant interfaces in interceptors.
When -lpthread is used without _REENTRANT defined, things are
not guaranteed to work.

This is especially important for  and sanitization of
interfaces around FILE.  Some APIs have alternative modes depending
on the _REENTRANT definition, and NetBSD intends to support sanitization
of the _REENTRANT ones.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
cfe/trunk/lib/Driver/ToolChains/NetBSD.h

Modified: cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp?rev=349650&r1=349649&r2=349650&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp Wed Dec 19 09:25:59 2018
@@ -457,3 +457,11 @@ SanitizerMask NetBSD::getSupportedSaniti
   }
   return Res;
 }
+
+void NetBSD::addClangTargetOptions(const ArgList &,
+   ArgStringList &CC1Args,
+   Action::OffloadKind) const {
+  const SanitizerArgs &SanArgs = getSanitizerArgs();
+  if (SanArgs.hasAnySanitizer())
+CC1Args.push_back("-D_REENTRANT");
+}

Modified: cfe/trunk/lib/Driver/ToolChains/NetBSD.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/NetBSD.h?rev=349650&r1=349649&r2=349650&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/NetBSD.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/NetBSD.h Wed Dec 19 09:25:59 2018
@@ -76,6 +76,10 @@ public:
 
   SanitizerMask getSupportedSanitizers() const override;
 
+  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args,
+ Action::OffloadKind DeviceOffloadKind) const 
override;
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;


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


[PATCH] D55828: [clang] [Driver] Disable -faddrsig by default on NetBSD

2018-12-19 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349647: [Driver] Disable -faddrsig by default on NetBSD 
(authored by mgorny, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D55828

Files:
  lib/Driver/ToolChains/Clang.cpp


Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -5273,7 +5273,8 @@
   if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
(TC.getTriple().isOSBinFormatELF() ||
 TC.getTriple().isOSBinFormatCOFF()) &&
-   TC.useIntegratedAs()))
+   TC.useIntegratedAs() &&
+   RawTriple.getOS() != llvm::Triple::NetBSD))
 CmdArgs.push_back("-faddrsig");
 
   // Finally add the compile command to the compilation.


Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -5273,7 +5273,8 @@
   if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
(TC.getTriple().isOSBinFormatELF() ||
 TC.getTriple().isOSBinFormatCOFF()) &&
-   TC.useIntegratedAs()))
+   TC.useIntegratedAs() &&
+   RawTriple.getOS() != llvm::Triple::NetBSD))
 CmdArgs.push_back("-faddrsig");
 
   // Finally add the compile command to the compilation.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r349649 - [Driver] Add .hasAnySanitizer() to SanitizerArgs

2018-12-19 Thread Michal Gorny via cfe-commits
Author: mgorny
Date: Wed Dec 19 09:25:55 2018
New Revision: 349649

URL: http://llvm.org/viewvc/llvm-project?rev=349649&view=rev
Log:
[Driver] Add .hasAnySanitizer() to SanitizerArgs

Add a simple method to query whether any sanitizer was enabled,
via SanitizerArgs.  This will be used in the NetBSD driver to pass
additional definitions that are required by all sanitizers.

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

Modified:
cfe/trunk/include/clang/Driver/SanitizerArgs.h

Modified: cfe/trunk/include/clang/Driver/SanitizerArgs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/SanitizerArgs.h?rev=349649&r1=349648&r2=349649&view=diff
==
--- cfe/trunk/include/clang/Driver/SanitizerArgs.h (original)
+++ cfe/trunk/include/clang/Driver/SanitizerArgs.h Wed Dec 19 09:25:55 2018
@@ -82,6 +82,7 @@ class SanitizerArgs {
   bool needsUnwindTables() const;
   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
   bool hasCrossDsoCfi() const { return CfiCrossDso; }
+  bool hasAnySanitizer() const { return !Sanitizers.empty(); }
   void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
 };


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


r349647 - [Driver] Disable -faddrsig by default on NetBSD

2018-12-19 Thread Michal Gorny via cfe-commits
Author: mgorny
Date: Wed Dec 19 09:25:46 2018
New Revision: 349647

URL: http://llvm.org/viewvc/llvm-project?rev=349647&view=rev
Log:
[Driver] Disable -faddrsig by default on NetBSD

Avoid passing -faddrsig by default on NetBSD.  This platform is still
using old GNU binutils that crashes on executables containing those
sections.

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

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

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=349647&r1=349646&r2=349647&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Dec 19 09:25:46 2018
@@ -5273,7 +5273,8 @@ void Clang::ConstructJob(Compilation &C,
   if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
(TC.getTriple().isOSBinFormatELF() ||
 TC.getTriple().isOSBinFormatCOFF()) &&
-   TC.useIntegratedAs()))
+   TC.useIntegratedAs() &&
+   RawTriple.getOS() != llvm::Triple::NetBSD))
 CmdArgs.push_back("-faddrsig");
 
   // Finally add the compile command to the compilation.


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


r349648 - [Basic] Correct description of SanitizerSet.empty()

2018-12-19 Thread Michal Gorny via cfe-commits
Author: mgorny
Date: Wed Dec 19 09:25:51 2018
New Revision: 349648

URL: http://llvm.org/viewvc/llvm-project?rev=349648&view=rev
Log:
[Basic] Correct description of SanitizerSet.empty()

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

Modified:
cfe/trunk/include/clang/Basic/Sanitizers.h

Modified: cfe/trunk/include/clang/Basic/Sanitizers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Sanitizers.h?rev=349648&r1=349647&r2=349648&view=diff
==
--- cfe/trunk/include/clang/Basic/Sanitizers.h (original)
+++ cfe/trunk/include/clang/Basic/Sanitizers.h Wed Dec 19 09:25:51 2018
@@ -66,7 +66,7 @@ struct SanitizerSet {
   /// Disable the sanitizers specified in \p K.
   void clear(SanitizerMask K = SanitizerKind::All) { Mask &= ~K; }
 
-  /// Returns true if at least one sanitizer is enabled.
+  /// Returns true if no sanitizers are enabled.
   bool empty() const { return Mask == 0; }
 
   /// Bitmask of enabled sanitizers.


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


[PATCH] D55811: [compiler-rt] [sanitizer_common] Fix sha2 interceptors not to use vars in array len

2018-12-19 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL349645: [sanitizer_common] Fix sha2 interceptors not to use 
vars in array len (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D55811?vs=178608&id=178897#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55811

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -8511,9 +8511,10 @@
 if (context) \
   COMMON_INTERCEPTOR_WRITE_RANGE(ctx, context, SHA##LEN##_CTX_sz); \
   } \
-  INTERCEPTOR(void, SHA##LEN##_Final, u8 digest[SHA##LEN##_digest_length], \
+  INTERCEPTOR(void, SHA##LEN##_Final, u8 digest[LEN/8], \
   void *context) { \
 void *ctx; \
+CHECK_EQ(SHA##LEN##_digest_length, LEN/8); \
 COMMON_INTERCEPTOR_ENTER(ctx, SHA##LEN##_Final, digest, context); \
 if (context) \
   COMMON_INTERCEPTOR_READ_RANGE(ctx, context, SHA##LEN##_CTX_sz); \


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
===
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -8511,9 +8511,10 @@
 if (context) \
   COMMON_INTERCEPTOR_WRITE_RANGE(ctx, context, SHA##LEN##_CTX_sz); \
   } \
-  INTERCEPTOR(void, SHA##LEN##_Final, u8 digest[SHA##LEN##_digest_length], \
+  INTERCEPTOR(void, SHA##LEN##_Final, u8 digest[LEN/8], \
   void *context) { \
 void *ctx; \
+CHECK_EQ(SHA##LEN##_digest_length, LEN/8); \
 COMMON_INTERCEPTOR_ENTER(ctx, SHA##LEN##_Final, digest, context); \
 if (context) \
   COMMON_INTERCEPTOR_READ_RANGE(ctx, context, SHA##LEN##_CTX_sz); \
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55552: [Sema] Better static assert diagnostics for expressions involving temporaries.

2018-12-19 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

LGTM. Tiny style suggestions, which I won't mind if you ignore.




Comment at: include/clang/AST/Type.h:995
   void getAsStringInternal(std::string &Str,
-   const PrintingPolicy &Policy) const {
-return getAsStringInternal(split(), Str, Policy);
-  }
+   const PrintingPolicy &Policy) const;
 

Nit: could this function have been left in-line, and just changed `split()` to 
`splitAccordingToPolicy(this, Policy)`?
Even simpler, could `splitAccordingToPolicy` be made a member function of 
`QualType`, so that most of these diffs could be simply 
`s/split()/splitAccordingToPolicy(Policy)/` without introducing any new 
temporary variables or anything?  I.e.
```
void getAsStringInternal(std::string &Str,
  const PrintingPolicy &Policy) const {
return getAsStringInternal(splitAccordingToPolicy(Policy), Str, Policy);
}
```
But if that would make the code harder to read instead of easier, then don't 
mind me.



Comment at: include/clang/AST/Type.h:998
   static void getAsStringInternal(SplitQualType split, std::string &out,
-  const PrintingPolicy &policy) {
-return getAsStringInternal(split.Ty, split.Quals, out, policy);
-  }
+  const PrintingPolicy &policy);
 

Nit: this function's body hasn't changed, so personally I would have left it 
alone (not out-of-lined it).


Repository:
  rC Clang

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

https://reviews.llvm.org/D2



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


[PATCH] D55891: [compiler-rt] [xray] [tests] Detect and handle missing LLVMTestingSupport gracefully

2018-12-19 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: krytarowski, dberris, george.karpenkov.
Herald added subscribers: Sanitizers, llvm-commits.

Add a code to properly test for presence of LLVMTestingSupport library
when performing a stand-alone build, and skip tests requiring it when
it is not present.  Since the library is not installed, llvm-config
reported empty --libs for it and the tests failed to link with undefined
references.  Skipping the two fdr_* test files is better than failing to
build, and should be good enough until we find a better solution.

NB: both installing LLVMTestingSupport and building it automatically
from within compiler-rt sources are non-trivial.  The former due to
dependency on gtest, the latter due to tight integration with LLVM
source tree.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D55891

Files:
  cmake/Modules/CompilerRTUtils.cmake
  lib/xray/tests/CMakeLists.txt
  lib/xray/tests/unit/CMakeLists.txt


Index: lib/xray/tests/unit/CMakeLists.txt
===
--- lib/xray/tests/unit/CMakeLists.txt
+++ lib/xray/tests/unit/CMakeLists.txt
@@ -1,10 +1,16 @@
-add_xray_unittest(XRayTest SOURCES
+set(TEST_SOURCES
   allocator_test.cc
   buffer_queue_test.cc
-  fdr_controller_test.cc
-  fdr_log_writer_test.cc
   function_call_trie_test.cc
   profile_collector_test.cc
   segmented_array_test.cc
   test_helpers.cc
   xray_unit_test_main.cc)
+
+if (NOT COMPILER_RT_STANDALONE_BUILD OR COMPILER_RT_HAS_LLVMTESTINGSUPPORT)
+  list(APPEND TEST_SOURCES
+fdr_controller_test.cc
+fdr_log_writer_test.cc)
+endif()
+
+add_xray_unittest(XRayTest SOURCES ${TEST_SOURCES})
Index: lib/xray/tests/CMakeLists.txt
===
--- lib/xray/tests/CMakeLists.txt
+++ lib/xray/tests/CMakeLists.txt
@@ -60,6 +60,10 @@
   if (COMPILER_RT_STANDALONE_BUILD)
 append_list_if(COMPILER_RT_HAS_LLVMXRAY ${LLVM_XRAY_LDFLAGS} 
XRAY_UNITTEST_LINK_FLAGS)
 append_list_if(COMPILER_RT_HAS_LLVMXRAY ${LLVM_XRAY_LIBLIST} 
XRAY_UNITTEST_LINK_FLAGS)
+append_list_if(COMPILER_RT_HAS_LLVMTESTINGSUPPORT
+  ${LLVM_TESTINGSUPPORT_LDFLAGS} XRAY_UNITTEST_LINK_FLAGS)
+append_list_if(COMPILER_RT_HAS_LLVMTESTINGSUPPORT
+  ${LLVM_TESTINGSUPPORT_LIBLIST} XRAY_UNITTEST_LINK_FLAGS)
   else()
 # We add the library directories one at a time in our CFLAGS.
 foreach (DIR ${LLVM_LIBRARY_DIR})
Index: cmake/Modules/CompilerRTUtils.cmake
===
--- cmake/Modules/CompilerRTUtils.cmake
+++ cmake/Modules/CompilerRTUtils.cmake
@@ -239,7 +239,7 @@
 # Detect if we have the LLVMXRay and TestingSupport library installed and
 # available from llvm-config.
 execute_process(
-  COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "xray" "testingsupport"
+  COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "xray"
   RESULT_VARIABLE HAD_ERROR
   OUTPUT_VARIABLE CONFIG_OUTPUT)
 if (HAD_ERROR)
@@ -254,6 +254,26 @@
   set(COMPILER_RT_HAS_LLVMXRAY TRUE)
 endif()
 
+set(COMPILER_RT_HAS_LLVMTESTINGSUPPORT FALSE)
+execute_process(
+  COMMAND ${LLVM_CONFIG_PATH} "--ldflags" "--libs" "testingsupport"
+  RESULT_VARIABLE HAD_ERROR
+  OUTPUT_VARIABLE CONFIG_OUTPUT)
+if (HAD_ERROR)
+  message(WARNING "llvm-config finding testingsupport failed with status 
${HAD_ERROR}")
+else()
+  string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT 
${CONFIG_OUTPUT})
+  list(GET CONFIG_OUTPUT 0 LDFLAGS)
+  list(GET CONFIG_OUTPUT 1 LIBLIST)
+  if (LIBLIST STREQUAL "")
+message(WARNING "testingsupport library not installed, some tests will 
be skipped")
+  else()
+set(LLVM_TESTINGSUPPORT_LDFLAGS ${LDFLAGS} CACHE STRING "Linker flags 
for LLVMTestingSupport library")
+set(LLVM_TESTINGSUPPORT_LIBLIST ${LIBLIST} CACHE STRING "Library list 
for LLVMTestingSupport")
+set(COMPILER_RT_HAS_LLVMTESTINGSUPPORT TRUE)
+  endif()
+endif()
+
 # Make use of LLVM CMake modules.
 # --cmakedir is supported since llvm r291218 (4.0 release)
 execute_process(


Index: lib/xray/tests/unit/CMakeLists.txt
===
--- lib/xray/tests/unit/CMakeLists.txt
+++ lib/xray/tests/unit/CMakeLists.txt
@@ -1,10 +1,16 @@
-add_xray_unittest(XRayTest SOURCES
+set(TEST_SOURCES
   allocator_test.cc
   buffer_queue_test.cc
-  fdr_controller_test.cc
-  fdr_log_writer_test.cc
   function_call_trie_test.cc
   profile_collector_test.cc
   segmented_array_test.cc
   test_helpers.cc
   xray_unit_test_main.cc)
+
+if (NOT COMPILER_RT_STANDALONE_BUILD OR COMPILER_RT_HAS_LLVMTESTINGSUPPORT)
+  list(APPEND TEST_SOURCES
+fdr_controller_test.cc
+fdr_log_writer_test.cc)
+endif()
+
+add_xray_unittest(XRayTest SOURCES ${TEST_SOURCES})
Index: lib/xray/tests/CMakeLists.txt
=

[PATCH] D53891: [LTO] Add option to enable LTOUnit splitting, and disable unless needed

2018-12-19 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked 2 inline comments as done.
tejohnson added inline comments.



Comment at: lib/CodeGen/BackendUtil.cpp:831
+  *OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary,
+  /*EmitModuleHash=*/false));
 }

pcc wrote:
> Why add this argument here (and below)?
I think this was leftover from an earlier version where I had added a new 
parameter. Will revert this change (here and below).



Comment at: lib/Driver/ToolChains/Clang.cpp:5112
+  bool EnableSplitLTOUnit = Args.hasFlag(
+  options::OPT_fsplit_lto_unit, options::OPT_fno_split_lto_unit, false);
+  if (EnableSplitLTOUnit || WholeProgramVTables || Sanitize.needsLTO()) {

pcc wrote:
> Should this default to `WholeProgramVTables || Sanitize.needsLTO()` and emit 
> an error if the user passes the (for now) unsupported combinations 
> `-fno-split-lto-unit -fwhole-program-vtables` or `-fno-split-lto-unit 
> -fsanitize=cfi`?
I think the code below needs to stay as is to allow -fsplit-lto-unit to also 
enable the splitting even when the other options aren't on (not sure when that 
would be used outside of testing, but I'm assuming we want a way to force that 
on). 

But yes I think it makes sense to emit an error on those combinations (when my 
follow on patches go in then we would remove the error with -fno-split-lto-unit 
-fwhole-program-vtables).


Repository:
  rC Clang

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

https://reviews.llvm.org/D53891



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


[PATCH] D55552: [Sema] Better static assert diagnostics for expressions involving temporaries.

2018-12-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, but you should wait a few days before committing in case @Quuxplusone has 
comments.


Repository:
  rC Clang

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

https://reviews.llvm.org/D2



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


[PATCH] D55890: [X86][SSE] Auto upgrade PADDS/PSUBS intrinsics to SADD_SAT/SSUB_SAT generic intrinsics (clang)

2018-12-19 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon created this revision.
RKSimon added reviewers: craig.topper, spatel, nikic, tkrupa.
Herald added a subscriber: llvm-commits.

This emits SADD_SAT/SSUB_SAT generic intrinsics for the SSE saturated math 
intrinsics.

I'm still working on the llvm sibling patch (auto upgrade etc.) as there's a 
number of things that need unravelling. If people are interested in getting 
this committed quicker I could include minimal llvm side commit changes 
(GCCBuiltin and fast-isel tests) in the meantime.


Repository:
  rL LLVM

https://reviews.llvm.org/D55890

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/avx2-builtins.c
  test/CodeGen/avx512bw-builtins.c
  test/CodeGen/avx512vlbw-builtins.c
  test/CodeGen/sse2-builtins.c

Index: test/CodeGen/sse2-builtins.c
===
--- test/CodeGen/sse2-builtins.c
+++ test/CodeGen/sse2-builtins.c
@@ -47,13 +47,13 @@
 
 __m128i test_mm_adds_epi8(__m128i A, __m128i B) {
   // CHECK-LABEL: test_mm_adds_epi8
-  // CHECK: call <16 x i8> @llvm.x86.sse2.padds.b(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call <16 x i8> @llvm.sadd.sat.v16i8(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   return _mm_adds_epi8(A, B);
 }
 
 __m128i test_mm_adds_epi16(__m128i A, __m128i B) {
   // CHECK-LABEL: test_mm_adds_epi16
-  // CHECK: call <8 x i16> @llvm.x86.sse2.padds.w(<8 x i16> %{{.*}}, <8 x i16> %{{.*}})
+  // CHECK: call <8 x i16> @llvm.sadd.sat.v8i16(<8 x i16> %{{.*}}, <8 x i16> %{{.*}})
   return _mm_adds_epi16(A, B);
 }
 
@@ -1460,13 +1460,13 @@
 
 __m128i test_mm_subs_epi8(__m128i A, __m128i B) {
   // CHECK-LABEL: test_mm_subs_epi8
-  // CHECK: call <16 x i8> @llvm.x86.sse2.psubs.b(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
+  // CHECK: call <16 x i8> @llvm.ssub.sat.v16i8(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
   return _mm_subs_epi8(A, B);
 }
 
 __m128i test_mm_subs_epi16(__m128i A, __m128i B) {
   // CHECK-LABEL: test_mm_subs_epi16
-  // CHECK: call <8 x i16> @llvm.x86.sse2.psubs.w(<8 x i16> %{{.*}}, <8 x i16> %{{.*}})
+  // CHECK: call <8 x i16> @llvm.ssub.sat.v8i16(<8 x i16> %{{.*}}, <8 x i16> %{{.*}})
   return _mm_subs_epi16(A, B);
 }
 
Index: test/CodeGen/avx512vlbw-builtins.c
===
--- test/CodeGen/avx512vlbw-builtins.c
+++ test/CodeGen/avx512vlbw-builtins.c
@@ -1075,49 +1075,49 @@
 
 __m128i test_mm_mask_adds_epi8(__m128i __W, __mmask16 __U, __m128i __A, __m128i __B) {
   // CHECK-LABEL: @test_mm_mask_adds_epi8
-  // CHECK: @llvm.x86.sse2.padds.b
+  // CHECK: @llvm.sadd.sat.v16i8
   // CHECK: select <16 x i1> %{{.*}}, <16 x i8> %{{.*}}, <16 x i8> %{{.*}}
   return _mm_mask_adds_epi8(__W,__U,__A,__B); 
 }
 __m128i test_mm_maskz_adds_epi8(__mmask16 __U, __m128i __A, __m128i __B) {
   // CHECK-LABEL: @test_mm_maskz_adds_epi8
-  // CHECK: @llvm.x86.sse2.padds.b
+  // CHECK: @llvm.sadd.sat.v16i8
   // CHECK: select <16 x i1> %{{.*}}, <16 x i8> %{{.*}}, <16 x i8> %{{.*}}
   return _mm_maskz_adds_epi8(__U,__A,__B); 
 }
 __m256i test_mm256_mask_adds_epi8(__m256i __W, __mmask32 __U, __m256i __A, __m256i __B) {
   // CHECK-LABEL: @test_mm256_mask_adds_epi8
-  // CHECK: @llvm.x86.avx2.padds.b
+  // CHECK: @llvm.sadd.sat.v32i8
   // CHECK: select <32 x i1> %{{.*}}, <32 x i8> %{{.*}}, <32 x i8> %{{.*}}
   return _mm256_mask_adds_epi8(__W,__U,__A,__B); 
 }
 __m256i test_mm256_maskz_adds_epi8(__mmask32 __U, __m256i __A, __m256i __B) {
   // CHECK-LABEL: @test_mm256_maskz_adds_epi8
-  // CHECK: @llvm.x86.avx2.padds.b
+  // CHECK: @llvm.sadd.sat.v32i8
   // CHECK: select <32 x i1> %{{.*}}, <32 x i8> %{{.*}}, <32 x i8> %{{.*}}
   return _mm256_maskz_adds_epi8(__U,__A,__B); 
 }
 __m128i test_mm_mask_adds_epi16(__m128i __W, __mmask8 __U, __m128i __A, __m128i __B) {
   // CHECK-LABEL: @test_mm_mask_adds_epi16
-  // CHECK: @llvm.x86.sse2.padds.w
+  // CHECK: @llvm.sadd.sat.v8i16
   // CHECK: select <8 x i1> %{{.*}}, <8 x i16> %{{.*}}, <8 x i16> %{{.*}}
   return _mm_mask_adds_epi16(__W,__U,__A,__B); 
 }
 __m128i test_mm_maskz_adds_epi16(__mmask8 __U, __m128i __A, __m128i __B) {
   // CHECK-LABEL: @test_mm_maskz_adds_epi16
-  // CHECK: @llvm.x86.sse2.padds.w
+  // CHECK: @llvm.sadd.sat.v8i16
   // CHECK: select <8 x i1> %{{.*}}, <8 x i16> %{{.*}}, <8 x i16> %{{.*}}
   return _mm_maskz_adds_epi16(__U,__A,__B); 
 }
 __m256i test_mm256_mask_adds_epi16(__m256i __W, __mmask16 __U, __m256i __A, __m256i __B) {
   // CHECK-LABEL: @test_mm256_mask_adds_epi16
-  // CHECK: @llvm.x86.avx2.padds.w
+  // CHECK: @llvm.sadd.sat.v16i16
   // CHECK: select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> %{{.*}}
   return _mm256_mask_adds_epi16(__W,__U,__A,__B); 
 }
 __m256i test_mm256_maskz_adds_epi16(__mmask16 __U, __m256i __A, __m256i __B) {
   // CHECK-LABEL: @test_mm256_maskz_adds_epi16
-  // CHECK: @llvm.x86.avx2.padds.w
+  // CHECK: @llvm.sadd.sat.v16i16
   // CHECK: select <16 x i1> %{{.*}}, <16 x i16> %{{.*}}, <16 x i16> %{{.*}}
   return _mm256_maskz_adds_epi16(__U,__A,__B); 
 }
@@ -1527,49 +

[PATCH] D54450: Get the correct range of tokens for preprocessor conditions

2018-12-19 Thread Miklos Vajna via Phabricator via cfe-commits
vmiklos added a comment.

Ping, could this be reviewed, please? :-) Thanks!


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

https://reviews.llvm.org/D54450



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


[PATCH] D55784: [clang-tidy] Update abseil-duration-comparison to handle macro arguments

2018-12-19 Thread Hyrum Wright via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
hwright marked an inline comment as done.
Closed by commit rL349636: [clang-tidy] Diagnose abseil-duration-comparison on 
macro arguments (authored by hwright, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55784?vs=178733&id=178891#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55784

Files:
  clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
  clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.cpp
  clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h
  clang-tools-extra/trunk/clang-tidy/abseil/DurationSubtractionCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp

Index: clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h
===
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h
@@ -65,7 +65,7 @@
 
 /// Assuming `Node` has type `double` or `int` representing a time interval of
 /// `Scale`, return the expression to make it a suitable `Duration`.
-llvm::Optional rewriteExprFromNumberToDuration(
+std::string rewriteExprFromNumberToDuration(
 const ast_matchers::MatchFinder::MatchResult &Result, DurationScale Scale,
 const Expr *Node);
 
Index: clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
@@ -19,6 +19,26 @@
 namespace tidy {
 namespace abseil {
 
+/// Return `true` if `E` is a either: not a macro at all; or an argument to
+/// one. In the latter case, we should still transform it.
+static bool IsValidMacro(const MatchFinder::MatchResult &Result,
+ const Expr *E) {
+  if (!E->getBeginLoc().isMacroID())
+return true;
+
+  SourceLocation Loc = E->getBeginLoc();
+  // We want to get closer towards the initial macro typed into the source only
+  // if the location is being expanded as a macro argument.
+  while (Result.SourceManager->isMacroArgExpansion(Loc)) {
+// We are calling getImmediateMacroCallerLoc, but note it is essentially
+// equivalent to calling getImmediateSpellingLoc in this context according
+// to Clang implementation. We are not calling getImmediateSpellingLoc
+// because Clang comment says it "should not generally be used by clients."
+Loc = Result.SourceManager->getImmediateMacroCallerLoc(Loc);
+  }
+  return !Loc.isMacroID();
+}
+
 void DurationComparisonCheck::registerMatchers(MatchFinder *Finder) {
   auto Matcher =
   binaryOperator(anyOf(hasOperatorName(">"), hasOperatorName(">="),
@@ -35,10 +55,6 @@
 void DurationComparisonCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Binop = Result.Nodes.getNodeAs("binop");
 
-  // Don't try to replace things inside of macro definitions.
-  if (Binop->getExprLoc().isMacroID())
-return;
-
   llvm::Optional Scale = getScaleForInverse(
   Result.Nodes.getNodeAs("function_decl")->getName());
   if (!Scale)
@@ -48,19 +64,19 @@
   // want to handle the case of rewriting both sides. This is much simpler if
   // we unconditionally try and rewrite both, and let the rewriter determine
   // if nothing needs to be done.
-  llvm::Optional LhsReplacement =
+  if (!IsValidMacro(Result, Binop->getLHS()) ||
+  !IsValidMacro(Result, Binop->getRHS()))
+return;
+  std::string LhsReplacement =
   rewriteExprFromNumberToDuration(Result, *Scale, Binop->getLHS());
-  llvm::Optional RhsReplacement =
+  std::string RhsReplacement =
   rewriteExprFromNumberToDuration(Result, *Scale, Binop->getRHS());
 
-  if (!(LhsReplacement && RhsReplacement))
-return;
-
   diag(Binop->getBeginLoc(), "perform comparison in the duration domain")
   << FixItHint::CreateReplacement(Binop->getSourceRange(),
-  (llvm::Twine(*LhsReplacement) + " " +
+  (llvm::Twine(LhsReplacement) + " " +
Binop->getOpcodeStr() + " " +
-   *RhsReplacement)
+   RhsReplacement)
   .str());
 }
 
Index: clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.cpp
===
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.cpp
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.cpp
@@ -183,14 +183,11 @@
   return ScaleIter->second;
 }
 
-llvm::Optional rewriteExprFromNumberToDuration(
+std::string rewriteExprFromNumberToDuration(
 const ast_ma

[clang-tools-extra] r349636 - [clang-tidy] Diagnose abseil-duration-comparison on macro arguments

2018-12-19 Thread Hyrum Wright via cfe-commits
Author: hwright
Date: Wed Dec 19 08:03:34 2018
New Revision: 349636

URL: http://llvm.org/viewvc/llvm-project?rev=349636&view=rev
Log:
[clang-tidy] Diagnose abseil-duration-comparison on macro arguments

Summary:
This change relaxes the requirements on the utility
`rewriteExprFromNumberToDuration` function, and introduces new checking
inside of the `abseil-duration-comparison` check to allow macro argument
expression transformation.

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

Modified:
clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.cpp
clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.h
clang-tools-extra/trunk/clang-tidy/abseil/DurationSubtractionCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-comparison.cpp

Modified: clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp?rev=349636&r1=349635&r2=349636&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationComparisonCheck.cpp Wed 
Dec 19 08:03:34 2018
@@ -19,6 +19,26 @@ namespace clang {
 namespace tidy {
 namespace abseil {
 
+/// Return `true` if `E` is a either: not a macro at all; or an argument to
+/// one. In the latter case, we should still transform it.
+static bool IsValidMacro(const MatchFinder::MatchResult &Result,
+ const Expr *E) {
+  if (!E->getBeginLoc().isMacroID())
+return true;
+
+  SourceLocation Loc = E->getBeginLoc();
+  // We want to get closer towards the initial macro typed into the source only
+  // if the location is being expanded as a macro argument.
+  while (Result.SourceManager->isMacroArgExpansion(Loc)) {
+// We are calling getImmediateMacroCallerLoc, but note it is essentially
+// equivalent to calling getImmediateSpellingLoc in this context according
+// to Clang implementation. We are not calling getImmediateSpellingLoc
+// because Clang comment says it "should not generally be used by clients."
+Loc = Result.SourceManager->getImmediateMacroCallerLoc(Loc);
+  }
+  return !Loc.isMacroID();
+}
+
 void DurationComparisonCheck::registerMatchers(MatchFinder *Finder) {
   auto Matcher =
   binaryOperator(anyOf(hasOperatorName(">"), hasOperatorName(">="),
@@ -35,10 +55,6 @@ void DurationComparisonCheck::registerMa
 void DurationComparisonCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Binop = Result.Nodes.getNodeAs("binop");
 
-  // Don't try to replace things inside of macro definitions.
-  if (Binop->getExprLoc().isMacroID())
-return;
-
   llvm::Optional Scale = getScaleForInverse(
   Result.Nodes.getNodeAs("function_decl")->getName());
   if (!Scale)
@@ -48,19 +64,19 @@ void DurationComparisonCheck::check(cons
   // want to handle the case of rewriting both sides. This is much simpler if
   // we unconditionally try and rewrite both, and let the rewriter determine
   // if nothing needs to be done.
-  llvm::Optional LhsReplacement =
+  if (!IsValidMacro(Result, Binop->getLHS()) ||
+  !IsValidMacro(Result, Binop->getRHS()))
+return;
+  std::string LhsReplacement =
   rewriteExprFromNumberToDuration(Result, *Scale, Binop->getLHS());
-  llvm::Optional RhsReplacement =
+  std::string RhsReplacement =
   rewriteExprFromNumberToDuration(Result, *Scale, Binop->getRHS());
 
-  if (!(LhsReplacement && RhsReplacement))
-return;
-
   diag(Binop->getBeginLoc(), "perform comparison in the duration domain")
   << FixItHint::CreateReplacement(Binop->getSourceRange(),
-  (llvm::Twine(*LhsReplacement) + " " +
+  (llvm::Twine(LhsReplacement) + " " +
Binop->getOpcodeStr() + " " +
-   *RhsReplacement)
+   RhsReplacement)
   .str());
 }
 

Modified: clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.cpp?rev=349636&r1=349635&r2=349636&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationRewriter.cpp Wed Dec 19 
08:03:34 2018
@@ -183,14 +183,11 @@ llvm::Optional getScaleFo
   return ScaleIter->second;
 }
 
-llvm::Optional rewriteExprFromNumberToDuration(
+std::string rewriteExprFromNumberToDuration(
 const ast_matchers::MatchFinder::MatchResult &Result, DurationScale Scale,
 const Expr *Node) {
   const Ex

[PATCH] D55861: [OpenMP] Fix data sharing analysis in nested clause

2018-12-19 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC349635: [OpenMP] Fix data sharing analysis in nested clause 
(authored by jdenny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55861?vs=178803&id=178890#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D55861

Files:
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/target_teams_messages.cpp


Index: test/OpenMP/target_teams_messages.cpp
===
--- test/OpenMP/target_teams_messages.cpp
+++ test/OpenMP/target_teams_messages.cpp
@@ -50,6 +50,16 @@
 #pragma omp target teams default(none)
   ++argc; // expected-error {{variable 'argc' must have explicitly specified 
data sharing attributes}}
 
+#pragma omp target teams default(none)
+#pragma omp parallel num_threads(argc) // expected-error {{variable 'argc' 
must have explicitly specified data sharing attributes}}
+  ;
+
+#pragma omp target teams default(none)
+  {
+#pragma omp parallel num_threads(argc) // expected-error {{variable 'argc' 
must have explicitly specified data sharing attributes}}
+;
+  }
+
   goto L2; // expected-error {{use of undeclared label 'L2'}}
 #pragma omp target teams
   L2:
Index: lib/Sema/SemaOpenMP.cpp
===
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -2390,13 +2390,9 @@
   void VisitStmt(Stmt *S) {
 for (Stmt *C : S->children()) {
   if (C) {
-if (auto *OED = dyn_cast(C)) {
-  // Check implicitly captured variables in the task-based directives 
to
-  // check if they must be firstprivatized.
-  VisitSubCaptures(OED);
-} else {
-  Visit(C);
-}
+// Check implicitly captured variables in the task-based directives to
+// check if they must be firstprivatized.
+Visit(C);
   }
 }
   }


Index: test/OpenMP/target_teams_messages.cpp
===
--- test/OpenMP/target_teams_messages.cpp
+++ test/OpenMP/target_teams_messages.cpp
@@ -50,6 +50,16 @@
 #pragma omp target teams default(none)
   ++argc; // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
 
+#pragma omp target teams default(none)
+#pragma omp parallel num_threads(argc) // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
+  ;
+
+#pragma omp target teams default(none)
+  {
+#pragma omp parallel num_threads(argc) // expected-error {{variable 'argc' must have explicitly specified data sharing attributes}}
+;
+  }
+
   goto L2; // expected-error {{use of undeclared label 'L2'}}
 #pragma omp target teams
   L2:
Index: lib/Sema/SemaOpenMP.cpp
===
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -2390,13 +2390,9 @@
   void VisitStmt(Stmt *S) {
 for (Stmt *C : S->children()) {
   if (C) {
-if (auto *OED = dyn_cast(C)) {
-  // Check implicitly captured variables in the task-based directives to
-  // check if they must be firstprivatized.
-  VisitSubCaptures(OED);
-} else {
-  Visit(C);
-}
+// Check implicitly captured variables in the task-based directives to
+// check if they must be firstprivatized.
+Visit(C);
   }
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r349635 - [OpenMP] Fix data sharing analysis in nested clause

2018-12-19 Thread Joel E. Denny via cfe-commits
Author: jdenny
Date: Wed Dec 19 07:59:47 2018
New Revision: 349635

URL: http://llvm.org/viewvc/llvm-project?rev=349635&view=rev
Log:
[OpenMP] Fix data sharing analysis in nested clause

Without this patch, clang doesn't complain that X needs explicit data
sharing attributes in the following:

```
 #pragma omp target teams default(none)
 {
   #pragma omp parallel num_threads(X)
 ;
 }
```

However, clang does produce that complaint after the braces are
removed.  With this patch, clang complains in both cases.

Reviewed By: ABataev

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

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/target_teams_messages.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=349635&r1=349634&r2=349635&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Dec 19 07:59:47 2018
@@ -2390,13 +2390,9 @@ public:
   void VisitStmt(Stmt *S) {
 for (Stmt *C : S->children()) {
   if (C) {
-if (auto *OED = dyn_cast(C)) {
-  // Check implicitly captured variables in the task-based directives 
to
-  // check if they must be firstprivatized.
-  VisitSubCaptures(OED);
-} else {
-  Visit(C);
-}
+// Check implicitly captured variables in the task-based directives to
+// check if they must be firstprivatized.
+Visit(C);
   }
 }
   }

Modified: cfe/trunk/test/OpenMP/target_teams_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_teams_messages.cpp?rev=349635&r1=349634&r2=349635&view=diff
==
--- cfe/trunk/test/OpenMP/target_teams_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/target_teams_messages.cpp Wed Dec 19 07:59:47 2018
@@ -50,6 +50,16 @@ int main(int argc, char **argv) {
 #pragma omp target teams default(none)
   ++argc; // expected-error {{variable 'argc' must have explicitly specified 
data sharing attributes}}
 
+#pragma omp target teams default(none)
+#pragma omp parallel num_threads(argc) // expected-error {{variable 'argc' 
must have explicitly specified data sharing attributes}}
+  ;
+
+#pragma omp target teams default(none)
+  {
+#pragma omp parallel num_threads(argc) // expected-error {{variable 'argc' 
must have explicitly specified data sharing attributes}}
+;
+  }
+
   goto L2; // expected-error {{use of undeclared label 'L2'}}
 #pragma omp target teams
   L2:


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


[PATCH] D55784: [clang-tidy] Update abseil-duration-comparison to handle macro arguments

2018-12-19 Thread Hyrum Wright via Phabricator via cfe-commits
hwright marked 2 inline comments as done.
hwright added inline comments.



Comment at: test/clang-tidy/abseil-duration-comparison.cpp:146
+#define VALUE_IF_2(e) (e)
+#define VALUE_IF(v, e, type) (v ? VALUE_IF_2(absl::To##type##Seconds(e)) : 0)
+  int a3 = VALUE_IF(1, d1, Double);

aaron.ballman wrote:
> hwright wrote:
> > aaron.ballman wrote:
> > > What if this is changed to:
> > > ```
> > > #define VALUE_IF(v, e, type) (v ? (5 > 
> > > VALUE_IF_2(absl::To##type##Seconds(e))) : 0)
> > > ```
> > This also doesn't transform.
> Fantastic, thank you! I wouldn't expect a fix-it there due to the macro 
> shenanigans, but I'm surprised it does not diagnose given that it expands to 
> basically the same thing as `a` and `a2` above: https://godbolt.org/z/D1MvGX 
> (ignore the errors but look at the macro expansion from the diagnostics).
> 
> Granted, this situation is uncommon enough, so feel free to add a FIXME 
> comment to the `a4` test case to say that it probably should be diagnosed 
> without a fix-it hint (assuming you agree).
I actually prefer not to diagnose here, mostly because I'm not sure what value 
we'd actually give without a fix-it hint.  "You are holding it wrong, but we 
can't tell you how to hold it right."

Ultimately, though, I think you are right that the number of cases this occurs 
are vanishingly small, and I'd expect folks doing these kinds of craziness to 
know what they are doing (and take responsibility thereof).  Perhaps that's 
optimistic.


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

https://reviews.llvm.org/D55784



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


[PATCH] D55552: [Sema] Better static assert diagnostics for expressions involving temporaries.

2018-12-19 Thread Clement Courbet via Phabricator via cfe-commits
courbet updated this revision to Diff 17.
courbet added a comment.

clang-format diff


Repository:
  rC Clang

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

https://reviews.llvm.org/D2

Files:
  include/clang/AST/PrettyPrinter.h
  include/clang/AST/Type.h
  lib/AST/TypePrinter.cpp
  lib/Sema/SemaTemplate.cpp
  test/SemaCXX/static-assert-cxx17.cpp
  test/SemaCXX/static-assert.cpp

Index: test/SemaCXX/static-assert.cpp
===
--- test/SemaCXX/static-assert.cpp
+++ test/SemaCXX/static-assert.cpp
@@ -76,6 +76,8 @@
   static const Tp value = v;
   typedef Tp value_type;
   typedef integral_constant type;
+  constexpr operator value_type() const noexcept { return value; }
+  constexpr value_type operator()() const noexcept { return value; }
 };
 
 template 
@@ -103,6 +105,7 @@
 } // namespace std
 
 struct ExampleTypes {
+  explicit ExampleTypes(int);
   using T = int;
   using U = float;
 };
@@ -119,6 +122,18 @@
 // expected-error@-1{{static_assert failed due to requirement 'std::is_const::value == false' "message"}}
 static_assert(!(std::is_const::value == true), "message");
 // expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value == true)' "message"}}
+static_assert(std::is_const(), "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const()' "message"}}
+static_assert(!(std::is_const()()), "message");
+// expected-error@-1{{static_assert failed due to requirement '!(std::is_const()())' "message"}}
+static_assert(std::is_same()), int>::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_same, int>::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
 
 struct BI_tag {};
 struct RAI_tag : BI_tag {};
Index: test/SemaCXX/static-assert-cxx17.cpp
===
--- test/SemaCXX/static-assert-cxx17.cpp
+++ test/SemaCXX/static-assert-cxx17.cpp
@@ -54,3 +54,44 @@
 }
 template void foo5();
 // expected-note@-1{{in instantiation of function template specialization 'foo5' requested here}}
+
+struct ExampleTypes {
+  explicit ExampleTypes(int);
+  using T = int;
+  using U = float;
+};
+
+template 
+struct X {
+  int i = 0;
+  int j = 0;
+  constexpr operator bool() const { return false; }
+};
+
+template 
+void foo6() {
+  static_assert(X());
+  // expected-error@-1{{static_assert failed due to requirement 'X()'}}
+  static_assert(X{});
+  // expected-error@-1{{static_assert failed due to requirement 'X{}'}}
+  static_assert(X{1, 2});
+  // expected-error@-1{{static_assert failed due to requirement 'X{1, 2}'}}
+  static_assert(X({1, 2}));
+  // expected-error@-1{{static_assert failed due to requirement 'X({1, 2})'}}
+  static_assert(typename T::T{0});
+  // expected-error@-1{{static_assert failed due to requirement 'int{0}'}}
+  static_assert(typename T::T(0));
+  // expected-error@-1{{static_assert failed due to requirement 'int(0)'}}
+  static_assert(sizeof(X) == 0);
+  // expected-error@-1{{static_assert failed due to requirement 'sizeof(X) == 0'}}
+  static_assert((const X *)nullptr);
+  // expected-error@-1{{static_assert failed due to requirement '(const X *)nullptr'}}
+  static_assert(static_cast *>(nullptr));
+  // expected-error@-1{{static_assert failed due to requirement 'static_cast *>(nullptr)'}}
+  static_assert((const X[]){} == nullptr);
+  // expected-error@-1{{static_assert failed due to requirement '(X const[0]){} == nullptr'}}
+  static_assert(sizeof(X().X::~X())>) == 0);
+  // expected-error@-1{{static_assert failed due to requirement 'sizeof(X) == 0'}}
+}
+template void foo6();
+// expected-note@-1{{in instantiation of function template specialization 'foo6' requested here}}
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -3122,8 +3122,10 @@
   std::string Description;
   {
 llvm::raw_string_ostream Out(Description);
-FailedBooleanConditionPrinterHelper Helper(getPrintingPolicy());
-FailedCond->printPretty(Out, &Helper, getPrintingPolicy());
+PrintingPolicy Policy = getPrintingPolicy();
+Policy.PrintCanonicalTypes = true;
+FailedBooleanConditionPrinterHelper Helper(Policy);
+FailedCond->printPretty(Out, &Helper, Policy, 0, "\n", nullptr);
   }
   return { FailedCond, Description };
 }
Index: lib/AST/TypePrinter.cpp
===
--- lib/AST/TypePrinter.cpp
+++ lib/AS

[PATCH] D55552: [Sema] Better static assert diagnostics for expressions involving temporaries.

2018-12-19 Thread Clement Courbet via Phabricator via cfe-commits
courbet updated this revision to Diff 178887.
courbet marked 2 inline comments as done.
courbet added a comment.

address review comments


Repository:
  rC Clang

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

https://reviews.llvm.org/D2

Files:
  include/clang/AST/PrettyPrinter.h
  include/clang/AST/Type.h
  lib/AST/TypePrinter.cpp
  lib/Sema/SemaTemplate.cpp
  test/SemaCXX/static-assert-cxx17.cpp
  test/SemaCXX/static-assert.cpp

Index: test/SemaCXX/static-assert.cpp
===
--- test/SemaCXX/static-assert.cpp
+++ test/SemaCXX/static-assert.cpp
@@ -76,6 +76,8 @@
   static const Tp value = v;
   typedef Tp value_type;
   typedef integral_constant type;
+  constexpr operator value_type() const noexcept { return value; }
+  constexpr value_type operator()() const noexcept { return value; }
 };
 
 template 
@@ -103,6 +105,7 @@
 } // namespace std
 
 struct ExampleTypes {
+  explicit ExampleTypes(int);
   using T = int;
   using U = float;
 };
@@ -119,6 +122,18 @@
 // expected-error@-1{{static_assert failed due to requirement 'std::is_const::value == false' "message"}}
 static_assert(!(std::is_const::value == true), "message");
 // expected-error@-1{{static_assert failed due to requirement '!(std::is_const::value == true)' "message"}}
+static_assert(std::is_const(), "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const()' "message"}}
+static_assert(!(std::is_const()()), "message");
+// expected-error@-1{{static_assert failed due to requirement '!(std::is_const()())' "message"}}
+static_assert(std::is_same()), int>::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_same, int>::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
+static_assert(std::is_const::value, "message");
+// expected-error@-1{{static_assert failed due to requirement 'std::is_const::value' "message"}}
 
 struct BI_tag {};
 struct RAI_tag : BI_tag {};
Index: test/SemaCXX/static-assert-cxx17.cpp
===
--- test/SemaCXX/static-assert-cxx17.cpp
+++ test/SemaCXX/static-assert-cxx17.cpp
@@ -54,3 +54,44 @@
 }
 template void foo5();
 // expected-note@-1{{in instantiation of function template specialization 'foo5' requested here}}
+
+struct ExampleTypes {
+  explicit ExampleTypes(int);
+  using T = int;
+  using U = float;
+};
+
+template 
+struct X {
+  int i = 0;
+  int j = 0;
+  constexpr operator bool() const { return false; }
+};
+
+template 
+void foo6() {
+  static_assert(X());
+  // expected-error@-1{{static_assert failed due to requirement 'X()'}}
+  static_assert(X{});
+  // expected-error@-1{{static_assert failed due to requirement 'X{}'}}
+  static_assert(X{1, 2});
+  // expected-error@-1{{static_assert failed due to requirement 'X{1, 2}'}}
+  static_assert(X({1, 2}));
+  // expected-error@-1{{static_assert failed due to requirement 'X({1, 2})'}}
+  static_assert(typename T::T{0});
+  // expected-error@-1{{static_assert failed due to requirement 'int{0}'}}
+  static_assert(typename T::T(0));
+  // expected-error@-1{{static_assert failed due to requirement 'int(0)'}}
+  static_assert(sizeof(X) == 0);
+  // expected-error@-1{{static_assert failed due to requirement 'sizeof(X) == 0'}}
+  static_assert((const X *)nullptr);
+  // expected-error@-1{{static_assert failed due to requirement '(const X *)nullptr'}}
+  static_assert(static_cast *>(nullptr));
+  // expected-error@-1{{static_assert failed due to requirement 'static_cast *>(nullptr)'}}
+  static_assert((const X[]){} == nullptr);
+  // expected-error@-1{{static_assert failed due to requirement '(X const[0]){} == nullptr'}}
+  static_assert(sizeof(X().X::~X())>) == 0);
+  // expected-error@-1{{static_assert failed due to requirement 'sizeof(X) == 0'}}
+}
+template void foo6();
+// expected-note@-1{{in instantiation of function template specialization 'foo6' requested here}}
Index: lib/Sema/SemaTemplate.cpp
===
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -3122,8 +3122,10 @@
   std::string Description;
   {
 llvm::raw_string_ostream Out(Description);
-FailedBooleanConditionPrinterHelper Helper(getPrintingPolicy());
-FailedCond->printPretty(Out, &Helper, getPrintingPolicy());
+PrintingPolicy Policy = getPrintingPolicy();
+Policy.PrintCanonicalTypes = true;
+FailedBooleanConditionPrinterHelper Helper(Policy);
+FailedCond->printPretty(Out, &Helper, Policy, 0, "\n", nullptr);
   }
   return { FailedCond, Description };
 }
Index: lib/AST/TypePrinter.cpp
==

[PATCH] D55552: [Sema] Better static assert diagnostics for expressions involving temporaries.

2018-12-19 Thread Clement Courbet via Phabricator via cfe-commits
courbet marked 6 inline comments as done.
courbet added inline comments.



Comment at: lib/AST/TypePrinter.cpp:165
 
+static SplitQualType splitAccordingToPolicy(QualType t,
+const PrintingPolicy &Policy) {

aaron.ballman wrote:
> `t` doesn't meet the usual naming requirements; how about `QT`?
I was keeping it for consistency with `TypePrinter::print(QualType t,`, but 
done.



Comment at: lib/Sema/SemaTemplate.cpp:3062
 public:
-  explicit FailedBooleanConditionPrinterHelper(const PrintingPolicy &P)
-  : Policy(P) {}
+  FailedBooleanConditionPrinterHelper(const PrintingPolicy &P) : Policy(P) {}
 

aaron.ballman wrote:
> Why are you dropping the `explicit` here?
Sorry, this is a revert of an approach where it had two parameters.


Repository:
  rC Clang

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

https://reviews.llvm.org/D2



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


[PATCH] D55363: [clangd] Expose FileStatus in LSP.

2018-12-19 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Could we add a capability to the init request to check for this extension? We 
don't want to send those notifications to clients that don't have the code to 
handle them.

Another observation: when I played around with the previous version of the 
patch, `RunningAction` and `BuildingAST` where constantly "blinking", i.e. it 
changes faster than I can read it.
This lead to them being irritating and not providing any actual value.

Maybe consider sending an update after some period of time, e.g. `0.5s`? (I 
expect this particular strategy to be a bit complicated and out of scope of 
this patch, so another alternative is to simply not send them to the clients in 
the first version). WDYT?




Comment at: clangd/ClangdLSPServer.cpp:806
+void ClangdLSPServer::onFileUpdated(PathRef File, const TUStatus &Status) {
+  notify("textDocument/clangd.fileStatus", Status.render(File));
+}

It's somewhat easy to miss the `clangd` in the middle, would personally prefer 
the `clangd.textDocument/fileStatus`. But up to you.




Comment at: clangd/Protocol.h:999
+  /// Details of the state that are worth sufacing to users.
+  std::vector details;
+};

Why not `vector`? What's the use of the `MessageType`?



Comment at: clangd/TUScheduler.cpp:741
+  case TUAction::Queued:
+OS << "Queued";
+break;

Maybe start with a lower case? 
Arguably `clangd: queued` looks more natural than `clangd: Queued`

Also consider maybe change this to `file is queued` to make it clear it's not 
clangd that's queuing up somewhere.



Comment at: clangd/TUScheduler.cpp:744
+  case TUAction::RunningAction:
+OS << "RunningAction"
+   << "(" << Action.Name << ")";

Maybe make it `running ${action name}`, e.g. `running find references`?


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D55363



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


  1   2   >