[PATCH] D38939: [clangd] Handle exit notification (proper shutdown)

2017-10-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.

So I'm not totally convinced that treating an abrupt exit or EOF as an error is 
worth the hassle (others might disagree), but it's certainly reasonable.
Could you add a test for the new behavior?
something like

RUN: not clangd -run-synchronously < %s


RUN: not clangd -run-synchronously < %s



https://reviews.llvm.org/D38939



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


r315982 - [Coverage] Discard deferred region in closing if-else

2017-10-17 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Tue Oct 17 00:47:39 2017
New Revision: 315982

URL: http://llvm.org/viewvc/llvm-project?rev=315982&view=rev
Log:
[Coverage] Discard deferred region in closing if-else

A trailing deferred region isn't necessary in a function that ends with
this pattern:

  ...
  else {
...
return;
  }

Special-case this pattern so that the closing curly brace of the
function isn't marked as uncovered. This issue came up in PR34962.

Modified:
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
cfe/trunk/test/CoverageMapping/deferred-region.cpp

Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=315982&r1=315981&r2=315982&view=diff
==
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Tue Oct 17 00:47:39 2017
@@ -758,6 +758,22 @@ struct CounterCoverageMappingBuilder
 handleFileExit(getEnd(S));
   }
 
+  /// Determine whether the final deferred region emitted in \p Body should be
+  /// discarded.
+  static bool discardFinalDeferredRegionInDecl(Stmt *Body) {
+if (auto *CS = dyn_cast(Body)) {
+  Stmt *LastStmt = CS->body_back();
+  if (auto *IfElse = dyn_cast(LastStmt)) {
+if (auto *Else = dyn_cast_or_null(IfElse->getElse()))
+  LastStmt = Else->body_back();
+else
+  LastStmt = IfElse->getElse();
+  }
+  return dyn_cast_or_null(LastStmt);
+}
+return false;
+  }
+
   void VisitDecl(const Decl *D) {
 assert(!DeferredRegion && "Deferred region never completed");
 
@@ -770,14 +786,14 @@ struct CounterCoverageMappingBuilder
 Counter ExitCount = propagateCounts(getRegionCounter(Body), Body);
 assert(RegionStack.empty() && "Regions entered but never exited");
 
-// Special case: if the last statement is a return, throw away the
-// deferred region. This allows the closing brace to have a count.
-if (auto *CS = dyn_cast_or_null(Body))
-  if (dyn_cast_or_null(CS->body_back()))
+if (DeferredRegion) {
+  // Complete (or discard) any deferred regions introduced by the last
+  // statement.
+  if (discardFinalDeferredRegionInDecl(Body))
 DeferredRegion = None;
-
-// Complete any deferred regions introduced by the last statement.
-popRegions(completeDeferred(ExitCount, getEnd(Body)));
+  else
+popRegions(completeDeferred(ExitCount, getEnd(Body)));
+}
   }
 
   void VisitReturnStmt(const ReturnStmt *S) {

Modified: cfe/trunk/test/CoverageMapping/deferred-region.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/deferred-region.cpp?rev=315982&r1=315981&r2=315982&view=diff
==
--- cfe/trunk/test/CoverageMapping/deferred-region.cpp (original)
+++ cfe/trunk/test/CoverageMapping/deferred-region.cpp Tue Oct 17 00:47:39 2017
@@ -31,11 +31,28 @@ void baz() { // CHECK: [[@LINE]]:12 -> [
 // CHECK-LABEL: _Z3mazv:
 void maz() {
   if (true)
-return; // CHECK: Gap,File 0, [[@LINE]]:11 -> 36:3 = (#0 - #1)
+return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
 
   return; // CHECK-NOT: Gap
 }
 
+// CHECK-LABEL: _Z4maazv:
+void maaz() {
+  if (true)
+return; // CHECK: Gap,File 0, [[@LINE]]:11
+  else
+return; // CHECK-NOT: Gap,File 0, [[@LINE]]
+}
+
+// CHECK-LABEL: _Z5maaazv:
+void maaaz() {
+  if (true) {
+return;
+  } else {  // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE]]:10
+return; // CHECK-NOT: Gap,File 0, [[@LINE]]
+  }
+}
+
 // CHECK-LABEL: _Z3bari:
 void bar(int x) {
   IF (x)
@@ -158,6 +175,9 @@ int main() {
   foo(1);
   fooo(0);
   fooo(1);
+  maz();
+  maaz();
+  maaaz();
   baz();
   bar(0);
   bar(1);


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


[PATCH] D38989: [clang-rename] Rename enum.

2017-10-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
Herald added subscribers: mgorny, klimek.

- Add unit tests for renaming enum.
- Support unscoped enum constants in expressions.


https://reviews.llvm.org/D38989

Files:
  lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
  unittests/Rename/CMakeLists.txt
  unittests/Rename/RenameEnumTest.cpp

Index: unittests/Rename/RenameEnumTest.cpp
===
--- /dev/null
+++ unittests/Rename/RenameEnumTest.cpp
@@ -0,0 +1,185 @@
+#include "ClangRenameTest.h"
+
+namespace clang {
+namespace clang_rename {
+namespace test {
+namespace {
+
+class RenameEnumTest : public ClangRenameTest {
+public:
+  RenameEnumTest() {
+AppendToHeader(R"(
+#define MACRO(x) x
+namespace a {
+enum A1 { Red };
+enum class A2 { Blue };
+struct C {
+ enum NestedEnum { White };
+ enum class NestedScopedEnum { Black };
+};
+namespace d {
+enum A3 { Orange };
+} // namespace d
+enum A4 { Pink };
+} // namespace a
+enum A5 { Green };)");
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(
+RenameEnumTests, RenameEnumTest,
+testing::ValuesIn(std::vector({
+{"void f(a::A2 arg) { a::A2 t = a::A2::Blue; }",
+ "void f(b::B2 arg) { b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"},
+{"void f() { a::A1* t1; }", "void f() { b::B1* t1; }", "a::A1",
+ "b::B1"},
+{"void f() { a::A2* t1; }", "void f() { b::B2* t1; }", "a::A2",
+ "b::B2"},
+{"void f() { enum a::A2 t = a::A2::Blue; }",
+ "void f() { enum b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"},
+{"void f() { enum a::A2 t = a::A2::Blue; }",
+ "void f() { enum b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"},
+
+{"void f() { a::A1 t = a::Red; }", "void f() { b::B1 t = b::B1::Red; }",
+ "a::A1", "b::B1"},
+{"void f() { a::A1 t = a::A1::Red; }",
+ "void f() { b::B1 t = b::B1::Red; }", "a::A1", "b::B1"},
+{"void f() { auto t = a::Red; }", "void f() { auto t = b::B1::Red; }",
+ "a::A1", "b::B1"},
+{"namespace b { void f() { a::A1 t = a::Red; } }",
+ "namespace b { void f() { B1 t = B1::Red; } }", "a::A1", "b::B1"},
+{"void f() { a::d::A3 t = a::d::Orange; }",
+ "void f() { a::b::B3 t = a::b::B3::Orange; }", "a::d::A3", "a::b::B3"},
+{"namespace a { void f() { a::d::A3 t = a::d::Orange; } }",
+ "namespace a { void f() { b::B3 t = b::B3::Orange; } }", "a::d::A3",
+ "a::b::B3"},
+{"void f() { A5 t = Green; }", "void f() { B5 t = Green; }", "A5",
+ "B5"},
+
+// namespace qualifiers
+{"namespace a { void f(A1 a1) {} }",
+ "namespace a { void f(b::B1 a1) {} }", "a::A1", "b::B1"},
+{"namespace a { void f(A2 a2) {} }",
+ "namespace a { void f(b::B2 a2) {} }", "a::A2", "b::B2"},
+{"namespace b { void f(a::A1 a1) {} }",
+ "namespace b { void f(B1 a1) {} }", "a::A1", "b::B1"},
+{"namespace b { void f(a::A2 a2) {} }",
+ "namespace b { void f(B2 a2) {} }", "a::A2", "b::B2"},
+
+// nested enums
+{"void f() { a::C::NestedEnum t = a::C::White; }",
+ "void f() { a::C::NewNestedEnum t = a::C::NewNestedEnum::White; }",
+ "a::C::NestedEnum", "a::C::NewNestedEnum"},
+{"void f() { a::C::NestedScopedEnum t = a::C::NestedScopedEnum::Black; "
+ "}",
+ "void f() { a::C::NewNestedScopedEnum t = "
+ "a::C::NewNestedScopedEnum::Black; }",
+ "a::C::NestedScopedEnum", "a::C::NewNestedScopedEnum"},
+
+// macros
+{"void f(MACRO(a::A1) a1) {}", "void f(MACRO(b::B1) a1) {}", "a::A1",
+ "b::B1"},
+{"void f(MACRO(a::A2) a2) {}", "void f(MACRO(b::B2) a2) {}", "a::A2",
+ "b::B2"},
+{"#define FOO(T, t) T t\nvoid f() { FOO(a::A1, a1); }",
+ "#define FOO(T, t) T t\nvoid f() { FOO(b::B1, a1); }", "a::A1",
+ "b::B1"},
+{"#define FOO(T, t) T t\nvoid f() { FOO(a::A2, a2); }",
+ "#define FOO(T, t) T t\nvoid f() { FOO(b::B2, a2); }", "a::A2",
+ "b::B2"},
+{"#define FOO(n) a::A1 n\nvoid f() { FOO(a1); FOO(a2); }",
+ "#define FOO(n) b::B1 n\nvoid f() { FOO(a1); FOO(a2); }", "a::A1",
+ "b::B1"},
+
+// using and type alias
+{"using a::A1; A1 gA;", "using b::B1; b::B1 gA;", "a::A1", "b::B1"},
+{"using a::A2; A2 gA;", "using b::B2; b::B2 gA;", "a::A2", "b::B2"},
+{"struct S { using T = a::A1; T a_; };",
+ "struct S { using T = b::B1; T a_; };", "a::A1", "b::B1"},
+{"using T = a::A1; T gA;", "using T = b::B1; T gA;", "a::A1", "b::B1"},
+{"using T = a::A2; T gA;", "using T = b::B2; T gA;", "a::A2", "b::B2"},
+{"typedef a::A1 T; T gA;", "typedef b::B1 T; T gA;", "a::A1", "b::B1"},
+{"typedef a::A2 T; T gA;", "typedef b::B2 T; T gA;", "a::A2", "b::B2"},
+{"type

[PATCH] D38989: [clang-rename] Rename enum.

2017-10-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:212
+  // Ignore the case where there is no prefix qualifer for the enum 
constant
+  // expression like `a = Green`.
+  if (!Expr->hasQualifier())

Why do we ignore this case? What if `Color` is moved to a different namespace? 
We would also need to qualify `Green` with a new namespace.



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:218
+  llvm::dyn_cast_or_null(getClosestAncestorDecl(*T))) {
+if (ED->isScoped()) {
+  return true;

nit: no braces



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:228
+  // enum constant `Green` should be excluded).
+  //ns1::ns2::Green;
+  //^  ^  ^

I'm wondering why the old `EndLoc` points to `G` instead of `n` in `Green`.


https://reviews.llvm.org/D38989



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


[PATCH] D38599: Remove warnings for dynamic_cast fallback.

2017-10-17 Thread Ryan Prichard via Phabricator via cfe-commits
rprichard added a comment.

In https://reviews.llvm.org/D38599#899198, @danalbert wrote:

> In https://reviews.llvm.org/D38599#899196, @howard.hinnant wrote:
>
> > Fwiw, I wrote this code.  All of that "fallback" stuff was written to make 
> > customer code that was incorrect, but working on OS X 
> > -version-that-used-libsupc++ continue to work.  I.e. to be a crutch for 
> > incorrect code.  It should all be removed if you no longer want to provide 
> > such a crutch.
>
>
> Android may end up wanting to use it for the same reason. I've backed it out 
> for now, but it may end up being something we need since a fair number of NDK 
> users (majority, probably) use libsupc++ and that might be a point of pain in 
> migrating to libc++abi. Other Linux distros may want it as well, so probably 
> worth leaving the code around.


On OS X, dynamic vague linkage appears to work by default, and 
_LIBCXX_DYNAMIC_FALLBACK catches some code that slips through the cracks (e.g. 
code that does something odd like: specify visibility attributes, explicitly 
specify RTLD_LOCAL, link with -Bsymbolic, etc.). dlopen defaults to 
RTLD_GLOBAL, which merges weak definitions, even with an executable. 
System.loadLibrary uses RTLD_GLOBAL.

On Android, AFAICT, dynamic vague linkage doesn't work prior to M, and with M, 
it only works between shared objects loaded in one batch. Loading multiple C++ 
shared objects one-at-a-time generally results in duplicated type_info objects, 
which break the various RTTI-dependent features when libc++/libc++abi are used.

_LIBCXX_DYNAMIC_FALLBACK doesn't generally fix __dynamic_cast to account for 
duplicated type_info objects. Instead, it flags a specific situation that's 
easy to detect. If we have code like this...

  Static *s = new Derived;
  dynamic_cast(s)

... __dynamic_cast will search the RTTI graph of `Derived` looking for `Static` 
and `Dest`. It expects to find at least one instance of `Static`. If it 
doesn't, there's obviously something wrong, because, assuming the C++ ABI has 
been followed, the `s` pointer is not really of type `Static`! This situation 
is cheap to detect (a couple extra comparisons). If `Static` //is// found, the 
fallback doesn't activate, but dynamic_cast can still fail, e.g.:

- If a `Dest` in the RTTI graph doesn't match `&typeid(Dest)` where 
dynamic_cast is used, then dynamic_cast can incorrectly return NULL.
- If there are two `Dest` objects in the RTTI graph with unequal addresses, 
then dynamic_cast can incorrectly return non-NULL when the cast should have 
been ambiguous. (Writing this test case is a fun little exercise.)
- Multiple `Static` objects with unequal addresses probably causes similar 
failures, as long as one of them matches `&typeid(Static)` where dynamic_cast 
is used.

I think _LIBCXX_DYNAMIC_FALLBACK is fine to enable on Android, but (1) it seems 
insufficient, (2) I'm skeptical about removing the diagnostic, and (3) a 
general solution to the libc++abi RTTI problem tends to make 
_LIBCXX_DYNAMIC_FALLBACK irrelevant. i.e. We may need to simply compare 
typeinfo strings like gnustl does (or the `#ifdef _WIN32` code for 
dynamic_cast), which subsumes _LIBCXX_DYNAMIC_FALLBACK.

I'm still intrigued by the `shouldRTTIBeUnique` / `_LIBCPP_NONUNIQUE_RTTI_BIT` 
stuff I linked above. I'm a little surprised that 64-bit iOS would need that 
behavior. Maybe we need to turn it on for Android, but where is the 
corresponding flag for libcxxabi?


https://reviews.llvm.org/D38599



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


r315984 - [CodeGen] EmitPointerWithAlignment() to generate TBAA info along with LValue base info

2017-10-17 Thread Ivan A. Kosarev via cfe-commits
Author: kosarev
Date: Tue Oct 17 02:12:13 2017
New Revision: 315984

URL: http://llvm.org/viewvc/llvm-project?rev=315984&view=rev
Log:
[CodeGen] EmitPointerWithAlignment() to generate TBAA info along with LValue 
base info

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

Added:
cfe/trunk/test/CodeGen/tbaa-cast.cpp
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
cfe/trunk/lib/CodeGen/CodeGenTBAA.h

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=315984&r1=315983&r2=315984&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Oct 17 02:12:13 2017
@@ -916,7 +916,8 @@ void CodeGenModule::EmitExplicitCastExpr
 /// EmitPointerWithAlignment - Given an expression of pointer type, try to
 /// derive a more accurate bound on the alignment of the pointer.
 Address CodeGenFunction::EmitPointerWithAlignment(const Expr *E,
-  LValueBaseInfo *BaseInfo) {
+  LValueBaseInfo *BaseInfo,
+  TBAAAccessInfo *TBAAInfo) {
   // We allow this with ObjC object pointers because of fragile ABIs.
   assert(E->getType()->isPointerType() ||
  E->getType()->isObjCObjectPointerType());
@@ -936,20 +937,30 @@ Address CodeGenFunction::EmitPointerWith
 if (PtrTy->getPointeeType()->isVoidType())
   break;
 
-LValueBaseInfo InnerInfo;
-Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), &InnerInfo);
-if (BaseInfo) *BaseInfo = InnerInfo;
-
-// If this is an explicit bitcast, and the source l-value is
-// opaque, honor the alignment of the casted-to type.
-if (isa(CE) &&
-InnerInfo.getAlignmentSource() != AlignmentSource::Decl) {
-  LValueBaseInfo ExpInfo;
+LValueBaseInfo InnerBaseInfo;
+TBAAAccessInfo InnerTBAAInfo;
+Address Addr = EmitPointerWithAlignment(CE->getSubExpr(),
+&InnerBaseInfo,
+&InnerTBAAInfo);
+if (BaseInfo) *BaseInfo = InnerBaseInfo;
+if (TBAAInfo) *TBAAInfo = InnerTBAAInfo;
+
+if (isa(CE)) {
+  LValueBaseInfo TargetTypeBaseInfo;
+  TBAAAccessInfo TargetTypeTBAAInfo;
   CharUnits Align = getNaturalPointeeTypeAlignment(E->getType(),
-   &ExpInfo);
-  if (BaseInfo)
-BaseInfo->mergeForCast(ExpInfo);
-  Addr = Address(Addr.getPointer(), Align);
+   &TargetTypeBaseInfo,
+   
&TargetTypeTBAAInfo);
+  if (TBAAInfo)
+*TBAAInfo = CGM.mergeTBAAInfoForCast(*TBAAInfo,
+ TargetTypeTBAAInfo);
+  // If the source l-value is opaque, honor the alignment of the
+  // casted-to type.
+  if (InnerBaseInfo.getAlignmentSource() != AlignmentSource::Decl) {
+if (BaseInfo)
+  BaseInfo->mergeForCast(TargetTypeBaseInfo);
+Addr = Address(Addr.getPointer(), Align);
+  }
 }
 
 if (SanOpts.has(SanitizerKind::CFIUnrelatedCast) &&
@@ -969,12 +980,13 @@ Address CodeGenFunction::EmitPointerWith
 
 // Array-to-pointer decay.
 case CK_ArrayToPointerDecay:
-  return EmitArrayToPointerDecay(CE->getSubExpr(), BaseInfo);
+  return EmitArrayToPointerDecay(CE->getSubExpr(), BaseInfo, TBAAInfo);
 
 // Derived-to-base conversions.
 case CK_UncheckedDerivedToBase:
 case CK_DerivedToBase: {
-  Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), BaseInfo);
+  Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), BaseInfo,
+  TBAAInfo);
   auto Derived = CE->getSubExpr()->getType()->getPointeeCXXRecordDecl();
   return GetAddressOfBaseClass(Addr, Derived,
CE->path_begin(), CE->path_end(),
@@ -994,6 +1006,7 @@ Address CodeGenFunction::EmitPointerWith
 if (UO->getOpcode() == UO_AddrOf) {
   LValue LV = EmitLValue(UO->getSubExpr());
   if (BaseInfo) *BaseInfo = LV.getBaseInfo();
+  if (TBAAInfo) *TBAAInfo = LV.getTBAAInfo();
   return LV.getAddress();
 }
   }
@@ -1001,7 +1014,8 @@ Address CodeGenFunction::EmitPointerWith
   // TODO: conditional operators, comma.
 
   // Otherwise, use the alignment of the type.
-  CharUnits Align = getNaturalPointeeTypeAlignme

[PATCH] D38796: [CodeGen] EmitPointerWithAlignment() to generate TBAA info along with LValue base info

2017-10-17 Thread Ivan Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL315984: [CodeGen] EmitPointerWithAlignment() to generate 
TBAA info along with LValue… (authored by kosarev).

Changed prior to commit:
  https://reviews.llvm.org/D38796?vs=119089&id=119272#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38796

Files:
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.h
  cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
  cfe/trunk/lib/CodeGen/CodeGenTBAA.h
  cfe/trunk/test/CodeGen/tbaa-cast.cpp

Index: cfe/trunk/test/CodeGen/tbaa-cast.cpp
===
--- cfe/trunk/test/CodeGen/tbaa-cast.cpp
+++ cfe/trunk/test/CodeGen/tbaa-cast.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \
+// RUN: -emit-llvm -o - | FileCheck %s
+//
+// Check that we generate correct TBAA information for lvalues constructed
+// with use of casts.
+
+struct V {
+  unsigned n;
+};
+
+struct S {
+  char bytes[4];
+};
+
+void foo(S *p) {
+// CHECK-LABEL: _Z3fooP1S
+// CHECK: store i32 5, {{.*}}, !tbaa [[TAG_V_n:!.*]]
+  ((V*)p->bytes)->n = 5;
+}
+
+// CHECK-DAG: [[TAG_V_n]] = !{[[TYPE_V:!.*]], [[TYPE_int:!.*]], i64 0}
+// CHECK-DAG: [[TYPE_V]] = !{!"_ZTS1V", !{{.*}}, i64 0}
+// CHECK-DAG: [[TYPE_int]] = !{!"int", !{{.*}}, i64 0}
Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -916,7 +916,8 @@
 /// EmitPointerWithAlignment - Given an expression of pointer type, try to
 /// derive a more accurate bound on the alignment of the pointer.
 Address CodeGenFunction::EmitPointerWithAlignment(const Expr *E,
-  LValueBaseInfo *BaseInfo) {
+  LValueBaseInfo *BaseInfo,
+  TBAAAccessInfo *TBAAInfo) {
   // We allow this with ObjC object pointers because of fragile ABIs.
   assert(E->getType()->isPointerType() ||
  E->getType()->isObjCObjectPointerType());
@@ -936,20 +937,30 @@
 if (PtrTy->getPointeeType()->isVoidType())
   break;
 
-LValueBaseInfo InnerInfo;
-Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), &InnerInfo);
-if (BaseInfo) *BaseInfo = InnerInfo;
-
-// If this is an explicit bitcast, and the source l-value is
-// opaque, honor the alignment of the casted-to type.
-if (isa(CE) &&
-InnerInfo.getAlignmentSource() != AlignmentSource::Decl) {
-  LValueBaseInfo ExpInfo;
+LValueBaseInfo InnerBaseInfo;
+TBAAAccessInfo InnerTBAAInfo;
+Address Addr = EmitPointerWithAlignment(CE->getSubExpr(),
+&InnerBaseInfo,
+&InnerTBAAInfo);
+if (BaseInfo) *BaseInfo = InnerBaseInfo;
+if (TBAAInfo) *TBAAInfo = InnerTBAAInfo;
+
+if (isa(CE)) {
+  LValueBaseInfo TargetTypeBaseInfo;
+  TBAAAccessInfo TargetTypeTBAAInfo;
   CharUnits Align = getNaturalPointeeTypeAlignment(E->getType(),
-   &ExpInfo);
-  if (BaseInfo)
-BaseInfo->mergeForCast(ExpInfo);
-  Addr = Address(Addr.getPointer(), Align);
+   &TargetTypeBaseInfo,
+   &TargetTypeTBAAInfo);
+  if (TBAAInfo)
+*TBAAInfo = CGM.mergeTBAAInfoForCast(*TBAAInfo,
+ TargetTypeTBAAInfo);
+  // If the source l-value is opaque, honor the alignment of the
+  // casted-to type.
+  if (InnerBaseInfo.getAlignmentSource() != AlignmentSource::Decl) {
+if (BaseInfo)
+  BaseInfo->mergeForCast(TargetTypeBaseInfo);
+Addr = Address(Addr.getPointer(), Align);
+  }
 }
 
 if (SanOpts.has(SanitizerKind::CFIUnrelatedCast) &&
@@ -969,12 +980,13 @@
 
 // Array-to-pointer decay.
 case CK_ArrayToPointerDecay:
-  return EmitArrayToPointerDecay(CE->getSubExpr(), BaseInfo);
+  return EmitArrayToPointerDecay(CE->getSubExpr(), BaseInfo, TBAAInfo);
 
 // Derived-to-base conversions.
 case CK_UncheckedDerivedToBase:
 case CK_DerivedToBase: {
-  Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), BaseInfo);
+  Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), BaseInfo,
+  TBAAInfo);
   auto Derived = CE->getSubExpr()->getType()->getPointeeCXXRecordDecl();
   return GetAddressOfBaseClass(Addr, Derived,

[PATCH] D38989: [clang-rename] Rename enum.

2017-10-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 119274.
hokein marked 2 inline comments as done.
hokein added a comment.

address review comments, and add FIXME


https://reviews.llvm.org/D38989

Files:
  lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
  unittests/Rename/CMakeLists.txt
  unittests/Rename/RenameEnumTest.cpp

Index: unittests/Rename/RenameEnumTest.cpp
===
--- /dev/null
+++ unittests/Rename/RenameEnumTest.cpp
@@ -0,0 +1,189 @@
+#include "ClangRenameTest.h"
+
+namespace clang {
+namespace clang_rename {
+namespace test {
+namespace {
+
+class RenameEnumTest : public ClangRenameTest {
+public:
+  RenameEnumTest() {
+AppendToHeader(R"(
+#define MACRO(x) x
+namespace a {
+enum A1 { Red };
+enum class A2 { Blue };
+struct C {
+ enum NestedEnum { White };
+ enum class NestedScopedEnum { Black };
+};
+namespace d {
+enum A3 { Orange };
+} // namespace d
+enum A4 { Pink };
+} // namespace a
+enum A5 { Green };)");
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(
+RenameEnumTests, RenameEnumTest,
+testing::ValuesIn(std::vector({
+{"void f(a::A2 arg) { a::A2 t = a::A2::Blue; }",
+ "void f(b::B2 arg) { b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"},
+{"void f() { a::A1* t1; }", "void f() { b::B1* t1; }", "a::A1",
+ "b::B1"},
+{"void f() { a::A2* t1; }", "void f() { b::B2* t1; }", "a::A2",
+ "b::B2"},
+{"void f() { enum a::A2 t = a::A2::Blue; }",
+ "void f() { enum b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"},
+{"void f() { enum a::A2 t = a::A2::Blue; }",
+ "void f() { enum b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"},
+
+{"void f() { a::A1 t = a::Red; }", "void f() { b::B1 t = b::B1::Red; }",
+ "a::A1", "b::B1"},
+{"void f() { a::A1 t = a::A1::Red; }",
+ "void f() { b::B1 t = b::B1::Red; }", "a::A1", "b::B1"},
+{"void f() { auto t = a::Red; }", "void f() { auto t = b::B1::Red; }",
+ "a::A1", "b::B1"},
+{"namespace b { void f() { a::A1 t = a::Red; } }",
+ "namespace b { void f() { B1 t = B1::Red; } }", "a::A1", "b::B1"},
+{"void f() { a::d::A3 t = a::d::Orange; }",
+ "void f() { a::b::B3 t = a::b::B3::Orange; }", "a::d::A3", "a::b::B3"},
+{"namespace a { void f() { a::d::A3 t = a::d::Orange; } }",
+ "namespace a { void f() { b::B3 t = b::B3::Orange; } }", "a::d::A3",
+ "a::b::B3"},
+{"void f() { A5 t = Green; }", "void f() { B5 t = Green; }", "A5",
+ "B5"},
+// FIXME: the new namespace qualifier should be added to the unscoped
+// enum constant.
+{"namespace a { void f() { auto t = Green; } }",
+ "namespace a { void f() { auto t = Green; } }", "a::A1", "b::B1"},
+
+// namespace qualifiers
+{"namespace a { void f(A1 a1) {} }",
+ "namespace a { void f(b::B1 a1) {} }", "a::A1", "b::B1"},
+{"namespace a { void f(A2 a2) {} }",
+ "namespace a { void f(b::B2 a2) {} }", "a::A2", "b::B2"},
+{"namespace b { void f(a::A1 a1) {} }",
+ "namespace b { void f(B1 a1) {} }", "a::A1", "b::B1"},
+{"namespace b { void f(a::A2 a2) {} }",
+ "namespace b { void f(B2 a2) {} }", "a::A2", "b::B2"},
+
+// nested enums
+{"void f() { a::C::NestedEnum t = a::C::White; }",
+ "void f() { a::C::NewNestedEnum t = a::C::NewNestedEnum::White; }",
+ "a::C::NestedEnum", "a::C::NewNestedEnum"},
+{"void f() { a::C::NestedScopedEnum t = a::C::NestedScopedEnum::Black; "
+ "}",
+ "void f() { a::C::NewNestedScopedEnum t = "
+ "a::C::NewNestedScopedEnum::Black; }",
+ "a::C::NestedScopedEnum", "a::C::NewNestedScopedEnum"},
+
+// macros
+{"void f(MACRO(a::A1) a1) {}", "void f(MACRO(b::B1) a1) {}", "a::A1",
+ "b::B1"},
+{"void f(MACRO(a::A2) a2) {}", "void f(MACRO(b::B2) a2) {}", "a::A2",
+ "b::B2"},
+{"#define FOO(T, t) T t\nvoid f() { FOO(a::A1, a1); }",
+ "#define FOO(T, t) T t\nvoid f() { FOO(b::B1, a1); }", "a::A1",
+ "b::B1"},
+{"#define FOO(T, t) T t\nvoid f() { FOO(a::A2, a2); }",
+ "#define FOO(T, t) T t\nvoid f() { FOO(b::B2, a2); }", "a::A2",
+ "b::B2"},
+{"#define FOO(n) a::A1 n\nvoid f() { FOO(a1); FOO(a2); }",
+ "#define FOO(n) b::B1 n\nvoid f() { FOO(a1); FOO(a2); }", "a::A1",
+ "b::B1"},
+
+// using and type alias
+{"using a::A1; A1 gA;", "using b::B1; b::B1 gA;", "a::A1", "b::B1"},
+{"using a::A2; A2 gA;", "using b::B2; b::B2 gA;", "a::A2", "b::B2"},
+{"struct S { using T = a::A1; T a_; };",
+ "struct S { using T = b::B1; T a_; };", "a::A1", "b::B1"},
+{"using T = a::A1; T gA;", "using T = b::B1; T gA;", "a::A1", "b::B1"},
+{"using T = a::A2

[PATCH] D38618: Do not add a colon chunk to the code completion of class inheritance access modifiers

2017-10-17 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 119273.
yvvan added a comment.

Rebased to update ScopeFlags.
Rereview please


https://reviews.llvm.org/D38618

Files:
  include/clang/Sema/Scope.h
  lib/Parse/ParseDeclCXX.cpp
  lib/Sema/SemaCodeComplete.cpp
  test/Index/complete-super.cpp


Index: test/Index/complete-super.cpp
===
--- test/Index/complete-super.cpp
+++ test/Index/complete-super.cpp
@@ -40,3 +40,8 @@
 // CHECK-ACCESS-PATTERN: NotImplemented:{TypedText private}{Colon :} (40)
 // CHECK-ACCESS-PATTERN: NotImplemented:{TypedText protected}{Colon :} (40)
 // CHECK-ACCESS-PATTERN: NotImplemented:{TypedText public}{Colon :} (40)
+
+// RUN: env CINDEXTEST_CODE_COMPLETE_PATTERNS=1 c-index-test 
-code-completion-at=%s:10:12 %s | FileCheck 
-check-prefix=CHECK-INHERITANCE-PATTERN %s
+// CHECK-INHERITANCE-PATTERN: NotImplemented:{TypedText private} (40)
+// CHECK-INHERITANCE-PATTERN: NotImplemented:{TypedText protected} (40)
+// CHECK-INHERITANCE-PATTERN: NotImplemented:{TypedText public} (40)
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -1658,21 +1658,22 @@
   if (CCC == Sema::PCC_Class) {
 AddTypedefResult(Results);
 
+bool IsNotInheritanceScope = !(S->getFlags() & 
Scope::ClassInheritanceScope);
 // public:
 Builder.AddTypedTextChunk("public");
-if (Results.includeCodePatterns())
+if (IsNotInheritanceScope && Results.includeCodePatterns())
   Builder.AddChunk(CodeCompletionString::CK_Colon);
 Results.AddResult(Result(Builder.TakeString()));
 
 // protected:
 Builder.AddTypedTextChunk("protected");
-if (Results.includeCodePatterns())
+if (IsNotInheritanceScope && Results.includeCodePatterns())
   Builder.AddChunk(CodeCompletionString::CK_Colon);
 Results.AddResult(Result(Builder.TakeString()));
 
 // private:
 Builder.AddTypedTextChunk("private");
-if (Results.includeCodePatterns())
+if (IsNotInheritanceScope && Results.includeCodePatterns())
   Builder.AddChunk(CodeCompletionString::CK_Colon);
 Results.AddResult(Result(Builder.TakeString()));
   }
Index: lib/Parse/ParseDeclCXX.cpp
===
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -3195,6 +3195,9 @@
   }
 
   if (Tok.is(tok::colon)) {
+ParseScope InheritanceScope(this, Scope::ClassScope | Scope::DeclScope |
+  Scope::ClassInheritanceScope);
+
 ParseBaseClause(TagDecl);
 if (!Tok.is(tok::l_brace)) {
   bool SuggestFixIt = false;
Index: include/clang/Sema/Scope.h
===
--- include/clang/Sema/Scope.h
+++ include/clang/Sema/Scope.h
@@ -127,6 +127,9 @@
 
 /// This is a compound statement scope.
 CompoundStmtScope = 0x40,
+
+/// We are between inheritance colon and the real class/struct definition 
scope
+ClassInheritanceScope = 0x80,
   };
 private:
   /// The parent scope for this scope.  This is null for the translation-unit


Index: test/Index/complete-super.cpp
===
--- test/Index/complete-super.cpp
+++ test/Index/complete-super.cpp
@@ -40,3 +40,8 @@
 // CHECK-ACCESS-PATTERN: NotImplemented:{TypedText private}{Colon :} (40)
 // CHECK-ACCESS-PATTERN: NotImplemented:{TypedText protected}{Colon :} (40)
 // CHECK-ACCESS-PATTERN: NotImplemented:{TypedText public}{Colon :} (40)
+
+// RUN: env CINDEXTEST_CODE_COMPLETE_PATTERNS=1 c-index-test -code-completion-at=%s:10:12 %s | FileCheck -check-prefix=CHECK-INHERITANCE-PATTERN %s
+// CHECK-INHERITANCE-PATTERN: NotImplemented:{TypedText private} (40)
+// CHECK-INHERITANCE-PATTERN: NotImplemented:{TypedText protected} (40)
+// CHECK-INHERITANCE-PATTERN: NotImplemented:{TypedText public} (40)
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -1658,21 +1658,22 @@
   if (CCC == Sema::PCC_Class) {
 AddTypedefResult(Results);
 
+bool IsNotInheritanceScope = !(S->getFlags() & Scope::ClassInheritanceScope);
 // public:
 Builder.AddTypedTextChunk("public");
-if (Results.includeCodePatterns())
+if (IsNotInheritanceScope && Results.includeCodePatterns())
   Builder.AddChunk(CodeCompletionString::CK_Colon);
 Results.AddResult(Result(Builder.TakeString()));
 
 // protected:
 Builder.AddTypedTextChunk("protected");
-if (Results.includeCodePatterns())
+if (IsNotInheritanceScope && Results.includeCodePatterns())
   Builder.AddChunk(CodeCompletionString::CK_Colon);

[PATCH] D38989: [clang-rename] Rename enum.

2017-10-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:212
+  // Ignore the case where there is no prefix qualifer for the enum 
constant
+  // expression like `a = Green`.
+  if (!Expr->hasQualifier())

ioeric wrote:
> Why do we ignore this case? What if `Color` is moved to a different 
> namespace? We would also need to qualify `Green` with a new namespace.
Thanks for pointing it out (we missed such test case before).

Yeah, this should be a FIXME, and added the case to the unittest.



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:228
+  // enum constant `Green` should be excluded).
+  //ns1::ns2::Green;
+  //^  ^  ^

ioeric wrote:
> I'm wondering why the old `EndLoc` points to `G` instead of `n` in `Green`.
This is the behavior of `Expr->getLocEnd()` or 
`Expr->getSourceRange().getEnd()`, which returns the start location of the last 
token.


https://reviews.llvm.org/D38989



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


[PATCH] D38985: [refactor] Add support for editor commands that connect IDEs/editors to the refactoring actions

2017-10-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

+sammccall who is currently working on clangD, he might have ideas on the 
clangD/refactor integration.


Repository:
  rL LLVM

https://reviews.llvm.org/D38985



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


[PATCH] D38985: [refactor] Add support for editor commands that connect IDEs/editors to the refactoring actions

2017-10-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: include/clang/Tooling/Refactoring/EditorCommandRegistry.def:5
+
+REFACTORING_EDITOR_COMMAND(ExtractFunction, "Extract Function")
+

Isn't `rename` also supported?



Comment at: include/clang/Tooling/Refactoring/EditorCommands.h:23
+/// Editor commands allow refactoring rules to be bound to commands that can
+/// be used from an editor that integrates with Clang's refactoring engine.
+///

Could you elaborate a bit on the editor/clangd integration? For example, if 
clangd wants to extract a function, how would clangd discover the rule to use 
and pass options into the engine? Would editor/clangd be responsible for 
applying the changes? 



Comment at: include/clang/Tooling/Refactoring/RefactoringActionRule.h:57
+
+  /// Returns the editor command that's was bound to this rule.
+  virtual const EditorCommand *getEditorCommand() { return nullptr; }

nit: s/that's was/that was/



Comment at: include/clang/Tooling/Refactoring/RefactoringActionRule.h:58
+  /// Returns the editor command that's was bound to this rule.
+  virtual const EditorCommand *getEditorCommand() { return nullptr; }
 };

I'm still not quite sure about the intention of `EditorCommand` (is it supposed 
to be used as a mapping from name to rule, or the other way around?), but I'm a 
bit concerned about mixing editor logic with the refactoring rules this way. 
Also to enable a editor command, it seems to me that we would need to touch 
both the registry and the rule creation code, which seems a bit cumbersome.

I think we should either 1) separate out the command logic cleanly without 
touching action/rule interfaces in the refactoring engine or 2) simply bake the 
logic into the refactoring engine.

It is unclear to me if 1) is possible, but for 2), I think we could introduce a 
`RefactoringEngine` class which carries all refactoring actions as well as a 
map to serve the purpose of `EditorCommand`. And I think by doing this, we 
could also make the interfaces of `RefactoringEngine` more explicit.


Repository:
  rL LLVM

https://reviews.llvm.org/D38985



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


r315986 - [CodeGen] Pass TBAA info along with lvalue base info everywhere

2017-10-17 Thread Ivan A. Kosarev via cfe-commits
Author: kosarev
Date: Tue Oct 17 03:17:43 2017
New Revision: 315986

URL: http://llvm.org/viewvc/llvm-project?rev=315986&view=rev
Log:
[CodeGen] Pass TBAA info along with lvalue base info everywhere

This patch addresses the rest of the cases where we pass lvalue
base info, but do not provide corresponding TBAA info.

This patch should not bring in any functional changes.

This is part of D38126 reworked to be a separate patch to make
reviewing easier.

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

Modified:
cfe/trunk/lib/CodeGen/CGAtomic.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
cfe/trunk/lib/CodeGen/CGValue.h
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=315986&r1=315985&r2=315986&view=diff
==
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Tue Oct 17 03:17:43 2017
@@ -96,9 +96,8 @@ namespace {
 BFI.StorageSize = AtomicSizeInBits;
 BFI.StorageOffset += OffsetInChars;
 LVal = LValue::MakeBitfield(Address(Addr, lvalue.getAlignment()),
-BFI, lvalue.getType(),
-lvalue.getBaseInfo());
-LVal.setTBAAInfo(lvalue.getTBAAInfo());
+BFI, lvalue.getType(), 
lvalue.getBaseInfo(),
+lvalue.getTBAAInfo());
 AtomicTy = C.getIntTypeForBitwidth(AtomicSizeInBits, OrigBFI.IsSigned);
 if (AtomicTy.isNull()) {
   llvm::APInt Size(
@@ -1346,15 +1345,15 @@ RValue AtomicInfo::convertAtomicTempToRV
   if (LVal.isBitField())
 return CGF.EmitLoadOfBitfieldLValue(
 LValue::MakeBitfield(addr, LVal.getBitFieldInfo(), LVal.getType(),
- LVal.getBaseInfo()), loc);
+ LVal.getBaseInfo(), TBAAAccessInfo()), loc);
   if (LVal.isVectorElt())
 return CGF.EmitLoadOfLValue(
 LValue::MakeVectorElt(addr, LVal.getVectorIdx(), LVal.getType(),
-  LVal.getBaseInfo()), loc);
+  LVal.getBaseInfo(), TBAAAccessInfo()), loc);
   assert(LVal.isExtVectorElt());
   return CGF.EmitLoadOfExtVectorElementLValue(LValue::MakeExtVectorElt(
   addr, LVal.getExtVectorElts(), LVal.getType(),
-  LVal.getBaseInfo()));
+  LVal.getBaseInfo(), TBAAAccessInfo()));
 }
 
 RValue AtomicInfo::ConvertIntToValueOrAtomic(llvm::Value *IntVal,
@@ -1670,29 +1669,30 @@ EmitAtomicUpdateValue(CodeGenFunction &C
   UpdateLVal =
   LValue::MakeBitfield(Ptr, AtomicLVal.getBitFieldInfo(),
AtomicLVal.getType(),
-   AtomicLVal.getBaseInfo());
+   AtomicLVal.getBaseInfo(),
+   AtomicLVal.getTBAAInfo());
   DesiredLVal =
   LValue::MakeBitfield(DesiredAddr, AtomicLVal.getBitFieldInfo(),
-   AtomicLVal.getType(),
-   AtomicLVal.getBaseInfo());
+   AtomicLVal.getType(), AtomicLVal.getBaseInfo(),
+   AtomicLVal.getTBAAInfo());
 } else if (AtomicLVal.isVectorElt()) {
   UpdateLVal = LValue::MakeVectorElt(Ptr, AtomicLVal.getVectorIdx(),
  AtomicLVal.getType(),
- AtomicLVal.getBaseInfo());
+ AtomicLVal.getBaseInfo(),
+ AtomicLVal.getTBAAInfo());
   DesiredLVal = LValue::MakeVectorElt(
   DesiredAddr, AtomicLVal.getVectorIdx(), AtomicLVal.getType(),
-  AtomicLVal.getBaseInfo());
+  AtomicLVal.getBaseInfo(), AtomicLVal.getTBAAInfo());
 } else {
   assert(AtomicLVal.isExtVectorElt());
   UpdateLVal = LValue::MakeExtVectorElt(Ptr, AtomicLVal.getExtVectorElts(),
 AtomicLVal.getType(),
-AtomicLVal.getBaseInfo());
+AtomicLVal.getBaseInfo(),
+AtomicLVal.getTBAAInfo());
   DesiredLVal = LValue::MakeExtVectorElt(
   DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
-  AtomicLVal.getBaseInfo());
+  AtomicLVal.getBaseInfo(), AtomicLVal.getTBAAInfo());
 }
-UpdateLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
-DesiredLVal.setTBAAInfo(AtomicLVal.getTBAAInfo());
 UpRVal = CGF.EmitLoadOfLValue(UpdateLVal, SourceLocation());
   }
   // Store new value in the corresponding memory area
@@ -1775,20 +1775,19 @@ static void EmitAtomicUpdateValue(CodeGe
   if (AtomicLVal.isBitField()) {
 DesiredLVal =
  

[PATCH] D38945: [CodeGen] Pass TBAA info along with lvalue base info everywhere

2017-10-17 Thread Ivan Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL315986: [CodeGen] Pass TBAA info along with lvalue base info 
everywhere (authored by kosarev).

Changed prior to commit:
  https://reviews.llvm.org/D38945?vs=119129&id=119278#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38945

Files:
  cfe/trunk/lib/CodeGen/CGAtomic.cpp
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
  cfe/trunk/lib/CodeGen/CGValue.h
  cfe/trunk/lib/CodeGen/CodeGenFunction.h

Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -3213,9 +3213,8 @@
 LValue LHS = EmitLValue(E->getBase());
 auto *Idx = EmitIdxAfterBase(/*Promote*/false);
 assert(LHS.isSimple() && "Can only subscript lvalue vectors here!");
-return LValue::MakeVectorElt(LHS.getAddress(), Idx,
- E->getBase()->getType(),
- LHS.getBaseInfo());
+return LValue::MakeVectorElt(LHS.getAddress(), Idx, E->getBase()->getType(),
+ LHS.getBaseInfo(), TBAAAccessInfo());
   }
 
   // All the other cases basically behave like simple offsetting.
@@ -3567,7 +3566,7 @@
 llvm::Constant *CV =
 llvm::ConstantDataVector::get(getLLVMContext(), Indices);
 return LValue::MakeExtVectorElt(Base.getAddress(), CV, type,
-Base.getBaseInfo());
+Base.getBaseInfo(), TBAAAccessInfo());
   }
   assert(Base.isExtVectorElt() && "Can only subscript lvalue vec elts here!");
 
@@ -3578,7 +3577,7 @@
 CElts.push_back(BaseElts->getAggregateElement(Indices[i]));
   llvm::Constant *CV = llvm::ConstantVector::get(CElts);
   return LValue::MakeExtVectorElt(Base.getExtVectorAddress(), CV, type,
-  Base.getBaseInfo());
+  Base.getBaseInfo(), TBAAAccessInfo());
 }
 
 LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
@@ -3708,7 +3707,8 @@
 
 QualType fieldType =
   field->getType().withCVRQualifiers(base.getVRQualifiers());
-return LValue::MakeBitfield(Addr, Info, fieldType, FieldBaseInfo);
+return LValue::MakeBitfield(Addr, Info, fieldType, FieldBaseInfo,
+TBAAAccessInfo());
   }
 
   Address addr = base.getAddress();
Index: cfe/trunk/lib/CodeGen/CGAtomic.cpp
===
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp
@@ -96,9 +96,8 @@
 BFI.StorageSize = AtomicSizeInBits;
 BFI.StorageOffset += OffsetInChars;
 LVal = LValue::MakeBitfield(Address(Addr, lvalue.getAlignment()),
-BFI, lvalue.getType(),
-lvalue.getBaseInfo());
-LVal.setTBAAInfo(lvalue.getTBAAInfo());
+BFI, lvalue.getType(), lvalue.getBaseInfo(),
+lvalue.getTBAAInfo());
 AtomicTy = C.getIntTypeForBitwidth(AtomicSizeInBits, OrigBFI.IsSigned);
 if (AtomicTy.isNull()) {
   llvm::APInt Size(
@@ -1346,15 +1345,15 @@
   if (LVal.isBitField())
 return CGF.EmitLoadOfBitfieldLValue(
 LValue::MakeBitfield(addr, LVal.getBitFieldInfo(), LVal.getType(),
- LVal.getBaseInfo()), loc);
+ LVal.getBaseInfo(), TBAAAccessInfo()), loc);
   if (LVal.isVectorElt())
 return CGF.EmitLoadOfLValue(
 LValue::MakeVectorElt(addr, LVal.getVectorIdx(), LVal.getType(),
-  LVal.getBaseInfo()), loc);
+  LVal.getBaseInfo(), TBAAAccessInfo()), loc);
   assert(LVal.isExtVectorElt());
   return CGF.EmitLoadOfExtVectorElementLValue(LValue::MakeExtVectorElt(
   addr, LVal.getExtVectorElts(), LVal.getType(),
-  LVal.getBaseInfo()));
+  LVal.getBaseInfo(), TBAAAccessInfo()));
 }
 
 RValue AtomicInfo::ConvertIntToValueOrAtomic(llvm::Value *IntVal,
@@ -1670,29 +1669,30 @@
   UpdateLVal =
   LValue::MakeBitfield(Ptr, AtomicLVal.getBitFieldInfo(),
AtomicLVal.getType(),
-   AtomicLVal.getBaseInfo());
+   AtomicLVal.getBaseInfo(),
+   AtomicLVal.getTBAAInfo());
   DesiredLVal =
   LValue::MakeBitfield(DesiredAddr, AtomicLVal.getBitFieldInfo(),
-   AtomicLVal.getType(),
-   AtomicLVal.getBaseInfo());
+   AtomicLVal.getType(), AtomicLVal.getBaseInfo(),
+   AtomicLVal.getTBAAInfo());
 } else if (AtomicLVal.isVectorElt()) {
   UpdateLVal = LValue::MakeVectorElt(Ptr, AtomicLVal.getVectorIdx(),
 

[PATCH] D38989: [clang-rename] Rename enum.

2017-10-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:212
+  // Ignore the case where there is no prefix qualifer for the enum 
constant
+  // expression like `a = Green`.
+  if (!Expr->hasQualifier())

hokein wrote:
> ioeric wrote:
> > Why do we ignore this case? What if `Color` is moved to a different 
> > namespace? We would also need to qualify `Green` with a new namespace.
> Thanks for pointing it out (we missed such test case before).
> 
> Yeah, this should be a FIXME, and added the case to the unittest.
It would be nice if this could also be fixed in this patch; I think it might 
affect the current code structure. This doesn't seem to be a very hard case to 
fix after all?



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:228
+  // enum constant `Green` should be excluded).
+  //ns1::ns2::Green;
+  //^  ^  ^

hokein wrote:
> ioeric wrote:
> > I'm wondering why the old `EndLoc` points to `G` instead of `n` in `Green`.
> This is the behavior of `Expr->getLocEnd()` or 
> `Expr->getSourceRange().getEnd()`, which returns the start location of the 
> last token.
I'm a bit nervous about the implementation - it feels a bit too hacky...

Would it be possible to get the range for the qualifier `ns1::ns2::` from the 
`DeclRefExpr`?


https://reviews.llvm.org/D38989



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


r315989 - [CodeGen] Refine generation of TBAA info for bit-field lvalues

2017-10-17 Thread Ivan A. Kosarev via cfe-commits
Author: kosarev
Date: Tue Oct 17 04:20:19 2017
New Revision: 315989

URL: http://llvm.org/viewvc/llvm-project?rev=315989&view=rev
Log:
[CodeGen] Refine generation of TBAA info for bit-field lvalues

The main change is that now we generate TBAA info before
constructing the resulting lvalue instead of constructing lvalue
with some default TBAA info and fixing it as necessary
afterwards. We also keep the TBAA info close to lvalue base info,
which is supposed to simplify their future merging.

This patch should not bring in any functional changes.

This is part of D38126 reworked to be a separate patch to
simplify review.

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

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=315989&r1=315988&r2=315989&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Oct 17 04:20:19 2017
@@ -3679,15 +3679,6 @@ static bool hasAnyVptr(const QualType Ty
 LValue CodeGenFunction::EmitLValueForField(LValue base,
const FieldDecl *field) {
   LValueBaseInfo BaseInfo = base.getBaseInfo();
-  AlignmentSource fieldAlignSource =
-getFieldAlignmentSource(BaseInfo.getAlignmentSource());
-  LValueBaseInfo FieldBaseInfo(fieldAlignSource, BaseInfo.getMayAlias());
-
-  QualType type = field->getType();
-  const RecordDecl *rec = field->getParent();
-  if (rec->isUnion() || rec->hasAttr() || type->isVectorType())
-FieldBaseInfo.setMayAlias(true);
-  bool mayAlias = FieldBaseInfo.getMayAlias();
 
   if (field->isBitField()) {
 const CGRecordLayout &RL =
@@ -3707,20 +3698,55 @@ LValue CodeGenFunction::EmitLValueForFie
 
 QualType fieldType =
   field->getType().withCVRQualifiers(base.getVRQualifiers());
+// TODO: Support TBAA for bit fields.
+LValueBaseInfo FieldBaseInfo(BaseInfo.getAlignmentSource(), false);
 return LValue::MakeBitfield(Addr, Info, fieldType, FieldBaseInfo,
 TBAAAccessInfo());
   }
 
+  // Fields of may-alias structures are may-alias themselves.
+  // FIXME: this should get propagated down through anonymous structs
+  // and unions.
+  QualType FieldType = field->getType();
+  const RecordDecl *rec = field->getParent();
+  AlignmentSource BaseAlignSource = BaseInfo.getAlignmentSource();
+  LValueBaseInfo FieldBaseInfo(getFieldAlignmentSource(BaseAlignSource), 
false);
+  TBAAAccessInfo FieldTBAAInfo;
+  if (BaseInfo.getMayAlias() || rec->hasAttr() ||
+  FieldType->isVectorType()) {
+FieldBaseInfo.setMayAlias(true);
+FieldTBAAInfo = CGM.getTBAAMayAliasAccessInfo();
+  } else if (rec->isUnion()) {
+// TODO: Support TBAA for unions.
+FieldBaseInfo.setMayAlias(true);
+FieldTBAAInfo = CGM.getTBAAMayAliasAccessInfo();
+  } else {
+// If no base type been assigned for the base access, then try to generate
+// one for this base lvalue.
+FieldTBAAInfo = base.getTBAAInfo();
+if (!FieldTBAAInfo.BaseType) {
+FieldTBAAInfo.BaseType = CGM.getTBAABaseTypeInfo(base.getType());
+assert(!FieldTBAAInfo.Offset &&
+   "Nonzero offset for an access with no base type!");
+}
+
+// Adjust offset to be relative to the base type.
+const ASTRecordLayout &Layout =
+getContext().getASTRecordLayout(field->getParent());
+unsigned CharWidth = getContext().getCharWidth();
+if (FieldTBAAInfo.BaseType)
+  FieldTBAAInfo.Offset +=
+  Layout.getFieldOffset(field->getFieldIndex()) / CharWidth;
+
+// Update the final access type.
+FieldTBAAInfo.AccessType = CGM.getTBAATypeInfo(FieldType);
+  }
+
   Address addr = base.getAddress();
   unsigned cvr = base.getVRQualifiers();
-  bool TBAAPath = CGM.getCodeGenOpts().StructPathTBAA;
   if (rec->isUnion()) {
 // For unions, there is no pointer adjustment.
-assert(!type->isReferenceType() && "union has reference member");
-// TODO: handle path-aware TBAA for union.
-TBAAPath = false;
-
-const auto FieldType = field->getType();
+assert(!FieldType->isReferenceType() && "union has reference member");
 if (CGM.getCodeGenOpts().StrictVTablePointers &&
 hasAnyVptr(FieldType, getContext()))
   // Because unions can easily skip invariant.barriers, we need to add
@@ -3732,24 +3758,17 @@ LValue CodeGenFunction::EmitLValueForFie
 addr = emitAddrOfFieldStorage(*this, addr, field);
 
 // If this is a reference field, load the reference right now.
-if (const ReferenceType *refType = type->getAs()) {
+if (const ReferenceType *refType = FieldType->getAs()) {
   llvm::LoadInst *load = Builder.CreateLoad(addr, "ref");
   if (cvr & Qualifiers::Volatile) load->setVolatile(true);
 
-  // Loading the reference will disable path-aware TBAA.
-  TBAAPath = false

[PATCH] D38947: [CodeGen] Refine generation of TBAA info for bit-field lvalues

2017-10-17 Thread Ivan Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL315989: [CodeGen] Refine generation of TBAA info for 
bit-field lvalues (authored by kosarev).

Changed prior to commit:
  https://reviews.llvm.org/D38947?vs=119257&id=119288#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38947

Files:
  cfe/trunk/lib/CodeGen/CGExpr.cpp

Index: cfe/trunk/lib/CodeGen/CGExpr.cpp
===
--- cfe/trunk/lib/CodeGen/CGExpr.cpp
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp
@@ -3679,15 +3679,6 @@
 LValue CodeGenFunction::EmitLValueForField(LValue base,
const FieldDecl *field) {
   LValueBaseInfo BaseInfo = base.getBaseInfo();
-  AlignmentSource fieldAlignSource =
-getFieldAlignmentSource(BaseInfo.getAlignmentSource());
-  LValueBaseInfo FieldBaseInfo(fieldAlignSource, BaseInfo.getMayAlias());
-
-  QualType type = field->getType();
-  const RecordDecl *rec = field->getParent();
-  if (rec->isUnion() || rec->hasAttr() || type->isVectorType())
-FieldBaseInfo.setMayAlias(true);
-  bool mayAlias = FieldBaseInfo.getMayAlias();
 
   if (field->isBitField()) {
 const CGRecordLayout &RL =
@@ -3707,20 +3698,55 @@
 
 QualType fieldType =
   field->getType().withCVRQualifiers(base.getVRQualifiers());
+// TODO: Support TBAA for bit fields.
+LValueBaseInfo FieldBaseInfo(BaseInfo.getAlignmentSource(), false);
 return LValue::MakeBitfield(Addr, Info, fieldType, FieldBaseInfo,
 TBAAAccessInfo());
   }
 
+  // Fields of may-alias structures are may-alias themselves.
+  // FIXME: this should get propagated down through anonymous structs
+  // and unions.
+  QualType FieldType = field->getType();
+  const RecordDecl *rec = field->getParent();
+  AlignmentSource BaseAlignSource = BaseInfo.getAlignmentSource();
+  LValueBaseInfo FieldBaseInfo(getFieldAlignmentSource(BaseAlignSource), false);
+  TBAAAccessInfo FieldTBAAInfo;
+  if (BaseInfo.getMayAlias() || rec->hasAttr() ||
+  FieldType->isVectorType()) {
+FieldBaseInfo.setMayAlias(true);
+FieldTBAAInfo = CGM.getTBAAMayAliasAccessInfo();
+  } else if (rec->isUnion()) {
+// TODO: Support TBAA for unions.
+FieldBaseInfo.setMayAlias(true);
+FieldTBAAInfo = CGM.getTBAAMayAliasAccessInfo();
+  } else {
+// If no base type been assigned for the base access, then try to generate
+// one for this base lvalue.
+FieldTBAAInfo = base.getTBAAInfo();
+if (!FieldTBAAInfo.BaseType) {
+FieldTBAAInfo.BaseType = CGM.getTBAABaseTypeInfo(base.getType());
+assert(!FieldTBAAInfo.Offset &&
+   "Nonzero offset for an access with no base type!");
+}
+
+// Adjust offset to be relative to the base type.
+const ASTRecordLayout &Layout =
+getContext().getASTRecordLayout(field->getParent());
+unsigned CharWidth = getContext().getCharWidth();
+if (FieldTBAAInfo.BaseType)
+  FieldTBAAInfo.Offset +=
+  Layout.getFieldOffset(field->getFieldIndex()) / CharWidth;
+
+// Update the final access type.
+FieldTBAAInfo.AccessType = CGM.getTBAATypeInfo(FieldType);
+  }
+
   Address addr = base.getAddress();
   unsigned cvr = base.getVRQualifiers();
-  bool TBAAPath = CGM.getCodeGenOpts().StructPathTBAA;
   if (rec->isUnion()) {
 // For unions, there is no pointer adjustment.
-assert(!type->isReferenceType() && "union has reference member");
-// TODO: handle path-aware TBAA for union.
-TBAAPath = false;
-
-const auto FieldType = field->getType();
+assert(!FieldType->isReferenceType() && "union has reference member");
 if (CGM.getCodeGenOpts().StrictVTablePointers &&
 hasAnyVptr(FieldType, getContext()))
   // Because unions can easily skip invariant.barriers, we need to add
@@ -3732,24 +3758,17 @@
 addr = emitAddrOfFieldStorage(*this, addr, field);
 
 // If this is a reference field, load the reference right now.
-if (const ReferenceType *refType = type->getAs()) {
+if (const ReferenceType *refType = FieldType->getAs()) {
   llvm::LoadInst *load = Builder.CreateLoad(addr, "ref");
   if (cvr & Qualifiers::Volatile) load->setVolatile(true);
 
-  // Loading the reference will disable path-aware TBAA.
-  TBAAPath = false;
-  TBAAAccessInfo TBAAInfo = mayAlias ? CGM.getTBAAMayAliasAccessInfo() :
-   CGM.getTBAAAccessInfo(type);
-  CGM.DecorateInstructionWithTBAA(load, TBAAInfo);
-
-  mayAlias = false;
-  type = refType->getPointeeType();
-
-  CharUnits alignment =
-getNaturalTypeAlignment(type, &FieldBaseInfo, /* TBAAInfo= */ nullptr,
-/* forPointeeType= */ true);
-  FieldBaseInfo.setMayAlias(false);
-  addr = Address(load, alignment);
+  CGM.DecorateInstructionWithTBAA(load, FieldTBAAInfo);
+
+  FieldType = refType->getPointeeType();
+  Ch

[PATCH] D34030: Fix the postorder visting of the ClassTemplateSpecializationDecl nodes in the RecursiveASTVisitor.

2017-10-17 Thread Peter Siket via Phabricator via cfe-commits
MontyKutyi added a comment.

Ping.


https://reviews.llvm.org/D34030



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


[PATCH] D38757: [libc++] Fix PR34898 - vector iterator constructors and assign method perform push_back instead of emplace_back.

2017-10-17 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF accepted this revision.
EricWF added a comment.

In https://reviews.llvm.org/D38757#897536, @dlj wrote:

> Hmm, looking more at this change... while it does make the behaviour 
> consistent for Forward and Input iterators, I think it's just making them 
> both do the wrong thing.
>
> Specifically, based on this:
>
> "... i and j denote iterators satisfying input iterator requirements and 
> refer to elements implicitly convertible to value_­type..."
>
> https://timsong-cpp.github.io/cppwp/n4659/container.requirements#sequence.reqmts-3
>
> So, for example, in test_emplacable_concept, the vector constructor should be 
> diagnosed, because there is no way to *implicitly* convert from the 
> dereferenced iterator type to the inserted type. The selected constructor is 
> explicit. Using emplacement just omits a *second* potentially-expensive 
> conversion: the explicit constructor behaviour (invoked through forwarding) 
> may still be undesired.


No, these types should be EmplaceConstructed if construction is supposed to 
occur when we are constructing a new element in the container, which is what 
this test does. These elements *need* to be constructed using the Allocator. 
The implicit construction is useful in PR34906 
, which we implicitly construct a 
value and then assign it to an already existing container.

This patch is correct to forward to emplace instead of push_back.




Comment at: 
test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp:55
 int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
-int* an = a + sizeof(a)/sizeof(a[0]);
+int* an = a + sizeof(a) / sizeof(a[0]);
 std::allocator alloc;

Sorry, this is all just re-formatting.



Comment at: test/support/emplace_constructible.h:6
+
+#if TEST_STD_VER >= 11
+  template 

THis file needs re-formatting.


https://reviews.llvm.org/D38757



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


[PATCH] D38757: [libc++] Fix PR34898 - vector iterator constructors and assign method perform push_back instead of emplace_back.

2017-10-17 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 119301.
EricWF added a comment.

- Update whitespace.


https://reviews.llvm.org/D38757

Files:
  include/deque
  include/list
  include/vector
  test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp
  test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp
  test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp
  test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp
  test/std/containers/sequences/vector/vector.cons/assign_iter_iter.pass.cpp
  test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
  
test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
  test/support/container_test_types.h
  test/support/emplace_constructible.h

Index: test/support/emplace_constructible.h
===
--- /dev/null
+++ test/support/emplace_constructible.h
@@ -0,0 +1,74 @@
+#ifndef TEST_SUPPORT_EMPLACE_CONSTRUCTIBLE_H
+#define TEST_SUPPORT_EMPLACE_CONSTRUCTIBLE_H
+
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 11
+template 
+struct EmplaceConstructible {
+  T value;
+  explicit EmplaceConstructible(T value) : value(value) {}
+  EmplaceConstructible(EmplaceConstructible const&) = delete;
+};
+
+template 
+struct EmplaceConstructibleAndMoveInsertable {
+  int copied = 0;
+  T value;
+  explicit EmplaceConstructibleAndMoveInsertable(T value) : value(value) {}
+
+  EmplaceConstructibleAndMoveInsertable(
+  EmplaceConstructibleAndMoveInsertable&& Other)
+  : copied(Other.copied + 1), value(std::move(Other.value)) {}
+};
+
+template 
+struct EmplaceConstructibleAndMoveable {
+  int copied = 0;
+  int assigned = 0;
+  T value;
+  explicit EmplaceConstructibleAndMoveable(T value) noexcept : value(value) {}
+
+  EmplaceConstructibleAndMoveable(EmplaceConstructibleAndMoveable&& Other)
+  noexcept : copied(Other.copied + 1),
+ value(std::move(Other.value)) {}
+
+  EmplaceConstructibleAndMoveable&
+  operator=(EmplaceConstructibleAndMoveable&& Other) noexcept {
+copied = Other.copied;
+assigned = Other.assigned + 1;
+value = std::move(Other.value);
+return *this;
+  }
+};
+
+template 
+struct EmplaceConstructibleMoveableAndAssignable {
+  int copied = 0;
+  int assigned = 0;
+  T value;
+  explicit EmplaceConstructibleMoveableAndAssignable(T value) noexcept
+  : value(value) {}
+
+  EmplaceConstructibleMoveableAndAssignable(
+  EmplaceConstructibleMoveableAndAssignable&& Other) noexcept
+  : copied(Other.copied + 1),
+value(std::move(Other.value)) {}
+
+  EmplaceConstructibleMoveableAndAssignable&
+  operator=(EmplaceConstructibleMoveableAndAssignable&& Other) noexcept {
+copied = Other.copied;
+assigned = Other.assigned + 1;
+value = std::move(Other.value);
+return *this;
+  }
+
+  EmplaceConstructibleMoveableAndAssignable& operator=(T xvalue) {
+value = std::move(xvalue);
+++assigned;
+return *this;
+  }
+};
+#endif
+
+#endif // TEST_SUPPORT_EMPLACE_CONSTRUCTIBLE_H
Index: test/support/container_test_types.h
===
--- test/support/container_test_types.h
+++ test/support/container_test_types.h
@@ -234,6 +234,19 @@
   return &c;
 }
 
+template 
+struct ExpectConstructGuard {
+  ExpectConstructGuard(int N)  {
+auto CC = getConstructController();
+assert(!CC->unchecked());
+CC->expect(N);
+  }
+
+  ~ExpectConstructGuard() {
+assert(!getConstructController()->unchecked());
+  }
+};
+
 //===--===//
 //   ContainerTestAllocator
 //===--===//
@@ -417,7 +430,12 @@
   return arg.data;
 }
   };
-
+  template 
+  class vector;
+  template 
+  class deque;
+  template 
+  class list;
   template 
   class map;
   template 
@@ -444,6 +462,13 @@
 // TCT - Test container type
 namespace TCT {
 
+template >
+using vector = std::vector >;
+template >
+using deque = std::deque >;
+template >
+using list = std::list >;
+
 template , class Value = CopyInsertable<2>,
   class ValueTp = std::pair >
 using unordered_map =
@@ -488,5 +513,4 @@
 
 } // end namespace TCT
 
-
 #endif // SUPPORT_CONTAINER_TEST_TYPES_H
Index: test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
===
--- test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
+++ test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
@@ -21,56 +21,152 @@
 #include "test_allocator.h"
 #include "min_allocator.h"
 #include "asan_testing.h"
+#if TEST_STD_VER >= 11
+#include "emplace_constructible.h"
+#include "container_test_types.h"
+#endif
 
 template 
-void
-test(Iterator first, Iterator last, const A& a)
-{

[libcxx] r315994 - [libc++] Fix PR34898 - vector iterator constructors and assign method perform push_back instead of emplace_back.

2017-10-17 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Oct 17 06:03:17 2017
New Revision: 315994

URL: http://llvm.org/viewvc/llvm-project?rev=315994&view=rev
Log:
[libc++] Fix PR34898 - vector iterator constructors and assign method perform 
push_back instead of emplace_back.

Summary:
The constructors `vector(Iter, Iter, Alloc = Alloc{})` and `assign(Iter, Iter)` 
don't correctly perform EmplaceConstruction from the result of dereferencing 
the iterator. This results in them performing an additional and unneeded copy.

This patch addresses the issue by correctly using `emplace_back` in C++11 and 
newer.

There are also some bugs in our `insert` implementation, but those will be 
handled separately. 

@mclow.lists We should probably merge this into 5.1, agreed?

Reviewers: mclow.lists, dlj, EricWF

Reviewed By: mclow.lists, EricWF

Subscribers: cfe-commits, mclow.lists

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

Added:

libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_iter_iter.pass.cpp
libcxx/trunk/test/support/emplace_constructible.h
Modified:
libcxx/trunk/include/deque
libcxx/trunk/include/list
libcxx/trunk/include/vector

libcxx/trunk/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp

libcxx/trunk/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp

libcxx/trunk/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp

libcxx/trunk/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp

libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp

libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
libcxx/trunk/test/support/container_test_types.h

Modified: libcxx/trunk/include/deque
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/deque?rev=315994&r1=315993&r2=315994&view=diff
==
--- libcxx/trunk/include/deque (original)
+++ libcxx/trunk/include/deque Tue Oct 17 06:03:17 2017
@@ -1356,7 +1356,6 @@ public:
 iterator insert(const_iterator __p, initializer_list __il)
 {return insert(__p, __il.begin(), __il.end());}
 #endif  // _LIBCPP_CXX03_LANG
-
 iterator insert(const_iterator __p, const value_type& __v);
 iterator insert(const_iterator __p, size_type __n, const value_type& __v);
 template 
@@ -2224,7 +2223,11 @@ deque<_Tp, _Allocator>::__append(_InpIte

!__is_forward_iterator<_InpIter>::value>::type*)
 {
 for (; __f != __l; ++__f)
+#ifdef _LIBCPP_CXX03_LANG
 push_back(*__f);
+#else
+emplace_back(*__f);
+#endif
 }
 
 template 

Modified: libcxx/trunk/include/list
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/list?rev=315994&r1=315993&r2=315994&view=diff
==
--- libcxx/trunk/include/list (original)
+++ libcxx/trunk/include/list Tue Oct 17 06:03:17 2017
@@ -992,6 +992,15 @@ public:
 void push_front(const value_type& __x);
 void push_back(const value_type& __x);
 
+#ifndef _LIBCPP_CXX03_LANG
+template 
+_LIBCPP_INLINE_VISIBILITY
+void __emplace_back(_Arg&& __arg) { 
emplace_back(_VSTD::forward<_Arg>(__arg)); }
+#else
+_LIBCPP_INLINE_VISIBILITY
+void __emplace_back(value_type const& __arg) { push_back(__arg); }
+#endif
+
 iterator insert(const_iterator __p, const value_type& __x);
 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
 template 
@@ -1189,7 +1198,7 @@ list<_Tp, _Alloc>::list(_InpIter __f, _I
 __get_db()->__insert_c(this);
 #endif
 for (; __f != __l; ++__f)
-push_back(*__f);
+__emplace_back(*__f);
 }
 
 template 
@@ -1202,7 +1211,7 @@ list<_Tp, _Alloc>::list(_InpIter __f, _I
 __get_db()->__insert_c(this);
 #endif
 for (; __f != __l; ++__f)
-push_back(*__f);
+__emplace_back(*__f);
 }
 
 template 

Modified: libcxx/trunk/include/vector
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/vector?rev=315994&r1=315993&r2=315994&view=diff
==
--- libcxx/trunk/include/vector (original)
+++ libcxx/trunk/include/vector Tue Oct 17 06:03:17 2017
@@ -674,6 +674,17 @@ public:
 const value_type* data() const _NOEXCEPT
 {return _VSTD::__to_raw_pointer(this->__begin_);}
 
+#ifdef _LIBCPP_CXX03_LANG
+_LIBCPP_INLINE_VISIBILITY
+void __emplace_back(const value_type& __x) { push_back(__x); }
+#else
+template 
+_LIBCPP_INLINE_VISIBILITY
+void __emplace_back(_Arg&& __arg) {
+  emplace_back(_VSTD::forward<_Arg>(__arg));
+}
+#endif
+
 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
 
 #ifndef _LIBCPP_CXX03_LANG
@@ -1128,7 +1139,7 @@ vector<_Tp, _Allocator>::vector(_InputIt
 __get_db()->__insert_c(this

[PATCH] D38757: [libc++] Fix PR34898 - vector iterator constructors and assign method perform push_back instead of emplace_back.

2017-10-17 Thread Eric Fiselier via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL315994: [libc++] Fix PR34898 - vector iterator constructors 
and assign method perform… (authored by EricWF).

Changed prior to commit:
  https://reviews.llvm.org/D38757?vs=119301&id=119302#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38757

Files:
  libcxx/trunk/include/deque
  libcxx/trunk/include/list
  libcxx/trunk/include/vector
  
libcxx/trunk/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp
  libcxx/trunk/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp
  
libcxx/trunk/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp
  
libcxx/trunk/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp
  
libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_iter_iter.pass.cpp
  
libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
  
libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
  libcxx/trunk/test/support/container_test_types.h
  libcxx/trunk/test/support/emplace_constructible.h

Index: libcxx/trunk/include/deque
===
--- libcxx/trunk/include/deque
+++ libcxx/trunk/include/deque
@@ -1356,7 +1356,6 @@
 iterator insert(const_iterator __p, initializer_list __il)
 {return insert(__p, __il.begin(), __il.end());}
 #endif  // _LIBCPP_CXX03_LANG
-
 iterator insert(const_iterator __p, const value_type& __v);
 iterator insert(const_iterator __p, size_type __n, const value_type& __v);
 template 
@@ -2224,7 +2223,11 @@
!__is_forward_iterator<_InpIter>::value>::type*)
 {
 for (; __f != __l; ++__f)
+#ifdef _LIBCPP_CXX03_LANG
 push_back(*__f);
+#else
+emplace_back(*__f);
+#endif
 }
 
 template 
Index: libcxx/trunk/include/vector
===
--- libcxx/trunk/include/vector
+++ libcxx/trunk/include/vector
@@ -674,6 +674,17 @@
 const value_type* data() const _NOEXCEPT
 {return _VSTD::__to_raw_pointer(this->__begin_);}
 
+#ifdef _LIBCPP_CXX03_LANG
+_LIBCPP_INLINE_VISIBILITY
+void __emplace_back(const value_type& __x) { push_back(__x); }
+#else
+template 
+_LIBCPP_INLINE_VISIBILITY
+void __emplace_back(_Arg&& __arg) {
+  emplace_back(_VSTD::forward<_Arg>(__arg));
+}
+#endif
+
 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
 
 #ifndef _LIBCPP_CXX03_LANG
@@ -1128,7 +1139,7 @@
 __get_db()->__insert_c(this);
 #endif
 for (; __first != __last; ++__first)
-push_back(*__first);
+__emplace_back(*__first);
 }
 
 template 
@@ -1145,7 +1156,7 @@
 __get_db()->__insert_c(this);
 #endif
 for (; __first != __last; ++__first)
-push_back(*__first);
+__emplace_back(*__first);
 }
 
 template 
@@ -1365,7 +1376,7 @@
 {
 clear();
 for (; __first != __last; ++__first)
-push_back(*__first);
+__emplace_back(*__first);
 }
 
 template 
Index: libcxx/trunk/include/list
===
--- libcxx/trunk/include/list
+++ libcxx/trunk/include/list
@@ -992,6 +992,15 @@
 void push_front(const value_type& __x);
 void push_back(const value_type& __x);
 
+#ifndef _LIBCPP_CXX03_LANG
+template 
+_LIBCPP_INLINE_VISIBILITY
+void __emplace_back(_Arg&& __arg) { emplace_back(_VSTD::forward<_Arg>(__arg)); }
+#else
+_LIBCPP_INLINE_VISIBILITY
+void __emplace_back(value_type const& __arg) { push_back(__arg); }
+#endif
+
 iterator insert(const_iterator __p, const value_type& __x);
 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
 template 
@@ -1189,7 +1198,7 @@
 __get_db()->__insert_c(this);
 #endif
 for (; __f != __l; ++__f)
-push_back(*__f);
+__emplace_back(*__f);
 }
 
 template 
@@ -1202,7 +1211,7 @@
 __get_db()->__insert_c(this);
 #endif
 for (; __f != __l; ++__f)
-push_back(*__f);
+__emplace_back(*__f);
 }
 
 template 
Index: libcxx/trunk/test/support/emplace_constructible.h
===
--- libcxx/trunk/test/support/emplace_constructible.h
+++ libcxx/trunk/test/support/emplace_constructible.h
@@ -0,0 +1,74 @@
+#ifndef TEST_SUPPORT_EMPLACE_CONSTRUCTIBLE_H
+#define TEST_SUPPORT_EMPLACE_CONSTRUCTIBLE_H
+
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 11
+template 
+struct EmplaceConstructible {
+  T value;
+  explicit EmplaceConstructible(T value) : value(value) {}
+  EmplaceConstructible(EmplaceConstructible const&) = delete;
+};
+
+template 
+struct EmplaceConstructibleAndMoveInsertable {
+  int copied = 0;
+  T value;
+  explicit EmplaceConstructibleAndMoveInsertable(T value) : value(value) {}
+
+  EmplaceConstructibleAndMoveInsertable(

[libcxx] r315995 - Refactor _LIBCPP__ENDIAN

2017-10-17 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Oct 17 06:16:01 2017
New Revision: 315995

URL: http://llvm.org/viewvc/llvm-project?rev=315995&view=rev
Log:
Refactor _LIBCPP__ENDIAN

Previously this macro used 0/1 to indicate if it was set.
This is unlike all other libc++ configuration macros which
use ifdef/ifndef.

This patch makes this macro consistent with everything else.

Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/string

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=315995&r1=315994&r2=315995&view=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Tue Oct 17 06:16:01 2017
@@ -184,36 +184,30 @@
 
 #ifdef __LITTLE_ENDIAN__
 #if __LITTLE_ENDIAN__
-#define _LIBCPP_LITTLE_ENDIAN 1
-#define _LIBCPP_BIG_ENDIAN0
+#define _LIBCPP_LITTLE_ENDIAN
 #endif  // __LITTLE_ENDIAN__
 #endif  // __LITTLE_ENDIAN__
 
 #ifdef __BIG_ENDIAN__
 #if __BIG_ENDIAN__
-#define _LIBCPP_LITTLE_ENDIAN 0
-#define _LIBCPP_BIG_ENDIAN1
+#define _LIBCPP_BIG_ENDIAN
 #endif  // __BIG_ENDIAN__
 #endif  // __BIG_ENDIAN__
 
 #ifdef __BYTE_ORDER__
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-#define _LIBCPP_LITTLE_ENDIAN 1
-#define _LIBCPP_BIG_ENDIAN 0
+#define _LIBCPP_LITTLE_ENDIAN
 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-#define _LIBCPP_LITTLE_ENDIAN 0
-#define _LIBCPP_BIG_ENDIAN 1
+#define _LIBCPP_BIG_ENDIAN
 #endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
 #endif // __BYTE_ORDER__
 
 #ifdef __FreeBSD__
 # include 
 #  if _BYTE_ORDER == _LITTLE_ENDIAN
-#   define _LIBCPP_LITTLE_ENDIAN 1
-#   define _LIBCPP_BIG_ENDIAN0
+#   define _LIBCPP_LITTLE_ENDIAN
 # else  // _BYTE_ORDER == _LITTLE_ENDIAN
-#   define _LIBCPP_LITTLE_ENDIAN 0
-#   define _LIBCPP_BIG_ENDIAN1
+#   define _LIBCPP_BIG_ENDIAN
 # endif  // _BYTE_ORDER == _LITTLE_ENDIAN
 # ifndef __LONG_LONG_SUPPORTED
 #  define _LIBCPP_HAS_NO_LONG_LONG
@@ -223,19 +217,16 @@
 #ifdef __NetBSD__
 # include 
 #  if _BYTE_ORDER == _LITTLE_ENDIAN
-#   define _LIBCPP_LITTLE_ENDIAN 1
-#   define _LIBCPP_BIG_ENDIAN0
+#   define _LIBCPP_LITTLE_ENDIAN
 # else  // _BYTE_ORDER == _LITTLE_ENDIAN
-#   define _LIBCPP_LITTLE_ENDIAN 0
-#   define _LIBCPP_BIG_ENDIAN1
+#   define _LIBCPP_BIG_ENDIAN
 # endif  // _BYTE_ORDER == _LITTLE_ENDIAN
 # define _LIBCPP_HAS_QUICK_EXIT
 #endif  // __NetBSD__
 
 #if defined(_WIN32)
 #  define _LIBCPP_WIN32API
-#  define _LIBCPP_LITTLE_ENDIAN 1
-#  define _LIBCPP_BIG_ENDIAN0
+#  define _LIBCPP_LITTLE_ENDIAN
 #  define _LIBCPP_SHORT_WCHAR   1
 // Both MinGW and native MSVC provide a "MSVC"-like enviroment
 #  define _LIBCPP_MSVCRT_LIKE
@@ -265,11 +256,9 @@
 #ifdef __sun__
 # include 
 # ifdef _LITTLE_ENDIAN
-#   define _LIBCPP_LITTLE_ENDIAN 1
-#   define _LIBCPP_BIG_ENDIAN0
+#   define _LIBCPP_LITTLE_ENDIAN
 # else
-#   define _LIBCPP_LITTLE_ENDIAN 0
-#   define _LIBCPP_BIG_ENDIAN1
+#   define _LIBCPP_BIG_ENDIAN
 # endif
 #endif // __sun__
 
@@ -290,18 +279,16 @@
 # define _LIBCPP_USING_DEV_RANDOM
 #endif
 
-#if !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN)
+#if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
 # include 
 # if __BYTE_ORDER == __LITTLE_ENDIAN
-#  define _LIBCPP_LITTLE_ENDIAN 1
-#  define _LIBCPP_BIG_ENDIAN0
+#  define _LIBCPP_LITTLE_ENDIAN
 # elif __BYTE_ORDER == __BIG_ENDIAN
-#  define _LIBCPP_LITTLE_ENDIAN 0
-#  define _LIBCPP_BIG_ENDIAN1
+#  define _LIBCPP_BIG_ENDIAN
 # else  // __BYTE_ORDER == __BIG_ENDIAN
 #  error unable to determine endian
 # endif
-#endif  // !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN)
+#endif  // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
 
 #if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
 #define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))

Modified: libcxx/trunk/include/string
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=315995&r1=315994&r2=315995&view=diff
==
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Tue Oct 17 06:16:01 2017
@@ -670,7 +670,7 @@ private:
 size_type __cap_;
 };
 
-#if _LIBCPP_BIG_ENDIAN
+#ifdef _LIBCPP_BIG_ENDIAN
 static const size_type __short_mask = 0x01;
 static const size_type __long_mask  = 0x1ul;
 #else  // _LIBCPP_BIG_ENDIAN
@@ -700,7 +700,7 @@ private:
 pointer   __data_;
 };
 
-#if _LIBCPP_BIG_ENDIAN
+#ifdef _LIBCPP_BIG_ENDIAN
 static const size_type __short_mask = 0x80;
 static const size_type __long_mask  = ~(size_type(~0) >> 1);
 #else  // _LIBCPP_BIG_ENDIAN
@@ -1241,7 +1241,7 @@ private:
 
 _LIBCPP_INLINE_VISIBILITY
 void __set_short_size(size_type __s) _NOEXCEPT
-#   if _LIBCPP_BIG_ENDIAN
+#   ifdef _LIBCPP_BIG_ENDIAN
 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
 

[PATCH] D38989: [clang-rename] Rename enum.

2017-10-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 119309.
hokein added a comment.

Use getQualifierLoc.


https://reviews.llvm.org/D38989

Files:
  lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
  unittests/Rename/CMakeLists.txt
  unittests/Rename/RenameEnumTest.cpp

Index: unittests/Rename/RenameEnumTest.cpp
===
--- /dev/null
+++ unittests/Rename/RenameEnumTest.cpp
@@ -0,0 +1,189 @@
+#include "ClangRenameTest.h"
+
+namespace clang {
+namespace clang_rename {
+namespace test {
+namespace {
+
+class RenameEnumTest : public ClangRenameTest {
+public:
+  RenameEnumTest() {
+AppendToHeader(R"(
+#define MACRO(x) x
+namespace a {
+enum A1 { Red };
+enum class A2 { Blue };
+struct C {
+ enum NestedEnum { White };
+ enum class NestedScopedEnum { Black };
+};
+namespace d {
+enum A3 { Orange };
+} // namespace d
+enum A4 { Pink };
+} // namespace a
+enum A5 { Green };)");
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(
+RenameEnumTests, RenameEnumTest,
+testing::ValuesIn(std::vector({
+{"void f(a::A2 arg) { a::A2 t = a::A2::Blue; }",
+ "void f(b::B2 arg) { b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"},
+{"void f() { a::A1* t1; }", "void f() { b::B1* t1; }", "a::A1",
+ "b::B1"},
+{"void f() { a::A2* t1; }", "void f() { b::B2* t1; }", "a::A2",
+ "b::B2"},
+{"void f() { enum a::A2 t = a::A2::Blue; }",
+ "void f() { enum b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"},
+{"void f() { enum a::A2 t = a::A2::Blue; }",
+ "void f() { enum b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"},
+
+{"void f() { a::A1 t = a::Red; }", "void f() { b::B1 t = b::B1::Red; }",
+ "a::A1", "b::B1"},
+{"void f() { a::A1 t = a::A1::Red; }",
+ "void f() { b::B1 t = b::B1::Red; }", "a::A1", "b::B1"},
+{"void f() { auto t = a::Red; }", "void f() { auto t = b::B1::Red; }",
+ "a::A1", "b::B1"},
+{"namespace b { void f() { a::A1 t = a::Red; } }",
+ "namespace b { void f() { B1 t = B1::Red; } }", "a::A1", "b::B1"},
+{"void f() { a::d::A3 t = a::d::Orange; }",
+ "void f() { a::b::B3 t = a::b::B3::Orange; }", "a::d::A3", "a::b::B3"},
+{"namespace a { void f() { a::d::A3 t = a::d::Orange; } }",
+ "namespace a { void f() { b::B3 t = b::B3::Orange; } }", "a::d::A3",
+ "a::b::B3"},
+{"void f() { A5 t = Green; }", "void f() { B5 t = Green; }", "A5",
+ "B5"},
+// FIXME: the new namespace qualifier should be added to the unscoped
+// enum constant.
+{"namespace a { void f() { auto t = Green; } }",
+ "namespace a { void f() { auto t = Green; } }", "a::A1", "b::B1"},
+
+// namespace qualifiers
+{"namespace a { void f(A1 a1) {} }",
+ "namespace a { void f(b::B1 a1) {} }", "a::A1", "b::B1"},
+{"namespace a { void f(A2 a2) {} }",
+ "namespace a { void f(b::B2 a2) {} }", "a::A2", "b::B2"},
+{"namespace b { void f(a::A1 a1) {} }",
+ "namespace b { void f(B1 a1) {} }", "a::A1", "b::B1"},
+{"namespace b { void f(a::A2 a2) {} }",
+ "namespace b { void f(B2 a2) {} }", "a::A2", "b::B2"},
+
+// nested enums
+{"void f() { a::C::NestedEnum t = a::C::White; }",
+ "void f() { a::C::NewNestedEnum t = a::C::NewNestedEnum::White; }",
+ "a::C::NestedEnum", "a::C::NewNestedEnum"},
+{"void f() { a::C::NestedScopedEnum t = a::C::NestedScopedEnum::Black; "
+ "}",
+ "void f() { a::C::NewNestedScopedEnum t = "
+ "a::C::NewNestedScopedEnum::Black; }",
+ "a::C::NestedScopedEnum", "a::C::NewNestedScopedEnum"},
+
+// macros
+{"void f(MACRO(a::A1) a1) {}", "void f(MACRO(b::B1) a1) {}", "a::A1",
+ "b::B1"},
+{"void f(MACRO(a::A2) a2) {}", "void f(MACRO(b::B2) a2) {}", "a::A2",
+ "b::B2"},
+{"#define FOO(T, t) T t\nvoid f() { FOO(a::A1, a1); }",
+ "#define FOO(T, t) T t\nvoid f() { FOO(b::B1, a1); }", "a::A1",
+ "b::B1"},
+{"#define FOO(T, t) T t\nvoid f() { FOO(a::A2, a2); }",
+ "#define FOO(T, t) T t\nvoid f() { FOO(b::B2, a2); }", "a::A2",
+ "b::B2"},
+{"#define FOO(n) a::A1 n\nvoid f() { FOO(a1); FOO(a2); }",
+ "#define FOO(n) b::B1 n\nvoid f() { FOO(a1); FOO(a2); }", "a::A1",
+ "b::B1"},
+
+// using and type alias
+{"using a::A1; A1 gA;", "using b::B1; b::B1 gA;", "a::A1", "b::B1"},
+{"using a::A2; A2 gA;", "using b::B2; b::B2 gA;", "a::A2", "b::B2"},
+{"struct S { using T = a::A1; T a_; };",
+ "struct S { using T = b::B1; T a_; };", "a::A1", "b::B1"},
+{"using T = a::A1; T gA;", "using T = b::B1; T gA;", "a::A1", "b::B1"},
+{"using T = a::A2; T gA;", "using T = b::B2; T gA;", "a::A2", "b::B2"},
+   

[PATCH] D38989: [clang-rename] Rename enum.

2017-10-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:212
+  // Ignore the case where there is no prefix qualifer for the enum 
constant
+  // expression like `a = Green`.
+  if (!Expr->hasQualifier())

ioeric wrote:
> hokein wrote:
> > ioeric wrote:
> > > Why do we ignore this case? What if `Color` is moved to a different 
> > > namespace? We would also need to qualify `Green` with a new namespace.
> > Thanks for pointing it out (we missed such test case before).
> > 
> > Yeah, this should be a FIXME, and added the case to the unittest.
> It would be nice if this could also be fixed in this patch; I think it might 
> affect the current code structure. This doesn't seem to be a very hard case 
> to fix after all?
To fix this case , we have to insert the prefix qualifier at the BeginLoc, 
which is not supported by the current code.
I prefer to do it in a follow-up patch. 



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:228
+  // enum constant `Green` should be excluded).
+  //ns1::ns2::Green;
+  //^  ^  ^

ioeric wrote:
> hokein wrote:
> > ioeric wrote:
> > > I'm wondering why the old `EndLoc` points to `G` instead of `n` in 
> > > `Green`.
> > This is the behavior of `Expr->getLocEnd()` or 
> > `Expr->getSourceRange().getEnd()`, which returns the start location of the 
> > last token.
> I'm a bit nervous about the implementation - it feels a bit too hacky...
> 
> Would it be possible to get the range for the qualifier `ns1::ns2::` from the 
> `DeclRefExpr`?
Switched to use `getQualifierLoc`, we still need to exclude the last `::` by 
moving 1 character backward.


https://reviews.llvm.org/D38989



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


[PATCH] D38989: [clang-rename] Rename enum.

2017-10-17 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.

Lg




Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:212
+  // Ignore the case where there is no prefix qualifer for the enum 
constant
+  // expression like `a = Green`.
+  if (!Expr->hasQualifier())

hokein wrote:
> ioeric wrote:
> > hokein wrote:
> > > ioeric wrote:
> > > > Why do we ignore this case? What if `Color` is moved to a different 
> > > > namespace? We would also need to qualify `Green` with a new namespace.
> > > Thanks for pointing it out (we missed such test case before).
> > > 
> > > Yeah, this should be a FIXME, and added the case to the unittest.
> > It would be nice if this could also be fixed in this patch; I think it 
> > might affect the current code structure. This doesn't seem to be a very 
> > hard case to fix after all?
> To fix this case , we have to insert the prefix qualifier at the BeginLoc, 
> which is not supported by the current code.
> I prefer to do it in a follow-up patch. 
Sure. Up to you.



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:228
+  // enum constant `Green` should be excluded).
+  //ns1::ns2::Green;
+  //^  ^  ^

hokein wrote:
> ioeric wrote:
> > hokein wrote:
> > > ioeric wrote:
> > > > I'm wondering why the old `EndLoc` points to `G` instead of `n` in 
> > > > `Green`.
> > > This is the behavior of `Expr->getLocEnd()` or 
> > > `Expr->getSourceRange().getEnd()`, which returns the start location of 
> > > the last token.
> > I'm a bit nervous about the implementation - it feels a bit too hacky...
> > 
> > Would it be possible to get the range for the qualifier `ns1::ns2::` from 
> > the `DeclRefExpr`?
> Switched to use `getQualifierLoc`, we still need to exclude the last `::` by 
> moving 1 character backward.
It might also make sense to double check that the old end loc is pointing at 
"::".


https://reviews.llvm.org/D38989



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


r315996 - [CMake][OpenMP] Customize default offloading arch

2017-10-17 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Tue Oct 17 06:37:36 2017
New Revision: 315996

URL: http://llvm.org/viewvc/llvm-project?rev=315996&view=rev
Log:
[CMake][OpenMP] Customize default offloading arch

For the shuffle instructions in reductions we need at least sm_30
but the user may want to customize the default architecture.

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

Modified:
cfe/trunk/CMakeLists.txt
cfe/trunk/include/clang/Config/config.h.cmake
cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
cfe/trunk/lib/Driver/ToolChains/Cuda.h

Modified: cfe/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=315996&r1=315995&r2=315996&view=diff
==
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Tue Oct 17 06:37:36 2017
@@ -235,6 +235,17 @@ endif()
 set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
   "Default OpenMP runtime used by -fopenmp.")
 
+# OpenMP offloading requires at least sm_30 because we use shuffle instructions
+# to generate efficient code for reductions.
+set(CLANG_OPENMP_NVPTX_DEFAULT_ARCH "sm_30" CACHE STRING
+  "Default architecture for OpenMP offloading to Nvidia GPUs.")
+string(REGEX MATCH "^sm_([0-9]+)$" MATCHED_ARCH 
"${CLANG_OPENMP_NVPTX_DEFAULT_ARCH}")
+if (NOT DEFINED MATCHED_ARCH OR "${CMAKE_MATCH_1}" LESS 30)
+  message(WARNING "Resetting default architecture for OpenMP offloading to 
Nvidia GPUs to sm_30")
+  set(CLANG_OPENMP_NVPTX_DEFAULT_ARCH "sm_30" CACHE STRING
+"Default architecture for OpenMP offloading to Nvidia GPUs." FORCE)
+endif()
+
 set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
   "Vendor-specific text for showing with version information.")
 

Modified: cfe/trunk/include/clang/Config/config.h.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Config/config.h.cmake?rev=315996&r1=315995&r2=315996&view=diff
==
--- cfe/trunk/include/clang/Config/config.h.cmake (original)
+++ cfe/trunk/include/clang/Config/config.h.cmake Tue Oct 17 06:37:36 2017
@@ -20,6 +20,9 @@
 /* Default OpenMP runtime used by -fopenmp. */
 #define CLANG_DEFAULT_OPENMP_RUNTIME "${CLANG_DEFAULT_OPENMP_RUNTIME}"
 
+/* Default architecture for OpenMP offloading to Nvidia GPUs. */
+#define CLANG_OPENMP_NVPTX_DEFAULT_ARCH "${CLANG_OPENMP_NVPTX_DEFAULT_ARCH}"
+
 /* Multilib suffix for libdir. */
 #define CLANG_LIBDIR_SUFFIX "${CLANG_LIBDIR_SUFFIX}"
 

Modified: cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Cuda.cpp?rev=315996&r1=315995&r2=315996&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Cuda.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Cuda.cpp Tue Oct 17 06:37:36 2017
@@ -542,9 +542,9 @@ CudaToolChain::TranslateArgs(const llvm:
   // flags are not duplicated.
   // Also append the compute capability.
   if (DeviceOffloadKind == Action::OFK_OpenMP) {
-for (Arg *A : Args){
+for (Arg *A : Args) {
   bool IsDuplicate = false;
-  for (Arg *DALArg : *DAL){
+  for (Arg *DALArg : *DAL) {
 if (A == DALArg) {
   IsDuplicate = true;
   break;
@@ -555,14 +555,9 @@ CudaToolChain::TranslateArgs(const llvm:
 }
 
 StringRef Arch = DAL->getLastArgValue(options::OPT_march_EQ);
-if (Arch.empty()) {
-  // Default compute capability for CUDA toolchain is the
-  // lowest compute capability supported by the installed
-  // CUDA version.
-  DAL->AddJoinedArg(nullptr,
-  Opts.getOption(options::OPT_march_EQ),
-  CudaInstallation.getLowestExistingArch());
-}
+if (Arch.empty())
+  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
+CLANG_OPENMP_NVPTX_DEFAULT_ARCH);
 
 return DAL;
   }

Modified: cfe/trunk/lib/Driver/ToolChains/Cuda.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Cuda.h?rev=315996&r1=315995&r2=315996&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Cuda.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/Cuda.h Tue Oct 17 06:37:36 2017
@@ -76,17 +76,6 @@ public:
   std::string getLibDeviceFile(StringRef Gpu) const {
 return LibDeviceMap.lookup(Gpu);
   }
-  /// \brief Get lowest available compute capability
-  /// for which a libdevice library exists.
-  std::string getLowestExistingArch() const {
-std::string LibDeviceFile;
-for (auto key : LibDeviceMap.keys()) {
-  LibDeviceFile = LibDeviceMap.lookup(key);
-  if (!LibDeviceFile.empty())
-return key;
-}
-return "sm_20";
-  }
 };
 
 namespace tools {


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

[PATCH] D38883: [CMake][OpenMP] Customize default offloading arch

2017-10-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL315996: [CMake][OpenMP] Customize default offloading arch 
(authored by Hahnfeld).

Changed prior to commit:
  https://reviews.llvm.org/D38883?vs=118961&id=119310#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38883

Files:
  cfe/trunk/CMakeLists.txt
  cfe/trunk/include/clang/Config/config.h.cmake
  cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
  cfe/trunk/lib/Driver/ToolChains/Cuda.h


Index: cfe/trunk/include/clang/Config/config.h.cmake
===
--- cfe/trunk/include/clang/Config/config.h.cmake
+++ cfe/trunk/include/clang/Config/config.h.cmake
@@ -20,6 +20,9 @@
 /* Default OpenMP runtime used by -fopenmp. */
 #define CLANG_DEFAULT_OPENMP_RUNTIME "${CLANG_DEFAULT_OPENMP_RUNTIME}"
 
+/* Default architecture for OpenMP offloading to Nvidia GPUs. */
+#define CLANG_OPENMP_NVPTX_DEFAULT_ARCH "${CLANG_OPENMP_NVPTX_DEFAULT_ARCH}"
+
 /* Multilib suffix for libdir. */
 #define CLANG_LIBDIR_SUFFIX "${CLANG_LIBDIR_SUFFIX}"
 
Index: cfe/trunk/CMakeLists.txt
===
--- cfe/trunk/CMakeLists.txt
+++ cfe/trunk/CMakeLists.txt
@@ -235,6 +235,17 @@
 set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
   "Default OpenMP runtime used by -fopenmp.")
 
+# OpenMP offloading requires at least sm_30 because we use shuffle instructions
+# to generate efficient code for reductions.
+set(CLANG_OPENMP_NVPTX_DEFAULT_ARCH "sm_30" CACHE STRING
+  "Default architecture for OpenMP offloading to Nvidia GPUs.")
+string(REGEX MATCH "^sm_([0-9]+)$" MATCHED_ARCH 
"${CLANG_OPENMP_NVPTX_DEFAULT_ARCH}")
+if (NOT DEFINED MATCHED_ARCH OR "${CMAKE_MATCH_1}" LESS 30)
+  message(WARNING "Resetting default architecture for OpenMP offloading to 
Nvidia GPUs to sm_30")
+  set(CLANG_OPENMP_NVPTX_DEFAULT_ARCH "sm_30" CACHE STRING
+"Default architecture for OpenMP offloading to Nvidia GPUs." FORCE)
+endif()
+
 set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
   "Vendor-specific text for showing with version information.")
 
Index: cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Cuda.cpp
@@ -542,9 +542,9 @@
   // flags are not duplicated.
   // Also append the compute capability.
   if (DeviceOffloadKind == Action::OFK_OpenMP) {
-for (Arg *A : Args){
+for (Arg *A : Args) {
   bool IsDuplicate = false;
-  for (Arg *DALArg : *DAL){
+  for (Arg *DALArg : *DAL) {
 if (A == DALArg) {
   IsDuplicate = true;
   break;
@@ -555,14 +555,9 @@
 }
 
 StringRef Arch = DAL->getLastArgValue(options::OPT_march_EQ);
-if (Arch.empty()) {
-  // Default compute capability for CUDA toolchain is the
-  // lowest compute capability supported by the installed
-  // CUDA version.
-  DAL->AddJoinedArg(nullptr,
-  Opts.getOption(options::OPT_march_EQ),
-  CudaInstallation.getLowestExistingArch());
-}
+if (Arch.empty())
+  DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ),
+CLANG_OPENMP_NVPTX_DEFAULT_ARCH);
 
 return DAL;
   }
Index: cfe/trunk/lib/Driver/ToolChains/Cuda.h
===
--- cfe/trunk/lib/Driver/ToolChains/Cuda.h
+++ cfe/trunk/lib/Driver/ToolChains/Cuda.h
@@ -76,17 +76,6 @@
   std::string getLibDeviceFile(StringRef Gpu) const {
 return LibDeviceMap.lookup(Gpu);
   }
-  /// \brief Get lowest available compute capability
-  /// for which a libdevice library exists.
-  std::string getLowestExistingArch() const {
-std::string LibDeviceFile;
-for (auto key : LibDeviceMap.keys()) {
-  LibDeviceFile = LibDeviceMap.lookup(key);
-  if (!LibDeviceFile.empty())
-return key;
-}
-return "sm_20";
-  }
 };
 
 namespace tools {


Index: cfe/trunk/include/clang/Config/config.h.cmake
===
--- cfe/trunk/include/clang/Config/config.h.cmake
+++ cfe/trunk/include/clang/Config/config.h.cmake
@@ -20,6 +20,9 @@
 /* Default OpenMP runtime used by -fopenmp. */
 #define CLANG_DEFAULT_OPENMP_RUNTIME "${CLANG_DEFAULT_OPENMP_RUNTIME}"
 
+/* Default architecture for OpenMP offloading to Nvidia GPUs. */
+#define CLANG_OPENMP_NVPTX_DEFAULT_ARCH "${CLANG_OPENMP_NVPTX_DEFAULT_ARCH}"
+
 /* Multilib suffix for libdir. */
 #define CLANG_LIBDIR_SUFFIX "${CLANG_LIBDIR_SUFFIX}"
 
Index: cfe/trunk/CMakeLists.txt
===
--- cfe/trunk/CMakeLists.txt
+++ cfe/trunk/CMakeLists.txt
@@ -235,6 +235,17 @@
 set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
   "Default OpenMP runtime used by -fopenmp.")
 
+# OpenMP offloading requires at least sm_30 because we use shuffle instructions
+# to generate efficient code 

[libcxx] r315997 - fix shadowing warnings in new tests

2017-10-17 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Oct 17 06:45:20 2017
New Revision: 315997

URL: http://llvm.org/viewvc/llvm-project?rev=315997&view=rev
Log:
fix shadowing warnings in new tests

Modified:
libcxx/trunk/test/support/emplace_constructible.h

Modified: libcxx/trunk/test/support/emplace_constructible.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/emplace_constructible.h?rev=315997&r1=315996&r2=315997&view=diff
==
--- libcxx/trunk/test/support/emplace_constructible.h (original)
+++ libcxx/trunk/test/support/emplace_constructible.h Tue Oct 17 06:45:20 2017
@@ -7,7 +7,7 @@
 template 
 struct EmplaceConstructible {
   T value;
-  explicit EmplaceConstructible(T value) : value(value) {}
+  explicit EmplaceConstructible(T xvalue) : value(xvalue) {}
   EmplaceConstructible(EmplaceConstructible const&) = delete;
 };
 
@@ -15,7 +15,7 @@ template 
 struct EmplaceConstructibleAndMoveInsertable {
   int copied = 0;
   T value;
-  explicit EmplaceConstructibleAndMoveInsertable(T value) : value(value) {}
+  explicit EmplaceConstructibleAndMoveInsertable(T xvalue) : value(xvalue) {}
 
   EmplaceConstructibleAndMoveInsertable(
   EmplaceConstructibleAndMoveInsertable&& Other)
@@ -27,7 +27,7 @@ struct EmplaceConstructibleAndMoveable {
   int copied = 0;
   int assigned = 0;
   T value;
-  explicit EmplaceConstructibleAndMoveable(T value) noexcept : value(value) {}
+  explicit EmplaceConstructibleAndMoveable(T xvalue) noexcept : value(xvalue) 
{}
 
   EmplaceConstructibleAndMoveable(EmplaceConstructibleAndMoveable&& Other)
   noexcept : copied(Other.copied + 1),


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


[PATCH] D34272: [Tooling] A new framework for executing clang frontend actions.

2017-10-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 119314.
ioeric added a comment.

- Fix broken unit tests when they are run in threads in the same process.


https://reviews.llvm.org/D34272

Files:
  include/clang/Tooling/CommonOptionsParser.h
  include/clang/Tooling/Execution.h
  include/clang/Tooling/ToolExecutorPluginRegistry.h
  include/clang/Tooling/Tooling.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/CommonOptionsParser.cpp
  lib/Tooling/Execution.cpp
  lib/Tooling/Tooling.cpp
  unittests/Tooling/ToolingTest.cpp

Index: unittests/Tooling/ToolingTest.cpp
===
--- unittests/Tooling/ToolingTest.cpp
+++ unittests/Tooling/ToolingTest.cpp
@@ -10,11 +10,14 @@
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclGroup.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Execution.h"
+#include "clang/Tooling/ToolExecutorPluginRegistry.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Config/llvm-config.h"
@@ -60,6 +63,60 @@
  private:
   bool * const FoundTopLevelDecl;
 };
+
+// This traverses the AST and outputs function name as key and "1" as value for
+// each function declaration.
+class ASTConsumerWithResult
+: public ASTConsumer,
+  public RecursiveASTVisitor {
+public:
+  using ASTVisitor = RecursiveASTVisitor;
+
+  explicit ASTConsumerWithResult(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+  void HandleTranslationUnit(clang::ASTContext &Context) override {
+TraverseDecl(Context.getTranslationUnitDecl());
+  }
+
+  bool TraverseFunctionDecl(clang::FunctionDecl *Decl) {
+Context->getToolResults()->addResult(Decl->getNameAsString(), "1");
+return ASTVisitor::TraverseFunctionDecl(Decl);
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultAction : public ASTFrontendAction {
+public:
+  explicit ReportResultAction(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+protected:
+  std::unique_ptr
+  CreateASTConsumer(clang::CompilerInstance &compiler,
+llvm::StringRef /* dummy */) override {
+std::unique_ptr ast_consumer{
+new ASTConsumerWithResult(Context)};
+return ast_consumer;
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultActionFactory : public FrontendActionFactory {
+public:
+  ReportResultActionFactory(ExecutionContext *Context) : Context(Context) {}
+  FrontendAction *create() override { return new ReportResultAction(Context); }
+
+private:
+  ExecutionContext *const Context;
+};
+
 } // end namespace
 
 TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) {
@@ -533,5 +590,169 @@
 }
 #endif
 
+inline llvm::Error make_string_error(const llvm::Twine &Message) {
+  return llvm::make_error(Message,
+ llvm::inconvertibleErrorCode());
+}
+
+class TestToolExecutor : public ToolExecutor {
+public:
+  static const char *ExecutorName;
+
+  TestToolExecutor(std::unique_ptr Options)
+  : OptionsParser(std::move(Options)) {}
+
+  llvm::StringRef getExecutorName() const override { return ExecutorName; }
+
+  llvm::Error execute(const ExecutionConfig &) override {
+return llvm::Error::success();
+  }
+
+  ExecutionContext *getExecutionContext() override { return nullptr; };
+
+  llvm::ArrayRef getSourcePaths() const {
+return OptionsParser->getSourcePathList();
+  }
+
+  void mapVirtualFile(StringRef FilePath, StringRef Content) override {
+VFS[FilePath] = Content;
+  }
+
+private:
+  std::unique_ptr OptionsParser;
+  std::string SourcePaths;
+  std::map VFS;
+};
+
+const char *TestToolExecutor::ExecutorName = "TestToolExecutor";
+
+class TestToolExecutorPlugin : public ToolExecutorPlugin {
+public:
+  llvm::Expected>
+  create(int &argc, const char **argv,
+ llvm::cl::OptionCategory &Category) override {
+// Depending on the test runner, test cases might run in different threads
+// in the same process, so we put test options in the stack and manually
+// remove it from the global registry later so that tests do not interfere
+// with each other.
+llvm::cl::opt TestExecutor("test_executor",
+ llvm::cl::desc("Use TestToolExecutor"));
+auto OptionsParser = llvm::make_unique(
+argc, argv, Category, llvm::cl::OneOrMore, /*Overview=*/nullptr,
+/*ExitOnError=*/false);
+TestExecutor.removeArgument();
+if (OptionsParser->hasError())
+  return make_string_error("[TestToolExecutorPlugin] " +
+   OptionsParser->getErrorMessage());
+if (!TestExecutor)
+  return make_string_error(
+  

[PATCH] D38835: [refactor] selection: new CodeRangeASTSelection represents a set of selected consecutive statements

2017-10-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: unittests/Tooling/ASTSelectionTest.cpp:688
+  Source, {2, 2}, None,
+  [](SourceRange SelectionRange, Optional Node) {
+EXPECT_TRUE(Node);

arphaman wrote:
> hokein wrote:
> > I'm a bit confused here, if the selection range is none/empty,  shouldn't 
> > `SelectedASTNode` be empty?
> > 
> > If this behavior is intended, I'd suggest documenting it in 
> > `findSelectedASTNodesWithRange`.
> No, the AST selection will work even with a cursor location, hence it won't 
> be empty.
> 
> However, the CodeRangeASTSelection requires a non-empty selection range, so 
> it won't work with just cursors.
I see, thanks.

> the AST selection will work even with a cursor location, hence it won't be 
> empty.

Is this documented somewhere in the code? I couldn't find any comments in the 
definition of `findSelectedASTNodesWithRange` or `findSelectedASTNodes` in this 
file.  Would be nice to document it although this is a test API, so that it 
won't confuse future code readers.


Repository:
  rL LLVM

https://reviews.llvm.org/D38835



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


r315999 - [clang-rename] Rename enum.

2017-10-17 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Oct 17 07:14:41 2017
New Revision: 315999

URL: http://llvm.org/viewvc/llvm-project?rev=315999&view=rev
Log:
[clang-rename] Rename enum.

Summary:
* Add unit tests for renaming enum.
* Support unscoped enum constants in expressions.

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, mgorny, cfe-commits

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

Added:
cfe/trunk/unittests/Rename/RenameEnumTest.cpp
Modified:
cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
cfe/trunk/unittests/Rename/CMakeLists.txt

Modified: cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp?rev=315999&r1=315998&r2=315999&view=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp Tue Oct 17 
07:14:41 2017
@@ -196,13 +196,46 @@ public:
 const NamedDecl *Decl = Expr->getFoundDecl();
 // Get the underlying declaration of the shadow declaration introduced by a
 // using declaration.
-if (auto* UsingShadow = llvm::dyn_cast(Decl)) {
+if (auto *UsingShadow = llvm::dyn_cast(Decl)) {
   Decl = UsingShadow->getTargetDecl();
 }
 
+auto BeginLoc = Expr->getLocStart();
+auto EndLoc = Expr->getLocEnd();
+// In case of renaming an enum declaration, we have to explicitly handle
+// unscoped enum constants referenced in expressions (e.g.
+// "auto r = ns1::ns2::Green" where Green is an enum constant of an 
unscoped
+// enum decl "ns1::ns2::Color") as these enum constants cannot be caught by
+// TypeLoc.
+if (const auto *T = llvm::dyn_cast(Decl)) {
+  // FIXME: Handle the enum constant without prefix qualifiers (`a = 
Green`)
+  // when renaming an unscoped enum declaration with a new namespace.
+  if (!Expr->hasQualifier())
+return true;
+
+  if (const auto *ED =
+  llvm::dyn_cast_or_null(getClosestAncestorDecl(*T))) {
+if (ED->isScoped())
+  return true;
+Decl = ED;
+  }
+  // The current fix would qualify "ns1::ns2::Green" as
+  // "ns1::ns2::Color::Green".
+  //
+  // Get the EndLoc of the replacement by moving 1 character backward (
+  // to exclude the last '::').
+  //
+  //ns1::ns2::Green;
+  //^  ^^
+  // BeginLoc  |EndLoc of the qualifier
+  //   new EndLoc
+  EndLoc = Expr->getQualifierLoc().getEndLoc().getLocWithOffset(-1);
+  assert(EndLoc.isValid() &&
+ "The enum constant should have prefix qualifers.");
+}
 if (isInUSRSet(Decl)) {
-  RenameInfo Info = {Expr->getSourceRange().getBegin(),
- Expr->getSourceRange().getEnd(),
+  RenameInfo Info = {BeginLoc,
+ EndLoc,
  Decl,
  getClosestAncestorDecl(*Expr),
  Expr->getQualifier(),
@@ -364,10 +397,13 @@ private:
   // Get the supported declaration from a given typeLoc. If the declaration 
type
   // is not supported, returns nullptr.
   //
-  // FIXME: support more types, e.g. enum, type alias.
+  // FIXME: support more types, e.g. type alias.
   const NamedDecl *getSupportedDeclFromTypeLoc(TypeLoc Loc) {
 if (const auto *RD = Loc.getType()->getAsCXXRecordDecl())
   return RD;
+if (const auto *ED =
+llvm::dyn_cast_or_null(Loc.getType()->getAsTagDecl()))
+  return ED;
 return nullptr;
   }
 

Modified: cfe/trunk/unittests/Rename/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/CMakeLists.txt?rev=315999&r1=315998&r2=315999&view=diff
==
--- cfe/trunk/unittests/Rename/CMakeLists.txt (original)
+++ cfe/trunk/unittests/Rename/CMakeLists.txt Tue Oct 17 07:14:41 2017
@@ -7,6 +7,7 @@ include_directories(${CLANG_SOURCE_DIR})
 
 add_clang_unittest(ClangRenameTests
   RenameClassTest.cpp
+  RenameEnumTest.cpp
   RenameFunctionTest.cpp
   )
 

Added: cfe/trunk/unittests/Rename/RenameEnumTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Rename/RenameEnumTest.cpp?rev=315999&view=auto
==
--- cfe/trunk/unittests/Rename/RenameEnumTest.cpp (added)
+++ cfe/trunk/unittests/Rename/RenameEnumTest.cpp Tue Oct 17 07:14:41 2017
@@ -0,0 +1,189 @@
+#include "ClangRenameTest.h"
+
+namespace clang {
+namespace clang_rename {
+namespace test {
+namespace {
+
+class RenameEnumTest : public ClangRenameTest {
+public:
+  RenameEnumTest() {
+AppendToHeader(R"(
+#define MACRO(x) x
+namespace a {
+enum A1 { Red };
+enum class A2 { Blue };
+struct C {
+ enum NestedEnum { White };
+

[PATCH] D38989: [clang-rename] Rename enum.

2017-10-17 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL315999: [clang-rename] Rename enum. (authored by hokein).

Repository:
  rL LLVM

https://reviews.llvm.org/D38989

Files:
  cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
  cfe/trunk/unittests/Rename/CMakeLists.txt
  cfe/trunk/unittests/Rename/RenameEnumTest.cpp

Index: cfe/trunk/unittests/Rename/RenameEnumTest.cpp
===
--- cfe/trunk/unittests/Rename/RenameEnumTest.cpp
+++ cfe/trunk/unittests/Rename/RenameEnumTest.cpp
@@ -0,0 +1,189 @@
+#include "ClangRenameTest.h"
+
+namespace clang {
+namespace clang_rename {
+namespace test {
+namespace {
+
+class RenameEnumTest : public ClangRenameTest {
+public:
+  RenameEnumTest() {
+AppendToHeader(R"(
+#define MACRO(x) x
+namespace a {
+enum A1 { Red };
+enum class A2 { Blue };
+struct C {
+ enum NestedEnum { White };
+ enum class NestedScopedEnum { Black };
+};
+namespace d {
+enum A3 { Orange };
+} // namespace d
+enum A4 { Pink };
+} // namespace a
+enum A5 { Green };)");
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(
+RenameEnumTests, RenameEnumTest,
+testing::ValuesIn(std::vector({
+{"void f(a::A2 arg) { a::A2 t = a::A2::Blue; }",
+ "void f(b::B2 arg) { b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"},
+{"void f() { a::A1* t1; }", "void f() { b::B1* t1; }", "a::A1",
+ "b::B1"},
+{"void f() { a::A2* t1; }", "void f() { b::B2* t1; }", "a::A2",
+ "b::B2"},
+{"void f() { enum a::A2 t = a::A2::Blue; }",
+ "void f() { enum b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"},
+{"void f() { enum a::A2 t = a::A2::Blue; }",
+ "void f() { enum b::B2 t = b::B2::Blue; }", "a::A2", "b::B2"},
+
+{"void f() { a::A1 t = a::Red; }", "void f() { b::B1 t = b::B1::Red; }",
+ "a::A1", "b::B1"},
+{"void f() { a::A1 t = a::A1::Red; }",
+ "void f() { b::B1 t = b::B1::Red; }", "a::A1", "b::B1"},
+{"void f() { auto t = a::Red; }", "void f() { auto t = b::B1::Red; }",
+ "a::A1", "b::B1"},
+{"namespace b { void f() { a::A1 t = a::Red; } }",
+ "namespace b { void f() { B1 t = B1::Red; } }", "a::A1", "b::B1"},
+{"void f() { a::d::A3 t = a::d::Orange; }",
+ "void f() { a::b::B3 t = a::b::B3::Orange; }", "a::d::A3", "a::b::B3"},
+{"namespace a { void f() { a::d::A3 t = a::d::Orange; } }",
+ "namespace a { void f() { b::B3 t = b::B3::Orange; } }", "a::d::A3",
+ "a::b::B3"},
+{"void f() { A5 t = Green; }", "void f() { B5 t = Green; }", "A5",
+ "B5"},
+// FIXME: the new namespace qualifier should be added to the unscoped
+// enum constant.
+{"namespace a { void f() { auto t = Green; } }",
+ "namespace a { void f() { auto t = Green; } }", "a::A1", "b::B1"},
+
+// namespace qualifiers
+{"namespace a { void f(A1 a1) {} }",
+ "namespace a { void f(b::B1 a1) {} }", "a::A1", "b::B1"},
+{"namespace a { void f(A2 a2) {} }",
+ "namespace a { void f(b::B2 a2) {} }", "a::A2", "b::B2"},
+{"namespace b { void f(a::A1 a1) {} }",
+ "namespace b { void f(B1 a1) {} }", "a::A1", "b::B1"},
+{"namespace b { void f(a::A2 a2) {} }",
+ "namespace b { void f(B2 a2) {} }", "a::A2", "b::B2"},
+
+// nested enums
+{"void f() { a::C::NestedEnum t = a::C::White; }",
+ "void f() { a::C::NewNestedEnum t = a::C::NewNestedEnum::White; }",
+ "a::C::NestedEnum", "a::C::NewNestedEnum"},
+{"void f() { a::C::NestedScopedEnum t = a::C::NestedScopedEnum::Black; "
+ "}",
+ "void f() { a::C::NewNestedScopedEnum t = "
+ "a::C::NewNestedScopedEnum::Black; }",
+ "a::C::NestedScopedEnum", "a::C::NewNestedScopedEnum"},
+
+// macros
+{"void f(MACRO(a::A1) a1) {}", "void f(MACRO(b::B1) a1) {}", "a::A1",
+ "b::B1"},
+{"void f(MACRO(a::A2) a2) {}", "void f(MACRO(b::B2) a2) {}", "a::A2",
+ "b::B2"},
+{"#define FOO(T, t) T t\nvoid f() { FOO(a::A1, a1); }",
+ "#define FOO(T, t) T t\nvoid f() { FOO(b::B1, a1); }", "a::A1",
+ "b::B1"},
+{"#define FOO(T, t) T t\nvoid f() { FOO(a::A2, a2); }",
+ "#define FOO(T, t) T t\nvoid f() { FOO(b::B2, a2); }", "a::A2",
+ "b::B2"},
+{"#define FOO(n) a::A1 n\nvoid f() { FOO(a1); FOO(a2); }",
+ "#define FOO(n) b::B1 n\nvoid f() { FOO(a1); FOO(a2); }", "a::A1",
+ "b::B1"},
+
+// using and type alias
+{"using a::A1; A1 gA;", "using b::B1; b::B1 gA;", "a::A1", "b::B1"},
+{"using a::A2; A2 gA;", "using b::B2; b::B2 gA;", "a::A2", "b::B2"},
+{"struct S { using T = a::A1; T a_; };",
+ "struct S { using T = b::B1; T a_; };", "a::A1", "b::B1"}

r316000 - CodeGen: Fix invalid bitcasts for atomic builtins

2017-10-17 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Tue Oct 17 07:19:29 2017
New Revision: 316000

URL: http://llvm.org/viewvc/llvm-project?rev=316000&view=rev
Log:
CodeGen: Fix invalid bitcasts for atomic builtins

Currently clang assumes the temporary variables emitted during
codegen of atomic builtins have address space 0, which
is not true for target triple amdgcn---amdgiz and causes invalid
bitcasts.

This patch fixes that.

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

Modified:
cfe/trunk/lib/CodeGen/CGAtomic.cpp
cfe/trunk/test/CodeGenOpenCL/atomic-ops.cl

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=316000&r1=315999&r2=316000&view=diff
==
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Tue Oct 17 07:19:29 2017
@@ -1226,7 +1226,8 @@ RValue CodeGenFunction::EmitAtomicExpr(A
   return RValue::get(nullptr);
 
 return convertTempToRValue(
-Builder.CreateBitCast(Dest, ConvertTypeForMem(RValTy)->getPointerTo()),
+Builder.CreateBitCast(Dest, ConvertTypeForMem(RValTy)->getPointerTo(
+Dest.getAddressSpace())),
 RValTy, E->getExprLoc());
   }
 
@@ -1298,7 +1299,8 @@ RValue CodeGenFunction::EmitAtomicExpr(A
 
   assert(Atomics.getValueSizeInBits() <= Atomics.getAtomicSizeInBits());
   return convertTempToRValue(
-  Builder.CreateBitCast(Dest, ConvertTypeForMem(RValTy)->getPointerTo()),
+  Builder.CreateBitCast(Dest, ConvertTypeForMem(RValTy)->getPointerTo(
+  Dest.getAddressSpace())),
   RValTy, E->getExprLoc());
 }
 

Modified: cfe/trunk/test/CodeGenOpenCL/atomic-ops.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/atomic-ops.cl?rev=316000&r1=315999&r2=316000&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/atomic-ops.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/atomic-ops.cl Tue Oct 17 07:19:29 2017
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -O0 -o - 
-triple=amdgcn-amd-amdhsa-opencl | opt -instnamer -S | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -O0 -o - 
-triple=amdgcn-amd-amdhsa-amdgizcl | opt -instnamer -S | FileCheck %s
 
 // Also test serialization of atomic operations here, to avoid duplicating the 
test.
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-pch -O0 -o %t 
-triple=amdgcn-amd-amdhsa-opencl
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -include-pch %t -O0 
-triple=amdgcn-amd-amdhsa-opencl -emit-llvm -o - | opt -instnamer -S | 
FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-pch -O0 -o %t 
-triple=amdgcn-amd-amdhsa-amdgizcl
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -include-pch %t -O0 
-triple=amdgcn-amd-amdhsa-amdgizcl -emit-llvm -o - | opt -instnamer -S | 
FileCheck %s
 
 #ifndef ALREADY_INCLUDED
 #define ALREADY_INCLUDED
@@ -32,22 +32,22 @@ atomic_int j;
 
 void fi1(atomic_int *i) {
   // CHECK-LABEL: @fi1
-  // CHECK: load atomic i32, i32 addrspace(4)* %{{[.0-9A-Z_a-z]+}} 
syncscope("workgroup") seq_cst
+  // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} syncscope("workgroup") 
seq_cst
   int x = __opencl_atomic_load(i, memory_order_seq_cst, 
memory_scope_work_group);
 
-  // CHECK: load atomic i32, i32 addrspace(4)* %{{[.0-9A-Z_a-z]+}} 
syncscope("agent") seq_cst
+  // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} syncscope("agent") 
seq_cst
   x = __opencl_atomic_load(i, memory_order_seq_cst, memory_scope_device);
 
-  // CHECK: load atomic i32, i32 addrspace(4)* %{{[.0-9A-Z_a-z]+}} seq_cst
+  // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} seq_cst
   x = __opencl_atomic_load(i, memory_order_seq_cst, 
memory_scope_all_svm_devices);
 
-  // CHECK: load atomic i32, i32 addrspace(4)* %{{[.0-9A-Z_a-z]+}} 
syncscope("subgroup") seq_cst
+  // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} syncscope("subgroup") 
seq_cst
   x = __opencl_atomic_load(i, memory_order_seq_cst, memory_scope_sub_group);
 }
 
 void fi2(atomic_int *i) {
   // CHECK-LABEL: @fi2
-  // CHECK: store atomic i32 %{{[.0-9A-Z_a-z]+}}, i32 addrspace(4)* 
%{{[.0-9A-Z_a-z]+}} syncscope("workgroup") seq_cst
+  // CHECK: store atomic i32 %{{[.0-9A-Z_a-z]+}}, i32* %{{[.0-9A-Z_a-z]+}} 
syncscope("workgroup") seq_cst
   __opencl_atomic_store(i, 1, memory_order_seq_cst, memory_scope_work_group);
 }
 
@@ -56,7 +56,7 @@ void test_addr(global atomic_int *ig, pr
   // CHECK: store atomic i32 %{{[.0-9A-Z_a-z]+}}, i32 addrspace(1)* 
%{{[.0-9A-Z_a-z]+}} syncscope("workgroup") seq_cst
   __opencl_atomic_store(ig, 1, memory_order_seq_cst, memory_scope_work_group);
 
-  // CHECK: store atomic i32 %{{[.0-9A-Z_a-z]+}}, i32* %{{[.0-9A-Z_a-z]+}} 
syncscope("workgroup") seq_cst
+  // CHECK: store atomic i32 %{{[.0-9A-Z_a-z]+}}, i32 addrspace(5)* 
%{{[.0-9A-Z_a-z]+}} syncscope("workgroup") seq_cst
   __opencl_atomic

[PATCH] D38966: CodeGen: Fix invalid bitcasts for atomic builtins

2017-10-17 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316000: CodeGen: Fix invalid bitcasts for atomic builtins 
(authored by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D38966?vs=119182&id=119319#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38966

Files:
  cfe/trunk/lib/CodeGen/CGAtomic.cpp
  cfe/trunk/test/CodeGenOpenCL/atomic-ops.cl

Index: cfe/trunk/lib/CodeGen/CGAtomic.cpp
===
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp
@@ -1226,7 +1226,8 @@
   return RValue::get(nullptr);
 
 return convertTempToRValue(
-Builder.CreateBitCast(Dest, ConvertTypeForMem(RValTy)->getPointerTo()),
+Builder.CreateBitCast(Dest, ConvertTypeForMem(RValTy)->getPointerTo(
+Dest.getAddressSpace())),
 RValTy, E->getExprLoc());
   }
 
@@ -1298,7 +1299,8 @@
 
   assert(Atomics.getValueSizeInBits() <= Atomics.getAtomicSizeInBits());
   return convertTempToRValue(
-  Builder.CreateBitCast(Dest, ConvertTypeForMem(RValTy)->getPointerTo()),
+  Builder.CreateBitCast(Dest, ConvertTypeForMem(RValTy)->getPointerTo(
+  Dest.getAddressSpace())),
   RValTy, E->getExprLoc());
 }
 
Index: cfe/trunk/test/CodeGenOpenCL/atomic-ops.cl
===
--- cfe/trunk/test/CodeGenOpenCL/atomic-ops.cl
+++ cfe/trunk/test/CodeGenOpenCL/atomic-ops.cl
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -O0 -o - -triple=amdgcn-amd-amdhsa-opencl | opt -instnamer -S | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -O0 -o - -triple=amdgcn-amd-amdhsa-amdgizcl | opt -instnamer -S | FileCheck %s
 
 // Also test serialization of atomic operations here, to avoid duplicating the test.
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-pch -O0 -o %t -triple=amdgcn-amd-amdhsa-opencl
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -include-pch %t -O0 -triple=amdgcn-amd-amdhsa-opencl -emit-llvm -o - | opt -instnamer -S | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-pch -O0 -o %t -triple=amdgcn-amd-amdhsa-amdgizcl
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -include-pch %t -O0 -triple=amdgcn-amd-amdhsa-amdgizcl -emit-llvm -o - | opt -instnamer -S | FileCheck %s
 
 #ifndef ALREADY_INCLUDED
 #define ALREADY_INCLUDED
@@ -32,58 +32,58 @@
 
 void fi1(atomic_int *i) {
   // CHECK-LABEL: @fi1
-  // CHECK: load atomic i32, i32 addrspace(4)* %{{[.0-9A-Z_a-z]+}} syncscope("workgroup") seq_cst
+  // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} syncscope("workgroup") seq_cst
   int x = __opencl_atomic_load(i, memory_order_seq_cst, memory_scope_work_group);
 
-  // CHECK: load atomic i32, i32 addrspace(4)* %{{[.0-9A-Z_a-z]+}} syncscope("agent") seq_cst
+  // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} syncscope("agent") seq_cst
   x = __opencl_atomic_load(i, memory_order_seq_cst, memory_scope_device);
 
-  // CHECK: load atomic i32, i32 addrspace(4)* %{{[.0-9A-Z_a-z]+}} seq_cst
+  // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} seq_cst
   x = __opencl_atomic_load(i, memory_order_seq_cst, memory_scope_all_svm_devices);
 
-  // CHECK: load atomic i32, i32 addrspace(4)* %{{[.0-9A-Z_a-z]+}} syncscope("subgroup") seq_cst
+  // CHECK: load atomic i32, i32* %{{[.0-9A-Z_a-z]+}} syncscope("subgroup") seq_cst
   x = __opencl_atomic_load(i, memory_order_seq_cst, memory_scope_sub_group);
 }
 
 void fi2(atomic_int *i) {
   // CHECK-LABEL: @fi2
-  // CHECK: store atomic i32 %{{[.0-9A-Z_a-z]+}}, i32 addrspace(4)* %{{[.0-9A-Z_a-z]+}} syncscope("workgroup") seq_cst
+  // CHECK: store atomic i32 %{{[.0-9A-Z_a-z]+}}, i32* %{{[.0-9A-Z_a-z]+}} syncscope("workgroup") seq_cst
   __opencl_atomic_store(i, 1, memory_order_seq_cst, memory_scope_work_group);
 }
 
 void test_addr(global atomic_int *ig, private atomic_int *ip, local atomic_int *il) {
   // CHECK-LABEL: @test_addr
   // CHECK: store atomic i32 %{{[.0-9A-Z_a-z]+}}, i32 addrspace(1)* %{{[.0-9A-Z_a-z]+}} syncscope("workgroup") seq_cst
   __opencl_atomic_store(ig, 1, memory_order_seq_cst, memory_scope_work_group);
 
-  // CHECK: store atomic i32 %{{[.0-9A-Z_a-z]+}}, i32* %{{[.0-9A-Z_a-z]+}} syncscope("workgroup") seq_cst
+  // CHECK: store atomic i32 %{{[.0-9A-Z_a-z]+}}, i32 addrspace(5)* %{{[.0-9A-Z_a-z]+}} syncscope("workgroup") seq_cst
   __opencl_atomic_store(ip, 1, memory_order_seq_cst, memory_scope_work_group);
 
   // CHECK: store atomic i32 %{{[.0-9A-Z_a-z]+}}, i32 addrspace(3)* %{{[.0-9A-Z_a-z]+}} syncscope("workgroup") seq_cst
   __opencl_atomic_store(il, 1, memory_order_seq_cst, memory_scope_work_group);
 }
 
 void fi3(atomic_int *i, atomic_uint *ui) {
   // CHECK-LABEL: @fi3
-  // CHECK: atomicrmw and i32 addrspace(4)* %{{[.0-9A-Z_a-z]+}}, i32 %{{[.0-9A-Z_a-z]+}} syncscope("workgroup") seq_cst
+  // CHECK: atomicrmw and i32* %{{[.0-9A-Z_a-z]+}}, i32 %{{[.0-9A-Z_a-z]+}} syncscope("workgroup"

r316001 - [OpenMP] Implement omp_is_initial_device() as builtin

2017-10-17 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Tue Oct 17 07:28:14 2017
New Revision: 316001

URL: http://llvm.org/viewvc/llvm-project?rev=316001&view=rev
Log:
[OpenMP] Implement omp_is_initial_device() as builtin

This allows to return the static value that we know at compile time.

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

Added:
cfe/trunk/test/OpenMP/is_initial_device.c
Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/include/clang/Basic/Builtins.h
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Basic/Builtins.cpp

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=316001&r1=316000&r2=316001&view=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Tue Oct 17 07:28:14 2017
@@ -1434,6 +1434,9 @@ LANGBUILTIN(__builtin_load_halff, "fhC*"
 BUILTIN(__builtin_os_log_format_buffer_size, "zcC*.", "p:0:nut")
 BUILTIN(__builtin_os_log_format, "v*v*cC*.", "p:0:nt")
 
+// OpenMP 4.0
+LANGBUILTIN(omp_is_initial_device, "i", "nc", OMP_LANG)
+
 // Builtins for XRay
 BUILTIN(__xray_customevent, "vcC*z", "")
 

Modified: cfe/trunk/include/clang/Basic/Builtins.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.h?rev=316001&r1=316000&r2=316001&view=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.h (original)
+++ cfe/trunk/include/clang/Basic/Builtins.h Tue Oct 17 07:28:14 2017
@@ -38,6 +38,7 @@ enum LanguageID {
   MS_LANG = 0x10, // builtin requires MS mode.
   OCLC20_LANG = 0x20, // builtin for OpenCL C 2.0 only.
   OCLC1X_LANG = 0x40, // builtin for OpenCL C 1.x only.
+  OMP_LANG = 0x80,// builtin requires OpenMP.
   ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
   ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG,  // builtin requires GNU mode.
   ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG,// builtin requires MS mode.

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=316001&r1=316000&r2=316001&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Oct 17 07:28:14 2017
@@ -7929,6 +7929,9 @@ bool IntExprEvaluator::VisitBuiltinCallE
 return BuiltinOp == Builtin::BI__atomic_always_lock_free ?
 Success(0, E) : Error(E);
   }
+  case Builtin::BIomp_is_initial_device:
+// We can decide statically which value the runtime would return if called.
+return Success(Info.getLangOpts().OpenMPIsDevice ? 0 : 1, E);
   }
 }
 

Modified: cfe/trunk/lib/Basic/Builtins.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Builtins.cpp?rev=316001&r1=316000&r2=316001&view=diff
==
--- cfe/trunk/lib/Basic/Builtins.cpp (original)
+++ cfe/trunk/lib/Basic/Builtins.cpp Tue Oct 17 07:28:14 2017
@@ -75,8 +75,9 @@ bool Builtin::Context::builtinIsSupporte
   (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES) == 
OCLC20_LANG;
   bool OclCUnsupported = !LangOpts.OpenCL &&
  (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES);
+  bool OpenMPUnsupported = !LangOpts.OpenMP && BuiltinInfo.Langs == OMP_LANG;
   return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported 
&&
- !OclC1Unsupported && !OclC2Unsupported &&
+ !OclC1Unsupported && !OclC2Unsupported && !OpenMPUnsupported &&
  !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported;
 }
 

Added: cfe/trunk/test/OpenMP/is_initial_device.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/is_initial_device.c?rev=316001&view=auto
==
--- cfe/trunk/test/OpenMP/is_initial_device.c (added)
+++ cfe/trunk/test/OpenMP/is_initial_device.c Tue Oct 17 07:28:14 2017
@@ -0,0 +1,36 @@
+// REQUIRES: powerpc-registered-target
+
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple powerpc64le-unknown-unknown 
-fopenmp-targets=powerpc64le-unknown-unknown \
+// RUN:-emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x ir -triple powerpc64le-unknown-unknown 
-emit-llvm \
+// RUN: %t-ppc-host.bc -o - | FileCheck %s -check-prefixes 
HOST,OUTLINED
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple powerpc64le-unknown-unknown 
-emit-llvm -fopenmp-is-device \
+// RUN: %s -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | 
FileCheck %s -check-prefixes DEVICE,OUTLINED
+
+// expected-no-diagnostics
+int check() {
+  int host = omp_is_initial_device();
+  int device;
+#pragma omp target map(tofrom: device)
+  {
+device 

[PATCH] D38968: [OpenMP] Implement omp_is_initial_device() as builtin

2017-10-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316001: [OpenMP] Implement omp_is_initial_device() as 
builtin (authored by Hahnfeld).

Changed prior to commit:
  https://reviews.llvm.org/D38968?vs=119190&id=119320#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38968

Files:
  cfe/trunk/include/clang/Basic/Builtins.def
  cfe/trunk/include/clang/Basic/Builtins.h
  cfe/trunk/lib/AST/ExprConstant.cpp
  cfe/trunk/lib/Basic/Builtins.cpp
  cfe/trunk/test/OpenMP/is_initial_device.c


Index: cfe/trunk/include/clang/Basic/Builtins.h
===
--- cfe/trunk/include/clang/Basic/Builtins.h
+++ cfe/trunk/include/clang/Basic/Builtins.h
@@ -38,6 +38,7 @@
   MS_LANG = 0x10, // builtin requires MS mode.
   OCLC20_LANG = 0x20, // builtin for OpenCL C 2.0 only.
   OCLC1X_LANG = 0x40, // builtin for OpenCL C 1.x only.
+  OMP_LANG = 0x80,// builtin requires OpenMP.
   ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
   ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG,  // builtin requires GNU mode.
   ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG,// builtin requires MS mode.
Index: cfe/trunk/include/clang/Basic/Builtins.def
===
--- cfe/trunk/include/clang/Basic/Builtins.def
+++ cfe/trunk/include/clang/Basic/Builtins.def
@@ -1434,6 +1434,9 @@
 BUILTIN(__builtin_os_log_format_buffer_size, "zcC*.", "p:0:nut")
 BUILTIN(__builtin_os_log_format, "v*v*cC*.", "p:0:nt")
 
+// OpenMP 4.0
+LANGBUILTIN(omp_is_initial_device, "i", "nc", OMP_LANG)
+
 // Builtins for XRay
 BUILTIN(__xray_customevent, "vcC*z", "")
 
Index: cfe/trunk/test/OpenMP/is_initial_device.c
===
--- cfe/trunk/test/OpenMP/is_initial_device.c
+++ cfe/trunk/test/OpenMP/is_initial_device.c
@@ -0,0 +1,36 @@
+// REQUIRES: powerpc-registered-target
+
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple powerpc64le-unknown-unknown 
-fopenmp-targets=powerpc64le-unknown-unknown \
+// RUN:-emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x ir -triple powerpc64le-unknown-unknown 
-emit-llvm \
+// RUN: %t-ppc-host.bc -o - | FileCheck %s -check-prefixes 
HOST,OUTLINED
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple powerpc64le-unknown-unknown 
-emit-llvm -fopenmp-is-device \
+// RUN: %s -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | 
FileCheck %s -check-prefixes DEVICE,OUTLINED
+
+// expected-no-diagnostics
+int check() {
+  int host = omp_is_initial_device();
+  int device;
+#pragma omp target map(tofrom: device)
+  {
+device = omp_is_initial_device();
+  }
+
+  return host + device;
+}
+
+// The host should get a value of 1:
+// HOST: define{{.*}} @check()
+// HOST: [[HOST:%.*]] = alloca i32
+// HOST: store i32 1, i32* [[HOST]]
+
+// OUTLINED: define{{.*}} @{{.*}}omp_offloading{{.*}}(i32*{{.*}} 
[[DEVICE_ARGUMENT:%.*]])
+// OUTLINED: [[DEVICE_ADDR_STORAGE:%.*]] = alloca i32*
+// OUTLINED: store i32* [[DEVICE_ARGUMENT]], i32** [[DEVICE_ADDR_STORAGE]]
+// OUTLINED: [[DEVICE_ADDR:%.*]] = load i32*, i32** [[DEVICE_ADDR_STORAGE]]
+
+// The outlined function that is called as fallback also runs on the host:
+// HOST: store i32 1, i32* [[DEVICE_ADDR]]
+
+// The device should get a value of 0:
+// DEVICE: store i32 0, i32* [[DEVICE_ADDR]]
Index: cfe/trunk/lib/AST/ExprConstant.cpp
===
--- cfe/trunk/lib/AST/ExprConstant.cpp
+++ cfe/trunk/lib/AST/ExprConstant.cpp
@@ -7929,6 +7929,9 @@
 return BuiltinOp == Builtin::BI__atomic_always_lock_free ?
 Success(0, E) : Error(E);
   }
+  case Builtin::BIomp_is_initial_device:
+// We can decide statically which value the runtime would return if called.
+return Success(Info.getLangOpts().OpenMPIsDevice ? 0 : 1, E);
   }
 }
 
Index: cfe/trunk/lib/Basic/Builtins.cpp
===
--- cfe/trunk/lib/Basic/Builtins.cpp
+++ cfe/trunk/lib/Basic/Builtins.cpp
@@ -75,8 +75,9 @@
   (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES) == 
OCLC20_LANG;
   bool OclCUnsupported = !LangOpts.OpenCL &&
  (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES);
+  bool OpenMPUnsupported = !LangOpts.OpenMP && BuiltinInfo.Langs == OMP_LANG;
   return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported 
&&
- !OclC1Unsupported && !OclC2Unsupported &&
+ !OclC1Unsupported && !OclC2Unsupported && !OpenMPUnsupported &&
  !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported;
 }
 


Index: cfe/trunk/include/clang/Basic/Builtins.h
===
--- cfe/trunk/include/clang/Basic/Builtins.h
+++ cfe/trunk/include/clang/Basic/Builtins.h
@@ -38,6 +38,7 @@
   MS_LANG = 0x10, // builtin requires MS m

[PATCH] D34272: [Tooling] A new framework for executing clang frontend actions.

2017-10-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 119325.
ioeric marked 2 inline comments as done.
ioeric added a comment.

- Move StandaloneToolExecutor into a separate header; added ExecutionTest.cpp.


https://reviews.llvm.org/D34272

Files:
  include/clang/Tooling/CommonOptionsParser.h
  include/clang/Tooling/Execution.h
  include/clang/Tooling/StandaloneExecution.h
  include/clang/Tooling/ToolExecutorPluginRegistry.h
  include/clang/Tooling/Tooling.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/CommonOptionsParser.cpp
  lib/Tooling/Execution.cpp
  lib/Tooling/StandaloneExecution.cpp
  lib/Tooling/Tooling.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/ExecutionTest.cpp

Index: unittests/Tooling/ExecutionTest.cpp
===
--- /dev/null
+++ unittests/Tooling/ExecutionTest.cpp
@@ -0,0 +1,251 @@
+//===- unittest/Tooling/ExecutionTest.cpp - Tool execution tests. ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Execution.h"
+#include "clang/Tooling/StandaloneExecution.h"
+#include "clang/Tooling/ToolExecutorPluginRegistry.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+namespace clang {
+namespace tooling {
+
+namespace {
+
+// This traverses the AST and outputs function name as key and "1" as value for
+// each function declaration.
+class ASTConsumerWithResult
+: public ASTConsumer,
+  public RecursiveASTVisitor {
+public:
+  using ASTVisitor = RecursiveASTVisitor;
+
+  explicit ASTConsumerWithResult(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+  void HandleTranslationUnit(clang::ASTContext &Context) override {
+TraverseDecl(Context.getTranslationUnitDecl());
+  }
+
+  bool TraverseFunctionDecl(clang::FunctionDecl *Decl) {
+Context->getToolResults()->addResult(Decl->getNameAsString(), "1");
+return ASTVisitor::TraverseFunctionDecl(Decl);
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultAction : public ASTFrontendAction {
+public:
+  explicit ReportResultAction(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+protected:
+  std::unique_ptr
+  CreateASTConsumer(clang::CompilerInstance &compiler,
+llvm::StringRef /* dummy */) override {
+std::unique_ptr ast_consumer{
+new ASTConsumerWithResult(Context)};
+return ast_consumer;
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultActionFactory : public FrontendActionFactory {
+public:
+  ReportResultActionFactory(ExecutionContext *Context) : Context(Context) {}
+  FrontendAction *create() override { return new ReportResultAction(Context); }
+
+private:
+  ExecutionContext *const Context;
+};
+
+inline llvm::Error make_string_error(const llvm::Twine &Message) {
+  return llvm::make_error(Message,
+ llvm::inconvertibleErrorCode());
+}
+
+} // namespace
+
+class TestToolExecutor : public ToolExecutor {
+public:
+  static const char *ExecutorName;
+
+  TestToolExecutor(std::unique_ptr Options)
+  : OptionsParser(std::move(Options)) {}
+
+  llvm::StringRef getExecutorName() const override { return ExecutorName; }
+
+  llvm::Error execute(const ExecutionConfig &) override {
+return llvm::Error::success();
+  }
+
+  ExecutionContext *getExecutionContext() override { return nullptr; };
+
+  llvm::ArrayRef getSourcePaths() const {
+return OptionsParser->getSourcePathList();
+  }
+
+  void mapVirtualFile(StringRef FilePath, StringRef Content) override {
+VFS[FilePath] = Content;
+  }
+
+private:
+  std::unique_ptr OptionsParser;
+  std::string SourcePaths;
+  std::map VFS;
+};
+
+const char *TestToolExecutor::ExecutorName = "TestToolExecutor";
+
+class TestToolExecutorPlugin : public ToolExecutorPlugin {
+public:
+  llvm::Expected>
+  create(int &argc, const char **argv,
+ llvm::cl::OptionCategory &Category) override {
+// Depending on the test runner, test cases might run in different threads
+// in the same process, so we put test options in the stack and manually
+// remove it from the global registry later so that tests do not interfere
+// with each other.
+llvm::cl::opt TestExecutor("test_executor",
+ llvm::cl::desc("Use TestToolExecutor"));
+auto OptionsParser = llvm::make_unique(
+argc, argv, Category, llvm::c

[PATCH] D39005: [OpenMP] Clean up variable and function names for NVPTX backend

2017-10-17 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea created this revision.
Herald added a subscriber: jholewinski.

Clean-up variable and function names.


Repository:
  rL LLVM

https://reviews.llvm.org/D39005

Files:
  lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp


Index: lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
===
--- lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
+++ lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
@@ -37,6 +37,8 @@
 
   /// \brief Clean up the name to remove symbols invalid in PTX.
   std::string cleanUpName(StringRef Name);
+  /// Set a clean name, ensuring collisions are avoided.
+  void generateCleanName(Value &V);
 };
 }
 
@@ -50,20 +52,31 @@
 "Assign valid PTX names to globals", false, false)
 
 bool NVPTXAssignValidGlobalNames::runOnModule(Module &M) {
-  for (GlobalVariable &GV : M.globals()) {
-// We are only allowed to rename local symbols.
-if (GV.hasLocalLinkage()) {
-  // setName doesn't do extra work if the name does not change.
-  // Note: this does not create collisions - if setName is asked to set the
-  // name to something that already exists, it adds a proper postfix to
-  // avoid collisions.
-  GV.setName(cleanUpName(GV.getName()));
-}
-  }
+  // We are only allowed to rename local symbols.
+  for (GlobalVariable &GV : M.globals())
+if (GV.hasLocalLinkage())
+  generateCleanName(GV);
+
+  // Clean function symbols.
+  for (auto &FN : M.functions())
+if (FN.hasLocalLinkage())
+  generateCleanName(FN);
 
   return true;
 }
 
+void NVPTXAssignValidGlobalNames::generateCleanName(Value &V) {
+  std::string ValidName;
+  do {
+ValidName = cleanUpName(V.getName());
+// setName doesn't do extra work if the name does not change.
+// Collisions are avoided by adding a suffix (which may yet be unclean in
+// PTX).
+V.setName(ValidName);
+// If there are no collisions return, otherwise clean up the new name.
+  } while (!V.getName().equals(ValidName));
+}
+
 std::string NVPTXAssignValidGlobalNames::cleanUpName(StringRef Name) {
   std::string ValidName;
   raw_string_ostream ValidNameStream(ValidName);


Index: lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
===
--- lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
+++ lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp
@@ -37,6 +37,8 @@
 
   /// \brief Clean up the name to remove symbols invalid in PTX.
   std::string cleanUpName(StringRef Name);
+  /// Set a clean name, ensuring collisions are avoided.
+  void generateCleanName(Value &V);
 };
 }
 
@@ -50,20 +52,31 @@
 "Assign valid PTX names to globals", false, false)
 
 bool NVPTXAssignValidGlobalNames::runOnModule(Module &M) {
-  for (GlobalVariable &GV : M.globals()) {
-// We are only allowed to rename local symbols.
-if (GV.hasLocalLinkage()) {
-  // setName doesn't do extra work if the name does not change.
-  // Note: this does not create collisions - if setName is asked to set the
-  // name to something that already exists, it adds a proper postfix to
-  // avoid collisions.
-  GV.setName(cleanUpName(GV.getName()));
-}
-  }
+  // We are only allowed to rename local symbols.
+  for (GlobalVariable &GV : M.globals())
+if (GV.hasLocalLinkage())
+  generateCleanName(GV);
+
+  // Clean function symbols.
+  for (auto &FN : M.functions())
+if (FN.hasLocalLinkage())
+  generateCleanName(FN);
 
   return true;
 }
 
+void NVPTXAssignValidGlobalNames::generateCleanName(Value &V) {
+  std::string ValidName;
+  do {
+ValidName = cleanUpName(V.getName());
+// setName doesn't do extra work if the name does not change.
+// Collisions are avoided by adding a suffix (which may yet be unclean in
+// PTX).
+V.setName(ValidName);
+// If there are no collisions return, otherwise clean up the new name.
+  } while (!V.getName().equals(ValidName));
+}
+
 std::string NVPTXAssignValidGlobalNames::cleanUpName(StringRef Name) {
   std::string ValidName;
   raw_string_ostream ValidNameStream(ValidName);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38978: [OpenMP] Enable the lowering of implicitly shared variables in OpenMP GPU-offloaded target regions to the GPU shared memory

2017-10-17 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 119327.
gtbercea added a comment.

Eliminate variable and function name clean-up. That has been moved into a 
separate patch: https://reviews.llvm.org/D39005


Repository:
  rL LLVM

https://reviews.llvm.org/D38978

Files:
  include/llvm/CodeGen/TargetPassConfig.h
  lib/CodeGen/TargetPassConfig.cpp
  lib/Target/NVPTX/CMakeLists.txt
  lib/Target/NVPTX/NVPTX.h
  lib/Target/NVPTX/NVPTXAsmPrinter.cpp
  lib/Target/NVPTX/NVPTXFrameLowering.cpp
  lib/Target/NVPTX/NVPTXFunctionDataSharing.cpp
  lib/Target/NVPTX/NVPTXFunctionDataSharing.h
  lib/Target/NVPTX/NVPTXInstrInfo.td
  lib/Target/NVPTX/NVPTXLowerAlloca.cpp
  lib/Target/NVPTX/NVPTXLowerSharedFrameIndicesPass.cpp
  lib/Target/NVPTX/NVPTXRegisterInfo.cpp
  lib/Target/NVPTX/NVPTXRegisterInfo.h
  lib/Target/NVPTX/NVPTXRegisterInfo.td
  lib/Target/NVPTX/NVPTXTargetMachine.cpp
  lib/Target/NVPTX/NVPTXUtilities.cpp
  lib/Target/NVPTX/NVPTXUtilities.h

Index: lib/Target/NVPTX/NVPTXUtilities.h
===
--- lib/Target/NVPTX/NVPTXUtilities.h
+++ lib/Target/NVPTX/NVPTXUtilities.h
@@ -14,6 +14,8 @@
 #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXUTILITIES_H
 #define LLVM_LIB_TARGET_NVPTX_NVPTXUTILITIES_H
 
+#include "NVPTXTargetMachine.h"
+#include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/GlobalVariable.h"
 #include "llvm/IR/IntrinsicInst.h"
@@ -60,6 +62,8 @@
 bool getAlign(const Function &, unsigned index, unsigned &);
 bool getAlign(const CallInst &, unsigned index, unsigned &);
 
+bool ptrIsStored(Value *Ptr);
+
 }
 
 #endif
Index: lib/Target/NVPTX/NVPTXUtilities.cpp
===
--- lib/Target/NVPTX/NVPTXUtilities.cpp
+++ lib/Target/NVPTX/NVPTXUtilities.cpp
@@ -28,6 +28,8 @@
 
 namespace llvm {
 
+#define DEBUG_TYPE "nvptx-utilities"
+
 namespace {
 typedef std::map > key_val_pair_t;
 typedef std::map global_val_annot_t;
@@ -314,4 +316,50 @@
   return false;
 }
 
+/// Returns true if there are any instructions storing
+/// the address of this pointer.
+bool ptrIsStored(Value *Ptr) {
+  SmallVector PointerAliases;
+  PointerAliases.push_back(Ptr);
+
+  SmallVector Users;
+  for (const Use &U : Ptr->uses())
+Users.push_back(U.getUser());
+
+  for (unsigned I = 0; I < Users.size(); ++I) {
+// Get pointer usage
+const User *FU = Users[I];
+
+// Check if Ptr or an alias to it is the destination of the store
+auto SI = dyn_cast(FU);
+if (SI) {
+  for (auto Alias: PointerAliases)
+if (SI->getValueOperand() == Alias)
+  return true;
+  continue;
+}
+
+// TODO: Can loads lead to address being taken?
+// TODO: Can GEPs lead to address being taken?
+
+// Bitcasts increase aliases of the pointer
+auto BI = dyn_cast(FU);
+if (BI) {
+  for (const Use &U : BI->uses())
+Users.push_back(U.getUser());
+  PointerAliases.push_back(BI);
+  continue;
+}
+
+// TODO:
+// There may be other instructions which increase the number
+// of alias values ex. operations on the address of the alloca.
+// The whole alloca'ed memory region needs to be shared if at
+// least one of the values needs to be shared.
+  }
+
+  // Address of the pointer has been stored
+  return false;
+}
+
 } // namespace llvm
Index: lib/Target/NVPTX/NVPTXTargetMachine.cpp
===
--- lib/Target/NVPTX/NVPTXTargetMachine.cpp
+++ lib/Target/NVPTX/NVPTXTargetMachine.cpp
@@ -54,6 +54,7 @@
 void initializeNVPTXLowerAggrCopiesPass(PassRegistry &);
 void initializeNVPTXLowerArgsPass(PassRegistry &);
 void initializeNVPTXLowerAllocaPass(PassRegistry &);
+void initializeNVPTXFunctionDataSharingPass(PassRegistry &);
 
 } // end namespace llvm
 
@@ -72,6 +73,7 @@
   initializeNVPTXAssignValidGlobalNamesPass(PR);
   initializeNVPTXLowerArgsPass(PR);
   initializeNVPTXLowerAllocaPass(PR);
+  initializeNVPTXFunctionDataSharingPass(PR);
   initializeNVPTXLowerAggrCopiesPass(PR);
 }
 
@@ -148,6 +150,7 @@
   bool addInstSelector() override;
   void addPostRegAlloc() override;
   void addMachineSSAOptimization() override;
+  void addMachineSSALowering() override;
 
   FunctionPass *createTargetRegisterAllocator(bool) override;
   void addFastRegAlloc(FunctionPass *RegAllocPass) override;
@@ -248,10 +251,15 @@
   // before the address space inference passes.
   addPass(createNVPTXLowerArgsPass(&getNVPTXTargetMachine()));
   if (getOptLevel() != CodeGenOpt::None) {
+// Add address space inference passes
 addAddressSpaceInferencePasses();
 if (!DisableLoadStoreVectorizer)
   addPass(createLoadStoreVectorizerPass());
 addStraightLineScalarOptimizationPasses();
+  } else {
+// Even when no optimizations are used, we need to lower certain
+// alloca instructions to the appropriate memory type for correctness.
+addPass(createNVPTXFunctionDataSharingPass(&getNVPTXTa

[PATCH] D34272: [Tooling] A new framework for executing clang frontend actions.

2017-10-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 119331.
ioeric marked an inline comment as done.
ioeric added a comment.

- Addressed review comments.


https://reviews.llvm.org/D34272

Files:
  include/clang/Tooling/CommonOptionsParser.h
  include/clang/Tooling/Execution.h
  include/clang/Tooling/StandaloneExecution.h
  include/clang/Tooling/ToolExecutorPluginRegistry.h
  include/clang/Tooling/Tooling.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/CommonOptionsParser.cpp
  lib/Tooling/Execution.cpp
  lib/Tooling/StandaloneExecution.cpp
  lib/Tooling/Tooling.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/ExecutionTest.cpp

Index: unittests/Tooling/ExecutionTest.cpp
===
--- /dev/null
+++ unittests/Tooling/ExecutionTest.cpp
@@ -0,0 +1,251 @@
+//===- unittest/Tooling/ExecutionTest.cpp - Tool execution tests. ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Execution.h"
+#include "clang/Tooling/StandaloneExecution.h"
+#include "clang/Tooling/ToolExecutorPluginRegistry.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+namespace clang {
+namespace tooling {
+
+namespace {
+
+// This traverses the AST and outputs function name as key and "1" as value for
+// each function declaration.
+class ASTConsumerWithResult
+: public ASTConsumer,
+  public RecursiveASTVisitor {
+public:
+  using ASTVisitor = RecursiveASTVisitor;
+
+  explicit ASTConsumerWithResult(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+  void HandleTranslationUnit(clang::ASTContext &Context) override {
+TraverseDecl(Context.getTranslationUnitDecl());
+  }
+
+  bool TraverseFunctionDecl(clang::FunctionDecl *Decl) {
+Context->getToolResults()->addResult(Decl->getNameAsString(), "1");
+return ASTVisitor::TraverseFunctionDecl(Decl);
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultAction : public ASTFrontendAction {
+public:
+  explicit ReportResultAction(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+protected:
+  std::unique_ptr
+  CreateASTConsumer(clang::CompilerInstance &compiler,
+StringRef /* dummy */) override {
+std::unique_ptr ast_consumer{
+new ASTConsumerWithResult(Context)};
+return ast_consumer;
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultActionFactory : public FrontendActionFactory {
+public:
+  ReportResultActionFactory(ExecutionContext *Context) : Context(Context) {}
+  FrontendAction *create() override { return new ReportResultAction(Context); }
+
+private:
+  ExecutionContext *const Context;
+};
+
+inline llvm::Error make_string_error(const llvm::Twine &Message) {
+  return llvm::make_error(Message,
+ llvm::inconvertibleErrorCode());
+}
+
+} // namespace
+
+class TestToolExecutor : public ToolExecutor {
+public:
+  static const char *ExecutorName;
+
+  TestToolExecutor(std::unique_ptr Options)
+  : OptionsParser(std::move(Options)) {}
+
+  StringRef getExecutorName() const override { return ExecutorName; }
+
+  llvm::Error execute(const ExecutionConfig &) override {
+return llvm::Error::success();
+  }
+
+  ExecutionContext *getExecutionContext() override { return nullptr; };
+
+  llvm::ArrayRef getSourcePaths() const {
+return OptionsParser->getSourcePathList();
+  }
+
+  void mapVirtualFile(StringRef FilePath, StringRef Content) override {
+VFS[FilePath] = Content;
+  }
+
+private:
+  std::unique_ptr OptionsParser;
+  std::string SourcePaths;
+  std::map VFS;
+};
+
+const char *TestToolExecutor::ExecutorName = "TestToolExecutor";
+
+class TestToolExecutorPlugin : public ToolExecutorPlugin {
+public:
+  llvm::Expected>
+  create(int &argc, const char **argv,
+ llvm::cl::OptionCategory &Category) override {
+// Depending on the test runner, test cases might run in different threads
+// in the same process, so we put test options in the stack and manually
+// remove it from the global registry later so that tests do not interfere
+// with each other.
+llvm::cl::opt TestExecutor("test_executor",
+ llvm::cl::desc("Use TestToolExecutor"));
+auto OptionsParser = llvm::make_unique(
+argc, argv, Category, llvm::cl::OneOrMore, /*Overview=*/nullptr,
+/*ExitOnError=*/f

[PATCH] D34272: [Tooling] A new framework for executing clang frontend actions.

2017-10-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Thanks for the review!




Comment at: include/clang/Tooling/CommonOptionsParser.h:116
+  bool HasError;
+  std::string ErrorMessage;
   std::unique_ptr Compilations;

arphaman wrote:
> Would it be better to have an `llvm::Error' instead of the two fields?
It would make the code a bit more complicated... we would need to convert 
between `Error` and strings a few times here and in the user code.



Comment at: include/clang/Tooling/Execution.h:76
+private:
+  ToolResults *Results;
+};

arphaman wrote:
> Why not `unique_ptr`/`shared_ptr`? Who owns the results?
The context creator owns the results. Here we only store a reference.



Comment at: include/clang/Tooling/Execution.h:136
+/// TUs in sequence.
+class StandaloneToolExecutor : public ToolExecutor {
+public:

arphaman wrote:
> Maybe this class and `InMemoryToolResults` should be in a separate header?
Moved `StandaloneToolExecutor` into a separate header. I am keeping 
`InMemoryToolResults` here since it might be used by other executors.


https://reviews.llvm.org/D34272



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


[PATCH] D34272: [Tooling] A new framework for executing clang frontend actions.

2017-10-17 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 119337.
ioeric added a comment.

- Minor cleanup in tests.


https://reviews.llvm.org/D34272

Files:
  include/clang/Tooling/CommonOptionsParser.h
  include/clang/Tooling/Execution.h
  include/clang/Tooling/StandaloneExecution.h
  include/clang/Tooling/ToolExecutorPluginRegistry.h
  include/clang/Tooling/Tooling.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/CommonOptionsParser.cpp
  lib/Tooling/Execution.cpp
  lib/Tooling/StandaloneExecution.cpp
  lib/Tooling/Tooling.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/ExecutionTest.cpp

Index: unittests/Tooling/ExecutionTest.cpp
===
--- /dev/null
+++ unittests/Tooling/ExecutionTest.cpp
@@ -0,0 +1,249 @@
+//===- unittest/Tooling/ExecutionTest.cpp - Tool execution tests. ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Execution.h"
+#include "clang/Tooling/StandaloneExecution.h"
+#include "clang/Tooling/ToolExecutorPluginRegistry.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+namespace clang {
+namespace tooling {
+
+namespace {
+
+// This traverses the AST and outputs function name as key and "1" as value for
+// each function declaration.
+class ASTConsumerWithResult
+: public ASTConsumer,
+  public RecursiveASTVisitor {
+public:
+  using ASTVisitor = RecursiveASTVisitor;
+
+  explicit ASTConsumerWithResult(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+  void HandleTranslationUnit(clang::ASTContext &Context) override {
+TraverseDecl(Context.getTranslationUnitDecl());
+  }
+
+  bool TraverseFunctionDecl(clang::FunctionDecl *Decl) {
+Context->getToolResults()->addResult(Decl->getNameAsString(), "1");
+return ASTVisitor::TraverseFunctionDecl(Decl);
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultAction : public ASTFrontendAction {
+public:
+  explicit ReportResultAction(ExecutionContext *Context) : Context(Context) {
+assert(Context != nullptr);
+  }
+
+protected:
+  std::unique_ptr
+  CreateASTConsumer(clang::CompilerInstance &compiler,
+StringRef /* dummy */) override {
+std::unique_ptr ast_consumer{
+new ASTConsumerWithResult(Context)};
+return ast_consumer;
+  }
+
+private:
+  ExecutionContext *const Context;
+};
+
+class ReportResultActionFactory : public FrontendActionFactory {
+public:
+  ReportResultActionFactory(ExecutionContext *Context) : Context(Context) {}
+  FrontendAction *create() override { return new ReportResultAction(Context); }
+
+private:
+  ExecutionContext *const Context;
+};
+
+inline llvm::Error make_string_error(const llvm::Twine &Message) {
+  return llvm::make_error(Message,
+ llvm::inconvertibleErrorCode());
+}
+
+} // namespace
+
+class TestToolExecutor : public ToolExecutor {
+public:
+  static const char *ExecutorName;
+
+  TestToolExecutor(std::unique_ptr Options)
+  : OptionsParser(std::move(Options)) {}
+
+  StringRef getExecutorName() const override { return ExecutorName; }
+
+  llvm::Error execute(const ExecutionConfig &) override {
+return llvm::Error::success();
+  }
+
+  ExecutionContext *getExecutionContext() override { return nullptr; };
+
+  llvm::ArrayRef getSourcePaths() const {
+return OptionsParser->getSourcePathList();
+  }
+
+  void mapVirtualFile(StringRef FilePath, StringRef Content) override {
+VFS[FilePath] = Content;
+  }
+
+private:
+  std::unique_ptr OptionsParser;
+  std::string SourcePaths;
+  std::map VFS;
+};
+
+const char *TestToolExecutor::ExecutorName = "TestToolExecutor";
+
+class TestToolExecutorPlugin : public ToolExecutorPlugin {
+public:
+  llvm::Expected>
+  create(int &argc, const char **argv,
+ llvm::cl::OptionCategory &Category) override {
+// Depending on the test runner, test cases might run in different threads
+// in the same process, so we put test options in the stack and manually
+// remove it from the global registry later so that tests do not interfere
+// with each other.
+llvm::cl::opt TestExecutor("test_executor",
+ llvm::cl::desc("Use TestToolExecutor"));
+auto OptionsParser = llvm::make_unique(
+argc, argv, Category, llvm::cl::OneOrMore, /*Overview=*/nullptr,
+/*ExitOnError=*/false);
+TestExecutor.removeArgument();
+

[libcxx] r316009 - fix shadowing warnings in new tests, try 2

2017-10-17 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Oct 17 09:06:42 2017
New Revision: 316009

URL: http://llvm.org/viewvc/llvm-project?rev=316009&view=rev
Log:
fix shadowing warnings in new tests, try 2

Modified:
libcxx/trunk/test/support/emplace_constructible.h

Modified: libcxx/trunk/test/support/emplace_constructible.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/emplace_constructible.h?rev=316009&r1=316008&r2=316009&view=diff
==
--- libcxx/trunk/test/support/emplace_constructible.h (original)
+++ libcxx/trunk/test/support/emplace_constructible.h Tue Oct 17 09:06:42 2017
@@ -47,8 +47,8 @@ struct EmplaceConstructibleMoveableAndAs
   int copied = 0;
   int assigned = 0;
   T value;
-  explicit EmplaceConstructibleMoveableAndAssignable(T value) noexcept
-  : value(value) {}
+  explicit EmplaceConstructibleMoveableAndAssignable(T xvalue) noexcept
+  : value(xvalue) {}
 
   EmplaceConstructibleMoveableAndAssignable(
   EmplaceConstructibleMoveableAndAssignable&& Other) noexcept


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


Re: [libcxx] r315994 - [libc++] Fix PR34898 - vector iterator constructors and assign method perform push_back instead of emplace_back.

2017-10-17 Thread Eric Fiselier via cfe-commits
These shadowing warnings should be fixed now.

/Eric

On Tue, Oct 17, 2017 at 10:03 AM, Maxim Kuvyrkov 
wrote:

> Hi Eric,
>
> This seems to have broken ARM and AArch64 buildbots:
>
> http://lab.llvm.org:8011/builders/libcxx-libcxxabi-
> libunwind-arm-linux/builds/850
> http://lab.llvm.org:8011/builders/libcxx-libcxxabi-libunwind-arm-linux-
> noexceptions/builds/931
> http://lab.llvm.org:8011/builders/libcxx-libcxxabi-
> libunwind-aarch64-linux/builds/873
> http://lab.llvm.org:8011/builders/libcxx-libcxxabi-
> libunwind-aarch64-linux-noexceptions/builds/826
>
> Would you please take a look?
>
> --
> Maxim Kuvyrkov
> www.linaro.org
>
>
>
> > On Oct 17, 2017, at 4:03 PM, Eric Fiselier via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >
> > Author: ericwf
> > Date: Tue Oct 17 06:03:17 2017
> > New Revision: 315994
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=315994&view=rev
> > Log:
> > [libc++] Fix PR34898 - vector iterator constructors and assign method
> perform push_back instead of emplace_back.
> >
> > Summary:
> > The constructors `vector(Iter, Iter, Alloc = Alloc{})` and `assign(Iter,
> Iter)` don't correctly perform EmplaceConstruction from the result of
> dereferencing the iterator. This results in them performing an additional
> and unneeded copy.
> >
> > This patch addresses the issue by correctly using `emplace_back` in
> C++11 and newer.
> >
> > There are also some bugs in our `insert` implementation, but those will
> be handled separately.
> >
> > @mclow.lists We should probably merge this into 5.1, agreed?
> >
> > Reviewers: mclow.lists, dlj, EricWF
> >
> > Reviewed By: mclow.lists, EricWF
> >
> > Subscribers: cfe-commits, mclow.lists
> >
> > Differential Revision: https://reviews.llvm.org/D38757
> >
> > Added:
> >libcxx/trunk/test/std/containers/sequences/vector/
> vector.cons/assign_iter_iter.pass.cpp
> >libcxx/trunk/test/support/emplace_constructible.h
> > Modified:
> >libcxx/trunk/include/deque
> >libcxx/trunk/include/list
> >libcxx/trunk/include/vector
> >libcxx/trunk/test/std/containers/sequences/deque/
> deque.cons/assign_iter_iter.pass.cpp
> >libcxx/trunk/test/std/containers/sequences/deque/
> deque.cons/iter_iter.pass.cpp
> >libcxx/trunk/test/std/containers/sequences/deque/
> deque.cons/iter_iter_alloc.pass.cpp
> >libcxx/trunk/test/std/containers/sequences/list/
> list.cons/input_iterator.pass.cpp
> >libcxx/trunk/test/std/containers/sequences/vector/
> vector.cons/construct_iter_iter.pass.cpp
> >libcxx/trunk/test/std/containers/sequences/vector/
> vector.cons/construct_iter_iter_alloc.pass.cpp
> >libcxx/trunk/test/support/container_test_types.h
> >
> > Modified: libcxx/trunk/include/deque
> > URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/
> deque?rev=315994&r1=315993&r2=315994&view=diff
> > 
> ==
> > --- libcxx/trunk/include/deque (original)
> > +++ libcxx/trunk/include/deque Tue Oct 17 06:03:17 2017
> > @@ -1356,7 +1356,6 @@ public:
> > iterator insert(const_iterator __p, initializer_list
> __il)
> > {return insert(__p, __il.begin(), __il.end());}
> > #endif  // _LIBCPP_CXX03_LANG
> > -
> > iterator insert(const_iterator __p, const value_type& __v);
> > iterator insert(const_iterator __p, size_type __n, const value_type&
> __v);
> > template 
> > @@ -2224,7 +2223,11 @@ deque<_Tp, _Allocator>::__append(_InpIte
> >
> !__is_forward_iterator<_InpIter>::value>::type*)
> > {
> > for (; __f != __l; ++__f)
> > +#ifdef _LIBCPP_CXX03_LANG
> > push_back(*__f);
> > +#else
> > +emplace_back(*__f);
> > +#endif
> > }
> >
> > template 
> >
> > Modified: libcxx/trunk/include/list
> > URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/
> list?rev=315994&r1=315993&r2=315994&view=diff
> > 
> ==
> > --- libcxx/trunk/include/list (original)
> > +++ libcxx/trunk/include/list Tue Oct 17 06:03:17 2017
> > @@ -992,6 +992,15 @@ public:
> > void push_front(const value_type& __x);
> > void push_back(const value_type& __x);
> >
> > +#ifndef _LIBCPP_CXX03_LANG
> > +template 
> > +_LIBCPP_INLINE_VISIBILITY
> > +void __emplace_back(_Arg&& __arg) { 
> > emplace_back(_VSTD::forward<_Arg>(__arg));
> }
> > +#else
> > +_LIBCPP_INLINE_VISIBILITY
> > +void __emplace_back(value_type const& __arg) { push_back(__arg); }
> > +#endif
> > +
> > iterator insert(const_iterator __p, const value_type& __x);
> > iterator insert(const_iterator __p, size_type __n, const value_type&
> __x);
> > template 
> > @@ -1189,7 +1198,7 @@ list<_Tp, _Alloc>::list(_InpIter __f, _I
> > __get_db()->__insert_c(this);
> > #endif
> > for (; __f != __l; ++__f)
> > -push_back(*__f);
> > +__emplace_back(*__f);
> > }
> >
> > template 
> > @@ -1202,7 +1211,7 @@ list<_Tp, _Alloc>::list(_InpIter __f, _I
> > __get

Re: [libcxx] r315994 - [libc++] Fix PR34898 - vector iterator constructors and assign method perform push_back instead of emplace_back.

2017-10-17 Thread Bruno Cardoso Lopes via cfe-commits
Hi Eric,

This is also failing
http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/39697/

Can you take a look?

Thanks,

On Tue, Oct 17, 2017 at 9:07 AM, Eric Fiselier via cfe-commits
 wrote:
> These shadowing warnings should be fixed now.
>
> /Eric
>
> On Tue, Oct 17, 2017 at 10:03 AM, Maxim Kuvyrkov 
> wrote:
>>
>> Hi Eric,
>>
>> This seems to have broken ARM and AArch64 buildbots:
>>
>>
>> http://lab.llvm.org:8011/builders/libcxx-libcxxabi-libunwind-arm-linux/builds/850
>>
>> http://lab.llvm.org:8011/builders/libcxx-libcxxabi-libunwind-arm-linux-noexceptions/builds/931
>>
>> http://lab.llvm.org:8011/builders/libcxx-libcxxabi-libunwind-aarch64-linux/builds/873
>>
>> http://lab.llvm.org:8011/builders/libcxx-libcxxabi-libunwind-aarch64-linux-noexceptions/builds/826
>>
>> Would you please take a look?
>>
>> --
>> Maxim Kuvyrkov
>> www.linaro.org
>>
>>
>>
>>
>> > On Oct 17, 2017, at 4:03 PM, Eric Fiselier via cfe-commits
>> >  wrote:
>> >
>> > Author: ericwf
>> > Date: Tue Oct 17 06:03:17 2017
>> > New Revision: 315994
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=315994&view=rev
>> > Log:
>> > [libc++] Fix PR34898 - vector iterator constructors and assign method
>> > perform push_back instead of emplace_back.
>> >
>> > Summary:
>> > The constructors `vector(Iter, Iter, Alloc = Alloc{})` and `assign(Iter,
>> > Iter)` don't correctly perform EmplaceConstruction from the result of
>> > dereferencing the iterator. This results in them performing an additional
>> > and unneeded copy.
>> >
>> > This patch addresses the issue by correctly using `emplace_back` in
>> > C++11 and newer.
>> >
>> > There are also some bugs in our `insert` implementation, but those will
>> > be handled separately.
>> >
>> > @mclow.lists We should probably merge this into 5.1, agreed?
>> >
>> > Reviewers: mclow.lists, dlj, EricWF
>> >
>> > Reviewed By: mclow.lists, EricWF
>> >
>> > Subscribers: cfe-commits, mclow.lists
>> >
>> > Differential Revision: https://reviews.llvm.org/D38757
>> >
>> > Added:
>> >
>> > libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_iter_iter.pass.cpp
>> >libcxx/trunk/test/support/emplace_constructible.h
>> > Modified:
>> >libcxx/trunk/include/deque
>> >libcxx/trunk/include/list
>> >libcxx/trunk/include/vector
>> >
>> > libcxx/trunk/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp
>> >
>> > libcxx/trunk/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp
>> >
>> > libcxx/trunk/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp
>> >
>> > libcxx/trunk/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp
>> >
>> > libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
>> >
>> > libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
>> >libcxx/trunk/test/support/container_test_types.h
>> >
>> > Modified: libcxx/trunk/include/deque
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/deque?rev=315994&r1=315993&r2=315994&view=diff
>> >
>> > ==
>> > --- libcxx/trunk/include/deque (original)
>> > +++ libcxx/trunk/include/deque Tue Oct 17 06:03:17 2017
>> > @@ -1356,7 +1356,6 @@ public:
>> > iterator insert(const_iterator __p, initializer_list
>> > __il)
>> > {return insert(__p, __il.begin(), __il.end());}
>> > #endif  // _LIBCPP_CXX03_LANG
>> > -
>> > iterator insert(const_iterator __p, const value_type& __v);
>> > iterator insert(const_iterator __p, size_type __n, const value_type&
>> > __v);
>> > template 
>> > @@ -2224,7 +2223,11 @@ deque<_Tp, _Allocator>::__append(_InpIte
>> >
>> > !__is_forward_iterator<_InpIter>::value>::type*)
>> > {
>> > for (; __f != __l; ++__f)
>> > +#ifdef _LIBCPP_CXX03_LANG
>> > push_back(*__f);
>> > +#else
>> > +emplace_back(*__f);
>> > +#endif
>> > }
>> >
>> > template 
>> >
>> > Modified: libcxx/trunk/include/list
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/list?rev=315994&r1=315993&r2=315994&view=diff
>> >
>> > ==
>> > --- libcxx/trunk/include/list (original)
>> > +++ libcxx/trunk/include/list Tue Oct 17 06:03:17 2017
>> > @@ -992,6 +992,15 @@ public:
>> > void push_front(const value_type& __x);
>> > void push_back(const value_type& __x);
>> >
>> > +#ifndef _LIBCPP_CXX03_LANG
>> > +template 
>> > +_LIBCPP_INLINE_VISIBILITY
>> > +void __emplace_back(_Arg&& __arg) {
>> > emplace_back(_VSTD::forward<_Arg>(__arg)); }
>> > +#else
>> > +_LIBCPP_INLINE_VISIBILITY
>> > +void __emplace_back(value_type const& __arg) { push_back(__arg); }
>> > +#endif
>> > +
>> > iterator insert(const_iterator __p, const value_type& __x);
>> > iterator insert(const_iterator __p, size_type __n, const value_type&
>> > __x);
>> > te

[PATCH] D34272: [Tooling] A new framework for executing clang frontend actions.

2017-10-17 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: include/clang/Tooling/CommonOptionsParser.h:90
   ///
-  /// This constructor exits program in case of error.
+  /// If \p ExitOnError is set (default), This constructor exits program in 
case
+  /// of error; otherwise, this sets the error flag and stores error messages.

hokein wrote:
> `... is set to true` for clarify.
If we want error handling, why not make it a static factory that returns an 
ErrorOr instead?



Comment at: include/clang/Tooling/Execution.h:26-27
+//
+//  This is still experimental but expected to replace the existing `ClangTool`
+//  interface.
+//

I'd remove this line. Those tend to only get stale without anybody changing 
them :)



Comment at: include/clang/Tooling/Execution.h:49
+public:
+  virtual ~ToolResults() {}
+  virtual void addResult(StringRef Key, StringRef Value) = 0;

I think = default is the new cool way.



Comment at: include/clang/Tooling/Execution.h:51-53
+  virtual std::vector> AllKVResults() = 0;
+  virtual void forEachResult(
+  llvm::function_ref Callback) = 0;

Why do we need to get the results via the interface? For example, in a 
map/reduce style setup getting the results is infeasible.



Comment at: include/clang/Tooling/Execution.h:76
+
+  virtual ToolResults *getToolResults() const { return Results; }
+

I think it's weird that this is virtual, but we also  have a default 
implementation that returns something that we require in the constructor. 
Either make that virtual, and don't put in a default implementation, or make it 
non-virtual.



Comment at: include/clang/Tooling/Execution.h:90
+private:
+  // A reference to the results container. Not owned!
+  ToolResults *Results;

I don't think we need to annotate every unowned pointer. Pointers are unowned 
by default, otherwise we'd use unique_ptr.



Comment at: include/clang/Tooling/Execution.h:164-166
+createExecutorFromCommandLineArgs(int &argc, const char **argv,
+  llvm::cl::OptionCategory &Category,
+  const char *Overview = nullptr);

I think for clang-refactor we'll need one level of abstraction in the middle:
We'll need to be able to say "run on all translation units referencing symbol 
X" - how will this fit into the design?
Also, how will code changes generally fit with this design?


https://reviews.llvm.org/D34272



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


[PATCH] D39008: [CodeGen] Propagate may-alias'ness of lvalues with TBAA info

2017-10-17 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev created this revision.
kosarev added a project: clang.

This patch fixes various places in clang to propagate may-alias TBAA access 
descriptors during construction of lvalues, thus eliminating the need for the 
LValueBaseInfo::MayAlias flag.

This is part of https://reviews.llvm.org/D38126 reworked to be a separate patch 
to simplify review.


Repository:
  rL LLVM

https://reviews.llvm.org/D39008

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGObjCRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGValue.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/CodeGenTBAA.cpp
  lib/CodeGen/CodeGenTBAA.h

Index: lib/CodeGen/CodeGenTBAA.h
===
--- lib/CodeGen/CodeGenTBAA.h
+++ lib/CodeGen/CodeGenTBAA.h
@@ -53,6 +53,14 @@
Offset == Other.Offset;
   }
 
+  bool operator!=(const TBAAAccessInfo &Other) const {
+return !(*this == Other);
+  }
+
+  explicit operator bool() const {
+return *this != TBAAAccessInfo();
+  }
+
   /// BaseType - The base/leading access type. May be null if this access
   /// descriptor represents an access that is not considered to be an access
   /// to an aggregate or union member.
@@ -143,10 +151,18 @@
   /// accesses.
   TBAAAccessInfo getMayAliasAccessInfo();
 
+  /// isMayAliasAccessInfo - Test for the may-alias TBAA access descriptor.
+  bool isMayAliasAccessInfo(TBAAAccessInfo Info);
+
   /// mergeTBAAInfoForCast - Get merged TBAA information for the purpose of
   /// type casts.
   TBAAAccessInfo mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo,
   TBAAAccessInfo TargetInfo);
+
+  /// mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the
+  /// purpose of conditional operator.
+  TBAAAccessInfo mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA,
+ TBAAAccessInfo InfoB);
 };
 
 }  // end namespace CodeGen
@@ -177,9 +193,7 @@
 
   static bool isEqual(const clang::CodeGen::TBAAAccessInfo &LHS,
   const clang::CodeGen::TBAAAccessInfo &RHS) {
-return LHS.BaseType == RHS.BaseType &&
-   LHS.AccessType == RHS.AccessType &&
-   LHS.Offset == RHS.Offset;
+return LHS == RHS;
   }
 };
 
Index: lib/CodeGen/CodeGenTBAA.cpp
===
--- lib/CodeGen/CodeGenTBAA.cpp
+++ lib/CodeGen/CodeGenTBAA.cpp
@@ -88,6 +88,25 @@
   return false;
 }
 
+/// Check if the given type is a valid base type to be used in access tags.
+static bool isValidBaseType(QualType QTy) {
+  if (QTy->isReferenceType())
+return false;
+  if (const RecordType *TTy = QTy->getAs()) {
+const RecordDecl *RD = TTy->getDecl()->getDefinition();
+// Incomplete types are not valid base access types.
+if (!RD)
+  return false;
+if (RD->hasFlexibleArrayMember())
+  return false;
+// RD can be struct, union, class, interface or enum.
+// For now, we only handle struct and class.
+if (RD->isStruct() || RD->isClass())
+  return true;
+  }
+  return false;
+}
+
 llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
   // At -O0 or relaxed aliasing, TBAA is not emitted for regular types.
   if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
@@ -98,8 +117,16 @@
   if (TypeHasMayAlias(QTy))
 return getChar();
 
-  const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
+  // We need this function to not fall back to returning the "omnipotent char"
+  // type node for aggregate and union types. Otherwise, any dereference of an
+  // aggregate will result into the may-alias access descriptor, meaning all
+  // subsequent accesses to direct and indirect members of that aggregate will
+  // be considered may-alias too.
+  // TODO: Combine getTypeInfo() and getBaseTypeInfo() into a single function.
+  if (isValidBaseType(QTy))
+return getBaseTypeInfo(QTy);
 
+  const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
   if (llvm::MDNode *N = MetadataCache[Ty])
 return N;
 
@@ -232,20 +259,6 @@
   return StructMetadataCache[Ty] = nullptr;
 }
 
-/// Check if the given type is a valid base type to be used in access tags.
-static bool isValidBaseType(QualType QTy) {
-  if (const RecordType *TTy = QTy->getAs()) {
-const RecordDecl *RD = TTy->getDecl()->getDefinition();
-if (RD->hasFlexibleArrayMember())
-  return false;
-// RD can be struct, union, class, interface or enum.
-// For now, we only handle struct and class.
-if (RD->isStruct() || RD->isClass())
-  return true;
-  }
-  return false;
-}
-
 llvm::MDNode *CodeGenTBAA::getBaseTypeInfo(QualType QTy) {
   if (!isValidBaseType(QTy))
 return nullptr;
@@ -317,3 +330,26 @@
 return MayAliasInfo;
   return TargetInfo;
 }
+
+bool CodeGenTBAA::isMayAliasAccessInfo(TBAAAccessInfo Info) {
+ 

r316011 - [OPENMP] Fix capturing of boolean variables in debug mode.

2017-10-17 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Oct 17 09:47:34 2017
New Revision: 316011

URL: http://llvm.org/viewvc/llvm-project?rev=316011&view=rev
Log:
[OPENMP] Fix capturing of boolean variables in debug mode.

If the variables is boolean and we generating inner function with real
types, the codegen may crash because of not loading boolean value from
memory.

Modified:
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=316011&r1=316010&r2=316011&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Tue Oct 17 09:47:34 2017
@@ -501,9 +501,10 @@ CodeGenFunction::GenerateOpenMPCapturedS
 llvm::Value *CallArg;
 auto I = LocalAddrs.find(Arg);
 if (I != LocalAddrs.end()) {
-  LValue LV =
-  WrapperCGF.MakeAddrLValue(I->second.second, Arg->getType(),
-AlignmentSource::Decl);
+  LValue LV = WrapperCGF.MakeAddrLValue(
+  I->second.second,
+  I->second.first ? I->second.first->getType() : Arg->getType(),
+  AlignmentSource::Decl);
   CallArg = WrapperCGF.EmitLoadOfScalar(LV, SourceLocation());
 } else {
   auto EI = VLASizes.find(Arg);
@@ -516,7 +517,7 @@ CodeGenFunction::GenerateOpenMPCapturedS
 CallArg = WrapperCGF.EmitLoadOfScalar(LV, SourceLocation());
   }
 }
-CallArgs.emplace_back(CallArg);
+CallArgs.emplace_back(WrapperCGF.EmitFromMemory(CallArg, Arg->getType()));
   }
   CGM.getOpenMPRuntime().emitOutlinedFunctionCall(WrapperCGF, S.getLocStart(),
   F, CallArgs);

Modified: cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp?rev=316011&r1=316010&r2=316011&view=diff
==
--- cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp Tue Oct 17 09:47:34 
2017
@@ -11,7 +11,7 @@ int main() {
   int c[10][10][10];
 #pragma omp target parallel firstprivate(a, b) map(tofrom  \
: c) map(tofrom \
-: bb)
+: bb) if (a)
   {
 int &f = c[1][1][1];
 int &g = a;
@@ -54,7 +54,7 @@ int main() {
   return 0;
 }
 
-// CHECK: define internal void @__omp_offloading{{[^(]+}}([10 x [10 x [10 x 
i32]]] addrspace(1)* {{[^,]+}}, i32 {{[^,]+}}, [10 x [10 x i32]]* {{[^,]+}}, i8 
addrspace(1)* noalias{{[^)]+}})
+// CHECK: define internal void @__omp_offloading{{[^(]+}}([10 x [10 x [10 x 
i32]]] addrspace(1)* {{[^,]+}}, i32 {{[^,]+}}, [10 x [10 x i32]]* {{[^,]+}}, i8 
addrspace(1)* noalias{{[^,]+}}, i1 {{[^)]+}})
 // CHECK: addrspacecast [10 x [10 x [10 x i32]]] addrspace(1)* %{{.+}} to [10 
x [10 x [10 x i32]]]*
 // CHECK: call void [[NONDEBUG_WRAPPER:.+]](i32* {{[^,]+}}, i32* {{[^,]+}}, 
[10 x [10 x [10 x i32]]]* {{[^,]+}}, i64 {{[^,]+}}, [10 x [10 x i32]]* 
{{[^,]+}}, i8* {{[^)]+}})
 


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


Re: [libcxx] r315994 - [libc++] Fix PR34898 - vector iterator constructors and assign method perform push_back instead of emplace_back.

2017-10-17 Thread Maxim Kuvyrkov via cfe-commits
Hi Eric,

This seems to have broken ARM and AArch64 buildbots:

http://lab.llvm.org:8011/builders/libcxx-libcxxabi-libunwind-arm-linux/builds/850
http://lab.llvm.org:8011/builders/libcxx-libcxxabi-libunwind-arm-linux-noexceptions/builds/931
http://lab.llvm.org:8011/builders/libcxx-libcxxabi-libunwind-aarch64-linux/builds/873
http://lab.llvm.org:8011/builders/libcxx-libcxxabi-libunwind-aarch64-linux-noexceptions/builds/826

Would you please take a look?

--
Maxim Kuvyrkov
www.linaro.org



> On Oct 17, 2017, at 4:03 PM, Eric Fiselier via cfe-commits 
>  wrote:
> 
> Author: ericwf
> Date: Tue Oct 17 06:03:17 2017
> New Revision: 315994
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=315994&view=rev
> Log:
> [libc++] Fix PR34898 - vector iterator constructors and assign method perform 
> push_back instead of emplace_back.
> 
> Summary:
> The constructors `vector(Iter, Iter, Alloc = Alloc{})` and `assign(Iter, 
> Iter)` don't correctly perform EmplaceConstruction from the result of 
> dereferencing the iterator. This results in them performing an additional and 
> unneeded copy.
> 
> This patch addresses the issue by correctly using `emplace_back` in C++11 and 
> newer.
> 
> There are also some bugs in our `insert` implementation, but those will be 
> handled separately. 
> 
> @mclow.lists We should probably merge this into 5.1, agreed?
> 
> Reviewers: mclow.lists, dlj, EricWF
> 
> Reviewed By: mclow.lists, EricWF
> 
> Subscribers: cfe-commits, mclow.lists
> 
> Differential Revision: https://reviews.llvm.org/D38757
> 
> Added:
>
> libcxx/trunk/test/std/containers/sequences/vector/vector.cons/assign_iter_iter.pass.cpp
>libcxx/trunk/test/support/emplace_constructible.h
> Modified:
>libcxx/trunk/include/deque
>libcxx/trunk/include/list
>libcxx/trunk/include/vector
>
> libcxx/trunk/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp
>
> libcxx/trunk/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp
>
> libcxx/trunk/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp
>
> libcxx/trunk/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp
>
> libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
>
> libcxx/trunk/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
>libcxx/trunk/test/support/container_test_types.h
> 
> Modified: libcxx/trunk/include/deque
> URL: 
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/deque?rev=315994&r1=315993&r2=315994&view=diff
> ==
> --- libcxx/trunk/include/deque (original)
> +++ libcxx/trunk/include/deque Tue Oct 17 06:03:17 2017
> @@ -1356,7 +1356,6 @@ public:
> iterator insert(const_iterator __p, initializer_list __il)
> {return insert(__p, __il.begin(), __il.end());}
> #endif  // _LIBCPP_CXX03_LANG
> -
> iterator insert(const_iterator __p, const value_type& __v);
> iterator insert(const_iterator __p, size_type __n, const value_type& __v);
> template 
> @@ -2224,7 +2223,11 @@ deque<_Tp, _Allocator>::__append(_InpIte
>
> !__is_forward_iterator<_InpIter>::value>::type*)
> {
> for (; __f != __l; ++__f)
> +#ifdef _LIBCPP_CXX03_LANG
> push_back(*__f);
> +#else
> +emplace_back(*__f);
> +#endif
> }
> 
> template 
> 
> Modified: libcxx/trunk/include/list
> URL: 
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/list?rev=315994&r1=315993&r2=315994&view=diff
> ==
> --- libcxx/trunk/include/list (original)
> +++ libcxx/trunk/include/list Tue Oct 17 06:03:17 2017
> @@ -992,6 +992,15 @@ public:
> void push_front(const value_type& __x);
> void push_back(const value_type& __x);
> 
> +#ifndef _LIBCPP_CXX03_LANG
> +template 
> +_LIBCPP_INLINE_VISIBILITY
> +void __emplace_back(_Arg&& __arg) { 
> emplace_back(_VSTD::forward<_Arg>(__arg)); }
> +#else
> +_LIBCPP_INLINE_VISIBILITY
> +void __emplace_back(value_type const& __arg) { push_back(__arg); }
> +#endif
> +
> iterator insert(const_iterator __p, const value_type& __x);
> iterator insert(const_iterator __p, size_type __n, const value_type& __x);
> template 
> @@ -1189,7 +1198,7 @@ list<_Tp, _Alloc>::list(_InpIter __f, _I
> __get_db()->__insert_c(this);
> #endif
> for (; __f != __l; ++__f)
> -push_back(*__f);
> +__emplace_back(*__f);
> }
> 
> template 
> @@ -1202,7 +1211,7 @@ list<_Tp, _Alloc>::list(_InpIter __f, _I
> __get_db()->__insert_c(this);
> #endif
> for (; __f != __l; ++__f)
> -push_back(*__f);
> +__emplace_back(*__f);
> }
> 
> template 
> 
> Modified: libcxx/trunk/include/vector
> URL: 
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/vector?rev=315994&r1=315993&r2=315994&view=diff
> ==

r316013 - Sema: use new `getNS{,U}IntegerType` for NS{,U}Integer

2017-10-17 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Tue Oct 17 10:39:32 2017
New Revision: 316013

URL: http://llvm.org/viewvc/llvm-project?rev=316013&view=rev
Log:
Sema: use new `getNS{,U}IntegerType` for NS{,U}Integer

Use the new helper methods to get the underlying type for NSUInteger,
NSInteger types.  This avoids spreading the knowledge of the underlying
types in various sites.  For non-LLP64 targets, this has no change.

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

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=316013&r1=316012&r2=316013&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Oct 17 10:39:32 2017
@@ -6168,9 +6168,9 @@ shouldNotPrintDirectly(const ASTContext
   while (const TypedefType *UserTy = TyTy->getAs()) {
 StringRef Name = UserTy->getDecl()->getName();
 QualType CastTy = llvm::StringSwitch(Name)
-  .Case("CFIndex", Context.LongTy)
-  .Case("NSInteger", Context.LongTy)
-  .Case("NSUInteger", Context.UnsignedLongTy)
+  .Case("CFIndex", Context.getNSIntegerType())
+  .Case("NSInteger", Context.getNSIntegerType())
+  .Case("NSUInteger", Context.getNSUIntegerType())
   .Case("SInt32", Context.IntTy)
   .Case("UInt32", Context.UnsignedIntTy)
   .Default(QualType());


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


r316015 - Replace use of SmallVector::back + pop_back with pop_back_val

2017-10-17 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Tue Oct 17 10:45:21 2017
New Revision: 316015

URL: http://llvm.org/viewvc/llvm-project?rev=316015&view=rev
Log:
Replace use of SmallVector::back + pop_back with pop_back_val

I ran across an instance where the value was being loaded
out via back, then immediately popped.  Since pop_back_val
is more efficient at this (it moves out), replace this 
instance.

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

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=316015&r1=316014&r2=316015&view=diff
==
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Tue Oct 17 10:45:21 2017
@@ -361,8 +361,7 @@ static bool hasThrowOutNonThrowingFunc(S
   SmallVector Stack;
   Stack.push_back(&BodyCFG->getEntry());
   while (!Stack.empty()) {
-CFGBlock *CurBlock = Stack.back();
-Stack.pop_back();
+CFGBlock *CurBlock = Stack.pop_back_val();
 
 unsigned ID = CurBlock->getBlockID();
 ThrowState CurState = States[ID];


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


[PATCH] D39005: [OpenMP] Clean up variable and function names for NVPTX backend

2017-10-17 Thread Justin Lebar via Phabricator via cfe-commits
jlebar added a comment.

This has been tried twice before, see https://reviews.llvm.org/D29883 and 
https://reviews.llvm.org/D17738.  I'm as unhappy about this as anyone, and 
personally I don't have any preference about how we try to solve it.  But I 
think we shouldn't check this in without hearing the objections from those past 
attempts.


Repository:
  rL LLVM

https://reviews.llvm.org/D39005



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


r316016 - [OpenCL] Restrict swizzle length check to OpenCL mode

2017-10-17 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Tue Oct 17 10:54:57 2017
New Revision: 316016

URL: http://llvm.org/viewvc/llvm-project?rev=316016&view=rev
Log:
[OpenCL] Restrict swizzle length check to OpenCL mode

Changes behavior introduced in r298369 to only error out on
vector component invalid length access on OpenCL mode.

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

rdar://problem/33568748

Added:
cfe/trunk/test/Sema/vector_swizzle_length.c
Modified:
cfe/trunk/lib/Sema/SemaExprMember.cpp
cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl

Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=316016&r1=316015&r2=316016&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Tue Oct 17 10:54:57 2017
@@ -384,7 +384,9 @@ CheckExtVectorComponent(Sema &S, QualTyp
 }
   }
 
-  if (!HalvingSwizzle) {
+  // OpenCL mode requires swizzle length to be in accordance with accepted
+  // sizes. Clang however supports arbitrary lengths for other languages.
+  if (S.getLangOpts().OpenCL && !HalvingSwizzle) {
 unsigned SwizzleLength = CompName->getLength();
 
 if (HexSwizzle)

Added: cfe/trunk/test/Sema/vector_swizzle_length.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vector_swizzle_length.c?rev=316016&view=auto
==
--- cfe/trunk/test/Sema/vector_swizzle_length.c (added)
+++ cfe/trunk/test/Sema/vector_swizzle_length.c Tue Oct 17 10:54:57 2017
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -x c %s -verify -pedantic -fsyntax-only
+// expected-no-diagnostics
+
+typedef float float8 __attribute__((ext_vector_type(8)));
+
+void foo() {
+float8 f2 = (float8){0, 0, 0, 0, 0, 0, 0, 0};
+(void)f2.s01234;
+(void)f2.xyzxy;
+}

Modified: cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl?rev=316016&r1=316015&r2=316016&view=diff
==
--- cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl (original)
+++ cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl Tue Oct 17 10:54:57 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 -x cl %s -verify -pedantic -fsyntax-only
 
 typedef float float8 __attribute__((ext_vector_type(8)));
 


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


[PATCH] D38868: [OpenCL] Restrict swizzle length check to OpenCL mode

2017-10-17 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316016: [OpenCL] Restrict swizzle length check to OpenCL 
mode (authored by bruno).

Changed prior to commit:
  https://reviews.llvm.org/D38868?vs=118966&id=119351#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38868

Files:
  cfe/trunk/lib/Sema/SemaExprMember.cpp
  cfe/trunk/test/Sema/vector_swizzle_length.c
  cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl


Index: cfe/trunk/test/Sema/vector_swizzle_length.c
===
--- cfe/trunk/test/Sema/vector_swizzle_length.c
+++ cfe/trunk/test/Sema/vector_swizzle_length.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -x c %s -verify -pedantic -fsyntax-only
+// expected-no-diagnostics
+
+typedef float float8 __attribute__((ext_vector_type(8)));
+
+void foo() {
+float8 f2 = (float8){0, 0, 0, 0, 0, 0, 0, 0};
+(void)f2.s01234;
+(void)f2.xyzxy;
+}
Index: cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl
===
--- cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl
+++ cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 -x cl %s -verify -pedantic -fsyntax-only
 
 typedef float float8 __attribute__((ext_vector_type(8)));
 
Index: cfe/trunk/lib/Sema/SemaExprMember.cpp
===
--- cfe/trunk/lib/Sema/SemaExprMember.cpp
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp
@@ -384,7 +384,9 @@
 }
   }
 
-  if (!HalvingSwizzle) {
+  // OpenCL mode requires swizzle length to be in accordance with accepted
+  // sizes. Clang however supports arbitrary lengths for other languages.
+  if (S.getLangOpts().OpenCL && !HalvingSwizzle) {
 unsigned SwizzleLength = CompName->getLength();
 
 if (HexSwizzle)


Index: cfe/trunk/test/Sema/vector_swizzle_length.c
===
--- cfe/trunk/test/Sema/vector_swizzle_length.c
+++ cfe/trunk/test/Sema/vector_swizzle_length.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -x c %s -verify -pedantic -fsyntax-only
+// expected-no-diagnostics
+
+typedef float float8 __attribute__((ext_vector_type(8)));
+
+void foo() {
+float8 f2 = (float8){0, 0, 0, 0, 0, 0, 0, 0};
+(void)f2.s01234;
+(void)f2.xyzxy;
+}
Index: cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl
===
--- cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl
+++ cfe/trunk/test/SemaOpenCL/vector_swizzle_length.cl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 -x cl %s -verify -pedantic -fsyntax-only
 
 typedef float float8 __attribute__((ext_vector_type(8)));
 
Index: cfe/trunk/lib/Sema/SemaExprMember.cpp
===
--- cfe/trunk/lib/Sema/SemaExprMember.cpp
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp
@@ -384,7 +384,9 @@
 }
   }
 
-  if (!HalvingSwizzle) {
+  // OpenCL mode requires swizzle length to be in accordance with accepted
+  // sizes. Clang however supports arbitrary lengths for other languages.
+  if (S.getLangOpts().OpenCL && !HalvingSwizzle) {
 unsigned SwizzleLength = CompName->getLength();
 
 if (HexSwizzle)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39005: [OpenMP] Clean up variable and function names for NVPTX backend

2017-10-17 Thread Artem Belevich via Phabricator via cfe-commits
tra requested changes to this revision.
tra added a comment.

Justin is right. I completely forgot about this. :-/
Hal offered possible solution: https://reviews.llvm.org/D17738#661115


Repository:
  rL LLVM

https://reviews.llvm.org/D39005



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


[PATCH] D39013: [CFG] Relax Wexceptions warning on rethrow

2017-10-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.

As reported here: https://bugs.llvm.org/show_bug.cgi?id=34973

"catch(...)" should catch EVERYTHING, even a rethrow.  This
patch changes the order of the checks to ensure that the
catch(...) will catch everything.


https://reviews.llvm.org/D39013

Files:
  lib/Sema/AnalysisBasedWarnings.cpp
  test/SemaCXX/warn-throw-out-noexcept-func.cpp


Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -289,14 +289,14 @@
 
 static bool isThrowCaught(const CXXThrowExpr *Throw,
   const CXXCatchStmt *Catch) {
+  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
+  if (!CaughtType)
+return true;
   const Type *ThrowType = nullptr;
   if (Throw->getSubExpr())
 ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
   if (!ThrowType)
 return false;
-  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
-  if (!CaughtType)
-return true;
   if (ThrowType->isReferenceType())
 ThrowType = ThrowType->castAs()
 ->getPointeeType()
Index: test/SemaCXX/warn-throw-out-noexcept-func.cpp
===
--- test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -239,9 +239,11 @@
   } catch (const S &s) {
   }
 }
-void o_ShouldDiag() noexcept { //expected-note {{function declared 
non-throwing here}}
+// As seen in p34973, this should not throw the warning.  If there is an active
+// exception, catch(...) catches everything. 
+void o_ShouldDiag() noexcept {
   try {
-throw; //expected-warning {{has a non-throwing exception specification 
but}}
+throw;
   } catch (...) {
   }
 }


Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -289,14 +289,14 @@
 
 static bool isThrowCaught(const CXXThrowExpr *Throw,
   const CXXCatchStmt *Catch) {
+  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
+  if (!CaughtType)
+return true;
   const Type *ThrowType = nullptr;
   if (Throw->getSubExpr())
 ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
   if (!ThrowType)
 return false;
-  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
-  if (!CaughtType)
-return true;
   if (ThrowType->isReferenceType())
 ThrowType = ThrowType->castAs()
 ->getPointeeType()
Index: test/SemaCXX/warn-throw-out-noexcept-func.cpp
===
--- test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -239,9 +239,11 @@
   } catch (const S &s) {
   }
 }
-void o_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
+// As seen in p34973, this should not throw the warning.  If there is an active
+// exception, catch(...) catches everything. 
+void o_ShouldDiag() noexcept {
   try {
-throw; //expected-warning {{has a non-throwing exception specification but}}
+throw;
   } catch (...) {
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39013: [CFG] Relax Wexceptions warning on rethrow

2017-10-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Have a question on the behavior here, see inline.




Comment at: lib/Sema/AnalysisBasedWarnings.cpp:299
   if (!ThrowType)
 return false;
   if (ThrowType->isReferenceType())

The other potential fix here is to simply change this line here to "return 
true;".  This would result the warning being suppressed on 'rethrow' if there 
is any catch statements. 

I wonder what the opinion of the reviewers is on this one.



Comment at: test/SemaCXX/warn-throw-out-noexcept-func.cpp:244
+// exception, catch(...) catches everything. 
+void o_ShouldDiag() noexcept {
   try {

Doh, I should have changed the name here... Still want your feedback on above 
though.


https://reviews.llvm.org/D39013



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


[PATCH] D38354: Fix test by using -target instead of cc1 arguments (c-index-test goes through the driver)

2017-10-17 Thread Filipe Cabecinhas via Phabricator via cfe-commits
filcab added a comment.

Ping!


https://reviews.llvm.org/D38354



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


[PATCH] D39015: [Analyzer] Always use non-reference types when creating expressions in BodyFarm, removes std::call_once crash

2017-10-17 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov created this revision.
Herald added subscribers: szepet, kristof.beyls, xazax.hun, javed.absar, 
aemerson.

Remove an option to use a reference type (on by default!) since a non-reference 
type is always needed for creating expressions, functions with multiple boolean 
parameters are very hard to use, and in general it was just a booby trap for 
further crashes.
Furthermore, generalize `call_once` test case to fix some of the crashes 
mentioned https://bugs.llvm.org/show_bug.cgi?id=34869


https://reviews.llvm.org/D39015

Files:
  lib/Analysis/BodyFarm.cpp
  test/Analysis/call_once.cpp

Index: test/Analysis/call_once.cpp
===
--- test/Analysis/call_once.cpp
+++ test/Analysis/call_once.cpp
@@ -17,7 +17,7 @@
 #endif
 
 template 
-void call_once(once_flag &o, Callable func, Args... args) {};
+void call_once(once_flag &o, Callable&& func, Args&&... args) {};
 
 } // namespace std
 
Index: lib/Analysis/BodyFarm.cpp
===
--- lib/Analysis/BodyFarm.cpp
+++ lib/Analysis/BodyFarm.cpp
@@ -63,8 +63,7 @@
   
   /// Create a new DeclRefExpr for the referenced variable.
   DeclRefExpr *makeDeclRefExpr(const VarDecl *D,
-   bool RefersToEnclosingVariableOrCapture = false,
-   bool GetNonReferenceType = false);
+   bool RefersToEnclosingVariableOrCapture = false);
   
   /// Create a new UnaryOperator representing a dereference.
   UnaryOperator *makeDereference(const Expr *Arg, QualType Ty);
@@ -82,8 +81,7 @@
   /// DeclRefExpr in the process.
   ImplicitCastExpr *
   makeLvalueToRvalue(const VarDecl *Decl,
- bool RefersToEnclosingVariableOrCapture = false,
- bool GetNonReferenceType = false);
+ bool RefersToEnclosingVariableOrCapture = false);
 
   /// Create an implicit cast of the given type.
   ImplicitCastExpr *makeImplicitCast(const Expr *Arg, QualType Ty,
@@ -138,12 +136,10 @@
   return new (C) CompoundStmt(C, Stmts, SourceLocation(), SourceLocation());
 }
 
-DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D,
-   bool RefersToEnclosingVariableOrCapture,
-   bool GetNonReferenceType) {
-  auto Type = D->getType();
-  if (GetNonReferenceType)
-Type = Type.getNonReferenceType();
+DeclRefExpr *ASTMaker::makeDeclRefExpr(
+const VarDecl *D,
+bool RefersToEnclosingVariableOrCapture) {
+  QualType Type = D->getType().getNonReferenceType();
 
   DeclRefExpr *DR = DeclRefExpr::Create(
   C, NestedNameSpecifierLoc(), SourceLocation(), const_cast(D),
@@ -162,14 +158,10 @@
 
 ImplicitCastExpr *
 ASTMaker::makeLvalueToRvalue(const VarDecl *Arg,
- bool RefersToEnclosingVariableOrCapture,
- bool GetNonReferenceType) {
-  auto Type = Arg->getType();
-  if (GetNonReferenceType)
-Type = Type.getNonReferenceType();
+ bool RefersToEnclosingVariableOrCapture) {
+  QualType Type = Arg->getType().getNonReferenceType();
   return makeLvalueToRvalue(makeDeclRefExpr(Arg,
-RefersToEnclosingVariableOrCapture,
-GetNonReferenceType),
+RefersToEnclosingVariableOrCapture),
 Type);
 }
 
@@ -263,7 +255,7 @@
 
   return new (C) CallExpr(
   /*ASTContext=*/C,
-  /*StmtClass=*/M.makeLvalueToRvalue(/*Expr=*/Callback),
+  /*StmtClass=*/M.makeLvalueToRvalue(/*Expr=*/Callback), // TODO: this is a crashling line w/ reference type
   /*args=*/CallArgs,
   /*QualType=*/C.VoidTy,
   /*ExprValueType=*/VK_RValue,
@@ -365,12 +357,13 @@
 // Lambda requires callback itself inserted as a first parameter.
 CallArgs.push_back(
 M.makeDeclRefExpr(Callback,
-  /* RefersToEnclosingVariableOrCapture= */ true,
-  /* GetNonReferenceType= */ true));
+  /* RefersToEnclosingVariableOrCapture= */ true));
 
   // All arguments past first two ones are passed to the callback.
   for (unsigned int i = 2; i < D->getNumParams(); i++)
-CallArgs.push_back(M.makeLvalueToRvalue(D->getParamDecl(i)));
+CallArgs.push_back(
+M.makeLvalueToRvalue(D->getParamDecl(i),
+ /* RefersToEnclosingVariableOrCapture= */ false));
 
   CallExpr *CallbackCall;
   if (isLambdaCall) {
@@ -385,8 +378,7 @@
 
   DeclRefExpr *FlagDecl =
   M.makeDeclRefExpr(Flag,
-/* RefersToEnclosingVariableOrCapture=*/true,
-/* GetNonReferenceType=*/true);
+/* RefersToEnclosingVariableOrCapture=*/true);
 
 
   MemberExpr *Deref = M.makeMemberExpression(FlagDecl, FlagFieldDecl);

[PATCH] D39015: [Analyzer] Always use non-reference types when creating expressions in BodyFarm, removes std::call_once crash

2017-10-17 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov updated this revision to Diff 119360.

https://reviews.llvm.org/D39015

Files:
  lib/Analysis/BodyFarm.cpp
  test/Analysis/call_once.cpp


Index: test/Analysis/call_once.cpp
===
--- test/Analysis/call_once.cpp
+++ test/Analysis/call_once.cpp
@@ -17,7 +17,7 @@
 #endif
 
 template 
-void call_once(once_flag &o, Callable func, Args... args) {};
+void call_once(once_flag &o, Callable&& func, Args&&... args) {};
 
 } // namespace std
 
Index: lib/Analysis/BodyFarm.cpp
===
--- lib/Analysis/BodyFarm.cpp
+++ lib/Analysis/BodyFarm.cpp
@@ -63,8 +63,7 @@
   
   /// Create a new DeclRefExpr for the referenced variable.
   DeclRefExpr *makeDeclRefExpr(const VarDecl *D,
-   bool RefersToEnclosingVariableOrCapture = false,
-   bool GetNonReferenceType = false);
+   bool RefersToEnclosingVariableOrCapture = 
false);
   
   /// Create a new UnaryOperator representing a dereference.
   UnaryOperator *makeDereference(const Expr *Arg, QualType Ty);
@@ -82,8 +81,7 @@
   /// DeclRefExpr in the process.
   ImplicitCastExpr *
   makeLvalueToRvalue(const VarDecl *Decl,
- bool RefersToEnclosingVariableOrCapture = false,
- bool GetNonReferenceType = false);
+ bool RefersToEnclosingVariableOrCapture = false);
 
   /// Create an implicit cast of the given type.
   ImplicitCastExpr *makeImplicitCast(const Expr *Arg, QualType Ty,
@@ -138,12 +136,10 @@
   return new (C) CompoundStmt(C, Stmts, SourceLocation(), SourceLocation());
 }
 
-DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D,
-   bool RefersToEnclosingVariableOrCapture,
-   bool GetNonReferenceType) {
-  auto Type = D->getType();
-  if (GetNonReferenceType)
-Type = Type.getNonReferenceType();
+DeclRefExpr *ASTMaker::makeDeclRefExpr(
+const VarDecl *D,
+bool RefersToEnclosingVariableOrCapture) {
+  QualType Type = D->getType().getNonReferenceType();
 
   DeclRefExpr *DR = DeclRefExpr::Create(
   C, NestedNameSpecifierLoc(), SourceLocation(), const_cast(D),
@@ -162,14 +158,10 @@
 
 ImplicitCastExpr *
 ASTMaker::makeLvalueToRvalue(const VarDecl *Arg,
- bool RefersToEnclosingVariableOrCapture,
- bool GetNonReferenceType) {
-  auto Type = Arg->getType();
-  if (GetNonReferenceType)
-Type = Type.getNonReferenceType();
+ bool RefersToEnclosingVariableOrCapture) {
+  QualType Type = Arg->getType().getNonReferenceType();
   return makeLvalueToRvalue(makeDeclRefExpr(Arg,
-RefersToEnclosingVariableOrCapture,
-GetNonReferenceType),
+
RefersToEnclosingVariableOrCapture),
 Type);
 }
 
@@ -365,12 +357,13 @@
 // Lambda requires callback itself inserted as a first parameter.
 CallArgs.push_back(
 M.makeDeclRefExpr(Callback,
-  /* RefersToEnclosingVariableOrCapture= */ true,
-  /* GetNonReferenceType= */ true));
+  /* RefersToEnclosingVariableOrCapture= */ true));
 
   // All arguments past first two ones are passed to the callback.
   for (unsigned int i = 2; i < D->getNumParams(); i++)
-CallArgs.push_back(M.makeLvalueToRvalue(D->getParamDecl(i)));
+CallArgs.push_back(
+M.makeLvalueToRvalue(D->getParamDecl(i),
+ /* RefersToEnclosingVariableOrCapture= */ false));
 
   CallExpr *CallbackCall;
   if (isLambdaCall) {
@@ -385,8 +378,7 @@
 
   DeclRefExpr *FlagDecl =
   M.makeDeclRefExpr(Flag,
-/* RefersToEnclosingVariableOrCapture=*/true,
-/* GetNonReferenceType=*/true);
+/* RefersToEnclosingVariableOrCapture=*/true);
 
 
   MemberExpr *Deref = M.makeMemberExpression(FlagDecl, FlagFieldDecl);


Index: test/Analysis/call_once.cpp
===
--- test/Analysis/call_once.cpp
+++ test/Analysis/call_once.cpp
@@ -17,7 +17,7 @@
 #endif
 
 template 
-void call_once(once_flag &o, Callable func, Args... args) {};
+void call_once(once_flag &o, Callable&& func, Args&&... args) {};
 
 } // namespace std
 
Index: lib/Analysis/BodyFarm.cpp
===
--- lib/Analysis/BodyFarm.cpp
+++ lib/Analysis/BodyFarm.cpp
@@ -63,8 +63,7 @@
   
   /// Create a new DeclRefExpr for the referenced variable.
   DeclRefExpr *makeDeclRefExpr(const VarDecl *D,
-   bool RefersToEnclosingVariableOrCapture = false,
-   bool GetNonReferenceType = fals

Re: Patch bug 27628 (clang-tidy should exit with a failure code when there are errors)

2017-10-17 Thread Antoni Boucher via cfe-commits

Since the patch was redirected to the right mailing list and the subject
was edited, I believe everything is okay, now?
Is there any news?
Thanks.

On Thu, Sep 28, 2017 at 06:56:57PM +, Friedman, Eli wrote:

When you're submitting a patch, please make sure you're sending 
it to the right list, and the "subject" line actually describes 
what the patch changes; otherwise, reviewers won't notice the 
patch.  Optionally, you can submit a patch using Phabricator, 
a tool which which makes patch reviews a little easier.  See 
http://llvm.org/docs/DeveloperPolicy.html#code-reviews


-Eli

On 9/28/2017 10:22 AM, Antoni Boucher via cfe-commits wrote:


Any news on this?


Aaand the patch itself...

-K

On 9/8/2017 10:32 AM, Krzysztof Parzyszek via cfe-commits wrote:


This should to to cfe-commits. Redirecting.

-Krzysztof

On 9/8/2017 10:25 AM, Antoni Boucher via llvm-commits wrote:

Hello. I've fixed the bug 27628: 
https://bugs.llvm.org/show_bug.cgi?id=27628


I attached the patch.

Thanks.


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





-- Qualcomm Innovation Center, Inc. is a member of Code 
Aurora Forum, hosted by The Linux Foundation -- 
next part -- An embedded and charset-unspecified 
text was scrubbed... Name: clang-tidy-error-code.diff URL: 



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



-- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation 
Center, Inc. is a member of Code Aurora Forum, a Linux Foundation 
Collaborative Project



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


Re: Patch bug 27628 (clang-tidy should exit with a failure code when there are errors)

2017-10-17 Thread Friedman, Eli via cfe-commits
Sometimes people just lose track; "pinging" is normal (see 
http://llvm.org/docs/DeveloperPolicy.html#code-reviews).  And sometimes 
it's helpful to CC reviewers in the area; adding Alexander Kornienko.


-Eli

On 10/17/2017 12:03 PM, Antoni Boucher wrote:

Since the patch was redirected to the right mailing list and the subject
was edited, I believe everything is okay, now?
Is there any news?
Thanks.

On Thu, Sep 28, 2017 at 06:56:57PM +, Friedman, Eli wrote:

When you're submitting a patch, please make sure you're sending it to 
the right list, and the "subject" line actually describes what the 
patch changes; otherwise, reviewers won't notice the patch.  
Optionally, you can submit a patch using Phabricator, a tool which 
which makes patch reviews a little easier.  See 
http://llvm.org/docs/DeveloperPolicy.html#code-reviews


-Eli

On 9/28/2017 10:22 AM, Antoni Boucher via cfe-commits wrote:


Any news on this?


Aaand the patch itself...

-K

On 9/8/2017 10:32 AM, Krzysztof Parzyszek via cfe-commits wrote:


This should to to cfe-commits. Redirecting.

-Krzysztof

On 9/8/2017 10:25 AM, Antoni Boucher via llvm-commits wrote:

Hello. I've fixed the bug 27628: 
https://bugs.llvm.org/show_bug.cgi?id=27628


I attached the patch.

Thanks.


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





-- Qualcomm Innovation Center, Inc. is a member of Code Aurora 
Forum, hosted by The Linux Foundation -- next part 
-- An embedded and charset-unspecified text was 
scrubbed... Name: clang-tidy-error-code.diff URL: 



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



-- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation 
Center, Inc. is a member of Code Aurora Forum, a Linux Foundation 
Collaborative Project




--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux 
Foundation Collaborative Project

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


[libcxx] r316021 - Refactor std::list node allocation logic.

2017-10-17 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Oct 17 12:12:23 2017
New Revision: 316021

URL: http://llvm.org/viewvc/llvm-project?rev=316021&view=rev
Log:
Refactor std::list node allocation logic.

The logic to allocate a node within std::list was repeated
in a bunch of places. This is unneeded. This patch refactors
the shared logic into a single function to reduce duplication.

This patch is part of a set to clean up node construction in
general, but refactoring construction requires some more work
to make it work cleanly in C++03

Modified:
libcxx/trunk/include/list

Modified: libcxx/trunk/include/list
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/list?rev=316021&r1=316020&r2=316021&view=diff
==
--- libcxx/trunk/include/list (original)
+++ libcxx/trunk/include/list Tue Oct 17 12:12:23 2017
@@ -1071,6 +1071,16 @@ public:
 
 bool __invariants() const;
 
+typedef __allocator_destructor<__node_allocator> __node_destructor;
+typedef unique_ptr<__node, __node_destructor> __hold_pointer;
+
+_LIBCPP_INLINE_VISIBILITY
+__hold_pointer __allocate_node(__node_allocator& __na) {
+  __node_pointer __p = __node_alloc_traits::allocate(__na, 1);
+  __p->__prev_ = nullptr;
+  return __hold_pointer(__p, __node_destructor(__na, 1));
+}
+
 #if _LIBCPP_DEBUG_LEVEL >= 2
 
 bool __dereferenceable(const const_iterator* __i) const;
@@ -1397,9 +1407,7 @@ list<_Tp, _Alloc>::insert(const_iterator
 " referring to this list");
 #endif
 __node_allocator& __na = base::__node_alloc();
-typedef __allocator_destructor<__node_allocator> _Dp;
-unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), 
_Dp(__na, 1));
-__hold->__prev_ = 0;
+__hold_pointer __hold = __allocate_node(__na);
 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), 
__x);
 __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link());
 ++base::__sz();
@@ -1426,9 +1434,7 @@ list<_Tp, _Alloc>::insert(const_iterator
 {
 size_type __ds = 0;
 __node_allocator& __na = base::__node_alloc();
-typedef __allocator_destructor<__node_allocator> _Dp;
-unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), 
_Dp(__na, 1));
-__hold->__prev_ = 0;
+__hold_pointer __hold = __allocate_node(__na);
 __node_alloc_traits::construct(__na, 
_VSTD::addressof(__hold->__value_), __x);
 ++__ds;
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1494,9 +1500,7 @@ list<_Tp, _Alloc>::insert(const_iterator
 {
 size_type __ds = 0;
 __node_allocator& __na = base::__node_alloc();
-typedef __allocator_destructor<__node_allocator> _Dp;
-unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), 
_Dp(__na, 1));
-__hold->__prev_ = 0;
+__hold_pointer __hold = __allocate_node(__na);
 __node_alloc_traits::construct(__na, 
_VSTD::addressof(__hold->__value_), *__f);
 ++__ds;
 #if _LIBCPP_DEBUG_LEVEL >= 2
@@ -1549,8 +1553,7 @@ void
 list<_Tp, _Alloc>::push_front(const value_type& __x)
 {
 __node_allocator& __na = base::__node_alloc();
-typedef __allocator_destructor<__node_allocator> _Dp;
-unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), 
_Dp(__na, 1));
+__hold_pointer __hold = __allocate_node(__na);
 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), 
__x);
 __link_pointer __nl = __hold->__as_link();
 __link_nodes_at_front(__nl, __nl);
@@ -1563,8 +1566,7 @@ void
 list<_Tp, _Alloc>::push_back(const value_type& __x)
 {
 __node_allocator& __na = base::__node_alloc();
-typedef __allocator_destructor<__node_allocator> _Dp;
-unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), 
_Dp(__na, 1));
+__hold_pointer __hold = __allocate_node(__na);
 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), 
__x);
 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
 ++base::__sz();
@@ -1578,8 +1580,7 @@ void
 list<_Tp, _Alloc>::push_front(value_type&& __x)
 {
 __node_allocator& __na = base::__node_alloc();
-typedef __allocator_destructor<__node_allocator> _Dp;
-unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), 
_Dp(__na, 1));
+__hold_pointer __hold = __allocate_node(__na);
 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), 
_VSTD::move(__x));
 __link_nodes_at_front(__hold.get()->__as_link(), 
__hold.get()->__as_link());
 ++base::__sz();
@@ -1591,8 +1592,7 @@ void
 list<_Tp, _Alloc>::push_back(value_type&& __x)
 {
 __node_allocator& __na = base::__node_alloc();
-typedef __allocator_destructor<__node_allocator> _Dp;
-unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), 
_Dp(__na, 1));
+__hold_pointer __hold = __allocate_node(__na);
 _

[PATCH] D38939: [clangd] Handle exit notification (proper shutdown)

2017-10-17 Thread Raoul Wols via Phabricator via cfe-commits
rwols updated this revision to Diff 119370.
rwols added a comment.

- Add test shutdown-with-exit.test
- Add test shutdown-without-exit.test
- Make protocol.test pass by inverting exit code ("# RUN: not ...")


https://reviews.llvm.org/D38939

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  clangd/tool/ClangdMain.cpp
  test/clangd/authority-less-uri.test
  test/clangd/completion-priorities.test
  test/clangd/completion-qualifiers.test
  test/clangd/completion-snippet.test
  test/clangd/completion.test
  test/clangd/definitions.test
  test/clangd/diagnostics-preamble.test
  test/clangd/diagnostics.test
  test/clangd/did-change-watch-files.test
  test/clangd/extra-flags.test
  test/clangd/fixits.test
  test/clangd/formatting.test
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  test/clangd/input-mirror.test
  test/clangd/protocol.test
  test/clangd/shutdown-with-exit.test
  test/clangd/shutdown-without-exit.test
  test/clangd/signature-help.test
  test/clangd/unsupported-method.test

Index: test/clangd/unsupported-method.test
===
--- test/clangd/unsupported-method.test
+++ test/clangd/unsupported-method.test
@@ -17,3 +17,7 @@
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":2,"method":"shutdown"}
+# CHECK: {"jsonrpc":"2.0","id":2,"result":null}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/signature-help.test
===
--- test/clangd/signature-help.test
+++ test/clangd/signature-help.test
@@ -40,3 +40,7 @@
 Content-Length: 49
 
 {"jsonrpc":"2.0","id":10,"method":"shutdown"}
+# CHECK: {"jsonrpc":"2.0","id":10,"result":null}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/shutdown-without-exit.test
===
--- /dev/null
+++ test/clangd/shutdown-without-exit.test
@@ -0,0 +1,6 @@
+# RUN: not clangd -run-synchronously < %s
+# vim: fileformat=dos
+# It is absolutely vital that this file has CRLF line endings.
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/shutdown-with-exit.test
===
--- /dev/null
+++ test/clangd/shutdown-with-exit.test
@@ -0,0 +1,9 @@
+# RUN: clangd -run-synchronously < %s
+# vim: fileformat=dos
+# It is absolutely vital that this file has CRLF line endings.
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":3,"method":"shutdown"}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/protocol.test
===
--- test/clangd/protocol.test
+++ test/clangd/protocol.test
@@ -1,5 +1,5 @@
-# RUN: clangd -run-synchronously < %s | FileCheck %s
-# RUN: clangd -run-synchronously < %s 2>&1 | FileCheck -check-prefix=STDERR %s
+# RUN: not clangd -run-synchronously < %s | FileCheck %s
+# RUN: not clangd -run-synchronously < %s 2>&1 | FileCheck -check-prefix=STDERR %s
 # vim: fileformat=dos
 # It is absolutely vital that this file has CRLF line endings.
 #
Index: test/clangd/input-mirror.test
===
--- test/clangd/input-mirror.test
+++ test/clangd/input-mirror.test
@@ -152,3 +152,7 @@
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":3,"method":"shutdown"}
+# CHECK: {"jsonrpc":"2.0","id":3,"result":null}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/initialize-params.test
===
--- test/clangd/initialize-params.test
+++ test/clangd/initialize-params.test
@@ -20,3 +20,7 @@
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":3,"method":"shutdown"}
+# CHECK: {"jsonrpc":"2.0","id":3,"result":null}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/initialize-params-invalid.test
===
--- test/clangd/initialize-params-invalid.test
+++ test/clangd/initialize-params-invalid.test
@@ -20,3 +20,7 @@
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":3,"method":"shutdown"}
+# CHECK: {"jsonrpc":"2.0","id":3,"result":null}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/formatting.test
===
--- test/clangd/formatting.test
+++ test/clangd/formatting.test
@@ -65,3 +65,7 @@
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":6,"method":"shutdown"}
+# CHECK: {"jsonrpc":"2.0","id":6,"result":null}
+Content-Length: 33
+
+{"jsonrpc":"2.0":"method":"exit"}
Index: test/clangd/fixits.test
===
--- test/clangd/fixits.test
+++ test/clangd/fixits.test
@@ -26,3 +26,7 @@
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":3,"method":"shutdown"}
+# CHECK

[PATCH] D38939: [clangd] Handle exit notification (proper shutdown)

2017-10-17 Thread Raoul Wols via Phabricator via cfe-commits
rwols added a comment.

> So I'm not totally convinced that treating an abrupt exit or EOF as an error 
> is worth the hassle

Agreed, at least from the POV of a client clangd shuts down gracefully now.


https://reviews.llvm.org/D38939



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


r316022 - Expose ConsumeAnyToken interface to external clients.

2017-10-17 Thread Vassil Vassilev via cfe-commits
Author: vvassilev
Date: Tue Oct 17 12:38:57 2017
New Revision: 316022

URL: http://llvm.org/viewvc/llvm-project?rev=316022&view=rev
Log:
Expose ConsumeAnyToken interface to external clients.

Modified:
cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=316022&r1=316021&r2=316022&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Oct 17 12:38:57 2017
@@ -338,6 +338,27 @@ public:
 return true;
   }
 
+  /// ConsumeAnyToken - Dispatch to the right Consume* method based on the
+  /// current token type.  This should only be used in cases where the type of
+  /// the token really isn't known, e.g. in error recovery.
+  SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok = false) {
+if (isTokenParen())
+  return ConsumeParen();
+if (isTokenBracket())
+  return ConsumeBracket();
+if (isTokenBrace())
+  return ConsumeBrace();
+if (isTokenStringLiteral())
+  return ConsumeStringToken();
+if (Tok.is(tok::code_completion))
+  return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
+  : handleUnexpectedCodeCompletionToken();
+if (Tok.isAnnotation())
+  return ConsumeAnnotationToken();
+return ConsumeToken();
+  }
+
+
   SourceLocation getEndOfPreviousToken() {
 return PP.getLocForEndOfToken(PrevTokLocation);
   }
@@ -388,26 +409,6 @@ private:
   PP.EnterToken(Next);
   }
 
-  /// ConsumeAnyToken - Dispatch to the right Consume* method based on the
-  /// current token type.  This should only be used in cases where the type of
-  /// the token really isn't known, e.g. in error recovery.
-  SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok = false) {
-if (isTokenParen())
-  return ConsumeParen();
-if (isTokenBracket())
-  return ConsumeBracket();
-if (isTokenBrace())
-  return ConsumeBrace();
-if (isTokenStringLiteral())
-  return ConsumeStringToken();
-if (Tok.is(tok::code_completion))
-  return ConsumeCodeCompletionTok ? ConsumeCodeCompletionToken()
-  : handleUnexpectedCodeCompletionToken();
-if (Tok.isAnnotation())
-  return ConsumeAnnotationToken();
-return ConsumeToken();
-  }
-
   SourceLocation ConsumeAnnotationToken() {
 assert(Tok.isAnnotation() && "wrong consume method");
 SourceLocation Loc = Tok.getLocation();


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


[PATCH] D39017: [CMake] Build Fuchsia toolchain as -O3

2017-10-17 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
Herald added a subscriber: mgorny.

Repository:
  rL LLVM

https://reviews.llvm.org/D39017

Files:
  cmake/caches/Fuchsia-stage2.cmake


Index: cmake/caches/Fuchsia-stage2.cmake
===
--- cmake/caches/Fuchsia-stage2.cmake
+++ cmake/caches/Fuchsia-stage2.cmake
@@ -30,8 +30,8 @@
 endif()
 
 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
-set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
-set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
 
 set(LLVM_BUILTIN_TARGETS "x86_64-fuchsia;aarch64-fuchsia" CACHE STRING "")
 foreach(target x86_64;aarch64)


Index: cmake/caches/Fuchsia-stage2.cmake
===
--- cmake/caches/Fuchsia-stage2.cmake
+++ cmake/caches/Fuchsia-stage2.cmake
@@ -30,8 +30,8 @@
 endif()
 
 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
-set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE STRING "")
-set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE STRING "")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE STRING "")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE STRING "")
 
 set(LLVM_BUILTIN_TARGETS "x86_64-fuchsia;aarch64-fuchsia" CACHE STRING "")
 foreach(target x86_64;aarch64)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39017: [CMake] Build Fuchsia toolchain as -O3

2017-10-17 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr accepted this revision.
mcgrathr added a comment.
This revision is now accepted and ready to land.

LGTM
Since we use lld, -Wl,-O2 also helps make the binaries smaller.


Repository:
  rL LLVM

https://reviews.llvm.org/D39017



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


[PATCH] D38126: Make TBAA information to be part of LValueBaseInfo

2017-10-17 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev updated this revision to Diff 119373.
kosarev edited the summary of this revision.
kosarev added a comment.

Rebased on top of https://reviews.llvm.org/D39008 and ready for review.


https://reviews.llvm.org/D38126

Files:
  CodeGen/CGAtomic.cpp
  CodeGen/CGClass.cpp
  CodeGen/CGExpr.cpp
  CodeGen/CGObjCRuntime.cpp
  CodeGen/CGOpenMPRuntime.cpp
  CodeGen/CGValue.h
  CodeGen/CodeGenFunction.cpp
  CodeGen/CodeGenFunction.h

Index: CodeGen/CodeGenFunction.h
===
--- CodeGen/CodeGenFunction.h
+++ CodeGen/CodeGenFunction.h
@@ -1919,45 +1919,39 @@
 
   LValue MakeAddrLValue(Address Addr, QualType T,
 AlignmentSource Source = AlignmentSource::Type) {
-return LValue::MakeAddr(Addr, T, getContext(), LValueBaseInfo(Source),
-CGM.getTBAAAccessInfo(T));
+return LValue::MakeAddr(Addr, T, getContext(),
+LValueBaseInfo(Source, CGM.getTBAAAccessInfo(T)));
   }
 
-  LValue MakeAddrLValue(Address Addr, QualType T, LValueBaseInfo BaseInfo,
-TBAAAccessInfo TBAAInfo) {
-return LValue::MakeAddr(Addr, T, getContext(), BaseInfo, TBAAInfo);
+  LValue MakeAddrLValue(Address Addr, QualType T, LValueBaseInfo BaseInfo) {
+return LValue::MakeAddr(Addr, T, getContext(), BaseInfo);
   }
 
   LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
 AlignmentSource Source = AlignmentSource::Type) {
 return LValue::MakeAddr(Address(V, Alignment), T, getContext(),
-LValueBaseInfo(Source), CGM.getTBAAAccessInfo(T));
+LValueBaseInfo(Source, CGM.getTBAAAccessInfo(T)));
   }
 
   LValue MakeAddrLValue(llvm::Value *V, QualType T, CharUnits Alignment,
-LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
-return LValue::MakeAddr(Address(V, Alignment), T, getContext(),
-BaseInfo, TBAAInfo);
+LValueBaseInfo BaseInfo) {
+return LValue::MakeAddr(Address(V, Alignment), T, getContext(), BaseInfo);
   }
 
   LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T);
   LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T);
   CharUnits getNaturalTypeAlignment(QualType T,
 LValueBaseInfo *BaseInfo = nullptr,
-TBAAAccessInfo *TBAAInfo = nullptr,
 bool forPointeeType = false);
   CharUnits getNaturalPointeeTypeAlignment(QualType T,
-   LValueBaseInfo *BaseInfo = nullptr,
-   TBAAAccessInfo *TBAAInfo = nullptr);
+   LValueBaseInfo *BaseInfo = nullptr);
 
   Address EmitLoadOfReference(Address Ref, const ReferenceType *RefTy,
-  LValueBaseInfo *BaseInfo = nullptr,
-  TBAAAccessInfo *TBAAInfo = nullptr);
+  LValueBaseInfo *BaseInfo = nullptr);
   LValue EmitLoadOfReferenceLValue(Address Ref, const ReferenceType *RefTy);
 
   Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy,
-LValueBaseInfo *BaseInfo = nullptr,
-TBAAAccessInfo *TBAAInfo = nullptr);
+LValueBaseInfo *BaseInfo = nullptr);
   LValue EmitLoadOfPointerLValue(Address Ptr, const PointerType *PtrTy);
 
   /// CreateTempAlloca - This creates an alloca and inserts it into the entry
@@ -3083,13 +3077,13 @@
 SourceLocation Loc,
 AlignmentSource Source = AlignmentSource::Type,
 bool isNontemporal = false) {
-return EmitLoadOfScalar(Addr, Volatile, Ty, Loc, LValueBaseInfo(Source),
-CGM.getTBAAAccessInfo(Ty), isNontemporal);
+return EmitLoadOfScalar(Addr, Volatile, Ty, Loc,
+LValueBaseInfo(Source, CGM.getTBAAAccessInfo(Ty)),
+isNontemporal);
   }
 
   llvm::Value *EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty,
 SourceLocation Loc, LValueBaseInfo BaseInfo,
-TBAAAccessInfo TBAAInfo,
 bool isNontemporal = false);
 
   /// EmitLoadOfScalar - Load a scalar value from an address, taking
@@ -3105,13 +3099,13 @@
  bool Volatile, QualType Ty,
  AlignmentSource Source = AlignmentSource::Type,
  bool isInit = false, bool isNontemporal = false) {
-EmitStoreOfScalar(Value, Addr, Volatile, Ty, LValueBaseInfo(Source),
-  CGM.getTBAAAccessInfo(Ty), isInit, isNontemporal);
+EmitStoreOfScalar(Value, Addr, Volatile, Ty,
+  LValueBase

[PATCH] D5767: Template Instantiation Observer + a few other templight-related changes

2017-10-17 Thread Ábel Sinkovics via Phabricator via cfe-commits
sabel83 updated this revision to Diff 119377.
sabel83 added reviewers: cfe-commits, klimek, mclow.lists, martong, xazax.hun.

https://reviews.llvm.org/D5767

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/FrontendActions.h
  include/clang/Frontend/FrontendOptions.h
  include/clang/FrontendTool/Utils.h
  include/clang/Sema/Sema.h
  include/clang/Sema/TemplateInstCallbacks.h
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/FrontendActions.cpp
  lib/FrontendTool/ExecuteCompilerInvocation.cpp
  lib/Parse/ParseAST.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Sema/SemaType.cpp
  test/Sema/templight-deduced-func.cpp
  test/Sema/templight-default-arg-inst.cpp
  test/Sema/templight-default-func-arg.cpp
  test/Sema/templight-default-template-arg.cpp
  test/Sema/templight-exception-spec-func.cpp
  test/Sema/templight-explicit-template-arg.cpp
  test/Sema/templight-memoization.cpp
  test/Sema/templight-nested-memoization.cpp
  test/Sema/templight-nested-template-instantiation.cpp
  test/Sema/templight-one-instantiation.cpp
  test/Sema/templight-prior-template-arg.cpp
  tools/CMakeLists.txt

Index: tools/CMakeLists.txt
===
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -34,3 +34,4 @@
 
 # libclang may require clang-tidy in clang-tools-extra.
 add_clang_subdirectory(libclang)
+add_subdirectory(templight)
Index: test/Sema/templight-prior-template-arg.cpp
===
--- /dev/null
+++ test/Sema/templight-prior-template-arg.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -templight-dump %s 2>&1 | FileCheck %s
+template
+class A {};
+
+template  class Outer>
+class B {};
+
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B::Outer'$}}
+// CHECK: {{^kind:[ ]+PriorTemplateArgumentSubstitution$}}
+// CHECK: {{^event:[ ]+Begin$}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:}}[[@LINE+50]]{{:1'$}}
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B::Outer'$}}
+// CHECK: {{^kind:[ ]+PriorTemplateArgumentSubstitution$}}
+// CHECK: {{^event:[ ]+End$}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:}}[[@LINE+45]]{{:1'$}}
+//
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+TemplateInstantiation$}}
+// CHECK: {{^event:[ ]+Begin$}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:}}[[@LINE+39]]{{:6'$}}
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+TemplateInstantiation$}}
+// CHECK: {{^event:[ ]+End$}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:}}[[@LINE+34]]{{:6'$}}
+//
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+TemplateInstantiation$}}
+// CHECK: {{^event:[ ]+Begin$}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:}}[[@LINE+28]]{{:6'$}}
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+TemplateInstantiation$}}
+// CHECK: {{^event:[ ]+End$}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:}}[[@LINE+23]]{{:6'$}}
+//
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+Memoization$}}
+// CHECK: {{^event:[ ]+Begin$}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:}}[[@LINE+17]]{{:6'$}}
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+Memoization$}}
+// CHECK: {{^event:[ ]+End$}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:}}[[@LINE+12]]{{:6'$}}
+//
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+Memoization$}}
+// CHECK: {{^event:[ ]+Begin$}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:}}[[@LINE+6]]{{:6'$}}
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'B'$}}
+// CHECK: {{^kind:[ ]+Memoization$}}
+// CHECK: {{^event:[ ]+End$}}
+// CHECK: {{^poi:[ ]+'.*templight-prior-template-arg.cpp:}}[[@LINE+1]]{{:6'$}}
+B b;
Index: test/Sema/templight-one-instantiation.cpp
===
--- /dev/null
+++ test/Sema/templight-one-instantiation.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -templight-dump %s 2>&1 | FileCheck %s
+
+template 
+struct foo {};
+
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'foo'$}}
+// CHECK: {{^kind:[ ]+TemplateInstantiation$}}
+// CHECK: {{^event:[ ]+Begin$}}
+// CHECK: {{^poi:[ ]+'.*templight-one-instantiation.cpp:}}[[@LINE+6]]{{:10'$}}
+// CHECK-LABEL: {{^---$}}
+// CHECK: {{^name:[ ]+'foo'$}}
+// CHECK: {{^kind:[ ]+TemplateInstantiation$}}
+// CHECK: {{^event:[ ]+End$}}
+// CHECK: {{^poi:[ ]+'.*templight-one-instantiation.cpp:}}[[@LINE+1]]{{:10'$}}
+foo x;
Index: test/Sema/templight-nested-template-instantiation.cpp
===
--- /dev/null
+++ test/Sema/templight-nested-template-instantiation.cpp
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -templight-dump %s 2>&1 | FileCheck %s

[PATCH] D39013: [CFG] Relax Wexceptions warning on rethrow

2017-10-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 119379.
erichkeane edited the summary of this revision.
erichkeane added a comment.

I've convinced myself that a re-throw with a catch around it should not be 
diagnosed, otherwise there is no way to suppress the warning in this case.  It 
ends up being a false-positive in many cases.


https://reviews.llvm.org/D39013

Files:
  lib/Sema/AnalysisBasedWarnings.cpp
  test/SemaCXX/warn-throw-out-noexcept-func.cpp


Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -293,7 +293,7 @@
   if (Throw->getSubExpr())
 ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
   if (!ThrowType)
-return false;
+return true;
   const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
   if (!CaughtType)
 return true;
Index: test/SemaCXX/warn-throw-out-noexcept-func.cpp
===
--- test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -239,12 +239,22 @@
   } catch (const S &s) {
   }
 }
-void o_ShouldDiag() noexcept { //expected-note {{function declared 
non-throwing here}}
+// As seen in p34973, this should not throw the warning.  If there is an active
+// exception, catch(...) catches everything. 
+void o_ShouldNotDiag() noexcept {
   try {
-throw; //expected-warning {{has a non-throwing exception specification 
but}}
+throw;
   } catch (...) {
   }
 }
+// In fact, a rethrow with ANY catch should be trusted here, otherwise it is
+// going to result in many false positives.
+void p_ShouldNotDiag() noexcept {
+  try {
+throw;
+  } catch (int){
+  }
+}
 
 #define NOEXCEPT noexcept
 void with_macro() NOEXCEPT { //expected-note {{function declared non-throwing 
here}}


Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -293,7 +293,7 @@
   if (Throw->getSubExpr())
 ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
   if (!ThrowType)
-return false;
+return true;
   const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
   if (!CaughtType)
 return true;
Index: test/SemaCXX/warn-throw-out-noexcept-func.cpp
===
--- test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -239,12 +239,22 @@
   } catch (const S &s) {
   }
 }
-void o_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
+// As seen in p34973, this should not throw the warning.  If there is an active
+// exception, catch(...) catches everything. 
+void o_ShouldNotDiag() noexcept {
   try {
-throw; //expected-warning {{has a non-throwing exception specification but}}
+throw;
   } catch (...) {
   }
 }
+// In fact, a rethrow with ANY catch should be trusted here, otherwise it is
+// going to result in many false positives.
+void p_ShouldNotDiag() noexcept {
+  try {
+throw;
+  } catch (int){
+  }
+}
 
 #define NOEXCEPT noexcept
 void with_macro() NOEXCEPT { //expected-note {{function declared non-throwing here}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39013: [CFG] Relax Wexceptions warning on rethrow

2017-10-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D39013#900046, @erichkeane wrote:

> I've convinced myself that a re-throw with a catch around it should not be 
> diagnosed, otherwise there is no way to suppress the warning in this case.  
> It ends up being a false-positive in many cases.


Wouldn't a catch-all handler suppress the warning in that case? e.g.,

  void f() noexcept {
try {
  throw; // rethrows
} catch (int) {
  // We hope this catches it, and if it always does, then this is a fp 
warning.
} catch (...) {
  // However, without cross-TU analysis, we can't know that detail and it 
seems plausible that
  // the active exception object is something else, so the catch-all is not 
unreasonable and adds
  // extra safety. The diagnostic (even if a fp) requires the developer to 
think about this case.
  assert(false);
}
  }




Comment at: lib/Sema/AnalysisBasedWarnings.cpp:299
   if (!ThrowType)
 return false;
   if (ThrowType->isReferenceType())

erichkeane wrote:
> The other potential fix here is to simply change this line here to "return 
> true;".  This would result the warning being suppressed on 'rethrow' if there 
> is any catch statements. 
> 
> I wonder what the opinion of the reviewers is on this one.
I'm a little bit concerned about it, truth be told. The current behavior has 
false positives, and this patch trades those for false negatives. The question 
boils down to which is the more likely scenario. Rethrow from within a try 
block that catches the exception being rethrown seems like a rather unlikely 
scenario to me. Do you have examples of this being a false positive with 
real-world code?

I do agree that the catch-all handler should silence the diagnostic, however.


https://reviews.llvm.org/D39013



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


[PATCH] D39013: [CFG] Relax Wexceptions warning on rethrow

2017-10-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

> Wouldn't a catch-all handler suppress the warning in that case? e.g.,

Yep, you're right of course.  I'll revert to my first patch and update this.  
I'd surmised that false-positives were worse than false-negatives, but since 
there is a trivial workaround, I'm ok with that.  Thanks for the quick review!




Comment at: lib/Sema/AnalysisBasedWarnings.cpp:299
   if (!ThrowType)
 return false;
   if (ThrowType->isReferenceType())

aaron.ballman wrote:
> erichkeane wrote:
> > The other potential fix here is to simply change this line here to "return 
> > true;".  This would result the warning being suppressed on 'rethrow' if 
> > there is any catch statements. 
> > 
> > I wonder what the opinion of the reviewers is on this one.
> I'm a little bit concerned about it, truth be told. The current behavior has 
> false positives, and this patch trades those for false negatives. The 
> question boils down to which is the more likely scenario. Rethrow from within 
> a try block that catches the exception being rethrown seems like a rather 
> unlikely scenario to me. Do you have examples of this being a false positive 
> with real-world code?
> 
> I do agree that the catch-all handler should silence the diagnostic, however.
I don't have any examples, just the bug report.  


https://reviews.llvm.org/D39013



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


r316026 - Enable support for the [[nodiscard]] attribute from WG14 N2050 when enabling double square bracket attributes in C code.

2017-10-17 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Oct 17 13:33:35 2017
New Revision: 316026

URL: http://llvm.org/viewvc/llvm-project?rev=316026&view=rev
Log:
Enable support for the [[nodiscard]] attribute from WG14 N2050 when enabling 
double square bracket attributes in C code.

Added:
cfe/trunk/test/Sema/c2x-nodiscard.c
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/lib/AST/Decl.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=316026&r1=316025&r2=316026&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Tue Oct 17 13:33:35 2017
@@ -2004,10 +2004,10 @@ def WarnUnused : InheritableAttr {
 }
 
 def WarnUnusedResult : InheritableAttr {
-  let Spellings = [CXX11<"", "nodiscard", 201603>,
+  let Spellings = [CXX11<"", "nodiscard", 201603>, C2x<"", "nodiscard">,
CXX11<"clang", "warn_unused_result">,
GCC<"warn_unused_result">];
-  let Subjects = SubjectList<[ObjCMethod, Enum, CXXRecord, FunctionLike],
+  let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike],
  WarnDiag, "ExpectedFunctionMethodEnumOrClass">;
   let Documentation = [WarnUnusedResultsDocs];
 }

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=316026&r1=316025&r2=316026&view=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Tue Oct 17 13:33:35 2017
@@ -3056,7 +3056,8 @@ SourceRange FunctionDecl::getExceptionSp
 const Attr *FunctionDecl::getUnusedResultAttr() const {
   QualType RetType = getReturnType();
   if (RetType->isRecordType()) {
-if (const CXXRecordDecl *Ret = RetType->getAsCXXRecordDecl()) {
+if (const auto *Ret =
+dyn_cast_or_null(RetType->getAsTagDecl())) {
   if (const auto *R = Ret->getAttr())
 return R;
 }

Added: cfe/trunk/test/Sema/c2x-nodiscard.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c2x-nodiscard.c?rev=316026&view=auto
==
--- cfe/trunk/test/Sema/c2x-nodiscard.c (added)
+++ cfe/trunk/test/Sema/c2x-nodiscard.c Tue Oct 17 13:33:35 2017
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
+
+struct [[nodiscard]] S1 { // ok
+  int i;
+};
+struct [[nodiscard nodiscard]] S2 { // expected-error {{attribute 'nodiscard' 
cannot appear multiple times in an attribute specifier}}
+  int i;
+};
+struct [[nodiscard("Wrong")]] S3 { // expected-error {{'nodiscard' cannot have 
an argument list}}
+  int i;
+};
+
+[[nodiscard]] int f1(void);
+enum [[nodiscard]] E1 { One };
+
+[[nodiscard]] int i; // expected-warning {{'nodiscard' attribute only applies 
to functions, methods, enums, and classes}}
+
+struct [[nodiscard]] S4 {
+  int i;
+};
+struct S4 get_s(void);
+
+enum [[nodiscard]] E2 { Two };
+enum E2 get_e(void);
+
+[[nodiscard]] int get_i();
+
+void f2(void) {
+  get_s(); // expected-warning {{ignoring return value of function declared 
with 'nodiscard' attribute}}
+  get_i(); // expected-warning {{ignoring return value of function declared 
with 'nodiscard' attribute}}
+  get_e(); // expected-warning {{ignoring return value of function declared 
with 'nodiscard' attribute}}
+
+  // Okay, warnings are not encouraged
+  (void)get_s();
+  (void)get_i();
+  (void)get_e();
+}
+
+struct [[nodiscard]] error_info{
+  int i;
+};
+
+struct error_info enable_missile_safety_mode(void);
+void launch_missiles(void);
+void test_missiles(void) {
+  enable_missile_safety_mode(); // expected-warning {{ignoring return value of 
function declared with 'nodiscard'}}
+  launch_missiles();
+}
+


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


Re: r316026 - Enable support for the [[nodiscard]] attribute from WG14 N2050 when enabling double square bracket attributes in C code.

2017-10-17 Thread Aaron Ballman via cfe-commits
I said WG14 N2050 when I meant N2051. My fat fingers and I apologize
for the confusion with the commit log.

~Aaron

On Tue, Oct 17, 2017 at 4:33 PM, Aaron Ballman via cfe-commits
 wrote:
> Author: aaronballman
> Date: Tue Oct 17 13:33:35 2017
> New Revision: 316026
>
> URL: http://llvm.org/viewvc/llvm-project?rev=316026&view=rev
> Log:
> Enable support for the [[nodiscard]] attribute from WG14 N2050 when enabling 
> double square bracket attributes in C code.
>
> Added:
> cfe/trunk/test/Sema/c2x-nodiscard.c
> Modified:
> cfe/trunk/include/clang/Basic/Attr.td
> cfe/trunk/lib/AST/Decl.cpp
>
> Modified: cfe/trunk/include/clang/Basic/Attr.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=316026&r1=316025&r2=316026&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/Attr.td (original)
> +++ cfe/trunk/include/clang/Basic/Attr.td Tue Oct 17 13:33:35 2017
> @@ -2004,10 +2004,10 @@ def WarnUnused : InheritableAttr {
>  }
>
>  def WarnUnusedResult : InheritableAttr {
> -  let Spellings = [CXX11<"", "nodiscard", 201603>,
> +  let Spellings = [CXX11<"", "nodiscard", 201603>, C2x<"", "nodiscard">,
> CXX11<"clang", "warn_unused_result">,
> GCC<"warn_unused_result">];
> -  let Subjects = SubjectList<[ObjCMethod, Enum, CXXRecord, FunctionLike],
> +  let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike],
>   WarnDiag, "ExpectedFunctionMethodEnumOrClass">;
>let Documentation = [WarnUnusedResultsDocs];
>  }
>
> Modified: cfe/trunk/lib/AST/Decl.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=316026&r1=316025&r2=316026&view=diff
> ==
> --- cfe/trunk/lib/AST/Decl.cpp (original)
> +++ cfe/trunk/lib/AST/Decl.cpp Tue Oct 17 13:33:35 2017
> @@ -3056,7 +3056,8 @@ SourceRange FunctionDecl::getExceptionSp
>  const Attr *FunctionDecl::getUnusedResultAttr() const {
>QualType RetType = getReturnType();
>if (RetType->isRecordType()) {
> -if (const CXXRecordDecl *Ret = RetType->getAsCXXRecordDecl()) {
> +if (const auto *Ret =
> +dyn_cast_or_null(RetType->getAsTagDecl())) {
>if (const auto *R = Ret->getAttr())
>  return R;
>  }
>
> Added: cfe/trunk/test/Sema/c2x-nodiscard.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c2x-nodiscard.c?rev=316026&view=auto
> ==
> --- cfe/trunk/test/Sema/c2x-nodiscard.c (added)
> +++ cfe/trunk/test/Sema/c2x-nodiscard.c Tue Oct 17 13:33:35 2017
> @@ -0,0 +1,49 @@
> +// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify 
> %s
> +
> +struct [[nodiscard]] S1 { // ok
> +  int i;
> +};
> +struct [[nodiscard nodiscard]] S2 { // expected-error {{attribute 
> 'nodiscard' cannot appear multiple times in an attribute specifier}}
> +  int i;
> +};
> +struct [[nodiscard("Wrong")]] S3 { // expected-error {{'nodiscard' cannot 
> have an argument list}}
> +  int i;
> +};
> +
> +[[nodiscard]] int f1(void);
> +enum [[nodiscard]] E1 { One };
> +
> +[[nodiscard]] int i; // expected-warning {{'nodiscard' attribute only 
> applies to functions, methods, enums, and classes}}
> +
> +struct [[nodiscard]] S4 {
> +  int i;
> +};
> +struct S4 get_s(void);
> +
> +enum [[nodiscard]] E2 { Two };
> +enum E2 get_e(void);
> +
> +[[nodiscard]] int get_i();
> +
> +void f2(void) {
> +  get_s(); // expected-warning {{ignoring return value of function declared 
> with 'nodiscard' attribute}}
> +  get_i(); // expected-warning {{ignoring return value of function declared 
> with 'nodiscard' attribute}}
> +  get_e(); // expected-warning {{ignoring return value of function declared 
> with 'nodiscard' attribute}}
> +
> +  // Okay, warnings are not encouraged
> +  (void)get_s();
> +  (void)get_i();
> +  (void)get_e();
> +}
> +
> +struct [[nodiscard]] error_info{
> +  int i;
> +};
> +
> +struct error_info enable_missile_safety_mode(void);
> +void launch_missiles(void);
> +void test_missiles(void) {
> +  enable_missile_safety_mode(); // expected-warning {{ignoring return value 
> of function declared with 'nodiscard'}}
> +  launch_missiles();
> +}
> +
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39013: [CFG] Relax Wexceptions warning on rethrow

2017-10-17 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 119383.
erichkeane edited the summary of this revision.
erichkeane added a comment.

Changes as requested by @aaron.ballman


https://reviews.llvm.org/D39013

Files:
  lib/Sema/AnalysisBasedWarnings.cpp
  test/SemaCXX/warn-throw-out-noexcept-func.cpp


Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -289,14 +289,14 @@
 
 static bool isThrowCaught(const CXXThrowExpr *Throw,
   const CXXCatchStmt *Catch) {
+  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
+  if (!CaughtType)
+return true;
   const Type *ThrowType = nullptr;
   if (Throw->getSubExpr())
 ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
   if (!ThrowType)
 return false;
-  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
-  if (!CaughtType)
-return true;
   if (ThrowType->isReferenceType())
 ThrowType = ThrowType->castAs()
 ->getPointeeType()
Index: test/SemaCXX/warn-throw-out-noexcept-func.cpp
===
--- test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -239,13 +239,30 @@
   } catch (const S &s) {
   }
 }
-void o_ShouldDiag() noexcept { //expected-note {{function declared 
non-throwing here}}
+// As seen in p34973, this should not throw the warning.  If there is an active
+// exception, catch(...) catches everything. 
+void o_ShouldNotDiag() noexcept {
   try {
-throw; //expected-warning {{has a non-throwing exception specification 
but}}
+throw;
   } catch (...) {
   }
 }
 
+void p_ShouldDiag() noexcept { //expected-note {{function declared 
non-throwing here}}
+  try {
+throw; //expected-warning {{has a non-throwing exception specification 
but}}
+  } catch (int){
+  }
+}
+
+void q_ShouldNotDiag() noexcept {
+  try {
+throw;
+  } catch (int){
+  } catch (...){
+  }
+}
+
 #define NOEXCEPT noexcept
 void with_macro() NOEXCEPT { //expected-note {{function declared non-throwing 
here}}
   throw 1; // expected-warning {{has a non-throwing exception specification 
but}}


Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -289,14 +289,14 @@
 
 static bool isThrowCaught(const CXXThrowExpr *Throw,
   const CXXCatchStmt *Catch) {
+  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
+  if (!CaughtType)
+return true;
   const Type *ThrowType = nullptr;
   if (Throw->getSubExpr())
 ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
   if (!ThrowType)
 return false;
-  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
-  if (!CaughtType)
-return true;
   if (ThrowType->isReferenceType())
 ThrowType = ThrowType->castAs()
 ->getPointeeType()
Index: test/SemaCXX/warn-throw-out-noexcept-func.cpp
===
--- test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -239,13 +239,30 @@
   } catch (const S &s) {
   }
 }
-void o_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
+// As seen in p34973, this should not throw the warning.  If there is an active
+// exception, catch(...) catches everything. 
+void o_ShouldNotDiag() noexcept {
   try {
-throw; //expected-warning {{has a non-throwing exception specification but}}
+throw;
   } catch (...) {
   }
 }
 
+void p_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
+  try {
+throw; //expected-warning {{has a non-throwing exception specification but}}
+  } catch (int){
+  }
+}
+
+void q_ShouldNotDiag() noexcept {
+  try {
+throw;
+  } catch (int){
+  } catch (...){
+  }
+}
+
 #define NOEXCEPT noexcept
 void with_macro() NOEXCEPT { //expected-note {{function declared non-throwing here}}
   throw 1; // expected-warning {{has a non-throwing exception specification but}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r316028 - This test case was missing -fsyntax-only, so I've added it. NFC to the actual test contents, just how the test is executed.

2017-10-17 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Oct 17 13:49:30 2017
New Revision: 316028

URL: http://llvm.org/viewvc/llvm-project?rev=316028&view=rev
Log:
This test case was missing -fsyntax-only, so I've added it. NFC to the actual 
test contents, just how the test is executed.

Modified:
cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp

Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp?rev=316028&r1=316027&r2=316028&view=diff
==
--- cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.fallthrough/p1.cpp Tue Oct 17 
13:49:30 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++1z -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++1z -verify %s
 
 void f(int n) {
   switch (n) {


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


[PATCH] D18953: [ms][dll] #26935 Defining a dllimport function should cause it to be exported

2017-10-17 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: cfe/trunk/lib/Sema/SemaDecl.cpp:5650
+  NewImportAttr->getRange(), S.Context,
+  NewImportAttr->getSpellingListIndex()));
+} else {

NewImportAttr can be nullptr here, at least for invalid code. This change 
introduced https://bugs.llvm.org/show_bug.cgi?id=34981 , please take a look.


Repository:
  rL LLVM

https://reviews.llvm.org/D18953



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


[PATCH] D39013: [CFG] Relax Wexceptions warning on rethrow

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

LGTM! Thank you for the fix!


https://reviews.llvm.org/D39013



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


r316030 - [CFG] Relax Wexceptions warning on rethrow

2017-10-17 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Tue Oct 17 13:57:24 2017
New Revision: 316030

URL: http://llvm.org/viewvc/llvm-project?rev=316030&view=rev
Log:
[CFG] Relax Wexceptions warning on rethrow 

As reported here: https://bugs.llvm.org/show_bug.cgi?id=34973

"catch(...)" should catch EVERYTHING, even a rethrow. This
patch changes the order in which things are checked to ensure
that a '...' catch will get a rethrow.

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

Modified:
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=316030&r1=316029&r2=316030&view=diff
==
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Tue Oct 17 13:57:24 2017
@@ -289,14 +289,14 @@ enum ThrowState {
 
 static bool isThrowCaught(const CXXThrowExpr *Throw,
   const CXXCatchStmt *Catch) {
+  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
+  if (!CaughtType)
+return true;
   const Type *ThrowType = nullptr;
   if (Throw->getSubExpr())
 ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
   if (!ThrowType)
 return false;
-  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
-  if (!CaughtType)
-return true;
   if (ThrowType->isReferenceType())
 ThrowType = ThrowType->castAs()
 ->getPointeeType()

Modified: cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp?rev=316030&r1=316029&r2=316030&view=diff
==
--- cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp Tue Oct 17 13:57:24 
2017
@@ -239,13 +239,30 @@ void n_ShouldNotDiag() noexcept {
   } catch (const S &s) {
   }
 }
-void o_ShouldDiag() noexcept { //expected-note {{function declared 
non-throwing here}}
+// As seen in p34973, this should not throw the warning.  If there is an active
+// exception, catch(...) catches everything. 
+void o_ShouldNotDiag() noexcept {
   try {
-throw; //expected-warning {{has a non-throwing exception specification 
but}}
+throw;
   } catch (...) {
   }
 }
 
+void p_ShouldDiag() noexcept { //expected-note {{function declared 
non-throwing here}}
+  try {
+throw; //expected-warning {{has a non-throwing exception specification 
but}}
+  } catch (int){
+  }
+}
+
+void q_ShouldNotDiag() noexcept {
+  try {
+throw;
+  } catch (int){
+  } catch (...){
+  }
+}
+
 #define NOEXCEPT noexcept
 void with_macro() NOEXCEPT { //expected-note {{function declared non-throwing 
here}}
   throw 1; // expected-warning {{has a non-throwing exception specification 
but}}


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


[PATCH] D39013: [CFG] Relax Wexceptions warning on rethrow

2017-10-17 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316030: [CFG] Relax Wexceptions warning on rethrow  
(authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D39013?vs=119383&id=119386#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39013

Files:
  cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
  cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp


Index: cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
===
--- cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -239,13 +239,30 @@
   } catch (const S &s) {
   }
 }
-void o_ShouldDiag() noexcept { //expected-note {{function declared 
non-throwing here}}
+// As seen in p34973, this should not throw the warning.  If there is an active
+// exception, catch(...) catches everything. 
+void o_ShouldNotDiag() noexcept {
   try {
-throw; //expected-warning {{has a non-throwing exception specification 
but}}
+throw;
   } catch (...) {
   }
 }
 
+void p_ShouldDiag() noexcept { //expected-note {{function declared 
non-throwing here}}
+  try {
+throw; //expected-warning {{has a non-throwing exception specification 
but}}
+  } catch (int){
+  }
+}
+
+void q_ShouldNotDiag() noexcept {
+  try {
+throw;
+  } catch (int){
+  } catch (...){
+  }
+}
+
 #define NOEXCEPT noexcept
 void with_macro() NOEXCEPT { //expected-note {{function declared non-throwing 
here}}
   throw 1; // expected-warning {{has a non-throwing exception specification 
but}}
Index: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
===
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
@@ -289,14 +289,14 @@
 
 static bool isThrowCaught(const CXXThrowExpr *Throw,
   const CXXCatchStmt *Catch) {
+  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
+  if (!CaughtType)
+return true;
   const Type *ThrowType = nullptr;
   if (Throw->getSubExpr())
 ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
   if (!ThrowType)
 return false;
-  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
-  if (!CaughtType)
-return true;
   if (ThrowType->isReferenceType())
 ThrowType = ThrowType->castAs()
 ->getPointeeType()


Index: cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
===
--- cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ cfe/trunk/test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -239,13 +239,30 @@
   } catch (const S &s) {
   }
 }
-void o_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
+// As seen in p34973, this should not throw the warning.  If there is an active
+// exception, catch(...) catches everything. 
+void o_ShouldNotDiag() noexcept {
   try {
-throw; //expected-warning {{has a non-throwing exception specification but}}
+throw;
   } catch (...) {
   }
 }
 
+void p_ShouldDiag() noexcept { //expected-note {{function declared non-throwing here}}
+  try {
+throw; //expected-warning {{has a non-throwing exception specification but}}
+  } catch (int){
+  }
+}
+
+void q_ShouldNotDiag() noexcept {
+  try {
+throw;
+  } catch (int){
+  } catch (...){
+  }
+}
+
 #define NOEXCEPT noexcept
 void with_macro() NOEXCEPT { //expected-note {{function declared non-throwing here}}
   throw 1; // expected-warning {{has a non-throwing exception specification but}}
Index: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
===
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
@@ -289,14 +289,14 @@
 
 static bool isThrowCaught(const CXXThrowExpr *Throw,
   const CXXCatchStmt *Catch) {
+  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
+  if (!CaughtType)
+return true;
   const Type *ThrowType = nullptr;
   if (Throw->getSubExpr())
 ThrowType = Throw->getSubExpr()->getType().getTypePtrOrNull();
   if (!ThrowType)
 return false;
-  const Type *CaughtType = Catch->getCaughtType().getTypePtrOrNull();
-  if (!CaughtType)
-return true;
   if (ThrowType->isReferenceType())
 ThrowType = ThrowType->castAs()
 ->getPointeeType()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r316032 - Fix PR34981, a crash-on-invalid merging dllimport to an invalid redecl.

2017-10-17 Thread Nico Weber via cfe-commits
Author: nico
Date: Tue Oct 17 14:14:02 2017
New Revision: 316032

URL: http://llvm.org/viewvc/llvm-project?rev=316032&view=rev
Log:
Fix PR34981, a crash-on-invalid merging dllimport to an invalid redecl.

This is basically like r288207, just the other way round.

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/dllimport.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=316032&r1=316031&r2=316032&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Oct 17 14:14:02 2017
@@ -5975,7 +5975,7 @@ static void checkDLLAttributeRedeclarati
NamedDecl *NewDecl,
bool IsSpecialization,
bool IsDefinition) {
-  if (OldDecl->isInvalidDecl())
+  if (OldDecl->isInvalidDecl() || NewDecl->isInvalidDecl())
 return;
 
   bool IsTemplate = false;
@@ -6081,7 +6081,8 @@ static void checkDLLAttributeRedeclarati
   NewDecl->dropAttr();
 }
   } else if (IsInline && OldImportAttr && !IsMicrosoft) {
-// In MinGW, seeing a function declared inline drops the dllimport 
attribute.
+// In MinGW, seeing a function declared inline drops the dllimport
+// attribute.
 OldDecl->dropAttr();
 NewDecl->dropAttr();
 S.Diag(NewDecl->getLocation(),

Modified: cfe/trunk/test/Sema/dllimport.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/dllimport.c?rev=316032&r1=316031&r2=316032&view=diff
==
--- cfe/trunk/test/Sema/dllimport.c (original)
+++ cfe/trunk/test/Sema/dllimport.c Tue Oct 17 14:14:02 2017
@@ -211,9 +211,14 @@ __declspec(dllimport) void redecl6();
   void redecl7();
 __declspec(dllimport) inline void redecl7() {}
 
-// PR31069: Don't crash trying to merge attributes for redeclaration of 
invalid decl.
+// PR31069: Don't crash trying to merge attributes for redeclaration of invalid
+// decl.
 void __declspec(dllimport) redecl8(unknowntype X); // expected-error{{unknown 
type name 'unknowntype'}}
 void redecl8(unknowntype X) { } // expected-error{{unknown type name 
'unknowntype'}}
+// PR32021: Similarly, don't crash trying to merge attributes from a valid
+// decl to an invalid redeclaration.
+void __declspec(dllimport) redecl9(void); // expected-note{{previous 
declaration is here}}
+int redecl9(void) {} // expected-error{{conflicting types for 'redecl9'}}
 
 // External linkage is required.
 __declspec(dllimport) static int staticFunc(); // expected-error{{'staticFunc' 
must have external linkage when declared 'dllimport'}}


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


[PATCH] D39005: [OpenMP] Clean up variable and function names for NVPTX backend

2017-10-17 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added a comment.

Hi Artem, Justin,

I see that this patch is the same as the patch Arpith wanted to post a while 
back i.e. https://reviews.llvm.org/D17738.

Was there a consensus regarding what the right thing to do is in this case?

I'd be interested to get the ball rolling in regard to coming up with a fix for 
this. I see some suggestions in past patches. Some help/clarification  would be 
much appreciated.

Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D39005



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


[PATCH] D39017: [CMake] Build Fuchsia toolchain as -O3

2017-10-17 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added a comment.

Yes, specifically, lld does string tail merging (instead of regular string 
merging) when -O2 is given, so it would produce slightly smaller outputs.


Repository:
  rL LLVM

https://reviews.llvm.org/D39017



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


[PATCH] D5767: Template Instantiation Observer + a few other templight-related changes

2017-10-17 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

Whee, thanks for driving this, much appreciated :D




Comment at: include/clang/FrontendTool/Utils.h:25
+
+std::unique_ptr CreateFrontendAction(CompilerInstance &CI);
 

Please add a comment now that this is exported.



Comment at: include/clang/Sema/TemplateInstCallbacks.h:32
+  /// \brief Called before doing AST-parsing.
+  void initialize(const Sema &TheSema) {
+this->initializeImpl(TheSema);

Note sure how others think about this, but I'd have expected the design to have:
a) a pure interface
b) an implementation TemplateInstantiationCallbacksCollection or somesuch that 
has a vector of TICs and forwards calls on them


https://reviews.llvm.org/D5767



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


[PATCH] D39015: [Analyzer] Always use non-reference types when creating expressions in BodyFarm, removes std::call_once crash

2017-10-17 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

Looks good to me.

This comment is unrelated to this particular patch, but since I know you're 
doing other work in the area I think it would also be good to have test cases 
for the two other forms of call_once defined in . It looks to me like 
those will be used for projects that that use pre-C++11 -- so we should have 
test coverage for them.


https://reviews.llvm.org/D39015



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


r316041 - [Analyzer] Always use non-reference types when creating expressions in BodyFarm.

2017-10-17 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Tue Oct 17 15:28:18 2017
New Revision: 316041

URL: http://llvm.org/viewvc/llvm-project?rev=316041&view=rev
Log:
[Analyzer] Always use non-reference types when creating expressions in BodyFarm.

Remove an option to use a reference type (on by default!) since a
non-reference type is always needed for creating expressions, functions
with multiple boolean parameters are very hard to use, and in general it
was just a booby trap for further crashes.
Furthermore, generalize call_once test case to fix some of the crashes mentioned
https://bugs.llvm.org/show_bug.cgi?id=34869
Also removes std::call_once crash.

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

Modified:
cfe/trunk/lib/Analysis/BodyFarm.cpp
cfe/trunk/test/Analysis/call_once.cpp

Modified: cfe/trunk/lib/Analysis/BodyFarm.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BodyFarm.cpp?rev=316041&r1=316040&r2=316041&view=diff
==
--- cfe/trunk/lib/Analysis/BodyFarm.cpp (original)
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp Tue Oct 17 15:28:18 2017
@@ -63,8 +63,7 @@ public:
   
   /// Create a new DeclRefExpr for the referenced variable.
   DeclRefExpr *makeDeclRefExpr(const VarDecl *D,
-   bool RefersToEnclosingVariableOrCapture = false,
-   bool GetNonReferenceType = false);
+   bool RefersToEnclosingVariableOrCapture = 
false);
   
   /// Create a new UnaryOperator representing a dereference.
   UnaryOperator *makeDereference(const Expr *Arg, QualType Ty);
@@ -82,8 +81,7 @@ public:
   /// DeclRefExpr in the process.
   ImplicitCastExpr *
   makeLvalueToRvalue(const VarDecl *Decl,
- bool RefersToEnclosingVariableOrCapture = false,
- bool GetNonReferenceType = false);
+ bool RefersToEnclosingVariableOrCapture = false);
 
   /// Create an implicit cast of the given type.
   ImplicitCastExpr *makeImplicitCast(const Expr *Arg, QualType Ty,
@@ -138,12 +136,10 @@ CompoundStmt *ASTMaker::makeCompound(Arr
   return new (C) CompoundStmt(C, Stmts, SourceLocation(), SourceLocation());
 }
 
-DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D,
-   bool RefersToEnclosingVariableOrCapture,
-   bool GetNonReferenceType) {
-  auto Type = D->getType();
-  if (GetNonReferenceType)
-Type = Type.getNonReferenceType();
+DeclRefExpr *ASTMaker::makeDeclRefExpr(
+const VarDecl *D,
+bool RefersToEnclosingVariableOrCapture) {
+  QualType Type = D->getType().getNonReferenceType();
 
   DeclRefExpr *DR = DeclRefExpr::Create(
   C, NestedNameSpecifierLoc(), SourceLocation(), const_cast(D),
@@ -162,14 +158,10 @@ ImplicitCastExpr *ASTMaker::makeLvalueTo
 
 ImplicitCastExpr *
 ASTMaker::makeLvalueToRvalue(const VarDecl *Arg,
- bool RefersToEnclosingVariableOrCapture,
- bool GetNonReferenceType) {
-  auto Type = Arg->getType();
-  if (GetNonReferenceType)
-Type = Type.getNonReferenceType();
+ bool RefersToEnclosingVariableOrCapture) {
+  QualType Type = Arg->getType().getNonReferenceType();
   return makeLvalueToRvalue(makeDeclRefExpr(Arg,
-RefersToEnclosingVariableOrCapture,
-GetNonReferenceType),
+
RefersToEnclosingVariableOrCapture),
 Type);
 }
 
@@ -365,12 +357,13 @@ static Stmt *create_call_once(ASTContext
 // Lambda requires callback itself inserted as a first parameter.
 CallArgs.push_back(
 M.makeDeclRefExpr(Callback,
-  /* RefersToEnclosingVariableOrCapture= */ true,
-  /* GetNonReferenceType= */ true));
+  /* RefersToEnclosingVariableOrCapture= */ true));
 
   // All arguments past first two ones are passed to the callback.
   for (unsigned int i = 2; i < D->getNumParams(); i++)
-CallArgs.push_back(M.makeLvalueToRvalue(D->getParamDecl(i)));
+CallArgs.push_back(
+M.makeLvalueToRvalue(D->getParamDecl(i),
+ /* RefersToEnclosingVariableOrCapture= */ false));
 
   CallExpr *CallbackCall;
   if (isLambdaCall) {
@@ -385,8 +378,7 @@ static Stmt *create_call_once(ASTContext
 
   DeclRefExpr *FlagDecl =
   M.makeDeclRefExpr(Flag,
-/* RefersToEnclosingVariableOrCapture=*/true,
-/* GetNonReferenceType=*/true);
+/* RefersToEnclosingVariableOrCapture=*/true);
 
 
   MemberExpr *Deref = M.makeMemberExpression(FlagDecl, FlagFieldDecl);

Modified: cfe/trunk/test/Analysis/call_once.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/call_once.cpp?rev=316041&r1=3160

[PATCH] D39015: [Analyzer] Always use non-reference types when creating expressions in BodyFarm, removes std::call_once crash

2017-10-17 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316041: [Analyzer] Always use non-reference types when 
creating expressions in BodyFarm. (authored by george.karpenkov).

Changed prior to commit:
  https://reviews.llvm.org/D39015?vs=119360&id=119392#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39015

Files:
  cfe/trunk/lib/Analysis/BodyFarm.cpp
  cfe/trunk/test/Analysis/call_once.cpp


Index: cfe/trunk/lib/Analysis/BodyFarm.cpp
===
--- cfe/trunk/lib/Analysis/BodyFarm.cpp
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp
@@ -63,8 +63,7 @@
   
   /// Create a new DeclRefExpr for the referenced variable.
   DeclRefExpr *makeDeclRefExpr(const VarDecl *D,
-   bool RefersToEnclosingVariableOrCapture = false,
-   bool GetNonReferenceType = false);
+   bool RefersToEnclosingVariableOrCapture = 
false);
   
   /// Create a new UnaryOperator representing a dereference.
   UnaryOperator *makeDereference(const Expr *Arg, QualType Ty);
@@ -82,8 +81,7 @@
   /// DeclRefExpr in the process.
   ImplicitCastExpr *
   makeLvalueToRvalue(const VarDecl *Decl,
- bool RefersToEnclosingVariableOrCapture = false,
- bool GetNonReferenceType = false);
+ bool RefersToEnclosingVariableOrCapture = false);
 
   /// Create an implicit cast of the given type.
   ImplicitCastExpr *makeImplicitCast(const Expr *Arg, QualType Ty,
@@ -138,12 +136,10 @@
   return new (C) CompoundStmt(C, Stmts, SourceLocation(), SourceLocation());
 }
 
-DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D,
-   bool RefersToEnclosingVariableOrCapture,
-   bool GetNonReferenceType) {
-  auto Type = D->getType();
-  if (GetNonReferenceType)
-Type = Type.getNonReferenceType();
+DeclRefExpr *ASTMaker::makeDeclRefExpr(
+const VarDecl *D,
+bool RefersToEnclosingVariableOrCapture) {
+  QualType Type = D->getType().getNonReferenceType();
 
   DeclRefExpr *DR = DeclRefExpr::Create(
   C, NestedNameSpecifierLoc(), SourceLocation(), const_cast(D),
@@ -162,14 +158,10 @@
 
 ImplicitCastExpr *
 ASTMaker::makeLvalueToRvalue(const VarDecl *Arg,
- bool RefersToEnclosingVariableOrCapture,
- bool GetNonReferenceType) {
-  auto Type = Arg->getType();
-  if (GetNonReferenceType)
-Type = Type.getNonReferenceType();
+ bool RefersToEnclosingVariableOrCapture) {
+  QualType Type = Arg->getType().getNonReferenceType();
   return makeLvalueToRvalue(makeDeclRefExpr(Arg,
-RefersToEnclosingVariableOrCapture,
-GetNonReferenceType),
+
RefersToEnclosingVariableOrCapture),
 Type);
 }
 
@@ -365,12 +357,13 @@
 // Lambda requires callback itself inserted as a first parameter.
 CallArgs.push_back(
 M.makeDeclRefExpr(Callback,
-  /* RefersToEnclosingVariableOrCapture= */ true,
-  /* GetNonReferenceType= */ true));
+  /* RefersToEnclosingVariableOrCapture= */ true));
 
   // All arguments past first two ones are passed to the callback.
   for (unsigned int i = 2; i < D->getNumParams(); i++)
-CallArgs.push_back(M.makeLvalueToRvalue(D->getParamDecl(i)));
+CallArgs.push_back(
+M.makeLvalueToRvalue(D->getParamDecl(i),
+ /* RefersToEnclosingVariableOrCapture= */ false));
 
   CallExpr *CallbackCall;
   if (isLambdaCall) {
@@ -385,8 +378,7 @@
 
   DeclRefExpr *FlagDecl =
   M.makeDeclRefExpr(Flag,
-/* RefersToEnclosingVariableOrCapture=*/true,
-/* GetNonReferenceType=*/true);
+/* RefersToEnclosingVariableOrCapture=*/true);
 
 
   MemberExpr *Deref = M.makeMemberExpression(FlagDecl, FlagFieldDecl);
Index: cfe/trunk/test/Analysis/call_once.cpp
===
--- cfe/trunk/test/Analysis/call_once.cpp
+++ cfe/trunk/test/Analysis/call_once.cpp
@@ -17,7 +17,7 @@
 #endif
 
 template 
-void call_once(once_flag &o, Callable func, Args... args) {};
+void call_once(once_flag &o, Callable&& func, Args&&... args) {};
 
 } // namespace std
 


Index: cfe/trunk/lib/Analysis/BodyFarm.cpp
===
--- cfe/trunk/lib/Analysis/BodyFarm.cpp
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp
@@ -63,8 +63,7 @@
   
   /// Create a new DeclRefExpr for the referenced variable.
   DeclRefExpr *makeDeclRefExpr(const VarDecl *D,
-   bool RefersToEnclosingVariableOrCapture = false,
-   bool GetNonRef

r316042 - Basic: fix `__INTPTR_TYPE__` for Windows ARM

2017-10-17 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Tue Oct 17 15:49:53 2017
New Revision: 316042

URL: http://llvm.org/viewvc/llvm-project?rev=316042&view=rev
Log:
Basic: fix `__INTPTR_TYPE__` for Windows ARM

The `IntPtrType` for Windows ARM should be `int` as per MSVC.  Adjust
the type accordingly.

Modified:
cfe/trunk/lib/Basic/Targets/ARM.cpp
cfe/trunk/test/Preprocessor/woa-defaults.c

Modified: cfe/trunk/lib/Basic/Targets/ARM.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/ARM.cpp?rev=316042&r1=316041&r2=316042&view=diff
==
--- cfe/trunk/lib/Basic/Targets/ARM.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/ARM.cpp Tue Oct 17 15:49:53 2017
@@ -923,6 +923,7 @@ WindowsARMTargetInfo::WindowsARMTargetIn
const TargetOptions &Opts)
 : WindowsTargetInfo(Triple, Opts), Triple(Triple) {
   SizeType = UnsignedInt;
+  IntPtrType = SignedInt;
 }
 
 void WindowsARMTargetInfo::getVisualStudioDefines(const LangOptions &Opts,

Modified: cfe/trunk/test/Preprocessor/woa-defaults.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/woa-defaults.c?rev=316042&r1=316041&r2=316042&view=diff
==
--- cfe/trunk/test/Preprocessor/woa-defaults.c (original)
+++ cfe/trunk/test/Preprocessor/woa-defaults.c Tue Oct 17 15:49:53 2017
@@ -10,9 +10,12 @@
 // CHECK: #define _M_THUMB _M_ARM
 // CHECK: #define _WIN32 1
 
+
 // CHECK: #define __ARM_PCS 1
 // CHECK: #define __ARM_PCS_VFP 1
 // CHECK: #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
+// CHECK: #define __INTPTR_TYPE__ int
+// CHECK: #define __PTRDIFF_TYPE__ int
 // CHECK: #define __SIZEOF_DOUBLE__ 8
 // CHECK: #define __SIZEOF_FLOAT__ 4
 // CHECK: #define __SIZEOF_INT__ 4
@@ -25,6 +28,8 @@
 // CHECK: #define __SIZEOF_SIZE_T__ 4
 // CHECK: #define __SIZEOF_WCHAR_T__ 2
 // CHECK: #define __SIZEOF_WINT_T__ 4
+// CHECK: #define __SIZE_TYPE__ unsigned int
+// CHECK: #define __UINTPTR_TYPE__ unsigned int
 
 // CHECK-NOT: __THUMB_INTERWORK__
 // CHECK-NOT: __ARM_EABI__


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


[PATCH] D39017: [CMake] Build Fuchsia toolchain as -O3

2017-10-17 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

It seems like with the current patch, CMake already sets `-Wl,-O3` so that 
should be sufficient.


Repository:
  rL LLVM

https://reviews.llvm.org/D39017



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


[PATCH] D39005: [OpenMP] Clean up variable and function names for NVPTX backend

2017-10-17 Thread Justin Lebar via Phabricator via cfe-commits
jlebar added a comment.

> I'd be interested to get the ball rolling in regard to coming up with a fix 
> for this. I see some suggestions in past patches. Some help/clarification 
> would be much appreciated.

Happy to help, but I'm not sure what to offer beyond the link in Art's previous 
comment.


Repository:
  rL LLVM

https://reviews.llvm.org/D39005



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


r316043 - Resubmit "[lit] Raise the logic for enabling clang & lld substitutions to llvm."

2017-10-17 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Tue Oct 17 16:43:36 2017
New Revision: 316043

URL: http://llvm.org/viewvc/llvm-project?rev=316043&view=rev
Log:
Resubmit "[lit] Raise the logic for enabling clang & lld substitutions to llvm."

The substitution for %debuginfo_tests had been inadvertently removed.
This adds it back.

Modified:
cfe/trunk/test/lit.cfg.py

Modified: cfe/trunk/test/lit.cfg.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/lit.cfg.py?rev=316043&r1=316042&r2=316043&view=diff
==
--- cfe/trunk/test/lit.cfg.py (original)
+++ cfe/trunk/test/lit.cfg.py Tue Oct 17 16:43:36 2017
@@ -39,162 +39,45 @@ config.test_source_root = os.path.dirnam
 # test_exec_root: The root path where tests should be run.
 config.test_exec_root = os.path.join(config.clang_obj_root, 'test')
 
-# Clear some environment variables that might affect Clang.
-#
-# This first set of vars are read by Clang, but shouldn't affect tests
-# that aren't specifically looking for these features, or are required
-# simply to run the tests at all.
-#
-# FIXME: Should we have a tool that enforces this?
-
-# safe_env_vars = ('TMPDIR', 'TEMP', 'TMP', 'USERPROFILE', 'PWD',
-#  'MACOSX_DEPLOYMENT_TARGET', 'IPHONEOS_DEPLOYMENT_TARGET',
-#  'VCINSTALLDIR', 'VC100COMNTOOLS', 'VC90COMNTOOLS',
-#  'VC80COMNTOOLS')
-possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS',
-   'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
-   'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH',
-   'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH',
-   'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING',
-   'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX',
-   'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS',
-   'LIBCLANG_RESOURCE_USAGE',
-   'LIBCLANG_CODE_COMPLETION_LOGGING']
-# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it.
-if platform.system() != 'Windows':
-possibly_dangerous_env_vars.append('INCLUDE')
-
-llvm_config.clear_environment(possibly_dangerous_env_vars)
-
-# Tweak the PATH to include the tools dir and the scripts dir.
-llvm_config.with_environment(
-'PATH', [config.llvm_tools_dir, config.clang_tools_dir], append_path=True)
+llvm_config.use_default_substitutions()
 
-llvm_config.with_environment('LD_LIBRARY_PATH', [
- config.llvm_shlib_dir, config.llvm_libs_dir], 
append_path=True)
+llvm_config.use_clang()
 
 # Propagate path to symbolizer for ASan/MSan.
 llvm_config.with_system_environment(
 ['ASAN_SYMBOLIZER_PATH', 'MSAN_SYMBOLIZER_PATH'])
 
-llvm_config.use_default_substitutions()
-
-# Discover the 'clang' and 'clangcc' to use.
-
-
-def inferClang(PATH):
-# Determine which clang to use.
-clang = os.getenv('CLANG')
-
-# If the user set clang in the environment, definitely use that and don't
-# try to validate.
-if clang:
-return clang
-
-# Otherwise look in the path.
-clang = lit.util.which('clang', PATH)
-
-if not clang:
-lit_config.fatal("couldn't find 'clang' program, try setting "
- 'CLANG in your environment')
-
-return clang
-
-
-config.clang = inferClang(config.environment['PATH']).replace('\\', '/')
-if not lit_config.quiet:
-lit_config.note('using clang: %r' % config.clang)
-
-# Plugins (loadable modules)
-# TODO: This should be supplied by Makefile or autoconf.
-if sys.platform in ['win32', 'cygwin']:
-has_plugins = config.enable_shared
-else:
-has_plugins = True
-
-if has_plugins and config.llvm_plugin_ext:
-config.available_features.add('plugins')
-
-config.substitutions.append(('%llvmshlibdir', config.llvm_shlib_dir))
-config.substitutions.append(('%pluginext', config.llvm_plugin_ext))
 config.substitutions.append(('%PATH%', config.environment['PATH']))
 
-if config.clang_examples:
-config.available_features.add('examples')
 
-builtin_include_dir = llvm_config.get_clang_builtin_include_dir(config.clang)
+# For each occurrence of a clang tool name, replace it with the full path to
+# the build directory holding that tool.  We explicitly specify the directories
+# to search to ensure that we get the tools just built and not some random
+# tools that might happen to be in the user's PATH.
+tool_dirs = [config.clang_tools_dir, config.llvm_tools_dir]
 
 tools = [
-# By specifying %clang_cc1 as part of the substitution, this substitution
-# relies on repeated substitution, so must come before %clang_cc1.
-ToolSubst('%clang_analyze_cc1', command='%clang_cc1',
-  extra_args=['-analyze', '%analyze']),
-ToolSubst('%clang_cc1', command=config.clang, extra_args=[
-  '-cc1', '-internal-isystem', builtin_include_dir, 
'-nostdsysteminc']),
-T

r316046 - Basic: fix __{,U}INTPTR_TYPE__ on ARM

2017-10-17 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Tue Oct 17 17:00:50 2017
New Revision: 316046

URL: http://llvm.org/viewvc/llvm-project?rev=316046&view=rev
Log:
Basic: fix __{,U}INTPTR_TYPE__ on ARM

Darwin and OpenBSD are the only platforms which use `long int` for
`__INTPTR_TYPE__`.  The other platforms use `int` in 32-bit, and `long
int` on 64-bit (except for VMS and Windows which are LLP64).  Adjust the
type definitions to match the platform definitions.  We now generate the
same definition as GCC on all the targets.

Modified:
cfe/trunk/lib/Basic/Targets/ARM.cpp
cfe/trunk/test/Preprocessor/init.c
cfe/trunk/test/Preprocessor/stdint.c

Modified: cfe/trunk/lib/Basic/Targets/ARM.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/ARM.cpp?rev=316046&r1=316045&r2=316046&view=diff
==
--- cfe/trunk/lib/Basic/Targets/ARM.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/ARM.cpp Tue Oct 17 17:00:50 2017
@@ -236,6 +236,10 @@ ARMTargetInfo::ARMTargetInfo(const llvm:
 break;
   }
 
+  IntPtrType = (Triple.isOSDarwin() || Triple.getOS() == llvm::Triple::OpenBSD)
+   ? SignedLong
+   : SignedInt;
+
   // Cache arch related info.
   setArchInfo();
 
@@ -923,7 +927,6 @@ WindowsARMTargetInfo::WindowsARMTargetIn
const TargetOptions &Opts)
 : WindowsTargetInfo(Triple, Opts), Triple(Triple) {
   SizeType = UnsignedInt;
-  IntPtrType = SignedInt;
 }
 
 void WindowsARMTargetInfo::getVisualStudioDefines(const LangOptions &Opts,

Modified: cfe/trunk/test/Preprocessor/init.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=316046&r1=316045&r2=316046&view=diff
==
--- cfe/trunk/test/Preprocessor/init.c (original)
+++ cfe/trunk/test/Preprocessor/init.c Tue Oct 17 17:00:50 2017
@@ -1668,10 +1668,10 @@
 // ARM:#define __INTMAX_MAX__ 9223372036854775807LL
 // ARM:#define __INTMAX_TYPE__ long long int
 // ARM:#define __INTMAX_WIDTH__ 64
-// ARM:#define __INTPTR_FMTd__ "ld"
-// ARM:#define __INTPTR_FMTi__ "li"
-// ARM:#define __INTPTR_MAX__ 2147483647L
-// ARM:#define __INTPTR_TYPE__ long int
+// ARM:#define __INTPTR_FMTd__ "d"
+// ARM:#define __INTPTR_FMTi__ "i"
+// ARM:#define __INTPTR_MAX__ 2147483647
+// ARM:#define __INTPTR_TYPE__ int
 // ARM:#define __INTPTR_WIDTH__ 32
 // ARM:#define __INT_FAST16_FMTd__ "hd"
 // ARM:#define __INT_FAST16_FMTi__ "hi"
@@ -1763,8 +1763,8 @@
 // ARM:#define __UINTMAX_MAX__ 18446744073709551615ULL
 // ARM:#define __UINTMAX_TYPE__ long long unsigned int
 // ARM:#define __UINTMAX_WIDTH__ 64
-// ARM:#define __UINTPTR_MAX__ 4294967295UL
-// ARM:#define __UINTPTR_TYPE__ long unsigned int
+// ARM:#define __UINTPTR_MAX__ 4294967295U
+// ARM:#define __UINTPTR_TYPE__ unsigned int
 // ARM:#define __UINTPTR_WIDTH__ 32
 // ARM:#define __UINT_FAST16_MAX__ 65535
 // ARM:#define __UINT_FAST16_TYPE__ unsigned short
@@ -1860,10 +1860,10 @@
 // ARM-BE:#define __INTMAX_MAX__ 9223372036854775807LL
 // ARM-BE:#define __INTMAX_TYPE__ long long int
 // ARM-BE:#define __INTMAX_WIDTH__ 64
-// ARM-BE:#define __INTPTR_FMTd__ "ld"
-// ARM-BE:#define __INTPTR_FMTi__ "li"
-// ARM-BE:#define __INTPTR_MAX__ 2147483647L
-// ARM-BE:#define __INTPTR_TYPE__ long int
+// ARM-BE:#define __INTPTR_FMTd__ "d"
+// ARM-BE:#define __INTPTR_FMTi__ "i"
+// ARM-BE:#define __INTPTR_MAX__ 2147483647
+// ARM-BE:#define __INTPTR_TYPE__ int
 // ARM-BE:#define __INTPTR_WIDTH__ 32
 // ARM-BE:#define __INT_FAST16_FMTd__ "hd"
 // ARM-BE:#define __INT_FAST16_FMTi__ "hi"
@@ -1953,8 +1953,8 @@
 // ARM-BE:#define __UINTMAX_MAX__ 18446744073709551615ULL
 // ARM-BE:#define __UINTMAX_TYPE__ long long unsigned int
 // ARM-BE:#define __UINTMAX_WIDTH__ 64
-// ARM-BE:#define __UINTPTR_MAX__ 4294967295UL
-// ARM-BE:#define __UINTPTR_TYPE__ long unsigned int
+// ARM-BE:#define __UINTPTR_MAX__ 4294967295U
+// ARM-BE:#define __UINTPTR_TYPE__ unsigned int
 // ARM-BE:#define __UINTPTR_WIDTH__ 32
 // ARM-BE:#define __UINT_FAST16_MAX__ 65535
 // ARM-BE:#define __UINT_FAST16_TYPE__ unsigned short
@@ -2053,10 +2053,10 @@
 // ARMEABISOFTFP:#define __INTMAX_MAX__ 9223372036854775807LL
 // ARMEABISOFTFP:#define __INTMAX_TYPE__ long long int
 // ARMEABISOFTFP:#define __INTMAX_WIDTH__ 64
-// ARMEABISOFTFP:#define __INTPTR_FMTd__ "ld"
-// ARMEABISOFTFP:#define __INTPTR_FMTi__ "li"
-// ARMEABISOFTFP:#define __INTPTR_MAX__ 2147483647L
-// ARMEABISOFTFP:#define __INTPTR_TYPE__ long int
+// ARMEABISOFTFP:#define __INTPTR_FMTd__ "d"
+// ARMEABISOFTFP:#define __INTPTR_FMTi__ "i"
+// ARMEABISOFTFP:#define __INTPTR_MAX__ 2147483647
+// ARMEABISOFTFP:#define __INTPTR_TYPE__ int
 // ARMEABISOFTFP:#define __INTPTR_WIDTH__ 32
 // ARMEABISOFTFP:#define __INT_FAST16_FMTd__ "hd"
 // ARMEABISOFTFP:#define __INT_FAST16_FMTi__ "hi"
@@ -2148,8 +2148,8 @@
 // ARMEABISOFTFP:#define __UINTMAX_MAX__ 18446744073709551615ULL
 // ARMEABIS

[PATCH] D39024: [clang-format] Sort whole block of using declarations while partially formatting

2017-10-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a subscriber: klimek.

This patch enables sorting the full block of using declarations when
some line is affected.


https://reviews.llvm.org/D39024

Files:
  lib/Format/UsingDeclarationsSorter.cpp
  unittests/Format/UsingDeclarationsSorterTest.cpp

Index: unittests/Format/UsingDeclarationsSorterTest.cpp
===
--- unittests/Format/UsingDeclarationsSorterTest.cpp
+++ unittests/Format/UsingDeclarationsSorterTest.cpp
@@ -291,13 +291,41 @@
 }
 
 TEST_F(UsingDeclarationsSorterTest, SortsPartialRangeOfUsingDeclarations) {
-  EXPECT_EQ("using b;\n"
-"using a;\n"
+  // Sorts the whole block of using declarations surrounding the range.
+  EXPECT_EQ("using a;\n"
+"using b;\n"
 "using c;",
 sortUsingDeclarations("using b;\n"
   "using c;\n" // starts at offset 10
   "using a;",
   {tooling::Range(10, 15)}));
+  EXPECT_EQ("using a;\n"
+"using b;\n"
+"using c;\n"
+"using A = b;",
+sortUsingDeclarations("using b;\n"
+  "using c;\n" // starts at offset 10
+  "using a;\n"
+  "using A = b;",
+  {tooling::Range(10, 15)}));
+
+  EXPECT_EQ("using d;\n"
+"using c;\n"
+"\n"
+"using a;\n"
+"using b;\n"
+"\n"
+"using f;\n"
+"using e;",
+sortUsingDeclarations("using d;\n"
+  "using c;\n"
+  "\n"
+  "using b;\n" // starts at offset 19
+  "using a;\n"
+  "\n"
+  "using f;\n"
+  "using e;",
+  {tooling::Range(19, 1)}));
 }
 
 } // end namespace
Index: lib/Format/UsingDeclarationsSorter.cpp
===
--- lib/Format/UsingDeclarationsSorter.cpp
+++ lib/Format/UsingDeclarationsSorter.cpp
@@ -74,37 +74,40 @@
 }
 
 void endUsingDeclarationBlock(
-SmallVectorImpl *UsingDeclarations,
+SmallVectorImpl *UsingDeclarations, bool *BlockAffected,
 const SourceManager &SourceMgr, tooling::Replacements *Fixes) {
-  SmallVector SortedUsingDeclarations(
-  UsingDeclarations->begin(), UsingDeclarations->end());
-  std::stable_sort(SortedUsingDeclarations.begin(),
-   SortedUsingDeclarations.end());
-  for (size_t I = 0, E = UsingDeclarations->size(); I < E; ++I) {
-if ((*UsingDeclarations)[I].Line == SortedUsingDeclarations[I].Line)
-  continue;
-auto Begin = (*UsingDeclarations)[I].Line->First->Tok.getLocation();
-auto End = (*UsingDeclarations)[I].Line->Last->Tok.getEndLoc();
-auto SortedBegin =
-SortedUsingDeclarations[I].Line->First->Tok.getLocation();
-auto SortedEnd = SortedUsingDeclarations[I].Line->Last->Tok.getEndLoc();
-StringRef Text(SourceMgr.getCharacterData(SortedBegin),
-   SourceMgr.getCharacterData(SortedEnd) -
-   SourceMgr.getCharacterData(SortedBegin));
-DEBUG({
-  StringRef OldText(SourceMgr.getCharacterData(Begin),
-SourceMgr.getCharacterData(End) -
-SourceMgr.getCharacterData(Begin));
-  llvm::dbgs() << "Replacing '" << OldText << "' with '" << Text << "'\n";
-});
-auto Range = CharSourceRange::getCharRange(Begin, End);
-auto Err = Fixes->add(tooling::Replacement(SourceMgr, Range, Text));
-if (Err) {
-  llvm::errs() << "Error while sorting using declarations: "
-   << llvm::toString(std::move(Err)) << "\n";
+  if (*BlockAffected) {
+SmallVector SortedUsingDeclarations(
+UsingDeclarations->begin(), UsingDeclarations->end());
+std::stable_sort(SortedUsingDeclarations.begin(),
+ SortedUsingDeclarations.end());
+for (size_t I = 0, E = UsingDeclarations->size(); I < E; ++I) {
+  if ((*UsingDeclarations)[I].Line == SortedUsingDeclarations[I].Line)
+continue;
+  auto Begin = (*UsingDeclarations)[I].Line->First->Tok.getLocation();
+  auto End = (*UsingDeclarations)[I].Line->Last->Tok.getEndLoc();
+  auto SortedBegin =
+  SortedUsingDeclarations[I].Line->First->Tok.getLocation();
+  auto SortedEnd = SortedUsingDeclarations[I].Line->Last->Tok.getEndLoc();
+  StringRef Text(SourceMgr.getCharacterData(SortedBegin),
+ SourceMgr.getCharacterData(SortedEnd) -
+ SourceMgr.getCharacterData(SortedBegin));
+  DEBUG({
+StringRef OldText(SourceMgr.getCharacterData(Begin),
+   

Re: r313386 - [Sema] Error out early for tags defined inside an enumeration.

2017-10-17 Thread Volodymyr Sapsai via cfe-commits


> On Oct 11, 2017, at 16:02, Richard Smith  wrote:
> 
> On 22 September 2017 at 18:00, Volodymyr Sapsai via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> 
> 
>> On Sep 21, 2017, at 15:17, Richard Smith > > wrote:
>> 
>> On 15 September 2017 at 12:51, Volodymyr Sapsai via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> Author: vsapsai
>> Date: Fri Sep 15 12:51:42 2017
>> New Revision: 313386
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=313386&view=rev 
>> 
>> Log:
>> [Sema] Error out early for tags defined inside an enumeration.
>> 
>> This fixes PR28903 by avoiding access check for inner enum constant. We
>> are performing access check because one enum constant references another
>> and because enum is defined in CXXRecordDecl. But access check doesn't
>> work because FindDeclaringClass doesn't expect more than one EnumDecl
>> and because inner enum has access AS_none due to not being an immediate
>> child of a record.
>> 
>> The change detects an enum is defined in wrong place and allows to skip
>> parsing its body. Access check is skipped together with body parsing.
>> There was no crash in C, added test case to cover the new error.
>> 
>> rdar://problem/28530809 <>
>> 
>> Reviewers: rnk, doug.gregor, rsmith
>> 
>> Reviewed By: doug.gregor
>> 
>> Subscribers: cfe-commits
>> 
>> Differential Revision: https://reviews.llvm.org/D37089 
>> 
>> 
>> 
>> Modified:
>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> cfe/trunk/lib/Sema/SemaDecl.cpp
>> cfe/trunk/test/Sema/enum.c
>> cfe/trunk/test/SemaCXX/enum.cpp
>> 
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=313386&r1=313385&r2=313386&view=diff
>>  
>> 
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep 15 12:51:42 
>> 2017
>> @@ -1335,6 +1335,8 @@ def err_type_defined_in_alias_template :
>>"%0 cannot be defined in a type alias template">;
>>  def err_type_defined_in_condition : Error<
>>"%0 cannot be defined in a condition">;
>> +def err_type_defined_in_enum : Error<
>> +  "%0 cannot be defined in an enumeration">;
>> 
>>  def note_pure_virtual_function : Note<
>>"unimplemented pure virtual method %0 in %1">;
>> 
>> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=313386&r1=313385&r2=313386&view=diff
>>  
>> 
>> ==
>> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Sep 15 12:51:42 2017
>> @@ -13928,6 +13928,12 @@ CreateNewDecl:
>>  Invalid = true;
>>}
>> 
>> +  if (!Invalid && TUK == TUK_Definition && DC->getDeclKind() == Decl::Enum) 
>> {
>> +Diag(New->getLocation(), diag::err_type_defined_in_enum)
>> +  << Context.getTagDeclType(New);
>> +Invalid = true;
>> +  }
>> 
>> This looks like the wrong fix. As noted elsewhere, this is wrong in C. And 
>> in C++, the relevant context is a type-specifier, which should be rejected 
>> due to the check 7 lines above.
>> 
>> It looks like the actual bug is that we don't consider the type within a C99 
>> compound literal to be a type-specifier. The fact that the context is an 
>> enumeration is irrelevant.
> 
> At which point can we detect IsTypeSpecifier should be true? Which in turn 
> boils down to DeclSpecContext should be DSC_type_specifier. Currently we have 
> DeclSpecContext DSC_normal because it is a default argument in 
> Parser::ParseSpecifierQualifierList. Which is called from
> 
> #4clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, 
> bool, bool, clang::OpaquePtr&, clang::SourceLocation&) at 
> llvm-project/clang/lib/Parse/ParseExpr.cpp:2375
> 
> The call to ParseSpecifierQualfiierList here should always pass 
> DSC_type_specifier. We're parsing a type within parentheses (which we've 
> already disambiguated as being a type cast / compound literal rather than an 
> expression), which is the DSC_type_specifier case.
Thanks, Richard, that works. As the result in clang/test/CXX/drs/dr5xx.cpp for

sizeof(const);

We change error from "requires a type specifier” to “expected a type” which 
seems OK to me (we use it for other dr539 cases). Will send patch for code 
review soon.

> #5clang::Parser::ParseCastExpression(bool, bool, bool&, 
> clang::Parser::Typ

[PATCH] D39027: [docs][refactor] Add a new tutorial that talks about how one can implement refactoring actions

2017-10-17 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

This patch adds a new tutorial to Clang's talks that walks through an example 
of a refactoring action and how it can be implemented in Clang.


Repository:
  rL LLVM

https://reviews.llvm.org/D39027

Files:
  docs/RefactoringActionTutorial.rst
  docs/RefactoringEngine.rst
  docs/index.rst

Index: docs/index.rst
===
--- docs/index.rst
+++ docs/index.rst
@@ -61,6 +61,7 @@
HowToSetupToolingForLLVM
JSONCompilationDatabase
RefactoringEngine
+   RefactoringActionTutorial
 
 Using Clang Tools
 =
Index: docs/RefactoringEngine.rst
===
--- docs/RefactoringEngine.rst
+++ docs/RefactoringEngine.rst
@@ -18,7 +18,10 @@
 to the Clang AST ` if you want to learn more
 about how the AST is structured.
 
-..  FIXME: create new refactoring action tutorial and link to the tutorial
+You can also take a look a the
+:doc:`refactoring action tutorial ` to see how
+you can use the components that are described in this document to implement
+actual refactoring actions.
 
 Introduction
 
Index: docs/RefactoringActionTutorial.rst
===
--- /dev/null
+++ docs/RefactoringActionTutorial.rst
@@ -0,0 +1,382 @@
+=
+Tutorial for building refactoring actions
+=
+
+.. warning::
+
+  This tutorial talks about a work-in-progress library in Clang.
+  Some of the described features might not be available yet in trunk, but should
+  be there in the near future.
+
+This document is intended to show how to build refactoring actions that
+perform source-to-source transformations and integrate with editors that
+use ``libclang/clangd`` and the ``clang-refactor`` command-line refactoring
+tool. The document uses Clang's `refactoring engine `_
+and the `LibTooling `_ library.
+
+In order to work on the compiler, you need some basic knowledge of the
+abstract syntax tree (AST). To this end, the reader is encouraged to
+skim the :doc:`Introduction to the Clang
+AST `.
+
+How to obtain & build Clang
+===
+
+Before working on the refactoring action, you'll need to download and build
+LLVM and Clang. The
+:doc:`AST matchers tutorial`
+provides a section that describes how to obtain and build LLVM and Clang.
+
+Implementing a local source transformation
+==
+
+This tutorial walks through an implementation of the
+"flatten nested if statements" refactoring operation. This action can take a
+selected ``if`` statement that's nested in another ``if`` and merge the two
+into ``if``s one just one ``if``. For example, the following code:
+
+.. code-block:: c++
+
+  int computeArrayOffset(int x, int y) {
+if (x >= 0) {
+  if (y >= 0) {
+return x * 4 + y;
+  }
+}
+throw std::runtime_error("negative indices");
+  }
+
+
+becomes:
+
+.. code-block:: c++
+
+  int computeArrayOffset(int x, int y) {
+if (x >= 0 && y >= 0)
+  return x * 4 + y;
+throw std::runtime_error("negative indices");
+  }
+
+after this refactoring.
+
+This refactoring is a local source transformation, since it only requires one
+translation unit in order to perform the refactoring.
+
+Before diving into a potential implementation of a refactoring, let's try
+to break it down. This operation is a "flatten" operation, which in theory
+could be applied to other types of directives, like the ``switch`` statements
+or maybe even loops. We can think of the particular flavor of the refactoring
+that merges the ``if`` statements as just one refactoring operation that's
+contained in the "flatten" refactoring action. The refactoring library
+encourages you to think in terms like these. In particular, it encourages
+developers to decompose refactorings into a single action that contains one or
+more operation that either produce similar results or have different refactoring
+modes of operation. The different operations should still be identifiable
+by just one name, like "flatten". For the rest of the tutorial I will talk
+about the decomposed refactoring using terms like the "flatten" refactoring
+action and the "flatten nested if statements" refactoring operation.
+
+Now that we've established and decomposed the refactoring action, let's go
+ahead and look at how it can be implemented.
+
+Step 1: Create the "flatten nested if statements" refactoring operation
+---
+
+Let's start our implementation with the refactoring operation class that will
+be responsible for making the source changes.
+
+We can start by adding an implementation file in ``lib/Tooling/Refactoring``.
+Let's call it something like ``FlattenIfStatements.cpp``. Don't forget to add
+it to 

[PATCH] D39031: [Analyzer] Correctly handle parameters passed by reference when bodyfarming std::call_once

2017-10-17 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov created this revision.
Herald added subscribers: szepet, kristof.beyls, xazax.hun, javed.absar, 
aemerson.

Also explicitly do not support functors for now, since that entails figuring 
out which call operator corresponds to the passed parameters.
Resolution: we really should not do body farming for templated C++ functions, 
even in seemingly trivial cases!


https://reviews.llvm.org/D39031

Files:
  lib/Analysis/BodyFarm.cpp
  test/Analysis/call_once.cpp

Index: test/Analysis/call_once.cpp
===
--- test/Analysis/call_once.cpp
+++ test/Analysis/call_once.cpp
@@ -249,3 +249,44 @@
 void test_no_segfault_on_different_impl() {
   std::call_once(g, false); // no-warning
 }
+
+void test_lambda_refcapture() {
+  static std::once_flag flag;
+  int a = 6;
+  std::call_once(flag, [&](int &a) { a = 42; }, a);
+  clang_analyzer_eval(a == 42); // expected-warning{{TRUE}}
+}
+
+void test_lambda_refcapture2() {
+  static std::once_flag flag;
+  int a = 6;
+  std::call_once(flag, [=](int &a) { a = 42; }, a);
+  clang_analyzer_eval(a == 42); // expected-warning{{TRUE}}
+}
+
+void test_lambda_fail_refcapture() {
+  static std::once_flag flag;
+  int a = 6;
+  std::call_once(flag, [=](int a) { a = 42; }, a);
+  clang_analyzer_eval(a == 42); // expected-warning{{FALSE}}
+}
+
+void mutator(int ¶m) {
+  param = 42;
+}
+void test_reftypes_funcptr() {
+  static std::once_flag flag;
+  int a = 6;
+  std::call_once(flag, &mutator, a);
+  clang_analyzer_eval(a == 42); // expected-warning{{TRUE}}
+}
+
+void fail_mutator(int param) {
+  param = 42;
+}
+void test_mutator_noref() {
+  static std::once_flag flag;
+  int a = 6;
+  std::call_once(flag, &fail_mutator, a);
+  clang_analyzer_eval(a == 42); // expected-warning{{FALSE}}
+}
Index: lib/Analysis/BodyFarm.cpp
===
--- lib/Analysis/BodyFarm.cpp
+++ lib/Analysis/BodyFarm.cpp
@@ -264,11 +264,8 @@
 
 static CallExpr *create_call_once_lambda_call(ASTContext &C, ASTMaker M,
   const ParmVarDecl *Callback,
-  QualType CallbackType,
+  CXXRecordDecl *CallbackDecl,
   ArrayRef CallArgs) {
-
-  CXXRecordDecl *CallbackDecl = CallbackType->getAsCXXRecordDecl();
-
   assert(CallbackDecl != nullptr);
   assert(CallbackDecl->isLambda());
   FunctionDecl *callOperatorDecl = CallbackDecl->getLambdaCallOperator();
@@ -319,6 +316,9 @@
   const ParmVarDecl *Flag = D->getParamDecl(0);
   const ParmVarDecl *Callback = D->getParamDecl(1);
   QualType CallbackType = Callback->getType().getNonReferenceType();
+
+  // Nullable pointer, non-null iff function is a CXXRecordDecl.
+  CXXRecordDecl *CallbackRecordDecl = CallbackType->getAsCXXRecordDecl();
   QualType FlagType = Flag->getType().getNonReferenceType();
   auto *FlagRecordDecl = dyn_cast_or_null(FlagType->getAsTagDecl());
 
@@ -348,28 +348,59 @@
 return nullptr;
   }
 
-  bool isLambdaCall = CallbackType->getAsCXXRecordDecl() &&
-  CallbackType->getAsCXXRecordDecl()->isLambda();
+  bool isLambdaCall = CallbackRecordDecl && CallbackRecordDecl->isLambda();
+  if (CallbackRecordDecl && !isLambdaCall) {
+DEBUG(llvm::dbgs() << "Not supported: synthesizing body for functors when "
+   << "body farming std::call_once, ignoring the call.");
+return nullptr;
+  }
 
   SmallVector CallArgs;
+  const FunctionProtoType *CallbackFunctionType;
+  if (isLambdaCall) {
 
-  if (isLambdaCall)
 // Lambda requires callback itself inserted as a first parameter.
 CallArgs.push_back(
 M.makeDeclRefExpr(Callback,
   /* RefersToEnclosingVariableOrCapture= */ true));
+CallbackFunctionType = CallbackRecordDecl->getLambdaCallOperator()
+   ->getType()
+   ->getAs();
+  } else {
+CallbackFunctionType =
+CallbackType->getPointeeType()->getAs();
+  }
 
-  // All arguments past first two ones are passed to the callback.
-  for (unsigned int i = 2; i < D->getNumParams(); i++)
-CallArgs.push_back(
-M.makeLvalueToRvalue(D->getParamDecl(i),
- /* RefersToEnclosingVariableOrCapture= */ false));
+  if (!CallbackFunctionType)
+return nullptr;
+
+  // First two arguments are used for the flag and for the callback.
+  if (D->getNumParams() != CallbackFunctionType->getNumParams() + 2) {
+DEBUG(llvm::dbgs() << "Number of params of the callback does not match "
+   << "the number of params passed to std::call_once, "
+   << "ignoring the call");
+return nullptr;
+  }
+
+  // All arguments past first two ones are passed to the callback,
+  // and we turn lvalues into rvalues if the argument is not passed by
+  // reference.
+  for

[PATCH] D39017: [CMake] Build Fuchsia toolchain as -O3

2017-10-17 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316053: [CMake] Build Fuchsia toolchain as -O3 (authored by 
phosek).

Changed prior to commit:
  https://reviews.llvm.org/D39017?vs=119372&id=119417#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39017

Files:
  cfe/trunk/cmake/caches/Fuchsia-stage2.cmake


Index: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
===
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
@@ -30,8 +30,8 @@
 endif()
 
 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
-set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
-set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
 
 set(LLVM_BUILTIN_TARGETS "x86_64-fuchsia;aarch64-fuchsia" CACHE STRING "")
 foreach(target x86_64;aarch64)


Index: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
===
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
@@ -30,8 +30,8 @@
 endif()
 
 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
-set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE STRING "")
-set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE STRING "")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE STRING "")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE STRING "")
 
 set(LLVM_BUILTIN_TARGETS "x86_64-fuchsia;aarch64-fuchsia" CACHE STRING "")
 foreach(target x86_64;aarch64)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r316053 - [CMake] Build Fuchsia toolchain as -O3

2017-10-17 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Tue Oct 17 18:27:54 2017
New Revision: 316053

URL: http://llvm.org/viewvc/llvm-project?rev=316053&view=rev
Log:
[CMake] Build Fuchsia toolchain as -O3

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

Modified:
cfe/trunk/cmake/caches/Fuchsia-stage2.cmake

Modified: cfe/trunk/cmake/caches/Fuchsia-stage2.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/Fuchsia-stage2.cmake?rev=316053&r1=316052&r2=316053&view=diff
==
--- cfe/trunk/cmake/caches/Fuchsia-stage2.cmake (original)
+++ cfe/trunk/cmake/caches/Fuchsia-stage2.cmake Tue Oct 17 18:27:54 2017
@@ -30,8 +30,8 @@ if(APPLE)
 endif()
 
 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
-set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
-set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
 
 set(LLVM_BUILTIN_TARGETS "x86_64-fuchsia;aarch64-fuchsia" CACHE STRING "")
 foreach(target x86_64;aarch64)


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


  1   2   >