[libcxx] r307518 - Fix issues with UBSAN test configuration.

2017-07-09 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Sun Jul  9 21:32:21 2017
New Revision: 307518

URL: http://llvm.org/viewvc/llvm-project?rev=307518=rev
Log:
Fix issues with UBSAN test configuration.

On Apple the test feature 'sanitizer-new-delete' was incorrectly
getting added to the LIT feature set, which mistakenly caused tests
to be disabled when using UBSAN (the feature is only needed with 
ASAN/MSAN/TSAN).

Modified:

libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp
libcxx/trunk/utils/libcxx/test/target_info.py

Modified: 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp?rev=307518=307517=307518=diff
==
--- 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp
 (original)
+++ 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default_throws_bad_alloc.pass.cpp
 Sun Jul  9 21:32:21 2017
@@ -16,7 +16,7 @@
 // UNSUPPORTED: c++98, c++03, c++11
 
 // The sanitizers replace new/delete with versions that do not throw bad_alloc.
-// UNSUPPORTED: sanitizer-new-delete, ubsan
+// UNSUPPORTED: sanitizer-new-delete
 
 
 #include 

Modified: libcxx/trunk/utils/libcxx/test/target_info.py
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/utils/libcxx/test/target_info.py?rev=307518=307517=307518=diff
==
--- libcxx/trunk/utils/libcxx/test/target_info.py (original)
+++ libcxx/trunk/utils/libcxx/test/target_info.py Sun Jul  9 21:32:21 2017
@@ -169,10 +169,6 @@ class DarwinLocalTI(DefaultTargetInfo):
 # should be available in libc++ directly.
 return False
 
-def add_sanitizer_features(self, sanitizer_type, features):
-if sanitizer_type == 'Undefined':
-features.add('sanitizer-new-delete')
-
 
 class FreeBSDLocalTI(DefaultTargetInfo):
 def __init__(self, full_config):


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


[libcxx] r307517 - Work around PR31864 - ATOMIC_LLONG_LOCK_FREE is incorrect in 32 bit builds

2017-07-09 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Sun Jul  9 21:16:50 2017
New Revision: 307517

URL: http://llvm.org/viewvc/llvm-project?rev=307517=rev
Log:
Work around PR31864 - ATOMIC_LLONG_LOCK_FREE is incorrect in 32 bit builds

Modified:
libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp

Modified: 
libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp?rev=307517=307516=307517=diff
==
--- libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp 
(original)
+++ libcxx/trunk/test/std/atomics/atomics.lockfree/isalwayslockfree.pass.cpp 
Sun Jul  9 21:16:50 2017
@@ -25,6 +25,40 @@ template  void checkAlwaysLo
 assert(std::atomic().is_lock_free());
 }
 
+// FIXME: This separate test is needed to work around llvm.org/PR31864
+// which causes ATOMIC_LLONG_LOCK_FREE to be defined as '1' in 32-bit builds
+// even though __atomic_always_lock_free returns true for the same type.
+constexpr bool NeedWorkaroundForPR31864 =
+#if defined(__clang__)
+(sizeof(void*) == 4); // Needed on 32 bit builds
+#else
+false;
+#endif
+
+template * = nullptr,
+  class LLong = long long,
+  class ULLong = unsigned long long>
+void checkLongLongTypes() {
+  static_assert(std::atomic::is_always_lock_free == (2 == 
ATOMIC_LLONG_LOCK_FREE));
+  static_assert(std::atomic::is_always_lock_free == (2 == 
ATOMIC_LLONG_LOCK_FREE));
+}
+
+// Used to make the calls to __atomic_always_lock_free dependent on a template
+// parameter.
+template  constexpr size_t getSizeOf() { return sizeof(T); }
+
+template * = nullptr,
+  class LLong = long long,
+  class ULLong = unsigned long long>
+void checkLongLongTypes() {
+  constexpr bool ExpectLockFree = 
__atomic_always_lock_free(getSizeOf(), 0);
+  static_assert(std::atomic::is_always_lock_free == ExpectLockFree, "");
+  static_assert(std::atomic::is_always_lock_free == ExpectLockFree, 
"");
+  static_assert((0 != ATOMIC_LLONG_LOCK_FREE) == ExpectLockFree, "");
+}
+
 int main()
 {
 // structs and unions can't be defined in the template invocation.
@@ -94,8 +128,7 @@ int main()
 static_assert(std::atomic::is_always_lock_free == (2 == 
ATOMIC_INT_LOCK_FREE));
 static_assert(std::atomic::is_always_lock_free == (2 == 
ATOMIC_LONG_LOCK_FREE));
 static_assert(std::atomic::is_always_lock_free == (2 == 
ATOMIC_LONG_LOCK_FREE));
-static_assert(std::atomic::is_always_lock_free == (2 == 
ATOMIC_LLONG_LOCK_FREE));
-static_assert(std::atomic::is_always_lock_free == (2 
== ATOMIC_LLONG_LOCK_FREE));
+checkLongLongTypes();
 static_assert(std::atomic::is_always_lock_free == (2 == 
ATOMIC_POINTER_LOCK_FREE));
 static_assert(std::atomic::is_always_lock_free == (2 == 
ATOMIC_POINTER_LOCK_FREE));
 }


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


r307515 - Remove incorrect FIXME comment; the FIXME was addressed before the changes were committed

2017-07-09 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Sun Jul  9 19:59:26 2017
New Revision: 307515

URL: http://llvm.org/viewvc/llvm-project?rev=307515=rev
Log:
Remove incorrect FIXME comment; the FIXME was addressed before the changes were 
committed

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

Modified: cfe/trunk/lib/Sema/SemaCoroutine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCoroutine.cpp?rev=307515=307514=307515=diff
==
--- cfe/trunk/lib/Sema/SemaCoroutine.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCoroutine.cpp Sun Jul  9 19:59:26 2017
@@ -745,8 +745,6 @@ static Expr *buildStdNoThrowDeclRef(Sema
 return nullptr;
   }
 
-  // FIXME: Mark the variable as ODR used. This currently does not work
-  // likely due to the scope at in which this function is called.
   auto *VD = Result.getAsSingle();
   if (!VD) {
 Result.suppressDiagnostics();


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


r307514 - Remove non-ascii characters introduced in r307513

2017-07-09 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Sun Jul  9 19:52:34 2017
New Revision: 307514

URL: http://llvm.org/viewvc/llvm-project?rev=307514=rev
Log:
Remove non-ascii characters introduced in r307513

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

Modified: cfe/trunk/lib/Sema/SemaCoroutine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCoroutine.cpp?rev=307514=307513=307514=diff
==
--- cfe/trunk/lib/Sema/SemaCoroutine.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCoroutine.cpp Sun Jul  9 19:52:34 2017
@@ -87,10 +87,10 @@ static QualType lookupPromiseType(Sema &
   // [over.match.funcs]4
   // For non-static member functions, the type of the implicit object
   // parameter is
-  //  — “lvalue reference to cv X” for functions declared without a
-  //ref-qualifier or with the & ref-qualifier
-  //  — “rvalue reference to cv X” for functions declared with the &&
-  //ref-qualifier
+  //  -- "lvalue reference to cv X" for functions declared without a
+  //  ref-qualifier or with the & ref-qualifier
+  //  -- "rvalue reference to cv X" for functions declared with the &&
+  //  ref-qualifier
   QualType T =
   MD->getThisType(S.Context)->getAs()->getPointeeType();
   T = FnType->getRefQualifier() == RQ_RValue


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


[PATCH] D35180: Expose the Clang::QualType to llvm::Type conversion functions

2017-07-09 Thread Benoit Vey via Phabricator via cfe-commits
Praetonus updated this revision to Diff 105803.
Praetonus added a comment.

Patch updated to adhere to the coding style based on @majnemer's comments.


https://reviews.llvm.org/D35180

Files:
  include/clang/CodeGen/CodeGenABITypes.h
  lib/CodeGen/CodeGenABITypes.cpp


Index: lib/CodeGen/CodeGenABITypes.cpp
===
--- lib/CodeGen/CodeGenABITypes.cpp
+++ lib/CodeGen/CodeGenABITypes.cpp
@@ -64,3 +64,19 @@
   returnType, /*IsInstanceMethod=*/false, /*IsChainCall=*/false, argTypes,
   info, {}, args);
 }
+
+llvm::FunctionType *
+CodeGen::convertFreeFunctionType(CodeGenModule , const FunctionDecl *FD) {
+  assert(FD != nullptr && "Expected a non-null function declaration!");
+  llvm::Type *T = CGM.getTypes().ConvertFunctionType(FD->getType(), FD);
+
+  if (auto FT = dyn_cast(T))
+return FT;
+
+  return nullptr;
+}
+
+llvm::Type *
+CodeGen::convertTypeForMemory(CodeGenModule , QualType T) {
+  return CGM.getTypes().ConvertTypeForMem(T);
+}
Index: include/clang/CodeGen/CodeGenABITypes.h
===
--- include/clang/CodeGen/CodeGenABITypes.h
+++ include/clang/CodeGen/CodeGenABITypes.h
@@ -31,6 +31,7 @@
 namespace llvm {
   class DataLayout;
   class Module;
+  class Type;
 }
 
 namespace clang {
@@ -70,6 +71,12 @@
   FunctionType::ExtInfo info,
   RequiredArgs args);
 
+// Returns null if the function type is incomplete and can't be lowered.
+llvm::FunctionType *convertFreeFunctionType(CodeGenModule ,
+const FunctionDecl *FD);
+
+llvm::Type *convertTypeForMemory(CodeGenModule , QualType T);
+
 }  // end namespace CodeGen
 }  // end namespace clang
 


Index: lib/CodeGen/CodeGenABITypes.cpp
===
--- lib/CodeGen/CodeGenABITypes.cpp
+++ lib/CodeGen/CodeGenABITypes.cpp
@@ -64,3 +64,19 @@
   returnType, /*IsInstanceMethod=*/false, /*IsChainCall=*/false, argTypes,
   info, {}, args);
 }
+
+llvm::FunctionType *
+CodeGen::convertFreeFunctionType(CodeGenModule , const FunctionDecl *FD) {
+  assert(FD != nullptr && "Expected a non-null function declaration!");
+  llvm::Type *T = CGM.getTypes().ConvertFunctionType(FD->getType(), FD);
+
+  if (auto FT = dyn_cast(T))
+return FT;
+
+  return nullptr;
+}
+
+llvm::Type *
+CodeGen::convertTypeForMemory(CodeGenModule , QualType T) {
+  return CGM.getTypes().ConvertTypeForMem(T);
+}
Index: include/clang/CodeGen/CodeGenABITypes.h
===
--- include/clang/CodeGen/CodeGenABITypes.h
+++ include/clang/CodeGen/CodeGenABITypes.h
@@ -31,6 +31,7 @@
 namespace llvm {
   class DataLayout;
   class Module;
+  class Type;
 }
 
 namespace clang {
@@ -70,6 +71,12 @@
   FunctionType::ExtInfo info,
   RequiredArgs args);
 
+// Returns null if the function type is incomplete and can't be lowered.
+llvm::FunctionType *convertFreeFunctionType(CodeGenModule ,
+const FunctionDecl *FD);
+
+llvm::Type *convertTypeForMemory(CodeGenModule , QualType T);
+
 }  // end namespace CodeGen
 }  // end namespace clang
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35180: Expose the Clang::QualType to llvm::Type conversion functions

2017-07-09 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: lib/CodeGen/CodeGenABITypes.cpp:71
+  assert(FD != nullptr && "Expected a non-null function declaration!");
+  llvm::Type* T = CGM.getTypes().ConvertFunctionType(FD->getType(), FD);
+

Pointers lean right.



Comment at: lib/CodeGen/CodeGenABITypes.cpp:73
+
+  if(auto FT = dyn_cast(T))
+return FT;

need a space between the `if` and the parenthesis.


https://reviews.llvm.org/D35180



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


[PATCH] D35172: Keep the IdentifierInfo in the Token for alternative operator keyword

2017-07-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

It looks like there are fewer special cases with this direction then our 
present one, though I worry that they'll be less obvious. On the whole, this 
seems like a improvement.




Comment at: lib/Lex/PPExpressions.cpp:242
   switch (PeekTok.getKind()) {
-  default:  // Non-value token.
+  default:
+// If this token's spelling is a pp-identifier, check to see if it is

I'm concerned that this will do the wrong thing for a keyword operator that is 
not permitted in a pp expression, like and_eq. It seems safer to revert this 
change and instead add a isCPlusPlusOperatorKeyword check to the "if" condition 
above.


https://reviews.llvm.org/D35172



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


r307513 - [coroutines] Include the implicit object parameter type when looking up coroutine_traits for member functions.

2017-07-09 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Sun Jul  9 18:27:22 2017
New Revision: 307513

URL: http://llvm.org/viewvc/llvm-project?rev=307513=rev
Log:
[coroutines] Include the implicit object parameter type when looking up 
coroutine_traits for member functions.

This patch was originally from Toby Allsopp, but I hijacked it and
fixed it up with his permission.

Modified:
cfe/trunk/lib/Sema/SemaCoroutine.cpp
cfe/trunk/test/SemaCXX/coroutines.cpp

Modified: cfe/trunk/lib/Sema/SemaCoroutine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCoroutine.cpp?rev=307513=307512=307513=diff
==
--- cfe/trunk/lib/Sema/SemaCoroutine.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCoroutine.cpp Sun Jul  9 18:27:22 2017
@@ -43,9 +43,10 @@ static bool lookupMember(Sema , const
 
 /// Look up the std::coroutine_traits<...>::promise_type for the given
 /// function type.
-static QualType lookupPromiseType(Sema , const FunctionProtoType *FnType,
-  SourceLocation KwLoc,
-  SourceLocation FuncLoc) {
+static QualType lookupPromiseType(Sema , const FunctionDecl *FD,
+  SourceLocation KwLoc) {
+  const FunctionProtoType *FnType = FD->getType()->castAs();
+  const SourceLocation FuncLoc = FD->getLocation();
   // FIXME: Cache std::coroutine_traits once we've found it.
   NamespaceDecl *StdExp = S.lookupStdExperimentalNamespace();
   if (!StdExp) {
@@ -71,16 +72,35 @@ static QualType lookupPromiseType(Sema &
 return QualType();
   }
 
-  // Form template argument list for coroutine_traits.
+  // Form template argument list for coroutine_traits according
+  // to [dcl.fct.def.coroutine]3
   TemplateArgumentListInfo Args(KwLoc, KwLoc);
-  Args.addArgument(TemplateArgumentLoc(
-  TemplateArgument(FnType->getReturnType()),
-  S.Context.getTrivialTypeSourceInfo(FnType->getReturnType(), KwLoc)));
-  // FIXME: If the function is a non-static member function, add the type
-  // of the implicit object parameter before the formal parameters.
-  for (QualType T : FnType->getParamTypes())
+  auto AddArg = [&](QualType T) {
 Args.addArgument(TemplateArgumentLoc(
 TemplateArgument(T), S.Context.getTrivialTypeSourceInfo(T, KwLoc)));
+  };
+  AddArg(FnType->getReturnType());
+  // If the function is a non-static member function, add the type
+  // of the implicit object parameter before the formal parameters.
+  if (auto *MD = dyn_cast(FD)) {
+if (MD->isInstance()) {
+  // [over.match.funcs]4
+  // For non-static member functions, the type of the implicit object
+  // parameter is
+  //  — “lvalue reference to cv X” for functions declared without a
+  //ref-qualifier or with the & ref-qualifier
+  //  — “rvalue reference to cv X” for functions declared with the &&
+  //ref-qualifier
+  QualType T =
+  MD->getThisType(S.Context)->getAs()->getPointeeType();
+  T = FnType->getRefQualifier() == RQ_RValue
+  ? S.Context.getRValueReferenceType(T)
+  : S.Context.getLValueReferenceType(T, /*SpelledAsLValue*/ true);
+  AddArg(T);
+}
+  }
+  for (QualType T : FnType->getParamTypes())
+AddArg(T);
 
   // Build the template-id.
   QualType CoroTrait =
@@ -424,12 +444,16 @@ static ExprResult buildPromiseCall(Sema
 VarDecl *Sema::buildCoroutinePromise(SourceLocation Loc) {
   assert(isa(CurContext) && "not in a function scope");
   auto *FD = cast(CurContext);
-
-  QualType T =
-  FD->getType()->isDependentType()
-  ? Context.DependentTy
-  : lookupPromiseType(*this, 
FD->getType()->castAs(),
-  Loc, FD->getLocation());
+  bool IsThisDependentType = [&] {
+if (auto *MD = dyn_cast_or_null(FD))
+  return MD->isInstance() && MD->getThisType(Context)->isDependentType();
+else
+  return false;
+  }();
+
+  QualType T = FD->getType()->isDependentType() || IsThisDependentType
+   ? Context.DependentTy
+   : lookupPromiseType(*this, FD, Loc);
   if (T.isNull())
 return nullptr;
 

Modified: cfe/trunk/test/SemaCXX/coroutines.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/coroutines.cpp?rev=307513=307512=307513=diff
==
--- cfe/trunk/test/SemaCXX/coroutines.cpp (original)
+++ cfe/trunk/test/SemaCXX/coroutines.cpp Sun Jul  9 18:27:22 2017
@@ -22,8 +22,24 @@ void no_coroutine_traits() {
 
 namespace std {
 namespace experimental {
-template 
-struct coroutine_traits; // expected-note {{declared here}}
+
+template 
+struct void_t_imp {
+  using type = void;
+};
+template 
+using void_t = typename void_t_imp::type;
+
+template 
+struct traits_sfinae_base {};
+
+template 
+struct traits_sfinae_base {
+  using promise_type = typename 

[PATCH] D35180: Expose the Clang::QualType to llvm::Type conversion functions

2017-07-09 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Looks great, thanks!


https://reviews.llvm.org/D35180



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


[PATCH] D35180: Expose the Clang::QualType to llvm::Type conversion functions

2017-07-09 Thread Benoit Vey via Phabricator via cfe-commits
Praetonus updated this revision to Diff 105795.
Praetonus marked 3 inline comments as done.
Praetonus added a comment.

Patch updated. I've made the convertFreeFunctionType return null on failure.


https://reviews.llvm.org/D35180

Files:
  include/clang/CodeGen/CodeGenABITypes.h
  lib/CodeGen/CodeGenABITypes.cpp


Index: lib/CodeGen/CodeGenABITypes.cpp
===
--- lib/CodeGen/CodeGenABITypes.cpp
+++ lib/CodeGen/CodeGenABITypes.cpp
@@ -64,3 +64,19 @@
   returnType, /*IsInstanceMethod=*/false, /*IsChainCall=*/false, argTypes,
   info, {}, args);
 }
+
+llvm::FunctionType *
+CodeGen::convertFreeFunctionType(CodeGenModule , const FunctionDecl *FD) {
+  assert(FD != nullptr && "Expected a non-null function declaration!");
+  llvm::Type* T = CGM.getTypes().ConvertFunctionType(FD->getType(), FD);
+
+  if(auto FT = dyn_cast(T))
+return FT;
+
+  return nullptr;
+}
+
+llvm::Type *
+CodeGen::convertTypeForMemory(CodeGenModule , QualType T) {
+  return CGM.getTypes().ConvertTypeForMem(T);
+}
Index: include/clang/CodeGen/CodeGenABITypes.h
===
--- include/clang/CodeGen/CodeGenABITypes.h
+++ include/clang/CodeGen/CodeGenABITypes.h
@@ -31,6 +31,7 @@
 namespace llvm {
   class DataLayout;
   class Module;
+  class Type;
 }
 
 namespace clang {
@@ -70,6 +71,12 @@
   FunctionType::ExtInfo info,
   RequiredArgs args);
 
+// Returns null if the function type is incomplete and can't be lowered.
+llvm::FunctionType *convertFreeFunctionType(CodeGenModule ,
+const FunctionDecl *FD);
+
+llvm::Type *convertTypeForMemory(CodeGenModule , QualType T);
+
 }  // end namespace CodeGen
 }  // end namespace clang
 


Index: lib/CodeGen/CodeGenABITypes.cpp
===
--- lib/CodeGen/CodeGenABITypes.cpp
+++ lib/CodeGen/CodeGenABITypes.cpp
@@ -64,3 +64,19 @@
   returnType, /*IsInstanceMethod=*/false, /*IsChainCall=*/false, argTypes,
   info, {}, args);
 }
+
+llvm::FunctionType *
+CodeGen::convertFreeFunctionType(CodeGenModule , const FunctionDecl *FD) {
+  assert(FD != nullptr && "Expected a non-null function declaration!");
+  llvm::Type* T = CGM.getTypes().ConvertFunctionType(FD->getType(), FD);
+
+  if(auto FT = dyn_cast(T))
+return FT;
+
+  return nullptr;
+}
+
+llvm::Type *
+CodeGen::convertTypeForMemory(CodeGenModule , QualType T) {
+  return CGM.getTypes().ConvertTypeForMem(T);
+}
Index: include/clang/CodeGen/CodeGenABITypes.h
===
--- include/clang/CodeGen/CodeGenABITypes.h
+++ include/clang/CodeGen/CodeGenABITypes.h
@@ -31,6 +31,7 @@
 namespace llvm {
   class DataLayout;
   class Module;
+  class Type;
 }
 
 namespace clang {
@@ -70,6 +71,12 @@
   FunctionType::ExtInfo info,
   RequiredArgs args);
 
+// Returns null if the function type is incomplete and can't be lowered.
+llvm::FunctionType *convertFreeFunctionType(CodeGenModule ,
+const FunctionDecl *FD);
+
+llvm::Type *convertTypeForMemory(CodeGenModule , QualType T);
+
 }  // end namespace CodeGen
 }  // end namespace clang
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r307510 - Fix test failure to to new/delete ellisions

2017-07-09 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Sun Jul  9 15:20:07 2017
New Revision: 307510

URL: http://llvm.org/viewvc/llvm-project?rev=307510=rev
Log:
Fix test failure to to new/delete ellisions

Modified:

libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp?rev=307510=307509=307510=diff
==
--- 
libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp
 Sun Jul  9 15:20:07 2017
@@ -29,11 +29,12 @@ struct A
 
 int main()
 {
+globalMemCounter.reset();
 std::allocator a;
 assert(globalMemCounter.checkOutstandingNewEq(0));
 assert(A_constructed == 0);
 globalMemCounter.last_new_size = 0;
-A* ap = a.allocate(3);
+A* volatile ap = a.allocate(3);
 assert(globalMemCounter.checkOutstandingNewEq(1));
 assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int)));
 assert(A_constructed == 0);
@@ -42,7 +43,7 @@ int main()
 assert(A_constructed == 0);
 
 globalMemCounter.last_new_size = 0;
-A* ap2 = a.allocate(3, (const void*)5);
+A* volatile ap2 = a.allocate(3, (const void*)5);
 assert(globalMemCounter.checkOutstandingNewEq(1));
 assert(globalMemCounter.checkLastNewSizeEq(3 * sizeof(int)));
 assert(A_constructed == 0);


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


[PATCH] D35174: [libc++] Fix unrepresentable enum for clang-cl unstable ABI

2017-07-09 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

Maybe using a static const variable instead of an enum would work better? 
`__long_mask` should never actually be ODR used so a definition for it should 
never actually be needed.


https://reviews.llvm.org/D35174



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


[PATCH] D35056: GCC ABI incompatibility when passing object with trivial copy ctor, trivial dtor, and non-trivial move ctor

2017-07-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Thank you, I like this approach much better, and the IRGen changes seem fine to 
me.  I'd like to defer to someone else (probably Richard) to review whether the 
changes to completeDefinition() are correct; I'm not up-to-date with how we 
handle lazy declarations.


https://reviews.llvm.org/D35056



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


[PATCH] D35180: Expose the Clang::QualType to llvm::Type conversion functions

2017-07-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Hmm.  Maybe it would make more sense to allow it to return null, and then add a 
comment explaining that it will do so if it can't lower the function type yet.


https://reviews.llvm.org/D35180



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


[PATCH] D35187: [libclang] Support for querying whether an enum is scoped

2017-07-09 Thread Johann Klähn via Phabricator via cfe-commits
jklaehn created this revision.

This patch allows checking whether an enum declaration is scoped
through libclang and clang.cindex (Python).


https://reviews.llvm.org/D35187

Files:
  bindings/python/clang/cindex.py
  bindings/python/tests/cindex/test_cursor.py
  include/clang-c/Index.h
  test/Index/print-type-declaration.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndex.cpp
  tools/libclang/libclang.exports

Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -12,6 +12,7 @@
 clang_CXXMethod_isPureVirtual
 clang_CXXMethod_isStatic
 clang_CXXMethod_isVirtual
+clang_EnumDecl_isScoped
 clang_Cursor_getArgument
 clang_Cursor_getNumTemplateArguments
 clang_Cursor_getTemplateArgumentKind
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -7807,6 +7807,15 @@
   return (Method && Method->isVirtual()) ? 1 : 0;
 }
 
+unsigned clang_EnumDecl_isScoped(CXCursor C) {
+  if (!clang_isDeclaration(C.kind))
+return 0;
+
+  const Decl *D = cxcursor::getCursorDecl(C);
+  const EnumDecl *Enum = D ? dyn_cast_or_null(D) : nullptr;
+  return (Enum && Enum->isScoped()) ? 1 : 0;
+}
+
 //===--===//
 // Attribute introspection.
 //===--===//
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -804,6 +804,8 @@
   printf(" (const)");
 if (clang_CXXMethod_isPureVirtual(Cursor))
   printf(" (pure)");
+if (clang_EnumDecl_isScoped(Cursor))
+  printf(" (scoped)");
 if (clang_Cursor_isVariadic(Cursor))
   printf(" (variadic)");
 if (clang_Cursor_isObjCOptional(Cursor))
Index: test/Index/print-type-declaration.cpp
===
--- test/Index/print-type-declaration.cpp
+++ test/Index/print-type-declaration.cpp
@@ -7,6 +7,13 @@
   auto b = a;
 }
 
+enum RegularEnum {};
+
+enum class ScopedEnum {};
+
 // RUN: c-index-test -test-print-type-declaration -std=c++11 %s | FileCheck %s
 // CHECK: VarDecl=a:6:8 (Definition) [typedeclaration=Test] [typekind=Record]
 // CHECK: VarDecl=b:7:8 (Definition) [typedeclaration=Test] [typekind=Record]
+// CHECK: EnumDecl=RegularEnum:10:6 (Definition) [typedeclaration=RegularEnum] [typekind=Enum]
+// CHECK: EnumDecl=ScopedEnum:12:12 (Definition) (scoped) [typedeclaration=ScopedEnum] [typekind=Enum]
+
Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -4417,6 +4417,11 @@
 CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
 
 /**
+ * \brief Determine if an enum declaration refers to a scoped enum.
+ */
+CINDEX_LINKAGE unsigned clang_EnumDecl_isScoped(CXCursor C);
+
+/**
  * \brief Determine if a C++ member function or member function template is
  * declared 'const'.
  */
Index: bindings/python/tests/cindex/test_cursor.py
===
--- bindings/python/tests/cindex/test_cursor.py
+++ bindings/python/tests/cindex/test_cursor.py
@@ -255,6 +255,22 @@
 assert foo.is_virtual_method()
 assert not bar.is_virtual_method()
 
+def test_is_scoped_enum():
+"""Ensure Cursor.is_scoped_enum works."""
+source = 'class X {}; enum RegularEnum {}; enum class ScopedEnum {};'
+tu = get_tu(source, lang='cpp')
+
+cls = get_cursor(tu, 'X')
+regular_enum = get_cursor(tu, 'RegularEnum')
+scoped_enum = get_cursor(tu, 'ScopedEnum')
+assert cls is not None
+assert regular_enum is not None
+assert scoped_enum is not None
+
+assert not cls.is_scoped_enum()
+assert not regular_enum.is_scoped_enum()
+assert scoped_enum.is_scoped_enum()
+
 def test_underlying_type():
 tu = get_tu('typedef int foo;')
 typedef = get_cursor(tu, 'foo')
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -1478,6 +1478,11 @@
 """
 return conf.lib.clang_CXXMethod_isVirtual(self)
 
+def is_scoped_enum(self):
+"""Returns True if the cursor refers to a scoped enum declaration.
+"""
+return conf.lib.clang_EnumDecl_isScoped(self)
+
 def get_definition(self):
 """
 If the cursor is a reference to a declaration or a declaration of
@@ -3314,6 +3319,10 @@
[Cursor],
bool),
 
+  ("clang_EnumDecl_isScoped",
+   [Cursor],
+   bool),
+
   ("clang_defaultDiagnosticDisplayOptions",
[],
c_uint),

[PATCH] D30946: [ScopePrinting] Added support to print full scopes of types and declarations.

2017-07-09 Thread Simon Schroeder via Phabricator via cfe-commits
schroedersi added a comment.

Ping :)


https://reviews.llvm.org/D30946



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


[PATCH] D35172: Keep the IdentifierInfo in the Token for alternative operator keyword

2017-07-09 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

My interaction with this is as a submitter for Melanie, so hopefully she can 
validate that this doesn't break anything subtle.  To me it DOES seem like a 
good approach, however Richard likely has a better idea about it, so I want to 
give him a bit of time before accepting.


https://reviews.llvm.org/D35172



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


r307509 - [analyzer] Faster hashing of subsequences in CompoundStmts.

2017-07-09 Thread Raphael Isemann via cfe-commits
Author: teemperor
Date: Sun Jul  9 14:14:36 2017
New Revision: 307509

URL: http://llvm.org/viewvc/llvm-project?rev=307509=rev
Log:
[analyzer] Faster hashing of subsequences in CompoundStmts.

Summary: This patches improves the hashing subsequences in CompoundStmts by 
incrementally hashing all subsequences with the same starting position. This 
results in a reduction of the time for this constraint while running over 
SQLite from 1.10 seconds to 0.55 seconds (-50%).

Reviewers: NoQ

Reviewed By: NoQ

Subscribers: cfe-commits, xazax.hun, v.g.vassilev

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

Modified:
cfe/trunk/lib/Analysis/CloneDetection.cpp

Modified: cfe/trunk/lib/Analysis/CloneDetection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CloneDetection.cpp?rev=307509=307508=307509=diff
==
--- cfe/trunk/lib/Analysis/CloneDetection.cpp (original)
+++ cfe/trunk/lib/Analysis/CloneDetection.cpp Sun Jul  9 14:14:36 2017
@@ -239,16 +239,27 @@ size_t RecursiveCloneTypeIIConstraint::s
   }
 
   if (CS) {
-for (unsigned Length = 2; Length <= CS->size(); ++Length) {
-  for (unsigned Pos = 0; Pos <= CS->size() - Length; ++Pos) {
-llvm::MD5 Hash;
-for (unsigned i = Pos; i < Pos + Length; ++i) {
-  size_t ChildHash = ChildHashes[i];
-  Hash.update(StringRef(reinterpret_cast(),
-sizeof(ChildHash)));
+// If we're in a CompoundStmt, we hash all possible combinations of child
+// statements to find clones in those subsequences.
+// We first go through every possible starting position of a subsequence.
+for (unsigned Pos = 0; Pos < CS->size(); ++Pos) {
+  // Then we try all possible lengths this subsequence could have and
+  // reuse the same hash object to make sure we only hash every child
+  // hash exactly once.
+  llvm::MD5 Hash;
+  for (unsigned Length = 1; Length <= CS->size() - Pos; ++Length) {
+// Grab the current child hash and put it into our hash. We do
+// -1 on the index because we start counting the length at 1.
+size_t ChildHash = ChildHashes[Pos + Length - 1];
+Hash.update(
+StringRef(reinterpret_cast(), 
sizeof(ChildHash)));
+// If we have at least two elements in our subsequence, we can start
+// saving it.
+if (Length > 1) {
+  llvm::MD5 SubHash = Hash;
+  StmtsByHash.push_back(std::make_pair(
+  createHash(SubHash), StmtSequence(CS, D, Pos, Pos + Length)));
 }
-StmtsByHash.push_back(std::make_pair(
-createHash(Hash), StmtSequence(CS, D, Pos, Pos + Length)));
   }
 }
   }


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


[PATCH] Add warning to clang-reorder-fields when dependencies of init-list exprs are violated

2017-07-09 Thread Sam Conrad via cfe-commits
This adds a warning emitted by clang-reorder-fields when the reordering
fields breaks dependencies in the initializer list (such that
-Wuninitialized would warn).  For example, given:
Foo::Foo(int x)
  : a(x)
  , b(a) {}

Reordering fields to [b,a] gives:
Foo::Foo(int x)
  : b(a)
  , a(x) {}

Emits the warning:
2: Warning: reordering field a after b makes a uninitialized when used in
init expression.

The patch also reformats a few lines that were over 80 columns wide.
Index: tools/extra/clang-reorder-fields/ReorderFieldsAction.cpp
===
--- tools/extra/clang-reorder-fields/ReorderFieldsAction.cpp	(revision 306926)
+++ tools/extra/clang-reorder-fields/ReorderFieldsAction.cpp	(working copy)
@@ -22,6 +22,7 @@
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Refactoring.h"
+#include "llvm/ADT/SetVector.h"
 #include 
 #include 
 
@@ -28,6 +29,7 @@
 namespace clang {
 namespace reorder_fields {
 using namespace clang::ast_matchers;
+using llvm::SmallSetVector;
 
 /// \brief Finds the definition of a record by name.
 ///
@@ -127,13 +129,32 @@
   return true;
 }
 
+/// \brief Find all member fields used in the given init-list initializer expr
+/// that belong to the same record
+///
+/// \returns a set of field declarations, empty if none were present
+static SmallSetVector
+findMembersUsedInInitExpr(const CXXCtorInitializer *Initializer,
+  ASTContext ) {
+  SmallSetVector Results;
+  auto FoundExprs =
+  match(findAll(memberExpr(hasObjectExpression(cxxThisExpr())).bind("ME")),
+*Initializer->getInit(), Context);
+  for (BoundNodes  : FoundExprs)
+if (auto *MemExpr = BN.getNodeAs("ME"))
+  if (FieldDecl *FD = dyn_cast(MemExpr->getMemberDecl()))
+Results.insert(FD);
+  return Results;
+}
+
 /// \brief Reorders initializers in a C++ struct/class constructor.
 ///
-/// A constructor can have initializers for an arbitrary subset of the class's fields.
-/// Thus, we need to ensure that we reorder just the initializers that are present.
+/// A constructor can have initializers for an arbitrary subset of the class's
+/// fields.  Thus, we need to ensure that we reorder just the initializers that
+/// are present.
 static void reorderFieldsInConstructor(
 const CXXConstructorDecl *CtorDecl, ArrayRef NewFieldsOrder,
-const ASTContext ,
+ASTContext ,
 std::map ) {
   assert(CtorDecl && "Constructor declaration is null");
   if (CtorDecl->isImplicit() || CtorDecl->getNumCtorInitializers() <= 1)
@@ -140,8 +161,8 @@
 return;
 
   // The method FunctionDecl::isThisDeclarationADefinition returns false
-  // for a defaulted function unless that function has been implicitly defined.
-  // Thus this assert needs to be after the previous checks.
+  // for a defaulted function unless that function has been implicitly
+  // defined.  Thus this assert needs to be after the previous checks.
   assert(CtorDecl->isThisDeclarationADefinition() && "Not a definition");
 
   SmallVector NewFieldsPositions(NewFieldsOrder.size());
@@ -153,6 +174,22 @@
   for (const auto *Initializer : CtorDecl->inits()) {
 if (!Initializer->isWritten())
   continue;
+
+// Warn if this reordering violates initialization expr dependencies
+const auto UsedMembers = findMembersUsedInInitExpr(Initializer, Context);
+for (auto *UM : UsedMembers) {
+  const auto *ThisM = Initializer->getMember();
+  if (NewFieldsPositions[UM->getFieldIndex()] >
+  NewFieldsPositions[ThisM->getFieldIndex()]) {
+llvm::errs() << Context.getSourceManager().getSpellingLineNumber(
+Initializer->getSourceLocation())
+ << ": Warning: reordering field " << UM->getName()
+ << " after " << ThisM->getName() << " makes "
+ << UM->getName()
+ << " uninitialized when used in init expression\n";
+  }
+}
+
 OldWrittenInitializersOrder.push_back(Initializer);
 NewWrittenInitializersOrder.push_back(Initializer);
   }
@@ -182,12 +219,12 @@
 const ASTContext ,
 std::map ) {
   assert(InitListEx && "Init list expression is null");
-  // We care only about InitListExprs which originate from source code. 
+  // We care only about InitListExprs which originate from source code.
   // Implicit InitListExprs are created by the semantic analyzer.
   if (!InitListEx->isExplicit())
 return true;
-  // The method InitListExpr::getSyntacticForm may return nullptr indicating that
-  // the current initializer list also serves as its syntactic form.
+  // The method InitListExpr::getSyntacticForm may return nullptr indicating
+  // that the current initializer list also serves as its syntactic form.
   if (const auto *SyntacticForm = InitListEx->getSyntacticForm())
  

[PATCH] D35046: [coroutines] Include "this" type when looking up coroutine_traits

2017-07-09 Thread Toby Allsopp via Phabricator via cfe-commits
toby-allsopp added a comment.

In https://reviews.llvm.org/D35046#802838, @EricWF wrote:

> I think the test could be improved. First could you add the test within 
> `test/SemaCXX/coroutines.cpp`? Second could you add some negative tests that 
> check the diagnostics generated when you don't provide a specialization of 
> coroutine traits (ie that the old behaviour of not including the class type 
> now produces diagnostics). Could you also add tests for const/volatile and 
> lvalue/rvalue qualified member functions?


Will do, thanks for the suggestions.




Comment at: lib/Sema/SemaCoroutine.cpp:85
+if (MD->isInstance()) {
+  QualType T = MD->getThisType(S.Context);
+  Args.addArgument(TemplateArgumentLoc(

EricWF wrote:
> This seems wrong to me.
> 
> `getThisType` returns the type of the `this` parameter as specified under 
> [class.this] but according to the coroutines spec the type of the parameter 
> should be the type of the `implicit object parameter`, which is specified 
> under [[http://eel.is/c++draft/over.match.funcs#4 | (over.match.funcs) p4 ]].
Oh wow, that's a howler. I will check my tests against MSVC here. Thanks.



Comment at: lib/Sema/SemaCoroutine.cpp:441
+  return false;
+  }();
 

EricWF wrote:
> Huh, I've never seen lambdas used like this before but I really like it.
It's a sometimes controversial style called immediately-invoked lambda/function 
expression (IILE or IIFE). I saw other instances of it in this file (or 
possibly some other file in clang) so I'm assuming it's acceptable style.


https://reviews.llvm.org/D35046



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


[PATCH] D35180: Expose the Clang::QualType to llvm::Type conversion functions

2017-07-09 Thread Benoit Vey via Phabricator via cfe-commits
Praetonus updated this revision to Diff 105793.
Praetonus added a comment.

Patch updated based on @rjmccall's comments. I removed the wrapper for the 
ConvertType function, after giving it some thoughts I don't see any use case 
for it, I guess I added it by default. I left the convertFreeFunction function 
as returning an llvm::Type instead of an llvm::FunctionType as 
ConvertFunctionType represents incomplete function types as empty aggregate 
types.


https://reviews.llvm.org/D35180

Files:
  include/clang/CodeGen/CodeGenABITypes.h
  lib/CodeGen/CodeGenABITypes.cpp


Index: lib/CodeGen/CodeGenABITypes.cpp
===
--- lib/CodeGen/CodeGenABITypes.cpp
+++ lib/CodeGen/CodeGenABITypes.cpp
@@ -64,3 +64,14 @@
   returnType, /*IsInstanceMethod=*/false, /*IsChainCall=*/false, argTypes,
   info, {}, args);
 }
+
+llvm::Type *
+CodeGen::convertFreeFunctionType(CodeGenModule , const FunctionDecl *FD) {
+  assert(FD != nullptr && "Expected a non-null function declaration!");
+  return CGM.getTypes().ConvertFunctionType(FD->getType(), FD);
+}
+
+llvm::Type *
+CodeGen::convertTypeForMemory(CodeGenModule , QualType T) {
+  return CGM.getTypes().ConvertTypeForMem(T);
+}
Index: include/clang/CodeGen/CodeGenABITypes.h
===
--- include/clang/CodeGen/CodeGenABITypes.h
+++ include/clang/CodeGen/CodeGenABITypes.h
@@ -31,6 +31,7 @@
 namespace llvm {
   class DataLayout;
   class Module;
+  class Type;
 }
 
 namespace clang {
@@ -70,6 +71,10 @@
   FunctionType::ExtInfo info,
   RequiredArgs args);
 
+llvm::Type *convertFreeFunctionType(CodeGenModule , const FunctionDecl 
*FD);
+
+llvm::Type *convertTypeForMemory(CodeGenModule , QualType T);
+
 }  // end namespace CodeGen
 }  // end namespace clang
 


Index: lib/CodeGen/CodeGenABITypes.cpp
===
--- lib/CodeGen/CodeGenABITypes.cpp
+++ lib/CodeGen/CodeGenABITypes.cpp
@@ -64,3 +64,14 @@
   returnType, /*IsInstanceMethod=*/false, /*IsChainCall=*/false, argTypes,
   info, {}, args);
 }
+
+llvm::Type *
+CodeGen::convertFreeFunctionType(CodeGenModule , const FunctionDecl *FD) {
+  assert(FD != nullptr && "Expected a non-null function declaration!");
+  return CGM.getTypes().ConvertFunctionType(FD->getType(), FD);
+}
+
+llvm::Type *
+CodeGen::convertTypeForMemory(CodeGenModule , QualType T) {
+  return CGM.getTypes().ConvertTypeForMem(T);
+}
Index: include/clang/CodeGen/CodeGenABITypes.h
===
--- include/clang/CodeGen/CodeGenABITypes.h
+++ include/clang/CodeGen/CodeGenABITypes.h
@@ -31,6 +31,7 @@
 namespace llvm {
   class DataLayout;
   class Module;
+  class Type;
 }
 
 namespace clang {
@@ -70,6 +71,10 @@
   FunctionType::ExtInfo info,
   RequiredArgs args);
 
+llvm::Type *convertFreeFunctionType(CodeGenModule , const FunctionDecl *FD);
+
+llvm::Type *convertTypeForMemory(CodeGenModule , QualType T);
+
 }  // end namespace CodeGen
 }  // end namespace clang
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35186: [analyzer] Add annotation for functions taking user-facing strings

2017-07-09 Thread Erik Verbruggen via Phabricator via cfe-commits
erikjv updated this revision to Diff 105792.
erikjv added a comment.

Sorry, now with more context in the diff.


https://reviews.llvm.org/D35186

Files:
  lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  test/Analysis/localization-aggressive.m

Index: test/Analysis/localization-aggressive.m
===
--- test/Analysis/localization-aggressive.m
+++ test/Analysis/localization-aggressive.m
@@ -61,8 +61,16 @@
 NSString *CFNumberFormatterCreateStringWithNumber(float x);
 + (NSString *)forceLocalized:(NSString *)str
 __attribute__((annotate("returns_localized_nsstring")));
++ (NSString *)takesLocalizedString:
+(NSString *)__attribute__((annotate("takes_localized_nsstring")))str;
 @end
 
+NSString *
+takesLocalizedString(NSString *str
+ __attribute__((annotate("takes_localized_nsstring" {
+  return str;
+}
+
 // Test cases begin here
 @implementation LocalizationTestSuite
 
@@ -75,6 +83,8 @@
   return str;
 }
 
++ (NSString *) takesLocalizedString:(NSString *)str { return str; }
+
 // An ObjC method that returns a localized string
 + (NSString *)unLocalizedStringMethod {
   return @"UnlocalizedString";
@@ -269,4 +279,13 @@
   NSString *string2 = POSSIBLE_FALSE_POSITIVE(@"Hello", @"Hello"); // no-warning
 }
 
+- (void)testTakesLocalizedString {
+  NSString *localized = NSLocalizedString(@"Hello", @"World");
+  NSString *alsoLocalized = [LocalizationTestSuite takesLocalizedString:localized]; // no-warning
+  NSString *stillLocalized = [LocalizationTestSuite takesLocalizedString:alsoLocalized]; // no-warning
+  takesLocalizedString(stillLocalized); // no-warning
+
+  [LocalizationTestSuite takesLocalizedString:@"not localized"]; // expected-warning {{User-facing text should use localized string macro}}
+  takesLocalizedString(@"not localized"); // expected-warning {{User-facing text should use localized string macro}}
+}
 @end
Index: lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
+++ lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
@@ -57,7 +57,7 @@
 };
 
 class NonLocalizedStringChecker
-: public Checker {
 
@@ -80,8 +80,9 @@
   void setLocalizedState(SVal S, CheckerContext ) const;
 
   bool isAnnotatedAsLocalized(const Decl *D) const;
-  void reportLocalizationError(SVal S, const ObjCMethodCall ,
-   CheckerContext , int argumentNumber = 0) const;
+  bool isAnnotatedTakingLocalized(const Decl *D) const;
+  void reportLocalizationError(SVal S, const CallEvent , CheckerContext ,
+   int argumentNumber = 0) const;
 
   int getLocalizedArgumentForSelector(const IdentifierInfo *Receiver,
   Selector S) const;
@@ -97,6 +98,7 @@
   void checkPreObjCMessage(const ObjCMethodCall , CheckerContext ) const;
   void checkPostObjCMessage(const ObjCMethodCall , CheckerContext ) const;
   void checkPostStmt(const ObjCStringLiteral *SL, CheckerContext ) const;
+  void checkPreCall(const CallEvent , CheckerContext ) const;
   void checkPostCall(const CallEvent , CheckerContext ) const;
 };
 
@@ -654,6 +656,18 @@
   });
 }
 
+/// Checks to see if the method / function declaration includes
+/// __attribute__((annotate("takes_localized_nsstring")))
+bool NonLocalizedStringChecker::isAnnotatedTakingLocalized(const Decl *D) const {
+  if (!D)
+return false;
+  return std::any_of(
+  D->specific_attr_begin(),
+  D->specific_attr_end(), [](const AnnotateAttr *Ann) {
+return Ann->getAnnotation() == "takes_localized_nsstring";
+  });
+}
+
 /// Returns true if the given SVal is marked as Localized in the program state
 bool NonLocalizedStringChecker::hasLocalizedState(SVal S,
   CheckerContext ) const {
@@ -733,8 +747,7 @@
 
 /// Reports a localization error for the passed in method call and SVal
 void NonLocalizedStringChecker::reportLocalizationError(
-SVal S, const ObjCMethodCall , CheckerContext ,
-int argumentNumber) const {
+SVal S, const CallEvent , CheckerContext , int argumentNumber) const {
 
   // Don't warn about localization errors in classes and methods that
   // may be debug code.
@@ -832,7 +845,21 @@
 }
   }
 
-  if (argumentNumber < 0) // There was no match in UIMethods
+  if (argumentNumber < 0) { // There was no match in UIMethods
+if (const Decl *D = msg.getDecl()) {
+  if (const ObjCMethodDecl *OMD = dyn_cast_or_null(D)) {
+auto formals = OMD->parameters();
+for (unsigned i = 0, ei = formals.size(); i != ei; ++i) {
+  if (isAnnotatedTakingLocalized(formals[i])) {
+

[PATCH] D35186: [analyzer] Add annotation for functions taking user-facing strings

2017-07-09 Thread Erik Verbruggen via Phabricator via cfe-commits
erikjv created this revision.
Herald added a subscriber: xazax.hun.

There was already a returns_localized_nsstring annotation to indicate
that the return value could be passed to UIKit methods that would
display them. However, those UIKit methods were hard-coded, and it was
not possible to indicate that other classes/methods in a code-base would
do the same.

The takes_localized_nsstring annotation can be put on function
parameters and selector parameters to indicate that those will also show
the string to the user.


https://reviews.llvm.org/D35186

Files:
  lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  test/Analysis/localization-aggressive.m

Index: test/Analysis/localization-aggressive.m
===
--- test/Analysis/localization-aggressive.m
+++ test/Analysis/localization-aggressive.m
@@ -61,8 +61,16 @@
 NSString *CFNumberFormatterCreateStringWithNumber(float x);
 + (NSString *)forceLocalized:(NSString *)str
 __attribute__((annotate("returns_localized_nsstring")));
++ (NSString *)takesLocalizedString:
+(NSString *)__attribute__((annotate("takes_localized_nsstring")))str;
 @end
 
+NSString *
+takesLocalizedString(NSString *str
+ __attribute__((annotate("takes_localized_nsstring" {
+  return str;
+}
+
 // Test cases begin here
 @implementation LocalizationTestSuite
 
@@ -75,6 +83,8 @@
   return str;
 }
 
++ (NSString *) takesLocalizedString:(NSString *)str { return str; }
+
 // An ObjC method that returns a localized string
 + (NSString *)unLocalizedStringMethod {
   return @"UnlocalizedString";
@@ -269,4 +279,13 @@
   NSString *string2 = POSSIBLE_FALSE_POSITIVE(@"Hello", @"Hello"); // no-warning
 }
 
+- (void)testTakesLocalizedString {
+  NSString *localized = NSLocalizedString(@"Hello", @"World");
+  NSString *alsoLocalized = [LocalizationTestSuite takesLocalizedString:localized]; // no-warning
+  NSString *stillLocalized = [LocalizationTestSuite takesLocalizedString:alsoLocalized]; // no-warning
+  takesLocalizedString(stillLocalized); // no-warning
+
+  [LocalizationTestSuite takesLocalizedString:@"not localized"]; // expected-warning {{User-facing text should use localized string macro}}
+  takesLocalizedString(@"not localized"); // expected-warning {{User-facing text should use localized string macro}}
+}
 @end
Index: lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
+++ lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
@@ -57,7 +57,7 @@
 };
 
 class NonLocalizedStringChecker
-: public Checker {
 
@@ -80,8 +80,9 @@
   void setLocalizedState(SVal S, CheckerContext ) const;
 
   bool isAnnotatedAsLocalized(const Decl *D) const;
-  void reportLocalizationError(SVal S, const ObjCMethodCall ,
-   CheckerContext , int argumentNumber = 0) const;
+  bool isAnnotatedTakingLocalized(const Decl *D) const;
+  void reportLocalizationError(SVal S, const CallEvent , CheckerContext ,
+   int argumentNumber = 0) const;
 
   int getLocalizedArgumentForSelector(const IdentifierInfo *Receiver,
   Selector S) const;
@@ -97,6 +98,7 @@
   void checkPreObjCMessage(const ObjCMethodCall , CheckerContext ) const;
   void checkPostObjCMessage(const ObjCMethodCall , CheckerContext ) const;
   void checkPostStmt(const ObjCStringLiteral *SL, CheckerContext ) const;
+  void checkPreCall(const CallEvent , CheckerContext ) const;
   void checkPostCall(const CallEvent , CheckerContext ) const;
 };
 
@@ -654,6 +656,18 @@
   });
 }
 
+/// Checks to see if the method / function declaration includes
+/// __attribute__((annotate("takes_localized_nsstring")))
+bool NonLocalizedStringChecker::isAnnotatedTakingLocalized(const Decl *D) const {
+  if (!D)
+return false;
+  return std::any_of(
+  D->specific_attr_begin(),
+  D->specific_attr_end(), [](const AnnotateAttr *Ann) {
+return Ann->getAnnotation() == "takes_localized_nsstring";
+  });
+}
+
 /// Returns true if the given SVal is marked as Localized in the program state
 bool NonLocalizedStringChecker::hasLocalizedState(SVal S,
   CheckerContext ) const {
@@ -733,8 +747,7 @@
 
 /// Reports a localization error for the passed in method call and SVal
 void NonLocalizedStringChecker::reportLocalizationError(
-SVal S, const ObjCMethodCall , CheckerContext ,
-int argumentNumber) const {
+SVal S, const CallEvent , CheckerContext , int argumentNumber) const {
 
   // Don't warn about localization errors in classes and methods that
   // may be debug code.
@@ -832,7 +845,21 @@
 }
   }
 
-  

[PATCH] D35184: X86 Intrinsics: _bit_scan_forward should not be under #ifdef __RDRND__

2017-07-09 Thread Zvi Rackover via Phabricator via cfe-commits
zvi updated this revision to Diff 105788.
zvi added a comment.

rdrand64_step should be under the ifdef


https://reviews.llvm.org/D35184

Files:
  lib/Headers/immintrin.h
  test/CodeGen/bitscan-builtins.c


Index: test/CodeGen/bitscan-builtins.c
===
--- test/CodeGen/bitscan-builtins.c
+++ test/CodeGen/bitscan-builtins.c
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -o 
- %s | FileCheck %s
 
+// PR33722
+// RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -D_MSC_VER 
-emit-llvm -o - %s | FileCheck %s
+
 #include 
 
 int test_bit_scan_forward(int a) {
Index: lib/Headers/immintrin.h
===
--- lib/Headers/immintrin.h
+++ lib/Headers/immintrin.h
@@ -212,6 +212,15 @@
   return __builtin_ia32_rdrand32_step(__p);
 }
 
+#ifdef __x86_64__
+static __inline__ int __attribute__((__always_inline__, __nodebug__, 
__target__("rdrnd")))
+_rdrand64_step(unsigned long long *__p)
+{
+  return __builtin_ia32_rdrand64_step(__p);
+}
+#endif
+#endif /* __RDRND__ */
+
 /* __bit_scan_forward */
 static __inline__ int __attribute__((__always_inline__, __nodebug__))
 _bit_scan_forward(int __A) {
@@ -224,15 +233,6 @@
   return 31 - __builtin_clz(__A);
 }
 
-#ifdef __x86_64__
-static __inline__ int __attribute__((__always_inline__, __nodebug__, 
__target__("rdrnd")))
-_rdrand64_step(unsigned long long *__p)
-{
-  return __builtin_ia32_rdrand64_step(__p);
-}
-#endif
-#endif /* __RDRND__ */
-
 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__FSGSBASE__)
 #ifdef __x86_64__
 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, 
__target__("fsgsbase")))


Index: test/CodeGen/bitscan-builtins.c
===
--- test/CodeGen/bitscan-builtins.c
+++ test/CodeGen/bitscan-builtins.c
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
 
+// PR33722
+// RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -D_MSC_VER -emit-llvm -o - %s | FileCheck %s
+
 #include 
 
 int test_bit_scan_forward(int a) {
Index: lib/Headers/immintrin.h
===
--- lib/Headers/immintrin.h
+++ lib/Headers/immintrin.h
@@ -212,6 +212,15 @@
   return __builtin_ia32_rdrand32_step(__p);
 }
 
+#ifdef __x86_64__
+static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd")))
+_rdrand64_step(unsigned long long *__p)
+{
+  return __builtin_ia32_rdrand64_step(__p);
+}
+#endif
+#endif /* __RDRND__ */
+
 /* __bit_scan_forward */
 static __inline__ int __attribute__((__always_inline__, __nodebug__))
 _bit_scan_forward(int __A) {
@@ -224,15 +233,6 @@
   return 31 - __builtin_clz(__A);
 }
 
-#ifdef __x86_64__
-static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd")))
-_rdrand64_step(unsigned long long *__p)
-{
-  return __builtin_ia32_rdrand64_step(__p);
-}
-#endif
-#endif /* __RDRND__ */
-
 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__FSGSBASE__)
 #ifdef __x86_64__
 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("fsgsbase")))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35184: X86 Intrinsics: _bit_scan_forward should not be under #ifdef __RDRND__

2017-07-09 Thread Zvi Rackover via Phabricator via cfe-commits
zvi added inline comments.



Comment at: lib/Headers/immintrin.h:230
 static __inline__ int __attribute__((__always_inline__, __nodebug__, 
__target__("rdrnd")))
 _rdrand64_step(unsigned long long *__p)
 {

craig.topper wrote:
> Looks like we now aren't removing rdrand64_step. Should we put the rdrand 
> functions together and not have bit_scan between them?
Right! Thanks for pointing that out.


https://reviews.llvm.org/D35184



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


[PATCH] D35180: Expose the Clang::QualType to llvm::Type conversion functions

2017-07-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Exposing these operations seems fine, but I'm not thrilled about the APIs.  Of 
course, the APIs are exactly derived from IRGen's internal APIs, but we'd like 
to eventually clean those APIs up, and we certainly don't need to emulate them.




Comment at: include/clang/CodeGen/CodeGenABITypes.h:74
 
+llvm::Type *ConvertType(CodeGenModule , QualType T);
+

Is this one actually important to expose?  What sorts of future APIs are you 
expecting where clients will interact with IRGen other than in memory?

If we do need this, we should name it something clear so that people don't 
accidentally reach for it by default.  (This has actually been a pain point 
within IRGen for years.)  How about:

llvm;:Type *convertTypeForRValue(CodeGenModule , QualType type);



Comment at: include/clang/CodeGen/CodeGenABITypes.h:78
+QualType FT,
+const FunctionDecl *FD = nullptr);
+

Let's make this a specific API for getting the type of a function declaration.

llvm::FunctionType *convertFreeFunctionType(CodeGenModule , const 
FunctionDecl *FD);



Comment at: include/clang/CodeGen/CodeGenABITypes.h:80
+
+llvm::Type *ConvertTypeForMem(CodeGenModule , QualType T);
+

llvm::Type *convertTypeForMemory(CodeGenModule , QualType type);


https://reviews.llvm.org/D35180



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


[PATCH] D34992: Emit static constexpr member as available_externally definition

2017-07-09 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini updated this revision to Diff 105787.
mehdi_amini added a comment.

Fix issues around mutable fields and regression on "internal", add more testing.


https://reviews.llvm.org/D34992

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/cxx11-extern-constexpr.cpp

Index: clang/test/CodeGenCXX/cxx11-extern-constexpr.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx11-extern-constexpr.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -std=c++11 %s -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefix=CHECK --check-prefix=CXX11
+// RUN: %clang_cc1 -std=c++1z %s -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefix=CHECK --check-prefix=CXX17
+
+struct Bar {
+  int b;
+};
+
+struct MutableBar {
+  mutable int b;
+};
+
+struct Foo {
+  // CXX11: @_ZN3Foo21ConstexprStaticMemberE = available_externally constant i32 42,
+  // CXX17: @_ZN3Foo21ConstexprStaticMemberE = linkonce_odr constant i32 42,
+  static constexpr int ConstexprStaticMember = 42;
+  // CHECK: @_ZN3Foo17ConstStaticMemberE = available_externally constant i32 43,
+  static const int ConstStaticMember = 43;
+
+  // CXX11: @_ZN3Foo23ConstStaticStructMemberE = available_externally constant %struct.Bar { i32 44 },
+  // CXX17: @_ZN3Foo23ConstStaticStructMemberE = linkonce_odr constant %struct.Bar { i32 44 },
+  static constexpr Bar ConstStaticStructMember = {44};
+
+  // CXX11: @_ZN3Foo34ConstexprStaticMutableStructMemberE = external global %struct.MutableBar,
+  // CXX17: @_ZN3Foo34ConstexprStaticMutableStructMemberE = linkonce_odr global %struct.MutableBar { i32 45 },
+  static constexpr MutableBar ConstexprStaticMutableStructMember = {45};
+};
+// CHECK: @_ZL15ConstStaticexpr = internal constant i32 46,
+static constexpr int ConstStaticexpr = 46;
+// CHECK: @_ZL9ConstExpr = internal constant i32 46, align 4
+static const int ConstExpr = 46;
+
+// CHECK: @_ZL21ConstexprStaticStruct = internal constant %struct.Bar { i32 47 },
+static constexpr Bar ConstexprStaticStruct = {47};
+
+// CHECK: @_ZL28ConstexprStaticMutableStruct = internal global %struct.MutableBar { i32 48 },
+static constexpr MutableBar ConstexprStaticMutableStruct = {48};
+
+void use(const int &);
+void foo() {
+  use(Foo::ConstexprStaticMember);
+  use(Foo::ConstStaticMember);
+  use(Foo::ConstStaticStructMember.b);
+  use(Foo::ConstexprStaticMutableStructMember.b);
+  use(ConstStaticexpr);
+  use(ConstExpr);
+  use(ConstexprStaticStruct.b);
+  use(ConstexprStaticMutableStruct.b);
+}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2290,17 +2290,17 @@
 /// as a constant.
 ///
 /// If ExcludeCtor is true, the duration when the object's constructor runs
-/// will not be considered. The caller will need to verify that the object is
-/// not written to during its construction.
+/// will not be considered (unless trivial). The caller will need to verify that
+/// the object is not written to during its construction.
 bool CodeGenModule::isTypeConstant(QualType Ty, bool ExcludeCtor) {
   if (!Ty.isConstant(Context) && !Ty->isReferenceType())
 return false;
 
   if (Context.getLangOpts().CPlusPlus) {
-if (const CXXRecordDecl *Record
-  = Context.getBaseElementType(Ty)->getAsCXXRecordDecl())
-  return ExcludeCtor && !Record->hasMutableFields() &&
- Record->hasTrivialDestructor();
+if (const CXXRecordDecl *Record =
+Context.getBaseElementType(Ty)->getAsCXXRecordDecl())
+  return (ExcludeCtor || Record->hasTrivialDefaultConstructor()) &&
+ !Record->hasMutableFields() && Record->hasTrivialDestructor();
   }
 
   return true;
@@ -2372,7 +2372,7 @@
 
   auto *GV = new llvm::GlobalVariable(
   getModule(), Ty->getElementType(), false,
-  llvm::GlobalValue::ExternalLinkage, nullptr, MangledName, nullptr,
+  llvm::GlobalVariable::ExternalLinkage, nullptr, MangledName, nullptr,
   llvm::GlobalVariable::NotThreadLocal, TargetAddrSpace);
 
   // If we already created a global with the same mangled name (but different
@@ -2428,6 +2428,29 @@
 D->getType().isConstant(Context) &&
 isExternallyVisible(D->getLinkageAndVisibility().getLinkage()))
   GV->setSection(".cp.rodata");
+
+// Check if we a have a const declaration with an initializer, we may be
+// able to emit it as available_externally to expose it's value to the
+// optimizer.
+if (GV->hasExternalLinkage() && GV->isConstant() && !GV->hasInitializer() &&
+!D->hasDefinition() && D->hasInit()) {
+  bool HasMutableField = false;
+  if (Context.getLangOpts().CPlusPlus) {
+if (const CXXRecordDecl *Record =
+Context.getBaseElementType(D->getType())->getAsCXXRecordDecl())
+  HasMutableField = Record->hasMutableFields();
+  }
+
+  

[PATCH] D35184: X86 Intrinsics: _bit_scan_forward should not be under #ifdef __RDRND__

2017-07-09 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: lib/Headers/immintrin.h:230
 static __inline__ int __attribute__((__always_inline__, __nodebug__, 
__target__("rdrnd")))
 _rdrand64_step(unsigned long long *__p)
 {

Looks like we now aren't removing rdrand64_step. Should we put the rdrand 
functions together and not have bit_scan between them?


https://reviews.llvm.org/D35184



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


[PATCH] D35184: X86 Intrinsics: _bit_scan_forward should not be under #ifdef __RDRND__

2017-07-09 Thread Zvi Rackover via Phabricator via cfe-commits
zvi created this revision.

The _bit_scan_forward and _bit_scan_reverse intrinsics were accidentally
masked under the preprocessor checks that prune intrinsics definitions for the
benefit of faster compile-time on Windows. This patch moves the
definitons out of that region.

Fixes pr33722


https://reviews.llvm.org/D35184

Files:
  lib/Headers/immintrin.h
  test/CodeGen/bitscan-builtins.c


Index: test/CodeGen/bitscan-builtins.c
===
--- test/CodeGen/bitscan-builtins.c
+++ test/CodeGen/bitscan-builtins.c
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -o 
- %s | FileCheck %s
 
+// PR33722
+// RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -D_MSC_VER 
-emit-llvm -o - %s | FileCheck %s
+
 #include 
 
 int test_bit_scan_forward(int a) {
Index: lib/Headers/immintrin.h
===
--- lib/Headers/immintrin.h
+++ lib/Headers/immintrin.h
@@ -211,6 +211,7 @@
 {
   return __builtin_ia32_rdrand32_step(__p);
 }
+#endif /* __RDRND__ */
 
 /* __bit_scan_forward */
 static __inline__ int __attribute__((__always_inline__, __nodebug__))
@@ -231,7 +232,6 @@
   return __builtin_ia32_rdrand64_step(__p);
 }
 #endif
-#endif /* __RDRND__ */
 
 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__FSGSBASE__)
 #ifdef __x86_64__


Index: test/CodeGen/bitscan-builtins.c
===
--- test/CodeGen/bitscan-builtins.c
+++ test/CodeGen/bitscan-builtins.c
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
 
+// PR33722
+// RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -D_MSC_VER -emit-llvm -o - %s | FileCheck %s
+
 #include 
 
 int test_bit_scan_forward(int a) {
Index: lib/Headers/immintrin.h
===
--- lib/Headers/immintrin.h
+++ lib/Headers/immintrin.h
@@ -211,6 +211,7 @@
 {
   return __builtin_ia32_rdrand32_step(__p);
 }
+#endif /* __RDRND__ */
 
 /* __bit_scan_forward */
 static __inline__ int __attribute__((__always_inline__, __nodebug__))
@@ -231,7 +232,6 @@
   return __builtin_ia32_rdrand64_step(__p);
 }
 #endif
-#endif /* __RDRND__ */
 
 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__FSGSBASE__)
 #ifdef __x86_64__
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35082: [OpenCL] Add LangAS::opencl_private to represent private address space in AST

2017-07-09 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 105785.
yaxunl added a comment.

Treat (void*)0 as null pointer for OpenCL 1.2. Rebase to ToT.


https://reviews.llvm.org/D35082

Files:
  include/clang/Basic/AddressSpaces.h
  lib/AST/ASTContext.cpp
  lib/AST/Expr.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGDecl.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/address-spaces-mangling.cl
  test/Index/opencl-types.cl
  test/Parser/opencl-astype.cl
  test/Parser/opencl-atomics-cl20.cl
  test/SemaOpenCL/access-qualifier.cl
  test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
  test/SemaOpenCL/address-spaces.cl
  test/SemaOpenCL/arithmetic-conversions.cl
  test/SemaOpenCL/as_type.cl
  test/SemaOpenCL/cl20-device-side-enqueue.cl
  test/SemaOpenCL/event_t.cl
  test/SemaOpenCL/extension-begin.cl
  test/SemaOpenCL/half.cl
  test/SemaOpenCL/images.cl
  test/SemaOpenCL/invalid-block.cl
  test/SemaOpenCL/invalid-image.cl
  test/SemaOpenCL/invalid-kernel-parameters.cl
  test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
  test/SemaOpenCL/invalid-pipes-cl2.0.cl
  test/SemaOpenCL/null_literal.cl
  test/SemaOpenCL/null_queue.cl
  test/SemaOpenCL/queue_t_overload.cl
  test/SemaOpenCL/sampler_t.cl
  test/SemaOpenCL/shifts.cl
  test/SemaOpenCL/to_addr_builtin.cl
  test/SemaOpenCL/vec_step.cl
  test/SemaOpenCL/vector_conv_invalid.cl

Index: test/SemaOpenCL/vector_conv_invalid.cl
===
--- test/SemaOpenCL/vector_conv_invalid.cl
+++ test/SemaOpenCL/vector_conv_invalid.cl
@@ -7,7 +7,7 @@
 
 void vector_conv_invalid() {
   uint4 u = (uint4)(1);
-  int4 i = u; // expected-error{{initializing 'int4' (vector of 4 'int' values) with an expression of incompatible type 'uint4' (vector of 4 'unsigned int' values)}}
+  int4 i = u; // expected-error{{initializing '__private int4' (vector of 4 'int' values) with an expression of incompatible type '__private uint4' (vector of 4 'unsigned int' values)}}
   int4 e = (int4)u; // expected-error{{invalid conversion between ext-vector type 'int4' (vector of 4 'int' values) and 'uint4' (vector of 4 'unsigned int' values)}}
 
   uint3 u4 = (uint3)u; // expected-error{{invalid conversion between ext-vector type 'uint3' (vector of 3 'unsigned int' values) and 'uint4' (vector of 4 'unsigned int' values)}}
Index: test/SemaOpenCL/vec_step.cl
===
--- test/SemaOpenCL/vec_step.cl
+++ test/SemaOpenCL/vec_step.cl
@@ -26,7 +26,7 @@
   int res11[vec_step(int16) == 16 ? 1 : -1];
   int res12[vec_step(void) == 1 ? 1 : -1];
 
-  int res13 = vec_step(*incomplete1); // expected-error {{'vec_step' requires built-in scalar or vector type, 'struct S' invalid}}
-  int res14 = vec_step(int16*); // expected-error {{'vec_step' requires built-in scalar or vector type, 'int16 *' invalid}}
+  int res13 = vec_step(*incomplete1); // expected-error {{'vec_step' requires built-in scalar or vector type, '__private struct S' invalid}}
+  int res14 = vec_step(int16 *); // expected-error {{'vec_step' requires built-in scalar or vector type, '__private int16 *' invalid}}
   int res15 = vec_step(void(void)); // expected-error {{'vec_step' requires built-in scalar or vector type, 'void (void)' invalid}}
 }
Index: test/SemaOpenCL/to_addr_builtin.cl
===
--- test/SemaOpenCL/to_addr_builtin.cl
+++ test/SemaOpenCL/to_addr_builtin.cl
@@ -11,45 +11,45 @@
   glob = to_global(glob, loc);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
   // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
-  // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
+  // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-5{{invalid number of arguments to function: 'to_global'}}
 #endif
 
   int x;
   glob = to_global(x);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
-  // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
+  // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
-  // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
+  // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con_typedef);
 #if __OPENCL_C_VERSION__ < 

r307506 - [X86] Add __get_cpuid_count to cpuid.h. Update __get_cpuid to check the maximum level support before accessing the leaf. Rename level to leaf everywhere.

2017-07-09 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Sun Jul  9 10:43:10 2017
New Revision: 307506

URL: http://llvm.org/viewvc/llvm-project?rev=307506=rev
Log:
[X86] Add __get_cpuid_count to cpuid.h. Update __get_cpuid to check the maximum 
level support before accessing the leaf. Rename level to leaf everywhere.

This matches gcc behavior.

Modified:
cfe/trunk/lib/Headers/cpuid.h

Modified: cfe/trunk/lib/Headers/cpuid.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/cpuid.h?rev=307506=307505=307506=diff
==
--- cfe/trunk/lib/Headers/cpuid.h (original)
+++ cfe/trunk/lib/Headers/cpuid.h Sun Jul  9 10:43:10 2017
@@ -153,38 +153,31 @@
 #define bit_ENH_MOVSB   0x0200
 
 #if __i386__
-#define __cpuid(__level, __eax, __ebx, __ecx, __edx) \
+#define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \
 __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \
-  : "0"(__level))
+  : "0"(__leaf))
 
-#define __cpuid_count(__level, __count, __eax, __ebx, __ecx, __edx) \
+#define __cpuid_count(__leaf, __count, __eax, __ebx, __ecx, __edx) \
 __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \
-  : "0"(__level), "2"(__count))
+  : "0"(__leaf), "2"(__count))
 #else
 /* x86-64 uses %rbx as the base register, so preserve it. */
-#define __cpuid(__level, __eax, __ebx, __ecx, __edx) \
+#define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \
 __asm("  xchgq  %%rbx,%q1\n" \
   "  cpuid\n" \
   "  xchgq  %%rbx,%q1" \
 : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
-: "0"(__level))
+: "0"(__leaf))
 
-#define __cpuid_count(__level, __count, __eax, __ebx, __ecx, __edx) \
+#define __cpuid_count(__leaf, __count, __eax, __ebx, __ecx, __edx) \
 __asm("  xchgq  %%rbx,%q1\n" \
   "  cpuid\n" \
   "  xchgq  %%rbx,%q1" \
 : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
-: "0"(__level), "2"(__count))
+: "0"(__leaf), "2"(__count))
 #endif
 
-static __inline int __get_cpuid (unsigned int __level, unsigned int *__eax,
- unsigned int *__ebx, unsigned int *__ecx,
- unsigned int *__edx) {
-__cpuid(__level, *__eax, *__ebx, *__ecx, *__edx);
-return 1;
-}
-
-static __inline int __get_cpuid_max (unsigned int __level, unsigned int *__sig)
+static __inline int __get_cpuid_max (unsigned int __leaf, unsigned int *__sig)
 {
 unsigned int __eax, __ebx, __ecx, __edx;
 #if __i386__
@@ -208,8 +201,35 @@ static __inline int __get_cpuid_max (uns
 return 0;
 #endif
 
-__cpuid(__level, __eax, __ebx, __ecx, __edx);
+__cpuid(__leaf, __eax, __ebx, __ecx, __edx);
 if (__sig)
 *__sig = __ebx;
 return __eax;
 }
+
+static __inline int __get_cpuid (unsigned int __leaf, unsigned int *__eax,
+ unsigned int *__ebx, unsigned int *__ecx,
+ unsigned int *__edx)
+{
+unsigned int __max_leaf = __get_cpuid_max(__leaf & 0x8000, 0);
+
+if (__max_leaf == 0 || __max_leaf < __leaf)
+return 0;
+
+__cpuid(__leaf, *__eax, *__ebx, *__ecx, *__edx);
+return 1;
+}
+
+static __inline int __get_cpuid_count (unsigned int __leaf,
+   unsigned int __subleaf,
+   unsigned int *__eax, unsigned int 
*__ebx,
+   unsigned int *__ecx, unsigned int 
*__edx)
+{
+unsigned int __max_leaf = __get_cpuid_max(__leaf & 0x8000, 0);
+
+if (__max_leaf == 0 || __max_leaf < __leaf)
+return 0;
+
+__cpuid_count(__leaf, __subleaf, *__eax, *__ebx, *__ecx, *__edx);
+return 1;
+}


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


r307507 - [X86] Add more feature flag bit defines to cpuid.h for gcc compatibility.

2017-07-09 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Sun Jul  9 10:43:11 2017
New Revision: 307507

URL: http://llvm.org/viewvc/llvm-project?rev=307507=rev
Log:
[X86] Add more feature flag bit defines to cpuid.h for gcc compatibility.

Modified:
cfe/trunk/lib/Headers/cpuid.h

Modified: cfe/trunk/lib/Headers/cpuid.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/cpuid.h?rev=307507=307506=307507=diff
==
--- cfe/trunk/lib/Headers/cpuid.h (original)
+++ cfe/trunk/lib/Headers/cpuid.h Sun Jul  9 10:43:11 2017
@@ -79,7 +79,7 @@
 #define signature_VORTEX_edx 0x36387865
 #define signature_VORTEX_ecx 0x436f5320
 
-/* Features in %ecx for level 1 */
+/* Features in %ecx for leaf 1 */
 #define bit_SSE30x0001
 #define bit_PCLMULQDQ   0x0002
 #define bit_PCLMUL  bit_PCLMULQDQ   /* for gcc compat */
@@ -114,7 +114,7 @@
 #define bit_F16C0x2000
 #define bit_RDRND   0x4000
 
-/* Features in %edx for level 1 */
+/* Features in %edx for leaf 1 */
 #define bit_FPU 0x0001
 #define bit_VME 0x0002
 #define bit_DE  0x0004
@@ -147,10 +147,68 @@
 #define bit_TM  0x2000
 #define bit_PBE 0x8000
 
-/* Features in %ebx for level 7 sub-leaf 0 */
+/* Features in %ebx for leaf 7 sub-leaf 0 */
 #define bit_FSGSBASE0x0001
+#define bit_SGX 0x0004
+#define bit_BMI 0x0008
+#define bit_HLE 0x0010
+#define bit_AVX20x0020
 #define bit_SMEP0x0080
+#define bit_BMI20x0100
 #define bit_ENH_MOVSB   0x0200
+#define bit_RTM 0x0800
+#define bit_MPX 0x4000
+#define bit_AVX512F 0x0001
+#define bit_AVX512DQ0x0002
+#define bit_RDSEED  0x0004
+#define bit_ADX 0x0008
+#define bit_AVX512IFMA  0x0020
+#define bit_CLFLUSHOPT  0x0080
+#define bit_CLWB0x0100
+#define bit_AVX512PF0x0400
+#define bit_AVX51SER0x0800
+#define bit_AVX512CD0x1000
+#define bit_SHA 0x2000
+#define bit_AVX512BW0x4000
+#define bit_AVX512VL0x8000
+
+/* Features in %ecx for leaf 7 sub-leaf 0 */
+#define bit_PREFTCHWT1  0x0001
+#define bit_AVX512VBMI  0x0002
+#define bit_PKU 0x0004
+#define bit_OSPKE   0x0010
+#define bit_AVX512VPOPCNTDQ  0x4000
+#define bit_RDPID   0x0040
+
+/* Features in %edx for leaf 7 sub-leaf 0 */
+#define bit_AVX5124VNNIW  0x0004
+#define bit_AVX5124FMAPS  0x0008
+
+/* Features in %eax for leaf 13 sub-leaf 1 */
+#define bit_XSAVEOPT0x0001
+#define bit_XSAVEC  0x0002
+#define bit_XSAVES  0x0008
+
+/* Features in %ecx for leaf 0x8001 */
+#define bit_LAHF_LM 0x0001
+#define bit_ABM 0x0020
+#define bit_SSE4a   0x0040
+#define bit_PRFCHW  0x0100
+#define bit_XOP 0x0800
+#define bit_LWP 0x8000
+#define bit_FMA40x0001
+#define bit_TBM 0x0020
+#define bit_MWAITX  0x2000
+
+/* Features in %edx for leaf 0x8001 */
+#define bit_MMXEXT  0x0040
+#define bit_LM  0x2000
+#define bit_3DNOWP  0x4000
+#define bit_3DNOW   0x8000
+
+/* Features in %ebx for leaf 0x8001 */
+#define bit_CLZERO  0x0001
+
 
 #if __i386__
 #define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \


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


[libcxx] r307505 - optional: Implement LWG 2900 and P0602

2017-07-09 Thread Casey Carter via cfe-commits
Author: caseycarter
Date: Sun Jul  9 10:15:49 2017
New Revision: 307505

URL: http://llvm.org/viewvc/llvm-project?rev=307505=rev
Log:
optional: Implement LWG 2900 and P0602

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

Removed:

libcxx/trunk/test/libcxx/utilities/optional/optional.object/special_member_gen.pass.cpp
Modified:
libcxx/trunk/include/optional

libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.assign/move.pass.cpp

libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp

libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp

libcxx/trunk/test/std/utilities/optional/optional.object/special_member_gen.pass.cpp

Modified: libcxx/trunk/include/optional
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/optional?rev=307505=307504=307505=diff
==
--- libcxx/trunk/include/optional (original)
+++ libcxx/trunk/include/optional Sun Jul  9 10:15:49 2017
@@ -439,46 +439,122 @@ struct __optional_storage_base<_Tp, true
 }
 };
 
-template ::value>
-struct __optional_storage;
-
-template 
-struct __optional_storage<_Tp, true> : __optional_storage_base<_Tp>
+template ::value>
+struct __optional_copy_base : __optional_storage_base<_Tp>
 {
 using __optional_storage_base<_Tp>::__optional_storage_base;
 };
 
 template 
-struct __optional_storage<_Tp, false> : __optional_storage_base<_Tp>
+struct __optional_copy_base<_Tp, false> : __optional_storage_base<_Tp>
 {
-using value_type = _Tp;
 using __optional_storage_base<_Tp>::__optional_storage_base;
 
 _LIBCPP_INLINE_VISIBILITY
-__optional_storage() = default;
+__optional_copy_base() = default;
 
 _LIBCPP_INLINE_VISIBILITY
-__optional_storage(const __optional_storage& __opt)
+__optional_copy_base(const __optional_copy_base& __opt)
 {
 this->__construct_from(__opt);
 }
 
 _LIBCPP_INLINE_VISIBILITY
-__optional_storage(__optional_storage&& __opt)
+__optional_copy_base(__optional_copy_base&&) = default;
+_LIBCPP_INLINE_VISIBILITY
+__optional_copy_base& operator=(const __optional_copy_base&) = default;
+_LIBCPP_INLINE_VISIBILITY
+__optional_copy_base& operator=(__optional_copy_base&&) = default;
+};
+
+template ::value>
+struct __optional_move_base : __optional_copy_base<_Tp>
+{
+using __optional_copy_base<_Tp>::__optional_copy_base;
+};
+
+template 
+struct __optional_move_base<_Tp, false> : __optional_copy_base<_Tp>
+{
+using value_type = _Tp;
+using __optional_copy_base<_Tp>::__optional_copy_base;
+
+_LIBCPP_INLINE_VISIBILITY
+__optional_move_base() = default;
+_LIBCPP_INLINE_VISIBILITY
+__optional_move_base(const __optional_move_base&) = default;
+
+_LIBCPP_INLINE_VISIBILITY
+__optional_move_base(__optional_move_base&& __opt)
 noexcept(is_nothrow_move_constructible_v)
 {
 this->__construct_from(_VSTD::move(__opt));
 }
 
 _LIBCPP_INLINE_VISIBILITY
-__optional_storage& operator=(const __optional_storage& __opt)
+__optional_move_base& operator=(const __optional_move_base&) = default;
+_LIBCPP_INLINE_VISIBILITY
+__optional_move_base& operator=(__optional_move_base&&) = default;
+};
+
+template ::value &&
+is_trivially_copy_constructible<_Tp>::value &&
+is_trivially_copy_assignable<_Tp>::value>
+struct __optional_copy_assign_base : __optional_move_base<_Tp>
+{
+using __optional_move_base<_Tp>::__optional_move_base;
+};
+
+template 
+struct __optional_copy_assign_base<_Tp, false> : __optional_move_base<_Tp>
+{
+using __optional_move_base<_Tp>::__optional_move_base;
+
+_LIBCPP_INLINE_VISIBILITY
+__optional_copy_assign_base() = default;
+_LIBCPP_INLINE_VISIBILITY
+__optional_copy_assign_base(const __optional_copy_assign_base&) = default;
+_LIBCPP_INLINE_VISIBILITY
+__optional_copy_assign_base(__optional_copy_assign_base&&) = default;
+
+_LIBCPP_INLINE_VISIBILITY
+__optional_copy_assign_base& operator=(const __optional_copy_assign_base& 
__opt)
 {
 this->__assign_from(__opt);
 return *this;
 }
 
 _LIBCPP_INLINE_VISIBILITY
-__optional_storage& operator=(__optional_storage&& __opt)
+__optional_copy_assign_base& operator=(__optional_copy_assign_base&&) = 
default;
+};
+
+template ::value &&
+is_trivially_move_constructible<_Tp>::value &&
+is_trivially_move_assignable<_Tp>::value>
+struct __optional_move_assign_base : __optional_copy_assign_base<_Tp>
+{
+using __optional_copy_assign_base<_Tp>::__optional_copy_assign_base;
+};
+
+template 
+struct __optional_move_assign_base<_Tp, false> : 
__optional_copy_assign_base<_Tp>
+{
+using value_type = _Tp;
+using __optional_copy_assign_base<_Tp>::__optional_copy_assign_base;
+
+_LIBCPP_INLINE_VISIBILITY
+__optional_move_assign_base() = default;
+

[PATCH] D32385: [libcxx] optional: Implement LWG 2900 and P0602

2017-07-09 Thread Casey Carter via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307505: optional: Implement LWG 2900 and P0602 (authored by 
CaseyCarter).

Changed prior to commit:
  https://reviews.llvm.org/D32385?vs=101631=105784#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32385

Files:
  libcxx/trunk/include/optional
  
libcxx/trunk/test/libcxx/utilities/optional/optional.object/special_member_gen.pass.cpp
  
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.assign/move.pass.cpp
  
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
  
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
  
libcxx/trunk/test/std/utilities/optional/optional.object/special_member_gen.pass.cpp

Index: libcxx/trunk/include/optional
===
--- libcxx/trunk/include/optional
+++ libcxx/trunk/include/optional
@@ -439,46 +439,122 @@
 }
 };
 
-template ::value>
-struct __optional_storage;
-
-template 
-struct __optional_storage<_Tp, true> : __optional_storage_base<_Tp>
+template ::value>
+struct __optional_copy_base : __optional_storage_base<_Tp>
 {
 using __optional_storage_base<_Tp>::__optional_storage_base;
 };
 
 template 
-struct __optional_storage<_Tp, false> : __optional_storage_base<_Tp>
+struct __optional_copy_base<_Tp, false> : __optional_storage_base<_Tp>
 {
-using value_type = _Tp;
 using __optional_storage_base<_Tp>::__optional_storage_base;
 
 _LIBCPP_INLINE_VISIBILITY
-__optional_storage() = default;
+__optional_copy_base() = default;
 
 _LIBCPP_INLINE_VISIBILITY
-__optional_storage(const __optional_storage& __opt)
+__optional_copy_base(const __optional_copy_base& __opt)
 {
 this->__construct_from(__opt);
 }
 
 _LIBCPP_INLINE_VISIBILITY
-__optional_storage(__optional_storage&& __opt)
+__optional_copy_base(__optional_copy_base&&) = default;
+_LIBCPP_INLINE_VISIBILITY
+__optional_copy_base& operator=(const __optional_copy_base&) = default;
+_LIBCPP_INLINE_VISIBILITY
+__optional_copy_base& operator=(__optional_copy_base&&) = default;
+};
+
+template ::value>
+struct __optional_move_base : __optional_copy_base<_Tp>
+{
+using __optional_copy_base<_Tp>::__optional_copy_base;
+};
+
+template 
+struct __optional_move_base<_Tp, false> : __optional_copy_base<_Tp>
+{
+using value_type = _Tp;
+using __optional_copy_base<_Tp>::__optional_copy_base;
+
+_LIBCPP_INLINE_VISIBILITY
+__optional_move_base() = default;
+_LIBCPP_INLINE_VISIBILITY
+__optional_move_base(const __optional_move_base&) = default;
+
+_LIBCPP_INLINE_VISIBILITY
+__optional_move_base(__optional_move_base&& __opt)
 noexcept(is_nothrow_move_constructible_v)
 {
 this->__construct_from(_VSTD::move(__opt));
 }
 
 _LIBCPP_INLINE_VISIBILITY
-__optional_storage& operator=(const __optional_storage& __opt)
+__optional_move_base& operator=(const __optional_move_base&) = default;
+_LIBCPP_INLINE_VISIBILITY
+__optional_move_base& operator=(__optional_move_base&&) = default;
+};
+
+template ::value &&
+is_trivially_copy_constructible<_Tp>::value &&
+is_trivially_copy_assignable<_Tp>::value>
+struct __optional_copy_assign_base : __optional_move_base<_Tp>
+{
+using __optional_move_base<_Tp>::__optional_move_base;
+};
+
+template 
+struct __optional_copy_assign_base<_Tp, false> : __optional_move_base<_Tp>
+{
+using __optional_move_base<_Tp>::__optional_move_base;
+
+_LIBCPP_INLINE_VISIBILITY
+__optional_copy_assign_base() = default;
+_LIBCPP_INLINE_VISIBILITY
+__optional_copy_assign_base(const __optional_copy_assign_base&) = default;
+_LIBCPP_INLINE_VISIBILITY
+__optional_copy_assign_base(__optional_copy_assign_base&&) = default;
+
+_LIBCPP_INLINE_VISIBILITY
+__optional_copy_assign_base& operator=(const __optional_copy_assign_base& __opt)
 {
 this->__assign_from(__opt);
 return *this;
 }
 
 _LIBCPP_INLINE_VISIBILITY
-__optional_storage& operator=(__optional_storage&& __opt)
+__optional_copy_assign_base& operator=(__optional_copy_assign_base&&) = default;
+};
+
+template ::value &&
+is_trivially_move_constructible<_Tp>::value &&
+is_trivially_move_assignable<_Tp>::value>
+struct __optional_move_assign_base : __optional_copy_assign_base<_Tp>
+{
+using __optional_copy_assign_base<_Tp>::__optional_copy_assign_base;
+};
+
+template 
+struct __optional_move_assign_base<_Tp, false> : __optional_copy_assign_base<_Tp>
+{
+using value_type = _Tp;
+using __optional_copy_assign_base<_Tp>::__optional_copy_assign_base;
+
+_LIBCPP_INLINE_VISIBILITY
+__optional_move_assign_base() = default;
+_LIBCPP_INLINE_VISIBILITY
+__optional_move_assign_base(const __optional_move_assign_base& __opt) = default;
+_LIBCPP_INLINE_VISIBILITY
+

[PATCH] D34329: [clang-diff] Initial implementation.

2017-07-09 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

@johannes https://reviews.llvm.org/D34880 has landed, so feel free to propose 
patches to the StmtDataCollector API that would help you (e.g. to support 
identifiers). You can see examples how to use it in the CloneDetection.cpp 
(once for storing data in a FoldingetSetNodeID and once for directly hashing 
the data with MD5).


https://reviews.llvm.org/D34329



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


[PATCH] D35181: Defer addition of keywords to identifier table when loading AST

2017-07-09 Thread Johann Klähn via Phabricator via cfe-commits
jklaehn created this revision.

In `ASTUnit::LoadFromASTFile`, the preprocesor object is set up using
default-constructed `LangOptions` (which only later get populated).
Then, in the constructor of `IdentifierTable`, these default-constructed
`LangOptions` were used in the call to `AddKeywords`, leading to wrong
initialization of the identifier table.

This change defers adding the keywords to the identifier table until
after the language options have been loaded from the AST file.

Prior to this change the included test would fail due to the `class`
token being reported as an identifier (since the C++11 `enum class`
construct is not present when using the default language options).


https://reviews.llvm.org/D35181

Files:
  include/clang/Basic/IdentifierTable.h
  include/clang/Lex/Preprocessor.h
  lib/Basic/IdentifierTable.cpp
  lib/Frontend/ASTUnit.cpp
  lib/Lex/Preprocessor.cpp
  unittests/libclang/LibclangTest.cpp

Index: unittests/libclang/LibclangTest.cpp
===
--- unittests/libclang/LibclangTest.cpp
+++ unittests/libclang/LibclangTest.cpp
@@ -572,3 +572,67 @@
   EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU));
   DisplayDiagnostics();
 }
+
+class LibclangSerializationTest : public LibclangParseTest {
+public:
+  bool SaveAndLoadTU(const std::string ) {
+unsigned options = clang_defaultSaveOptions(ClangTU);
+if (clang_saveTranslationUnit(ClangTU, Filename.c_str(), options) !=
+CXSaveError_None) {
+  DEBUG(llvm::dbgs() << "Saving failed\n");
+  return false;
+}
+
+clang_disposeTranslationUnit(ClangTU);
+
+ClangTU = clang_createTranslationUnit(Index, Filename.c_str());
+
+if (!ClangTU) {
+  DEBUG(llvm::dbgs() << "Loading failed\n");
+  return false;
+}
+
+return true;
+  }
+};
+
+TEST_F(LibclangSerializationTest, TokenKindsAreCorrectAfterLoading) {
+  // Ensure that "class" is recognized as a keyword token after serializing
+  // and reloading the AST, as it is not a keyword for the default LangOptions.
+  std::string HeaderName = "test.h";
+  WriteFile(HeaderName, "enum class Something {};");
+
+  const char *Argv[] = {"-xc++-header", "-std=c++11"};
+
+  ClangTU = clang_parseTranslationUnit(Index, HeaderName.c_str(), Argv,
+   sizeof(Argv) / sizeof(Argv[0]), nullptr,
+   0, TUFlags);
+
+  auto CheckTokenKinds = [=]() {
+CXSourceRange Range =
+clang_getCursorExtent(clang_getTranslationUnitCursor(ClangTU));
+
+CXToken *Tokens;
+unsigned int NumTokens;
+clang_tokenize(ClangTU, Range, , );
+
+ASSERT_EQ(6u, NumTokens);
+EXPECT_EQ(CXToken_Keyword, clang_getTokenKind(Tokens[0]));
+EXPECT_EQ(CXToken_Keyword, clang_getTokenKind(Tokens[1]));
+EXPECT_EQ(CXToken_Identifier, clang_getTokenKind(Tokens[2]));
+EXPECT_EQ(CXToken_Punctuation, clang_getTokenKind(Tokens[3]));
+EXPECT_EQ(CXToken_Punctuation, clang_getTokenKind(Tokens[4]));
+EXPECT_EQ(CXToken_Punctuation, clang_getTokenKind(Tokens[5]));
+
+clang_disposeTokens(ClangTU, Tokens, NumTokens);
+  };
+
+  CheckTokenKinds();
+
+  std::string ASTName = "test.ast";
+  WriteFile(ASTName, "");
+
+  ASSERT_TRUE(SaveAndLoadTU(ASTName));
+
+  CheckTokenKinds();
+}
Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -73,12 +73,14 @@
SourceManager , MemoryBufferCache ,
HeaderSearch , ModuleLoader ,
IdentifierInfoLookup *IILookup, bool OwnsHeaders,
-   TranslationUnitKind TUKind)
+   TranslationUnitKind TUKind,
+   bool DeferKeywordAddition)
 : PPOpts(std::move(PPOpts)), Diags(), LangOpts(opts), Target(nullptr),
   AuxTarget(nullptr), FileMgr(Headers.getFileMgr()), SourceMgr(SM),
   PCMCache(PCMCache), ScratchBuf(new ScratchBuffer(SourceMgr)),
   HeaderInfo(Headers), TheModuleLoader(TheModuleLoader),
-  ExternalSource(nullptr), Identifiers(opts, IILookup),
+  ExternalSource(nullptr),
+  Identifiers(opts, IILookup, DeferKeywordAddition),
   PragmaHandlers(new PragmaNamespace(StringRef())),
   IncrementalProcessing(false), TUKind(TUKind), CodeComplete(nullptr),
   CodeCompletionFile(nullptr), CodeCompletionOffset(0),
Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -536,6 +536,10 @@
 // Initialize the preprocessor.
 PP.Initialize(*Target);
 
+// Populate the identifier table with info about keywords for the current
+// language.
+PP.getIdentifierTable().AddKeywords(LangOpt);
+
 if (!Context)
   return;
 
@@ -718,11 +722,13 @@
   HeaderSearch  = *AST->HeaderInfo;
   unsigned Counter;
 
+  // As 

r307501 - [analyzer] Make StmtDataCollector part of the CloneDetection API

2017-07-09 Thread Raphael Isemann via cfe-commits
Author: teemperor
Date: Sun Jul  9 08:56:39 2017
New Revision: 307501

URL: http://llvm.org/viewvc/llvm-project?rev=307501=rev
Log:
[analyzer] Make StmtDataCollector part of the CloneDetection API

Summary: We probably want to use this useful templates in other pieces of code 
(e.g. the one from D34329), so we should make this public.

Reviewers: NoQ

Reviewed By: NoQ

Subscribers: cfe-commits, xazax.hun, v.g.vassilev, johannes

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

Modified:
cfe/trunk/include/clang/Analysis/CloneDetection.h
cfe/trunk/lib/Analysis/CloneDetection.cpp

Modified: cfe/trunk/include/clang/Analysis/CloneDetection.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CloneDetection.h?rev=307501=307500=307501=diff
==
--- cfe/trunk/include/clang/Analysis/CloneDetection.h (original)
+++ cfe/trunk/include/clang/Analysis/CloneDetection.h Sun Jul  9 08:56:39 2017
@@ -15,6 +15,8 @@
 #ifndef LLVM_CLANG_AST_CLONEDETECTION_H
 #define LLVM_CLANG_AST_CLONEDETECTION_H
 
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
@@ -29,6 +31,192 @@ class VarDecl;
 class ASTContext;
 class CompoundStmt;
 
+namespace clone_detection {
+
+/// Returns a string that represents all macro expansions that expanded into 
the
+/// given SourceLocation.
+///
+/// If 'getMacroStack(A) == getMacroStack(B)' is true, then the SourceLocations
+/// A and B are expanded from the same macros in the same order.
+std::string getMacroStack(SourceLocation Loc, ASTContext );
+
+/// Collects the data of a single Stmt.
+///
+/// This class defines what a code clone is: If it collects for two statements
+/// the same data, then those two statements are considered to be clones of 
each
+/// other.
+///
+/// All collected data is forwarded to the given data consumer of the type T.
+/// The data consumer class needs to provide a member method with the 
signature:
+///   update(StringRef Str)
+template 
+class StmtDataCollector : public ConstStmtVisitor {
+
+  ASTContext 
+  /// The data sink to which all data is forwarded.
+  T 
+
+public:
+  /// Collects data of the given Stmt.
+  /// \param S The given statement.
+  /// \param Context The ASTContext of S.
+  /// \param DataConsumer The data sink to which all data is forwarded.
+  StmtDataCollector(const Stmt *S, ASTContext , T )
+  : Context(Context), DataConsumer(DataConsumer) {
+this->Visit(S);
+  }
+
+  typedef unsigned DataPiece;
+
+  // Below are utility methods for appending different data to the vector.
+
+  void addData(DataPiece Integer) {
+DataConsumer.update(
+StringRef(reinterpret_cast(), sizeof(Integer)));
+  }
+
+  void addData(llvm::StringRef Str) { DataConsumer.update(Str); }
+
+  void addData(const QualType ) { addData(QT.getAsString()); }
+
+// The functions below collect the class specific data of each Stmt subclass.
+
+// Utility macro for defining a visit method for a given class. This method
+// calls back to the ConstStmtVisitor to visit all parent classes.
+#define DEF_ADD_DATA(CLASS, CODE)  
\
+  void Visit##CLASS(const CLASS *S) {  
\
+CODE;  
\
+ConstStmtVisitor::Visit##CLASS(S);  
\
+  }
+
+  DEF_ADD_DATA(Stmt, {
+addData(S->getStmtClass());
+// This ensures that macro generated code isn't identical to 
macro-generated
+// code.
+addData(getMacroStack(S->getLocStart(), Context));
+addData(getMacroStack(S->getLocEnd(), Context));
+  })
+  DEF_ADD_DATA(Expr, { addData(S->getType()); })
+
+  //--- Builtin functionality --//
+  DEF_ADD_DATA(ArrayTypeTraitExpr, { addData(S->getTrait()); })
+  DEF_ADD_DATA(ExpressionTraitExpr, { addData(S->getTrait()); })
+  DEF_ADD_DATA(PredefinedExpr, { addData(S->getIdentType()); })
+  DEF_ADD_DATA(TypeTraitExpr, {
+addData(S->getTrait());
+for (unsigned i = 0; i < S->getNumArgs(); ++i)
+  addData(S->getArg(i)->getType());
+  })
+
+  //--- Calls --//
+  DEF_ADD_DATA(CallExpr, {
+// Function pointers don't have a callee and we just skip hashing it.
+if (const FunctionDecl *D = S->getDirectCallee()) {
+  // If the function is a template specialization, we also need to handle
+  // the template arguments as they are not included in the qualified name.
+  if (auto Args = D->getTemplateSpecializationArgs()) {
+std::string ArgString;
+
+// Print all template arguments into ArgString
+llvm::raw_string_ostream OS(ArgString);
+for (unsigned i = 0; i < Args->size(); ++i) {
+  

[PATCH] D35056: GCC ABI incompatibility when passing object with trivial copy ctor, trivial dtor, and non-trivial move ctor

2017-07-09 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 105776.
v.g.vassilev added a comment.

Remove accidentally added change in SemaDecl.cpp


https://reviews.llvm.org/D35056

Files:
  include/clang/AST/DeclCXX.h
  lib/AST/ASTImporter.cpp
  lib/AST/DeclCXX.cpp
  lib/CodeGen/CGCXXABI.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  test/CodeGenCXX/uncopyable-args.cpp

Index: test/CodeGenCXX/uncopyable-args.cpp
===
--- test/CodeGenCXX/uncopyable-args.cpp
+++ test/CodeGenCXX/uncopyable-args.cpp
@@ -52,12 +52,11 @@
 void bar() {
   foo({});
 }
-// FIXME: The copy ctor is implicitly deleted.
-// CHECK-DISABLED-LABEL: define void @_ZN9move_ctor3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED-NOT: call
-// CHECK-DISABLED: call void @_ZN9move_ctor3fooENS_1AE(%"struct.move_ctor::A"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN9move_ctor3fooENS_1AE(%"struct.move_ctor::A"*)
+// CHECK-LABEL: define void @_ZN9move_ctor3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK-NOT: call
+// CHECK: call void @_ZN9move_ctor3fooENS_1AE(%"struct.move_ctor::A"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN9move_ctor3fooENS_1AE(%"struct.move_ctor::A"*)
 
 // WIN64-LABEL: declare void @"\01?foo@move_ctor@@YAXUA@1@@Z"(%"struct.move_ctor::A"*)
 }
@@ -73,12 +72,11 @@
 void bar() {
   foo({});
 }
-// FIXME: The copy ctor is deleted.
-// CHECK-DISABLED-LABEL: define void @_ZN11all_deleted3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED-NOT: call
-// CHECK-DISABLED: call void @_ZN11all_deleted3fooENS_1AE(%"struct.all_deleted::A"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN11all_deleted3fooENS_1AE(%"struct.all_deleted::A"*)
+// CHECK-LABEL: define void @_ZN11all_deleted3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK-NOT: call
+// CHECK: call void @_ZN11all_deleted3fooENS_1AE(%"struct.all_deleted::A"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN11all_deleted3fooENS_1AE(%"struct.all_deleted::A"*)
 
 // WIN64-LABEL: declare void @"\01?foo@all_deleted@@YAXUA@1@@Z"(%"struct.all_deleted::A"*)
 }
@@ -93,12 +91,11 @@
 void bar() {
   foo({});
 }
-// FIXME: The copy and move ctors are implicitly deleted.
-// CHECK-DISABLED-LABEL: define void @_ZN18implicitly_deleted3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED-NOT: call
-// CHECK-DISABLED: call void @_ZN18implicitly_deleted3fooENS_1AE(%"struct.implicitly_deleted::A"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN18implicitly_deleted3fooENS_1AE(%"struct.implicitly_deleted::A"*)
+// CHECK-LABEL: define void @_ZN18implicitly_deleted3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK-NOT: call
+// CHECK: call void @_ZN18implicitly_deleted3fooENS_1AE(%"struct.implicitly_deleted::A"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN18implicitly_deleted3fooENS_1AE(%"struct.implicitly_deleted::A"*)
 
 // WIN64-LABEL: declare void @"\01?foo@implicitly_deleted@@YAXUA@1@@Z"(%"struct.implicitly_deleted::A"*)
 }
@@ -113,12 +110,11 @@
 void bar() {
   foo({});
 }
-// FIXME: The copy constructor is implicitly deleted.
-// CHECK-DISABLED-LABEL: define void @_ZN11one_deleted3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED-NOT: call
-// CHECK-DISABLED: call void @_ZN11one_deleted3fooENS_1AE(%"struct.one_deleted::A"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN11one_deleted3fooENS_1AE(%"struct.one_deleted::A"*)
+// CHECK-LABEL: define void @_ZN11one_deleted3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK-NOT: call
+// CHECK: call void @_ZN11one_deleted3fooENS_1AE(%"struct.one_deleted::A"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN11one_deleted3fooENS_1AE(%"struct.one_deleted::A"*)
 
 // WIN64-LABEL: declare void @"\01?foo@one_deleted@@YAXUA@1@@Z"(%"struct.one_deleted::A"*)
 }
@@ -195,12 +191,10 @@
 void bar() {
   foo({});
 }
-// FIXME: This class has a non-trivial copy ctor and a trivial copy ctor.  It's
-// not clear whether we should pass by address or in registers.
-// CHECK-DISABLED-LABEL: define void @_ZN14two_copy_ctors3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED: call void @_ZN14two_copy_ctors3fooENS_1BE(%"struct.two_copy_ctors::B"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN14two_copy_ctors3fooENS_1BE(%"struct.two_copy_ctors::B"*)
+// CHECK-LABEL: define void @_ZN14two_copy_ctors3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK: call void @_ZN14two_copy_ctors3fooENS_1BE(%"struct.two_copy_ctors::B"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN14two_copy_ctors3fooENS_1BE(%"struct.two_copy_ctors::B"*)
 
 // WIN64-LABEL: declare void @"\01?foo@two_copy_ctors@@YAXUB@1@@Z"(%"struct.two_copy_ctors::B"*)
 }
Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -5885,6 +5885,7 @@
   

[PATCH] D35056: GCC ABI incompatibility when passing object with trivial copy ctor, trivial dtor, and non-trivial move ctor

2017-07-09 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 105775.
v.g.vassilev added a comment.

Compute only once if there is a non-deleted move or copy constructor and store 
them in the `DefinitionData` of the `CXXRecordDecl`.


https://reviews.llvm.org/D35056

Files:
  include/clang/AST/DeclCXX.h
  lib/AST/ASTImporter.cpp
  lib/AST/DeclCXX.cpp
  lib/CodeGen/CGCXXABI.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Sema/SemaDecl.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  test/CodeGenCXX/uncopyable-args.cpp

Index: test/CodeGenCXX/uncopyable-args.cpp
===
--- test/CodeGenCXX/uncopyable-args.cpp
+++ test/CodeGenCXX/uncopyable-args.cpp
@@ -52,12 +52,11 @@
 void bar() {
   foo({});
 }
-// FIXME: The copy ctor is implicitly deleted.
-// CHECK-DISABLED-LABEL: define void @_ZN9move_ctor3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED-NOT: call
-// CHECK-DISABLED: call void @_ZN9move_ctor3fooENS_1AE(%"struct.move_ctor::A"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN9move_ctor3fooENS_1AE(%"struct.move_ctor::A"*)
+// CHECK-LABEL: define void @_ZN9move_ctor3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK-NOT: call
+// CHECK: call void @_ZN9move_ctor3fooENS_1AE(%"struct.move_ctor::A"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN9move_ctor3fooENS_1AE(%"struct.move_ctor::A"*)
 
 // WIN64-LABEL: declare void @"\01?foo@move_ctor@@YAXUA@1@@Z"(%"struct.move_ctor::A"*)
 }
@@ -73,12 +72,11 @@
 void bar() {
   foo({});
 }
-// FIXME: The copy ctor is deleted.
-// CHECK-DISABLED-LABEL: define void @_ZN11all_deleted3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED-NOT: call
-// CHECK-DISABLED: call void @_ZN11all_deleted3fooENS_1AE(%"struct.all_deleted::A"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN11all_deleted3fooENS_1AE(%"struct.all_deleted::A"*)
+// CHECK-LABEL: define void @_ZN11all_deleted3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK-NOT: call
+// CHECK: call void @_ZN11all_deleted3fooENS_1AE(%"struct.all_deleted::A"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN11all_deleted3fooENS_1AE(%"struct.all_deleted::A"*)
 
 // WIN64-LABEL: declare void @"\01?foo@all_deleted@@YAXUA@1@@Z"(%"struct.all_deleted::A"*)
 }
@@ -93,12 +91,11 @@
 void bar() {
   foo({});
 }
-// FIXME: The copy and move ctors are implicitly deleted.
-// CHECK-DISABLED-LABEL: define void @_ZN18implicitly_deleted3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED-NOT: call
-// CHECK-DISABLED: call void @_ZN18implicitly_deleted3fooENS_1AE(%"struct.implicitly_deleted::A"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN18implicitly_deleted3fooENS_1AE(%"struct.implicitly_deleted::A"*)
+// CHECK-LABEL: define void @_ZN18implicitly_deleted3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK-NOT: call
+// CHECK: call void @_ZN18implicitly_deleted3fooENS_1AE(%"struct.implicitly_deleted::A"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN18implicitly_deleted3fooENS_1AE(%"struct.implicitly_deleted::A"*)
 
 // WIN64-LABEL: declare void @"\01?foo@implicitly_deleted@@YAXUA@1@@Z"(%"struct.implicitly_deleted::A"*)
 }
@@ -113,12 +110,11 @@
 void bar() {
   foo({});
 }
-// FIXME: The copy constructor is implicitly deleted.
-// CHECK-DISABLED-LABEL: define void @_ZN11one_deleted3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED-NOT: call
-// CHECK-DISABLED: call void @_ZN11one_deleted3fooENS_1AE(%"struct.one_deleted::A"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN11one_deleted3fooENS_1AE(%"struct.one_deleted::A"*)
+// CHECK-LABEL: define void @_ZN11one_deleted3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK-NOT: call
+// CHECK: call void @_ZN11one_deleted3fooENS_1AE(%"struct.one_deleted::A"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN11one_deleted3fooENS_1AE(%"struct.one_deleted::A"*)
 
 // WIN64-LABEL: declare void @"\01?foo@one_deleted@@YAXUA@1@@Z"(%"struct.one_deleted::A"*)
 }
@@ -195,12 +191,10 @@
 void bar() {
   foo({});
 }
-// FIXME: This class has a non-trivial copy ctor and a trivial copy ctor.  It's
-// not clear whether we should pass by address or in registers.
-// CHECK-DISABLED-LABEL: define void @_ZN14two_copy_ctors3barEv()
-// CHECK-DISABLED: call void @_Z{{.*}}C1Ev(
-// CHECK-DISABLED: call void @_ZN14two_copy_ctors3fooENS_1BE(%"struct.two_copy_ctors::B"* %{{.*}})
-// CHECK-DISABLED-LABEL: declare void @_ZN14two_copy_ctors3fooENS_1BE(%"struct.two_copy_ctors::B"*)
+// CHECK-LABEL: define void @_ZN14two_copy_ctors3barEv()
+// CHECK: call void @_Z{{.*}}C1Ev(
+// CHECK: call void @_ZN14two_copy_ctors3fooENS_1BE(%"struct.two_copy_ctors::B"* %{{.*}})
+// CHECK-LABEL: declare void @_ZN14two_copy_ctors3fooENS_1BE(%"struct.two_copy_ctors::B"*)
 
 // WIN64-LABEL: declare void @"\01?foo@two_copy_ctors@@YAXUB@1@@Z"(%"struct.two_copy_ctors::B"*)
 }
Index: lib/Serialization/ASTWriter.cpp
===
--- 

[PATCH] D35082: [OpenCL] Add LangAS::opencl_private to represent private address space in AST

2017-07-09 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 105774.
yaxunl retitled this revision from "[WIP][OpenCL] Add LangAS::opencl_private to 
represent private address space in AST" to "[OpenCL] Add LangAS::opencl_private 
to represent private address space in AST".
yaxunl edited the summary of this revision.
yaxunl added a comment.

Update lit tests.

It is essentially done. Clang already drops all qualifiers when converting 
l-value to r-value.

The only missing part is to let Clang treat (void*)0 as a generic null pointer 
for OpenCL 1.2 and below since now it is a pointer to private address space.


https://reviews.llvm.org/D35082

Files:
  include/clang/Basic/AddressSpaces.h
  lib/AST/ASTContext.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGDecl.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/address-spaces-mangling.cl
  test/Index/opencl-types.cl
  test/Parser/opencl-astype.cl
  test/Parser/opencl-atomics-cl20.cl
  test/SemaOpenCL/access-qualifier.cl
  test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
  test/SemaOpenCL/address-spaces.cl
  test/SemaOpenCL/arithmetic-conversions.cl
  test/SemaOpenCL/as_type.cl
  test/SemaOpenCL/cl20-device-side-enqueue.cl
  test/SemaOpenCL/event_t.cl
  test/SemaOpenCL/extension-begin.cl
  test/SemaOpenCL/half.cl
  test/SemaOpenCL/images.cl
  test/SemaOpenCL/invalid-block.cl
  test/SemaOpenCL/invalid-image.cl
  test/SemaOpenCL/invalid-kernel-parameters.cl
  test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
  test/SemaOpenCL/invalid-pipes-cl2.0.cl
  test/SemaOpenCL/null_literal.cl
  test/SemaOpenCL/null_queue.cl
  test/SemaOpenCL/queue_t_overload.cl
  test/SemaOpenCL/sampler_t.cl
  test/SemaOpenCL/shifts.cl
  test/SemaOpenCL/to_addr_builtin.cl
  test/SemaOpenCL/vec_step.cl
  test/SemaOpenCL/vector_conv_invalid.cl

Index: test/SemaOpenCL/vector_conv_invalid.cl
===
--- test/SemaOpenCL/vector_conv_invalid.cl
+++ test/SemaOpenCL/vector_conv_invalid.cl
@@ -7,7 +7,7 @@
 
 void vector_conv_invalid() {
   uint4 u = (uint4)(1);
-  int4 i = u; // expected-error{{initializing 'int4' (vector of 4 'int' values) with an expression of incompatible type 'uint4' (vector of 4 'unsigned int' values)}}
+  int4 i = u; // expected-error{{initializing '__private int4' (vector of 4 'int' values) with an expression of incompatible type '__private uint4' (vector of 4 'unsigned int' values)}}
   int4 e = (int4)u; // expected-error{{invalid conversion between ext-vector type 'int4' (vector of 4 'int' values) and 'uint4' (vector of 4 'unsigned int' values)}}
 
   uint3 u4 = (uint3)u; // expected-error{{invalid conversion between ext-vector type 'uint3' (vector of 3 'unsigned int' values) and 'uint4' (vector of 4 'unsigned int' values)}}
Index: test/SemaOpenCL/vec_step.cl
===
--- test/SemaOpenCL/vec_step.cl
+++ test/SemaOpenCL/vec_step.cl
@@ -26,7 +26,7 @@
   int res11[vec_step(int16) == 16 ? 1 : -1];
   int res12[vec_step(void) == 1 ? 1 : -1];
 
-  int res13 = vec_step(*incomplete1); // expected-error {{'vec_step' requires built-in scalar or vector type, 'struct S' invalid}}
-  int res14 = vec_step(int16*); // expected-error {{'vec_step' requires built-in scalar or vector type, 'int16 *' invalid}}
+  int res13 = vec_step(*incomplete1); // expected-error {{'vec_step' requires built-in scalar or vector type, '__private struct S' invalid}}
+  int res14 = vec_step(int16 *); // expected-error {{'vec_step' requires built-in scalar or vector type, '__private int16 *' invalid}}
   int res15 = vec_step(void(void)); // expected-error {{'vec_step' requires built-in scalar or vector type, 'void (void)' invalid}}
 }
Index: test/SemaOpenCL/to_addr_builtin.cl
===
--- test/SemaOpenCL/to_addr_builtin.cl
+++ test/SemaOpenCL/to_addr_builtin.cl
@@ -11,45 +11,45 @@
   glob = to_global(glob, loc);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
   // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
-  // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
+  // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-5{{invalid number of arguments to function: 'to_global'}}
 #endif
 
   int x;
   glob = to_global(x);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
-  // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
+  // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con);
 #if __OPENCL_C_VERSION__ < 

[PATCH] D35153: Use DenseMap instead std::map for GVSummaryMapTy

2017-07-09 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson accepted this revision.
tejohnson added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D35153



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


[PATCH] D34331: func.wrap.func.con: Unset function before destroying anything

2017-07-09 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In https://reviews.llvm.org/D34331#802747, @EricWF wrote:

> @dexonsmith Mind if I hijack this and check in your changes to `` 
> with my tests?


Not at all.

In https://reviews.llvm.org/D34331#802821, @EricWF wrote:

> @dexonsmith I'm not sure it's sane to allow reentrant behavior. Could you 
> explain why you think it is?


It didn't seem sane to me at first either, despite this being supported by 
`std::unique_ptr` and `std::shared_ptr`.  I found our user fairly convincing, 
though:

- They had an underlying reference counted object, so only the destruction of 
the last copy of A nulled out the pointer (mimicked that with the `bool 
cancel`).
- They had a callback function intended to be called once, and dropping that 
function on cancellation (mimicked that with a global variable). The cancel 
operation nulled out a `std::function`, but destroying the objects captured in 
the lambda in that std::function also separately decided to perform a cancel, 
which should have been OK. The cancel function just contained `callback = 
nullptr`.

In https://reviews.llvm.org/D34331#802821, @EricWF wrote:

> Should the copy assignment operator allow reentrancy as well?


I'm not sure; what do you think?




Comment at: 
libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp:1
+//===--===//
+//

EricWF wrote:
> It seems like this test is testing behavior that should be required by the 
> standard, right?
> 
> If so it should live under `test/std`.
Yes, that likely is a better place.



Comment at: 
libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp:25
+  ~A() {
+asm("");
+if (cancel)

EricWF wrote:
> Is `asm("")` just to prevent optimizations? If so please use `DoNotOptimize` 
> from `test_macros.h`.
Sounds fine to me.


https://reviews.llvm.org/D34331



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


[PATCH] D35180: Expose the Clang::QualType to llvm::Type conversion functions

2017-07-09 Thread Benoit Vey via Phabricator via cfe-commits
Praetonus created this revision.

This change exposes the various CodeGenTypes::ConvertType functions in the 
public Clang API. This allows external tools using the Clang API to rely on it 
to generate LLVM types from C types. The precise use case that motivated this 
change is explained in an email 
 to the Clang 
mailing list.


https://reviews.llvm.org/D35180

Files:
  include/clang/CodeGen/CodeGenABITypes.h
  lib/CodeGen/CodeGenABITypes.cpp


Index: lib/CodeGen/CodeGenABITypes.cpp
===
--- lib/CodeGen/CodeGenABITypes.cpp
+++ lib/CodeGen/CodeGenABITypes.cpp
@@ -64,3 +64,20 @@
   returnType, /*IsInstanceMethod=*/false, /*IsChainCall=*/false, argTypes,
   info, {}, args);
 }
+
+llvm::Type *
+CodeGen::ConvertType(CodeGenModule , QualType T) {
+  return CGM.getTypes().ConvertType(T);
+}
+
+llvm::Type *
+CodeGen::ConvertFunctionType(CodeGenModule ,
+ QualType FT,
+ const FunctionDecl *FD) {
+  return CGM.getTypes().ConvertFunctionType(FT, FD);
+}
+
+llvm::Type *
+CodeGen::ConvertTypeForMem(CodeGenModule , QualType T) {
+  return CGM.getTypes().ConvertTypeForMem(T);
+}
Index: include/clang/CodeGen/CodeGenABITypes.h
===
--- include/clang/CodeGen/CodeGenABITypes.h
+++ include/clang/CodeGen/CodeGenABITypes.h
@@ -31,6 +31,7 @@
 namespace llvm {
   class DataLayout;
   class Module;
+  class Type;
 }
 
 namespace clang {
@@ -70,6 +71,14 @@
   FunctionType::ExtInfo info,
   RequiredArgs args);
 
+llvm::Type *ConvertType(CodeGenModule , QualType T);
+
+llvm::Type *ConvertFunctionType(CodeGenModule ,
+QualType FT,
+const FunctionDecl *FD = nullptr);
+
+llvm::Type *ConvertTypeForMem(CodeGenModule , QualType T);
+
 }  // end namespace CodeGen
 }  // end namespace clang
 


Index: lib/CodeGen/CodeGenABITypes.cpp
===
--- lib/CodeGen/CodeGenABITypes.cpp
+++ lib/CodeGen/CodeGenABITypes.cpp
@@ -64,3 +64,20 @@
   returnType, /*IsInstanceMethod=*/false, /*IsChainCall=*/false, argTypes,
   info, {}, args);
 }
+
+llvm::Type *
+CodeGen::ConvertType(CodeGenModule , QualType T) {
+  return CGM.getTypes().ConvertType(T);
+}
+
+llvm::Type *
+CodeGen::ConvertFunctionType(CodeGenModule ,
+ QualType FT,
+ const FunctionDecl *FD) {
+  return CGM.getTypes().ConvertFunctionType(FT, FD);
+}
+
+llvm::Type *
+CodeGen::ConvertTypeForMem(CodeGenModule , QualType T) {
+  return CGM.getTypes().ConvertTypeForMem(T);
+}
Index: include/clang/CodeGen/CodeGenABITypes.h
===
--- include/clang/CodeGen/CodeGenABITypes.h
+++ include/clang/CodeGen/CodeGenABITypes.h
@@ -31,6 +31,7 @@
 namespace llvm {
   class DataLayout;
   class Module;
+  class Type;
 }
 
 namespace clang {
@@ -70,6 +71,14 @@
   FunctionType::ExtInfo info,
   RequiredArgs args);
 
+llvm::Type *ConvertType(CodeGenModule , QualType T);
+
+llvm::Type *ConvertFunctionType(CodeGenModule ,
+QualType FT,
+const FunctionDecl *FD = nullptr);
+
+llvm::Type *ConvertTypeForMem(CodeGenModule , QualType T);
+
 }  // end namespace CodeGen
 }  // end namespace clang
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33842: CodeGen: Fix address space of global variable

2017-07-09 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307470: CodeGen: Fix address space of global variable 
(authored by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D33842?vs=105644=105770#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33842

Files:
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/lib/CodeGen/CGBlocks.cpp
  cfe/trunk/lib/CodeGen/CGDecl.cpp
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.h
  cfe/trunk/lib/CodeGen/TargetInfo.cpp
  cfe/trunk/lib/CodeGen/TargetInfo.h
  cfe/trunk/test/CodeGen/address-space.c
  cfe/trunk/test/CodeGen/default-address-space.c
  cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp

Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -2404,6 +2404,10 @@
 return LangAS::opencl_constant;
   }
 
+  llvm::Optional getConstantAddressSpace() const override {
+return LangAS::FirstTargetAddressSpace + AS.Constant;
+  }
+
   /// \returns Target specific vtbl ptr address space.
   unsigned getVtblPtrAddressSpace() const override { return AS.Constant; }
 
Index: cfe/trunk/lib/CodeGen/CGBlocks.cpp
===
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp
@@ -736,9 +736,9 @@
   llvm::Constant *isa =
   (!CGM.getContext().getLangOpts().OpenCL)
   ? CGM.getNSConcreteStackBlock()
-  : CGM.getNullPointer(cast(
-   CGM.getNSConcreteStackBlock()->getType()),
-   QualType(getContext().VoidPtrTy));
+  : CGM.getNullPointer(VoidPtrPtrTy,
+   CGM.getContext().getPointerType(
+   QualType(CGM.getContext().VoidPtrTy)));
   isa = llvm::ConstantExpr::getBitCast(isa, VoidPtrTy);
 
   // Build the block descriptor.
@@ -1141,12 +1141,11 @@
   auto fields = builder.beginStruct();
 
   // isa
-  fields.add(
-  (!CGM.getContext().getLangOpts().OpenCL)
-  ? CGM.getNSConcreteGlobalBlock()
-  : CGM.getNullPointer(cast(
-   CGM.getNSConcreteGlobalBlock()->getType()),
-   QualType(CGM.getContext().VoidPtrTy)));
+  fields.add((!CGM.getContext().getLangOpts().OpenCL)
+ ? CGM.getNSConcreteGlobalBlock()
+ : CGM.getNullPointer(CGM.VoidPtrPtrTy,
+  CGM.getContext().getPointerType(QualType(
+  CGM.getContext().VoidPtrTy;
 
   // __flags
   BlockFlags flags = BLOCK_IS_GLOBAL | BLOCK_HAS_SIGNATURE;
Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -2367,11 +2367,13 @@
   return llvm::ConstantExpr::getBitCast(Entry, Ty);
   }
 
-  unsigned AddrSpace = GetGlobalVarAddressSpace(D, Ty->getAddressSpace());
+  auto AddrSpace = GetGlobalVarAddressSpace(D);
+  auto TargetAddrSpace = getContext().getTargetAddressSpace(AddrSpace);
+
   auto *GV = new llvm::GlobalVariable(
   getModule(), Ty->getElementType(), false,
   llvm::GlobalValue::ExternalLinkage, nullptr, MangledName, nullptr,
-  llvm::GlobalVariable::NotThreadLocal, AddrSpace);
+  llvm::GlobalVariable::NotThreadLocal, TargetAddrSpace);
 
   // If we already created a global with the same mangled name (but different
   // type) before, take its name and remove it from its parent.
@@ -2428,8 +2430,14 @@
   GV->setSection(".cp.rodata");
   }
 
-  if (AddrSpace != Ty->getAddressSpace())
-return llvm::ConstantExpr::getAddrSpaceCast(GV, Ty);
+  auto ExpectedAS =
+  D ? D->getType().getAddressSpace()
+: (LangOpts.OpenCL ? LangAS::opencl_global : LangAS::Default);
+  auto ExpectedTargetAS = getContext().getTargetAddressSpace(ExpectedAS);
+  assert(ExpectedTargetAS == Ty->getPointerAddressSpace());
+  if (AddrSpace != ExpectedAS)
+return getTargetCodeGenInfo().performAddrSpaceCast(*this, GV, AddrSpace,
+   ExpectedAS, Ty);
 
   return GV;
 }
@@ -2563,18 +2571,27 @@
   getDataLayout().getTypeStoreSizeInBits(Ty));
 }
 
-unsigned CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D,
- unsigned AddrSpace) {
-  if (D && LangOpts.CUDA && LangOpts.CUDAIsDevice) {
-if (D->hasAttr())
-  AddrSpace = getContext().getTargetAddressSpace(LangAS::cuda_constant);
-else if (D->hasAttr())
-  AddrSpace = getContext().getTargetAddressSpace(LangAS::cuda_shared);
+unsigned 

[PATCH] D34927: [Bash-autocompletion] Fix a bug that -foo=bar doesn't handled properly

2017-07-09 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307478: [Bash-autocompletion] Fix a bug that -foo=bar 
doesn't handled properly (authored by yamaguchi).

Changed prior to commit:
  https://reviews.llvm.org/D34927?vs=105208=105771#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34927

Files:
  cfe/trunk/utils/bash-autocomplete.sh


Index: cfe/trunk/utils/bash-autocomplete.sh
===
--- cfe/trunk/utils/bash-autocomplete.sh
+++ cfe/trunk/utils/bash-autocomplete.sh
@@ -34,12 +34,18 @@
   elif [[ "$w1" == -*  && "$cur" == '=' ]]; then
 # -foo=
 arg="$w1=,"
+  elif [[ "$cur" == -*= ]]; then
+# -foo=
+arg="$cur,"
   elif [[ "$w1" == -* ]]; then
 # -foo  or -foo bar
 arg="$w1,$cur"
   elif [[ "$w2" == -* && "$w1" == '=' ]]; then
 # -foo=bar
 arg="$w2=,$cur"
+  elif [[ ${cur: -1} != '=' && ${cur/=} != $cur ]]; then
+# -foo=bar
+arg="${cur%=*}=,${cur#*=}"
   fi
 
   # expand ~ to $HOME


Index: cfe/trunk/utils/bash-autocomplete.sh
===
--- cfe/trunk/utils/bash-autocomplete.sh
+++ cfe/trunk/utils/bash-autocomplete.sh
@@ -34,12 +34,18 @@
   elif [[ "$w1" == -*  && "$cur" == '=' ]]; then
 # -foo=
 arg="$w1=,"
+  elif [[ "$cur" == -*= ]]; then
+# -foo=
+arg="$cur,"
   elif [[ "$w1" == -* ]]; then
 # -foo  or -foo bar
 arg="$w1,$cur"
   elif [[ "$w2" == -* && "$w1" == '=' ]]; then
 # -foo=bar
 arg="$w2=,$cur"
+  elif [[ ${cur: -1} != '=' && ${cur/=} != $cur ]]; then
+# -foo=bar
+arg="${cur%=*}=,${cur#*=}"
   fi
 
   # expand ~ to $HOME
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34770: [Bash-autocompletion] Auto complete cc1 options if -cc1 is specified

2017-07-09 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307479: [Bash-autocompletion] Auto complete cc1 options if 
-cc1 is specified (authored by yamaguchi).

Changed prior to commit:
  https://reviews.llvm.org/D34770?vs=105209=105772#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34770

Files:
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/test/Driver/autocomplete.c
  cfe/trunk/utils/bash-autocomplete.sh
  llvm/trunk/include/llvm/Option/OptTable.h
  llvm/trunk/lib/Option/OptTable.cpp

Index: cfe/trunk/test/Driver/autocomplete.c
===
--- cfe/trunk/test/Driver/autocomplete.c
+++ cfe/trunk/test/Driver/autocomplete.c
@@ -36,3 +36,7 @@
 // MTHREADMODELALL: posix single
 // RUN: %clang --autocomplete=-mrelocation-model, | FileCheck %s -check-prefix=MRELOCMODELALL
 // MRELOCMODELALL: dynamic-no-pic pic ropi ropi-rwpi rwpi static
+// RUN: %clang --autocomplete=-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CLANG
+// MRELOCMODEL_CLANG-NOT: -mrelocation-model
+// RUN: %clang --autocomplete=#-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CC1
+// MRELOCMODEL_CC1: -mrelocation-model
Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -1261,11 +1261,20 @@
 StringRef PassedFlags = A->getValue();
 std::vector SuggestedCompletions;
 
+unsigned short DisableFlags = options::NoDriverOption | options::Unsupported | options::Ignored;
+// We want to show cc1-only options only when clang is invoked as "clang -cc1".
+// When clang is invoked as "clang -cc1", we add "#" to the beginning of an --autocomplete
+// option so that the clang driver can distinguish whether it is requested to show cc1-only options or not.
+if (PassedFlags[0] == '#') {
+  DisableFlags &= ~options::NoDriverOption;
+  PassedFlags = PassedFlags.substr(1);
+}
+
 if (PassedFlags.find(',') == StringRef::npos) {
   // If the flag is in the form of "--autocomplete=-foo",
   // we were requested to print out all option names that start with "-foo".
   // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
-  SuggestedCompletions = Opts->findByPrefix(PassedFlags);
+  SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags);
 } else {
   // If the flag is in the form of "--autocomplete=foo,bar", we were
   // requested to print out all option values for "-foo" that start with
Index: cfe/trunk/utils/bash-autocomplete.sh
===
--- cfe/trunk/utils/bash-autocomplete.sh
+++ cfe/trunk/utils/bash-autocomplete.sh
@@ -27,25 +27,29 @@
   w1="${COMP_WORDS[$cword - 1]}"
   if [[ $cword > 1 ]]; then
 w2="${COMP_WORDS[$cword - 2]}"
+  # Clang want to know if -cc1 or -Xclang option is specified or not, because we don't want to show
+  # cc1 options otherwise.
+  if [[ "${COMP_WORDS[1]}" == "-cc1" || "$w1" == "-Xclang" ]]; then
+arg="#"
   fi
   if [[ "$cur" == -* ]]; then
 # -foo
-arg="$cur"
+arg="$arg$cur"
   elif [[ "$w1" == -*  && "$cur" == '=' ]]; then
 # -foo=
-arg="$w1=,"
+arg="$arg$w1=,"
   elif [[ "$cur" == -*= ]]; then
 # -foo=
-arg="$cur,"
+arg="$arg$cur,"
   elif [[ "$w1" == -* ]]; then
 # -foo  or -foo bar
-arg="$w1,$cur"
+arg="$arg$w1,$cur"
   elif [[ "$w2" == -* && "$w1" == '=' ]]; then
 # -foo=bar
-arg="$w2=,$cur"
+arg="$arg$w2=,$cur"
   elif [[ ${cur: -1} != '=' && ${cur/=} != $cur ]]; then
 # -foo=bar
-arg="${cur%=*}=,${cur#*=}"
+arg="$arg${cur%=*}=,${cur#*=}"
   fi
 
   # expand ~ to $HOME
Index: llvm/trunk/lib/Option/OptTable.cpp
===
--- llvm/trunk/lib/Option/OptTable.cpp
+++ llvm/trunk/lib/Option/OptTable.cpp
@@ -225,11 +225,15 @@
   return {};
 }
 
-std::vector OptTable::findByPrefix(StringRef Cur) const {
+std::vector
+OptTable::findByPrefix(StringRef Cur, unsigned short DisableFlags) const {
   std::vector Ret;
   for (const Info  : OptionInfos.slice(FirstSearchableIndex)) {
 if (!In.Prefixes || (!In.HelpText && !In.GroupID))
   continue;
+if (In.Flags & DisableFlags)
+  continue;
+
 for (int I = 0; In.Prefixes[I]; I++) {
   std::string S = std::string(In.Prefixes[I]) + std::string(In.Name);
   if (StringRef(S).startswith(Cur))
Index: llvm/trunk/include/llvm/Option/OptTable.h
===
--- llvm/trunk/include/llvm/Option/OptTable.h
+++ llvm/trunk/include/llvm/Option/OptTable.h
@@ -140,7 +140,8 @@
   //  to start with.
   ///
   /// \return The vector of flags which start with Cur.
-  std::vector findByPrefix(StringRef Cur) const;
+  std::vector findByPrefix(StringRef Cur,
+

[PATCH] D34725: Add sample PGO integration test to cover profile annotation and inlining.

2017-07-09 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307445: Add sample PGO integration test to cover profile 
annotation and inlining. (authored by dehao).

Repository:
  rL LLVM

https://reviews.llvm.org/D34725

Files:
  cfe/trunk/test/CodeGen/Inputs/pgo-sample.prof
  cfe/trunk/test/CodeGen/pgo-sample.c


Index: cfe/trunk/test/CodeGen/pgo-sample.c
===
--- cfe/trunk/test/CodeGen/pgo-sample.c
+++ cfe/trunk/test/CodeGen/pgo-sample.c
@@ -1,6 +1,34 @@
 // Test if PGO sample use passes are invoked.
 //
-// Ensure Pass PGOInstrumentationGenPass is invoked.
-// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s
-// CHECK: Remove unused exception handling info
-// CHECK: Sample profile pass
+// Ensure Pass SampleProfileLoader is invoked.
+// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s 
--check-prefix=STRUCTURE
+// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm -o - 2>&1 | 
FileCheck %s
+// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm 
-fexperimental-new-pass-manager -o - 2>&1 | FileCheck %s
+// STRUCTURE: Remove unused exception handling info
+// STRUCTURE: Sample profile pass
+
+void baz();
+
+// CHECK-LABEL: @callee(
+void callee(int t) {
+  for (int i = 0; i < t; i++)
+baz();
+}
+
+// CHECK-LABEL: @bar(
+// cold call to callee should not be inlined.
+// CHECK: call void @callee
+void bar(int x) {
+  if (x < 100)
+callee(x);
+}
+
+// CHECK-LABEL: @foo(
+// bar should be early-inlined because it is hot inline instance in profile.
+// callee should be inlined because it is hot callsite in the inline instance
+// of foo:bar.
+// CHECK-NOT: call void @callee
+// CHECK-NOT: call void @bar
+void foo(int x) {
+  bar(x);
+}
Index: cfe/trunk/test/CodeGen/Inputs/pgo-sample.prof
===
--- cfe/trunk/test/CodeGen/Inputs/pgo-sample.prof
+++ cfe/trunk/test/CodeGen/Inputs/pgo-sample.prof
@@ -1,2 +1,7 @@
-bar:100:100
- 1: 2000
+bar:1000:1000
+ 1: 1000
+ 2: 0
+foo:1000:1000
+ 1:bar:1000
+  1: 1000
+  2: 1000


Index: cfe/trunk/test/CodeGen/pgo-sample.c
===
--- cfe/trunk/test/CodeGen/pgo-sample.c
+++ cfe/trunk/test/CodeGen/pgo-sample.c
@@ -1,6 +1,34 @@
 // Test if PGO sample use passes are invoked.
 //
-// Ensure Pass PGOInstrumentationGenPass is invoked.
-// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s
-// CHECK: Remove unused exception handling info
-// CHECK: Sample profile pass
+// Ensure Pass SampleProfileLoader is invoked.
+// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=STRUCTURE
+// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm -o - 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm -fexperimental-new-pass-manager -o - 2>&1 | FileCheck %s
+// STRUCTURE: Remove unused exception handling info
+// STRUCTURE: Sample profile pass
+
+void baz();
+
+// CHECK-LABEL: @callee(
+void callee(int t) {
+  for (int i = 0; i < t; i++)
+baz();
+}
+
+// CHECK-LABEL: @bar(
+// cold call to callee should not be inlined.
+// CHECK: call void @callee
+void bar(int x) {
+  if (x < 100)
+callee(x);
+}
+
+// CHECK-LABEL: @foo(
+// bar should be early-inlined because it is hot inline instance in profile.
+// callee should be inlined because it is hot callsite in the inline instance
+// of foo:bar.
+// CHECK-NOT: call void @callee
+// CHECK-NOT: call void @bar
+void foo(int x) {
+  bar(x);
+}
Index: cfe/trunk/test/CodeGen/Inputs/pgo-sample.prof
===
--- cfe/trunk/test/CodeGen/Inputs/pgo-sample.prof
+++ cfe/trunk/test/CodeGen/Inputs/pgo-sample.prof
@@ -1,2 +1,7 @@
-bar:100:100
- 1: 2000
+bar:1000:1000
+ 1: 1000
+ 2: 0
+foo:1000:1000
+ 1:bar:1000
+  1: 1000
+  2: 1000
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34714: [MS] Don't statically initialize dllimport member function pointers

2017-07-09 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307446: [MS] Don't statically initialize dllimport member 
function pointers (authored by rnk).

Changed prior to commit:
  https://reviews.llvm.org/D34714?vs=104289=105768#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34714

Files:
  cfe/trunk/lib/AST/ExprConstant.cpp
  cfe/trunk/lib/Sema/SemaTemplate.cpp
  cfe/trunk/test/SemaCXX/dllimport-memptr.cpp

Index: cfe/trunk/lib/AST/ExprConstant.cpp
===
--- cfe/trunk/lib/AST/ExprConstant.cpp
+++ cfe/trunk/lib/AST/ExprConstant.cpp
@@ -1665,6 +1665,19 @@
   return true;
 }
 
+/// Member pointers are constant expressions unless they point to a
+/// non-virtual dllimport member function.
+static bool CheckMemberPointerConstantExpression(EvalInfo ,
+ SourceLocation Loc,
+ QualType Type,
+ const APValue ) {
+  const ValueDecl *Member = Value.getMemberPointerDecl();
+  const auto *FD = dyn_cast_or_null(Member);
+  if (!FD)
+return true;
+  return FD->isVirtual() || !FD->hasAttr();
+}
+
 /// Check that this core constant expression is of literal type, and if not,
 /// produce an appropriate diagnostic.
 static bool CheckLiteralType(EvalInfo , const Expr *E,
@@ -1757,6 +1770,9 @@
 return CheckLValueConstantExpression(Info, DiagLoc, Type, LVal);
   }
 
+  if (Value.isMemberPointer())
+return CheckMemberPointerConstantExpression(Info, DiagLoc, Type, Value);
+
   // Everything else is fine.
   return true;
 }
Index: cfe/trunk/lib/Sema/SemaTemplate.cpp
===
--- cfe/trunk/lib/Sema/SemaTemplate.cpp
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp
@@ -5319,10 +5319,16 @@
 /// value of the appropriate type.
 static NullPointerValueKind
 isNullPointerValueTemplateArgument(Sema , NonTypeTemplateParmDecl *Param,
-   QualType ParamType, Expr *Arg) {
+   QualType ParamType, Expr *Arg,
+   Decl *Entity = nullptr) {
   if (Arg->isValueDependent() || Arg->isTypeDependent())
 return NPV_NotNullPointer;
 
+  // dllimport'd entities aren't constant but are available inside of template
+  // arguments.
+  if (Entity && Entity->hasAttr())
+return NPV_NotNullPointer;
+
   if (!S.isCompleteType(Arg->getExprLoc(), ParamType))
 llvm_unreachable(
 "Incomplete parameter type in isNullPointerValueTemplateArgument!");
@@ -5566,14 +5572,8 @@
 
   // If our parameter has pointer type, check for a null template value.
   if (ParamType->isPointerType() || ParamType->isNullPtrType()) {
-NullPointerValueKind NPV;
-// dllimport'd entities aren't constant but are available inside of template
-// arguments.
-if (Entity && Entity->hasAttr())
-  NPV = NPV_NotNullPointer;
-else
-  NPV = isNullPointerValueTemplateArgument(S, Param, ParamType, ArgIn);
-switch (NPV) {
+switch (isNullPointerValueTemplateArgument(S, Param, ParamType, ArgIn,
+   Entity)) {
 case NPV_NullPointer:
   S.Diag(Arg->getExprLoc(), diag::warn_cxx98_compat_template_arg_null);
   Converted = TemplateArgument(S.Context.getCanonicalType(ParamType),
@@ -5765,39 +5765,8 @@
  TemplateArgument ) {
   bool Invalid = false;
 
-  // Check for a null pointer value.
   Expr *Arg = ResultArg;
-  switch (isNullPointerValueTemplateArgument(S, Param, ParamType, Arg)) {
-  case NPV_Error:
-return true;
-  case NPV_NullPointer:
-S.Diag(Arg->getExprLoc(), diag::warn_cxx98_compat_template_arg_null);
-Converted = TemplateArgument(S.Context.getCanonicalType(ParamType),
- /*isNullPtr*/true);
-return false;
-  case NPV_NotNullPointer:
-break;
-  }
-
   bool ObjCLifetimeConversion;
-  if (S.IsQualificationConversion(Arg->getType(),
-  ParamType.getNonReferenceType(),
-  false, ObjCLifetimeConversion)) {
-Arg = S.ImpCastExprToType(Arg, ParamType, CK_NoOp,
-  Arg->getValueKind()).get();
-ResultArg = Arg;
-  } else if (!S.Context.hasSameUnqualifiedType(Arg->getType(),
-ParamType.getNonReferenceType())) {
-// We can't perform this conversion.
-S.Diag(Arg->getLocStart(), diag::err_template_arg_not_convertible)
-  << Arg->getType() << ParamType << Arg->getSourceRange();
-S.Diag(Param->getLocation(), diag::note_template_param_here);
-return true;
-  }
-
-  // See through any implicit casts we added to fix the type.
-  while (ImplicitCastExpr *Cast = dyn_cast(Arg))
-Arg = Cast->getSubExpr();
 
   // C++ [temp.arg.nontype]p1:
   //
@@ -5854,6 +5823,37 @@
 DRE = 

[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-07-09 Thread wangxin via Phabricator via cfe-commits
wangxindsb added a comment.

Look forward to your review.


https://reviews.llvm.org/D34275



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


[PATCH] D32385: [libcxx] optional: Implement LWG 2900 and P0602

2017-07-09 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

LGTM. I'll deal with ensuring all vendors are willing to take this ABI break 
(or that they avoid it).


https://reviews.llvm.org/D32385



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


[PATCH] D35158: [libcxxabi][demangler] NFC: Don't make everything a template

2017-07-09 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington closed this revision.
erik.pilkington added a comment.

Landed as r307482 & r307481, thanks! (for some reason phab wasn't automatically 
closing this)


https://reviews.llvm.org/D35158



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


[PATCH] D33645: [analyzer] Add missing documentation for static analyzer checkers

2017-07-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I think next time we should add examples of warning messages here - not just 
"//warn" but how they literally may look - so that people were able to find 
this page, and not doxygen/github source code, when they google up their 
warning messages.


https://reviews.llvm.org/D33645



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


[PATCH] D35159: [libcxxabi][demangler] Use an AST to represent the demangled name

2017-07-09 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added inline comments.



Comment at: src/cxa_demangle.cpp:87
+
+class stream
+{

Doc
(same for non trivial APIs)



Comment at: src/cxa_demangle.cpp:125
+
+typedef unsigned stream_position;
+

Doc



Comment at: src/cxa_demangle.cpp:173
+
+class node
+{

Doc



Comment at: src/cxa_demangle.cpp:239
+virtual void print_left(stream& s) const = 0;
+virtual void print_right(stream&) const {}
+

Why is one pure virtual and not the other? Why isn't the stream const?



Comment at: src/cxa_demangle.cpp:244
+// Silence compiler warnings, this dtor will never be called.
+virtual ~node() {}
+};

`= default;`


https://reviews.llvm.org/D35159



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


[PATCH] D35175: New option that adds the DiagID enum name and index to Diagnostic output.

2017-07-09 Thread don hinton via Phabricator via cfe-commits
hintonda created this revision.

This option helps locate the origin of a diagnostic message
by outputing the enum name and index associated with a specific
DiagID, allowing users to grep the code for the enum name directly
without having to find it in the td files first.

Additional ideas:

1. add another option to pass in the index (or enum) to force an assert or 
backtrace when a specific DiagID is seen.
2. capture __FILE__ and __LINE__ when a diagnostic is created and output it.  
This would make it easier to find the specific instance, and verify all 
instances are actually tested.  Currently, it's almost impossible to determine 
if all instances are actually tested.
3. keep track of the permutations and make sure each one is tested.


https://reviews.llvm.org/D35175

Files:
  include/clang/Basic/DiagnosticIDs.h
  include/clang/Basic/DiagnosticOptions.def
  include/clang/Driver/Options.td
  lib/Basic/DiagnosticIDs.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/TextDiagnosticPrinter.cpp

Index: lib/Frontend/TextDiagnosticPrinter.cpp
===
--- lib/Frontend/TextDiagnosticPrinter.cpp
+++ lib/Frontend/TextDiagnosticPrinter.cpp
@@ -19,6 +19,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Signals.h"
 #include 
 using namespace clang;
 
@@ -103,6 +104,13 @@
   }
 }
   }
+  // If the user wants to see diagnostic ids, include it too.
+  if (DiagOpts.ShowDiagIDs) {
+OS << (Started ? "," : " [");
+Started = true;
+OS << DiagnosticIDs::getDiagIDName(Info.getID()) << ":" << Info.getID();
+  }
+
   if (Started)
 OS << ']';
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1079,6 +1079,8 @@
   << ShowCategory;
   }
 
+  Opts.ShowDiagIDs = Args.hasArg(OPT_fdiagnostics_show_diag_ids);
+
   StringRef Format =
 Args.getLastArgValue(OPT_fdiagnostics_format, "clang");
   if (Format == "clang")
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4046,6 +4046,11 @@
 CmdArgs.push_back(A->getValue());
   }
 
+  if (Args.hasFlag(options::OPT_fdiagnostics_show_diag_ids,
+   options::OPT_fno_diagnostics_show_diag_ids, false)) {
+CmdArgs.push_back("-fdiagnostics-show-diag-ids");
+  }
+
   if (Args.hasFlag(options::OPT_fdiagnostics_show_hotness,
options::OPT_fno_diagnostics_show_hotness, false))
 CmdArgs.push_back("-fdiagnostics-show-hotness");
Index: lib/Basic/DiagnosticIDs.cpp
===
--- lib/Basic/DiagnosticIDs.cpp
+++ lib/Basic/DiagnosticIDs.cpp
@@ -37,6 +37,7 @@
 };
 
 struct StaticDiagInfoRec {
+  const char *IDName;
   uint16_t DiagID;
   unsigned DefaultSeverity : 3;
   unsigned Class : 3;
@@ -74,8 +75,9 @@
 #define DIAG(ENUM, CLASS, DEFAULT_SEVERITY, DESC, GROUP, SFINAE, NOWERROR, \
  SHOWINSYSHEADER, CATEGORY)\
   {\
-diag::ENUM, DEFAULT_SEVERITY, CLASS, DiagnosticIDs::SFINAE, NOWERROR,  \
-SHOWINSYSHEADER, CATEGORY, GROUP, STR_SIZE(DESC, uint16_t), DESC   \
+#ENUM, diag::ENUM, DEFAULT_SEVERITY, CLASS, DiagnosticIDs::SFINAE, \
+NOWERROR, SHOWINSYSHEADER, CATEGORY, GROUP, STR_SIZE(DESC, uint16_t),  \
+DESC   \
   }\
   ,
 #include "clang/Basic/DiagnosticCommonKinds.inc"
@@ -179,6 +181,12 @@
   return 0;
 }
 
+StringRef DiagnosticIDs::getDiagIDName(unsigned DiagID) {
+  if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
+return StringRef(Info->IDName);
+  return StringRef();
+}
+
 namespace {
   // The diagnostic category names.
   struct StaticDiagCategoryRec {
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -742,6 +742,10 @@
 Group,  Flags<[CC1Option]>, HelpText<"Display include stacks for diagnostic notes">;
 def fdiagnostics_format_EQ : Joined<["-"], "fdiagnostics-format=">, Group;
 def fdiagnostics_show_category_EQ : Joined<["-"], "fdiagnostics-show-category=">, Group;
+def fdiagnostics_show_diag_ids : Flag<["-"], "fdiagnostics-show-diag-ids">,
+Group, Flags<[CC1Option]>;
+def fno_diagnostics_show_diag_ids : Flag<["-"], "fno-diagnostics-show-diag-ids">,
+Group, Flags<[CC1Option]>;
 def fdiagnostics_show_template_tree : Flag<["-"], 

[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-07-09 Thread wangxin via Phabricator via cfe-commits
wangxindsb updated this revision to Diff 105760.
wangxindsb marked an inline comment as done.
wangxindsb added a comment.

- Use the map of object to ctor/dtor to check the virtual call.
- Use CXXInstanceCall and getCXXThisVal method to get the 'this' instead of 
getThisSVal().
- Correct some format errors.


https://reviews.llvm.org/D34275

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

Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -1,79 +1,43 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
-/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable
-   from a constructor or destructor. If it is not set, we expect diagnostics
-   only in the constructor or destructor.
-
-   When PUREONLY is set, we expect diagnostics only for calls to pure virtual
-   functions not to non-pure virtual functions.
-*/
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
 class A {
 public:
   A();
-  A(int i);
 
   ~A() {};
   
-  virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}}
-  virtual void bar() = 0;
+  virtual int foo()=0;
+  virtual void bar()=0;
   void f() {
 foo();
-#if INTERPROCEDURAL
-// expected-warning-re@-2 ^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}}
-#endif
+// expected-warning:Call to virtual function during construction
   }
 };
 
 class B : public A {
 public:
   B() {
 foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-// expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-// expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
-
+// expected-warning:Call to virtual function during construction
   }
   ~B();
   
   virtual int foo();
   virtual void bar() { foo(); }
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}}
-#endif
+  // expected-warning:Call to virtual function during destruction
 };
 
 A::A() {
   f();
 }
 
-A::A(int i) {
-  foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}}
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}}
-#else
-  // expected-warning-re@-4 ^}}Call to pure virtual function during construction has undefined behavior}}
-#endif
-}
-
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
   this->foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during destruction will not dispatch to derived class}}
-#endif
-#endif
-
+  // expected-warning:Call to virtual function during destruction
 }
 
 class C : public B {
@@ -87,13 +51,7 @@
 
 C::C() {
   f(foo());
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 class D : public B {
@@ -103,7 +61,8 @@
   }
   ~D() { bar(); }
   int foo() final;
-  void bar() final { foo(); } // no-warning
+  void bar() final { foo(); } 
+  // no-warning
 };
 
 class E final : public B {
@@ -115,7 +74,6 @@
   int foo() override;
 };
 
-// Regression test: don't crash when there's no direct callee.
 class F {
 public:
   F() {
@@ -125,17 +83,96 @@
   void foo();
 };
 
-int main() {
-  A *a;
-  B *b;
-  C *c;
-  D *d;
-  E *e;
-  F *f;
+class G {
+public:
+  virtual void bar();
+  void foo() {
+bar();
+  // no warning
+  }
+};
+
+class H{
+public:
+  H() : initState(0) { init(); }
+  int initState;
+  virtual void f() const;
+  void init() {
+if 

[PATCH] D33365: [clang-tidy] misc-assertion-count: A New Check

2017-07-09 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D33365#775916, @alexfh wrote:

> In https://reviews.llvm.org/D33365#775880, @lebedev.ri wrote:
>
> > In https://reviews.llvm.org/D33365#775860, @alexfh wrote:
> >
> > > I guess, this check should go to `readability` or elsewhere, but 
> > > definitely not to `misc`.
> >
> >
> > Hmm, `misc` may be a bad place for this, but i think `readability` is even 
> > worse fit.
> >  The best guess would be something like `hardening` / `security`, but there 
> > is no such category.
>
>
> `readability` might be reasonable, since one of the most important functions 
> of asserts is documenting invariants. The second function is enforcing 
> invariants, but in correct code asserts are basically no-ops, and they fire 
> only when the code is being changed and the invariants become broken.


Ok, got it.

>>> Another big question is whether it's reasonable to set up specific ratio 
>>> limits on the density of asserts. I think, density of asserts strongly 
>>> depends on the nature of the code, and there is no single answer to how 
>>> much asserts should be used. IIUC, neither of the recommendations you 
>>> mentioned contain any quantitative measures, they just delegate the 
>>> decision to the developer.
>> 
>> No, it is not reasonable to set up **default** ratio limits on the density 
>> of asserts.
>>  That is exactly why the default params are NOP, and i even made sure that 
>> if the params are NOP, this check will not add any overhead (no PPCallback, 
>> no matchers).
>> 
>> Did that answer your question?
> 
> No, I'm not talking about default ratio limits. I wonder whether there's any 
> specific combination of the options that would serve well to the needs of any 
> real project. I suspect that the number of lines in a function alone is 
> insufficient to determine reasonable limits on the number of asserts in it. I 
> guess, if it's even possible to find out the number of invariants that is 
> valuable to enforce in a certain function, a much larger set of inputs should 
> be considered. One little example is that many functions check whether their 
> pointer arguments are not null. Thus, a function that has no pointer 
> arguments will naturally require fewer asserts.
> 
> The only relevant formalized rule I found, is the JPL's rule 16 you refer to 
> (functions with more than 10 LOCs should have at least one assertion). But it 
> doesn't go further and say how many assertions should be in a function with, 
> say, 30 lines of code (I think, because it would be rather difficult to 
> formalize all the different situations).
> 
> I think, this kind of a check needs some prior research (not necessarily in 
> the sense of a printed paper, but at least a thoughtful analysis of the 
> relevant metrics on real code bases)  to back up the specific way the 
> sufficiency of asserts is determined.

While might be slightly unrelated(?), there is obviously a Cyclomatic 
Complexity, and a Cognitive Complexity, from SonarQube 
.
The latter one **might** actually be interesting to have in 
`readability-function-size` or a separate check... Not sure if there are 
restrictions on the algorithm though.

>>> I'm not saying it's impossible to find good formalization of these rules, 
>>> but I'd expect some sort of analysis of existing codebases with regard to 
>>> how asserts are used (not just the density of asserts, but also positioning 
>>> of asserts and what is being checked by the asserts) in different types of 
>>> code.




Repository:
  rL LLVM

https://reviews.llvm.org/D33365



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


[PATCH] D35159: [libcxxabi][demangler] Use an AST to represent the demangled name

2017-07-09 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington marked 4 inline comments as done.
erik.pilkington added inline comments.



Comment at: src/cxa_demangle.cpp:44
 
+class string_ref
+{

mehdi_amini wrote:
> If this is supposed to be *the* ultimate LLVM demangler, can we follow LLVM 
> coding standard?
I would like if this followed LLVM conventions too, but this file is already 
written following this style and leaving it in some middle state would be ugly. 
All of libcxx[abi] follows this convention too, so this isn't a problem that is 
isolated to this file.



Comment at: src/cxa_demangle.cpp:239
+virtual void print_left(stream& s) const = 0;
+virtual void print_right(stream&) const {}
+

mehdi_amini wrote:
> Why is one pure virtual and not the other? Why isn't the stream const?
The second isn't pure virtual because its only implemented by nodes that have a 
part that goes on the right of the declarator, such as array types or functions 
types, but every node should implements print_left. The stream is where the AST 
is printed into, so making it const doesn't make sense. I renamed it to 
output_stream and wrote a comment to make this more clear in the new patch.


https://reviews.llvm.org/D35159



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


[PATCH] D35174: [libc++] Fix unrepresentable enum for clang-cl unstable ABI

2017-07-09 Thread Ben Craig via Phabricator via cfe-commits
bcraig created this revision.

When using LIBCXX_ABI_UNSTABLE=YES, clang-cl gave the following warning:

P:\llvm_master\src\llvm\projects\libcxx\include\string(683,51):
warning: enumerator value is not representable in the underlying type
'int' [-Wmicrosoft-enum-value]

Fixed by providing a sufficiently large representation, so long as C++11
strong enums are available.


https://reviews.llvm.org/D35174

Files:
  include/__config
  include/string


Index: include/string
===
--- include/string
+++ include/string
@@ -680,7 +680,7 @@
 enum {__long_mask  = 0x1ul};
 #else  // _LIBCPP_BIG_ENDIAN
 enum {__short_mask = 0x80};
-enum {__long_mask  = ~(size_type(~0) >> 1)};
+enum _LIBCPP_UNDERLYING_ENUM_TYPE(size_type) {__long_mask  = 
~(size_type(~0) >> 1)};
 #endif  // _LIBCPP_BIG_ENDIAN
 
 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
@@ -707,7 +707,7 @@
 
 #if _LIBCPP_BIG_ENDIAN
 enum {__short_mask = 0x80};
-enum {__long_mask  = ~(size_type(~0) >> 1)};
+enum _LIBCPP_UNDERLYING_ENUM_TYPE(size_type) {__long_mask  = 
~(size_type(~0) >> 1)};
 #else  // _LIBCPP_BIG_ENDIAN
 enum {__short_mask = 0x01};
 enum {__long_mask  = 0x1ul};
Index: include/__config
===
--- include/__config
+++ include/__config
@@ -849,9 +849,11 @@
 _LIBCPP_ALWAYS_INLINE explicit x(int __v) : __v_(static_cast<__lx>(__v)) 
{} \
 _LIBCPP_ALWAYS_INLINE operator int() const {return __v_;} \
 };
+#define _LIBCPP_UNDERLYING_ENUM_TYPE(t)
 #else  // _LIBCPP_HAS_NO_STRONG_ENUMS
 #define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x
 #define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
+#define _LIBCPP_UNDERLYING_ENUM_TYPE(t) : t
 #endif  // _LIBCPP_HAS_NO_STRONG_ENUMS
 
 #ifdef _LIBCPP_DEBUG


Index: include/string
===
--- include/string
+++ include/string
@@ -680,7 +680,7 @@
 enum {__long_mask  = 0x1ul};
 #else  // _LIBCPP_BIG_ENDIAN
 enum {__short_mask = 0x80};
-enum {__long_mask  = ~(size_type(~0) >> 1)};
+enum _LIBCPP_UNDERLYING_ENUM_TYPE(size_type) {__long_mask  = ~(size_type(~0) >> 1)};
 #endif  // _LIBCPP_BIG_ENDIAN
 
 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
@@ -707,7 +707,7 @@
 
 #if _LIBCPP_BIG_ENDIAN
 enum {__short_mask = 0x80};
-enum {__long_mask  = ~(size_type(~0) >> 1)};
+enum _LIBCPP_UNDERLYING_ENUM_TYPE(size_type) {__long_mask  = ~(size_type(~0) >> 1)};
 #else  // _LIBCPP_BIG_ENDIAN
 enum {__short_mask = 0x01};
 enum {__long_mask  = 0x1ul};
Index: include/__config
===
--- include/__config
+++ include/__config
@@ -849,9 +849,11 @@
 _LIBCPP_ALWAYS_INLINE explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
 _LIBCPP_ALWAYS_INLINE operator int() const {return __v_;} \
 };
+#define _LIBCPP_UNDERLYING_ENUM_TYPE(t)
 #else  // _LIBCPP_HAS_NO_STRONG_ENUMS
 #define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x
 #define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
+#define _LIBCPP_UNDERLYING_ENUM_TYPE(t) : t
 #endif  // _LIBCPP_HAS_NO_STRONG_ENUMS
 
 #ifdef _LIBCPP_DEBUG
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35169: Refactor DragonFly BSD toolchain driver.

2017-07-09 Thread Rimvydas via Phabricator via cfe-commits
rimvydas created this revision.
Herald added a subscriber: emaste.

Make it more similar to FreeBSD one to reduce differences.
In preparations for later submissions.

While there, add more handling of flags (including OpenMP 
https://reviews.llvm.org/D35129).


https://reviews.llvm.org/D35169

Files:
  lib/Driver/ToolChains/DragonFly.cpp
  lib/Driver/ToolChains/DragonFly.h

Index: lib/Driver/ToolChains/DragonFly.h
===
--- lib/Driver/ToolChains/DragonFly.h
+++ lib/Driver/ToolChains/DragonFly.h
@@ -11,12 +11,13 @@
 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_DRAGONFLY_H
 
 #include "Gnu.h"
-#include "clang/Driver/Tool.h"
+#include "clang/Driver/Driver.h"
 #include "clang/Driver/ToolChain.h"
 
 namespace clang {
 namespace driver {
 namespace tools {
+
 /// dragonfly -- Directly call GNU Binutils assembler and linker
 namespace dragonfly {
 class LLVM_LIBRARY_VISIBILITY Assembler : public GnuTool {
Index: lib/Driver/ToolChains/DragonFly.cpp
===
--- lib/Driver/ToolChains/DragonFly.cpp
+++ lib/Driver/ToolChains/DragonFly.cpp
@@ -10,7 +10,6 @@
 #include "DragonFly.h"
 #include "CommonArgs.h"
 #include "clang/Driver/Compilation.h"
-#include "clang/Driver/Driver.h"
 #include "clang/Driver/Options.h"
 #include "llvm/Option/ArgList.h"
 
@@ -54,21 +53,37 @@
  const InputInfoList ,
  const ArgList ,
  const char *LinkingOutput) const {
-  const Driver  = getToolChain().getDriver();
+  const toolchains::DragonFly  =
+  static_cast(getToolChain());
+  const Driver  = ToolChain.getDriver();
+  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const bool IsPIE =
+  !Args.hasArg(options::OPT_shared) && Args.hasArg(options::OPT_pie);
   ArgStringList CmdArgs;
 
+  // Silence warning for "clang -g foo.o -o foo"
+  Args.ClaimAllArgs(options::OPT_g_Group);
+  // and "clang -emit-llvm foo.o -o foo"
+  Args.ClaimAllArgs(options::OPT_emit_llvm);
+  // and for "clang -w foo.o -o foo". Other warning options are already
+  // handled somewhere else.
+  Args.ClaimAllArgs(options::OPT_w);
+
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
+  if (IsPIE)
+CmdArgs.push_back("-pie");
+
   CmdArgs.push_back("--eh-frame-hdr");
   if (Args.hasArg(options::OPT_static)) {
 CmdArgs.push_back("-Bstatic");
   } else {
 if (Args.hasArg(options::OPT_rdynamic))
   CmdArgs.push_back("-export-dynamic");
-if (Args.hasArg(options::OPT_shared))
+if (Args.hasArg(options::OPT_shared)) {
   CmdArgs.push_back("-Bshareable");
-else {
+} else {
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/usr/libexec/ld-elf.so.2");
 }
@@ -78,7 +93,7 @@
 
   // When building 32-bit code on DragonFly/pc64, we have to explicitly
   // instruct ld in the base system to link 32-bit code.
-  if (getToolChain().getArch() == llvm::Triple::x86) {
+  if (Arch == llvm::Triple::x86) {
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf_i386");
   }
@@ -91,43 +106,52 @@
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+const char *crt1 = nullptr;
 if (!Args.hasArg(options::OPT_shared)) {
   if (Args.hasArg(options::OPT_pg))
-CmdArgs.push_back(
-Args.MakeArgString(getToolChain().GetFilePath("gcrt1.o")));
-  else {
-if (Args.hasArg(options::OPT_pie))
-  CmdArgs.push_back(
-  Args.MakeArgString(getToolChain().GetFilePath("Scrt1.o")));
-else
-  CmdArgs.push_back(
-  Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
-  }
+crt1 = "gcrt1.o";
+  else if (IsPIE)
+crt1 = "Scrt1.o";
+  else
+crt1 = "crt1.o";
 }
-CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
-if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
-  CmdArgs.push_back(
-  Args.MakeArgString(getToolChain().GetFilePath("crtbeginS.o")));
+if (crt1)
+  CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crt1)));
+
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
+
+const char *crtbegin = nullptr;
+if (Args.hasArg(options::OPT_shared) || IsPIE)
+  crtbegin = "crtbeginS.o";
 else
-  CmdArgs.push_back(
-  Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
+  crtbegin = "crtbegin.o";
+
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
   }
 
-  Args.AddAllArgs(CmdArgs,
-  {options::OPT_L, options::OPT_T_Group, options::OPT_e});
+  Args.AddAllArgs(CmdArgs, options::OPT_L);
+  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
+  Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
+  Args.AddAllArgs(CmdArgs, options::OPT_e);

[PATCH] D34724: [analyzer] Add MagentaHandleChecker for the Magenta kernel

2017-07-09 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Thanks for publishing this. It seems that your code is already huge, and you 
have already added a lot of workarounds for various problems (known and new) in 
our APIs, while it'd sound great to actually solve these problems and simplify 
the API to make writing checkers easier (as in 
http://lists.llvm.org/pipermail/cfe-dev/2017-June/054457.html ). This technical 
debt seems to slow down any progress on the checkers dramatically - and i'm 
totally sorry about that.




Comment at: lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp:22-49
+//  mx_channel_write failed
+//+-+
+//| |
+//| |
+//| |  As argument
+//  mx_channel_create succeeded +-+-v-+in uninlined   +-+
+//  mx_channel_read succeeded   | |calls  | |

I wish all checkers had these :3



Comment at: lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp:219
+CallKind
+MagentaHandleChecker::CheckCallSignature(const FunctionDecl *FuncDecl) const {
+  if (!FuncDecl)

We're trying to use this `CallDescription` thing for this purpose recently.



Comment at: lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp:297-303
+const SymbolDerived *ElementSym = dyn_cast(Sym);
+if (!ElementSym)
+  continue;
+
+const SymbolRef ParentSymbol = ElementSym->getParentSymbol();
+if (Escaped.count(ParentSymbol) == 1)
+  EscapedSymbolRef.push_back(Sym);

Uhm, yet another unobvious boilerplate that shows us that checker API needs to 
be made a lot easier. Not many checkers need this, but i suspect that 
`PthreadLockChecker` may suffer from the same problem.



Comment at: lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp:326-339
+  int64_t ExtVal;
+  if (ExprSVal.getBaseKind() == SVal::NonLocKind &&
+  ExprSVal.getSubKind() == nonloc::ConcreteIntKind) {
+ExtVal = ExprSVal.castAs().getValue().getExtValue();
+  } else if (ExprSVal.getBaseKind() == SVal::LocKind &&
+ ExprSVal.getSubKind() == loc::ConcreteIntKind) {
+ExtVal = ExprSVal.castAs().getValue().getExtValue();

This code can be simplified to `return !State->assume(ExprSVal, true);`, which 
also works for symbolic `SVal`s (eg. as in `CheckSymbolConstraintToNotZero`).



Comment at: lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp:373-376
+  for (auto  : TrackedHandle) {
+SymbolRef Sym = CurItem.first;
+// Workaround for zombie symbol issue.
+bool IsSymDead = SymReaper.maybeDead(Sym);

This may work as well, yeah.



Comment at: lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp:456-457
+  // arguments is an acquired handle, treat it as an escaped handle.
+  // This is just a naive approach to reduce the false positive rate, should
+  // be refined later, e.g. through annotation
+  // TODO: Use annotation to make it more accurate.

This should be fixed by allowing `checkPointerEscape` report non-pointer 
escapes, or making a separate callback for non-pointer escapes. This huge 
boilerplate shouldn't be repeated in every checker that needs it.

Annotations are still great though.



Comment at: lib/StaticAnalyzer/Checkers/MagentaHandleChecker.cpp:606-607
+
+  Ctx.addTransition(State);
+  Ctx.addTransition(FailedState);
+

While this is the easiest thing to do, it halves the analyzer performance every 
time it happens, exploding the complexity exponentially - because the remaining 
path would be split up into two paths, which are analyzed independently.

So it is really really rarely a good idea to split the state in the checker.

The alternative approach would be to delay splitting the state now, and only do 
that when it starts to matter. This is annoying to implement, but this may 
work. An example of this would be how we handled failed `pthread_mutex_destroy` 
in http://lists.llvm.org/pipermail/cfe-dev/2017-April/053567.html / 
https://reviews.llvm.org/D32449 .


https://reviews.llvm.org/D34724



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


[PATCH] D35172: Keep the IdentifierInfo in the Token for alternative operator keyword

2017-07-09 Thread Olivier Goffart via Phabricator via cfe-commits
ogoffart created this revision.
Herald added a subscriber: klimek.

The goal of this commit is to fix clang-format so it does not merge tokens when
using the alternative spelling keywords. (eg: "not foo" should not become 
"notfoo")

The problem is that Preprocessor::HandleIdentifier used to drop the identifier 
info
from the token for these keyword. This means the first condition of
TokenAnnotator::spaceRequiredBefore is not met. We could add explicit check for
the spelling in that condition, but I think it is better to keep the 
IdentifierInfo
and handle the operator keyword explicitly when needed. That actually leads to 
simpler
code, and probably slightly more efficient as well.

Another side effect of this change is that __identifier(and) will now work as
one would expect, removing a FIXME from the MicrosoftExtensions.cpp test


https://reviews.llvm.org/D35172

Files:
  include/clang/Basic/IdentifierTable.h
  lib/Lex/PPDirectives.cpp
  lib/Lex/PPExpressions.cpp
  lib/Lex/Preprocessor.cpp
  test/Parser/MicrosoftExtensions.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -333,6 +333,16 @@
   verifyFormat("x = (a) xor (b);");
 }
 
+TEST_F(FormatTest, RecognizesUnaryOperatorKeywords) {
+  verifyFormat("x = compl(a);");
+  verifyFormat("x = not(a);");
+  verifyFormat("x = bitand(a);");
+  // Unary operator must not be merged with the next identifier
+  verifyFormat("x = compl a;");
+  verifyFormat("x = not a;");
+  verifyFormat("x = bitand a;");
+}
+
 //===--===//
 // Tests for control statements.
 //===--===//
Index: test/Parser/MicrosoftExtensions.cpp
===
--- test/Parser/MicrosoftExtensions.cpp
+++ test/Parser/MicrosoftExtensions.cpp
@@ -261,9 +261,7 @@
 #define identifier_weird(x) __identifier(x
 int k = identifier_weird(if)); // expected-error {{use of undeclared identifier 'if'}}
 
-// This is a bit weird, but the alternative tokens aren't keywords, and this
-// behavior matches MSVC. FIXME: Consider supporting this anyway.
-extern int __identifier(and) r; // expected-error {{cannot convert '&&' token to an identifier}}
+extern int __identifier(and);
 
 void f() {
   __identifier(() // expected-error {{cannot convert '(' token to an identifier}}
Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -712,14 +712,6 @@
 II.setIsFutureCompatKeyword(false);
   }
 
-  // C++ 2.11p2: If this is an alternative representation of a C++ operator,
-  // then we act as if it is the actual operator and not the textual
-  // representation of it.
-  if (II.isCPlusPlusOperatorKeyword() &&
-  !(getLangOpts().MSVCCompat &&
-getSourceManager().isInSystemHeader(Identifier.getLocation(
-Identifier.setIdentifierInfo(nullptr);
-
   // If this is an extension token, diagnose its use.
   // We avoid diagnosing tokens that originate from macro definitions.
   // FIXME: This warning is disabled in cases where it shouldn't be,
Index: lib/Lex/PPExpressions.cpp
===
--- lib/Lex/PPExpressions.cpp
+++ lib/Lex/PPExpressions.cpp
@@ -237,35 +237,30 @@
 PP.setCodeCompletionReached();
 PP.LexNonComment(PeekTok);
   }
-  
-  // If this token's spelling is a pp-identifier, check to see if it is
-  // 'defined' or if it is a macro.  Note that we check here because many
-  // keywords are pp-identifiers, so we can't check the kind.
-  if (IdentifierInfo *II = PeekTok.getIdentifierInfo()) {
-// Handle "defined X" and "defined(X)".
-if (II->isStr("defined"))
-  return EvaluateDefined(Result, PeekTok, DT, ValueLive, PP);
-
-// If this identifier isn't 'defined' or one of the special
-// preprocessor keywords and it wasn't macro expanded, it turns
-// into a simple 0, unless it is the C++ keyword "true", in which case it
-// turns into "1".
-if (ValueLive &&
-II->getTokenID() != tok::kw_true &&
-II->getTokenID() != tok::kw_false)
-  PP.Diag(PeekTok, diag::warn_pp_undef_identifier) << II;
-Result.Val = II->getTokenID() == tok::kw_true;
-Result.Val.setIsUnsigned(false);  // "0" is signed intmax_t 0.
-Result.setIdentifier(II);
-Result.setRange(PeekTok.getLocation());
-DT.IncludedUndefinedIds = (II->getTokenID() != tok::kw_true &&
-   II->getTokenID() != tok::kw_false);
-PP.LexNonComment(PeekTok);
-return false;
-  }
 
   switch (PeekTok.getKind()) {
-  default:  // Non-value token.
+  default:
+// If this token's spelling is a pp-identifier, check to see if it is
+// 

[PATCH] D35170: [libcxx] Remove stray backticks from BuildingLibcxx.rst

2017-07-09 Thread Jakub Wilk via Phabricator via cfe-commits
jwilk created this revision.

https://reviews.llvm.org/D35170

Files:
  docs/BuildingLibcxx.rst


Index: docs/BuildingLibcxx.rst
===
--- docs/BuildingLibcxx.rst
+++ docs/BuildingLibcxx.rst
@@ -78,9 +78,9 @@
 
   $ cd where-you-want-libcxx-to-live
   $ # Check out llvm, libc++ and libc++abi.
-  $ ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm``
-  $ ``svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx``
-  $ ``svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi``
+  $ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
+  $ svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
+  $ svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
   $ cd where-you-want-to-build
   $ mkdir build && cd build
   $ export CC=clang CXX=clang++


Index: docs/BuildingLibcxx.rst
===
--- docs/BuildingLibcxx.rst
+++ docs/BuildingLibcxx.rst
@@ -78,9 +78,9 @@
 
   $ cd where-you-want-libcxx-to-live
   $ # Check out llvm, libc++ and libc++abi.
-  $ ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm``
-  $ ``svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx``
-  $ ``svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi``
+  $ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
+  $ svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
+  $ svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
   $ cd where-you-want-to-build
   $ mkdir build && cd build
   $ export CC=clang CXX=clang++
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-07-09 Thread wangxin via Phabricator via cfe-commits
wangxindsb updated this revision to Diff 105737.
wangxindsb added a comment.

- Change the two bugtype to one.
- Use the generateErrorNode() for the pure virtual call.
- Change the test case for the new expression.


https://reviews.llvm.org/D34275

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

Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -1,79 +1,43 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
-/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable
-   from a constructor or destructor. If it is not set, we expect diagnostics
-   only in the constructor or destructor.
-
-   When PUREONLY is set, we expect diagnostics only for calls to pure virtual
-   functions not to non-pure virtual functions.
-*/
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
 class A {
 public:
   A();
-  A(int i);
 
   ~A() {};
   
-  virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}}
-  virtual void bar() = 0;
+  virtual int foo()=0;
+  virtual void bar()=0;
   void f() {
 foo();
-#if INTERPROCEDURAL
-// expected-warning-re@-2 ^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}}
-#endif
+// expected-warning:Call to virtual function during construction
   }
 };
 
 class B : public A {
 public:
   B() {
 foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-// expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-// expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
-
+// expected-warning:Call to virtual function during construction
   }
   ~B();
   
   virtual int foo();
   virtual void bar() { foo(); }
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}}
-#endif
+  // expected-warning:Call to virtual function during destruction
 };
 
 A::A() {
   f();
 }
 
-A::A(int i) {
-  foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}}
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}}
-#else
-  // expected-warning-re@-4 ^}}Call to pure virtual function during construction has undefined behavior}}
-#endif
-}
-
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
   this->foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during destruction will not dispatch to derived class}}
-#endif
-#endif
-
+  // expected-warning:Call to virtual function during destruction
 }
 
 class C : public B {
@@ -87,13 +51,7 @@
 
 C::C() {
   f(foo());
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 class D : public B {
@@ -103,7 +61,8 @@
   }
   ~D() { bar(); }
   int foo() final;
-  void bar() final { foo(); } // no-warning
+  void bar() final { foo(); } 
+  // no-warning
 };
 
 class E final : public B {
@@ -115,7 +74,6 @@
   int foo() override;
 };
 
-// Regression test: don't crash when there's no direct callee.
 class F {
 public:
   F() {
@@ -125,17 +83,96 @@
   void foo();
 };
 
-int main() {
-  A *a;
-  B *b;
-  C *c;
-  D *d;
-  E *e;
-  F *f;
+class G {
+public:
+  virtual void bar();
+  void foo() {
+bar();
+  // no warning
+  }
+};
+
+class H{
+public:
+  H() : initState(0) { init(); }
+  int initState;
+  virtual void f() const;
+  void init() {
+if (initState)
+  f();
+  // no warning
+  }
+
+  H(int i) {
+G g;
+g.foo();
+

[PATCH] D34748: [clang-diff] Fix multiple mappings.

2017-07-09 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes added a comment.

In https://reviews.llvm.org/D34748#802037, @arphaman wrote:

> Can you provide a test that demonstrates what this change fixed/improved?


My bad, it looks like this does not improve anything yet. In order to do so I 
will use additional heuristics for similarity, like in the reference 
implementation.


https://reviews.llvm.org/D34748



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


[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-07-09 Thread wangxin via Phabricator via cfe-commits
wangxindsb updated this revision to Diff 105738.
wangxindsb added a comment.

- Change the two bugtype to one.
- Use the generateErrorNode() for the pure virtual call.
- Change the test case for the new expression.


https://reviews.llvm.org/D34275

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

Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -1,79 +1,43 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
-/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable
-   from a constructor or destructor. If it is not set, we expect diagnostics
-   only in the constructor or destructor.
-
-   When PUREONLY is set, we expect diagnostics only for calls to pure virtual
-   functions not to non-pure virtual functions.
-*/
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
 class A {
 public:
   A();
-  A(int i);
 
   ~A() {};
   
-  virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}}
-  virtual void bar() = 0;
+  virtual int foo()=0;
+  virtual void bar()=0;
   void f() {
 foo();
-#if INTERPROCEDURAL
-// expected-warning-re@-2 ^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}}
-#endif
+// expected-warning:Call to virtual function during construction
   }
 };
 
 class B : public A {
 public:
   B() {
 foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-// expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-// expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
-
+// expected-warning:Call to virtual function during construction
   }
   ~B();
   
   virtual int foo();
   virtual void bar() { foo(); }
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}}
-#endif
+  // expected-warning:Call to virtual function during destruction
 };
 
 A::A() {
   f();
 }
 
-A::A(int i) {
-  foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}}
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}}
-#else
-  // expected-warning-re@-4 ^}}Call to pure virtual function during construction has undefined behavior}}
-#endif
-}
-
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
   this->foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during destruction will not dispatch to derived class}}
-#endif
-#endif
-
+  // expected-warning:Call to virtual function during destruction
 }
 
 class C : public B {
@@ -87,13 +51,7 @@
 
 C::C() {
   f(foo());
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 class D : public B {
@@ -103,7 +61,8 @@
   }
   ~D() { bar(); }
   int foo() final;
-  void bar() final { foo(); } // no-warning
+  void bar() final { foo(); } 
+  // no-warning
 };
 
 class E final : public B {
@@ -115,7 +74,6 @@
   int foo() override;
 };
 
-// Regression test: don't crash when there's no direct callee.
 class F {
 public:
   F() {
@@ -125,17 +83,96 @@
   void foo();
 };
 
-int main() {
-  A *a;
-  B *b;
-  C *c;
-  D *d;
-  E *e;
-  F *f;
+class G {
+public:
+  virtual void bar();
+  void foo() {
+bar();
+  // no warning
+  }
+};
+
+class H{
+public:
+  H() : initState(0) { init(); }
+  int initState;
+  virtual void f() const;
+  void init() {
+if (initState)
+  f();
+  // no warning
+  }
+
+  H(int i) {
+G g;
+g.foo();
+

[PATCH] D35082: [WIP][OpenCL] Add LangAS::opencl_private to represent private address space in AST

2017-07-09 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 105733.
yaxunl edited the summary of this revision.
yaxunl added a comment.

Add private address space qualifier to automatic variable and function 
parameter. Update sema tests.

ToDo: drop address space when converting l-value to r-value.


https://reviews.llvm.org/D35082

Files:
  include/clang/Basic/AddressSpaces.h
  lib/AST/ASTContext.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGDecl.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenOpenCL/address-spaces-mangling.cl
  test/SemaOpenCL/access-qualifier.cl
  test/SemaOpenCL/address-spaces-conversions-cl2.0.cl
  test/SemaOpenCL/address-spaces.cl
  test/SemaOpenCL/arithmetic-conversions.cl
  test/SemaOpenCL/as_type.cl
  test/SemaOpenCL/cl20-device-side-enqueue.cl
  test/SemaOpenCL/event_t.cl
  test/SemaOpenCL/extension-begin.cl
  test/SemaOpenCL/half.cl
  test/SemaOpenCL/images.cl
  test/SemaOpenCL/invalid-block.cl
  test/SemaOpenCL/invalid-image.cl
  test/SemaOpenCL/invalid-kernel-parameters.cl
  test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
  test/SemaOpenCL/invalid-pipes-cl2.0.cl
  test/SemaOpenCL/null_queue.cl
  test/SemaOpenCL/queue_t_overload.cl
  test/SemaOpenCL/sampler_t.cl
  test/SemaOpenCL/shifts.cl
  test/SemaOpenCL/to_addr_builtin.cl
  test/SemaOpenCL/vec_step.cl
  test/SemaOpenCL/vector_conv_invalid.cl

Index: test/SemaOpenCL/vector_conv_invalid.cl
===
--- test/SemaOpenCL/vector_conv_invalid.cl
+++ test/SemaOpenCL/vector_conv_invalid.cl
@@ -7,7 +7,7 @@
 
 void vector_conv_invalid() {
   uint4 u = (uint4)(1);
-  int4 i = u; // expected-error{{initializing 'int4' (vector of 4 'int' values) with an expression of incompatible type 'uint4' (vector of 4 'unsigned int' values)}}
+  int4 i = u; // expected-error{{initializing '__private int4' (vector of 4 'int' values) with an expression of incompatible type '__private uint4' (vector of 4 'unsigned int' values)}}
   int4 e = (int4)u; // expected-error{{invalid conversion between ext-vector type 'int4' (vector of 4 'int' values) and 'uint4' (vector of 4 'unsigned int' values)}}
 
   uint3 u4 = (uint3)u; // expected-error{{invalid conversion between ext-vector type 'uint3' (vector of 3 'unsigned int' values) and 'uint4' (vector of 4 'unsigned int' values)}}
Index: test/SemaOpenCL/vec_step.cl
===
--- test/SemaOpenCL/vec_step.cl
+++ test/SemaOpenCL/vec_step.cl
@@ -26,7 +26,7 @@
   int res11[vec_step(int16) == 16 ? 1 : -1];
   int res12[vec_step(void) == 1 ? 1 : -1];
 
-  int res13 = vec_step(*incomplete1); // expected-error {{'vec_step' requires built-in scalar or vector type, 'struct S' invalid}}
-  int res14 = vec_step(int16*); // expected-error {{'vec_step' requires built-in scalar or vector type, 'int16 *' invalid}}
+  int res13 = vec_step(*incomplete1); // expected-error {{'vec_step' requires built-in scalar or vector type, '__private struct S' invalid}}
+  int res14 = vec_step(int16 *); // expected-error {{'vec_step' requires built-in scalar or vector type, '__private int16 *' invalid}}
   int res15 = vec_step(void(void)); // expected-error {{'vec_step' requires built-in scalar or vector type, 'void (void)' invalid}}
 }
Index: test/SemaOpenCL/to_addr_builtin.cl
===
--- test/SemaOpenCL/to_addr_builtin.cl
+++ test/SemaOpenCL/to_addr_builtin.cl
@@ -11,45 +11,45 @@
   glob = to_global(glob, loc);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
   // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
-  // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
+  // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-5{{invalid number of arguments to function: 'to_global'}}
 #endif
 
   int x;
   glob = to_global(x);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
-  // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
+  // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
-  // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
+  // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *__private' from 'int'}}
 #else
   // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}}
 #endif
 
   glob = to_global(con_typedef);
 #if __OPENCL_C_VERSION__ < 

[PATCH] D35159: [libcxxabi][demangler] Use an AST to represent the demangled name

2017-07-09 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added inline comments.



Comment at: src/cxa_demangle.cpp:44
 
+class string_ref
+{

If this is supposed to be *the* ultimate LLVM demangler, can we follow LLVM 
coding standard?


https://reviews.llvm.org/D35159



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


[PATCH] D35046: [coroutines] Include "this" type when looking up coroutine_traits

2017-07-09 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF requested changes to this revision.
EricWF added a comment.
This revision now requires changes to proceed.

I think the test could be improved. First could you add the test within 
`test/SemaCXX/coroutines.cpp`? Second could you add some negative tests that 
check the diagnostics generated when you don't provide a specialization of 
coroutine traits (ie that the old behaviour of not including the class type now 
produces diagnostics). Could you also add tests for const/volatile and 
lvalue/rvalue qualified member functions?




Comment at: lib/Sema/SemaCoroutine.cpp:85
+if (MD->isInstance()) {
+  QualType T = MD->getThisType(S.Context);
+  Args.addArgument(TemplateArgumentLoc(

This seems wrong to me.

`getThisType` returns the type of the `this` parameter as specified under 
[class.this] but according to the coroutines spec the type of the parameter 
should be the type of the `implicit object parameter`, which is specified under 
[[http://eel.is/c++draft/over.match.funcs#4 | (over.match.funcs) p4 ]].



Comment at: lib/Sema/SemaCoroutine.cpp:441
+  return false;
+  }();
 

Huh, I've never seen lambdas used like this before but I really like it.


https://reviews.llvm.org/D35046



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


[PATCH] D35159: [libcxxabi][demangler] Use an AST to represent the demangled name

2017-07-09 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

This patch causes `test_demangle.pass.cpp` to fail with UBSan.

  Standard Error:
  --
  /home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:113:44: runtime error: 
null pointer passed as argument 2, which is declared to never be null
  /usr/include/string.h:47:14: note: nonnull attribute specified here
  #0 0x7ff62aae12fb in __cxxabiv1::(anonymous 
namespace)::stream::operator+=(__cxxabiv1::(anonymous namespace)::string_ref) 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:113:9
  #1 0x7ff62aaf9494 in __cxxabiv1::(anonymous 
namespace)::lambda_type_name::print_left(__cxxabiv1::(anonymous 
namespace)::stream&) const 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:1135:11
  #2 0x7ff62aae711a in __cxxabiv1::(anonymous 
namespace)::node::print(__cxxabiv1::(anonymous namespace)::stream&) const 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:233:9
  #3 0x7ff62aae711a in __cxxabiv1::(anonymous 
namespace)::qualified_name::print_left(__cxxabiv1::(anonymous 
namespace)::stream&) const 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:837
  #4 0x7ff62aaf0da3 in __cxxabiv1::(anonymous 
namespace)::node::print(__cxxabiv1::(anonymous namespace)::stream&) const 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:233:9
  #5 0x7ff62aaf0da3 in __cxxabiv1::(anonymous 
namespace)::node_array::print_with_seperator(__cxxabiv1::(anonymous 
namespace)::stream&, __cxxabiv1::(anonymous namespace)::string_ref) const 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:266
  #6 0x7ff62aafa85d in __cxxabiv1::(anonymous 
namespace)::template_params::print_left(__cxxabiv1::(anonymous 
namespace)::stream&) const 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:901:16
  #7 0x7ff62aafaab1 in __cxxabiv1::(anonymous 
namespace)::node::print(__cxxabiv1::(anonymous namespace)::stream&) const 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:233:9
  #8 0x7ff62aafaab1 in __cxxabiv1::(anonymous 
namespace)::name_with_template_args::print_left(__cxxabiv1::(anonymous 
namespace)::stream&) const 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:926
  #9 0x7ff62aae70b9 in __cxxabiv1::(anonymous 
namespace)::node::print(__cxxabiv1::(anonymous namespace)::stream&) const 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:233:9
  #10 0x7ff62aae70b9 in __cxxabiv1::(anonymous 
namespace)::qualified_name::print_left(__cxxabiv1::(anonymous 
namespace)::stream&) const 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:834
  #11 0x7ff62aafb102 in __cxxabiv1::(anonymous 
namespace)::node::print(__cxxabiv1::(anonymous namespace)::stream&) const 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:233:9
  #12 0x7ff62aafb102 in __cxxabiv1::(anonymous 
namespace)::top_level_function_decl::print_left(__cxxabiv1::(anonymous 
namespace)::stream&) const 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:679
  #13 0x7ff62aad779f in __cxxabiv1::(anonymous 
namespace)::node::print(__cxxabiv1::(anonymous namespace)::stream&) const 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:233:9
  #14 0x7ff62aad779f in __cxa_demangle 
/home/eric/workspace/libcxxabi/src/cxa_demangle.cpp:6313
  #15 0x4218a8 in test() 
/home/eric/workspace/libcxxabi/test/test_demangle.pass.cpp:29682:24
  #16 0x422204 in main 
/home/eric/workspace/libcxxabi/test/test_demangle.pass.cpp:29761:9
  #17 0x7ff629f8c82f in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
  #18 0x403a78 in _start 
(/home/eric/workspace/build-libcxxabi/test/Output/test_demangle.pass.cpp.exe+0x403a78)

Other than that I don't see any issues with this change. Thanks for working on 
this.


https://reviews.llvm.org/D35159



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


[PATCH] D34331: func.wrap.func.con: Unset function before destroying anything

2017-07-09 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

> However there is another bug here. operator=(function&&) doesn't correctly 
> call the destructor of the functor. I'll fix that as a separate commit.

Woops, I misread the diff. There is no existing bug W.R.T. missing destructor 
calls.


https://reviews.llvm.org/D34331



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


[PATCH] D34331: func.wrap.func.con: Unset function before destroying anything

2017-07-09 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF requested changes to this revision.
EricWF added a comment.
This revision now requires changes to proceed.

@dexonsmith I'm not sure it's sane to allow reentrant behavior. Could you 
explain why you think it is? Should the copy assignment operator allow 
reentrancy as well?

However there is another bug here. `operator=(function&&)` doesn't correctly 
call the destructor of the functor. I'll fix that as a separate commit.


https://reviews.llvm.org/D34331



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


[PATCH] D34331: func.wrap.func.con: Unset function before destroying anything

2017-07-09 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

@dexonsmith Mind if I hijack this and check in your changes to `` 
with my tests?




Comment at: 
libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp:1
+//===--===//
+//

It seems like this test is testing behavior that should be required by the 
standard, right?

If so it should live under `test/std`.



Comment at: 
libcxx/test/libcxx/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/move_reentrant.pass.cpp:25
+  ~A() {
+asm("");
+if (cancel)

Is `asm("")` just to prevent optimizations? If so please use `DoNotOptimize` 
from `test_macros.h`.


https://reviews.llvm.org/D34331



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


[PATCH] D34725: Add sample PGO integration test to cover profile annotation and inlining.

2017-07-09 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh reopened this revision.
danielcdh added a comment.
This revision is now accepted and ready to land.

the patch was reverted as it breaks on certain platforms (e.g. 
http://lab.llvm.org:8011/builders/clang-hexagon-elf/builds/10088/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Apgo-sample.c)


https://reviews.llvm.org/D34725



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


[PATCH] D35158: [libcxxabi][demangler] NFC: Don't make everything a template

2017-07-09 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington created this revision.
Herald added a reviewer: EricWF.

This is a NFC patch to not make every parse_* function templated on Db, which 
makes it easier to use methods on Db because it isn't dependent anymore. This 
is a prerequisite to using an AST to demangle, as per this thread: 
http://lists.llvm.org/pipermail/llvm-dev/2017-June/114448.html

Thanks,
Erik


https://reviews.llvm.org/D35158

Files:
  src/cxa_demangle.cpp

Index: src/cxa_demangle.cpp
===
--- src/cxa_demangle.cpp
+++ src/cxa_demangle.cpp
@@ -41,23 +41,223 @@
 success
 };
 
-template 
-const char* parse_type(const char* first, const char* last, C& db);
-template 
-const char* parse_encoding(const char* first, const char* last, C& db);
-template 
-const char* parse_name(const char* first, const char* last, C& db,
-   bool* ends_with_template_args = 0);
-template 
-const char* parse_expression(const char* first, const char* last, C& db);
-template 
-const char* parse_template_args(const char* first, const char* last, C& db);
-template 
-const char* parse_operator_name(const char* first, const char* last, C& db);
-template 
-const char* parse_unqualified_name(const char* first, const char* last, C& db);
-template 
-const char* parse_decltype(const char* first, const char* last, C& db);
+template 
+class arena
+{
+static const std::size_t alignment = 16;
+alignas(alignment) char buf_[N];
+char* ptr_;
+
+std::size_t 
+align_up(std::size_t n) noexcept
+{return (n + (alignment-1)) & ~(alignment-1);}
+
+bool
+pointer_in_buffer(char* p) noexcept
+{return buf_ <= p && p <= buf_ + N;}
+
+public:
+arena() noexcept : ptr_(buf_) {}
+~arena() {ptr_ = nullptr;}
+arena(const arena&) = delete;
+arena& operator=(const arena&) = delete;
+
+char* allocate(std::size_t n);
+void deallocate(char* p, std::size_t n) noexcept;
+
+static constexpr std::size_t size() {return N;}
+std::size_t used() const {return static_cast(ptr_ - buf_);}
+void reset() {ptr_ = buf_;}
+};
+
+template 
+char*
+arena::allocate(std::size_t n)
+{
+n = align_up(n);
+if (static_cast(buf_ + N - ptr_) >= n)
+{
+char* r = ptr_;
+ptr_ += n;
+return r;
+}
+return static_cast(std::malloc(n));
+}
+
+template 
+void
+arena::deallocate(char* p, std::size_t n) noexcept
+{
+if (pointer_in_buffer(p))
+{
+n = align_up(n);
+if (p + n == ptr_)
+ptr_ = p;
+}
+else
+std::free(p);
+}
+
+template 
+class short_alloc
+{
+arena& a_;
+public:
+typedef T value_type;
+
+public:
+template  struct rebind {typedef short_alloc<_Up, N> other;};
+
+short_alloc(arena& a) noexcept : a_(a) {}
+template 
+short_alloc(const short_alloc& a) noexcept
+: a_(a.a_) {}
+short_alloc(const short_alloc&) = default;
+short_alloc& operator=(const short_alloc&) = delete;
+
+T* allocate(std::size_t n)
+{
+return reinterpret_cast(a_.allocate(n*sizeof(T)));
+}
+void deallocate(T* p, std::size_t n) noexcept
+{
+a_.deallocate(reinterpret_cast(p), n*sizeof(T));
+}
+
+template 
+friend
+bool
+operator==(const short_alloc& x, const short_alloc& y) noexcept;
+
+template  friend class short_alloc;
+};
+
+template 
+inline
+bool
+operator==(const short_alloc& x, const short_alloc& y) noexcept
+{
+return N == M && _ == _;
+}
+
+template 
+inline
+bool
+operator!=(const short_alloc& x, const short_alloc& y) noexcept
+{
+return !(x == y);
+}
+
+template 
+class malloc_alloc
+{
+public:
+typedef T value_type;
+typedef T& reference;
+typedef const T& const_reference;
+typedef T* pointer;
+typedef const T* const_pointer;
+typedef std::size_t size_type;
+typedef std::ptrdiff_t difference_type;
+
+malloc_alloc() = default;
+template  malloc_alloc(const malloc_alloc&) noexcept {}
+
+T* allocate(std::size_t n)
+{
+return static_cast(std::malloc(n*sizeof(T)));
+}
+void deallocate(T* p, std::size_t) noexcept
+{
+std::free(p);
+}
+
+template  struct rebind { using other = malloc_alloc; };
+template 
+void construct(U* p, Args&&... args)
+{
+::new ((void*)p) U(std::forward(args)...);
+}
+void destroy(T* p)
+{
+p->~T();
+}
+};
+
+template 
+inline
+bool
+operator==(const malloc_alloc&, const malloc_alloc&) noexcept
+{
+return true;
+}
+
+template 
+inline
+bool
+operator!=(const malloc_alloc& x, const malloc_alloc& y) noexcept
+{
+return !(x == y);
+}
+
+const size_t bs = 4 * 1024;
+template  using Alloc = short_alloc;
+template  using Vector = std::vector;
+
+template 
+struct string_pair
+{
+StrT first;
+StrT second;
+
+ 

[PATCH] D35158: [libcxxabi][demangler] NFC: Don't make everything a template

2017-07-09 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

Assuming nothing in `arena<>`...`Db` actually changed (just moved), this LGTM 
if you split the move into a separate prep commit.


https://reviews.llvm.org/D35158



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


[PATCH] D35153: Use DenseMap instead std::map for GVSummaryMapTy

2017-07-09 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh created this revision.
Herald added a subscriber: sanjoy.

Frontend change for https://reviews.llvm.org/D35148


https://reviews.llvm.org/D35153

Files:
  lib/CodeGen/BackendUtil.cpp


Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -998,7 +998,7 @@
   std::unique_ptr OS,
   std::string SampleProfile,
   BackendAction Action) {
-  StringMap>
+  StringMap>
   ModuleToDefinedGVSummaries;
   
CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
 


Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -998,7 +998,7 @@
   std::unique_ptr OS,
   std::string SampleProfile,
   BackendAction Action) {
-  StringMap>
+  StringMap>
   ModuleToDefinedGVSummaries;
   CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34725: Add sample PGO integration test to cover profile annotation and inlining.

2017-07-09 Thread David Li via Phabricator via cfe-commits
davidxl accepted this revision.
davidxl added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D34725



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


[PATCH] D34714: [MS] Don't statically initialize dllimport member function pointers

2017-07-09 Thread Reid Kleckner via Phabricator via cfe-commits
rnk commandeered this revision.
rnk edited reviewers, added: majnemer; removed: rnk.
rnk added a comment.

@majnemer will be back Monday, grabbing this.


https://reviews.llvm.org/D34714



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


[PATCH] D34725: Add sample PGO integration test to cover profile annotation and inlining.

2017-07-09 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh updated this revision to Diff 105705.
danielcdh marked an inline comment as done.
danielcdh added a comment.

Integrate David's comment and add new PM test.


https://reviews.llvm.org/D34725

Files:
  test/CodeGen/Inputs/pgo-sample.prof
  test/CodeGen/pgo-sample.c


Index: test/CodeGen/pgo-sample.c
===
--- test/CodeGen/pgo-sample.c
+++ test/CodeGen/pgo-sample.c
@@ -1,6 +1,34 @@
 // Test if PGO sample use passes are invoked.
 //
-// Ensure Pass PGOInstrumentationGenPass is invoked.
-// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s
-// CHECK: Remove unused exception handling info
-// CHECK: Sample profile pass
+// Ensure Pass SampleProfileLoader is invoked.
+// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s 
--check-prefix=STRUCTURE
+// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm -o - 2>&1 | 
FileCheck %s
+// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm 
-fexperimental-new-pass-manager -o - 2>&1 | FileCheck %s
+// STRUCTURE: Remove unused exception handling info
+// STRUCTURE: Sample profile pass
+
+void baz();
+
+// CHECK-LABEL: @callee(
+void callee(int t) {
+  for (int i = 0; i < t; i++)
+baz();
+}
+
+// CHECK-LABEL: @bar(
+// cold call to callee should not be inlined.
+// CHECK: call void @callee
+void bar(int x) {
+  if (x < 100)
+callee(x);
+}
+
+// CHECK-LABEL: @foo(
+// bar should be early-inlined because it is hot inline instance in profile.
+// callee should be inlined because it is hot callsite in the inline instance
+// of foo:bar.
+// CHECK-NOT: call void @callee
+// CHECK-NOT: call void @bar
+void foo(int x) {
+  bar(x);
+}
Index: test/CodeGen/Inputs/pgo-sample.prof
===
--- test/CodeGen/Inputs/pgo-sample.prof
+++ test/CodeGen/Inputs/pgo-sample.prof
@@ -1,2 +1,7 @@
-bar:100:100
- 1: 2000
+bar:1000:1000
+ 1: 1000
+ 2: 0
+foo:1000:1000
+ 1:bar:1000
+  1: 1000
+  2: 1000


Index: test/CodeGen/pgo-sample.c
===
--- test/CodeGen/pgo-sample.c
+++ test/CodeGen/pgo-sample.c
@@ -1,6 +1,34 @@
 // Test if PGO sample use passes are invoked.
 //
-// Ensure Pass PGOInstrumentationGenPass is invoked.
-// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s
-// CHECK: Remove unused exception handling info
-// CHECK: Sample profile pass
+// Ensure Pass SampleProfileLoader is invoked.
+// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=STRUCTURE
+// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm -o - 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -mllvm -inline-threshold=0 -emit-llvm -fexperimental-new-pass-manager -o - 2>&1 | FileCheck %s
+// STRUCTURE: Remove unused exception handling info
+// STRUCTURE: Sample profile pass
+
+void baz();
+
+// CHECK-LABEL: @callee(
+void callee(int t) {
+  for (int i = 0; i < t; i++)
+baz();
+}
+
+// CHECK-LABEL: @bar(
+// cold call to callee should not be inlined.
+// CHECK: call void @callee
+void bar(int x) {
+  if (x < 100)
+callee(x);
+}
+
+// CHECK-LABEL: @foo(
+// bar should be early-inlined because it is hot inline instance in profile.
+// callee should be inlined because it is hot callsite in the inline instance
+// of foo:bar.
+// CHECK-NOT: call void @callee
+// CHECK-NOT: call void @bar
+void foo(int x) {
+  bar(x);
+}
Index: test/CodeGen/Inputs/pgo-sample.prof
===
--- test/CodeGen/Inputs/pgo-sample.prof
+++ test/CodeGen/Inputs/pgo-sample.prof
@@ -1,2 +1,7 @@
-bar:100:100
- 1: 2000
+bar:1000:1000
+ 1: 1000
+ 2: 0
+foo:1000:1000
+ 1:bar:1000
+  1: 1000
+  2: 1000
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34725: Add sample PGO integration test to cover profile annotation and inlining.

2017-07-09 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh added inline comments.



Comment at: test/CodeGen/pgo-sample.c:28
+// of foo:bar.
+// CHECK-NOT: call void @callee
+void foo(int x) {

davidxl wrote:
> SHould this be 'CHECK-NOT:  call'  as bar is also inlined?
There is still call to baz. Explicitly added CHECK-NOT call bar.


https://reviews.llvm.org/D34725



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


[PATCH] D34588: Check for _MSC_VER before define _LIBCPP_MSVCRT

2017-07-09 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.



> Thinking more about this, on Windows, is there a strong reason to default to 
> a different libc by default on Windows?

I'm mostly concerned with `-fms-extensions` + darwin, which doesn't apply to 
this scenario, maybe someone else knows a better answer here.

> @bruno would reusing `-ffreestanding` work for you here?

I think forcing the use of `-ffreestanding` with Apple platforms just for this 
is too restrictive.

> Or is there something else that we can identify about the target environment 
> that can indicate that the MS CRT is unavailable?  I think that what is weird 
> to me about this is that this is not about compatibility with Visual Studio 
> but about the underlying libc.  It feels like it would be similar in spirit 
> to say that libc++ defaults to libSystem as the underlying libc on Linux.

Right, makes total sense. I'm assuming that `-fms-extensions` for other targets 
(Linux) will also rely in not using `_LIBCPP_MSVCRT`, however #ifdefing for 
other platforms here doens't seem to add much because they usually do not set 
`_MSC_VER` anyways. Additional ideas?


https://reviews.llvm.org/D34588



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


[PATCH] D34985: Do not read the file to determine its name.

2017-07-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Looks like most of the users of this function are detecting whether we're in 
the builtins buffer. Perhaps we should have a dedicated method for that which 
uses something more principled than a string comparison against ""?




Comment at: lib/Basic/SourceManager.cpp:1485
+
+  return getBuffer(FID, Invalid)->getBufferIdentifier();
 }

This repeats the FID -> SLocEntry lookup; if you manage to get a ContentCache 
above, perhaps call `getBuffer(...)->getBufferIdentifier()` on it directly?

(If you can't get a content cache, this code path will also fail and will 
produce the name "<<>>".)


Repository:
  rL LLVM

https://reviews.llvm.org/D34985



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


[PATCH] D34955: [Basic] Detect Git submodule version in CMake

2017-07-09 Thread Brian Gesiak via Phabricator via cfe-commits
modocache updated this revision to Diff 105674.
modocache edited the summary of this revision.
modocache removed a subscriber: pcc.
modocache added a comment.

Update commit message.


https://reviews.llvm.org/D34955

Files:
  lib/Basic/CMakeLists.txt


Index: lib/Basic/CMakeLists.txt
===
--- lib/Basic/CMakeLists.txt
+++ lib/Basic/CMakeLists.txt
@@ -15,8 +15,25 @@
 endfunction()
 
 macro(find_first_existing_vc_file out_var path)
+  set(git_path "${path}/.git")
+
+  # Normally '.git' is a directory that contains a 'logs/HEAD' file that
+  # is updated as modifications are made to the repository. In case the
+  # repository is a Git submodule, '.git' is a file that contains text that
+  # indicates where the repository's Git directory exists.
+  if (EXISTS "${git_path}" AND NOT IS_DIRECTORY "${git_path}")
+FILE(READ "${git_path}" file_contents)
+STRING(REGEX REPLACE "\n" "" file_contents "${file_contents}")
+if ("${file_contents}" MATCHES "^gitdir:")
+  # '.git' is indeed a link to the submodule's Git directory.
+  # Use the path to that Git directory.
+  STRING(REGEX REPLACE "gitdir: " "" file_contents ${file_contents})
+  set(git_path "${git_path}${file_contents}")
+endif()
+  endif()
+
   find_first_existing_file(${out_var}
-"${path}/.git/logs/HEAD" # Git
+"${git_path}/logs/HEAD"  # Git or Git submodule
 "${path}/.svn/wc.db" # SVN 1.7
 "${path}/.svn/entries"   # SVN 1.6
 )


Index: lib/Basic/CMakeLists.txt
===
--- lib/Basic/CMakeLists.txt
+++ lib/Basic/CMakeLists.txt
@@ -15,8 +15,25 @@
 endfunction()
 
 macro(find_first_existing_vc_file out_var path)
+  set(git_path "${path}/.git")
+
+  # Normally '.git' is a directory that contains a 'logs/HEAD' file that
+  # is updated as modifications are made to the repository. In case the
+  # repository is a Git submodule, '.git' is a file that contains text that
+  # indicates where the repository's Git directory exists.
+  if (EXISTS "${git_path}" AND NOT IS_DIRECTORY "${git_path}")
+FILE(READ "${git_path}" file_contents)
+STRING(REGEX REPLACE "\n" "" file_contents "${file_contents}")
+if ("${file_contents}" MATCHES "^gitdir:")
+  # '.git' is indeed a link to the submodule's Git directory.
+  # Use the path to that Git directory.
+  STRING(REGEX REPLACE "gitdir: " "" file_contents ${file_contents})
+  set(git_path "${git_path}${file_contents}")
+endif()
+  endif()
+
   find_first_existing_file(${out_var}
-"${path}/.git/logs/HEAD" # Git
+"${git_path}/logs/HEAD"  # Git or Git submodule
 "${path}/.svn/wc.db" # SVN 1.7
 "${path}/.svn/entries"   # SVN 1.6
 )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34158: to support gcc 4.8 (and newer) compatibility on Linux, preinclude

2017-07-09 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 105671.
mibintc added a comment.

I updated the patch as James directed, moving the preinclude of stdc-predef.h 
into clang.cpp and out of the Linux toolchain entirely.  I also needed to 
update a couple more tests in tools/extra, so I will need to update that 
related differential as well.


https://reviews.llvm.org/D34158

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/InitPreprocessor.cpp
  test/Driver/Inputs/stdc-predef/bin/.keep
  test/Driver/Inputs/stdc-predef/usr/i386-unknown-linux/lib/.keep
  test/Driver/Inputs/stdc-predef/usr/include/stdc-predef.h
  test/Driver/Inputs/stdc-predef/usr/lib/.keep
  test/Driver/Inputs/stdc-predef/usr/x86_64-unknown-linux/lib/.keep
  test/Driver/clang_cpp.c
  test/Driver/crash report spaces.c
  test/Driver/crash-report-header.h
  test/Driver/crash-report.c
  test/Driver/rewrite-legacy-objc.m
  test/Driver/rewrite-map-in-diagnostics.c
  test/Driver/rewrite-objc.m
  test/Driver/stdc-predef-not.c
  test/Driver/stdc-predef.c
  test/Index/IBOutletCollection.m
  test/Index/annotate-macro-args.m
  test/Index/annotate-tokens-pp.c
  test/Index/annotate-tokens.c
  test/Index/c-index-getCursor-test.m
  test/Index/get-cursor-macro-args.m
  test/Index/get-cursor.cpp
  test/Preprocessor/ignore-pragmas.c
  unittests/Tooling/TestVisitor.h

Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3175,6 +3175,13 @@
   KernelOrKext) {
 CmdArgs.push_back("-ffreestanding");
 IsHosted = false;
+  } else {
+if (!Args.hasArg(options::OPT_nostdinc)) {
+  // For standards compliance, clang will preinclude 
+  // -ffreestanding suppresses this behavior.
+  CmdArgs.push_back("-finclude-if-exists");
+  CmdArgs.push_back("stdc-predef.h");
+}
   }
 
   // Forward -f (flag) options which we can pass directly.
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2425,6 +2425,10 @@
   for (const Arg *A : Args.filtered(OPT_chain_include))
 Opts.ChainedIncludes.emplace_back(A->getValue());
 
+  // Add the ordered list of -finclude-if-exists.
+  for (const Arg *A : Args.filtered(OPT_finclude_if_exists))
+Opts.FIncludeIfExists.emplace_back(A->getValue());
+
   for (const Arg *A : Args.filtered(OPT_remap_file)) {
 std::pair Split = StringRef(A->getValue()).split(';');
 
Index: lib/Frontend/InitPreprocessor.cpp
===
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -69,6 +69,12 @@
   Builder.append(Twine("#include \"") + File + "\"");
 }
 
+static void AddImplicitIncludeIfExists(MacroBuilder , StringRef File) {
+  Builder.append(Twine("#if __has_include( \"") + File + "\")");
+  Builder.append(Twine("#include \"") + File + "\"");
+  Builder.append(Twine("#endif"));
+}
+
 static void AddImplicitIncludeMacros(MacroBuilder , StringRef File) {
   Builder.append(Twine("#__include_macros \"") + File + "\"");
   // Marker token to stop the __include_macros fetch loop.
@@ -1088,6 +1094,12 @@
   // Exit the command line and go back to  (2 is LC_LEAVE).
   if (!PP.getLangOpts().AsmPreprocessor)
 Builder.append("# 1 \"\" 2");
+  
+  // Process -finclude-if-exists directives.
+  for (unsigned i = 0, e = InitOpts.FIncludeIfExists.size(); i != e; ++i) {
+const std::string  = InitOpts.FIncludeIfExists[i];
+AddImplicitIncludeIfExists(Builder, Path);
+  }
 
   // If -imacros are specified, include them now.  These are processed before
   // any -include directives.
Index: unittests/Tooling/TestVisitor.h
===
--- unittests/Tooling/TestVisitor.h
+++ unittests/Tooling/TestVisitor.h
@@ -52,6 +52,7 @@
   /// \brief Runs the current AST visitor over the given code.
   bool runOver(StringRef Code, Language L = Lang_CXX) {
 std::vector Args;
+Args.push_back("-nostdinc");
 switch (L) {
   case Lang_C: Args.push_back("-std=c99"); break;
   case Lang_CXX98: Args.push_back("-std=c++98"); break;
Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -729,6 +729,8 @@
   HelpText<"Use specified token cache file">;
 def detailed_preprocessing_record : Flag<["-"], "detailed-preprocessing-record">,
   HelpText<"include a detailed record of preprocessing actions">;
+def finclude_if_exists : Separate<["-"], "finclude-if-exists">, MetaVarName<"">,
+  HelpText<"Include file before parsing if file exists">;
 
 

[PATCH] D34955: [Basic] Detect Git submodule version in CMake

2017-07-09 Thread Brian Gesiak via Phabricator via cfe-commits
modocache updated this revision to Diff 105673.
modocache added a comment.

Use submodule's .git directory.


https://reviews.llvm.org/D34955

Files:
  lib/Basic/CMakeLists.txt


Index: lib/Basic/CMakeLists.txt
===
--- lib/Basic/CMakeLists.txt
+++ lib/Basic/CMakeLists.txt
@@ -15,8 +15,25 @@
 endfunction()
 
 macro(find_first_existing_vc_file out_var path)
+  set(git_path "${path}/.git")
+
+  # Normally '.git' is a directory that contains a 'logs/HEAD' file that
+  # is updated as modifications are made to the repository. In case the
+  # repository is a Git submodule, '.git' is a file that contains text that
+  # indicates where the repository's Git directory exists.
+  if (EXISTS "${git_path}" AND NOT IS_DIRECTORY "${git_path}")
+FILE(READ "${git_path}" file_contents)
+STRING(REGEX REPLACE "\n" "" file_contents "${file_contents}")
+if ("${file_contents}" MATCHES "^gitdir:")
+  # '.git' is indeed a link to the submodule's Git directory.
+  # Use the path to that Git directory.
+  STRING(REGEX REPLACE "gitdir: " "" file_contents ${file_contents})
+  set(git_path "${git_path}${file_contents}")
+endif()
+  endif()
+
   find_first_existing_file(${out_var}
-"${path}/.git/logs/HEAD" # Git
+"${git_path}/logs/HEAD"  # Git or Git submodule
 "${path}/.svn/wc.db" # SVN 1.7
 "${path}/.svn/entries"   # SVN 1.6
 )


Index: lib/Basic/CMakeLists.txt
===
--- lib/Basic/CMakeLists.txt
+++ lib/Basic/CMakeLists.txt
@@ -15,8 +15,25 @@
 endfunction()
 
 macro(find_first_existing_vc_file out_var path)
+  set(git_path "${path}/.git")
+
+  # Normally '.git' is a directory that contains a 'logs/HEAD' file that
+  # is updated as modifications are made to the repository. In case the
+  # repository is a Git submodule, '.git' is a file that contains text that
+  # indicates where the repository's Git directory exists.
+  if (EXISTS "${git_path}" AND NOT IS_DIRECTORY "${git_path}")
+FILE(READ "${git_path}" file_contents)
+STRING(REGEX REPLACE "\n" "" file_contents "${file_contents}")
+if ("${file_contents}" MATCHES "^gitdir:")
+  # '.git' is indeed a link to the submodule's Git directory.
+  # Use the path to that Git directory.
+  STRING(REGEX REPLACE "gitdir: " "" file_contents ${file_contents})
+  set(git_path "${git_path}${file_contents}")
+endif()
+  endif()
+
   find_first_existing_file(${out_var}
-"${path}/.git/logs/HEAD" # Git
+"${git_path}/logs/HEAD"  # Git or Git submodule
 "${path}/.svn/wc.db" # SVN 1.7
 "${path}/.svn/entries"   # SVN 1.6
 )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33676: Place implictly declared functions at block scope

2017-07-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/Parse/ParseStmt.cpp:843-845
+  return ParseCompoundStatement(isStmtExpr,
+Scope::DeclScope | Scope::CompoundStmtScope);
 }

This seems to miss quite a lot of places that introduce compound statement 
scopes. (Search for callers of `ParseCompundStatementBody` and callers of the 
2-argument form of `ParseCompoundStatement` for those.)


https://reviews.llvm.org/D33676



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


[PATCH] D33842: CodeGen: Fix address space of global variable

2017-07-09 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Great, thanks!  LGTM.


https://reviews.llvm.org/D33842



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


[PATCH] D35131: Prevent ClangTools from generating dependency files.D34304 created a way for ToolInvocations to conditionally generatedependency files, and updated call sites to preserve the old behav

2017-07-09 Thread Sterling Augustine via Phabricator via cfe-commits
saugustine created this revision.

...are yet another
call-path that needs updating to preserve the old behavior.


https://reviews.llvm.org/D35131

Files:
  lib/Tooling/Tooling.cpp


Index: lib/Tooling/Tooling.cpp
===
--- lib/Tooling/Tooling.cpp
+++ lib/Tooling/Tooling.cpp
@@ -336,6 +336,7 @@
   OverlayFileSystem->pushOverlay(InMemoryFileSystem);
   appendArgumentsAdjuster(getClangStripOutputAdjuster());
   appendArgumentsAdjuster(getClangSyntaxOnlyAdjuster());
+  appendArgumentsAdjuster(getClangStripDependencyFileAdjuster());
 }
 
 ClangTool::~ClangTool() {}


Index: lib/Tooling/Tooling.cpp
===
--- lib/Tooling/Tooling.cpp
+++ lib/Tooling/Tooling.cpp
@@ -336,6 +336,7 @@
   OverlayFileSystem->pushOverlay(InMemoryFileSystem);
   appendArgumentsAdjuster(getClangStripOutputAdjuster());
   appendArgumentsAdjuster(getClangSyntaxOnlyAdjuster());
+  appendArgumentsAdjuster(getClangStripDependencyFileAdjuster());
 }
 
 ClangTool::~ClangTool() {}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits