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

2018-08-03 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

In https://reviews.llvm.org/D48903#1188437, @malaperle wrote:

> In https://reviews.llvm.org/D48903#1187605, @simark wrote:
>
> > If somebody else could run the tests on Windows, it would make me a bit 
> > more confident too.
>
>
> Which tests/targets exactly? If you know


NVM, I saw the "check-clang and check-clang-tools" above.


Repository:
  rC Clang

https://reviews.llvm.org/D48903



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


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

2018-08-03 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete updated this revision to Diff 159160.
Rakete added a comment.

Add missing test cases. :)


Repository:
  rC Clang

https://reviews.llvm.org/D50291

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaDeclCXX.cpp
  test/CXX/special/class.copy/p10.cpp

Index: test/CXX/special/class.copy/p10.cpp
===
--- /dev/null
+++ test/CXX/special/class.copy/p10.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+// The implicitly-defined copy/move assignment operator is constexpr if
+// - X is a literal type, and
+// - [...]
+//
+// PR38143: Order of defaulted special members matters.
+struct X {
+  constexpr X() = default;
+  constexpr X(const X &) = default;
+  constexpr X =(const X &) = default;
+  ~X() = default;
+  constexpr X(X &&) = default;
+  constexpr X =(X &&) = default;
+};
+
+struct Y {
+  constexpr Y =(const Y &) = default;
+  constexpr Y =(Y &&) = default;
+  constexpr Y() = default;
+  constexpr Y(const Y &) = default;
+  ~Y() = default;
+  constexpr Y(Y &&) = default;
+};
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -6020,6 +6020,7 @@
 
   bool HasMethodWithOverrideControl = false,
HasOverridingMethodWithoutOverrideControl = false;
+  CXXMethodDecl *CopyAssignment = nullptr, *MoveAssignment = nullptr;
   if (!Record->isDependentType()) {
 for (auto *M : Record->methods()) {
   // See if a method overloads virtual methods in a base
@@ -6049,6 +6050,11 @@
 }
   }
 
+  if (CSM == CXXCopyAssignment)
+CopyAssignment = M;
+  else if (CSM == CXXMoveAssignment)
+MoveAssignment = M;
+
   // Set triviality for the purpose of calls if this is a user-provided
   // copy/move constructor or destructor.
   if ((CSM == CXXCopyConstructor || CSM == CXXMoveConstructor ||
@@ -6071,6 +6077,22 @@
 }
   }
 }
+
+// Now we can decide whether the special members are constexpr.
+auto ActOnSpecialMember = [this, ](CXXMethodDecl *MD) {
+  if (!MD->isInvalidDecl() && MD->isExplicitlyDefaulted()) {
+CheckExplicitlyDefaultedSpecialMemberConstexpr(MD);
+Record->finishedDefaultedOrDeletedMember(MD);
+  }
+};
+for (auto *M : Record->ctors())
+  ActOnSpecialMember(M);
+if (CopyAssignment)
+  ActOnSpecialMember(CopyAssignment);
+if (MoveAssignment)
+  ActOnSpecialMember(MoveAssignment);
+if (CXXDestructorDecl *CD = Record->getDestructor())
+  ActOnSpecialMember(CD);
   }
 
   if (HasMethodWithOverrideControl &&
@@ -6532,20 +6554,8 @@
   // C++11 [dcl.fct.def.default]p2:
   //   An explicitly-defaulted function may be declared constexpr only if it
   //   would have been implicitly declared as constexpr,
-  // Do not apply this rule to members of class templates, since core issue 1358
-  // makes such functions always instantiate to constexpr functions. For
-  // functions which cannot be constexpr (for non-constructors in C++11 and for
-  // destructors in C++1y), this is checked elsewhere.
-  bool Constexpr = defaultedSpecialMemberIsConstexpr(*this, RD, CSM,
- HasConstParam);
-  if ((getLangOpts().CPlusPlus14 ? !isa(MD)
- : isa(MD)) &&
-  MD->isConstexpr() && !Constexpr &&
-  MD->getTemplatedKind() == FunctionDecl::TK_NonTemplate) {
-Diag(MD->getLocStart(), diag::err_incorrect_defaulted_constexpr) << CSM;
-// FIXME: Explain why the special member can't be constexpr.
-HadError = true;
-  }
+  // We need to delay this, because at this point we may not have enough
+  // information to determine if MD is really constexpr or not.
 
   //   and may have an explicit exception-specification only if it is compatible
   //   with the exception-specification on the implicit declaration.
@@ -6568,8 +6578,6 @@
   if (First) {
 //  -- it is implicitly considered to be constexpr if the implicit
 // definition would be,
-MD->setConstexpr(Constexpr);
-
 //  -- it is implicitly considered to have the same exception-specification
 // as if it had been implicitly declared,
 FunctionProtoType::ExtProtoInfo EPI = Type->getExtProtoInfo();
@@ -6598,6 +6606,39 @@
 MD->setInvalidDecl();
 }
 
+void Sema::CheckExplicitlyDefaultedSpecialMemberConstexpr(CXXMethodDecl *MD) {
+  CXXSpecialMember CSM = getSpecialMember(MD);
+  assert(MD && MD->isExplicitlyDefaulted() && CSM != CXXInvalid &&
+ "not an explicitly-defaulted special member");
+
+  const FunctionProtoType *Type = MD->getType()->getAs();
+
+  unsigned ExpectedParams =
+  CSM != CXXDefaultConstructor && CSM != CXXDestructor;
+  QualType ArgType = ExpectedParams ? Type->getParamType(0) : QualType();
+
+  bool HasConstParam = ExpectedParams && ArgType->isReferenceType() &&

[PATCH] D50205: [libc++] Add availability markup for aligned new/delete

2018-08-03 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

How does this work when a user provides their own definitions? Does the 
attribute from the declaration still produce a warning? If so, then I think an 
in-compiler approach is better.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50205



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


[PATCH] D50214: Add inherited attributes before parsed attributes.

2018-08-03 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

For this patch the goal is to have the attributes in the AST in an order that 
is less surprising to consumers (including out-of-tree). If we change it now, 
new/revised code/diagnostics will be written to match this order.

I agree that ideally, most attributes (exceptions are e.g. `enable_if`) should 
be more like a set than a list, but I don't think we can get rid of the 
'ordered-ness' in general.

I though about ordering by SourceLocation as well and could be implemented like 
this:
Add all SLoc's sequences for two SourceLocation to lists. Start comparing from 
the bottom (=> the translation units) until there is a difference.

However, I dislike the idea that the result could potentially depend on 
SourceLocation that previously was only used when emitting diagnostics.




Comment at: test/Misc/ast-dump-attr.cpp:228-230
+// CHECK-NEXT: DeprecatedAttr{{.*}} Inherited
+// CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited
+// CHECK-NEXT: AnnotateAttr{{.*}} Inherited

Note that before rC338800, these were mixed-up (not even the reverse order)



Comment at: test/Sema/attr-availability-ios.c:10
 void f5(int) __attribute__((availability(ios,introduced=2.0))) 
__attribute__((availability(ios,deprecated=3.0))); // expected-note {{'f5' has 
been explicitly marked deprecated here}}
-void f6(int) __attribute__((availability(ios,deprecated=3.0)));
-void f6(int) __attribute__((availability(iOS,introduced=2.0))); // 
expected-note {{'f6' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(ios,deprecated=3.0))); // 
expected-note {{'f6' has been explicitly marked deprecated here}}
+void f6(int) __attribute__((availability(iOS,introduced=2.0)));

Note that the deprecated marker moved to the line that actually declares the 
function as deprecated.


Repository:
  rC Clang

https://reviews.llvm.org/D50214



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


[PATCH] D49355: Thread safety analysis: Allow lock upgrading and downgrading

2018-08-03 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

This change broke the acquire+release case. Concretely, in Flutter we have this 
code: 
https://github.com/flutter/engine/blob/master/lib/ui/isolate_name_server/isolate_name_server.h#L26.
 This worked fine previously, but after this change we're getting an error in 
https://github.com/flutter/engine/blob/master/lib/ui/isolate_name_server/isolate_name_server_natives.cc#L19
 and many other places like this one:

  
../../third_party/flutter/lib/ui/isolate_name_server/isolate_name_server_natives.cc:19:33:
 error: releasing mutex 'name_server->mutex_' that was not held 
[-Werror,-Wthread-safety-analysis]
Dart_Port port = name_server->LookupIsolatePortByName(name);
  ^
  
../../third_party/flutter/lib/ui/isolate_name_server/isolate_name_server_natives.cc:24:1:
 error: mutex 'name_server->mutex_' is still held at the end of function 
[-Werror,-Wthread-safety-analysis]
  }
  ^
  
../../third_party/flutter/lib/ui/isolate_name_server/isolate_name_server_natives.cc:19:33:
 note: mutex acquired here
Dart_Port port = name_server->LookupIsolatePortByName(name);

Would it be possible revert this change? The old logic was "all acquires; then 
all releases" and the new logic is "all releases; then all acquires" but I 
think this needs fancier logic with actual bookkeeping to detect the upgrade 
case without breaking the acquire+release case.


Repository:
  rC Clang

https://reviews.llvm.org/D49355



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


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

2018-08-03 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

In https://reviews.llvm.org/D48903#1187605, @simark wrote:

> If somebody else could run the tests on Windows, it would make me a bit more 
> confident too.


Which tests/targets exactly? If you know


Repository:
  rC Clang

https://reviews.llvm.org/D48903



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


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

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

Yay thx! Yeah, that's the best behavior i can imagine here.


Repository:
  rC Clang

https://reviews.llvm.org/D50211



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


[clang-tools-extra] r338947 - [clangd] Fix fuzzer build.

2018-08-03 Thread Matt Morehouse via cfe-commits
Author: morehouse
Date: Fri Aug  3 18:51:10 2018
New Revision: 338947

URL: http://llvm.org/viewvc/llvm-project?rev=338947=rev
Log:
[clangd] Fix fuzzer build.

Modified:
clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp

Modified: clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp?rev=338947=338946=338947=diff
==
--- clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp (original)
+++ clang-tools-extra/trunk/clangd/fuzzer/ClangdFuzzer.cpp Fri Aug  3 18:51:10 
2018
@@ -30,7 +30,8 @@ extern "C" int LLVMFuzzerTestOneInput(ui
   clang::clangd::ClangdServer::Options Opts;
 
   // Initialize and run ClangdLSPServer.
-  clang::clangd::ClangdLSPServer LSPServer(Out, CCOpts, llvm::None, Opts);
+  clang::clangd::ClangdLSPServer LSPServer(Out, CCOpts, llvm::None, false,
+   Opts);
   // fmemopen isn't portable, but I think we only run the fuzzer on Linux.
   LSPServer.run(fmemopen(data, size, "r"));
   return 0;


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


r338946 - [clang-fuzzer] Remove unused typedef.

2018-08-03 Thread Matt Morehouse via cfe-commits
Author: morehouse
Date: Fri Aug  3 18:42:47 2018
New Revision: 338946

URL: http://llvm.org/viewvc/llvm-project?rev=338946=rev
Log:
[clang-fuzzer] Remove unused typedef.

Modified:
cfe/trunk/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp

Modified: cfe/trunk/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp?rev=338946=338945=338946=diff
==
--- cfe/trunk/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp (original)
+++ cfe/trunk/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp Fri Aug  3 
18:42:47 2018
@@ -160,7 +160,6 @@ static void CreateAndRunJITFunc(const st
   EE->finalizeObject();
   EE->runStaticConstructorsDestructors(false);
 
-  typedef void (*func)(int*, int*, int*, int);
 #if defined(__GNUC__) && !defined(__clang) &&  
\
 ((__GNUC__ == 4) && (__GNUC_MINOR__ < 9))
 // Silence
@@ -173,7 +172,7 @@ static void CreateAndRunJITFunc(const st
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wpedantic"
 #endif
-  LLVMFunc f = 
reinterpret_cast(EE->getPointerToFunction(EntryFunc)); 
+  LLVMFunc f = reinterpret_cast(EE->getPointerToFunction(EntryFunc));
 #if defined(__GNUC__) && !defined(__clang) &&  
\
 ((__GNUC__ == 4) && (__GNUC_MINOR__ < 9))
 #pragma GCC diagnostic pop


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


[PATCH] D50286: avoid creating conditional cleanup blocks that contain only @llvm.lifetime.end calls

2018-08-03 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
rsmith marked an inline comment as done.
Closed by commit rC338945: Avoid creating conditional cleanup blocks that 
contain only @llvm.lifetime.end… (authored by rsmith, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D50286

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGenCXX/conditional-temporaries.cpp
  test/CodeGenCXX/lifetime-asan.cpp

Index: test/CodeGenCXX/lifetime-asan.cpp
===
--- test/CodeGenCXX/lifetime-asan.cpp
+++ test/CodeGenCXX/lifetime-asan.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 %s | FileCheck %s -check-prefixes=CHECK,CHECK-O0 --implicit-check-not=llvm.lifetime
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
+// RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
+// RUN: FileCheck %s -check-prefixes=CHECK,CHECK-ASAN-USE-AFTER-SCOPE
+
+extern int bar(char *A, int n);
+
+struct X { X(); ~X(); int *p; };
+struct Y { Y(); int *p; };
+
+extern "C" void a(), b(), c(), d();
+
+// CHECK-LABEL: @_Z3foo
+void foo(int n) {
+  // CHECK: call void @a()
+  a();
+
+  // CHECK: call void @b()
+  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 false
+  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 false
+  // CHECK: br i1
+  //
+  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.start
+  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 true
+  // CHECK: call void @_ZN1XC
+  // CHECK: br label
+  //
+  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.start
+  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 true
+  // CHECK: call void @_ZN1YC
+  // CHECK: br label
+  //
+  // CHECK: call void @c()
+  // CHECK-ASAN-USE-AFTER-SCOPE: br i1
+  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.end
+  // CHECK-ASAN-USE-AFTER-SCOPE: br i1
+  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.end
+  b(), (n ? X().p : Y().p), c();
+
+  // CHECK: call void @d()
+  d();
+}
Index: test/CodeGenCXX/conditional-temporaries.cpp
===
--- test/CodeGenCXX/conditional-temporaries.cpp
+++ test/CodeGenCXX/conditional-temporaries.cpp
@@ -1,6 +1,7 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O3 | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=amdgcn-amd-amdhsa -O3 | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,CHECK-NOOPT
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 | FileCheck %s --check-prefixes=CHECK,CHECK-OPT
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=amdgcn-amd-amdhsa -O2 | FileCheck %s --check-prefixes=CHECK,CHECK-OPT
 
 namespace {
 
@@ -38,20 +39,167 @@
 
 }
 
-// CHECK-LABEL: define i32 @_Z12getCtorCallsv()
+// CHECK-OPT-LABEL: define i32 @_Z12getCtorCallsv()
 int getCtorCalls() {
-  // CHECK: ret i32 5
+  // CHECK-OPT: ret i32 5
   return ctorcalls;
 }
 
-// CHECK-LABEL: define i32 @_Z12getDtorCallsv()
+// CHECK-OPT-LABEL: define i32 @_Z12getDtorCallsv()
 int getDtorCalls() {
-  // CHECK: ret i32 5
+  // CHECK-OPT: ret i32 5
   return dtorcalls;
 }
 
-// CHECK-LABEL: define zeroext i1 @_Z7successv()
+// CHECK-OPT-LABEL: define zeroext i1 @_Z7successv()
 bool success() {
-  // CHECK: ret i1 true
+  // CHECK-OPT: ret i1 true
   return ctorcalls == dtorcalls;
 }
+
+struct X { ~X(); int f(); };
+int g(int, int, int);
+// CHECK-LABEL: @_Z16lifetime_nontriv
+int lifetime_nontriv(bool cond) {
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: br i1
+  //
+  // CHECK-NOOPT: call void @llvm.lifetime.start
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: call i32 @_ZN1X1fEv(
+  // CHECK-NOOPT: call void @llvm.lifetime.start
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: call i32 @_ZN1X1fEv(
+  // CHECK-NOOPT: call void @llvm.lifetime.start
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: call i32 @_ZN1X1fEv(
+  // CHECK-NOOPT: call i32 @_Z1giii(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: call i32 @_Z1giii(i32 1, i32 2, i32 3)
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @_ZN1XD1Ev(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @llvm.lifetime.end
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @_ZN1XD1Ev(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @llvm.lifetime.end
+  

r338945 - Avoid creating conditional cleanup blocks that contain only @llvm.lifetime.end calls

2018-08-03 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Aug  3 18:25:06 2018
New Revision: 338945

URL: http://llvm.org/viewvc/llvm-project?rev=338945=rev
Log:
Avoid creating conditional cleanup blocks that contain only @llvm.lifetime.end 
calls

When a non-extended temporary object is created in a conditional branch, the
lifetime of that temporary ends outside the conditional (at the end of the
full-expression). If we're inserting lifetime markers, this means we could end
up generating

  if (some_cond) {
lifetime.start();
Tmp::Tmp();
  }
  // ...
  if (some_cond) {
lifetime.end();
  }

... for a full-expression containing a subexpression of the form `some_cond ?
Tmp().x : 0`. This patch moves the lifetime start for such a temporary out of
the conditional branch so that we don't need to generate an additional basic
block to hold the lifetime end marker.

This is disabled if we want precise lifetime markers (for asan's
stack-use-after-scope checks) or of the temporary has a non-trivial destructor
(in which case we'd generate an extra basic block anyway to hold the destructor
call).

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

Added:
cfe/trunk/test/CodeGenCXX/lifetime-asan.cpp
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGenCXX/conditional-temporaries.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=338945=338944=338945=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Aug  3 18:25:06 2018
@@ -498,18 +498,51 @@ EmitMaterializeTemporaryExpr(const Mater
   } else {
 switch (M->getStorageDuration()) {
 case SD_Automatic:
-case SD_FullExpression:
   if (auto *Size = EmitLifetimeStart(
   CGM.getDataLayout().getTypeAllocSize(Alloca.getElementType()),
   Alloca.getPointer())) {
-if (M->getStorageDuration() == SD_Automatic)
-  pushCleanupAfterFullExpr(NormalEHLifetimeMarker,
-Alloca, Size);
-else
-  pushFullExprCleanup(NormalEHLifetimeMarker, Alloca,
-   Size);
+pushCleanupAfterFullExpr(NormalEHLifetimeMarker,
+  Alloca, Size);
   }
   break;
+
+case SD_FullExpression: {
+  if (!ShouldEmitLifetimeMarkers)
+break;
+
+  // Avoid creating a conditional cleanup just to hold an llvm.lifetime.end
+  // marker. Instead, start the lifetime of a conditional temporary earlier
+  // so that it's unconditional. Don't do this in ASan's use-after-scope
+  // mode so that it gets the more precise lifetime marks. If the type has
+  // a non-trivial destructor, we'll have a cleanup block for it anyway,
+  // so this typically doesn't help; skip it in that case.
+  ConditionalEvaluation *OldConditional = nullptr;
+  CGBuilderTy::InsertPoint OldIP;
+  if (isInConditionalBranch() && !E->getType().isDestructedType() &&
+  !CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) {
+OldConditional = OutermostConditional;
+OutermostConditional = nullptr;
+
+OldIP = Builder.saveIP();
+llvm::BasicBlock *Block = OldConditional->getStartingBlock();
+Builder.restoreIP(CGBuilderTy::InsertPoint(
+Block, llvm::BasicBlock::iterator(Block->back(;
+  }
+
+  if (auto *Size = EmitLifetimeStart(
+  CGM.getDataLayout().getTypeAllocSize(Alloca.getElementType()),
+  Alloca.getPointer())) {
+pushFullExprCleanup(NormalEHLifetimeMarker, Alloca,
+ Size);
+  }
+
+  if (OldConditional) {
+OutermostConditional = OldConditional;
+Builder.restoreIP(OldIP);
+  }
+  break;
+}
+
 default:
   break;
 }

Modified: cfe/trunk/test/CodeGenCXX/conditional-temporaries.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/conditional-temporaries.cpp?rev=338945=338944=338945=diff
==
--- cfe/trunk/test/CodeGenCXX/conditional-temporaries.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/conditional-temporaries.cpp Fri Aug  3 18:25:06 
2018
@@ -1,6 +1,7 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O3 | 
FileCheck %s
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=amdgcn-amd-amdhsa -O3 | 
FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 
-disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,CHECK-NOOPT
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 | 
FileCheck %s --check-prefixes=CHECK,CHECK-OPT
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=amdgcn-amd-amdhsa -O2 | 
FileCheck 

[PATCH] D50286: avoid creating conditional cleanup blocks that contain only @llvm.lifetime.end calls

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

LGTM.


https://reviews.llvm.org/D50286



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


[PATCH] D50286: avoid creating conditional cleanup blocks that contain only @llvm.lifetime.end calls

2018-08-03 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith marked an inline comment as done.
rsmith added inline comments.



Comment at: lib/CodeGen/CGExpr.cpp:521
+  CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  !CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) {
+OldConditional = OutermostConditional;

rjmccall wrote:
> Why only when optimization is enabled?  This seems like a nice improvement 
> regardless.
> 
> Also, please mention why this is disabled for destructed types in the 
> comment, not just the commit message.
The `OptimizationLevel` check is dead anyway (we don't emit lifetime markers 
unless we're optimizing or in use-after-scope mode). Removed.


https://reviews.llvm.org/D50286



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


[PATCH] D50286: avoid creating conditional cleanup blocks that contain only @llvm.lifetime.end calls

2018-08-03 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith updated this revision to Diff 159153.

https://reviews.llvm.org/D50286

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGenCXX/conditional-temporaries.cpp
  test/CodeGenCXX/lifetime-asan.cpp

Index: test/CodeGenCXX/lifetime-asan.cpp
===
--- test/CodeGenCXX/lifetime-asan.cpp
+++ test/CodeGenCXX/lifetime-asan.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 %s | FileCheck %s -check-prefixes=CHECK,CHECK-O0 --implicit-check-not=llvm.lifetime
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
+// RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
+// RUN: FileCheck %s -check-prefixes=CHECK,CHECK-ASAN-USE-AFTER-SCOPE
+
+extern int bar(char *A, int n);
+
+struct X { X(); ~X(); int *p; };
+struct Y { Y(); int *p; };
+
+extern "C" void a(), b(), c(), d();
+
+// CHECK-LABEL: @_Z3foo
+void foo(int n) {
+  // CHECK: call void @a()
+  a();
+
+  // CHECK: call void @b()
+  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 false
+  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 false
+  // CHECK: br i1
+  //
+  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.start
+  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 true
+  // CHECK: call void @_ZN1XC
+  // CHECK: br label
+  //
+  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.start
+  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 true
+  // CHECK: call void @_ZN1YC
+  // CHECK: br label
+  //
+  // CHECK: call void @c()
+  // CHECK-ASAN-USE-AFTER-SCOPE: br i1
+  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.end
+  // CHECK-ASAN-USE-AFTER-SCOPE: br i1
+  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.end
+  b(), (n ? X().p : Y().p), c();
+
+  // CHECK: call void @d()
+  d();
+}
Index: test/CodeGenCXX/conditional-temporaries.cpp
===
--- test/CodeGenCXX/conditional-temporaries.cpp
+++ test/CodeGenCXX/conditional-temporaries.cpp
@@ -1,6 +1,7 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O3 | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=amdgcn-amd-amdhsa -O3 | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,CHECK-NOOPT
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 | FileCheck %s --check-prefixes=CHECK,CHECK-OPT
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=amdgcn-amd-amdhsa -O2 | FileCheck %s --check-prefixes=CHECK,CHECK-OPT
 
 namespace {
 
@@ -38,20 +39,167 @@
 
 }
 
-// CHECK-LABEL: define i32 @_Z12getCtorCallsv()
+// CHECK-OPT-LABEL: define i32 @_Z12getCtorCallsv()
 int getCtorCalls() {
-  // CHECK: ret i32 5
+  // CHECK-OPT: ret i32 5
   return ctorcalls;
 }
 
-// CHECK-LABEL: define i32 @_Z12getDtorCallsv()
+// CHECK-OPT-LABEL: define i32 @_Z12getDtorCallsv()
 int getDtorCalls() {
-  // CHECK: ret i32 5
+  // CHECK-OPT: ret i32 5
   return dtorcalls;
 }
 
-// CHECK-LABEL: define zeroext i1 @_Z7successv()
+// CHECK-OPT-LABEL: define zeroext i1 @_Z7successv()
 bool success() {
-  // CHECK: ret i1 true
+  // CHECK-OPT: ret i1 true
   return ctorcalls == dtorcalls;
 }
+
+struct X { ~X(); int f(); };
+int g(int, int, int);
+// CHECK-LABEL: @_Z16lifetime_nontriv
+int lifetime_nontriv(bool cond) {
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: br i1
+  //
+  // CHECK-NOOPT: call void @llvm.lifetime.start
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: call i32 @_ZN1X1fEv(
+  // CHECK-NOOPT: call void @llvm.lifetime.start
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: call i32 @_ZN1X1fEv(
+  // CHECK-NOOPT: call void @llvm.lifetime.start
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: call i32 @_ZN1X1fEv(
+  // CHECK-NOOPT: call i32 @_Z1giii(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: call i32 @_Z1giii(i32 1, i32 2, i32 3)
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @_ZN1XD1Ev(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @llvm.lifetime.end
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @_ZN1XD1Ev(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @llvm.lifetime.end
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @_ZN1XD1Ev(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call 

[PATCH] D50194: LLVM Proto Fuzzer - Run Functions on Suite of Inputs

2018-08-03 Thread Emmett Neyman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC338943: LLVM Proto Fuzzer - Run Functions on Suite of Inputs 
(authored by emmettneyman, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50194?vs=159151=159152#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50194

Files:
  tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  tools/clang-fuzzer/handle-llvm/handle_llvm.h
  tools/clang-fuzzer/handle-llvm/input_arrays.h

Index: tools/clang-fuzzer/handle-llvm/input_arrays.h
===
--- tools/clang-fuzzer/handle-llvm/input_arrays.h
+++ tools/clang-fuzzer/handle-llvm/input_arrays.h
@@ -0,0 +1,118 @@
+//==-- input_arrays.h - Helper function for LLVM fuzzer inputs -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Define a few static variables used by the LLVM Proto Fuzzer
+//
+//===--===//
+
+#include 
+
+static const int kArraySize = 64;
+static const int kNumArrays = 93;
+static const int kTotalSize = sizeof(int) * kArraySize * kNumArrays;
+
+// Define two arrays that will hold the input and output for the two functions
+static int OptArrays[kNumArrays][kArraySize];
+static int UnoptArrays[kNumArrays][kArraySize];
+
+// Define a corpus of possible inputs
+static int InputArrays[kNumArrays][kArraySize] =
+{ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+  {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
+  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+  {INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX},
+  {INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN},
+  {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
+  {16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16},
+  {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
+  {1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 

r338943 - LLVM Proto Fuzzer - Run Functions on Suite of Inputs

2018-08-03 Thread Emmett Neyman via cfe-commits
Author: emmettneyman
Date: Fri Aug  3 18:18:37 2018
New Revision: 338943

URL: http://llvm.org/viewvc/llvm-project?rev=338943=rev
Log:
LLVM Proto Fuzzer - Run Functions on Suite of Inputs

Summary:
Added corpus of arrays to use as inputs for the functions. Check that the two
functions modify the inputted arrays in the same way.

Reviewers: kcc, morehouse

Reviewed By: morehouse

Subscribers: mgorny, cfe-commits, llvm-commits

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

Added:
cfe/trunk/tools/clang-fuzzer/handle-llvm/input_arrays.h
Modified:
cfe/trunk/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
cfe/trunk/tools/clang-fuzzer/handle-llvm/handle_llvm.h

Modified: cfe/trunk/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp?rev=338943=338942=338943=diff
==
--- cfe/trunk/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp (original)
+++ cfe/trunk/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp Fri Aug  3 
18:18:37 2018
@@ -15,6 +15,7 @@
 
//===--===//
 
 #include "handle_llvm.h"
+#include "input_arrays.h"
 
 #include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
@@ -48,6 +49,9 @@
 
 using namespace llvm;
 
+// Define a type for the functions that are compiled and executed
+typedef void (*LLVMFunc)(int*, int*, int*, int);
+
 // Helper function to parse command line args and find the optimization level
 static void getOptLevel(const std::vector ,
   CodeGenOpt::Level ) {
@@ -68,7 +72,7 @@ static void getOptLevel(const std::vecto
   }
 }
 
-void ErrorAndExit(std::string message) {
+static void ErrorAndExit(std::string message) {
   errs()<< "ERROR: " << message << "\n";
   std::exit(1);
 }
@@ -88,7 +92,7 @@ static void AddOptimizationPasses(legacy
 }
 
 // Mimics the opt tool to run an optimization pass over the provided IR
-std::string OptLLVM(const std::string , CodeGenOpt::Level OLvl) {
+static std::string OptLLVM(const std::string , CodeGenOpt::Level OLvl) {
   // Create a module that will run the optimization passes
   SMDiagnostic Err;
   LLVMContext Context;
@@ -117,11 +121,19 @@ std::string OptLLVM(const std::string 
   return OS.str();
 }
 
-void CreateAndRunJITFun(const std::string , CodeGenOpt::Level OLvl) {
+// Takes a function and runs it on a set of inputs
+// First determines whether f is the optimized or unoptimized function
+static void RunFuncOnInputs(LLVMFunc f, int Arr[kNumArrays][kArraySize]) {
+  for (int i = 0; i < kNumArrays / 3; i++)
+f(Arr[i], Arr[i + (kNumArrays / 3)], Arr[i + (2 * kNumArrays / 3)],
+  kArraySize);
+}
+
+// Takes a string of IR and compiles it using LLVM's JIT Engine
+static void CreateAndRunJITFunc(const std::string , CodeGenOpt::Level OLvl) 
{
   SMDiagnostic Err;
   LLVMContext Context;
-  std::unique_ptr M = parseIR(MemoryBufferRef(IR, "IR"), Err,
-  Context);
+  std::unique_ptr M = parseIR(MemoryBufferRef(IR, "IR"), Err, Context);
   if (!M)
 ErrorAndExit("Could not parse IR");
 
@@ -161,17 +173,14 @@ void CreateAndRunJITFun(const std::strin
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wpedantic"
 #endif
-  func f = reinterpret_cast(EE->getPointerToFunction(EntryFunc));
+  LLVMFunc f = 
reinterpret_cast(EE->getPointerToFunction(EntryFunc)); 
 #if defined(__GNUC__) && !defined(__clang) &&  
\
 ((__GNUC__ == 4) && (__GNUC_MINOR__ < 9))
 #pragma GCC diagnostic pop
 #endif
 
-  // Define some dummy arrays to use an input for now
-  int a[] = {1};
-  int b[] = {1};
-  int c[] = {1};
-  f(a, b, c, 1);
+  // Figure out if we are running the optimized func or the unoptimized func
+  RunFuncOnInputs(f, (OLvl == CodeGenOpt::None) ? UnoptArrays : OptArrays);
 
   EE->runStaticConstructorsDestructors(true);
 }
@@ -180,6 +189,10 @@ void CreateAndRunJITFun(const std::strin
 // Mimics the lli tool to JIT the LLVM IR code and execute it
 void clang_fuzzer::HandleLLVM(const std::string ,
   const std::vector ) {
+  // Populate OptArrays and UnoptArrays with the arrays from InputArrays
+  memcpy(OptArrays, InputArrays, kTotalSize);
+  memcpy(UnoptArrays, InputArrays, kTotalSize);
+
   // Parse ExtraArgs to set the optimization level
   CodeGenOpt::Level OLvl;
   getOptLevel(ExtraArgs, OLvl);
@@ -187,8 +200,11 @@ void clang_fuzzer::HandleLLVM(const std:
   // First we optimize the IR by running a loop vectorizer pass
   std::string OptIR = OptLLVM(IR, OLvl);
 
-  CreateAndRunJITFun(OptIR, OLvl);
-  CreateAndRunJITFun(IR, CodeGenOpt::None);
-  
+  CreateAndRunJITFunc(OptIR, OLvl);
+  CreateAndRunJITFunc(IR, CodeGenOpt::None);
+
+  if (memcmp(OptArrays, UnoptArrays, kTotalSize))
+ErrorAndExit("!!!BUG!!!");
+
   return;
 }

Modified: 

[PATCH] D50194: LLVM Proto Fuzzer - Run Functions on Suite of Inputs

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

ready to land


Repository:
  rC Clang

https://reviews.llvm.org/D50194

Files:
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.h
  clang/tools/clang-fuzzer/handle-llvm/input_arrays.h

Index: clang/tools/clang-fuzzer/handle-llvm/input_arrays.h
===
--- /dev/null
+++ clang/tools/clang-fuzzer/handle-llvm/input_arrays.h
@@ -0,0 +1,118 @@
+//==-- input_arrays.h - Helper function for LLVM fuzzer inputs -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Define a few static variables used by the LLVM Proto Fuzzer
+//
+//===--===//
+
+#include 
+
+static const int kArraySize = 64;
+static const int kNumArrays = 93;
+static const int kTotalSize = sizeof(int) * kArraySize * kNumArrays;
+
+// Define two arrays that will hold the input and output for the two functions
+static int OptArrays[kNumArrays][kArraySize];
+static int UnoptArrays[kNumArrays][kArraySize];
+
+// Define a corpus of possible inputs
+static int InputArrays[kNumArrays][kArraySize] =
+{ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+  {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
+  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+  {INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX},
+  {INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN},
+  {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
+  {16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16},
+  {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
+  {1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024},
+  {65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 

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

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



Comment at: lib/CodeGen/CGExprConstant.cpp:2123
+// This means that the array type is probably "IncompleteType" or some
+// type that is not ConstantArray.
+if (CAT == nullptr && CommonElementType == nullptr && !NumInitElts) {

It definitely means that it's an incomplete array type, i.e. a flexible array 
member.



Comment at: test/CodeGenCXX/empty-struct-init-list.cpp:11
+} c;
+c d{ };

rjmccall wrote:
> Please make this a `FileCheck` test that tests the actual compiler output.
I'm sorry, I should've been more specific.  Please include a test line that 
shows the complete constant generated to initialize `@d`.


Repository:
  rC Clang

https://reviews.llvm.org/D49952



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


[PATCH] D50286: avoid creating conditional cleanup blocks that contain only @llvm.lifetime.end calls

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



Comment at: lib/CodeGen/CGExpr.cpp:521
+  CGM.getCodeGenOpts().OptimizationLevel > 0 &&
+  !CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) {
+OldConditional = OutermostConditional;

Why only when optimization is enabled?  This seems like a nice improvement 
regardless.

Also, please mention why this is disabled for destructed types in the comment, 
not just the commit message.


https://reviews.llvm.org/D50286



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


r338942 - [www] Update cxx_status and cxx_dr_status now that Clang 7 has branched.

2018-08-03 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Aug  3 18:02:00 2018
New Revision: 338942

URL: http://llvm.org/viewvc/llvm-project?rev=338942=rev
Log:
[www] Update cxx_status and cxx_dr_status now that Clang 7 has branched.

Modified:
cfe/trunk/www/cxx_dr_status.html
cfe/trunk/www/cxx_status.html
cfe/trunk/www/make_cxx_dr_status

Modified: cfe/trunk/www/cxx_dr_status.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_dr_status.html?rev=338942=338941=338942=diff
==
--- cfe/trunk/www/cxx_dr_status.html (original)
+++ cfe/trunk/www/cxx_dr_status.html Fri Aug  3 18:02:00 2018
@@ -2021,7 +2021,7 @@ of class templates
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#330;>330
 CD4
 Qualification conversions and pointers to arrays of pointers
-SVN
+Clang 7
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#331;>331
@@ -7093,7 +7093,7 @@ and POD class
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1213;>1213
 CD3
 Array subscripting and xvalues
-SVN
+Clang 7
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1214;>1214
@@ -9847,7 +9847,7 @@ and POD class
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1672;>1672
 CD4
 Layout compatibility with multiple empty bases
-SVN
+Clang 7
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1673;>1673
@@ -9937,7 +9937,7 @@ and POD class
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1687;>1687
 C++14
 Conversions of operands of built-in operators
-SVN
+Clang 7
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#1688;>1688
@@ -9991,7 +9991,7 @@ and POD class
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1696;>1696
 CD4
 Temporary lifetime and non-static data member initializers
-SVN
+Clang 7
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1697;>1697
@@ -10693,7 +10693,7 @@ and POD class
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1813;>1813
 CD4
 Direct vs indirect bases in standard-layout classes
-SVN
+Clang 7
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1814;>1814
@@ -11101,7 +11101,7 @@ and POD class
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1881;>1881
 CD4
 Standard-layout classes and unnamed bit-fields
-SVN
+Clang 7
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1882;>1882
@@ -12535,7 +12535,7 @@ and POD class
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2120;>2120
 CD4
 Array as first non-static data member in standard-layout class
-SVN
+Clang 7
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2121;>2121
@@ -13189,7 +13189,7 @@ and POD class
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2229;>2229
 tentatively ready
 Volatile unnamed bit-fields
-SVN
+Clang 7
   
   
 http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#2230;>2230

Modified: cfe/trunk/www/cxx_status.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=338942=338941=338942=diff
==
--- cfe/trunk/www/cxx_status.html (original)
+++ cfe/trunk/www/cxx_status.html Fri Aug  3 18:02:00 2018
@@ -707,7 +707,7 @@ version 3.7.
   
 
 http://wg21.link/p0620r1;>P0620R0 (DR)
-SVN
+Clang 7
   
   
 
@@ -1026,7 +1026,7 @@ and library features that are not part o
 
 
   
-SVN (http://wg21.link/p0096r5;>P0096R5)
+Clang 7 (http://wg21.link/p0096r5;>P0096R5)
   
 
 

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

2018-08-03 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete created this revision.
Rakete added a reviewer: rsmith.

Specific class layouts meant that the constexpr-ness of a special member could 
only be decided after every special member was seen. However, this was at odds 
with the implementation, which checked the constexpr-ness for each special 
member in the order in which they were declared (hence that the bug only occurs 
when special members are ordered in a specific order).

This patch moves the checking of constexpr-ness after evaluating each special 
member.
This fixes https://llvm.org/pr38143


Repository:
  rC Clang

https://reviews.llvm.org/D50291

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaDeclCXX.cpp

Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -6020,6 +6020,7 @@
 
   bool HasMethodWithOverrideControl = false,
HasOverridingMethodWithoutOverrideControl = false;
+  CXXMethodDecl *CopyAssignment = nullptr, *MoveAssignment = nullptr;
   if (!Record->isDependentType()) {
 for (auto *M : Record->methods()) {
   // See if a method overloads virtual methods in a base
@@ -6049,6 +6050,11 @@
 }
   }
 
+  if (CSM == CXXCopyAssignment)
+CopyAssignment = M;
+  else if (CSM == CXXMoveAssignment)
+MoveAssignment = M;
+
   // Set triviality for the purpose of calls if this is a user-provided
   // copy/move constructor or destructor.
   if ((CSM == CXXCopyConstructor || CSM == CXXMoveConstructor ||
@@ -6071,6 +6077,22 @@
 }
   }
 }
+
+// Now we can decide whether the special members are constexpr.
+auto ActOnSpecialMember = [this, ](CXXMethodDecl *MD) {
+  if (!MD->isInvalidDecl() && MD->isExplicitlyDefaulted()) {
+CheckExplicitlyDefaultedSpecialMemberConstexpr(MD);
+Record->finishedDefaultedOrDeletedMember(MD);
+  }
+};
+for (auto *M : Record->ctors())
+  ActOnSpecialMember(M);
+if (CopyAssignment)
+  ActOnSpecialMember(CopyAssignment);
+if (MoveAssignment)
+  ActOnSpecialMember(MoveAssignment);
+if (CXXDestructorDecl *CD = Record->getDestructor())
+  ActOnSpecialMember(CD);
   }
 
   if (HasMethodWithOverrideControl &&
@@ -6532,20 +6554,8 @@
   // C++11 [dcl.fct.def.default]p2:
   //   An explicitly-defaulted function may be declared constexpr only if it
   //   would have been implicitly declared as constexpr,
-  // Do not apply this rule to members of class templates, since core issue 1358
-  // makes such functions always instantiate to constexpr functions. For
-  // functions which cannot be constexpr (for non-constructors in C++11 and for
-  // destructors in C++1y), this is checked elsewhere.
-  bool Constexpr = defaultedSpecialMemberIsConstexpr(*this, RD, CSM,
- HasConstParam);
-  if ((getLangOpts().CPlusPlus14 ? !isa(MD)
- : isa(MD)) &&
-  MD->isConstexpr() && !Constexpr &&
-  MD->getTemplatedKind() == FunctionDecl::TK_NonTemplate) {
-Diag(MD->getLocStart(), diag::err_incorrect_defaulted_constexpr) << CSM;
-// FIXME: Explain why the special member can't be constexpr.
-HadError = true;
-  }
+  // We need to delay this, because at this point we may not have enough
+  // information to determine if MD is really constexpr or not.
 
   //   and may have an explicit exception-specification only if it is compatible
   //   with the exception-specification on the implicit declaration.
@@ -6568,8 +6578,6 @@
   if (First) {
 //  -- it is implicitly considered to be constexpr if the implicit
 // definition would be,
-MD->setConstexpr(Constexpr);
-
 //  -- it is implicitly considered to have the same exception-specification
 // as if it had been implicitly declared,
 FunctionProtoType::ExtProtoInfo EPI = Type->getExtProtoInfo();
@@ -6598,6 +6606,39 @@
 MD->setInvalidDecl();
 }
 
+void Sema::CheckExplicitlyDefaultedSpecialMemberConstexpr(CXXMethodDecl *MD) {
+  CXXSpecialMember CSM = getSpecialMember(MD);
+  assert(MD && MD->isExplicitlyDefaulted() && CSM != CXXInvalid &&
+ "not an explicitly-defaulted special member");
+
+  const FunctionProtoType *Type = MD->getType()->getAs();
+
+  unsigned ExpectedParams =
+  CSM != CXXDefaultConstructor && CSM != CXXDestructor;
+  QualType ArgType = ExpectedParams ? Type->getParamType(0) : QualType();
+
+  bool HasConstParam = ExpectedParams && ArgType->isReferenceType() &&
+   ArgType->getPointeeType().isConstQualified();
+
+  // Do not apply this rule to members of class templates, since core issue 1358
+  // makes such functions always instantiate to constexpr functions. For
+  // functions which cannot be constexpr (for non-constructors in C++11 and for
+  // destructors in C++1y), this is checked elsewhere.
+  bool Constexpr = defaultedSpecialMemberIsConstexpr(*this, 

Re: r338455 - [constexpr] Support for constant evaluation of __builtin_memcpy and

2018-08-03 Thread Richard Smith via cfe-commits
On Wed, 1 Aug 2018 at 10:52, Hans Wennborg via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> We hit this in Chromium too, see crbug.com/869824
>
> I've reverted in r338602
>

Thanks, fixed and re-landed in r338941.


> On Wed, Aug 1, 2018 at 5:26 PM, Benjamin Kramer via cfe-commits
>  wrote:
> > It's pretty easy to make this crash
> >
> > $ cat memcpy.c
> > void foo() {
> >   int a[1], b;
> >   memcpy((char*)a, (const char*), (unsigned long)4);
> > }
> >
> > $ clang memcpy.c
> > llvm/include/llvm/ADT/SmallVector.h:178: const_reference
> > llvm::SmallVectorTemplateCommon > void>::back() const [T = clang::APValue::LValue
> > PathEntry]: Assertion `!empty()' failed.
> >
> > On Wed, Aug 1, 2018 at 1:35 AM Richard Smith via cfe-commits
> >  wrote:
> >>
> >> Author: rsmith
> >> Date: Tue Jul 31 16:35:09 2018
> >> New Revision: 338455
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=338455=rev
> >> Log:
> >> [constexpr] Support for constant evaluation of __builtin_memcpy and
> >> __builtin_memmove (in non-type-punning cases).
> >>
> >> This is intended to permit libc++ to make std::copy etc constexpr
> >> without sacrificing the optimization that uses memcpy on
> >> trivially-copyable types.
> >>
> >> __builtin_strcpy and __builtin_wcscpy are not handled by this change.
> >> They'd be straightforward to add, but we haven't encountered a need for
> >> them just yet.
> >>
> >> Modified:
> >> cfe/trunk/include/clang/Basic/Builtins.def
> >> cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
> >> cfe/trunk/lib/AST/ExprConstant.cpp
> >> cfe/trunk/test/CodeGen/builtin-memfns.c
> >> cfe/trunk/test/SemaCXX/constexpr-string.cpp
> >>
> >> Modified: cfe/trunk/include/clang/Basic/Builtins.def
> >> URL:
> >>
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=338455=338454=338455=diff
> >>
> >>
> ==
> >> --- cfe/trunk/include/clang/Basic/Builtins.def (original)
> >> +++ cfe/trunk/include/clang/Basic/Builtins.def Tue Jul 31 16:35:09 2018
> >> @@ -471,6 +471,8 @@ BUILTIN(__builtin_wcslen, "zwC*", "nF")
> >>  BUILTIN(__builtin_wcsncmp, "iwC*wC*z", "nF")
> >>  BUILTIN(__builtin_wmemchr, "w*wC*wz", "nF")
> >>  BUILTIN(__builtin_wmemcmp, "iwC*wC*z", "nF")
> >> +BUILTIN(__builtin_wmemcpy, "w*w*wC*z", "nF")
> >> +BUILTIN(__builtin_wmemmove, "w*w*wC*z", "nF")
> >>  BUILTIN(__builtin_return_address, "v*IUi", "n")
> >>  BUILTIN(__builtin_extract_return_addr, "v*v*", "n")
> >>  BUILTIN(__builtin_frame_address, "v*IUi", "n")
> >> @@ -908,6 +910,8 @@ LIBBUILTIN(wcslen,  "zwC*", "f", "wc
> >>  LIBBUILTIN(wcsncmp, "iwC*wC*z", "f", "wchar.h", ALL_LANGUAGES)
> >>  LIBBUILTIN(wmemchr, "w*wC*wz",  "f", "wchar.h", ALL_LANGUAGES)
> >>  LIBBUILTIN(wmemcmp, "iwC*wC*z", "f", "wchar.h", ALL_LANGUAGES)
> >> +LIBBUILTIN(wmemcpy, "w*w*wC*z", "f", "wchar.h", ALL_LANGUAGES)
> >> +LIBBUILTIN(wmemmove,"w*w*wC*z", "f", "wchar.h", ALL_LANGUAGES)
> >>
> >>  // C99
> >>  // In some systems setjmp is a macro that expands to _setjmp. We
> undefine
> >>
> >> Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
> >> URL:
> >>
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=338455=338454=338455=diff
> >>
> >>
> ==
> >> --- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
> >> +++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Tue Jul 31
> >> 16:35:09 2018
> >> @@ -163,6 +163,20 @@ def note_constexpr_unsupported_unsized_a
> >>  def note_constexpr_unsized_array_indexed : Note<
> >>"indexing of array without known bound is not allowed "
> >>"in a constant expression">;
> >> +def note_constexpr_memcpy_type_pun : Note<
> >> +  "cannot constant evaluate '%select{memcpy|memmove}0' from object of "
> >> +  "type %1 to object of type %2">;
> >> +def note_constexpr_memcpy_nontrivial : Note<
> >> +  "cannot constant evaluate '%select{memcpy|memmove}0' between objects
> of
> >> "
> >> +  "non-trivially-copyable type %1">;
> >> +def note_constexpr_memcpy_overlap : Note<
> >> +  "'%select{memcpy|wmemcpy}0' between overlapping memory regions">;
> >> +def note_constexpr_memcpy_unsupported : Note<
> >> +  "'%select{%select{memcpy|wmemcpy}1|%select{memmove|wmemmove}1}0' "
> >> +  "not supported: %select{"
> >> +  "size to copy (%4) is not a multiple of size of element type %3
> (%5)|"
> >> +  "source is not a contiguous array of at least %4 elements of type
> %3|"
> >> +  "destination is not a contiguous array of at least %4 elements of
> type
> >> %3}2">;
> >>
> >>  def warn_integer_constant_overflow : Warning<
> >>"overflow in expression; result is %0 with type %1">,
> >>
> >> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> >> URL:
> >>
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=338455=338454=338455=diff
> >>
> >>
> 

r338941 - [constexpr] Support for constant evaluation of __builtin_memcpy and

2018-08-03 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Aug  3 17:57:17 2018
New Revision: 338941

URL: http://llvm.org/viewvc/llvm-project?rev=338941=rev
Log:
[constexpr] Support for constant evaluation of __builtin_memcpy and
__builtin_memmove (in non-type-punning cases).

This is intended to permit libc++ to make std::copy etc constexpr
without sacrificing the optimization that uses memcpy on
trivially-copyable types.

__builtin_strcpy and __builtin_wcscpy are not handled by this change.
They'd be straightforward to add, but we haven't encountered a need for
them just yet.

This reinstates r338455, reverted in r338602, with a fix to avoid trying
to constant-evaluate a memcpy call if either pointer operand has an
invalid designator.

Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/CodeGen/builtin-memfns.c
cfe/trunk/test/SemaCXX/constexpr-string.cpp

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=338941=338940=338941=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Fri Aug  3 17:57:17 2018
@@ -471,6 +471,8 @@ BUILTIN(__builtin_wcslen, "zwC*", "nF")
 BUILTIN(__builtin_wcsncmp, "iwC*wC*z", "nF")
 BUILTIN(__builtin_wmemchr, "w*wC*wz", "nF")
 BUILTIN(__builtin_wmemcmp, "iwC*wC*z", "nF")
+BUILTIN(__builtin_wmemcpy, "w*w*wC*z", "nF")
+BUILTIN(__builtin_wmemmove, "w*w*wC*z", "nF")
 BUILTIN(__builtin_return_address, "v*IUi", "n")
 BUILTIN(__builtin_extract_return_addr, "v*v*", "n")
 BUILTIN(__builtin_frame_address, "v*IUi", "n")
@@ -908,6 +910,8 @@ LIBBUILTIN(wcslen,  "zwC*", "f", "wc
 LIBBUILTIN(wcsncmp, "iwC*wC*z", "f", "wchar.h", ALL_LANGUAGES)
 LIBBUILTIN(wmemchr, "w*wC*wz",  "f", "wchar.h", ALL_LANGUAGES)
 LIBBUILTIN(wmemcmp, "iwC*wC*z", "f", "wchar.h", ALL_LANGUAGES)
+LIBBUILTIN(wmemcpy, "w*w*wC*z", "f", "wchar.h", ALL_LANGUAGES)
+LIBBUILTIN(wmemmove,"w*w*wC*z", "f", "wchar.h", ALL_LANGUAGES)
 
 // C99
 // In some systems setjmp is a macro that expands to _setjmp. We undefine

Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=338941=338940=338941=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Fri Aug  3 17:57:17 2018
@@ -163,6 +163,20 @@ def note_constexpr_unsupported_unsized_a
 def note_constexpr_unsized_array_indexed : Note<
   "indexing of array without known bound is not allowed "
   "in a constant expression">;
+def note_constexpr_memcpy_type_pun : Note<
+  "cannot constant evaluate '%select{memcpy|memmove}0' from object of "
+  "type %1 to object of type %2">;
+def note_constexpr_memcpy_nontrivial : Note<
+  "cannot constant evaluate '%select{memcpy|memmove}0' between objects of "
+  "non-trivially-copyable type %1">;
+def note_constexpr_memcpy_overlap : Note<
+  "'%select{memcpy|wmemcpy}0' between overlapping memory regions">;
+def note_constexpr_memcpy_unsupported : Note<
+  "'%select{%select{memcpy|wmemcpy}1|%select{memmove|wmemmove}1}0' "
+  "not supported: %select{"
+  "size to copy (%4) is not a multiple of size of element type %3 (%5)|"
+  "source is not a contiguous array of at least %4 elements of type %3|"
+  "destination is not a contiguous array of at least %4 elements of type 
%3}2">;
 
 def warn_integer_constant_overflow : Warning<
   "overflow in expression; result is %0 with type %1">,

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=338941=338940=338941=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Aug  3 17:57:17 2018
@@ -319,6 +319,25 @@ namespace {
   return false;
 }
 
+/// Get the range of valid index adjustments in the form
+///   {maximum value that can be subtracted from this pointer,
+///maximum value that can be added to this pointer}
+std::pair validIndexAdjustments() {
+  if (Invalid || isMostDerivedAnUnsizedArray())
+return {0, 0};
+
+  // [expr.add]p4: For the purposes of these operators, a pointer to a
+  // nonarray object behaves the same as a pointer to the first element of
+  // an array of length one with the type of the object as its element 
type.
+  bool IsArray = MostDerivedPathLength == Entries.size() &&
+ MostDerivedIsArrayElement;
+  uint64_t ArrayIndex =
+  IsArray ? Entries.back().ArrayIndex : (uint64_t)IsOnePastTheEnd;
+  uint64_t ArraySize =
+  IsArray ? 

[PATCH] D50194: LLVM Proto Fuzzer - Run Functions on Suite of Inputs

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

New input arrays and minor fixes


Repository:
  rC Clang

https://reviews.llvm.org/D50194

Files:
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.h
  clang/tools/clang-fuzzer/handle-llvm/input_arrays.h

Index: clang/tools/clang-fuzzer/handle-llvm/input_arrays.h
===
--- /dev/null
+++ clang/tools/clang-fuzzer/handle-llvm/input_arrays.h
@@ -0,0 +1,118 @@
+//==-- input_arrays.h - Helper function for LLVM fuzzer inputs -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Define a few static variables used by the LLVM Proto Fuzzer
+//
+//===--===//
+
+#include 
+
+static const int kArraySize = 64;
+static const int kNumArrays = 93;
+static const int kTotalSize = sizeof(int) * kArraySize * kNumArrays;
+
+// Define two arrays that will hold the input and output for the two functions
+static int OptArrays[kNumArrays][kArraySize];
+static int UnoptArrays[kNumArrays][kArraySize];
+
+// Define a corpus of possible inputs
+static int InputArrays[kNumArrays][kArraySize] =
+{ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+  {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
+  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+  {INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX},
+  {INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN, INT_MIN},
+  {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
+  {16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16},
+  {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255},
+  {1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024},
+  {65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 

[PATCH] D50286: avoid creating conditional cleanup blocks that contain only @llvm.lifetime.end calls

2018-08-03 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith updated this revision to Diff 159143.
rsmith added a comment.

Add forgotten test file.


https://reviews.llvm.org/D50286

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGenCXX/conditional-temporaries.cpp
  test/CodeGenCXX/lifetime-asan.cpp

Index: test/CodeGenCXX/lifetime-asan.cpp
===
--- test/CodeGenCXX/lifetime-asan.cpp
+++ test/CodeGenCXX/lifetime-asan.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 %s | FileCheck %s -check-prefixes=CHECK,CHECK-O0 --implicit-check-not=llvm.lifetime
+// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -o - -fno-exceptions -O0 \
+// RUN: -fsanitize=address -fsanitize-address-use-after-scope %s | \
+// RUN: FileCheck %s -check-prefixes=CHECK,CHECK-ASAN-USE-AFTER-SCOPE
+
+extern int bar(char *A, int n);
+
+struct X { X(); ~X(); int *p; };
+struct Y { Y(); int *p; };
+
+extern "C" void a(), b(), c(), d();
+
+// CHECK-LABEL: @_Z3foo
+void foo(int n) {
+  // CHECK: call void @a()
+  a();
+
+  // CHECK: call void @b()
+  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 false
+  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 false
+  // CHECK: br i1
+  //
+  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.start
+  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 true
+  // CHECK: call void @_ZN1XC
+  // CHECK: br label
+  //
+  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.start
+  // CHECK-ASAN-USE-AFTER-SCOPE: store i1 true
+  // CHECK: call void @_ZN1YC
+  // CHECK: br label
+  //
+  // CHECK: call void @c()
+  // CHECK-ASAN-USE-AFTER-SCOPE: br i1
+  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.end
+  // CHECK-ASAN-USE-AFTER-SCOPE: br i1
+  // CHECK-ASAN-USE-AFTER-SCOPE: @llvm.lifetime.end
+  b(), (n ? X().p : Y().p), c();
+
+  // CHECK: call void @d()
+  d();
+}
Index: test/CodeGenCXX/conditional-temporaries.cpp
===
--- test/CodeGenCXX/conditional-temporaries.cpp
+++ test/CodeGenCXX/conditional-temporaries.cpp
@@ -1,6 +1,7 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O3 | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=amdgcn-amd-amdhsa -O3 | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,CHECK-NOOPT
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 | FileCheck %s --check-prefixes=CHECK,CHECK-OPT
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=amdgcn-amd-amdhsa -O2 | FileCheck %s --check-prefixes=CHECK,CHECK-OPT
 
 namespace {
 
@@ -38,20 +39,167 @@
 
 }
 
-// CHECK-LABEL: define i32 @_Z12getCtorCallsv()
+// CHECK-OPT-LABEL: define i32 @_Z12getCtorCallsv()
 int getCtorCalls() {
-  // CHECK: ret i32 5
+  // CHECK-OPT: ret i32 5
   return ctorcalls;
 }
 
-// CHECK-LABEL: define i32 @_Z12getDtorCallsv()
+// CHECK-OPT-LABEL: define i32 @_Z12getDtorCallsv()
 int getDtorCalls() {
-  // CHECK: ret i32 5
+  // CHECK-OPT: ret i32 5
   return dtorcalls;
 }
 
-// CHECK-LABEL: define zeroext i1 @_Z7successv()
+// CHECK-OPT-LABEL: define zeroext i1 @_Z7successv()
 bool success() {
-  // CHECK: ret i1 true
+  // CHECK-OPT: ret i1 true
   return ctorcalls == dtorcalls;
 }
+
+struct X { ~X(); int f(); };
+int g(int, int, int);
+// CHECK-LABEL: @_Z16lifetime_nontriv
+int lifetime_nontriv(bool cond) {
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: br i1
+  //
+  // CHECK-NOOPT: call void @llvm.lifetime.start
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: call i32 @_ZN1X1fEv(
+  // CHECK-NOOPT: call void @llvm.lifetime.start
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: call i32 @_ZN1X1fEv(
+  // CHECK-NOOPT: call void @llvm.lifetime.start
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: call i32 @_ZN1X1fEv(
+  // CHECK-NOOPT: call i32 @_Z1giii(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: call i32 @_Z1giii(i32 1, i32 2, i32 3)
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @_ZN1XD1Ev(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @llvm.lifetime.end
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @_ZN1XD1Ev(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @llvm.lifetime.end
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @_ZN1XD1Ev(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+ 

[PATCH] D50194: LLVM Proto Fuzzer - Run Functions on Suite of Inputs

2018-08-03 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse accepted this revision.
morehouse added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:132
+// Takes a string of IR and compiles it using LLVM's JIT Engine
+static void CreateJITFunc(const std::string , CodeGenOpt::Level OLvl) {
   SMDiagnostic Err;

`CreateAndRunJITFunc` describes this better.



Comment at: clang/tools/clang-fuzzer/handle-llvm/input_arrays.h:36
+  {1, 1, 2, 3, 2, 3, 0, 11, 10, 0, 7, 5, 3, 1, 18, 18, 18, 18, 0, 18, 18, 18, 
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 
18, 18},
+  {0, 0, 2, 5, 4, 0, 2, 13, 12, 11, 0, 8, 6, 4, 2, 0, 20, 20, 20, 20, 0, 20, 
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 
20, 20},
+  {1, 1, 0, 1, 6, 2, 4, 1, 14, 13, 12, 0, 9, 7, 5, 3, 1, 22, 22, 22, 22, 22, 
0, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 
22, 22},

emmettneyman wrote:
> kcc wrote:
> > constants are not diverse enough. 
> Yeah, I will completely redo the input arrays.
Please land today once you do.



Comment at: clang/tools/clang-fuzzer/handle-llvm/input_arrays.h:15
+#include 
+#include 
+

Are these includes needed?



Comment at: clang/tools/clang-fuzzer/handle-llvm/input_arrays.h:19
+static const int NumArrays = 100;
+static const int TotalSize = sizeof(int) * ArraySize * NumArrays;
+

Maybe prefix these names with `k` since they are constant.


Repository:
  rC Clang

https://reviews.llvm.org/D50194



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


[PATCH] D50286: avoid creating conditional cleanup blocks that contain only @llvm.lifetime.end calls

2018-08-03 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith created this revision.
rsmith added a reviewer: rjmccall.

When a non-extended temporary object is created in a conditional branch, the 
lifetime of that temporary ends outside the conditional (at the end of the 
full-expression). If we're inserting lifetime markers, this means we can end up 
generating

  if (some_cond) {
lifetime.start();
Tmp::Tmp();
  }
  // ...
  if (some_cond) {
lifetime.end();
  }

for a full-expression containing a subexpression of the form `some_cond ? 
Tmp().x : 0`. This patch moves the lifetime start for such a temporary out of 
the conditional branch so that we don't need to generate an additional basic 
block to hold the lifetime end marker.

This is disabled if we want precise lifetime markers (for asan's 
stack-use-after-scope checks) or of the temporary has a non-trivial destructor 
(in which case we'd generate an extra basic block anyway to hold the destructor 
call).


Repository:
  rC Clang

https://reviews.llvm.org/D50286

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGenCXX/conditional-temporaries.cpp

Index: test/CodeGenCXX/conditional-temporaries.cpp
===
--- test/CodeGenCXX/conditional-temporaries.cpp
+++ test/CodeGenCXX/conditional-temporaries.cpp
@@ -1,6 +1,7 @@
 // REQUIRES: amdgpu-registered-target
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O3 | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm %s -o - -triple=amdgcn-amd-amdhsa -O3 | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 -disable-llvm-passes | FileCheck %s --check-prefixes=CHECK,CHECK-NOOPT
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -O2 | FileCheck %s --check-prefixes=CHECK,CHECK-OPT
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple=amdgcn-amd-amdhsa -O2 | FileCheck %s --check-prefixes=CHECK,CHECK-OPT
 
 namespace {
 
@@ -38,20 +39,167 @@
 
 }
 
-// CHECK-LABEL: define i32 @_Z12getCtorCallsv()
+// CHECK-OPT-LABEL: define i32 @_Z12getCtorCallsv()
 int getCtorCalls() {
-  // CHECK: ret i32 5
+  // CHECK-OPT: ret i32 5
   return ctorcalls;
 }
 
-// CHECK-LABEL: define i32 @_Z12getDtorCallsv()
+// CHECK-OPT-LABEL: define i32 @_Z12getDtorCallsv()
 int getDtorCalls() {
-  // CHECK: ret i32 5
+  // CHECK-OPT: ret i32 5
   return dtorcalls;
 }
 
-// CHECK-LABEL: define zeroext i1 @_Z7successv()
+// CHECK-OPT-LABEL: define zeroext i1 @_Z7successv()
 bool success() {
-  // CHECK: ret i1 true
+  // CHECK-OPT: ret i1 true
   return ctorcalls == dtorcalls;
 }
+
+struct X { ~X(); int f(); };
+int g(int, int, int);
+// CHECK-LABEL: @_Z16lifetime_nontriv
+int lifetime_nontriv(bool cond) {
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: store i1 false,
+  // CHECK-NOOPT: br i1
+  //
+  // CHECK-NOOPT: call void @llvm.lifetime.start
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: call i32 @_ZN1X1fEv(
+  // CHECK-NOOPT: call void @llvm.lifetime.start
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: call i32 @_ZN1X1fEv(
+  // CHECK-NOOPT: call void @llvm.lifetime.start
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: store i1 true,
+  // CHECK-NOOPT: call i32 @_ZN1X1fEv(
+  // CHECK-NOOPT: call i32 @_Z1giii(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: call i32 @_Z1giii(i32 1, i32 2, i32 3)
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @_ZN1XD1Ev(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @llvm.lifetime.end
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @_ZN1XD1Ev(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @llvm.lifetime.end
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @_ZN1XD1Ev(
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: load i1,
+  // CHECK-NOOPT: br i1
+  // CHECK-NOOPT: call void @llvm.lifetime.end
+  // CHECK-NOOPT: br label
+  //
+  // CHECK-NOOPT: ret
+
+  // CHECK-OPT: br i1
+  //
+  // CHECK-OPT: call void @llvm.lifetime.start
+  // CHECK-OPT: call i32 @_ZN1X1fEv(
+  // CHECK-OPT: call void @llvm.lifetime.start
+  // CHECK-OPT: call i32 @_ZN1X1fEv(
+  // CHECK-OPT: call void @llvm.lifetime.start
+  // CHECK-OPT: call i32 @_ZN1X1fEv(
+  // CHECK-OPT: call i32 @_Z1giii(
+  // CHECK-OPT: call void @_ZN1XD1Ev(
+  // CHECK-OPT: call void @llvm.lifetime.end
+  // CHECK-OPT: call void @_ZN1XD1Ev(
+  // CHECK-OPT: call void @llvm.lifetime.end
+  // CHECK-OPT: call void @_ZN1XD1Ev(
+  // CHECK-OPT: call void @llvm.lifetime.end
+  // CHECK-OPT: br label
+  return cond ? 

Re: r338667 - [analyzer] Extend NoStoreFuncVisitor to follow fields.

2018-08-03 Thread George Karpenkov via cfe-commits
Should be fixed in trunk

> On Aug 3, 2018, at 1:30 PM, George Karpenkov via cfe-commits 
>  wrote:
> 
> Yeah, saw that as well, fix coming.
> 
>> On Aug 3, 2018, at 10:32 AM, Alexander Kornienko > > wrote:
>> 
>> 
>> 
>> On Thu, Aug 2, 2018 at 4:03 AM George Karpenkov via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> Author: george.karpenkov
>> Date: Wed Aug  1 19:02:40 2018
>> New Revision: 338667
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=338667=rev 
>> 
>> Log:
>> [analyzer] Extend NoStoreFuncVisitor to follow fields.
>> 
>> rdar://39701823 
>> 
>> Differential Revision: https://reviews.llvm.org/D49901 
>> 
>> 
>> Modified:
>> cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
>> cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.c
>> cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
>> cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
>> 
>> Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=338667=338666=338667=diff
>>  
>> 
>> ==
>> --- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
>> +++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed Aug  1 
>> 19:02:40 2018
>> @@ -269,10 +269,14 @@ namespace {
>>  /// pointer dereference outside.
>>  class NoStoreFuncVisitor final : public BugReporterVisitor {
>>const SubRegion *RegionOfInterest;
>> +  MemRegionManager 
>>const SourceManager 
>>const PrintingPolicy 
>> -  static constexpr const char *DiagnosticsMsg =
>> -  "Returning without writing to '";
>> +
>> +  /// Recursion limit for dereferencing fields when looking for the
>> +  /// region of interest.
>> +  /// The limit of two indicates that we will dereference fields only once.
>> +  static const unsigned DEREFERENCE_LIMIT = 2;
>> 
>>/// Frames writing into \c RegionOfInterest.
>>/// This visitor generates a note only if a function does not write into
>> @@ -285,15 +289,17 @@ class NoStoreFuncVisitor final : public
>>llvm::SmallPtrSet FramesModifyingRegion;
>>llvm::SmallPtrSet 
>> FramesModifyingCalculated;
>> 
>> +  using RegionVector = SmallVector;
>>  public:
>>NoStoreFuncVisitor(const SubRegion *R)
>> -  : RegionOfInterest(R),
>> -SM(R->getMemRegionManager()->getContext().getSourceManager()),
>> -PP(R->getMemRegionManager()->getContext().getPrintingPolicy()) {}
>> +  : RegionOfInterest(R), MmrMgr(*R->getMemRegionManager()),
>> +SM(MmrMgr.getContext().getSourceManager()),
>> +PP(MmrMgr.getContext().getPrintingPolicy()) {}
>> 
>>void Profile(llvm::FoldingSetNodeID ) const override {
>>  static int Tag = 0;
>>  ID.AddPointer();
>> +ID.AddPointer(RegionOfInterest);
>>}
>> 
>>std::shared_ptr VisitNode(const ExplodedNode *N,
>> @@ -307,48 +313,69 @@ public:
>>  auto CallExitLoc = N->getLocationAs();
>> 
>>  // No diagnostic if region was modified inside the frame.
>> -if (!CallExitLoc)
>> +if (!CallExitLoc || isRegionOfInterestModifiedInFrame(N))
>>return nullptr;
>> 
>>  CallEventRef<> Call =
>>  BRC.getStateManager().getCallEventManager().getCaller(SCtx, State);
>> 
>> +if (SM.isInSystemHeader(Call->getDecl()->getSourceRange().getBegin()))
>> +  return nullptr;
>> +
>>  // Region of interest corresponds to an IVar, exiting a method
>>  // which could have written into that IVar, but did not.
>> -if (const auto *MC = dyn_cast(Call))
>> -  if (const auto *IvarR = dyn_cast(RegionOfInterest))
>> -if 
>> (potentiallyWritesIntoIvar(Call->getRuntimeDefinition().getDecl(),
>> -  IvarR->getDecl()) &&
>> -!isRegionOfInterestModifiedInFrame(N))
>> -  return notModifiedMemberDiagnostics(
>> -  Ctx, *CallExitLoc, Call, MC->getReceiverSVal().getAsRegion());
>> +if (const auto *MC = dyn_cast(Call)) {
>> +  if (const auto *IvarR = dyn_cast(RegionOfInterest)) {
>> +const MemRegion *SelfRegion = MC->getReceiverSVal().getAsRegion();
>> +if (RegionOfInterest->isSubRegionOf(SelfRegion) &&
>> +
>> potentiallyWritesIntoIvar(Call->getRuntimeDefinition().getDecl(),
>> +  IvarR->getDecl()))
>> +  return notModifiedDiagnostics(Ctx, *CallExitLoc, Call, {}, 
>> SelfRegion,
>> +"self", 
>> /*FirstIsReferenceType=*/false,
>> +1);
>> +  }
>> +}
>> 
>>  if (const auto *CCall = 

[libcxx] r338936 - Mark LWG#2260 as complete. We already did the right thing, so I just added tests to ensure that we continue to DTRT.

2018-08-03 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Fri Aug  3 16:28:48 2018
New Revision: 338936

URL: http://llvm.org/viewvc/llvm-project?rev=338936=rev
Log:
Mark LWG#2260 as complete. We already did the right thing, so I just added 
tests to ensure that we continue to DTRT.

Modified:

libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp
libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp
libcxx/trunk/www/cxx1z_status.html

Modified: 
libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp?rev=338936=338935=338936=diff
==
--- 
libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp
 Fri Aug  3 16:28:48 2018
@@ -39,6 +39,7 @@ int main()
 {
 {
 int i = 0;
+static_assert((std::is_same, 
decltype(std::pointer_traits >::pointer_to(i))>::value), "");
 A a = std::pointer_traits >::pointer_to(i);
 assert(a.t_ == );
 }

Modified: 
libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp?rev=338936=338935=338936=diff
==
--- libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp 
(original)
+++ libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp 
Fri Aug  3 16:28:48 2018
@@ -23,6 +23,7 @@ int main()
 {
 {
 int i = 0;
+static_assert((std::is_same::pointer_to(i))>::value), "");
 int* a = std::pointer_traits::pointer_to(i);
 assert(a == );
 }

Modified: libcxx/trunk/www/cxx1z_status.html
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=338936=338935=338936=diff
==
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Fri Aug  3 16:28:48 2018
@@ -442,7 +442,7 @@
https://wg21.link/LWG2777;>2777basic_string_view::copy 
should use char_traits::copyIssaquahComplete
https://wg21.link/LWG2778;>2778basic_string_view is missing 
constexprIssaquahComplete

-   https://wg21.link/LWG2260;>2260Missing 
requirement for Allocator::pointerKona
+   https://wg21.link/LWG2260;>2260Missing 
requirement for Allocator::pointerKonaComplete
https://wg21.link/LWG2676;>2676Provide 
filesystem::path overloads for File-based 
streamsKonaComplete
https://wg21.link/LWG2768;>2768any_cast 
and move semanticsKonaComplete
https://wg21.link/LWG2769;>2769Redundant 
const in the return type of any_cast(const 
any)KonaComplete
@@ -504,7 +504,7 @@
 
   
 
-  Last Updated: 22-May-2018
+  Last Updated: 3-Aug-2018
 
 
 


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


r338935 - [analyzer] Do not crash in NoStoreFuncVisitor notes if an unexpected region is found.

2018-08-03 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Fri Aug  3 16:19:07 2018
New Revision: 338935

URL: http://llvm.org/viewvc/llvm-project?rev=338935=rev
Log:
[analyzer] Do not crash in NoStoreFuncVisitor notes if an unexpected region is 
found.

Just do not generate the note at all in that case.

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=338935=338934=338935=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Fri Aug  3 
16:19:07 2018
@@ -351,10 +351,7 @@ public:
 
 ArrayRef parameters = getCallParameters(Call);
 for (unsigned I = 0; I < Call->getNumArgs() && I < parameters.size(); ++I) 
{
-  Optional AdjustedIdx = Call->getAdjustedParameterIndex(I);
-  if (!AdjustedIdx)
-continue;
-  const ParmVarDecl *PVD = parameters[*AdjustedIdx];
+  const ParmVarDecl *PVD = parameters[I];
   SVal S = Call->getArgSVal(I);
   bool ParamIsReferenceType = PVD->getType()->isReferenceType();
   std::string ParamName = PVD->getNameAsString();
@@ -565,15 +562,19 @@ private:
 SmallString<256> sbuf;
 llvm::raw_svector_ostream os(sbuf);
 os << "Returning without writing to '";
-prettyPrintRegionName(FirstElement, FirstIsReferenceType, MatchedRegion,
-  FieldChain, IndirectionLevel, os);
+
+// Do not generate the note if failed to pretty-print.
+if (!prettyPrintRegionName(FirstElement, FirstIsReferenceType,
+   MatchedRegion, FieldChain, IndirectionLevel, 
os))
+  return nullptr;
 
 os << "'";
 return std::make_shared(L, os.str());
   }
 
   /// Pretty-print region \p MatchedRegion to \p os.
-  void prettyPrintRegionName(StringRef FirstElement, bool FirstIsReferenceType,
+  /// \return Whether printing succeeded.
+  bool prettyPrintRegionName(StringRef FirstElement, bool FirstIsReferenceType,
  const MemRegion *MatchedRegion,
  const RegionVector ,
  int IndirectionLevel,
@@ -598,6 +599,7 @@ private:
 for (const MemRegion *R : RegionSequence) {
 
   // Just keep going up to the base region.
+  // Element regions may appear due to casts.
   if (isa(R) || isa(R))
 continue;
 
@@ -608,6 +610,10 @@ private:
 
   os << Sep;
 
+  // Can only reasonably pretty-print DeclRegions.
+  if (!isa(R))
+return false;
+
   const auto *DR = cast(R);
   Sep = DR->getValueType()->isAnyPointerType() ? "->" : ".";
   DR->getDecl()->getDeclName().print(os, PP);
@@ -617,6 +623,7 @@ private:
   prettyPrintFirstElement(FirstElement,
   /*MoreItemsExpected=*/false, IndirectionLevel,
   os);
+return true;
   }
 
   /// Print first item in the chain, return new separator.

Modified: cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp?rev=338935=338934=338935=diff
==
--- cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp (original)
+++ cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp Fri Aug  3 
16:19:07 2018
@@ -333,3 +333,27 @@ int useMaybeInitializeIndirectlyWithPoin
   return z; // expected-warning{{Undefined or garbage value returned to 
caller}}
 // expected-note@-1{{Undefined or garbage value returned to 
caller}}
 }
+
+
+
+struct HasFieldA {
+  int x;
+};
+
+struct HasFieldB {
+  int x;
+};
+
+void maybeInitializeHasField(HasFieldA *b) {
+  if (coin()) // expected-note{{Assuming the condition is false}}
+  // expected-note@-1{{Taking false branch}}
+((HasFieldB*)b)->x = 120;
+}
+
+int forceElementRegionApperence() {
+  HasFieldA a;
+  maybeInitializeHasField(); // expected-note{{Calling 
'maybeInitializeHasField'}}
+   // expected-note@-1{{Returning from 
'maybeInitializeHasField'}}
+  return ((HasFieldB*))->x; // expected-warning{{Undefined or garbage value 
returned to caller}}
+  // expected-note@-1{{Undefined or garbage value 
returned to caller}}
+}


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


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

2018-08-03 Thread Stella Stamenova via Phabricator via cfe-commits
stella.stamenova created this revision.
stella.stamenova added reviewers: asmith, zturner.
Herald added a subscriber: cfe-commits.

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

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


Repository:
  rC Clang

https://reviews.llvm.org/D50281

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


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


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


[PATCH] D45015: [Preprocessor] Allow libc++ to detect when aligned allocation is unavailable.

2018-08-03 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

In https://reviews.llvm.org/D45015#1188141, @EricWF wrote:

> Hi, I'm in the process of moving cities. please take over.
>
> Thanks, and sorry


No worries. Thanks for spending time on this issue and making the fix, 
committing is the easy part. Good luck with the move.


Repository:
  rL LLVM

https://reviews.llvm.org/D45015



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


[PATCH] D45015: [Preprocessor] Allow libc++ to detect when aligned allocation is unavailable.

2018-08-03 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL338934: [Preprocessor] Allow libc++ to detect when aligned 
allocation is unavailable. (authored by vsapsai, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45015?vs=150635=159121#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45015

Files:
  cfe/trunk/include/clang/Basic/DiagnosticGroups.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
  cfe/trunk/lib/Frontend/InitPreprocessor.cpp
  cfe/trunk/lib/Sema/SemaExprCXX.cpp
  cfe/trunk/test/Driver/unavailable_aligned_allocation.cpp
  cfe/trunk/test/Lexer/aligned-allocation.cpp

Index: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td
@@ -364,7 +364,6 @@
 def NullPointerArithmetic : DiagGroup<"null-pointer-arithmetic">;
 def : DiagGroup<"effc++", [NonVirtualDtor]>;
 def OveralignedType : DiagGroup<"over-aligned">;
-def AlignedAllocationUnavailable : DiagGroup<"aligned-allocation-unavailable">;
 def OldStyleCast : DiagGroup<"old-style-cast">;
 def : DiagGroup<"old-style-definition">;
 def OutOfLineDeclaration : DiagGroup<"out-of-line-declaration">;
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6465,12 +6465,12 @@
   "type %0 requires %1 bytes of alignment and the default allocator only "
   "guarantees %2 bytes">,
   InGroup, DefaultIgnore;
-def warn_aligned_allocation_unavailable :Warning<
+def err_aligned_allocation_unavailable : Error<
   "aligned %select{allocation|deallocation}0 function of type '%1' is only "
-  "available on %2 %3 or newer">, InGroup, DefaultError;
+  "available on %2 %3 or newer">;
 def note_silence_unligned_allocation_unavailable : Note<
   "if you supply your own aligned allocation functions, use "
-  "-Wno-aligned-allocation-unavailable to silence this diagnostic">;
+  "-faligned-allocation to silence this diagnostic">;
 
 def err_conditional_void_nonvoid : Error<
   "%select{left|right}1 operand to ? is void, but %select{right|left}1 operand "
Index: cfe/trunk/test/Lexer/aligned-allocation.cpp
===
--- cfe/trunk/test/Lexer/aligned-allocation.cpp
+++ cfe/trunk/test/Lexer/aligned-allocation.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++17 -verify %s \
+// RUN:   -DEXPECT_DEFINED
+//
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++17 -verify %s \
+// RUN:   -faligned-alloc-unavailable
+//
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++17 -verify %s \
+// RUN:   -faligned-allocation -faligned-alloc-unavailable
+
+// Test that __cpp_aligned_new is not defined when CC1 is passed
+// -faligned-alloc-unavailable by the Darwin driver, even when aligned
+// allocation is actually enabled.
+
+// expected-no-diagnostics
+#ifdef EXPECT_DEFINED
+# ifndef __cpp_aligned_new
+#   error "__cpp_aligned_new" should be defined
+# endif
+#else
+# ifdef __cpp_aligned_new
+#   error "__cpp_aligned_new" should not be defined
+# endif
+#endif
Index: cfe/trunk/test/Driver/unavailable_aligned_allocation.cpp
===
--- cfe/trunk/test/Driver/unavailable_aligned_allocation.cpp
+++ cfe/trunk/test/Driver/unavailable_aligned_allocation.cpp
@@ -51,4 +51,13 @@
 // RUN: -c -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=AVAILABLE
 //
+// Check that passing -faligned-allocation or -fno-aligned-allocation stops the
+// driver from passing -faligned-alloc-unavailable to cc1.
+//
+// RUN: %clang -target x86_64-apple-macosx10.12 -faligned-allocation -c -### %s 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=AVAILABLE
+//
+// RUN: %clang -target x86_64-apple-macosx10.12 -fno-aligned-allocation -c -### %s 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=AVAILABLE
+
 // AVAILABLE-NOT: "-faligned-alloc-unavailable"
Index: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
@@ -2035,7 +2035,11 @@
 void Darwin::addClangTargetOptions(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ,
Action::OffloadKind DeviceOffloadKind) const {
-  if (isAlignedAllocationUnavailable())
+  // Pass "-faligned-alloc-unavailable" only when the user hasn't manually
+  // enabled or disabled aligned allocations.
+  if 

r338934 - [Preprocessor] Allow libc++ to detect when aligned allocation is unavailable.

2018-08-03 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Aug  3 16:12:37 2018
New Revision: 338934

URL: http://llvm.org/viewvc/llvm-project?rev=338934=rev
Log:
[Preprocessor] Allow libc++ to detect when aligned allocation is unavailable.

Libc++ needs to know when aligned allocation is supported by clang, but is
otherwise unavailable at link time. Otherwise, libc++ will incorrectly end up
generating calls to `__builtin_operator_new`/`__builtin_operator_delete` with
alignment arguments.

This patch implements the following changes:

* The `__cpp_aligned_new` feature test macro to no longer be defined when
  aligned allocation is otherwise enabled but unavailable.

* The Darwin driver no longer passes `-faligned-alloc-unavailable` when the
  user manually specifies `-faligned-allocation` or `-fno-aligned-allocation`.

* Instead of a warning Clang now generates a hard error when an aligned
  allocation or deallocation function is referenced but unavailable.

Patch by Eric Fiselier.

Reviewers: rsmith, vsapsai, erik.pilkington, ahatanak, dexonsmith

Reviewed By: rsmith

Subscribers: Quuxplusone, cfe-commits

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


Added:
cfe/trunk/test/Lexer/aligned-allocation.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/Driver/unavailable_aligned_allocation.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=338934=338933=338934=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Aug  3 16:12:37 2018
@@ -364,7 +364,6 @@ def NonVirtualDtor : DiagGroup<"non-virt
 def NullPointerArithmetic : DiagGroup<"null-pointer-arithmetic">;
 def : DiagGroup<"effc++", [NonVirtualDtor]>;
 def OveralignedType : DiagGroup<"over-aligned">;
-def AlignedAllocationUnavailable : DiagGroup<"aligned-allocation-unavailable">;
 def OldStyleCast : DiagGroup<"old-style-cast">;
 def : DiagGroup<"old-style-definition">;
 def OutOfLineDeclaration : DiagGroup<"out-of-line-declaration">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=338934=338933=338934=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Aug  3 16:12:37 
2018
@@ -6465,12 +6465,12 @@ def warn_overaligned_type : Warning<
   "type %0 requires %1 bytes of alignment and the default allocator only "
   "guarantees %2 bytes">,
   InGroup, DefaultIgnore;
-def warn_aligned_allocation_unavailable :Warning<
+def err_aligned_allocation_unavailable : Error<
   "aligned %select{allocation|deallocation}0 function of type '%1' is only "
-  "available on %2 %3 or newer">, InGroup, 
DefaultError;
+  "available on %2 %3 or newer">;
 def note_silence_unligned_allocation_unavailable : Note<
   "if you supply your own aligned allocation functions, use "
-  "-Wno-aligned-allocation-unavailable to silence this diagnostic">;
+  "-faligned-allocation to silence this diagnostic">;
 
 def err_conditional_void_nonvoid : Error<
   "%select{left|right}1 operand to ? is void, but %select{right|left}1 operand 
"

Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=338934=338933=338934=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Fri Aug  3 16:12:37 2018
@@ -2035,7 +2035,11 @@ bool Darwin::isAlignedAllocationUnavaila
 void Darwin::addClangTargetOptions(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ,
Action::OffloadKind DeviceOffloadKind) 
const {
-  if (isAlignedAllocationUnavailable())
+  // Pass "-faligned-alloc-unavailable" only when the user hasn't manually
+  // enabled or disabled aligned allocations.
+  if (!DriverArgs.hasArgNoClaim(options::OPT_faligned_allocation,
+options::OPT_fno_aligned_allocation) &&
+  isAlignedAllocationUnavailable())
 CC1Args.push_back("-faligned-alloc-unavailable");
 }
 

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=338934=338933=338934=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp 

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

2018-08-03 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr, rsmith.
leonardchan added a project: clang.

Compiling the following causes clang to crash

  void cmp(char *x,  __attribute__((address_space(2))) char *y) {
 0 ? x : y;
  }

with the message: "wrong cast for pointers in different address spaces(must be 
an address space cast)!"

This is because during IR emission, the source and dest type for a bitcast 
should not have differing address spaces.

This fix ensures that an AddressSpaceConversion is used instead while retaining 
the `pointer type mismatch` warnings.


Repository:
  rC Clang

https://reviews.llvm.org/D50278

Files:
  lib/Sema/SemaExpr.cpp
  test/Sema/address_spaces_cond_op.c
  test/Sema/address_spaces_cond_op_ir.c


Index: test/Sema/address_spaces_cond_op_ir.c
===
--- /dev/null
+++ test/Sema/address_spaces_cond_op_ir.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -S -emit-llvm -o - %s | FileCheck %s
+
+#define _AS1 __attribute__((address_space(1)))
+#define _AS2 __attribute__((address_space(2)))
+
+char *cmp(_AS1 char *x, _AS2 char *y) {
+  return x < y ? x : y;
+}
+
+// CHECK:   %x.addr = alloca i8 addrspace(1)*, align 8
+// CHECK-NEXT:  %y.addr = alloca i8 addrspace(2)*, align 8
+// CHECK-NEXT:  store i8 addrspace(1)* %x, i8 addrspace(1)** %x.addr, align 8
+// CHECK-NEXT:  store i8 addrspace(2)* %y, i8 addrspace(2)** %y.addr, align 8
+// CHECK-NEXT:  %0 = load i8 addrspace(1)*, i8 addrspace(1)** %x.addr, align 8
+// CHECK-NEXT:  %1 = load i8 addrspace(2)*, i8 addrspace(2)** %y.addr, align 8
+// CHECK-NEXT:  %2 = addrspacecast i8 addrspace(2)* %1 to i8 addrspace(1)*
Index: test/Sema/address_spaces_cond_op.c
===
--- /dev/null
+++ test/Sema/address_spaces_cond_op.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -ast-dump %s | FileCheck %s
+
+#define _AS1 __attribute__((address_space(1)))
+#define _AS2 __attribute__((address_space(2)))
+
+char *cmp(_AS1 char *x, _AS2 char *y) {
+  return x < y ? x : y;
+}
+
+// CHECK:  |-ImplicitCastExpr {{.*}} 'void *' 
+// CHECK-NEXT: | `-ImplicitCastExpr {{.*}} '__attribute__((address_space(1))) 
char *' 
+// CHECK-NEXT: |   `-DeclRefExpr {{.*}} '__attribute__((address_space(1))) 
char *' {{.*}} 'x' '__attribute__((address_space(1))) char *'
+
+// CHECK: `-ImplicitCastExpr {{.*}} 'void *' 
+// CHECK-NEXT:  `-ImplicitCastExpr {{.*}} '__attribute__((address_space(2))) 
char *' 
+// CHECK-NEXT:   `-DeclRefExpr {{.*}} '__attribute__((address_space(2))) char 
*' {{.*}} 'y' '__attribute__((address_space(2))) char *'
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -6492,13 +6492,11 @@
   // Thus for conditional operator we merge CVR and address space unqualified
   // pointees and if there is a composite type we return a pointer to it with
   // merged qualifiers.
+  LHSCastKind =
+  LAddrSpace == ResultAddrSpace ? CK_BitCast : CK_AddressSpaceConversion;
+  RHSCastKind =
+  RAddrSpace == ResultAddrSpace ? CK_BitCast : CK_AddressSpaceConversion;
   if (S.getLangOpts().OpenCL) {
-LHSCastKind = LAddrSpace == ResultAddrSpace
-  ? CK_BitCast
-  : CK_AddressSpaceConversion;
-RHSCastKind = RAddrSpace == ResultAddrSpace
-  ? CK_BitCast
-  : CK_AddressSpaceConversion;
 lhQual.removeAddressSpace();
 rhQual.removeAddressSpace();
   }


Index: test/Sema/address_spaces_cond_op_ir.c
===
--- /dev/null
+++ test/Sema/address_spaces_cond_op_ir.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -S -emit-llvm -o - %s | FileCheck %s
+
+#define _AS1 __attribute__((address_space(1)))
+#define _AS2 __attribute__((address_space(2)))
+
+char *cmp(_AS1 char *x, _AS2 char *y) {
+  return x < y ? x : y;
+}
+
+// CHECK:   %x.addr = alloca i8 addrspace(1)*, align 8
+// CHECK-NEXT:  %y.addr = alloca i8 addrspace(2)*, align 8
+// CHECK-NEXT:  store i8 addrspace(1)* %x, i8 addrspace(1)** %x.addr, align 8
+// CHECK-NEXT:  store i8 addrspace(2)* %y, i8 addrspace(2)** %y.addr, align 8
+// CHECK-NEXT:  %0 = load i8 addrspace(1)*, i8 addrspace(1)** %x.addr, align 8
+// CHECK-NEXT:  %1 = load i8 addrspace(2)*, i8 addrspace(2)** %y.addr, align 8
+// CHECK-NEXT:  %2 = addrspacecast i8 addrspace(2)* %1 to i8 addrspace(1)*
Index: test/Sema/address_spaces_cond_op.c
===
--- /dev/null
+++ test/Sema/address_spaces_cond_op.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -ast-dump %s | FileCheck %s
+
+#define _AS1 __attribute__((address_space(1)))
+#define _AS2 __attribute__((address_space(2)))
+
+char *cmp(_AS1 char *x, _AS2 char *y) {
+  return x < y ? x : y;
+}
+
+// CHECK:  |-ImplicitCastExpr {{.*}} 'void *' 
+// CHECK-NEXT: | 

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

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

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

> I see, so that's how it's done!
>
> I also noticed that checker name was weird in exploded graph dumps, i.e. it 
> was showing regular new/delete stuff as if it was done by InnerPointer 
> checker. I'll check if this is fixed tomorrow.


This seemed interesting, so I tried out myself on the 
`NewDelete-path-notes.cpp` test file. I saw the following (using IP and ND 
abbreviations for InnerPointer and NewDelete respectively):

Before the patch,

- If only IP was turned on, I got ND's warnings with IP's name everywhere in 
the exploded graph.
- If only ND was turned on, I got the warnings under ND's tag.
- If both IP and ND were turned on, I got the warnings, and saw ND's name 
beside any allocation state change in the graph, but the bugs seemed to be 
tagged with IP's name in the end.

After this patch,

- If only IP is turned on, I get no warning but I see IP's tag in the graph on 
the last PurgeDeadSymbols node (I guess it's normal?).
- If only ND is turned on, I get the warnings with ND's tag everywhere.
- If both IP and ND are turned on, I get the warnings, and I see no trace of 
IP, only ND tags everywhere.

It was really messed up before, but I think I see an improvement there.


Repository:
  rC Clang

https://reviews.llvm.org/D50211



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


[PATCH] D45015: [Preprocessor] Allow libc++ to detect when aligned allocation is unavailable.

2018-08-03 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

Hi, I'm in the process of moving cities. please take over.

Thanks, and sorry


https://reviews.llvm.org/D45015



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


[PATCH] D50205: [libc++] Add availability markup for aligned new/delete

2018-08-03 Thread Louis Dionne via Phabricator via cfe-commits
ldionne updated this revision to Diff 159110.
ldionne added a comment.

Only include availability markup in this patch, do not change whether and when 
aligned allocation functions are used by the library. This will be handled in a 
separate patch.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50205

Files:
  libcxx/include/__config
  libcxx/include/new
  
libcxx/test/libcxx/language.support/support.dynamic/new.delete/new.delete.placement/new_deployment.fail.cpp
  
libcxx/test/libcxx/language.support/support.dynamic/new_faligned_allocation.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/delete_align_val_t_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_nothrow.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_nothrow_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/delete_align_val_t_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_replace.pass.cpp

Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_replace.pass.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_replace.pass.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_replace.pass.cpp
@@ -13,6 +13,13 @@
 // NOTE: GCC doesn't provide a -faligned-allocation flag
 // XFAIL: no-aligned-allocation && !gcc
 
+// XFAIL: availability=macosx10.12
+// XFAIL: availability=macosx10.11
+// XFAIL: availability=macosx10.10
+// XFAIL: availability=macosx10.9
+// XFAIL: availability=macosx10.8
+// XFAIL: availability=macosx10.7
+
 // test operator new replacement
 
 #include 
Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow_replace.pass.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow_replace.pass.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow_replace.pass.cpp
@@ -17,6 +17,13 @@
 // XFAIL: with_system_cxx_lib=macosx10.7
 // XFAIL: with_system_cxx_lib=macosx10.8
 
+// XFAIL: availability=macosx10.12
+// XFAIL: availability=macosx10.11
+// XFAIL: availability=macosx10.10
+// XFAIL: availability=macosx10.9
+// XFAIL: availability=macosx10.8
+// XFAIL: availability=macosx10.7
+
 // NOTE: gcc doesn't provide -faligned-allocation flag to test for
 // XFAIL: no-aligned-allocation && !gcc
 
Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow.pass.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow.pass.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow.pass.cpp
@@ -16,6 +16,13 @@
 // XFAIL: with_system_cxx_lib=macosx10.7
 // XFAIL: with_system_cxx_lib=macosx10.8
 
+// XFAIL: availability=macosx10.12
+// XFAIL: availability=macosx10.11
+// XFAIL: availability=macosx10.10
+// XFAIL: availability=macosx10.9
+// XFAIL: availability=macosx10.8
+// XFAIL: availability=macosx10.7
+
 // asan and msan will not call the new handler.
 // UNSUPPORTED: sanitizer-new-delete
 
Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t.pass.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t.pass.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t.pass.cpp
@@ -16,6 +16,13 @@
 // XFAIL: with_system_cxx_lib=macosx10.7
 // XFAIL: with_system_cxx_lib=macosx10.8
 
+// XFAIL: availability=macosx10.12
+// XFAIL: availability=macosx10.11
+// XFAIL: availability=macosx10.10
+// XFAIL: availability=macosx10.9
+// XFAIL: availability=macosx10.8
+// XFAIL: availability=macosx10.7
+
 // asan and msan will not call the new handler.
 // UNSUPPORTED: sanitizer-new-delete
 

[PATCH] D50276: [clang] Fix broken include_next in float.h

2018-08-03 Thread Louis Dionne via Phabricator via cfe-commits
ldionne created this revision.
ldionne added a reviewer: jfb.
Herald added subscribers: cfe-commits, dexonsmith.

The code defines __FLOAT_H and then includes the next , which is
guarded on __FLOAT_H so it gets skipped entirely. This commit uses the header
guard __CLANG_FLOAT_H, like other headers (such as limits.h) do.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50276

Files:
  clang/lib/Headers/float.h


Index: clang/lib/Headers/float.h
===
--- clang/lib/Headers/float.h
+++ clang/lib/Headers/float.h
@@ -21,8 +21,8 @@
  *===---===
  */
 
-#ifndef __FLOAT_H
-#define __FLOAT_H
+#ifndef __CLANG_FLOAT_H
+#define __CLANG_FLOAT_H
 
 /* If we're on MinGW, fall back to the system's float.h, which might have
  * additional definitions provided for Windows.
@@ -157,4 +157,4 @@
 #  define FLT16_TRUE_MIN__FLT16_TRUE_MIN__
 #endif /* __STDC_WANT_IEC_60559_TYPES_EXT__ */
 
-#endif /* __FLOAT_H */
+#endif /* __CLANG_FLOAT_H */


Index: clang/lib/Headers/float.h
===
--- clang/lib/Headers/float.h
+++ clang/lib/Headers/float.h
@@ -21,8 +21,8 @@
  *===---===
  */
 
-#ifndef __FLOAT_H
-#define __FLOAT_H
+#ifndef __CLANG_FLOAT_H
+#define __CLANG_FLOAT_H
 
 /* If we're on MinGW, fall back to the system's float.h, which might have
  * additional definitions provided for Windows.
@@ -157,4 +157,4 @@
 #  define FLT16_TRUE_MIN__FLT16_TRUE_MIN__
 #endif /* __STDC_WANT_IEC_60559_TYPES_EXT__ */
 
-#endif /* __FLOAT_H */
+#endif /* __CLANG_FLOAT_H */
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r338933 - [NFC][libc++] Consistently use spaces to indent

2018-08-03 Thread Louis Dionne via cfe-commits
Author: ldionne
Date: Fri Aug  3 15:36:53 2018
New Revision: 338933

URL: http://llvm.org/viewvc/llvm-project?rev=338933=rev
Log:
[NFC][libc++] Consistently use spaces to indent

rdar://problem/19988944

Modified:
libcxx/trunk/include/__tree
libcxx/trunk/include/any
libcxx/trunk/include/bitset
libcxx/trunk/include/chrono
libcxx/trunk/include/cstddef
libcxx/trunk/include/functional
libcxx/trunk/include/new
libcxx/trunk/include/numeric
libcxx/trunk/include/span
libcxx/trunk/include/sstream
libcxx/trunk/include/stdexcept
libcxx/trunk/include/typeinfo

Modified: libcxx/trunk/include/__tree
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__tree?rev=338933=338932=338933=diff
==
--- libcxx/trunk/include/__tree (original)
+++ libcxx/trunk/include/__tree Fri Aug  3 15:36:53 2018
@@ -857,7 +857,7 @@ public:
 __tree_iterator operator--(int)
 {__tree_iterator __t(*this); --(*this); return __t;}
 
-friend _LIBCPP_INLINE_VISIBILITY 
+friend _LIBCPP_INLINE_VISIBILITY
 bool operator==(const __tree_iterator& __x, const __tree_iterator& __y)
 {return __x.__ptr_ == __y.__ptr_;}
 friend _LIBCPP_INLINE_VISIBILITY
@@ -1488,7 +1488,7 @@ private:
 void __copy_assign_alloc(const __tree& __t, true_type)
 {
 if (__node_alloc() != __t.__node_alloc())
-   clear();
+clear();
 __node_alloc() = __t.__node_alloc();
 }
 _LIBCPP_INLINE_VISIBILITY
@@ -1830,7 +1830,7 @@ __tree<_Tp, _Compare, _Allocator>::opera
 __node_traits::propagate_on_container_move_assignment::value &&
 is_nothrow_move_assignable::value &&
 is_nothrow_move_assignable<__node_allocator>::value)
-
+
 {
 __move_assign(__t, integral_constant());

Modified: libcxx/trunk/include/any
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/any?rev=338933=338932=338933=diff
==
--- libcxx/trunk/include/any (original)
+++ libcxx/trunk/include/any Fri Aug  3 15:36:53 2018
@@ -110,7 +110,7 @@ void __throw_bad_any_cast()
 #ifndef _LIBCPP_NO_EXCEPTIONS
 throw bad_any_cast();
 #else
-   _VSTD::abort();
+_VSTD::abort();
 #endif
 }
 

Modified: libcxx/trunk/include/bitset
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/bitset?rev=338933=338932=338933=diff
==
--- libcxx/trunk/include/bitset (original)
+++ libcxx/trunk/include/bitset Fri Aug  3 15:36:53 2018
@@ -238,9 +238,9 @@ __bitset<_N_words, _Size>::__init(unsign
 size_t __sz = _Size;
 for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= 
__bits_per_word, __sz -= __bits_per_word )
 if ( __sz < __bits_per_word)
-   __t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) 
- 1;
+__t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1;
 else
-   __t[__i] = static_cast<__storage_type>(__v);
+__t[__i] = static_cast<__storage_type>(__v);
 
 _VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_);
 _VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + 
sizeof(__first_)/sizeof(__first_[0]),
@@ -254,7 +254,7 @@ __bitset<_N_words, _Size>::__init(unsign
 {
 __first_[0] = __v;
 if (_Size < __bits_per_word)
-   __first_[0] &= ( 1ULL << _Size ) - 1;
+__first_[0] &= ( 1ULL << _Size ) - 1;
 
 _VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), 
__storage_type(0));
 }
@@ -269,9 +269,9 @@ __bitset<_N_words, _Size>::__bitset(unsi
 #if __SIZEOF_SIZE_T__ == 8
 : __first_{__v}
 #elif __SIZEOF_SIZE_T__ == 4
-: __first_{static_cast<__storage_type>(__v), 
-   _Size >= 2 * __bits_per_word ? 
static_cast<__storage_type>(__v >> __bits_per_word)
-   : static_cast<__storage_type>((__v >> __bits_per_word) 
& (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
+: __first_{static_cast<__storage_type>(__v),
+_Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v 
>> __bits_per_word)
+: static_cast<__storage_type>((__v >> __bits_per_word) & 
(__storage_type(1) << (_Size - __bits_per_word)) - 1)}
 #else
 #error This constructor has not been ported to this platform
 #endif

Modified: libcxx/trunk/include/chrono
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/chrono?rev=338933=338932=338933=diff
==
--- libcxx/trunk/include/chrono (original)
+++ libcxx/trunk/include/chrono Fri Aug  3 15:36:53 2018
@@ -323,7 +323,7 @@ struct clock_time_conversion;
 
 template
   auto clock_cast(const time_point& t);
-  
+
 // 25.8.2, class last_spec// C++20
 struct last_spec;
 

[PATCH] D37302: [Headers] Define *_HAS_SUBNORM for FLT, DBL, LDBL

2018-08-03 Thread Louis Dionne via Phabricator via cfe-commits
ldionne accepted this revision.
ldionne added a comment.

What are we waiting for to move forward with this change?


Repository:
  rC Clang

https://reviews.llvm.org/D37302



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


[PATCH] D49918: [clang-tidy] Sequence init statements, declarations, and conditions correctly in if, switch, and while

2018-08-03 Thread Martin Böhme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE338932: [clang-tidy] Sequence init statements, 
declarations, and conditions correctly… (authored by mboehme, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D49918?vs=159093=159105#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49918

Files:
  clang-tidy/utils/ExprSequence.cpp
  test/clang-tidy/bugprone-use-after-move.cpp


Index: test/clang-tidy/bugprone-use-after-move.cpp
===
--- test/clang-tidy/bugprone-use-after-move.cpp
+++ test/clang-tidy/bugprone-use-after-move.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++11 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++17 
-fno-delayed-template-parsing
 
 typedef decltype(nullptr) nullptr_t;
 
@@ -1132,13 +1132,30 @@
   }
 }
 
-// If a variable is declared in an if statement, the declaration of the 
variable
-// (which is treated like a reinitialization by the check) is sequenced before
-// the evaluation of the condition (which constitutes a use).
-void ifStmtSequencesDeclAndCondition() {
+// If a variable is declared in an if, while or switch statement, the init
+// statement (for if and switch) is sequenced before the variable declaration,
+// which in turn is sequenced before the evaluation of the condition.
+void ifWhileAndSwitchSequenceInitDeclAndCondition() {
   for (int i = 0; i < 10; ++i) {
-if (A a = A()) {
-  std::move(a);
+A a1;
+if (A a2 = std::move(a1)) {
+  std::move(a2);
+}
+  }
+  for (int i = 0; i < 10; ++i) {
+A a1;
+if (A a2 = std::move(a1); A a3 = std::move(a2)) {
+  std::move(a3);
+}
+  }
+  while (A a = A()) {
+std::move(a);
+  }
+  for (int i = 0; i < 10; ++i) {
+A a1;
+switch (A a2 = a1; A a3 = std::move(a2)) {
+  case true:
+std::move(a3);
 }
   }
 }
Index: clang-tidy/utils/ExprSequence.cpp
===
--- clang-tidy/utils/ExprSequence.cpp
+++ clang-tidy/utils/ExprSequence.cpp
@@ -139,11 +139,26 @@
   if (S == ForRange->getLoopVarStmt())
 return ForRange->getBody();
 } else if (const auto *TheIfStmt = dyn_cast(Parent)) {
-  // If statement: If a variable is declared inside the condition, the
-  // expression used to initialize the variable is sequenced before the
-  // evaluation of the condition.
+  // If statement:
+  // - Sequence init statement before variable declaration.
+  // - Sequence variable declaration (along with the expression used to
+  //   initialize it) before the evaluation of the condition.
+  if (S == TheIfStmt->getInit())
+return TheIfStmt->getConditionVariableDeclStmt();
   if (S == TheIfStmt->getConditionVariableDeclStmt())
 return TheIfStmt->getCond();
+} else if (const auto *TheSwitchStmt = dyn_cast(Parent)) {
+  // Ditto for switch statements.
+  if (S == TheSwitchStmt->getInit())
+return TheSwitchStmt->getConditionVariableDeclStmt();
+  if (S == TheSwitchStmt->getConditionVariableDeclStmt())
+return TheSwitchStmt->getCond();
+} else if (const auto *TheWhileStmt = dyn_cast(Parent)) {
+  // While statement: Sequence variable declaration (along with the
+  // expression used to initialize it) before the evaluation of the
+  // condition.
+  if (S == TheWhileStmt->getConditionVariableDeclStmt())
+return TheWhileStmt->getCond();
 }
   }
 


Index: test/clang-tidy/bugprone-use-after-move.cpp
===
--- test/clang-tidy/bugprone-use-after-move.cpp
+++ test/clang-tidy/bugprone-use-after-move.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++11 -fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++17 -fno-delayed-template-parsing
 
 typedef decltype(nullptr) nullptr_t;
 
@@ -1132,13 +1132,30 @@
   }
 }
 
-// If a variable is declared in an if statement, the declaration of the variable
-// (which is treated like a reinitialization by the check) is sequenced before
-// the evaluation of the condition (which constitutes a use).
-void ifStmtSequencesDeclAndCondition() {
+// If a variable is declared in an if, while or switch statement, the init
+// statement (for if and switch) is sequenced before the variable declaration,
+// which in turn is sequenced before the evaluation of the condition.
+void ifWhileAndSwitchSequenceInitDeclAndCondition() {
   for (int i = 0; i < 10; ++i) {
-if (A a = A()) {
-  std::move(a);
+A a1;
+if (A a2 = std::move(a1)) {
+  std::move(a2);
+}
+  }
+  for (int i = 0; i < 10; ++i) {
+A a1;
+if (A a2 = std::move(a1); A a3 = std::move(a2)) {
+  std::move(a3);
+}
+  

[clang-tools-extra] r338932 - [clang-tidy] Sequence init statements, declarations, and conditions correctly in if, switch, and while

2018-08-03 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Fri Aug  3 15:20:04 2018
New Revision: 338932

URL: http://llvm.org/viewvc/llvm-project?rev=338932=rev
Log:
[clang-tidy] Sequence init statements, declarations, and conditions correctly 
in if, switch, and while

Summary: Fixes https://bugs.llvm.org/show_bug.cgi?id=36516.

Reviewers: ilya-biryukov, alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp

Modified: clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp?rev=338932=338931=338932=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp Fri Aug  3 
15:20:04 2018
@@ -139,11 +139,26 @@ const Stmt *ExprSequence::getSequenceSuc
   if (S == ForRange->getLoopVarStmt())
 return ForRange->getBody();
 } else if (const auto *TheIfStmt = dyn_cast(Parent)) {
-  // If statement: If a variable is declared inside the condition, the
-  // expression used to initialize the variable is sequenced before the
-  // evaluation of the condition.
+  // If statement:
+  // - Sequence init statement before variable declaration.
+  // - Sequence variable declaration (along with the expression used to
+  //   initialize it) before the evaluation of the condition.
+  if (S == TheIfStmt->getInit())
+return TheIfStmt->getConditionVariableDeclStmt();
   if (S == TheIfStmt->getConditionVariableDeclStmt())
 return TheIfStmt->getCond();
+} else if (const auto *TheSwitchStmt = dyn_cast(Parent)) {
+  // Ditto for switch statements.
+  if (S == TheSwitchStmt->getInit())
+return TheSwitchStmt->getConditionVariableDeclStmt();
+  if (S == TheSwitchStmt->getConditionVariableDeclStmt())
+return TheSwitchStmt->getCond();
+} else if (const auto *TheWhileStmt = dyn_cast(Parent)) {
+  // While statement: Sequence variable declaration (along with the
+  // expression used to initialize it) before the evaluation of the
+  // condition.
+  if (S == TheWhileStmt->getConditionVariableDeclStmt())
+return TheWhileStmt->getCond();
 }
   }
 

Modified: clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp?rev=338932=338931=338932=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp Fri Aug 
 3 15:20:04 2018
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++11 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++17 
-fno-delayed-template-parsing
 
 typedef decltype(nullptr) nullptr_t;
 
@@ -1132,13 +1132,30 @@ void forRangeSequences() {
   }
 }
 
-// If a variable is declared in an if statement, the declaration of the 
variable
-// (which is treated like a reinitialization by the check) is sequenced before
-// the evaluation of the condition (which constitutes a use).
-void ifStmtSequencesDeclAndCondition() {
+// If a variable is declared in an if, while or switch statement, the init
+// statement (for if and switch) is sequenced before the variable declaration,
+// which in turn is sequenced before the evaluation of the condition.
+void ifWhileAndSwitchSequenceInitDeclAndCondition() {
   for (int i = 0; i < 10; ++i) {
-if (A a = A()) {
-  std::move(a);
+A a1;
+if (A a2 = std::move(a1)) {
+  std::move(a2);
+}
+  }
+  for (int i = 0; i < 10; ++i) {
+A a1;
+if (A a2 = std::move(a1); A a3 = std::move(a2)) {
+  std::move(a3);
+}
+  }
+  while (A a = A()) {
+std::move(a);
+  }
+  for (int i = 0; i < 10; ++i) {
+A a1;
+switch (A a2 = a1; A a3 = std::move(a2)) {
+  case true:
+std::move(a3);
 }
   }
 }


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


[PATCH] D49223: [AST] Check described template at structural equivalence check.

2018-08-03 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin added inline comments.



Comment at: lib/AST/ASTStructuralEquivalence.cpp:958
 
+  if (D1->isTemplated() != D2->isTemplated())
+return false;

balazske wrote:
> a_sidorin wrote:
> > I think we can move the changes for both RecordDecl and FunctionDecl into 
> > `Finish()` and use `Decl::getDescribedTemplate()`. This will both simplify 
> > the patch and give us the support for templated VarDecls and TypeAliasDecls 
> > for free. What do you think?
> Yes it can be good to check with `getDescribedClassTemplate` in `Finish`. 
> (Similarly, there can be more things that are common to check with all `Decl` 
> or `NamedDecl` objects in `Finish`, specifically the name is checked. Or in 
> some cases the name does not matter, but in others yes?)
I think that name always matters for structure equivalence checking. I cannot 
remember any case where it was false during development of our PoC.


Repository:
  rC Clang

https://reviews.llvm.org/D49223



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


[PATCH] D45712: Diagnose invalid cv-qualifiers for friend decls.

2018-08-03 Thread Eli Friedman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL338931: Diagnose invalid cv-qualifiers for friend decls. 
(authored by efriedma, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D45712?vs=154707=159103#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45712

Files:
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/test/CXX/class.access/class.friend/p3-cxx0x.cpp
  cfe/trunk/test/Modules/odr_hash.cpp

Index: cfe/trunk/test/Modules/odr_hash.cpp
===
--- cfe/trunk/test/Modules/odr_hash.cpp
+++ cfe/trunk/test/Modules/odr_hash.cpp
@@ -2244,22 +2244,6 @@
 #endif
 
 #if defined(FIRST)
-struct T3 {};
-struct S3 {
-  friend const T3;
-};
-#elif defined(SECOND)
-struct T3 {};
-struct S3 {
-  friend T3;
-};
-#else
-S3 s3;
-// expected-error@second.h:* {{'Friend::S3' has different definitions in different modules; first difference is definition in module 'SecondModule' found friend 'Friend::T3'}}
-// expected-note@first.h:* {{but in 'FirstModule' found friend 'const Friend::T3'}}
-#endif
-
-#if defined(FIRST)
 struct T4 {};
 struct S4 {
   friend T4;
@@ -2292,14 +2276,12 @@
   friend class FriendA;  \
   friend struct FriendB; \
   friend FriendC;\
-  friend const FriendD;  \
   friend void Function();
 
 #if defined(FIRST) || defined(SECOND)
 class FriendA {};
 class FriendB {};
 class FriendC {};
-class FriendD {};
 #endif
 
 #if defined(FIRST) || defined(SECOND)
Index: cfe/trunk/test/CXX/class.access/class.friend/p3-cxx0x.cpp
===
--- cfe/trunk/test/CXX/class.access/class.friend/p3-cxx0x.cpp
+++ cfe/trunk/test/CXX/class.access/class.friend/p3-cxx0x.cpp
@@ -52,14 +52,25 @@
   // Ill-formed
   int friend; // expected-error {{'friend' must appear first in a non-function declaration}}
   unsigned friend int; // expected-error {{'friend' must appear first in a non-function declaration}}
-  const volatile friend int; // expected-error {{'friend' must appear first in a non-function declaration}}
+  const volatile friend int; // expected-error {{'friend' must appear first in a non-function declaration}} \
+ // expected-error {{'const' is invalid in friend declarations}} \
+ // expected-error {{'volatile' is invalid in friend declarations}}
   int
   friend; // expected-error {{'friend' must appear first in a non-function declaration}}
+  friend const int; // expected-error {{'const' is invalid in friend declarations}}
+  friend volatile int; // expected-error {{'volatile' is invalid in friend declarations}}
+  template  friend const class X; // expected-error {{'const' is invalid in friend declarations}}
+  // C++ doesn't have restrict and _Atomic, but they're both the same sort
+  // of qualifier.
+  typedef int *PtrToInt;
+  friend __restrict PtrToInt; // expected-error {{'restrict' is invalid in friend declarations}} \
+  // expected-error {{restrict requires a pointer or reference}}
+  friend _Atomic int; // expected-error {{'_Atomic' is invalid in friend declarations}}
 
   // OK
   int friend foo(void);
+  const int friend foo2(void);
   friend int;
-  friend const volatile int;
   friend
 
   float;
Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -14017,6 +14017,29 @@
   assert(DS.isFriendSpecified());
   assert(DS.getStorageClassSpec() == DeclSpec::SCS_unspecified);
 
+  // C++ [class.friend]p3:
+  // A friend declaration that does not declare a function shall have one of
+  // the following forms:
+  // friend elaborated-type-specifier ;
+  // friend simple-type-specifier ;
+  // friend typename-specifier ;
+  //
+  // Any declaration with a type qualifier does not have that form. (It's
+  // legal to specify a qualified type as a friend, you just can't write the
+  // keywords.)
+  if (DS.getTypeQualifiers()) {
+if (DS.getTypeQualifiers() & DeclSpec::TQ_const)
+  Diag(DS.getConstSpecLoc(), diag::err_friend_decl_spec) << "const";
+if (DS.getTypeQualifiers() & DeclSpec::TQ_volatile)
+  Diag(DS.getVolatileSpecLoc(), diag::err_friend_decl_spec) << "volatile";
+if (DS.getTypeQualifiers() & DeclSpec::TQ_restrict)
+  Diag(DS.getRestrictSpecLoc(), diag::err_friend_decl_spec) << "restrict";
+if (DS.getTypeQualifiers() & DeclSpec::TQ_atomic)
+  Diag(DS.getAtomicSpecLoc(), diag::err_friend_decl_spec) << "_Atomic";
+if (DS.getTypeQualifiers() & DeclSpec::TQ_unaligned)
+  Diag(DS.getUnalignedSpecLoc(), diag::err_friend_decl_spec) << "__unaligned";
+  }
+
   // Try to convert the decl specifier to a type.  This works for
   // friend templates because ActOnTag never produces a ClassTemplateDecl
   // 

r338931 - Diagnose invalid cv-qualifiers for friend decls.

2018-08-03 Thread Eli Friedman via cfe-commits
Author: efriedma
Date: Fri Aug  3 15:09:44 2018
New Revision: 338931

URL: http://llvm.org/viewvc/llvm-project?rev=338931=rev
Log:
Diagnose invalid cv-qualifiers for friend decls.

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


Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CXX/class.access/class.friend/p3-cxx0x.cpp
cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=338931=338930=338931=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Aug  3 15:09:44 2018
@@ -14017,6 +14017,29 @@ Decl *Sema::ActOnFriendTypeDecl(Scope *S
   assert(DS.isFriendSpecified());
   assert(DS.getStorageClassSpec() == DeclSpec::SCS_unspecified);
 
+  // C++ [class.friend]p3:
+  // A friend declaration that does not declare a function shall have one of
+  // the following forms:
+  // friend elaborated-type-specifier ;
+  // friend simple-type-specifier ;
+  // friend typename-specifier ;
+  //
+  // Any declaration with a type qualifier does not have that form. (It's
+  // legal to specify a qualified type as a friend, you just can't write the
+  // keywords.)
+  if (DS.getTypeQualifiers()) {
+if (DS.getTypeQualifiers() & DeclSpec::TQ_const)
+  Diag(DS.getConstSpecLoc(), diag::err_friend_decl_spec) << "const";
+if (DS.getTypeQualifiers() & DeclSpec::TQ_volatile)
+  Diag(DS.getVolatileSpecLoc(), diag::err_friend_decl_spec) << "volatile";
+if (DS.getTypeQualifiers() & DeclSpec::TQ_restrict)
+  Diag(DS.getRestrictSpecLoc(), diag::err_friend_decl_spec) << "restrict";
+if (DS.getTypeQualifiers() & DeclSpec::TQ_atomic)
+  Diag(DS.getAtomicSpecLoc(), diag::err_friend_decl_spec) << "_Atomic";
+if (DS.getTypeQualifiers() & DeclSpec::TQ_unaligned)
+  Diag(DS.getUnalignedSpecLoc(), diag::err_friend_decl_spec) << 
"__unaligned";
+  }
+
   // Try to convert the decl specifier to a type.  This works for
   // friend templates because ActOnTag never produces a ClassTemplateDecl
   // for a TUK_Friend.

Modified: cfe/trunk/test/CXX/class.access/class.friend/p3-cxx0x.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class.access/class.friend/p3-cxx0x.cpp?rev=338931=338930=338931=diff
==
--- cfe/trunk/test/CXX/class.access/class.friend/p3-cxx0x.cpp (original)
+++ cfe/trunk/test/CXX/class.access/class.friend/p3-cxx0x.cpp Fri Aug  3 
15:09:44 2018
@@ -52,14 +52,25 @@ struct {
   // Ill-formed
   int friend; // expected-error {{'friend' must appear first in a non-function 
declaration}}
   unsigned friend int; // expected-error {{'friend' must appear first in a 
non-function declaration}}
-  const volatile friend int; // expected-error {{'friend' must appear first in 
a non-function declaration}}
+  const volatile friend int; // expected-error {{'friend' must appear first in 
a non-function declaration}} \
+ // expected-error {{'const' is invalid in friend 
declarations}} \
+ // expected-error {{'volatile' is invalid in 
friend declarations}}
   int
   friend; // expected-error {{'friend' must appear first in a 
non-function declaration}}
+  friend const int; // expected-error {{'const' is invalid in friend 
declarations}}
+  friend volatile int; // expected-error {{'volatile' is invalid in friend 
declarations}}
+  template  friend const class X; // expected-error {{'const' is 
invalid in friend declarations}}
+  // C++ doesn't have restrict and _Atomic, but they're both the same sort
+  // of qualifier.
+  typedef int *PtrToInt;
+  friend __restrict PtrToInt; // expected-error {{'restrict' is invalid in 
friend declarations}} \
+  // expected-error {{restrict requires a pointer 
or reference}}
+  friend _Atomic int; // expected-error {{'_Atomic' is invalid in friend 
declarations}}
 
   // OK
   int friend foo(void);
+  const int friend foo2(void);
   friend int;
-  friend const volatile int;
   friend
 
   float;

Modified: cfe/trunk/test/Modules/odr_hash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash.cpp?rev=338931=338930=338931=diff
==
--- cfe/trunk/test/Modules/odr_hash.cpp (original)
+++ cfe/trunk/test/Modules/odr_hash.cpp Fri Aug  3 15:09:44 2018
@@ -2244,22 +2244,6 @@ S2 s2;
 #endif
 
 #if defined(FIRST)
-struct T3 {};
-struct S3 {
-  friend const T3;
-};
-#elif defined(SECOND)
-struct T3 {};
-struct S3 {
-  friend T3;
-};
-#else
-S3 s3;
-// expected-error@second.h:* {{'Friend::S3' has different definitions in 
different modules; first difference is definition in module 'SecondModule' 
found friend 'Friend::T3'}}
-// 

[PATCH] D50194: LLVM Proto Fuzzer - Run Functions on Suite of Inputs

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

Added static to some functions, made small fixes


Repository:
  rC Clang

https://reviews.llvm.org/D50194

Files:
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.h
  clang/tools/clang-fuzzer/handle-llvm/input_arrays.h

Index: clang/tools/clang-fuzzer/handle-llvm/input_arrays.h
===
--- /dev/null
+++ clang/tools/clang-fuzzer/handle-llvm/input_arrays.h
@@ -0,0 +1,126 @@
+//==-- input_arrays.h - Helper function for LLVM fuzzer inputs -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Define a few static variables used by the LLVM Proto Fuzzer
+//
+//===--===//
+
+#include 
+#include 
+
+static const int ArraySize = 64;
+static const int NumArrays = 100;
+static const int TotalSize = sizeof(int) * ArraySize * NumArrays;
+
+// Define two arrays that will hold the input and output for the two functions
+static int OptArrays[NumArrays][ArraySize];
+static int UnoptArrays[NumArrays][ArraySize];
+
+// Define a corpus of possible inputs
+static int InputArrays[NumArrays][ArraySize] =
+{ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+  {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
+  {0, 0, 0, 5, 0, 2, 0, 8, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
+  {1, 1, 2, 1, 6, 0, 3, 1, 10, 10, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
+  {0, 0, 2, 0, 0, 7, 0, 4, 2, 0, 12, 12, 0, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
+  {1, 1, 0, 2, 2, 9, 8, 0, 5, 3, 1, 14, 14, 14, 0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14},
+  {0, 0, 0, 4, 0, 1, 10, 9, 0, 6, 4, 2, 0, 16, 16, 16, 0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16},
+  {1, 1, 2, 3, 2, 3, 0, 11, 10, 0, 7, 5, 3, 1, 18, 18, 18, 18, 0, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18},
+  {0, 0, 2, 5, 4, 0, 2, 13, 12, 11, 0, 8, 6, 4, 2, 0, 20, 20, 20, 20, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
+  {1, 1, 0, 1, 6, 2, 4, 1, 14, 13, 12, 0, 9, 7, 5, 3, 1, 22, 22, 22, 22, 22, 0, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22},
+  {0, 0, 0, 0, 4, 4, 0, 3, 0, 15, 14, 13, 0, 10, 8, 6, 4, 2, 0, 24, 24, 24, 24, 24, 0, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24},
+  {1, 1, 2, 2, 6, 6, 2, 5, 2, 17, 16, 15, 14, 0, 11, 9, 7, 5, 3, 1, 26, 26, 26, 26, 26, 26, 0, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26},
+  {0, 0, 2, 4, 0, 8, 4, 0, 4, 1, 18, 17, 16, 15, 0, 12, 10, 8, 6, 4, 2, 0, 28, 28, 28, 28, 28, 28, 0, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 

[PATCH] D45015: [Preprocessor] Allow libc++ to detect when aligned allocation is unavailable.

2018-08-03 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Eric, will you have time to commit this patch? If you don't have time and don't 
have objections, I plan to land this change on your behalf.


https://reviews.llvm.org/D45015



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


[PATCH] D50194: LLVM Proto Fuzzer - Run Functions on Suite of Inputs

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



Comment at: clang/tools/clang-fuzzer/handle-llvm/input_arrays.h:36
+  {1, 1, 2, 3, 2, 3, 0, 11, 10, 0, 7, 5, 3, 1, 18, 18, 18, 18, 0, 18, 18, 18, 
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 
18, 18},
+  {0, 0, 2, 5, 4, 0, 2, 13, 12, 11, 0, 8, 6, 4, 2, 0, 20, 20, 20, 20, 0, 20, 
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 
20, 20},
+  {1, 1, 0, 1, 6, 2, 4, 1, 14, 13, 12, 0, 9, 7, 5, 3, 1, 22, 22, 22, 22, 22, 
0, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 
22, 22},

kcc wrote:
> constants are not diverse enough. 
Yeah, I will completely redo the input arrays.


Repository:
  rC Clang

https://reviews.llvm.org/D50194



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


[PATCH] D48714: [clang-tidy] fix PR37913, templated exception factory diagnosed correctly

2018-08-03 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 159099.
JonasToth added a comment.

- add better diagnostics about template instantiated exception types


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48714

Files:
  clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
  test/clang-tidy/hicpp-exception-baseclass.cpp

Index: test/clang-tidy/hicpp-exception-baseclass.cpp
===
--- test/clang-tidy/hicpp-exception-baseclass.cpp
+++ test/clang-tidy/hicpp-exception-baseclass.cpp
@@ -2,6 +2,7 @@
 
 namespace std {
 class exception {};
+class invalid_argument : public exception {};
 } // namespace std
 
 class derived_exception : public std::exception {};
@@ -36,38 +37,38 @@
   try {
 throw non_derived_exception();
 // CHECK-MESSAGES: [[@LINE-1]]:11: warning: throwing an exception whose type 'non_derived_exception' is not derived from 'std::exception'
-// CHECK-MESSAGES: 9:1: note: type defined here
+// CHECK-MESSAGES: 10:1: note: type defined here
   } catch (non_derived_exception ) {
   }
   throw non_derived_exception();
   // CHECK-MESSAGES: [[@LINE-1]]:9: warning: throwing an exception whose type 'non_derived_exception' is not derived from 'std::exception'
-  // CHECK-MESSAGES: 9:1: note: type defined here
+  // CHECK-MESSAGES: 10:1: note: type defined here
 
 // FIXME: More complicated kinds of inheritance should be checked later, but there is
 // currently no way use ASTMatchers for this kind of task.
 #if 0
   // Handle private inheritance cases correctly.
   try {
 throw bad_inheritance();
 // CHECK MESSAGES: [[@LINE-1]]:11: warning: throwing an exception whose type 'bad_inheritance' is not derived from 'std::exception'
-// CHECK MESSAGES: 10:1: note: type defined here
+// CHECK MESSAGES: 11:1: note: type defined here
 throw no_good_inheritance();
 // CHECK MESSAGES: [[@LINE-1]]:11: warning: throwing an exception whose type 'no_good_inheritance' is not derived from 'std::exception'
-// CHECK MESSAGES: 11:1: note: type defined here
+// CHECK MESSAGES: 12:1: note: type defined here
 throw really_creative();
 // CHECK MESSAGES: [[@LINE-1]]:11: warning: throwing an exception whose type 'really_creative' is not derived from 'std::exception'
-// CHECK MESSAGES: 12:1: note: type defined here
+// CHECK MESSAGES: 13:1: note: type defined here
   } catch (...) {
   }
   throw bad_inheritance();
   // CHECK MESSAGES: [[@LINE-1]]:9: warning: throwing an exception whose type 'bad_inheritance' is not derived from 'std::exception'
-  // CHECK MESSAGES: 10:1: note: type defined here
+  // CHECK MESSAGES: 11:1: note: type defined here
   throw no_good_inheritance();
   // CHECK MESSAGES: [[@LINE-1]]:9: warning: throwing an exception whose type 'no_good_inheritance' is not derived from 'std::exception'
-  // CHECK MESSAGES: 11:1: note: type defined here
+  // CHECK MESSAGES: 12:1: note: type defined here
   throw really_creative();
   // CHECK MESSAGES: [[@LINE-1]]:9: warning: throwing an exception whose type 'really_creative' is not derived from 'std::exception'
-  // CHECK MESSAGES: 12:1: note: type defined here
+  // CHECK MESSAGES: 13:1: note: type defined here
 #endif
 }
 
@@ -91,7 +92,7 @@
   throw deep_hierarchy(); // Ok
 
   try {
-throw terrible_idea(); // Ok, but multiple inheritance isn't clean
+throw terrible_idea();  // Ok, but multiple inheritance isn't clean
   } catch (std::exception ) { // Can be caught as std::exception, even with multiple inheritance
   }
   throw terrible_idea(); // Ok, but multiple inheritance
@@ -101,14 +102,10 @@
 template 
 void ThrowException() { throw T(); }
 // CHECK-MESSAGES: [[@LINE-1]]:31: warning: throwing an exception whose type 'bad_generic_exception' is not derived from 'std::exception'
-// CHECK-MESSAGES: 120:1: note: type defined here
-// CHECK-MESSAGES: [[@LINE-3]]:31: warning: throwing an exception whose type 'bad_generic_exception' is not derived from 'std::exception'
-// CHECK-MESSAGES: 120:1: note: type defined here
-// CHECK-MESSAGES: [[@LINE-5]]:31: warning: throwing an exception whose type 'exotic_exception' is not derived from 'std::exception'
-// CHECK-MESSAGES: 123:1: note: type defined here
-// CHECK-MESSAGES: [[@LINE-7]]:31: warning: throwing an exception whose type 'int' is not derived from 'std::exception'
-// CHECK-MESSAGES: [[@LINE-8]]:31: warning: throwing an exception whose type 'non_derived_exception' is not derived from 'std::exception'
-// CHECK-MESSAGES: 9:1: note: type defined here
+// CHECK-MESSAGES: [[@LINE-2]]:31: warning: throwing an exception whose type 'bad_generic_exception' is not derived from 'std::exception'
+// CHECK-MESSAGES: [[@LINE-3]]:31: warning: throwing an exception whose type 'exotic_exception' is not derived from 'std::exception'
+// CHECK-MESSAGES: [[@LINE-4]]:31: warning: throwing an exception whose type 'int' is not derived from 'std::exception'
+// CHECK-MESSAGES: [[@LINE-5]]:31: 

[PATCH] D50250: [clang][ubsan] Implicit Conversion Sanitizer - integer sign change - clang part

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



Comment at: lib/CodeGen/CGExprScalar.cpp:1036
+return;
+  // That's it. We can't rule out any more cases with the data we have.
+

rsmith wrote:
> lebedev.ri wrote:
> > rsmith wrote:
> > > I don't like the overlap between the implicit truncation check and this 
> > > check. I think you should aim for exactly one of those checks to fire for 
> > > any given integer conversion. There are the following cases:
> > > 
> > >  * Dst is smaller than Src: if the value changes at all (with sign change 
> > > or without), then the truncation check already catches it, and catching 
> > > it here does not seem useful
> > >  * Dst is the same size as Src or larger: sign change is the only 
> > > problem, and is only possible if exactly one of Src and Dst is signed
> > > 
> > > So I think you should bail out of this function if either Src and Dst are 
> > > both unsigned or both are signed, and also if Src is larger than Dst 
> > > (because we treat that case as a lossy truncation rather than as a sign 
> > > change).
> > > 
> > > And when you do emit a check here, the only thing you need to check is if 
> > > the signed value is negative (if so, you definitely changed the sign, and 
> > > if not, you definitely didn't -- except in the truncation cases that the 
> > > truncation sanitizer catches).
> > To be clear: we want to skip emitting in those cases if the other check 
> > (truncation) is enabled, right?
> > It does seem to make sense, (and i did thought about that a bit), but i 
> > need to think about it more..
> I think we want to skip emitting those checks always (regardless of whether 
> the other sanitizer is enabled). One way to think of it: this sanitizer 
> checks for non-truncating implicit integer conversions that change the value 
> of the result. The other sanitizer checks for truncating implicit integer 
> conversions that change the value of the result.
> 
> I don't see any point in allowing the user to ask to sanitize sign-changing 
> truncation but not other value-changing truncations. That would lead to this:
> ```
> int a = 0x17fff; // no sanitizer warning
> int b = 0x18000; // sanitizer warning
> int c = 0x1; // sanitizer warning
> int d = 0x2; // no sanitizer warning
> ```
> ... which I think makes no sense.
Hmm, wait, the "truncation" sanitizer doesn't catch this:

`int a = 0x8000u;`

... does it? (Because it looks for cases where the value doesn't round-trip, 
not for cases where the value was changed by the truncation.)


I've thought a bit more about the user model and use cases for these 
sanitizers, and I think what we want is:

 * a sanitizer that checks for implicit conversions with data loss (the 
existing truncation sanitizer)
 * a sanitizer that checks for implicit conversions that change the value, 
where either the source or destination was signed (approximately what this 
sanitizer is doing)

The difference between that and what you have here is that I think the new 
sanitizer should catch all of these cases:

```
int a = 0x17fff;
int b = 0x18000;
int c = 0x1;
int d = 0x2;
```

... because while the initializations of `a` and `d` don't change the sign of 
the result, that's only because they wrap around *past* a sign change.

So, I think what you have here is fine for the SrcBits <= DstBits case, but for 
the SrcBits > DstBits case, you should also check whether the value is the same 
as the original (that is, perform the truncation check).

In order to avoid duplicating work when both sanitizers are enabled, it'd make 
sense to combine the two sanitizer functions into a single function and reuse 
the checks.


Repository:
  rC Clang

https://reviews.llvm.org/D50250



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


[PATCH] D50194: LLVM Proto Fuzzer - Run Functions on Suite of Inputs

2018-08-03 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

In https://reviews.llvm.org/D50194#1187756, @emmettneyman wrote:

> An unrelated question:
>  Right now I have a mix of `static` and non-`static` functions in 
> `handle_llvm.cpp`. Should they all be `static`?


Any functions that are only used in the same file can and should be `static` or 
in an unnamed namespace.  Functions that implement something from a header file 
must not be `static`.


Repository:
  rC Clang

https://reviews.llvm.org/D50194



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


[PATCH] D50194: LLVM Proto Fuzzer - Run Functions on Suite of Inputs

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



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:75
 
+// Helper function to print error message and stop the fuzzer
 void ErrorAndExit(std::string message) {

Unnecessary comment.   The naming and implementation of this function are 
intuitive.



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:170
 
-  typedef void (*func)(int*, int*, int*, int);
-  func f = reinterpret_cast(EE->getPointerToFunction(EntryFunc)); 
+  LLVMFunc f = (LLVMFunc) EE->getPointerToFunction(EntryFunc); 
 

Does `reinterpret_cast` work here?



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:184
+  // Populate OptArrays and UnoptArrays with the arrays from InputArrays
+  memcpy(OptArrays, InputArrays, sizeof(int) * ArraySize * NumArrays);
+  memcpy(UnoptArrays, InputArrays, sizeof(int) * ArraySize * NumArrays);

The size here is reused a few times.  Let's create a variable for it.


Repository:
  rC Clang

https://reviews.llvm.org/D50194



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


[PATCH] D50250: [clang][ubsan] Implicit Conversion Sanitizer - integer sign change - clang part

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



Comment at: lib/CodeGen/CGExprScalar.cpp:1036
+return;
+  // That's it. We can't rule out any more cases with the data we have.
+

lebedev.ri wrote:
> rsmith wrote:
> > I don't like the overlap between the implicit truncation check and this 
> > check. I think you should aim for exactly one of those checks to fire for 
> > any given integer conversion. There are the following cases:
> > 
> >  * Dst is smaller than Src: if the value changes at all (with sign change 
> > or without), then the truncation check already catches it, and catching it 
> > here does not seem useful
> >  * Dst is the same size as Src or larger: sign change is the only problem, 
> > and is only possible if exactly one of Src and Dst is signed
> > 
> > So I think you should bail out of this function if either Src and Dst are 
> > both unsigned or both are signed, and also if Src is larger than Dst 
> > (because we treat that case as a lossy truncation rather than as a sign 
> > change).
> > 
> > And when you do emit a check here, the only thing you need to check is if 
> > the signed value is negative (if so, you definitely changed the sign, and 
> > if not, you definitely didn't -- except in the truncation cases that the 
> > truncation sanitizer catches).
> To be clear: we want to skip emitting in those cases if the other check 
> (truncation) is enabled, right?
> It does seem to make sense, (and i did thought about that a bit), but i need 
> to think about it more..
I think we want to skip emitting those checks always (regardless of whether the 
other sanitizer is enabled). One way to think of it: this sanitizer checks for 
non-truncating implicit integer conversions that change the value of the 
result. The other sanitizer checks for truncating implicit integer conversions 
that change the value of the result.

I don't see any point in allowing the user to ask to sanitize sign-changing 
truncation but not other value-changing truncations. That would lead to this:
```
int a = 0x17fff; // no sanitizer warning
int b = 0x18000; // sanitizer warning
int c = 0x1; // sanitizer warning
int d = 0x2; // no sanitizer warning
```
... which I think makes no sense.



Comment at: lib/CodeGen/CGExprScalar.cpp:1050-1051
+// NOTE: if it is unsigned, then the comparison is naturally always 
'false'.
+llvm::ICmpInst::Predicate Pred =
+VSigned ? llvm::ICmpInst::ICMP_SLT : llvm::ICmpInst::ICMP_ULT;
+// Get the zero of the same type with which we will be comparing.

lebedev.ri wrote:
> rsmith wrote:
> > If `!VSigned`, the result is a constant `false`; you don't need to emit an 
> > `icmp` to work that out.
> Ok, if you insist.
> I didn't do that in the first place because we will now have an `icmp`
> where one operand being a constant, so we can simplify it further.
> And i don't want to complicate this logic if middle-end already handles it :)
This becomes a lot simpler with the approach I described in the other comment 
thread, because you don't need a second `icmp eq` at all.


Repository:
  rC Clang

https://reviews.llvm.org/D50250



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


[PATCH] D49918: [clang-tidy] Sequence init statements, declarations, and conditions correctly in if, switch, and while

2018-08-03 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 159093.
mboehme added a comment.

Apply clang-format.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49918

Files:
  clang-tidy/utils/ExprSequence.cpp
  test/clang-tidy/bugprone-use-after-move.cpp


Index: test/clang-tidy/bugprone-use-after-move.cpp
===
--- test/clang-tidy/bugprone-use-after-move.cpp
+++ test/clang-tidy/bugprone-use-after-move.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++11 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++17 
-fno-delayed-template-parsing
 
 typedef decltype(nullptr) nullptr_t;
 
@@ -1132,13 +1132,30 @@
   }
 }
 
-// If a variable is declared in an if statement, the declaration of the 
variable
-// (which is treated like a reinitialization by the check) is sequenced before
-// the evaluation of the condition (which constitutes a use).
-void ifStmtSequencesDeclAndCondition() {
+// If a variable is declared in an if, while or switch statement, the init
+// statement (for if and switch) is sequenced before the variable declaration,
+// which in turn is sequenced before the evaluation of the condition.
+void ifWhileAndSwitchSequenceInitDeclAndCondition() {
   for (int i = 0; i < 10; ++i) {
-if (A a = A()) {
-  std::move(a);
+A a1;
+if (A a2 = std::move(a1)) {
+  std::move(a2);
+}
+  }
+  for (int i = 0; i < 10; ++i) {
+A a1;
+if (A a2 = std::move(a1); A a3 = std::move(a2)) {
+  std::move(a3);
+}
+  }
+  while (A a = A()) {
+std::move(a);
+  }
+  for (int i = 0; i < 10; ++i) {
+A a1;
+switch (A a2 = a1; A a3 = std::move(a2)) {
+  case true:
+std::move(a3);
 }
   }
 }
Index: clang-tidy/utils/ExprSequence.cpp
===
--- clang-tidy/utils/ExprSequence.cpp
+++ clang-tidy/utils/ExprSequence.cpp
@@ -139,11 +139,26 @@
   if (S == ForRange->getLoopVarStmt())
 return ForRange->getBody();
 } else if (const auto *TheIfStmt = dyn_cast(Parent)) {
-  // If statement: If a variable is declared inside the condition, the
-  // expression used to initialize the variable is sequenced before the
-  // evaluation of the condition.
+  // If statement:
+  // - Sequence init statement before variable declaration.
+  // - Sequence variable declaration (along with the expression used to
+  //   initialize it) before the evaluation of the condition.
+  if (S == TheIfStmt->getInit())
+return TheIfStmt->getConditionVariableDeclStmt();
   if (S == TheIfStmt->getConditionVariableDeclStmt())
 return TheIfStmt->getCond();
+} else if (const auto *TheSwitchStmt = dyn_cast(Parent)) {
+  // Ditto for switch statements.
+  if (S == TheSwitchStmt->getInit())
+return TheSwitchStmt->getConditionVariableDeclStmt();
+  if (S == TheSwitchStmt->getConditionVariableDeclStmt())
+return TheSwitchStmt->getCond();
+} else if (const auto *TheWhileStmt = dyn_cast(Parent)) {
+  // While statement: Sequence variable declaration (along with the
+  // expression used to initialize it) before the evaluation of the
+  // condition.
+  if (S == TheWhileStmt->getConditionVariableDeclStmt())
+return TheWhileStmt->getCond();
 }
   }
 


Index: test/clang-tidy/bugprone-use-after-move.cpp
===
--- test/clang-tidy/bugprone-use-after-move.cpp
+++ test/clang-tidy/bugprone-use-after-move.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++11 -fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++17 -fno-delayed-template-parsing
 
 typedef decltype(nullptr) nullptr_t;
 
@@ -1132,13 +1132,30 @@
   }
 }
 
-// If a variable is declared in an if statement, the declaration of the variable
-// (which is treated like a reinitialization by the check) is sequenced before
-// the evaluation of the condition (which constitutes a use).
-void ifStmtSequencesDeclAndCondition() {
+// If a variable is declared in an if, while or switch statement, the init
+// statement (for if and switch) is sequenced before the variable declaration,
+// which in turn is sequenced before the evaluation of the condition.
+void ifWhileAndSwitchSequenceInitDeclAndCondition() {
   for (int i = 0; i < 10; ++i) {
-if (A a = A()) {
-  std::move(a);
+A a1;
+if (A a2 = std::move(a1)) {
+  std::move(a2);
+}
+  }
+  for (int i = 0; i < 10; ++i) {
+A a1;
+if (A a2 = std::move(a1); A a3 = std::move(a2)) {
+  std::move(a3);
+}
+  }
+  while (A a = A()) {
+std::move(a);
+  }
+  for (int i = 0; i < 10; ++i) {
+A a1;
+switch (A a2 = a1; A a3 = std::move(a2)) {
+  case true:
+std::move(a3);
 }
   }
 }
Index: 

[PATCH] D50194: LLVM Proto Fuzzer - Run Functions on Suite of Inputs

2018-08-03 Thread Kostya Serebryany via Phabricator via cfe-commits
kcc added inline comments.



Comment at: clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp:128
+void RunFuncOnInputs(LLVMFunc f, int x) {
+  if (x) {
+for (int i = 0; i < NumArrays; i++)

looks like code duplication, also strange name for a variable: 'x'. 
Can't we just have one loop here and pass OptArrays/UnoptArrays as the 
parameter? 



Comment at: clang/tools/clang-fuzzer/handle-llvm/input_arrays.h:36
+  {1, 1, 2, 3, 2, 3, 0, 11, 10, 0, 7, 5, 3, 1, 18, 18, 18, 18, 0, 18, 18, 18, 
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 
18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 
18, 18},
+  {0, 0, 2, 5, 4, 0, 2, 13, 12, 11, 0, 8, 6, 4, 2, 0, 20, 20, 20, 20, 0, 20, 
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 
20, 20},
+  {1, 1, 0, 1, 6, 2, 4, 1, 14, 13, 12, 0, 9, 7, 5, 3, 1, 22, 22, 22, 22, 22, 
0, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 
22, 22},

constants are not diverse enough. 


Repository:
  rC Clang

https://reviews.llvm.org/D50194



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


[PATCH] D43424: [clang-doc] Implement a (simple) Markdown generator

2018-08-03 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 159091.
juliehockett marked an inline comment as done.
juliehockett added a comment.
Herald added a subscriber: arphaman.

Updating based on recent landed patches & updated tests


https://reviews.llvm.org/D43424

Files:
  clang-tools-extra/clang-doc/CMakeLists.txt
  clang-tools-extra/clang-doc/Generators.cpp
  clang-tools-extra/clang-doc/Generators.h
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/clang-doc/gen_tests.py
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/test/clang-doc/md-comment.cpp
  clang-tools-extra/test/clang-doc/md-linkage.cpp
  clang-tools-extra/test/clang-doc/md-module.cpp
  clang-tools-extra/test/clang-doc/md-namespace.cpp
  clang-tools-extra/test/clang-doc/md-record.cpp

Index: clang-tools-extra/test/clang-doc/md-record.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-doc/md-record.cpp
@@ -0,0 +1,97 @@
+// THIS IS A GENERATED TEST. DO NOT EDIT.
+// To regenerate, see clang-doc/gen_test.py docstring.
+//
+// This test requires Linux due to system-dependent USR for the inner class.
+// REQUIRES: system-linux
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+
+void H() {
+  class I {};
+}
+
+union A { int X; int Y; };
+
+enum B { X, Y };
+
+enum class Bc { A, B };
+
+struct C { int i; };
+
+class D {};
+
+class E {
+public:
+  E() {}
+  ~E() {}
+
+protected:
+  void ProtectedMethod();
+};
+
+void E::ProtectedMethod() {}
+
+class F : virtual private D, public E {};
+
+class X {
+  class Y {};
+};
+
+// RUN: clang-doc --format=md --doxygen --public --extra-arg=-fmodules-ts -p %t %t/test.cpp -output=%t/docs
+
+
+// RUN: cat %t/docs/./F.md | FileCheck %s --check-prefix CHECK-0
+// CHECK-0: # class F
+// CHECK-0: *Defined at line 36 of test*
+// CHECK-0: Inherits from E, D
+
+// RUN: cat %t/docs/./D.md | FileCheck %s --check-prefix CHECK-1
+// CHECK-1: # class D
+// CHECK-1: *Defined at line 23 of test*
+
+// RUN: cat %t/docs/./GlobalNamespace.md | FileCheck %s --check-prefix CHECK-2
+// CHECK-2: # Global Namespace
+// CHECK-2: ## Functions
+// CHECK-2: ### void H()
+// CHECK-2: *Defined at line 11 of test*
+// CHECK-2: ## Enums
+// CHECK-2: | enum B |
+// CHECK-2: --
+// CHECK-2: | X |
+// CHECK-2: | Y |
+// CHECK-2: *Defined at line 17 of test*
+// CHECK-2: | enum class Bc |
+// CHECK-2: --
+// CHECK-2: | A |
+// CHECK-2: | B |
+// CHECK-2: *Defined at line 19 of test*
+
+// RUN: cat %t/docs/./E.md | FileCheck %s --check-prefix CHECK-3
+// CHECK-3: # class E
+// CHECK-3: *Defined at line 25 of test*
+// CHECK-3: ## Functions
+// CHECK-3: ### void E()
+// CHECK-3: *Defined at line 27 of test*
+// CHECK-3: ### void ~E()
+// CHECK-3: *Defined at line 28 of test*
+// CHECK-3: ### void ProtectedMethod()
+// CHECK-3: *Defined at line 34 of test*
+
+// RUN: cat %t/docs/./C.md | FileCheck %s --check-prefix CHECK-4
+// CHECK-4: # struct C
+// CHECK-4: *Defined at line 21 of test*
+// CHECK-4: ## Members
+// CHECK-4: int i
+
+// RUN: cat %t/docs/./X.md | FileCheck %s --check-prefix CHECK-5
+// CHECK-5: # class X
+// CHECK-5: *Defined at line 38 of test*
+
+// RUN: cat %t/docs/./A.md | FileCheck %s --check-prefix CHECK-6
+// CHECK-6: # union A
+// CHECK-6: *Defined at line 15 of test*
+// CHECK-6: ## Members
+// CHECK-6: int X
+// CHECK-6: int Y
Index: clang-tools-extra/test/clang-doc/md-namespace.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-doc/md-namespace.cpp
@@ -0,0 +1,46 @@
+// THIS IS A GENERATED TEST. DO NOT EDIT.
+// To regenerate, see clang-doc/gen_test.py docstring.
+//
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+
+namespace A {
+  
+void f();
+
+}  // namespace A
+
+namespace A {
+
+void f(){};
+
+namespace B {
+
+enum E { X };
+
+E func(int i) { return X; }
+
+}  // namespace B
+}  // namespace A
+
+// RUN: clang-doc --format=md --doxygen --public --extra-arg=-fmodules-ts -p %t %t/test.cpp -output=%t/docs
+
+
+// RUN: cat %t/docs/./A.md | FileCheck %s --check-prefix CHECK-0
+// CHECK-0: # namespace A
+// CHECK-0: ## Functions
+// CHECK-0: ### void f()
+// CHECK-0: *Defined at line 17 of test*
+
+// RUN: cat %t/docs/A/B.md | FileCheck %s --check-prefix CHECK-1
+// CHECK-1: # namespace B
+// CHECK-1: ## Functions
+// CHECK-1: ### enum A::B::E func(int i)
+// CHECK-1: *Defined at line 23 of test*
+// CHECK-1: ## Enums
+// CHECK-1: | enum E |
+// CHECK-1: --
+// CHECK-1: | X |
+// CHECK-1: *Defined at line 21 of test*
Index: clang-tools-extra/test/clang-doc/md-module.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-doc/md-module.cpp
@@ -0,0 +1,24 @@
+// THIS IS A GENERATED TEST. DO 

[PATCH] D49796: [ASTImporter] Load external Decls when getting field index.

2018-08-03 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin added a comment.

Hi Balázs,
The approach is OK but I have some minor comments inline.




Comment at: lib/AST/ASTImporter.cpp:2840
 
-  return Index;
+  assert(false && "Field was not found in its parent context.");
+

`llvm_unreachable`?



Comment at: unittests/AST/ASTImporterTest.cpp:2642
+unsigned ToIndex = 0u;
+for (auto *F : ToLambda->fields()) {
+  if (F == ToField)

I think we can make `getFieldIndex()` a static method of ASTImporter and remove 
this loop.


Repository:
  rC Clang

https://reviews.llvm.org/D49796



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


[PATCH] D50269: [compiler-rt][builtins] Don't #include CoreFoundation in os_version_check.c

2018-08-03 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision.
erik.pilkington added a reviewer: arphaman.
Herald added subscribers: Sanitizers, llvm-commits, dexonsmith, dberris.

This breaks some configurations, so just forward declare everything that we 
need.

rdar://35943793

Thanks for taking a look!
Erik


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D50269

Files:
  compiler-rt/lib/builtins/os_version_check.c


Index: compiler-rt/lib/builtins/os_version_check.c
===
--- compiler-rt/lib/builtins/os_version_check.c
+++ compiler-rt/lib/builtins/os_version_check.c
@@ -15,7 +15,6 @@
 
 #ifdef __APPLE__
 
-#include 
 #include 
 #include 
 #include 
@@ -28,6 +27,33 @@
 static int32_t GlobalMajor, GlobalMinor, GlobalSubminor;
 static dispatch_once_t DispatchOnceCounter;
 
+/* We can't include  directly from here, so
+ * just forward declare everything that we need from it. */
+
+typedef const void *CFDataRef, *CFAllocatorRef, *CFPropertyListRef,
+   *CFStringRef, *CFDictionaryRef, *CFTypeRef, *CFErrorRef;
+
+#if __LLP64__
+typedef unsigned long long CFTypeID;
+typedef unsigned long long CFOptionFlags;
+typedef signed long long CFIndex;
+#else
+typedef unsigned long CFTypeID;
+typedef unsigned long CFOptionFlags;
+typedef signed long CFIndex;
+#endif
+
+typedef unsigned char UInt8;
+typedef _Bool Boolean;
+typedef CFIndex CFPropertyListFormat;
+typedef uint32_t CFStringEncoding;
+
+/* kCFStringEncodingASCII analog. */
+#define CF_STRING_ENCODING_ASCII 0x0600
+/* kCFStringEncodingUTF8 analog. */
+#define CF_STRING_ENCODING_UTF8 0x08000100
+#define CF_PROPERTY_LIST_IMMUTABLE 0
+
 typedef CFDataRef (*CFDataCreateWithBytesNoCopyFuncTy)(CFAllocatorRef,
const UInt8 *, CFIndex,
CFAllocatorRef);
@@ -146,15 +172,15 @@
 
   if (CFPropertyListCreateWithDataFunc)
 PListRef = (*CFPropertyListCreateWithDataFunc)(
-NULL, FileContentsRef, kCFPropertyListImmutable, NULL, NULL);
+NULL, FileContentsRef, CF_PROPERTY_LIST_IMMUTABLE, NULL, NULL);
   else
 PListRef = (*CFPropertyListCreateFromXMLDataFunc)(
-NULL, FileContentsRef, kCFPropertyListImmutable, NULL);
+NULL, FileContentsRef, CF_PROPERTY_LIST_IMMUTABLE, NULL);
   if (!PListRef)
 goto Fail;
 
   CFStringRef ProductVersion = (*CFStringCreateWithCStringNoCopyFunc)(
-  NULL, "ProductVersion", kCFStringEncodingASCII, kCFAllocatorNull);
+  NULL, "ProductVersion", CF_STRING_ENCODING_ASCII, kCFAllocatorNull);
   if (!ProductVersion)
 goto Fail;
   CFTypeRef OpaqueValue = (*CFDictionaryGetValueFunc)(PListRef, 
ProductVersion);
@@ -165,7 +191,7 @@
 
   char VersionStr[32];
   if (!(*CFStringGetCStringFunc)((CFStringRef)OpaqueValue, VersionStr,
- sizeof(VersionStr), kCFStringEncodingUTF8))
+ sizeof(VersionStr), CF_STRING_ENCODING_UTF8))
 goto Fail;
   sscanf(VersionStr, "%d.%d.%d", , , );
 
@@ -182,14 +208,10 @@
   /* Populate the global version variables, if they haven't already. */
   dispatch_once_f(, NULL, parseSystemVersionPList);
 
-  if (Major < GlobalMajor)
-return 1;
-  if (Major > GlobalMajor)
-return 0;
-  if (Minor < GlobalMinor)
-return 1;
-  if (Minor > GlobalMinor)
-return 0;
+  if (Major < GlobalMajor) return 1;
+  if (Major > GlobalMajor) return 0;
+  if (Minor < GlobalMinor) return 1;
+  if (Minor > GlobalMinor) return 0;
   return Subminor <= GlobalSubminor;
 }
 


Index: compiler-rt/lib/builtins/os_version_check.c
===
--- compiler-rt/lib/builtins/os_version_check.c
+++ compiler-rt/lib/builtins/os_version_check.c
@@ -15,7 +15,6 @@
 
 #ifdef __APPLE__
 
-#include 
 #include 
 #include 
 #include 
@@ -28,6 +27,33 @@
 static int32_t GlobalMajor, GlobalMinor, GlobalSubminor;
 static dispatch_once_t DispatchOnceCounter;
 
+/* We can't include  directly from here, so
+ * just forward declare everything that we need from it. */
+
+typedef const void *CFDataRef, *CFAllocatorRef, *CFPropertyListRef,
+   *CFStringRef, *CFDictionaryRef, *CFTypeRef, *CFErrorRef;
+
+#if __LLP64__
+typedef unsigned long long CFTypeID;
+typedef unsigned long long CFOptionFlags;
+typedef signed long long CFIndex;
+#else
+typedef unsigned long CFTypeID;
+typedef unsigned long CFOptionFlags;
+typedef signed long CFIndex;
+#endif
+
+typedef unsigned char UInt8;
+typedef _Bool Boolean;
+typedef CFIndex CFPropertyListFormat;
+typedef uint32_t CFStringEncoding;
+
+/* kCFStringEncodingASCII analog. */
+#define CF_STRING_ENCODING_ASCII 0x0600
+/* kCFStringEncodingUTF8 analog. */
+#define CF_STRING_ENCODING_UTF8 0x08000100
+#define CF_PROPERTY_LIST_IMMUTABLE 0
+
 typedef CFDataRef (*CFDataCreateWithBytesNoCopyFuncTy)(CFAllocatorRef,
const UInt8 *, 

[PATCH] D36892: [clang-tidy] check_clang_tidy.py: support CHECK-NOTES prefix

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

@lebedev.ri and @alexfh i would change the tests in 
https://reviews.llvm.org/D48714 to use CHECK-NOTES. Is it ok, to commit this 
one?

For testing purposes, you could change a single line of 
`hicpp-exception-baseclass.cpp` to use the CHECK-NOTES. I do the rest :)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D36892



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


[PATCH] D48714: [clang-tidy] fix PR37913, templated exception factory diagnosed correctly

2018-08-03 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: test/clang-tidy/hicpp-exception-baseclass.cpp:191
+void templated_thrower() { throw T{}(); }
+// CHECK-MESSAGES: [[@LINE-1]]:34: warning: throwing an exception whose type 
'int' is not derived from 'std::exception'
+

JonasToth wrote:
> alexfh wrote:
> > hokein wrote:
> > > I think giving message on the template function here is confusing to 
> > > users even it gets instantiated somewhere in this TU -- because users 
> > > have to find the location that triggers the template instantiation.
> > > 
> > > Maybe 
> > > 1) Add a note which gives the instantiation location to the message, or
> > > 2) ignore template case (some clang-tidy checks do this)
> > In this particular case it seems to be useful to get warnings from template 
> > instantiations. But the message will indeed be confusing.
> > 
> > Ideally, the message should have "in instantiation of xxx requested here" 
> > notes attached, as clang warnings do. But this is not working 
> > automatically, and it's implemented in Sema 
> > (`Sema::PrintInstantiationStack()` in lib/Sema/SemaTemplateInstantiate.cpp).
> > 
> > I wonder whether it's feasible to produce similar notes after Sema is dead? 
> > Maybe not the whole instantiation stack, but at least it should be possible 
> > to figure out that the enclosing function is a template instantiation or is 
> > a member function of an type that is an instantiation of a template. That 
> > would be useful for other checks as well.
> It should be possible to figure out, that the type comes from template 
> instantiation and that information could be added to the warning.
> 
> I will take a look at Sema and think about something like this. Unfortunatly 
> i dont have a lot of time :/
I did look further into the issue, i think it is non-trivial.

The newly added case is not a templated exception perse, but there is a 
exception-factory, which is templated, that creates a normal exception.

I did add another note for template instantiations, but i could not figure out 
a way to give better diagnostics for the new use-case.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48714



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


[PATCH] D50194: LLVM Proto Fuzzer - Run Functions on Suite of Inputs

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

Refactored code to avoid memcpy-ing function


Repository:
  rC Clang

https://reviews.llvm.org/D50194

Files:
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
  clang/tools/clang-fuzzer/handle-llvm/handle_llvm.h
  clang/tools/clang-fuzzer/handle-llvm/input_arrays.h

Index: clang/tools/clang-fuzzer/handle-llvm/input_arrays.h
===
--- /dev/null
+++ clang/tools/clang-fuzzer/handle-llvm/input_arrays.h
@@ -0,0 +1,125 @@
+//==-- input_arrays.h - Helper function for LLVM fuzzer inputs -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Define a few static variables used by the LLVM Proto Fuzzer
+//
+//===--===//
+
+#include 
+#include 
+
+static const int ArraySize = 64;
+static const int NumArrays = 100;
+
+// Define two arrays that will hold the input and output for the two functions
+static int OptArrays[NumArrays][ArraySize];
+static int UnoptArrays[NumArrays][ArraySize];
+
+// Define a corpus of possible inputs
+static int InputArrays[NumArrays][ArraySize] =
+{ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
+  {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
+  {0, 0, 0, 5, 0, 2, 0, 8, 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
+  {1, 1, 2, 1, 6, 0, 3, 1, 10, 10, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
+  {0, 0, 2, 0, 0, 7, 0, 4, 2, 0, 12, 12, 0, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
+  {1, 1, 0, 2, 2, 9, 8, 0, 5, 3, 1, 14, 14, 14, 0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14},
+  {0, 0, 0, 4, 0, 1, 10, 9, 0, 6, 4, 2, 0, 16, 16, 16, 0, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16},
+  {1, 1, 2, 3, 2, 3, 0, 11, 10, 0, 7, 5, 3, 1, 18, 18, 18, 18, 0, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18},
+  {0, 0, 2, 5, 4, 0, 2, 13, 12, 11, 0, 8, 6, 4, 2, 0, 20, 20, 20, 20, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20},
+  {1, 1, 0, 1, 6, 2, 4, 1, 14, 13, 12, 0, 9, 7, 5, 3, 1, 22, 22, 22, 22, 22, 0, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22},
+  {0, 0, 0, 0, 4, 4, 0, 3, 0, 15, 14, 13, 0, 10, 8, 6, 4, 2, 0, 24, 24, 24, 24, 24, 0, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24},
+  {1, 1, 2, 2, 6, 6, 2, 5, 2, 17, 16, 15, 14, 0, 11, 9, 7, 5, 3, 1, 26, 26, 26, 26, 26, 26, 0, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26},
+  {0, 0, 2, 4, 0, 8, 4, 0, 4, 1, 18, 17, 16, 15, 0, 12, 10, 8, 6, 4, 2, 0, 28, 28, 28, 28, 28, 28, 0, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28},
+  {1, 1, 0, 3, 2, 5, 6, 2, 6, 3, 0, 19, 

Re: r338259 - [analyzer] Add support for more invalidating functions in InnerPointerChecker.

2018-08-03 Thread Réka Nikolett Kovács via cfe-commits
Thanks very much for the example!
I committed it together with the design correction in r338918.

Alexander Kornienko  ezt írta (időpont: 2018. aug. 3.,
P, 5:36):

> Thanks for the prompt fix, it solved the problem.
>
> In case you want to add a regression test, this is what I came up with:
> $ cat test-isCalledOnStringObject.cc
> char *c();
> class B {};
> void d() {
>   B g, *h;
>   *(void **) = c() + 1;
>   *h = g;
> }
> $ ./clang-tidy -checks=-*,clang-analyzer* test-isCalledOnStringObject.cc
> -- -std=c++11
> @ 0x5640f3e56b85 32  clang::DeclarationName::isIdentifier()
> @ 0x5640f3ebaca3 80  clang::NamedDecl::getName()
> @ 0x5640f9f7e56b336  (anonymous
> namespace)::InnerPointerChecker::isCalledOnStringObject()
> @ 0x5640f9f7e0ef288  (anonymous
> namespace)::InnerPointerChecker::checkPostCall()
> @ 0x5640f9f7e080 48
> clang::ento::check::PostCall::_checkCall<>()
> @ 0x5640fa2d5c12 64  clang::ento::CheckerFn<>::operator()()
> @ 0x5640fa2c82d8208  (anonymous
> namespace)::CheckCallContext::runChecker()
> @ 0x5640fa2c4d6c384  expandGraphWithCheckers<>()
> @ 0x5640fa2c4acb208
> clang::ento::CheckerManager::runCheckersForCallEvent()
> @ 0x5640fa32fdc8 80
> clang::ento::CheckerManager::runCheckersForPostCall()
> @ 0x5640fa332ff3336  clang::ento::ExprEngine::evalCall()
> @ 0x5640fa332e89400
> clang::ento::ExprEngine::VisitCallExpr()
> @ 0x5640fa2ef8cb   4304  clang::ento::ExprEngine::Visit()
> @ 0x5640fa2ec38c464  clang::ento::ExprEngine::ProcessStmt()
> @ 0x5640fa2ec079208
> clang::ento::ExprEngine::processCFGElement()
> @ 0x5640fa31d8ff128
> clang::ento::CoreEngine::HandlePostStmt()
> @ 0x5640fa31d208496
> clang::ento::CoreEngine::dispatchWorkItem()
> @ 0x5640fa31cdbb544
> clang::ento::CoreEngine::ExecuteWorkList()
> @ 0x5640f9c466b4 80
> clang::ento::ExprEngine::ExecuteWorkList()
>
>
> On Fri, Aug 3, 2018 at 12:28 AM Réka Nikolett Kovács <
> rekanikol...@gmail.com> wrote:
>
>> Thanks for the notice. Have you managed to get the repro? I haven't
>> succeeded in constructing one yet, but I've committed a check for the
>> CXXRecordDecl. I hope that fixes the crashes.
>>
>> Alexander Kornienko  ezt írta (időpont: 2018. aug.
>> 2., Cs, 11:07):
>>
>>>
>>>
>>> On Mon, Jul 30, 2018 at 5:44 PM Reka Kovacs via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
 Author: rkovacs
 Date: Mon Jul 30 08:43:45 2018
 New Revision: 338259

 URL: http://llvm.org/viewvc/llvm-project?rev=338259=rev
 Log:
 [analyzer] Add support for more invalidating functions in
 InnerPointerChecker.

 According to the standard, pointers referring to the elements of a
 `basic_string` may be invalidated if they are used as an argument to
 any standard library function taking a reference to non-const
 `basic_string` as an argument. This patch makes InnerPointerChecker warn
 for these cases.

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

 Modified:
 cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
 cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
 cfe/trunk/test/Analysis/inner-pointer.cpp

 Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
 URL:
 http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp?rev=338259=338258=338259=diff

 ==
 --- cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
 (original)
 +++ cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp Mon
 Jul 30 08:43:45 2018
 @@ -91,37 +91,53 @@ public:
  ReserveFn("reserve"), ResizeFn("resize"),
  ShrinkToFitFn("shrink_to_fit"), SwapFn("swap") {}

 -  /// Check whether the function called on the container object is a
 -  /// member function that potentially invalidates pointers referring
 -  /// to the objects's internal buffer.
 -  bool mayInvalidateBuffer(const CallEvent ) const;
 -
 -  /// Record the connection between the symbol returned by c_str() and
 the
 -  /// corresponding string object region in the ProgramState. Mark the
 symbol
 -  /// released if the string object is destroyed.
 +  /// Check if the object of this member function call is a
 `basic_string`.
 +  bool isCalledOnStringObject(const CXXInstanceCall *ICall) const;
 +
 +  /// Check whether the called member function potentially invalidates
 +  /// pointers referring to the container object's inner buffer.
 +  bool isInvalidatingMemberFunction(const CallEvent ) const;
 +
 +  /// Mark 

[PATCH] D50154: [clangd] capitalize diagnostic messages

2018-08-03 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE338919: [clangd] capitalize diagnostic messages (authored 
by arphaman, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50154?vs=159059=159080#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50154

Files:
  clangd/Diagnostics.cpp
  test/clangd/diagnostics.test
  test/clangd/did-change-configuration-params.test
  test/clangd/execute-command.test
  test/clangd/extra-flags.test
  test/clangd/fixits.test
  unittests/clangd/ClangdUnitTests.cpp

Index: clangd/Diagnostics.cpp
===
--- clangd/Diagnostics.cpp
+++ clangd/Diagnostics.cpp
@@ -145,6 +145,13 @@
   OS << diagLeveltoString(D.Severity) << ": " << D.Message;
 }
 
+/// Capitalizes the first word in the diagnostic's message.
+std::string capitalize(std::string Message) {
+  if (!Message.empty())
+Message[0] = llvm::toUpper(Message[0]);
+  return Message;
+}
+
 /// Returns a message sent to LSP for the main diagnostic in \p D.
 /// The message includes all the notes with their corresponding locations.
 /// However, notes with fix-its are excluded as those usually only contain a
@@ -166,7 +173,7 @@
 printDiag(OS, Note);
   }
   OS.flush();
-  return Result;
+  return capitalize(std::move(Result));
 }
 
 /// Returns a message sent to LSP for the note of the main diagnostic.
@@ -179,7 +186,7 @@
   OS << "\n\n";
   printDiag(OS, Main);
   OS.flush();
-  return Result;
+  return capitalize(std::move(Result));
 }
 } // namespace
 
Index: test/clangd/did-change-configuration-params.test
===
--- test/clangd/did-change-configuration-params.test
+++ test/clangd/did-change-configuration-params.test
@@ -24,7 +24,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
-# CHECK-NEXT:"message": "variable 'i' is uninitialized when used here",
+# CHECK-NEXT:"message": "Variable 'i' is uninitialized when used here",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": 28,
Index: test/clangd/execute-command.test
===
--- test/clangd/execute-command.test
+++ test/clangd/execute-command.test
@@ -6,7 +6,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
-# CHECK-NEXT:"message": "using the result of an assignment as a condition without parentheses",
+# CHECK-NEXT:"message": "Using the result of an assignment as a condition without parentheses",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": 37,
Index: test/clangd/extra-flags.test
===
--- test/clangd/extra-flags.test
+++ test/clangd/extra-flags.test
@@ -6,7 +6,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
-# CHECK-NEXT:"message": "variable 'i' is uninitialized when used here",
+# CHECK-NEXT:"message": "Variable 'i' is uninitialized when used here",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": 28,
@@ -28,7 +28,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
-# CHECK-NEXT:"message": "variable 'i' is uninitialized when used here",
+# CHECK-NEXT:"message": "Variable 'i' is uninitialized when used here",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": 28,
Index: test/clangd/diagnostics.test
===
--- test/clangd/diagnostics.test
+++ test/clangd/diagnostics.test
@@ -6,7 +6,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
-# CHECK-NEXT:"message": "return type of 'main' is not 'int'",
+# CHECK-NEXT:"message": "Return type of 'main' is not 'int'",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": 4,
Index: test/clangd/fixits.test
===
--- test/clangd/fixits.test
+++ test/clangd/fixits.test
@@ -6,7 +6,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
-# CHECK-NEXT:"message": "using the result of an assignment as a condition without parentheses",
+# CHECK-NEXT:"message": "Using the result of an assignment as a condition without parentheses",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": 37,
@@ -23,7 +23,7 @@
 # CHECK-NEXT:"uri": "file://{{.*}}/foo.c"
 # CHECK-NEXT:  }
 ---

[clang-tools-extra] r338919 - [clangd] capitalize diagnostic messages

2018-08-03 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Fri Aug  3 13:43:28 2018
New Revision: 338919

URL: http://llvm.org/viewvc/llvm-project?rev=338919=rev
Log:
[clangd] capitalize diagnostic messages

The diagnostic messages that are sent to the client from Clangd are now always
capitalized.

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

Modified:
clang-tools-extra/trunk/clangd/Diagnostics.cpp
clang-tools-extra/trunk/test/clangd/diagnostics.test
clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test
clang-tools-extra/trunk/test/clangd/execute-command.test
clang-tools-extra/trunk/test/clangd/extra-flags.test
clang-tools-extra/trunk/test/clangd/fixits.test
clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp

Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.cpp?rev=338919=338918=338919=diff
==
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original)
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Fri Aug  3 13:43:28 2018
@@ -145,6 +145,13 @@ void printDiag(llvm::raw_string_ostream
   OS << diagLeveltoString(D.Severity) << ": " << D.Message;
 }
 
+/// Capitalizes the first word in the diagnostic's message.
+std::string capitalize(std::string Message) {
+  if (!Message.empty())
+Message[0] = llvm::toUpper(Message[0]);
+  return Message;
+}
+
 /// Returns a message sent to LSP for the main diagnostic in \p D.
 /// The message includes all the notes with their corresponding locations.
 /// However, notes with fix-its are excluded as those usually only contain a
@@ -166,7 +173,7 @@ std::string mainMessage(const Diag ) {
 printDiag(OS, Note);
   }
   OS.flush();
-  return Result;
+  return capitalize(std::move(Result));
 }
 
 /// Returns a message sent to LSP for the note of the main diagnostic.
@@ -179,7 +186,7 @@ std::string noteMessage(const Diag 
   OS << "\n\n";
   printDiag(OS, Main);
   OS.flush();
-  return Result;
+  return capitalize(std::move(Result));
 }
 } // namespace
 

Modified: clang-tools-extra/trunk/test/clangd/diagnostics.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/diagnostics.test?rev=338919=338918=338919=diff
==
--- clang-tools-extra/trunk/test/clangd/diagnostics.test (original)
+++ clang-tools-extra/trunk/test/clangd/diagnostics.test Fri Aug  3 13:43:28 
2018
@@ -6,7 +6,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
-# CHECK-NEXT:"message": "return type of 'main' is not 'int'",
+# CHECK-NEXT:"message": "Return type of 'main' is not 'int'",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": 4,

Modified: 
clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test?rev=338919=338918=338919=diff
==
--- clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test 
(original)
+++ clang-tools-extra/trunk/test/clangd/did-change-configuration-params.test 
Fri Aug  3 13:43:28 2018
@@ -24,7 +24,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
-# CHECK-NEXT:"message": "variable 'i' is uninitialized when used here",
+# CHECK-NEXT:"message": "Variable 'i' is uninitialized when used here",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": 28,

Modified: clang-tools-extra/trunk/test/clangd/execute-command.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/execute-command.test?rev=338919=338918=338919=diff
==
--- clang-tools-extra/trunk/test/clangd/execute-command.test (original)
+++ clang-tools-extra/trunk/test/clangd/execute-command.test Fri Aug  3 
13:43:28 2018
@@ -6,7 +6,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
-# CHECK-NEXT:"message": "using the result of an assignment as a 
condition without parentheses",
+# CHECK-NEXT:"message": "Using the result of an assignment as a 
condition without parentheses",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": 37,

Modified: clang-tools-extra/trunk/test/clangd/extra-flags.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/extra-flags.test?rev=338919=338918=338919=diff
==
--- clang-tools-extra/trunk/test/clangd/extra-flags.test (original)
+++ 

r338918 - [analyzer] Add test for a crash fixed in r338775.

2018-08-03 Thread Reka Kovacs via cfe-commits
Author: rkovacs
Date: Fri Aug  3 13:42:02 2018
New Revision: 338918

URL: http://llvm.org/viewvc/llvm-project?rev=338918=rev
Log:
[analyzer] Add test for a crash fixed in r338775.

Do not crash if a CXXRecordDecl cannot be obtained for an object.

Special thanks for the reproduction to Alexander Kornienko.

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
cfe/trunk/test/Analysis/inner-pointer.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp?rev=338918=338917=338918=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp Fri Aug  3 
13:42:02 2018
@@ -133,10 +133,7 @@ bool InnerPointerChecker::isCalledOnStri
 return false;
 
   CXXRecordDecl *Decl = ObjTy->getAsCXXRecordDecl();
-  if (!Decl || Decl->getName() != "basic_string")
-return false;
-
-  return true;
+  return Decl && Decl->getName() == "basic_string";
 }
 
 bool InnerPointerChecker::isInvalidatingMemberFunction(

Modified: cfe/trunk/test/Analysis/inner-pointer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inner-pointer.cpp?rev=338918=338917=338918=diff
==
--- cfe/trunk/test/Analysis/inner-pointer.cpp (original)
+++ cfe/trunk/test/Analysis/inner-pointer.cpp Fri Aug  3 13:42:02 2018
@@ -382,3 +382,13 @@ const char *escape_via_return_local() {
 // expected-note@-1 {{Inner pointer invalidated by call to 
destructor}}
 } // expected-warning {{Use of memory after it is freed}}
 // expected-note@-1 {{Use of memory after it is freed}}
+
+
+char *c();
+class A {};
+
+void no_CXXRecordDecl() {
+  A a, *b;
+  *(void **) = c() + 1;
+  *b = a; // no-crash
+}


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


Re: r338667 - [analyzer] Extend NoStoreFuncVisitor to follow fields.

2018-08-03 Thread George Karpenkov via cfe-commits
Yeah, saw that as well, fix coming.

> On Aug 3, 2018, at 10:32 AM, Alexander Kornienko  wrote:
> 
> 
> 
> On Thu, Aug 2, 2018 at 4:03 AM George Karpenkov via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> Author: george.karpenkov
> Date: Wed Aug  1 19:02:40 2018
> New Revision: 338667
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=338667=rev 
> 
> Log:
> [analyzer] Extend NoStoreFuncVisitor to follow fields.
> 
> rdar://39701823
> 
> Differential Revision: https://reviews.llvm.org/D49901 
> 
> 
> Modified:
> cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
> cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.c
> cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.cpp
> cfe/trunk/test/Analysis/diagnostics/no-store-func-path-notes.m
> 
> Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=338667=338666=338667=diff
>  
> 
> ==
> --- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed Aug  1 
> 19:02:40 2018
> @@ -269,10 +269,14 @@ namespace {
>  /// pointer dereference outside.
>  class NoStoreFuncVisitor final : public BugReporterVisitor {
>const SubRegion *RegionOfInterest;
> +  MemRegionManager 
>const SourceManager 
>const PrintingPolicy 
> -  static constexpr const char *DiagnosticsMsg =
> -  "Returning without writing to '";
> +
> +  /// Recursion limit for dereferencing fields when looking for the
> +  /// region of interest.
> +  /// The limit of two indicates that we will dereference fields only once.
> +  static const unsigned DEREFERENCE_LIMIT = 2;
> 
>/// Frames writing into \c RegionOfInterest.
>/// This visitor generates a note only if a function does not write into
> @@ -285,15 +289,17 @@ class NoStoreFuncVisitor final : public
>llvm::SmallPtrSet FramesModifyingRegion;
>llvm::SmallPtrSet FramesModifyingCalculated;
> 
> +  using RegionVector = SmallVector;
>  public:
>NoStoreFuncVisitor(const SubRegion *R)
> -  : RegionOfInterest(R),
> -SM(R->getMemRegionManager()->getContext().getSourceManager()),
> -PP(R->getMemRegionManager()->getContext().getPrintingPolicy()) {}
> +  : RegionOfInterest(R), MmrMgr(*R->getMemRegionManager()),
> +SM(MmrMgr.getContext().getSourceManager()),
> +PP(MmrMgr.getContext().getPrintingPolicy()) {}
> 
>void Profile(llvm::FoldingSetNodeID ) const override {
>  static int Tag = 0;
>  ID.AddPointer();
> +ID.AddPointer(RegionOfInterest);
>}
> 
>std::shared_ptr VisitNode(const ExplodedNode *N,
> @@ -307,48 +313,69 @@ public:
>  auto CallExitLoc = N->getLocationAs();
> 
>  // No diagnostic if region was modified inside the frame.
> -if (!CallExitLoc)
> +if (!CallExitLoc || isRegionOfInterestModifiedInFrame(N))
>return nullptr;
> 
>  CallEventRef<> Call =
>  BRC.getStateManager().getCallEventManager().getCaller(SCtx, State);
> 
> +if (SM.isInSystemHeader(Call->getDecl()->getSourceRange().getBegin()))
> +  return nullptr;
> +
>  // Region of interest corresponds to an IVar, exiting a method
>  // which could have written into that IVar, but did not.
> -if (const auto *MC = dyn_cast(Call))
> -  if (const auto *IvarR = dyn_cast(RegionOfInterest))
> -if (potentiallyWritesIntoIvar(Call->getRuntimeDefinition().getDecl(),
> -  IvarR->getDecl()) &&
> -!isRegionOfInterestModifiedInFrame(N))
> -  return notModifiedMemberDiagnostics(
> -  Ctx, *CallExitLoc, Call, MC->getReceiverSVal().getAsRegion());
> +if (const auto *MC = dyn_cast(Call)) {
> +  if (const auto *IvarR = dyn_cast(RegionOfInterest)) {
> +const MemRegion *SelfRegion = MC->getReceiverSVal().getAsRegion();
> +if (RegionOfInterest->isSubRegionOf(SelfRegion) &&
> +potentiallyWritesIntoIvar(Call->getRuntimeDefinition().getDecl(),
> +  IvarR->getDecl()))
> +  return notModifiedDiagnostics(Ctx, *CallExitLoc, Call, {}, 
> SelfRegion,
> +"self", 
> /*FirstIsReferenceType=*/false,
> +1);
> +  }
> +}
> 
>  if (const auto *CCall = dyn_cast(Call)) {
>const MemRegion *ThisR = CCall->getCXXThisVal().getAsRegion();
>if (RegionOfInterest->isSubRegionOf(ThisR)
> -  && !CCall->getDecl()->isImplicit()
> -  && !isRegionOfInterestModifiedInFrame(N))
> -return 

[PATCH] D50250: [clang][ubsan] Implicit Conversion Sanitizer - integer sign change - clang part

2018-08-03 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

@erichkeane, @rsmith thanks for taking a look!




Comment at: lib/CodeGen/CGExprScalar.cpp:1036
+return;
+  // That's it. We can't rule out any more cases with the data we have.
+

rsmith wrote:
> I don't like the overlap between the implicit truncation check and this 
> check. I think you should aim for exactly one of those checks to fire for any 
> given integer conversion. There are the following cases:
> 
>  * Dst is smaller than Src: if the value changes at all (with sign change or 
> without), then the truncation check already catches it, and catching it here 
> does not seem useful
>  * Dst is the same size as Src or larger: sign change is the only problem, 
> and is only possible if exactly one of Src and Dst is signed
> 
> So I think you should bail out of this function if either Src and Dst are 
> both unsigned or both are signed, and also if Src is larger than Dst (because 
> we treat that case as a lossy truncation rather than as a sign change).
> 
> And when you do emit a check here, the only thing you need to check is if the 
> signed value is negative (if so, you definitely changed the sign, and if not, 
> you definitely didn't -- except in the truncation cases that the truncation 
> sanitizer catches).
To be clear: we want to skip emitting in those cases if the other check 
(truncation) is enabled, right?
It does seem to make sense, (and i did thought about that a bit), but i need to 
think about it more..



Comment at: lib/CodeGen/CGExprScalar.cpp:1050-1051
+// NOTE: if it is unsigned, then the comparison is naturally always 
'false'.
+llvm::ICmpInst::Predicate Pred =
+VSigned ? llvm::ICmpInst::ICMP_SLT : llvm::ICmpInst::ICMP_ULT;
+// Get the zero of the same type with which we will be comparing.

rsmith wrote:
> If `!VSigned`, the result is a constant `false`; you don't need to emit an 
> `icmp` to work that out.
Ok, if you insist.
I didn't do that in the first place because we will now have an `icmp`
where one operand being a constant, so we can simplify it further.
And i don't want to complicate this logic if middle-end already handles it :)


Repository:
  rC Clang

https://reviews.llvm.org/D50250



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


r338916 - [OpenMP] Encode offload target triples into comdat key for offload initialization code

2018-08-03 Thread Sergey Dmitriev via cfe-commits
Author: sdmitriev
Date: Fri Aug  3 13:19:28 2018
New Revision: 338916

URL: http://llvm.org/viewvc/llvm-project?rev=338916=rev
Log:
[OpenMP] Encode offload target triples into comdat key for offload 
initialization code

Encoding offload target triples onto comdat group key for offload initialization
code guarantees that it will be executed once per each unique combination of
offload targets.

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

Added:
cfe/trunk/test/OpenMP/openmp_offload_registration.cpp   (with props)
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=338916=338915=338916=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Fri Aug  3 13:19:28 2018
@@ -3818,7 +3818,19 @@ CGOpenMPRuntime::createOffloadingBinaryD
 CGF.disableDebugInfo();
 const auto  = CGM.getTypes().arrangeNullaryFunction();
 llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI);
-std::string Descriptor = getName({"omp_offloading", "descriptor_reg"});
+
+// Encode offload target triples into the registration function name. It
+// will serve as a comdat key for the registration/unregistration code for
+// this particular combination of offloading targets.
+SmallVector RegFnNameParts(Devices.size() + 2U);
+RegFnNameParts[0] = "omp_offloading";
+RegFnNameParts[1] = "descriptor_reg";
+llvm::transform(Devices, std::next(RegFnNameParts.begin(), 2),
+[](const llvm::Triple ) -> const std::string& {
+  return T.getTriple();
+});
+llvm::sort(std::next(RegFnNameParts.begin(), 2), RegFnNameParts.end());
+std::string Descriptor = getName(RegFnNameParts);
 RegFn = CGM.CreateGlobalInitOrDestructFunction(FTy, Descriptor, FI);
 CGF.StartFunction(GlobalDecl(), C.VoidTy, RegFn, FI, FunctionArgList());
 CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__tgt_register_lib), Desc);

Added: cfe/trunk/test/OpenMP/openmp_offload_registration.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/openmp_offload_registration.cpp?rev=338916=auto
==
--- cfe/trunk/test/OpenMP/openmp_offload_registration.cpp (added)
+++ cfe/trunk/test/OpenMP/openmp_offload_registration.cpp Fri Aug  3 13:19:28 
2018
@@ -0,0 +1,49 @@
+// Test for offload registration code for two targets
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-unknown-linux-gnu 
-fopenmp-targets=x86_64-pc-linux-gnu,powerpc64le-ibm-linux-gnu -emit-llvm %s -o 
- | FileCheck %s
+// expected-no-diagnostics
+
+void foo() {
+#pragma omp target
+  {}
+}
+
+// CHECK-DAG: [[ENTTY:%.+]] = type { i8*, i8*, i[[SZ:32|64]], i32, i32 }
+// CHECK-DAG: [[DEVTY:%.+]] = type { i8*, i8*, [[ENTTY]]*, [[ENTTY]]* }
+// CHECK-DAG: [[DSCTY:%.+]] = type { i32, [[DEVTY]]*, [[ENTTY]]*, [[ENTTY]]* }
+
+// Comdat key for the offload registration code. Should have sorted offload
+// target triples encoded into the name.
+// CHECK-DAG: 
$[[REGFN:\.omp_offloading\..+\.powerpc64le-ibm-linux-gnu\.x86_64-pc-linux-gnu+]]
 = comdat any
+
+// Check if offloading descriptor is created.
+// CHECK: [[ENTBEGIN:@.+]] = external constant [[ENTTY]]
+// CHECK: [[ENTEND:@.+]] = external constant [[ENTTY]]
+// CHECK: [[DEV1BEGIN:@.+]] = extern_weak constant i8
+// CHECK: [[DEV1END:@.+]] = extern_weak constant i8
+// CHECK: [[DEV2BEGIN:@.+]] = extern_weak constant i8
+// CHECK: [[DEV2END:@.+]] = extern_weak constant i8
+// CHECK: [[IMAGES:@.+]] = internal unnamed_addr constant [2 x [[DEVTY]]] 
[{{.+}} { i8* [[DEV1BEGIN]], i8* [[DEV1END]], [[ENTTY]]* [[ENTBEGIN]], 
[[ENTTY]]* [[ENTEND]] }, {{.+}} { i8* [[DEV2BEGIN]], i8* [[DEV2END]], 
[[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }], comdat($[[REGFN]])
+// CHECK: [[DESC:@.+]] = internal constant [[DSCTY]] { i32 2, [[DEVTY]]* 
getelementptr inbounds ([2 x [[DEVTY]]], [2 x [[DEVTY]]]* [[IMAGES]], i32 0, 
i32 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }, comdat($[[REGFN]])
+
+// Check target registration is registered as a Ctor.
+// CHECK: appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* 
} { i32 0, void ()* @[[REGFN]], i8* bitcast (void ()* @[[REGFN]] to i8*) }]
+
+// Check presence of foo() and the outlined target region
+// CHECK: define void [[FOO:@.+]]()
+// CHECK: define internal void [[OUTLINEDTARGET:@.+]]() 
+
+// Check registration and unregistration code.
+
+// CHECK: define internal void @[[UNREGFN:.+]](i8*)
+// CHECK-SAME: comdat($[[REGFN]]) {
+// CHECK: call i32 @__tgt_unregister_lib([[DSCTY]]* [[DESC]])
+// CHECK: ret void
+// CHECK: declare i32 @__tgt_unregister_lib([[DSCTY]]*)
+
+// CHECK: define linkonce hidden void @[[REGFN]]()

[PATCH] D50250: [clang][ubsan] Implicit Conversion Sanitizer - integer sign change - clang part

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



Comment at: lib/CodeGen/CGExprScalar.cpp:1036
+return;
+  // That's it. We can't rule out any more cases with the data we have.
+

I don't like the overlap between the implicit truncation check and this check. 
I think you should aim for exactly one of those checks to fire for any given 
integer conversion. There are the following cases:

 * Dst is smaller than Src: if the value changes at all (with sign change or 
without), then the truncation check already catches it, and catching it here 
does not seem useful
 * Dst is the same size as Src or larger: sign change is the only problem, and 
is only possible if exactly one of Src and Dst is signed

So I think you should bail out of this function if either Src and Dst are both 
unsigned or both are signed, and also if Src is larger than Dst (because we 
treat that case as a lossy truncation rather than as a sign change).

And when you do emit a check here, the only thing you need to check is if the 
signed value is negative (if so, you definitely changed the sign, and if not, 
you definitely didn't -- except in the truncation cases that the truncation 
sanitizer catches).



Comment at: lib/CodeGen/CGExprScalar.cpp:1050-1051
+// NOTE: if it is unsigned, then the comparison is naturally always 
'false'.
+llvm::ICmpInst::Predicate Pred =
+VSigned ? llvm::ICmpInst::ICMP_SLT : llvm::ICmpInst::ICMP_ULT;
+// Get the zero of the same type with which we will be comparing.

If `!VSigned`, the result is a constant `false`; you don't need to emit an 
`icmp` to work that out.


Repository:
  rC Clang

https://reviews.llvm.org/D50250



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


[PATCH] D50218: [OpenMP] Encode offload target triples into comdat key for offload initialization code

2018-08-03 Thread Sergey Dmitriev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC338916: [OpenMP] Encode offload target triples into comdat 
key for offload… (authored by sdmitriev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D50218

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/openmp_offload_registration.cpp


Index: test/OpenMP/openmp_offload_registration.cpp
===
--- test/OpenMP/openmp_offload_registration.cpp
+++ test/OpenMP/openmp_offload_registration.cpp
@@ -0,0 +1,49 @@
+// Test for offload registration code for two targets
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-unknown-linux-gnu 
-fopenmp-targets=x86_64-pc-linux-gnu,powerpc64le-ibm-linux-gnu -emit-llvm %s -o 
- | FileCheck %s
+// expected-no-diagnostics
+
+void foo() {
+#pragma omp target
+  {}
+}
+
+// CHECK-DAG: [[ENTTY:%.+]] = type { i8*, i8*, i[[SZ:32|64]], i32, i32 }
+// CHECK-DAG: [[DEVTY:%.+]] = type { i8*, i8*, [[ENTTY]]*, [[ENTTY]]* }
+// CHECK-DAG: [[DSCTY:%.+]] = type { i32, [[DEVTY]]*, [[ENTTY]]*, [[ENTTY]]* }
+
+// Comdat key for the offload registration code. Should have sorted offload
+// target triples encoded into the name.
+// CHECK-DAG: 
$[[REGFN:\.omp_offloading\..+\.powerpc64le-ibm-linux-gnu\.x86_64-pc-linux-gnu+]]
 = comdat any
+
+// Check if offloading descriptor is created.
+// CHECK: [[ENTBEGIN:@.+]] = external constant [[ENTTY]]
+// CHECK: [[ENTEND:@.+]] = external constant [[ENTTY]]
+// CHECK: [[DEV1BEGIN:@.+]] = extern_weak constant i8
+// CHECK: [[DEV1END:@.+]] = extern_weak constant i8
+// CHECK: [[DEV2BEGIN:@.+]] = extern_weak constant i8
+// CHECK: [[DEV2END:@.+]] = extern_weak constant i8
+// CHECK: [[IMAGES:@.+]] = internal unnamed_addr constant [2 x [[DEVTY]]] 
[{{.+}} { i8* [[DEV1BEGIN]], i8* [[DEV1END]], [[ENTTY]]* [[ENTBEGIN]], 
[[ENTTY]]* [[ENTEND]] }, {{.+}} { i8* [[DEV2BEGIN]], i8* [[DEV2END]], 
[[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }], comdat($[[REGFN]])
+// CHECK: [[DESC:@.+]] = internal constant [[DSCTY]] { i32 2, [[DEVTY]]* 
getelementptr inbounds ([2 x [[DEVTY]]], [2 x [[DEVTY]]]* [[IMAGES]], i32 0, 
i32 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }, comdat($[[REGFN]])
+
+// Check target registration is registered as a Ctor.
+// CHECK: appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* 
} { i32 0, void ()* @[[REGFN]], i8* bitcast (void ()* @[[REGFN]] to i8*) }]
+
+// Check presence of foo() and the outlined target region
+// CHECK: define void [[FOO:@.+]]()
+// CHECK: define internal void [[OUTLINEDTARGET:@.+]]() 
+
+// Check registration and unregistration code.
+
+// CHECK: define internal void @[[UNREGFN:.+]](i8*)
+// CHECK-SAME: comdat($[[REGFN]]) {
+// CHECK: call i32 @__tgt_unregister_lib([[DSCTY]]* [[DESC]])
+// CHECK: ret void
+// CHECK: declare i32 @__tgt_unregister_lib([[DSCTY]]*)
+
+// CHECK: define linkonce hidden void @[[REGFN]]()
+// CHECK-SAME: comdat {
+// CHECK: call i32 @__tgt_register_lib([[DSCTY]]* [[DESC]])
+// CHECK: call i32 @__cxa_atexit(void (i8*)* @[[UNREGFN]], i8* bitcast 
([[DSCTY]]* [[DESC]] to i8*),
+// CHECK: ret void
+// CHECK: declare i32 @__tgt_register_lib([[DSCTY]]*)
+
Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3818,7 +3818,19 @@
 CGF.disableDebugInfo();
 const auto  = CGM.getTypes().arrangeNullaryFunction();
 llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI);
-std::string Descriptor = getName({"omp_offloading", "descriptor_reg"});
+
+// Encode offload target triples into the registration function name. It
+// will serve as a comdat key for the registration/unregistration code for
+// this particular combination of offloading targets.
+SmallVector RegFnNameParts(Devices.size() + 2U);
+RegFnNameParts[0] = "omp_offloading";
+RegFnNameParts[1] = "descriptor_reg";
+llvm::transform(Devices, std::next(RegFnNameParts.begin(), 2),
+[](const llvm::Triple ) -> const std::string& {
+  return T.getTriple();
+});
+llvm::sort(std::next(RegFnNameParts.begin(), 2), RegFnNameParts.end());
+std::string Descriptor = getName(RegFnNameParts);
 RegFn = CGM.CreateGlobalInitOrDestructFunction(FTy, Descriptor, FI);
 CGF.StartFunction(GlobalDecl(), C.VoidTy, RegFn, FI, FunctionArgList());
 CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__tgt_register_lib), Desc);


Index: test/OpenMP/openmp_offload_registration.cpp
===
--- test/OpenMP/openmp_offload_registration.cpp
+++ test/OpenMP/openmp_offload_registration.cpp
@@ -0,0 +1,49 @@
+// Test for offload registration code for two targets
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-unknown-linux-gnu 

[PATCH] D50218: [OpenMP] Encode offload target triples into comdat key for offload initialization code

2018-08-03 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


https://reviews.llvm.org/D50218



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


[PATCH] D50218: [OpenMP] Encode offload target triples into comdat key for offload initialization code

2018-08-03 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev updated this revision to Diff 159074.

https://reviews.llvm.org/D50218

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/openmp_offload_registration.cpp


Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3818,7 +3818,19 @@
 CGF.disableDebugInfo();
 const auto  = CGM.getTypes().arrangeNullaryFunction();
 llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI);
-std::string Descriptor = getName({"omp_offloading", "descriptor_reg"});
+
+// Encode offload target triples into the registration function name. It
+// will serve as a comdat key for the registration/unregistration code for
+// this particular combination of offloading targets.
+SmallVector RegFnNameParts(Devices.size() + 2U);
+RegFnNameParts[0] = "omp_offloading";
+RegFnNameParts[1] = "descriptor_reg";
+llvm::transform(Devices, std::next(RegFnNameParts.begin(), 2),
+[](const llvm::Triple ) -> const std::string& {
+  return T.getTriple();
+});
+llvm::sort(std::next(RegFnNameParts.begin(), 2), RegFnNameParts.end());
+std::string Descriptor = getName(RegFnNameParts);
 RegFn = CGM.CreateGlobalInitOrDestructFunction(FTy, Descriptor, FI);
 CGF.StartFunction(GlobalDecl(), C.VoidTy, RegFn, FI, FunctionArgList());
 CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__tgt_register_lib), Desc);
Index: test/OpenMP/openmp_offload_registration.cpp
===
--- test/OpenMP/openmp_offload_registration.cpp
+++ test/OpenMP/openmp_offload_registration.cpp
@@ -0,0 +1,49 @@
+// Test for offload registration code for two targets
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-unknown-linux-gnu 
-fopenmp-targets=x86_64-pc-linux-gnu,powerpc64le-ibm-linux-gnu -emit-llvm %s -o 
- | FileCheck %s
+// expected-no-diagnostics
+
+void foo() {
+#pragma omp target
+  {}
+}
+
+// CHECK-DAG: [[ENTTY:%.+]] = type { i8*, i8*, i[[SZ:32|64]], i32, i32 }
+// CHECK-DAG: [[DEVTY:%.+]] = type { i8*, i8*, [[ENTTY]]*, [[ENTTY]]* }
+// CHECK-DAG: [[DSCTY:%.+]] = type { i32, [[DEVTY]]*, [[ENTTY]]*, [[ENTTY]]* }
+
+// Comdat key for the offload registration code. Should have sorted offload
+// target triples encoded into the name.
+// CHECK-DAG: 
$[[REGFN:\.omp_offloading\..+\.powerpc64le-ibm-linux-gnu\.x86_64-pc-linux-gnu+]]
 = comdat any
+
+// Check if offloading descriptor is created.
+// CHECK: [[ENTBEGIN:@.+]] = external constant [[ENTTY]]
+// CHECK: [[ENTEND:@.+]] = external constant [[ENTTY]]
+// CHECK: [[DEV1BEGIN:@.+]] = extern_weak constant i8
+// CHECK: [[DEV1END:@.+]] = extern_weak constant i8
+// CHECK: [[DEV2BEGIN:@.+]] = extern_weak constant i8
+// CHECK: [[DEV2END:@.+]] = extern_weak constant i8
+// CHECK: [[IMAGES:@.+]] = internal unnamed_addr constant [2 x [[DEVTY]]] 
[{{.+}} { i8* [[DEV1BEGIN]], i8* [[DEV1END]], [[ENTTY]]* [[ENTBEGIN]], 
[[ENTTY]]* [[ENTEND]] }, {{.+}} { i8* [[DEV2BEGIN]], i8* [[DEV2END]], 
[[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }], comdat($[[REGFN]])
+// CHECK: [[DESC:@.+]] = internal constant [[DSCTY]] { i32 2, [[DEVTY]]* 
getelementptr inbounds ([2 x [[DEVTY]]], [2 x [[DEVTY]]]* [[IMAGES]], i32 0, 
i32 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }, comdat($[[REGFN]])
+
+// Check target registration is registered as a Ctor.
+// CHECK: appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* 
} { i32 0, void ()* @[[REGFN]], i8* bitcast (void ()* @[[REGFN]] to i8*) }]
+
+// Check presence of foo() and the outlined target region
+// CHECK: define void [[FOO:@.+]]()
+// CHECK: define internal void [[OUTLINEDTARGET:@.+]]() 
+
+// Check registration and unregistration code.
+
+// CHECK: define internal void @[[UNREGFN:.+]](i8*)
+// CHECK-SAME: comdat($[[REGFN]]) {
+// CHECK: call i32 @__tgt_unregister_lib([[DSCTY]]* [[DESC]])
+// CHECK: ret void
+// CHECK: declare i32 @__tgt_unregister_lib([[DSCTY]]*)
+
+// CHECK: define linkonce hidden void @[[REGFN]]()
+// CHECK-SAME: comdat {
+// CHECK: call i32 @__tgt_register_lib([[DSCTY]]* [[DESC]])
+// CHECK: call i32 @__cxa_atexit(void (i8*)* @[[UNREGFN]], i8* bitcast 
([[DSCTY]]* [[DESC]] to i8*),
+// CHECK: ret void
+// CHECK: declare i32 @__tgt_register_lib([[DSCTY]]*)
+


Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3818,7 +3818,19 @@
 CGF.disableDebugInfo();
 const auto  = CGM.getTypes().arrangeNullaryFunction();
 llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI);
-std::string Descriptor = getName({"omp_offloading", "descriptor_reg"});
+
+// Encode offload target triples into the registration function name. It
+// will serve as a comdat key for the 

[PATCH] D50119: Compiler support for P1144R0 "__is_trivially_relocatable(T)"

2018-08-03 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: lib/Sema/SemaDeclCXX.cpp:6187
+Record->dropAttr();
+  } else if (Record->needsImplicitMoveConstructor() &&
+ Record->defaultedMoveConstructorIsDeleted()) {

Rakete wrote:
> Rakete wrote:
> > Quuxplusone wrote:
> > > Rakete wrote:
> > > > This is dead code. `Record` never needs an implicit move constructor at 
> > > > this point, because either 1) it never did or 2) it was defined above 
> > > > by `LookupSpecialMember`.
> > > Confirmed that this code is never hit; and removed. Just for my own 
> > > information: you're saying that the call to `LookupSpecialMember` on line 
> > > 6179, even though it's looking up the //destructor//, will actually cause 
> > > all the `needsImplicitFootor` flags to get resolved? And so also I guess 
> > > I should never have been looking at those flags directly; I should have 
> > > handled this case by calling `LookupSpecialMember` like I do on line 
> > > 6196. Is that basically correct?
> > No, not the 6179 one, but the one before it 6163. Yeah you could have :)
> Sorry for the noise, that isn't it because of the if statement right before 
> 6163 :/. I was wrong...
> 
> Every implicit constructor is already defined before the call to 
> `CheckCompletedCXXClass` (except if it's a template), so 
> `needsImplicitFootor` is always `false`. This means that you can drop the if 
> statement right before 6163, because it's always true.
> 
> I'm 99% sure of the previous paragraph. :)
I notice that `test/SemaCXX/implicit-member-functions.cpp` has started failing 
in my branch, although there's a *possibility* that that's due to a change in 
master. I'm going to investigate a little bit.


Repository:
  rC Clang

https://reviews.llvm.org/D50119



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


[PATCH] D50119: Compiler support for P1144R0 "__is_trivially_relocatable(T)"

2018-08-03 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone updated this revision to Diff 159073.
Quuxplusone marked 8 inline comments as done.
Quuxplusone added a comment.

Correctly drop the attribute from non-relocatable instantiations of class 
templates (even though they don't print the diagnostic).


Repository:
  rC Clang

https://reviews.llvm.org/D50119

Files:
  docs/LanguageExtensions.rst
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/Features.def
  include/clang/Basic/TokenKinds.def
  include/clang/Basic/TypeTraits.h
  lib/AST/ASTImporter.cpp
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExprCXX.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  test/Lexer/has_extension_cxx.cpp
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/SemaCXX/trivially-relocatable.cpp

Index: test/SemaCXX/trivially-relocatable.cpp
===
--- /dev/null
+++ test/SemaCXX/trivially-relocatable.cpp
@@ -0,0 +1,510 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
+// expected-diagnostics
+
+static_assert(__has_extension(trivially_relocatable), "");
+
+// It shall appear at most once in each attribute-list
+// and no attribute-argument-clause shall be present.
+
+struct [[trivially_relocatable, trivially_relocatable]] B1 {};
+// expected-error@-1{{attribute 'trivially_relocatable' cannot appear multiple times in an attribute specifier}}
+
+struct [[trivially_relocatable]] [[trivially_relocatable]] B2 {}; // should really be an error
+
+struct [[trivially_relocatable(42)]] B3 {};
+// expected-error@-1{{attribute 'trivially_relocatable' cannot have an argument list}}
+
+
+//   The first declaration of a type shall specify the
+//   trivially_relocatable attribute if any declaration of that
+//   type specifies the trivially_relocatable attribute.
+
+struct [[trivially_relocatable]] A1 {};  // ok
+struct [[trivially_relocatable]] A1;
+
+struct [[trivially_relocatable]] A2;  // ok
+struct [[trivially_relocatable]] A2 {};
+
+struct [[trivially_relocatable]] A3 {};  // ok
+struct A3;
+
+struct [[trivially_relocatable]] A4;  // ok
+struct A4 {};
+
+struct A5 {};
+struct [[trivially_relocatable]] A5;
+// expected-error@-1{{type A5 declared 'trivially_relocatable' after its first declaration}}
+// expected-note@-3{{declaration missing 'trivially_relocatable' attribute is here}}
+// expected-warning@-3{{attribute declaration must precede definition}}
+// expected-note@-5{{previous definition is here}}
+
+struct A6;
+struct [[trivially_relocatable]] A6 {};
+// expected-error@-1{{type A6 declared 'trivially_relocatable' after its first declaration}}
+// expected-note@-3{{declaration missing 'trivially_relocatable' attribute is here}}
+
+
+// If a type T is declared with the trivially_relocatable attribute, and T is
+// either not move-constructible or not destructible, the program is ill-formed.
+
+struct NonDestructible {
+NonDestructible(const NonDestructible&) = default;
+NonDestructible(NonDestructible&&) = default;
+~NonDestructible() = delete;
+};
+struct NonCopyConstructible {
+NonCopyConstructible(const NonCopyConstructible&) = delete;
+};
+struct NonMoveConstructible {
+NonMoveConstructible(const NonMoveConstructible&) = default;
+NonMoveConstructible(NonMoveConstructible&&) = delete;
+};
+static_assert(!__is_trivially_relocatable(NonDestructible), "");
+static_assert(!__is_trivially_relocatable(NonCopyConstructible), "");
+static_assert(!__is_constructible(NonCopyConstructible, NonCopyConstructible&&), "");
+static_assert(!__is_trivially_relocatable(NonMoveConstructible), "");
+static_assert(!__is_constructible(NonMoveConstructible, NonMoveConstructible&&), "");
+
+struct [[trivially_relocatable]] D1 { ~D1() = delete; };
+// expected-error@-1{{cannot be applied to struct 'D1' because it is not destructible}}
+
+struct [[trivially_relocatable]] D2 : private NonDestructible { };
+// expected-error@-1{{cannot be applied to struct 'D2' because it is not destructible}}
+
+struct [[trivially_relocatable]] D3 { D3(const D3&) = delete; };
+// expected-error@-1{{cannot be applied to struct 'D3' because it is not move-constructible}}
+
+struct [[trivially_relocatable]] D4 { D4(const D4&) = default; D4(D4&&) = delete; };
+// expected-error@-1{{cannot be applied to struct 'D4' because it is not move-constructible}}
+
+struct [[trivially_relocatable]] D5 : private NonCopyConstructible { };
+// expected-error@-1{{cannot be applied to struct 'D5' because it is not move-constructible}}
+static_assert(!__is_constructible(D5, D5&&), "");
+
+struct [[trivially_relocatable]] D6 : private NonMoveConstructible { D6(D6&&) = default; };
+// expected-error@-1{{cannot be applied to struct 'D6' because it is not 

[PATCH] D48909: [clang-doc] Update BitcodeReader to use llvm::Error

2018-08-03 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 159071.
juliehockett marked 2 inline comments as done.

https://reviews.llvm.org/D48909

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeReader.h

Index: clang-tools-extra/clang-doc/BitcodeReader.h
===
--- clang-tools-extra/clang-doc/BitcodeReader.h
+++ clang-tools-extra/clang-doc/BitcodeReader.h
@@ -22,6 +22,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Bitcode/BitstreamReader.h"
+#include "llvm/Support/Error.h"
 
 namespace clang {
 namespace doc {
@@ -38,30 +39,31 @@
   enum class Cursor { BadBlock = 1, Record, BlockEnd, BlockBegin };
 
   // Top level parsing
-  bool validateStream();
-  bool readVersion();
-  bool readBlockInfoBlock();
+  llvm::Error validateStream();
+  llvm::Error readVersion();
+  llvm::Error readBlockInfoBlock();
 
   // Read a block of records into a single Info struct, calls readRecord on each
   // record found.
-  template  bool readBlock(unsigned ID, T I);
+  template  llvm::Error readBlock(unsigned ID, T I);
 
   // Step through a block of records to find the next data field.
-  template  bool readSubBlock(unsigned ID, T I);
+  template  llvm::Error readSubBlock(unsigned ID, T I);
 
   // Read record data into the given Info data field, calling the appropriate
   // parseRecord functions to parse and store the data.
-  template  bool readRecord(unsigned ID, T I);
+  template  llvm::Error readRecord(unsigned ID, T I);
 
   // Allocate the relevant type of info and add read data to the object.
-  template  std::unique_ptr createInfo(unsigned ID);
+  template 
+  llvm::Expected> createInfo(unsigned ID);
 
   // Helper function to step through blocks to find and dispatch the next record
   // or block to be read.
   Cursor skipUntilRecordOrBlock(unsigned );
 
   // Helper function to set up the approriate type of Info.
-  std::unique_ptr readBlockToInfo(unsigned ID);
+  llvm::Expected> readBlockToInfo(unsigned ID);
 
   llvm::BitstreamCursor 
   Optional BlockInfo;
Index: clang-tools-extra/clang-doc/BitcodeReader.cpp
===
--- clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -10,91 +10,99 @@
 #include "BitcodeReader.h"
 #include "llvm/ADT/IndexedMap.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 namespace doc {
 
 using Record = llvm::SmallVector;
 
-bool decodeRecord(Record R, llvm::SmallVectorImpl ,
-  llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, llvm::SmallVectorImpl ,
+ llvm::StringRef Blob) {
   Field.assign(Blob.begin(), Blob.end());
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, SymbolID , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, SymbolID , llvm::StringRef Blob) {
   if (R[0] != BitCodeConstants::USRHashSize)
-return false;
+return llvm::make_error("Incorrect USR size.\n",
+   llvm::inconvertibleErrorCode());
 
   // First position in the record is the length of the following array, so we
   // copy the following elements to the field.
   for (int I = 0, E = R[0]; I < E; ++I)
 Field[I] = R[I + 1];
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, bool , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, bool , llvm::StringRef Blob) {
   Field = R[0] != 0;
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, int , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, int , llvm::StringRef Blob) {
   if (R[0] > INT_MAX)
-return false;
+return llvm::make_error("Integer too large to parse.\n",
+   llvm::inconvertibleErrorCode());
   Field = (int)R[0];
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, AccessSpecifier , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, AccessSpecifier ,
+ llvm::StringRef Blob) {
   switch (R[0]) {
   case AS_public:
   case AS_private:
   case AS_protected:
   case AS_none:
 Field = (AccessSpecifier)R[0];
-return true;
+return llvm::Error::success();
   default:
-return false;
+return llvm::make_error(
+"Invalid value for AccessSpecifier.\n", llvm::inconvertibleErrorCode());
   }
 }
 
-bool decodeRecord(Record R, TagTypeKind , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, TagTypeKind , llvm::StringRef Blob) {
   switch (R[0]) {
   case TTK_Struct:
   case TTK_Interface:
   case TTK_Union:
   case TTK_Class:
   case TTK_Enum:
 Field = (TagTypeKind)R[0];
-return true;
+return llvm::Error::success();
   default:
-return false;
+return 

[PATCH] D48909: [clang-doc] Update BitcodeReader to use llvm::Error

2018-08-03 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 159070.

https://reviews.llvm.org/D48909

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeReader.h

Index: clang-tools-extra/clang-doc/BitcodeReader.h
===
--- clang-tools-extra/clang-doc/BitcodeReader.h
+++ clang-tools-extra/clang-doc/BitcodeReader.h
@@ -38,30 +38,31 @@
   enum class Cursor { BadBlock = 1, Record, BlockEnd, BlockBegin };
 
   // Top level parsing
-  bool validateStream();
-  bool readVersion();
-  bool readBlockInfoBlock();
+  llvm::Error validateStream();
+  llvm::Error readVersion();
+  llvm::Error readBlockInfoBlock();
 
   // Read a block of records into a single Info struct, calls readRecord on each
   // record found.
-  template  bool readBlock(unsigned ID, T I);
+  template  llvm::Error readBlock(unsigned ID, T I);
 
   // Step through a block of records to find the next data field.
-  template  bool readSubBlock(unsigned ID, T I);
+  template  llvm::Error readSubBlock(unsigned ID, T I);
 
   // Read record data into the given Info data field, calling the appropriate
   // parseRecord functions to parse and store the data.
-  template  bool readRecord(unsigned ID, T I);
+  template  llvm::Error readRecord(unsigned ID, T I);
 
   // Allocate the relevant type of info and add read data to the object.
-  template  std::unique_ptr createInfo(unsigned ID);
+  template 
+  llvm::Expected> createInfo(unsigned ID);
 
   // Helper function to step through blocks to find and dispatch the next record
   // or block to be read.
   Cursor skipUntilRecordOrBlock(unsigned );
 
   // Helper function to set up the approriate type of Info.
-  std::unique_ptr readBlockToInfo(unsigned ID);
+  llvm::Expected> readBlockToInfo(unsigned ID);
 
   llvm::BitstreamCursor 
   Optional BlockInfo;
Index: clang-tools-extra/clang-doc/BitcodeReader.cpp
===
--- clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -17,84 +17,91 @@
 
 using Record = llvm::SmallVector;
 
-bool decodeRecord(Record R, llvm::SmallVectorImpl ,
-  llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, llvm::SmallVectorImpl ,
+ llvm::StringRef Blob) {
   Field.assign(Blob.begin(), Blob.end());
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, SymbolID , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, SymbolID , llvm::StringRef Blob) {
   if (R[0] != BitCodeConstants::USRHashSize)
-return false;
+return llvm::make_error("Incorrect USR size.\n",
+   llvm::inconvertibleErrorCode());
 
   // First position in the record is the length of the following array, so we
   // copy the following elements to the field.
   for (int I = 0, E = R[0]; I < E; ++I)
 Field[I] = R[I + 1];
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, bool , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, bool , llvm::StringRef Blob) {
   Field = R[0] != 0;
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, int , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, int , llvm::StringRef Blob) {
   if (R[0] > INT_MAX)
-return false;
+return llvm::make_error("Integer too large to parse.\n",
+   llvm::inconvertibleErrorCode());
   Field = (int)R[0];
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, AccessSpecifier , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, AccessSpecifier ,
+ llvm::StringRef Blob) {
   switch (R[0]) {
   case AS_public:
   case AS_private:
   case AS_protected:
   case AS_none:
 Field = (AccessSpecifier)R[0];
-return true;
+return llvm::Error::success();
   default:
-return false;
+return llvm::make_error(
+"Invalid value for AccessSpecifier.\n", llvm::inconvertibleErrorCode());
   }
 }
 
-bool decodeRecord(Record R, TagTypeKind , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, TagTypeKind , llvm::StringRef Blob) {
   switch (R[0]) {
   case TTK_Struct:
   case TTK_Interface:
   case TTK_Union:
   case TTK_Class:
   case TTK_Enum:
 Field = (TagTypeKind)R[0];
-return true;
+return llvm::Error::success();
   default:
-return false;
+return llvm::make_error(
+"Invalid value for TagTypeKind.\n", llvm::inconvertibleErrorCode());
   }
 }
 
-bool decodeRecord(Record R, llvm::Optional ,
-  llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, llvm::Optional ,
+ llvm::StringRef Blob) {
   if (R[0] > INT_MAX)
-return false;
+return llvm::make_error("Integer too large to parse.\n",
+   

[PATCH] D50255: Add test for changing build configuration

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

In https://reviews.llvm.org/D50255#1187871, @arphaman wrote:

> Thanks! This LGTM.


Well, thanks for the hints!


Repository:
  rL LLVM

https://reviews.llvm.org/D50255



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


[clang-tools-extra] r338914 - [clangd] Add test for changing build configuration

2018-08-03 Thread Simon Marchi via cfe-commits
Author: simark
Date: Fri Aug  3 12:40:19 2018
New Revision: 338914

URL: http://llvm.org/viewvc/llvm-project?rev=338914=rev
Log:
[clangd] Add test for changing build configuration

Summary:
This patch adds tests for the two ways of changing build configuration
(pointing to a particular compile_commands.json):

- Through the workspace/didChangeConfiguration notification.
- Through the initialize request.

Subscribers: ilya-biryukov, ioeric, jkorous, arphaman, cfe-commits

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

Added:
clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test
clang-tools-extra/trunk/test/clangd/compile-commands-path.test

Added: 
clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test?rev=338914=auto
==
--- 
clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test 
(added)
+++ 
clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test 
Fri Aug  3 12:40:19 2018
@@ -0,0 +1,35 @@
+# Test that we can set choose a configuration/build directly in the initialize
+# request.
+
+# RUN: rm -rf %t.dir/* && mkdir -p %t.dir
+# RUN: mkdir %t.dir/build-1
+# RUN: mkdir %t.dir/build-2
+# RUN: echo '[{"directory": "%/t.dir", "command": "c++ the-file.cpp", "file": 
"the-file.cpp"}]' > %t.dir/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-1", "command": "c++ -DMACRO=1 
the-file.cpp", "file": "../the-file.cpp"}]' > 
%t.dir/build-1/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-2", "command": "c++ -DMACRO=2 
the-file.cpp", "file": "../the-file.cpp"}]' > 
%t.dir/build-2/compile_commands.json
+
+# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
+
+# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
+# (with the extra slash in the front), so we add it here.
+# RUN: sed -e "s|file://\([A-Z]\):/|file:///\1:/|g" %t.test.1 > %t.test
+
+# RUN: clangd -lit-test < %t.test | FileCheck -strict-whitespace %t.test
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"initializationOptions":{"compilationDatabasePath":"INPUT_DIR/build-1"}}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file://INPUT_DIR/the-file.cpp","languageId":"cpp","version":1,"text":"#if
 !defined(MACRO)\n#pragma message (\"MACRO is not defined\")\n#elif MACRO == 
1\n#pragma message (\"MACRO is one\")\n#elif MACRO == 2\n#pragma message 
(\"MACRO is two\")\n#else\n#pragma message (\"woops\")\n#endif\nint main() 
{}\n"}}}
+# CHECK:   "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:   "params": {
+# CHECK-NEXT: "diagnostics": [
+# CHECK-NEXT:   {
+# CHECK-NEXT: "message": "MACRO is one",
+---
+{"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-2"}}}
+# CHECK:   "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:   "params": {
+# CHECK-NEXT: "diagnostics": [
+# CHECK-NEXT:   {
+# CHECK-NEXT: "message": "MACRO is two",
+---
+{"jsonrpc":"2.0","id":1,"method":"shutdown"}

Added: clang-tools-extra/trunk/test/clangd/compile-commands-path.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/compile-commands-path.test?rev=338914=auto
==
--- clang-tools-extra/trunk/test/clangd/compile-commands-path.test (added)
+++ clang-tools-extra/trunk/test/clangd/compile-commands-path.test Fri Aug  3 
12:40:19 2018
@@ -0,0 +1,42 @@
+# Test that we can switch between configuration/build using the
+# workspace/didChangeConfiguration notification.
+
+# RUN: rm -rf %t.dir/* && mkdir -p %t.dir
+# RUN: mkdir %t.dir/build-1
+# RUN: mkdir %t.dir/build-2
+# RUN: echo '[{"directory": "%/t.dir", "command": "c++ the-file.cpp", "file": 
"the-file.cpp"}]' > %t.dir/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-1", "command": "c++ -DMACRO=1 
the-file.cpp", "file": "../the-file.cpp"}]' > 
%t.dir/build-1/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-2", "command": "c++ -DMACRO=2 
the-file.cpp", "file": "../the-file.cpp"}]' > 
%t.dir/build-2/compile_commands.json
+
+# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
+
+# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
+# (with the extra slash in the front), so we add it here.
+# RUN: sed -e "s|file://\([A-Z]\):/|file:///\1:/|g" %t.test.1 > %t.test
+
+# RUN: clangd -lit-test < %t.test | FileCheck -strict-whitespace %t.test
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{}}
+---

[PATCH] D50255: Add test for changing build configuration

2018-08-03 Thread Simon Marchi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL338914: [clangd] Add test for changing build configuration 
(authored by simark, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D50255

Files:
  clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test
  clang-tools-extra/trunk/test/clangd/compile-commands-path.test


Index: 
clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test
===
--- clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test
+++ clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test
@@ -0,0 +1,35 @@
+# Test that we can set choose a configuration/build directly in the initialize
+# request.
+
+# RUN: rm -rf %t.dir/* && mkdir -p %t.dir
+# RUN: mkdir %t.dir/build-1
+# RUN: mkdir %t.dir/build-2
+# RUN: echo '[{"directory": "%/t.dir", "command": "c++ the-file.cpp", "file": 
"the-file.cpp"}]' > %t.dir/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-1", "command": "c++ -DMACRO=1 
the-file.cpp", "file": "../the-file.cpp"}]' > 
%t.dir/build-1/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-2", "command": "c++ -DMACRO=2 
the-file.cpp", "file": "../the-file.cpp"}]' > 
%t.dir/build-2/compile_commands.json
+
+# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
+
+# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
+# (with the extra slash in the front), so we add it here.
+# RUN: sed -e "s|file://\([A-Z]\):/|file:///\1:/|g" %t.test.1 > %t.test
+
+# RUN: clangd -lit-test < %t.test | FileCheck -strict-whitespace %t.test
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"initializationOptions":{"compilationDatabasePath":"INPUT_DIR/build-1"}}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file://INPUT_DIR/the-file.cpp","languageId":"cpp","version":1,"text":"#if
 !defined(MACRO)\n#pragma message (\"MACRO is not defined\")\n#elif MACRO == 
1\n#pragma message (\"MACRO is one\")\n#elif MACRO == 2\n#pragma message 
(\"MACRO is two\")\n#else\n#pragma message (\"woops\")\n#endif\nint main() 
{}\n"}}}
+# CHECK:   "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:   "params": {
+# CHECK-NEXT: "diagnostics": [
+# CHECK-NEXT:   {
+# CHECK-NEXT: "message": "MACRO is one",
+---
+{"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-2"}}}
+# CHECK:   "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:   "params": {
+# CHECK-NEXT: "diagnostics": [
+# CHECK-NEXT:   {
+# CHECK-NEXT: "message": "MACRO is two",
+---
+{"jsonrpc":"2.0","id":1,"method":"shutdown"}
Index: clang-tools-extra/trunk/test/clangd/compile-commands-path.test
===
--- clang-tools-extra/trunk/test/clangd/compile-commands-path.test
+++ clang-tools-extra/trunk/test/clangd/compile-commands-path.test
@@ -0,0 +1,42 @@
+# Test that we can switch between configuration/build using the
+# workspace/didChangeConfiguration notification.
+
+# RUN: rm -rf %t.dir/* && mkdir -p %t.dir
+# RUN: mkdir %t.dir/build-1
+# RUN: mkdir %t.dir/build-2
+# RUN: echo '[{"directory": "%/t.dir", "command": "c++ the-file.cpp", "file": 
"the-file.cpp"}]' > %t.dir/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-1", "command": "c++ -DMACRO=1 
the-file.cpp", "file": "../the-file.cpp"}]' > 
%t.dir/build-1/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-2", "command": "c++ -DMACRO=2 
the-file.cpp", "file": "../the-file.cpp"}]' > 
%t.dir/build-2/compile_commands.json
+
+# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
+
+# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
+# (with the extra slash in the front), so we add it here.
+# RUN: sed -e "s|file://\([A-Z]\):/|file:///\1:/|g" %t.test.1 > %t.test
+
+# RUN: clangd -lit-test < %t.test | FileCheck -strict-whitespace %t.test
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file://INPUT_DIR/the-file.cpp","languageId":"cpp","version":1,"text":"#if
 !defined(MACRO)\n#pragma message (\"MACRO is not defined\")\n#elif MACRO == 
1\n#pragma message (\"MACRO is one\")\n#elif MACRO == 2\n#pragma message 
(\"MACRO is two\")\n#else\n#pragma message (\"woops\")\n#endif\nint main() 
{}\n"}}}
+# CHECK:   "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:   "params": {
+# CHECK-NEXT: "diagnostics": [
+# CHECK-NEXT:   {
+# CHECK-NEXT: "message": "MACRO is not defined",
+---
+{"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-1"}}}
+# CHECK:  

[PATCH] D50267: [ASTWriter] Use zlib::compress which operates on std::unique_ptr

2018-08-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay abandoned this revision.
MaskRay added a comment.

https://reviews.llvm.org/D50223 has been changed to improve zlib::compress's 
current SmallVectorImpl interface. This is no longer relevant.


Repository:
  rC Clang

https://reviews.llvm.org/D50267



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


[PATCH] D50110: Handle shared release attributes correctly

2018-08-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

In https://reviews.llvm.org/D50110#1187828, @aaronpuchert wrote:

> For now I think I'm done fixing things in the thread safety analysis, but if 
> I see myself contributing more in the longer term, I will definitely try to 
> obtain commit access.


Sounds good to me. I've commit in r338912. Thank you for the thread safety 
analysis patches!


Repository:
  rC Clang

https://reviews.llvm.org/D50110



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


r338912 - Properly add shared locks to the initial list of locks being tracked, instead of assuming unlock functions always use exclusive locks.

2018-08-03 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Aug  3 12:37:45 2018
New Revision: 338912

URL: http://llvm.org/viewvc/llvm-project?rev=338912=rev
Log:
Properly add shared locks to the initial list of locks being tracked, instead 
of assuming unlock functions always use exclusive locks.

Patch by Aaron Puchert.

Modified:
cfe/trunk/lib/Analysis/ThreadSafety.cpp
cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp

Modified: cfe/trunk/lib/Analysis/ThreadSafety.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ThreadSafety.cpp?rev=338912=338911=338912=diff
==
--- cfe/trunk/lib/Analysis/ThreadSafety.cpp (original)
+++ cfe/trunk/lib/Analysis/ThreadSafety.cpp Fri Aug  3 12:37:45 2018
@@ -2242,8 +2242,8 @@ void ThreadSafetyAnalyzer::runAnalysis(A
 // We must ignore such methods.
 if (A->args_size() == 0)
   return;
-// FIXME -- deal with exclusive vs. shared unlock functions?
-getMutexIDs(ExclusiveLocksToAdd, A, nullptr, D);
+getMutexIDs(A->isShared() ? SharedLocksToAdd : ExclusiveLocksToAdd, A,
+nullptr, D);
 getMutexIDs(LocksReleased, A, nullptr, D);
 CapDiagKind = ClassifyDiagnostic(A);
   } else if (const auto *A = dyn_cast(Attr)) {

Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp?rev=338912=338911=338912=diff
==
--- cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-analysis.cpp Fri Aug  3 12:37:45 
2018
@@ -4078,6 +4078,14 @@ public:
 mu_.Unlock();
   }
 
+  void unlockExclusive() EXCLUSIVE_UNLOCK_FUNCTION(mu_) {
+mu_.Unlock();
+  }
+
+  void unlockShared() SHARED_UNLOCK_FUNCTION(mu_) {
+mu_.ReaderUnlock();
+  }
+
   // Check failure to lock.
   void lockBad() EXCLUSIVE_LOCK_FUNCTION(mu_) {// expected-note {{mutex 
acquired here}}
 mu2_.Lock();


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


[PATCH] D50255: Add test for changing build configuration

2018-08-03 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

Thanks! This LGTM.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50255



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


[PATCH] D50154: [clangd] capitalize diagnostic messages if '-capitialize-diagnostic-text' is provided

2018-08-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

nit: The patch description needs to be updated.


https://reviews.llvm.org/D50154



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


[PATCH] D49910: [clang-tidy] Recognize [[clang::reinitializes]] attribute in bugprone-use-after-move

2018-08-03 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

Sorry, that code got formatted strangely. Here's the same code block in more 
legible form:

  MyContainer container;
  T t;
  while (GetNextT()) {
container.Add(t);
if (SomeCondition()) {
  PassToConsumer(std::move(container));
  container.Clear();
}
  }


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49910



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


[PATCH] D49910: [clang-tidy] Recognize [[clang::reinitializes]] attribute in bugprone-use-after-move

2018-08-03 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

In https://reviews.llvm.org/D49910#1187809, @aaron.ballman wrote:

> In https://reviews.llvm.org/D49910#1187492, @mboehme wrote:
>
> > In https://reviews.llvm.org/D49910#1187455, @aaron.ballman wrote:
> >
> > > Are you going to propose adding this attribute to libc++, or is this 
> > > expected to only work with UDTs?
> >
> >
> > I don't have any experience contributing to libc++, but I think this would 
> > make sense.
> >
> > The check currently hard-codes various member functions of classes in the 
> > "std" namespace that do reinitializations; I'm not sure though if those can 
> > be removed after the attribute has been added to libc++. We'd would also 
> > presumably have to add the attribute to libstdc++ -- does it accept 
> > Clang-only attributes? And what is the story for people using clang-tidy 
> > with MSVC projects? (I have to admit I'm very hazy on how that works...)
>
>
> I ask the question because it's novel to add an attribute to Clang that's 
> used only by clang-tidy, and I'm wondering who is expected to use that 
> attribute to help with this check. Is it expected to be an attribute users 
> use with their own custom datatypes and it's not needed for standards-based 
> APIs (because we handle those some other way), or something else? As it 
> stands, I sort of feel like this is a very heavy approach to solve an edge 
> case -- is there a lot of evidence for re-using a moved-from object after 
> reinitializing it?


Ah, now I understand what you're getting at.

Yes, I see this attribute mainly as something that people would add to their 
own user-defined types -- typically, containers and smart pointers.

I've regularly been getting internal feature requests for this. One typical 
pattern in which this comes up is the following:

MyContainer container;
T t;
while (GetNextT()) {

  container.Add(t);
  if (SomeCondition()) {
PassToConsumer(std::move(container));
container.Clear();
  }

}

I.e. you're incrementally adding items to some data structure, and at some 
point you decide the data structure is now complete, so you hand it off to a 
consumer and clear it, ready to be filled with the next batch of items.

As clang-tidy doesn't understand that the "container.Clear()" reinitializes the 
container, it complains that the Clear() is a use-after-move.

Yes, it's unusual to add an attribute to Clang that is only (at least 
initially) intended for use by clang-tidy -- but I don't really see how to 
implement this other than with an attribute.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49910



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


[PATCH] D40854: [clang-tidy] WIP implement cppcoreguidelines check for mixed integer arithmetic

2018-08-03 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 159064.
JonasToth added a comment.

- get check up to date


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40854

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/MixedIntArithmeticCheck.cpp
  clang-tidy/cppcoreguidelines/MixedIntArithmeticCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-mixed-int-arithmetic.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-mixed-int-arithmetic.cpp

Index: test/clang-tidy/cppcoreguidelines-mixed-int-arithmetic.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-mixed-int-arithmetic.cpp
@@ -0,0 +1,188 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-mixed-int-arithmetic %t
+
+enum UnsignedEnum : unsigned char {
+  UEnum1,
+  UEnum2
+};
+
+enum SignedEnum : signed char {
+  SEnum1,
+  SEnum2
+};
+
+unsigned char returnUnsignedCharacter() { return 42; }
+unsigned returnUnsignedNumber() { return 42u; }
+long returnBigNumber() { return 42; }
+float unrelatedThing() { return 42.f; }
+SignedEnum returnSignedEnum() { return SEnum1; }
+UnsignedEnum returnUnsignedEnum() { return UEnum1; }
+
+void mixed_binary() {
+  unsigned int UInt1 = 42;
+  signed int SInt1 = 42;
+  UnsignedEnum UE1 = UEnum1;
+  SignedEnum SE1 = SEnum1;
+  float UnrelatedFloat = 42.f;
+
+  // Test traditional integer types.
+  auto R1 = UInt1 + SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:21: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:13: note: unsigned operand
+
+  int R2 = UInt1 - SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:20: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:12: note: unsigned operand
+
+  unsigned int R3 = UInt1 * SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:29: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:21: note: unsigned operand
+
+  unsigned int R4 = UInt1 / returnBigNumber();
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:29: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:21: note: unsigned operand
+
+  char R5 = returnUnsignedCharacter() + SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:41: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:13: note: unsigned operand
+
+  auto R6 = SInt1 - 10u;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:13: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:21: note: unsigned operand
+
+  auto R7 = UInt1 * 10;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:21: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:13: note: unsigned operand
+
+  auto R8 = 10u / returnBigNumber();
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:19: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:13: note: unsigned operand
+
+  auto R9 = 10 + returnUnsignedCharacter();
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:13: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:18: note: unsigned operand
+
+  // Test enum types.
+  char R10 = returnUnsignedEnum() - SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:14: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:37: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:14: note: unsigned operand
+
+  unsigned char R11 = returnSignedEnum() * UInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:23: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:23: note: signed operand
+  // CHECK-MESSAGES: 

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

2018-08-03 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 159062.
JonasToth added a comment.

get check up to 8.0


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45444

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/ConstCheck.cpp
  clang-tidy/cppcoreguidelines/ConstCheck.h
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  docs/clang-tidy/checks/cppcoreguidelines-const.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-const-pointers-as-values.cpp
  test/clang-tidy/cppcoreguidelines-const-values.cpp

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

[PATCH] D50110: Handle shared release attributes correctly

2018-08-03 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

For now I think I'm done fixing things in the thread safety analysis, but if I 
see myself contributing more in the longer term, I will definitely try to 
obtain commit access.


Repository:
  rC Clang

https://reviews.llvm.org/D50110



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


[PATCH] D50267: [ASTWriter] Use zlib::compress which operates on std::unique_ptr

2018-08-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

This depends on https://reviews.llvm.org/D50223


Repository:
  rC Clang

https://reviews.llvm.org/D50267



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


[PATCH] D50267: [ASTWriter] Use zlib::compress which operates on std::unique_ptr

2018-08-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: ruiu, rsmith.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D50267

Files:
  lib/Serialization/ASTWriter.cpp


Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -2207,14 +2207,17 @@
 
   // Compress the buffer if possible. We expect that almost all PCM
   // consumers will not want its contents.
-  SmallString<0> CompressedBuffer;
+  std::unique_ptr CompressedData;
+  size_t CompressedSize;
   if (llvm::zlib::isAvailable()) {
-llvm::Error E = llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer);
+llvm::Error E =
+llvm::zlib::compress(Blob.drop_back(1), CompressedData, 
CompressedSize);
 if (!E) {
   RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED,
  Blob.size() - 1};
-  Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
-CompressedBuffer);
+  Stream.EmitRecordWithBlob(
+  SLocBufferBlobCompressedAbbrv, Record,
+  StringRef((char *)CompressedData.get(), CompressedSize));
   return;
 }
 llvm::consumeError(std::move(E));


Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -2207,14 +2207,17 @@
 
   // Compress the buffer if possible. We expect that almost all PCM
   // consumers will not want its contents.
-  SmallString<0> CompressedBuffer;
+  std::unique_ptr CompressedData;
+  size_t CompressedSize;
   if (llvm::zlib::isAvailable()) {
-llvm::Error E = llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer);
+llvm::Error E =
+llvm::zlib::compress(Blob.drop_back(1), CompressedData, CompressedSize);
 if (!E) {
   RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED,
  Blob.size() - 1};
-  Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
-CompressedBuffer);
+  Stream.EmitRecordWithBlob(
+  SLocBufferBlobCompressedAbbrv, Record,
+  StringRef((char *)CompressedData.get(), CompressedSize));
   return;
 }
 llvm::consumeError(std::move(E));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50218: [OpenMP] Encode offload target triples into comdat key for offload initialization code

2018-08-03 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:3828-3829
+RegFnNameParts[1] = "descriptor_reg";
+for (size_t I = 0; I < Devices.size(); ++I)
+  RegFnNameParts[I + 2U] = Devices[I].getTriple();
+llvm::sort(RegFnNameParts.begin() + 2, RegFnNameParts.end());

Use something like this:
```
llvm::copy(Devices, std::next(RegFnNameParts.begin(), 2));
```



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:3830
+  RegFnNameParts[I + 2U] = Devices[I].getTriple();
+llvm::sort(RegFnNameParts.begin() + 2, RegFnNameParts.end());
+std::string Descriptor = getName(RegFnNameParts);

Also, use `std::next(RegFnNameParts.begin(), 2)`


https://reviews.llvm.org/D50218



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


[PATCH] D49910: [clang-tidy] Recognize [[clang::reinitializes]] attribute in bugprone-use-after-move

2018-08-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D49910#1187492, @mboehme wrote:

> In https://reviews.llvm.org/D49910#1187455, @aaron.ballman wrote:
>
> > Are you going to propose adding this attribute to libc++, or is this 
> > expected to only work with UDTs?
>
>
> I don't have any experience contributing to libc++, but I think this would 
> make sense.
>
> The check currently hard-codes various member functions of classes in the 
> "std" namespace that do reinitializations; I'm not sure though if those can 
> be removed after the attribute has been added to libc++. We'd would also 
> presumably have to add the attribute to libstdc++ -- does it accept 
> Clang-only attributes? And what is the story for people using clang-tidy with 
> MSVC projects? (I have to admit I'm very hazy on how that works...)


I ask the question because it's novel to add an attribute to Clang that's used 
only by clang-tidy, and I'm wondering who is expected to use that attribute to 
help with this check. Is it expected to be an attribute users use with their 
own custom datatypes and it's not needed for standards-based APIs (because we 
handle those some other way), or something else? As it stands, I sort of feel 
like this is a very heavy approach to solve an edge case -- is there a lot of 
evidence for re-using a moved-from object after reinitializing it?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49910



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


[PATCH] D50154: [clangd] capitalize diagnostic messages if '-capitialize-diagnostic-text' is provided

2018-08-03 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: clangd/Diagnostics.cpp:149
+/// Capitalizes the first word in the diagnostic's message.
+std::string capitalizeDiagnosticText(std::string Message) {
+  if (!Message.empty())

nit: this doesn't have to be diagnostic text, so I'd probably call this 
`capitalize()`.


https://reviews.llvm.org/D50154



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


[PATCH] D50154: [clangd] capitalize diagnostic messages if '-capitialize-diagnostic-text' is provided

2018-08-03 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: test/clangd/capitalize-diagnostics.test:1
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}

ioeric wrote:
> This new test doesn't seem to be needed anymore?
Right, the note message is exercised by the unit test, which I didn't update. 
Updated it now.


https://reviews.llvm.org/D50154



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


[PATCH] D50154: [clangd] capitalize diagnostic messages if '-capitialize-diagnostic-text' is provided

2018-08-03 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 159059.
arphaman marked an inline comment as done.
arphaman added a comment.

Remove test and update unit test.


https://reviews.llvm.org/D50154

Files:
  clangd/Diagnostics.cpp
  test/clangd/diagnostics.test
  test/clangd/did-change-configuration-params.test
  test/clangd/execute-command.test
  test/clangd/extra-flags.test
  test/clangd/fixits.test
  unittests/clangd/ClangdUnitTests.cpp

Index: unittests/clangd/ClangdUnitTests.cpp
===
--- unittests/clangd/ClangdUnitTests.cpp
+++ unittests/clangd/ClangdUnitTests.cpp
@@ -172,15 +172,15 @@
   };
 
   // Diagnostics should turn into these:
-  clangd::Diagnostic MainLSP = MatchingLSP(D, R"(something terrible happened
+  clangd::Diagnostic MainLSP = MatchingLSP(D, R"(Something terrible happened
 
 main.cpp:6:7: remark: declared somewhere in the main file
 
 ../foo/baz/header.h:10:11:
 note: declared somewhere in the header file)");
 
   clangd::Diagnostic NoteInMainLSP =
-  MatchingLSP(NoteInMain, R"(declared somewhere in the main file
+  MatchingLSP(NoteInMain, R"(Declared somewhere in the main file
 
 main.cpp:2:3: error: something terrible happened)");
 
Index: test/clangd/fixits.test
===
--- test/clangd/fixits.test
+++ test/clangd/fixits.test
@@ -6,7 +6,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
-# CHECK-NEXT:"message": "using the result of an assignment as a condition without parentheses",
+# CHECK-NEXT:"message": "Using the result of an assignment as a condition without parentheses",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": 37,
@@ -23,7 +23,7 @@
 # CHECK-NEXT:"uri": "file://{{.*}}/foo.c"
 # CHECK-NEXT:  }
 ---
-{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":104,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"using the result of an assignment as a condition without parentheses"}]}}}
+{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":104,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"Using the result of an assignment as a condition without parentheses"}]}}}
 #  CHECK:  "id": 2,
 # CHECK-NEXT:  "jsonrpc": "2.0",
 # CHECK-NEXT:  "result": [
@@ -92,7 +92,7 @@
 # CHECK-NEXT:}
 # CHECK-NEXT:  ]
 ---
-{"jsonrpc":"2.0","id":3,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":104,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"using the result of an assignment as a condition without parentheses"}]}}}
+{"jsonrpc":"2.0","id":3,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":104,"character":13},"end":{"line":0,"character":35}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 32}, "end": {"line": 0, "character": 37}},"severity":2,"message":"Using the result of an assignment as a condition without parentheses"}]}}}
 # Make sure unused "code" and "source" fields ignored gracefully
 #  CHECK:  "id": 3,
 # CHECK-NEXT:  "jsonrpc": "2.0",
Index: test/clangd/extra-flags.test
===
--- test/clangd/extra-flags.test
+++ test/clangd/extra-flags.test
@@ -6,7 +6,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
-# CHECK-NEXT:"message": "variable 'i' is uninitialized when used here",
+# CHECK-NEXT:"message": "Variable 'i' is uninitialized when used here",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": 28,
@@ -28,7 +28,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
-# CHECK-NEXT:"message": "variable 'i' is uninitialized when used here",
+# CHECK-NEXT:"message": "Variable 'i' is uninitialized when used here",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
 # CHECK-NEXT:"character": 28,
Index: test/clangd/execute-command.test
===
--- test/clangd/execute-command.test
+++ test/clangd/execute-command.test
@@ -6,7 +6,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
-# CHECK-NEXT:"message": "using 

[PATCH] D50110: Handle shared release attributes correctly

2018-08-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D50110#1187771, @aaronpuchert wrote:

> Thanks for the review! Could you commit for me again?


I can, but it might also be a good idea for you to obtain your own commit 
privileges at this point 
(https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access), if that's 
something you're interested in. Let me know which route you'd like to go.


Repository:
  rC Clang

https://reviews.llvm.org/D50110



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


[PATCH] D50218: [OpenMP] Encode offload target triples into comdat key for offload initialization code

2018-08-03 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev updated this revision to Diff 159058.

https://reviews.llvm.org/D50218

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  test/OpenMP/openmp_offload_registration.cpp


Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3818,7 +3818,17 @@
 CGF.disableDebugInfo();
 const auto  = CGM.getTypes().arrangeNullaryFunction();
 llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI);
-std::string Descriptor = getName({"omp_offloading", "descriptor_reg"});
+
+// Encode offload target triples into the registration function name. It
+// will serve as a comdat key for the registration/unregistration code for
+// this particular combination of offloading targets.
+SmallVector RegFnNameParts(Devices.size() + 2U);
+RegFnNameParts[0] = "omp_offloading";
+RegFnNameParts[1] = "descriptor_reg";
+for (size_t I = 0; I < Devices.size(); ++I)
+  RegFnNameParts[I + 2U] = Devices[I].getTriple();
+llvm::sort(RegFnNameParts.begin() + 2, RegFnNameParts.end());
+std::string Descriptor = getName(RegFnNameParts);
 RegFn = CGM.CreateGlobalInitOrDestructFunction(FTy, Descriptor, FI);
 CGF.StartFunction(GlobalDecl(), C.VoidTy, RegFn, FI, FunctionArgList());
 CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__tgt_register_lib), Desc);
Index: test/OpenMP/openmp_offload_registration.cpp
===
--- test/OpenMP/openmp_offload_registration.cpp
+++ test/OpenMP/openmp_offload_registration.cpp
@@ -0,0 +1,49 @@
+// Test for offload registration code for two targets
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-unknown-linux-gnu 
-fopenmp-targets=x86_64-pc-linux-gnu,powerpc64le-ibm-linux-gnu -emit-llvm %s -o 
- | FileCheck %s
+// expected-no-diagnostics
+
+void foo() {
+#pragma omp target
+  {}
+}
+
+// CHECK-DAG: [[ENTTY:%.+]] = type { i8*, i8*, i[[SZ:32|64]], i32, i32 }
+// CHECK-DAG: [[DEVTY:%.+]] = type { i8*, i8*, [[ENTTY]]*, [[ENTTY]]* }
+// CHECK-DAG: [[DSCTY:%.+]] = type { i32, [[DEVTY]]*, [[ENTTY]]*, [[ENTTY]]* }
+
+// Comdat key for the offload registration code. Should have sorted offload
+// target triples encoded into the name.
+// CHECK-DAG: 
$[[REGFN:\.omp_offloading\..+\.powerpc64le-ibm-linux-gnu\.x86_64-pc-linux-gnu+]]
 = comdat any
+
+// Check if offloading descriptor is created.
+// CHECK: [[ENTBEGIN:@.+]] = external constant [[ENTTY]]
+// CHECK: [[ENTEND:@.+]] = external constant [[ENTTY]]
+// CHECK: [[DEV1BEGIN:@.+]] = extern_weak constant i8
+// CHECK: [[DEV1END:@.+]] = extern_weak constant i8
+// CHECK: [[DEV2BEGIN:@.+]] = extern_weak constant i8
+// CHECK: [[DEV2END:@.+]] = extern_weak constant i8
+// CHECK: [[IMAGES:@.+]] = internal unnamed_addr constant [2 x [[DEVTY]]] 
[{{.+}} { i8* [[DEV1BEGIN]], i8* [[DEV1END]], [[ENTTY]]* [[ENTBEGIN]], 
[[ENTTY]]* [[ENTEND]] }, {{.+}} { i8* [[DEV2BEGIN]], i8* [[DEV2END]], 
[[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }], comdat($[[REGFN]])
+// CHECK: [[DESC:@.+]] = internal constant [[DSCTY]] { i32 2, [[DEVTY]]* 
getelementptr inbounds ([2 x [[DEVTY]]], [2 x [[DEVTY]]]* [[IMAGES]], i32 0, 
i32 0), [[ENTTY]]* [[ENTBEGIN]], [[ENTTY]]* [[ENTEND]] }, comdat($[[REGFN]])
+
+// Check target registration is registered as a Ctor.
+// CHECK: appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* 
} { i32 0, void ()* @[[REGFN]], i8* bitcast (void ()* @[[REGFN]] to i8*) }]
+
+// Check presence of foo() and the outlined target region
+// CHECK: define void [[FOO:@.+]]()
+// CHECK: define internal void [[OUTLINEDTARGET:@.+]]() 
+
+// Check registration and unregistration code.
+
+// CHECK: define internal void @[[UNREGFN:.+]](i8*)
+// CHECK-SAME: comdat($[[REGFN]]) {
+// CHECK: call i32 @__tgt_unregister_lib([[DSCTY]]* [[DESC]])
+// CHECK: ret void
+// CHECK: declare i32 @__tgt_unregister_lib([[DSCTY]]*)
+
+// CHECK: define linkonce hidden void @[[REGFN]]()
+// CHECK-SAME: comdat {
+// CHECK: call i32 @__tgt_register_lib([[DSCTY]]* [[DESC]])
+// CHECK: call i32 @__cxa_atexit(void (i8*)* @[[UNREGFN]], i8* bitcast 
([[DSCTY]]* [[DESC]] to i8*),
+// CHECK: ret void
+// CHECK: declare i32 @__tgt_register_lib([[DSCTY]]*)
+


Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -3818,7 +3818,17 @@
 CGF.disableDebugInfo();
 const auto  = CGM.getTypes().arrangeNullaryFunction();
 llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI);
-std::string Descriptor = getName({"omp_offloading", "descriptor_reg"});
+
+// Encode offload target triples into the registration function name. It
+// will serve as a comdat key for the registration/unregistration code for
+// this particular combination of offloading targets.
+SmallVector 

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

2018-08-03 Thread via cfe-commits
Looks like I missed that the inferred types for the returned tuple 
elements are references; I will rebuild with ASan and

confirm my fix is correct, then commit again.

Thanks,
Scott

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

This change is causing ASan failures on the sanitizer bots:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/21898/steps/check-clang%20asan/logs/stdio
[9]

I've reverted it in r338904.

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


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

URL: http://llvm.org/viewvc/llvm-project?rev=338899=rev [1]
Log:
[OpenCL] Always emit alloca in entry block for enqueue_kernel
builtin

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

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

Added:
cfe/trunk/test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
[3]
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl [4]

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


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

[5]


==

--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Aug 3 08:50:52 2018
@@ -3338,23 +3338,29 @@ RValue CodeGenFunction::EmitBuiltinExpr(
// Create a temporary array to hold the sizes of local pointer
arguments
// for the block. \p First is the position of the first size
argument.
auto CreateArrayForSizeVar = [=](unsigned First) {
- auto *AT = llvm::ArrayType::get(SizeTy, NumArgs - First);
- auto *Arr = Builder.CreateAlloca(AT);
- llvm::Value *Ptr;
+ llvm::APInt ArraySize(32, NumArgs - First);
+ QualType SizeArrayTy = getContext().getConstantArrayType(
+ getContext().getSizeType(), ArraySize, ArrayType::Normal,
+ /*IndexTypeQuals=*/0);
+ auto Tmp = CreateMemTemp(SizeArrayTy, "block_sizes");
+ llvm::Value *TmpPtr = Tmp.getPointer();
+ llvm::Value *TmpSize = EmitLifetimeStart(
+
CGM.getDataLayout().getTypeAllocSize(Tmp.getElementType()), TmpPtr);
+ llvm::Value *ElemPtr;
// Each of the following arguments specifies the size of the
corresponding
// argument passed to the enqueued block.
auto *Zero = llvm::ConstantInt::get(IntTy, 0);
for (unsigned I = First; I < NumArgs; ++I) {
auto *Index = llvm::ConstantInt::get(IntTy, I - First);
- auto *GEP = Builder.CreateGEP(Arr, {Zero, Index});
+ auto *GEP = Builder.CreateGEP(TmpPtr, {Zero, Index});
if (I == First)
- Ptr = GEP;
+ ElemPtr = GEP;
auto *V =
Builder.CreateZExtOrTrunc(EmitScalarExpr(E->getArg(I)),
SizeTy);
Builder.CreateAlignedStore(
V, GEP,
CGM.getDataLayout().getPrefTypeAlignment(SizeTy));
}
- return Ptr;
+ return std::tie(ElemPtr, TmpSize, TmpPtr);
};

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

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

llvm::FunctionType *FTy = llvm::FunctionType::get(
Int32Ty, llvm::ArrayRef(ArgTys), false);
- return RValue::get(
- Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name),
- llvm::ArrayRef(Args)));
+ auto Call =
+
RValue::get(Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name),
+ llvm::ArrayRef(Args)));
+ if (TmpSize)
+ EmitLifetimeEnd(TmpSize, TmpPtr);
+ return Call;
}
// Any calls now have event arguments passed.
if (NumArgs >= 7) {
@@ -3430,15 +3439,19 @@ RValue CodeGenFunction::EmitBuiltinExpr(
ArgTys.push_back(Int32Ty);
Name = "__enqueue_kernel_events_varargs";

- auto *PtrToSizeArray = CreateArrayForSizeVar(7);
- Args.push_back(PtrToSizeArray);
- ArgTys.push_back(PtrToSizeArray->getType());
+ llvm::Value *ElemPtr, *TmpSize, *TmpPtr;
+ std::tie(ElemPtr, TmpSize, TmpPtr) =
CreateArrayForSizeVar(7);
+ Args.push_back(ElemPtr);
+ ArgTys.push_back(ElemPtr->getType());

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

  1   2   3   >