r339641 - [CStringSyntaxChecker] Check strlcat sizeof check

2018-08-13 Thread David Carlier via cfe-commits
Author: devnexen
Date: Mon Aug 13 22:12:53 2018
New Revision: 339641

URL: http://llvm.org/viewvc/llvm-project?rev=339641=rev
Log:
[CStringSyntaxChecker] Check strlcat sizeof check


- Assuming strlcat is used with strlcpy we check as we can if the last argument 
does not equal os not larger than the buffer.
- Advising the proper usual pattern.

Reviewers: NoQ, george.karpenkov

Reviewed By: george.karpenkov

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


Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
cfe/trunk/test/Analysis/cstring-syntax.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp?rev=339641=339640=339641=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp Mon Aug 13 
22:12:53 2018
@@ -90,7 +90,16 @@ class WalkAST: public StmtVisitorgetNumArgs() != 3)
 return false;
+  const FunctionDecl *FD = CE->getDirectCallee();
+  bool Append = CheckerContext::isCLibraryFunction(FD, "strlcat");
   const Expr *DstArg = CE->getArg(0);
   const Expr *LenArg = CE->getArg(2);
 
   const auto *DstArgDecl = 
dyn_cast(DstArg->IgnoreParenImpCasts());
   const auto *LenArgDecl = 
dyn_cast(LenArg->IgnoreParenLValueCasts());
   uint64_t DstOff = 0;
+  // - sizeof(dst)
+  // strlcat appends at most size - strlen(dst) - 1
+  if (Append && isSizeof(LenArg, DstArg))
+return true;
   // - size_t dstlen = sizeof(dst)
   if (LenArgDecl) {
 const auto *LenArgVal = dyn_cast(LenArgDecl->getDecl());
@@ -181,7 +196,10 @@ bool WalkAST::containsBadStrlcpyPattern(
   if (const auto *Buffer = 
dyn_cast(DstArgDecl->getType())) {
 ASTContext  = BR.getContext();
 uint64_t BufferLen = C.getTypeSize(Buffer) / 8;
-if ((BufferLen - DstOff) < ILRawVal)
+auto RemainingBufferLen = BufferLen - DstOff;
+if (Append)
+  RemainingBufferLen -= 1;
+if (RemainingBufferLen < ILRawVal)
   return true;
   }
 }
@@ -220,7 +238,7 @@ void WalkAST::VisitCallExpr(CallExpr *CE
  LenArg->getSourceRange());
 }
   } else if (CheckerContext::isCLibraryFunction(FD, "strlcpy")) {
-if (containsBadStrlcpyPattern(CE)) {
+if (containsBadStrlcpyStrlcatPattern(CE)) {
   const Expr *DstArg = CE->getArg(0);
   const Expr *LenArg = CE->getArg(2);
   PathDiagnosticLocation Loc =
@@ -236,6 +254,34 @@ void WalkAST::VisitCallExpr(CallExpr *CE
 
   BR.EmitBasicReport(FD, Checker, "Anti-pattern in the argument",
  "C String API", os.str(), Loc,
+ LenArg->getSourceRange());
+}
+  } else if (CheckerContext::isCLibraryFunction(FD, "strlcat")) {
+if (containsBadStrlcpyStrlcatPattern(CE)) {
+  const Expr *DstArg = CE->getArg(0);
+  const Expr *LenArg = CE->getArg(2);
+  PathDiagnosticLocation Loc =
+PathDiagnosticLocation::createBegin(LenArg, BR.getSourceManager(), AC);
+
+  StringRef DstName = getPrintableName(DstArg);
+  StringRef LenName = getPrintableName(LenArg);
+
+  SmallString<256> S;
+  llvm::raw_svector_ostream os(S);
+  os << "The third argument allows to potentially copy more bytes than it 
should. ";
+  os << "Replace with the value ";
+  if (!LenName.empty())
+os << "'" << LenName << "'";
+  else
+os << "  ";
+  if (!DstName.empty())
+os << " - strlen(" << DstName << ")";
+  else
+os << " - strlen()";
+  os << " - 1 or lower";
+
+  BR.EmitBasicReport(FD, Checker, "Anti-pattern in the argument",
+ "C String API", os.str(), Loc,
  LenArg->getSourceRange());
 }
   }

Modified: cfe/trunk/test/Analysis/cstring-syntax.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cstring-syntax.c?rev=339641=339640=339641=diff
==
--- cfe/trunk/test/Analysis/cstring-syntax.c (original)
+++ cfe/trunk/test/Analysis/cstring-syntax.c Mon Aug 13 22:12:53 2018
@@ -7,6 +7,7 @@ typedef __SIZE_TYPE__ size_t;
 char  *strncat(char *, const char *, size_t);
 size_t strlen (const char *s);
 size_t strlcpy(char *, const char *, size_t);
+size_t strlcat(char *, const char *, size_t);
 
 void testStrncat(const char *src) {
   char dest[10];
@@ -33,3 +34,19 @@ void testStrlcpy(const char *src) {
   strlcpy(dest + 5, src, 5);
   strlcpy(dest + 5, src, 10); // expected-warning {{The third argument is 
larger than the size of the input buffer.}}
 }
+
+void testStrlcat(const char *src) {
+  char dest[10];
+  size_t badlen = 10;
+  size_t ulen;
+  strlcpy(dest, "a", sizeof("a") - 1);
+  strlcat(dest, "", (sizeof("") - 1) - 

[PATCH] D49722: [CStringSyntaxChecker] Check strlcat sizeof check

2018-08-13 Thread David CARLIER via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339641: [CStringSyntaxChecker] Check strlcat sizeof check 
(authored by devnexen, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D49722?vs=160272=160513#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D49722

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
  cfe/trunk/test/Analysis/cstring-syntax.c

Index: cfe/trunk/test/Analysis/cstring-syntax.c
===
--- cfe/trunk/test/Analysis/cstring-syntax.c
+++ cfe/trunk/test/Analysis/cstring-syntax.c
@@ -7,6 +7,7 @@
 char  *strncat(char *, const char *, size_t);
 size_t strlen (const char *s);
 size_t strlcpy(char *, const char *, size_t);
+size_t strlcat(char *, const char *, size_t);
 
 void testStrncat(const char *src) {
   char dest[10];
@@ -33,3 +34,19 @@
   strlcpy(dest + 5, src, 5);
   strlcpy(dest + 5, src, 10); // expected-warning {{The third argument is larger than the size of the input buffer.}}
 }
+
+void testStrlcat(const char *src) {
+  char dest[10];
+  size_t badlen = 10;
+  size_t ulen;
+  strlcpy(dest, "a", sizeof("a") - 1);
+  strlcat(dest, "", (sizeof("") - 1) - sizeof(dest) - 1);
+  strlcpy(dest, "012345678", sizeof(dest));
+  strlcat(dest, "910", sizeof(dest)); // expected-warning {{The third argument allows to potentially copy more bytes than it should. Replace with the value- strlen(dest) - 1 or lower}}
+  strlcpy(dest, "0123456789", sizeof(dest));
+  strlcat(dest, "0123456789", badlen); // expected-warning {{The third argument allows to potentially copy more bytes than it should. Replace with the value 'badlen' - strlen(dest) - 1 or lower}}
+  strlcat(dest, "0123456789", badlen - strlen(dest) - 1);
+  strlcat(dest, src, ulen);
+  strlcpy(dest, src, 5);
+  strlcat(dest + 5, src, badlen); // expected-warning {{The third argument allows to potentially copy more bytes than it should. Replace with the value 'badlen' - strlen() - 1 or lower}}
+}
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
@@ -90,7 +90,16 @@
   ///   strlcpy(dst, "abcd", 4);
   ///   strlcpy(dst + 3, "abcd", 2);
   ///   strlcpy(dst, "abcd", cpy);
-  bool containsBadStrlcpyPattern(const CallExpr *CE);
+  /// Identify erroneous patterns in the last argument to strlcat - the number
+  /// of bytes to copy.
+  /// The bad pattern checked is when the last argument is basically
+  /// pointing to the destination buffer size or argument larger or
+  /// equal to.  
+  ///   char dst[2];
+  ///   strlcat(dst, src2, sizeof(dst));
+  ///   strlcat(dst, src2, 2);
+  ///   strlcat(dst, src2, 10);
+  bool containsBadStrlcpyStrlcatPattern(const CallExpr *CE);
 
 public:
   WalkAST(const CheckerBase *Checker, BugReporter , AnalysisDeclContext *AC)
@@ -142,15 +151,21 @@
   return false;
 }
 
-bool WalkAST::containsBadStrlcpyPattern(const CallExpr *CE) {
+bool WalkAST::containsBadStrlcpyStrlcatPattern(const CallExpr *CE) {
   if (CE->getNumArgs() != 3)
 return false;
+  const FunctionDecl *FD = CE->getDirectCallee();
+  bool Append = CheckerContext::isCLibraryFunction(FD, "strlcat");
   const Expr *DstArg = CE->getArg(0);
   const Expr *LenArg = CE->getArg(2);
 
   const auto *DstArgDecl = dyn_cast(DstArg->IgnoreParenImpCasts());
   const auto *LenArgDecl = dyn_cast(LenArg->IgnoreParenLValueCasts());
   uint64_t DstOff = 0;
+  // - sizeof(dst)
+  // strlcat appends at most size - strlen(dst) - 1
+  if (Append && isSizeof(LenArg, DstArg))
+return true;
   // - size_t dstlen = sizeof(dst)
   if (LenArgDecl) {
 const auto *LenArgVal = dyn_cast(LenArgDecl->getDecl());
@@ -181,7 +196,10 @@
   if (const auto *Buffer = dyn_cast(DstArgDecl->getType())) {
 ASTContext  = BR.getContext();
 uint64_t BufferLen = C.getTypeSize(Buffer) / 8;
-if ((BufferLen - DstOff) < ILRawVal)
+auto RemainingBufferLen = BufferLen - DstOff;
+if (Append)
+  RemainingBufferLen -= 1;
+if (RemainingBufferLen < ILRawVal)
   return true;
   }
 }
@@ -220,7 +238,7 @@
  LenArg->getSourceRange());
 }
   } else if (CheckerContext::isCLibraryFunction(FD, "strlcpy")) {
-if (containsBadStrlcpyPattern(CE)) {
+if (containsBadStrlcpyStrlcatPattern(CE)) {
   const Expr *DstArg = CE->getArg(0);
   const Expr *LenArg = CE->getArg(2);
   PathDiagnosticLocation Loc =
@@ -238,6 +256,34 @@
  "C String API", os.str(), Loc,
  LenArg->getSourceRange());
 }
+  } else if (CheckerContext::isCLibraryFunction(FD, "strlcat")) {
+if (containsBadStrlcpyStrlcatPattern(CE)) {
+  const 

Re: r339428 - Add Windows support for the GNUstep Objective-C ABI V2.

2018-08-13 Thread Galina Kistanova via cfe-commits
Hello David,

This commit broke the following test on the expensive check builder:
CodeGenObjC/2007-04-03-ObjcEH.m

The last green build is for r339427 -
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/11726
r339428 makes it red -
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/11723

Could you take care of this, please?

Thanks

Galina

On Fri, Aug 10, 2018 at 5:53 AM, David Chisnall via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: theraven
> Date: Fri Aug 10 05:53:13 2018
> New Revision: 339428
>
> URL: http://llvm.org/viewvc/llvm-project?rev=339428=rev
> Log:
> Add Windows support for the GNUstep Objective-C ABI V2.
>
> Summary:
> Introduces funclet-based unwinding for Objective-C and fixes an issue
> where global blocks can't have their isa pointers initialised on
> Windows.
>
> After discussion with Dustin, this changes the name mangling of
> Objective-C types to prevent a C++ catch statement of type struct X*
> from catching an Objective-C object of type X*.
>
> Reviewers: rjmccall, DHowett-MSFT
>
> Reviewed By: rjmccall, DHowett-MSFT
>
> Subscribers: mgrang, mstorsjo, smeenai, cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D50144
>
> Modified:
> cfe/trunk/include/clang/Driver/Options.td
> cfe/trunk/lib/AST/MicrosoftMangle.cpp
> cfe/trunk/lib/CodeGen/CGException.cpp
> cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
> cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
> cfe/trunk/lib/CodeGen/CGObjCRuntime.h
> cfe/trunk/lib/CodeGen/CodeGenFunction.h
> cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> cfe/trunk/test/CodeGenObjC/gnu-init.m
> cfe/trunk/test/CodeGenObjC/gnustep2-proto.m
> cfe/trunk/test/CodeGenObjCXX/arc-marker-funclet.mm
> cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
> cfe/trunk/test/CodeGenObjCXX/msabi-objc-extensions.mm
> cfe/trunk/test/CodeGenObjCXX/msabi-objc-types.mm
>
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Driver/Options.td?rev=339428=339427=339428=diff
> 
> ==
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Fri Aug 10 05:53:13 2018
> @@ -1488,7 +1488,7 @@ def fobjc_weak : Flag<["-"], "fobjc-weak
>HelpText<"Enable ARC-style weak references in Objective-C">;
>
>  // Objective-C ABI options.
> -def fobjc_runtime_EQ : Joined<["-"], "fobjc-runtime=">, Group,
> Flags<[CC1Option]>,
> +def fobjc_runtime_EQ : Joined<["-"], "fobjc-runtime=">, Group,
> Flags<[CC1Option, CoreOption]>,
>HelpText<"Specify the target Objective-C runtime kind and version">;
>  def fobjc_abi_version_EQ : Joined<["-"], "fobjc-abi-version=">,
> Group;
>  def fobjc_nonfragile_abi_version_EQ : Joined<["-"],
> "fobjc-nonfragile-abi-version=">, Group;
>
> Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> MicrosoftMangle.cpp?rev=339428=339427=339428=diff
> 
> ==
> --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
> +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Aug 10 05:53:13 2018
> @@ -445,7 +445,7 @@ void MicrosoftCXXNameMangler::mangle(con
>  mangleFunctionEncoding(FD, Context.shouldMangleDeclName(FD));
>else if (const VarDecl *VD = dyn_cast(D))
>  mangleVariableEncoding(VD);
> -  else
> +  else if (!isa(D))
>  llvm_unreachable("Tried to mangle unexpected NamedDecl!");
>  }
>
> @@ -1884,13 +1884,13 @@ void MicrosoftCXXNameMangler::mangleType
>  llvm_unreachable("placeholder types shouldn't get to name mangling");
>
>case BuiltinType::ObjCId:
> -mangleArtificalTagType(TTK_Struct, "objc_object");
> +mangleArtificalTagType(TTK_Struct, ".objc_object");
>  break;
>case BuiltinType::ObjCClass:
> -mangleArtificalTagType(TTK_Struct, "objc_class");
> +mangleArtificalTagType(TTK_Struct, ".objc_class");
>  break;
>case BuiltinType::ObjCSel:
> -mangleArtificalTagType(TTK_Struct, "objc_selector");
> +mangleArtificalTagType(TTK_Struct, ".objc_selector");
>  break;
>
>  #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
> @@ -2570,9 +2570,10 @@ void MicrosoftCXXNameMangler::mangleType
>
>  void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T,
> Qualifiers,
>   SourceRange) {
> -  // ObjC interfaces have structs underlying them.
> +  // ObjC interfaces are mangled as if they were structs with a name that
> is
> +  // not a valid C/C++ identifier
>mangleTagTypeKind(TTK_Struct);
> -  mangleName(T->getDecl());
> +  mangle(T->getDecl(), ".objc_cls_");
>  }
>
>  void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T,
> Qualifiers,
> @@ -2590,11 +2591,11 @@ void 

[PATCH] D50663: [libunwind] [cmake] Add MINGW_LIBRARIES to the linker flags

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

LGTM


Repository:
  rUNW libunwind

https://reviews.llvm.org/D50663



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


[PATCH] D49885: Thread safety analysis: Allow relockable scopes

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

The case distinction in `case attr::AcquireCapability` is not very beautiful, 
but it's due to the fact that scoped capabilities are not "real" capabilities 
and so we need to distinguish them.

What this still doesn't allow for is attributes on other classes than the 
scoped capability that reacquire it from the outside. So maybe this isn't the 
right solution, and we need to approach it in a different way. Maybe instead of 
modifying the `BuildLockset::handleCall`, we should change 
`ThreadSafetyAnalyzer::addLock`. I'll think about that, but not today.




Comment at: test/SemaCXX/warn-thread-safety-analysis.cpp:2769-2781
+class SCOPED_LOCKABLE MemberLock {
+ public:
+  MemberLock() EXCLUSIVE_LOCK_FUNCTION(mutex);
+  ~MemberLock() UNLOCK_FUNCTION(mutex);
+  void Lock() EXCLUSIVE_LOCK_FUNCTION(mutex);
+  Mutex mutex;
+};

@hokein This is your test case, I just renamed some things.


Repository:
  rC Clang

https://reviews.llvm.org/D49885



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


[PATCH] D50341: [libcxx] Fix XFAILs for aligned allocation tests on older OSX versions

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

What about defining a feature for unsupported configurations? I've tried

  if '__cpp_aligned_new' not in macros or \
  intMacroValue(macros['__cpp_aligned_new']) < 201606:
  self.config.available_features.add('libcpp-no-aligned-new')

and `// UNSUPPORTED: libcpp-no-aligned-new`. Seems to be working but it's not 
sufficient. For example, clang-6 for old macOS versions would define 
`__cpp_aligned_new` but a test would fail. Still, we can use another feature, 
not necessarily macro-based. Though probably something like 
`libcpp-no-aligned-new` can replace `// UNSUPPORTED: c++98, c++03, c++11, 
c++14`.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50341



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


[PATCH] D49885: Thread safety analysis: Allow relockable scopes

2018-08-13 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert updated this revision to Diff 160505.
aaronpuchert added a comment.

Fix crash. The problem was that ACQUIRES with arguments did not no longer have 
(only) `this` as argument, hence our assumption that we would have only 
ScopedLockableFactEntry's was false. So now we lock a bit closer which kind of 
ACQUIRES we actually have.


Repository:
  rC Clang

https://reviews.llvm.org/D49885

Files:
  lib/Analysis/ThreadSafety.cpp
  test/SemaCXX/warn-thread-safety-analysis.cpp

Index: test/SemaCXX/warn-thread-safety-analysis.cpp
===
--- test/SemaCXX/warn-thread-safety-analysis.cpp
+++ test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -2621,6 +2621,196 @@
 } // end namespace ReleasableScopedLock
 
 
+namespace RelockableScopedLock {
+
+class SCOPED_LOCKABLE RelockableExclusiveMutexLock {
+public:
+  RelockableExclusiveMutexLock(Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu);
+  ~RelockableExclusiveMutexLock() EXCLUSIVE_UNLOCK_FUNCTION();
+
+  void Lock() EXCLUSIVE_LOCK_FUNCTION();
+  void Unlock() UNLOCK_FUNCTION();
+};
+
+class SCOPED_LOCKABLE RelockableSharedMutexLock {
+public:
+  RelockableSharedMutexLock(Mutex *mu) SHARED_LOCK_FUNCTION(mu);
+  ~RelockableSharedMutexLock() UNLOCK_FUNCTION();
+
+  void Lock() SHARED_LOCK_FUNCTION();
+  void Unlock() UNLOCK_FUNCTION();
+};
+
+class SharedTraits {};
+class ExclusiveTraits {};
+
+class SCOPED_LOCKABLE RelockableMutexLock {
+public:
+  RelockableMutexLock(Mutex *mu, SharedTraits) SHARED_LOCK_FUNCTION(mu);
+  RelockableMutexLock(Mutex *mu, ExclusiveTraits) EXCLUSIVE_LOCK_FUNCTION(mu);
+  ~RelockableMutexLock() UNLOCK_FUNCTION();
+
+  void Lock() EXCLUSIVE_LOCK_FUNCTION();
+  void Unlock() UNLOCK_FUNCTION();
+
+  void ReaderLock() SHARED_LOCK_FUNCTION();
+  void ReaderUnlock() UNLOCK_FUNCTION();
+
+  void PromoteShared() UNLOCK_FUNCTION() EXCLUSIVE_LOCK_FUNCTION();
+  void DemoteExclusive() UNLOCK_FUNCTION() SHARED_LOCK_FUNCTION();
+};
+
+Mutex mu;
+int x GUARDED_BY(mu);
+
+void print(int);
+
+void write() {
+  RelockableExclusiveMutexLock scope();
+  x = 2;
+  scope.Unlock();
+
+  x = 3; // expected-warning {{writing variable 'x' requires holding mutex 'mu' exclusively}}
+
+  scope.Lock();
+  x = 4;
+}
+
+void read() {
+  RelockableSharedMutexLock scope();
+  print(x);
+  scope.Unlock();
+
+  print(x); // expected-warning {{reading variable 'x' requires holding mutex 'mu'}}
+  x = 3; // expected-warning {{writing variable 'x' requires holding mutex 'mu' exclusively}}
+
+  scope.Lock();
+  print(x);
+  x = 4; // expected-warning {{writing variable 'x' requires holding mutex 'mu' exclusively}}
+}
+
+void relockExclusive() {
+  RelockableMutexLock scope(, SharedTraits{});
+  print(x);
+  x = 2; // expected-warning {{writing variable 'x' requires holding mutex 'mu' exclusively}}
+  scope.ReaderUnlock();
+
+  print(x); // expected-warning {{reading variable 'x' requires holding mutex 'mu'}}
+
+  scope.Lock();
+  print(x);
+  x = 4;
+
+  scope.DemoteExclusive();
+  print(x);
+  x = 5; // expected-warning {{writing variable 'x' requires holding mutex 'mu' exclusively}}
+}
+
+void relockShared() {
+  RelockableMutexLock scope(, ExclusiveTraits{});
+  print(x);
+  x = 2;
+  scope.Unlock();
+
+  print(x); // expected-warning {{reading variable 'x' requires holding mutex 'mu'}}
+
+  scope.ReaderLock();
+  print(x);
+  x = 4; // expected-warning {{writing variable 'x' requires holding mutex 'mu' exclusively}}
+
+  scope.PromoteShared();
+  print(x);
+  x = 5;
+}
+
+void doubleUnlock1() {
+  RelockableExclusiveMutexLock scope();
+  scope.Unlock();
+  scope.Unlock(); // expected-warning {{releasing mutex 'mu' that was not held}}
+}
+
+void doubleUnlock2() {
+  RelockableSharedMutexLock scope();
+  scope.Unlock();
+  scope.Unlock(); // expected-warning {{releasing mutex 'mu' that was not held}}
+}
+
+void doubleLock1() {
+  RelockableExclusiveMutexLock scope();
+  scope.Lock(); // expected-warning {{acquiring mutex 'mu' that is already held}}
+}
+
+void doubleLock2() {
+  RelockableSharedMutexLock scope();
+  scope.Lock(); // expected-warning {{acquiring mutex 'mu' that is already held}}
+}
+
+void doubleLock3() {
+  RelockableExclusiveMutexLock scope();
+  scope.Unlock();
+  scope.Lock();
+  scope.Lock(); // expected-warning {{acquiring mutex 'mu' that is already held}}
+}
+
+void doubleLock4() {
+  RelockableSharedMutexLock scope();
+  scope.Unlock();
+  scope.Lock();
+  scope.Lock(); // expected-warning {{acquiring mutex 'mu' that is already held}}
+}
+
+// Doesn't make a lot of sense, just making sure there is no crash.
+void destructLock() {
+  RelockableExclusiveMutexLock scope();
+  scope.~RelockableExclusiveMutexLock();
+  scope.Lock(); // Maybe this should warn.
+} // expected-warning {{releasing mutex 'scope' that was not held}}
+
+class SCOPED_LOCKABLE MemberLock {
+ public:
+  MemberLock() EXCLUSIVE_LOCK_FUNCTION(mutex);
+  ~MemberLock() UNLOCK_FUNCTION(mutex);
+  void Lock() 

[PATCH] D50526: Model type attributes as regular Attrs

2018-08-13 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I went ahead and reverted this in https://reviews.llvm.org/rC339638, and will 
produce a reduction soon.


Repository:
  rC Clang

https://reviews.llvm.org/D50526



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


r339638 - Revert r339623 "Model type attributes as regular Attrs."

2018-08-13 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Mon Aug 13 18:55:37 2018
New Revision: 339638

URL: http://llvm.org/viewvc/llvm-project?rev=339638=rev
Log:
Revert r339623 "Model type attributes as regular Attrs."

This breaks compiling atlwin.h in Chromium. I'm sure the code is invalid
in some way, but we put a lot of work into accepting it, and I'm sure
rejecting it was not an intended consequence of this refactoring. :)

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp
cfe/trunk/lib/ARCMigrate/Transforms.cpp
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=339638=339637=339638=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Aug 13 18:55:37 2018
@@ -31,7 +31,6 @@
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/AddressSpaces.h"
-#include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
@@ -1423,7 +1422,7 @@ public:
 
   QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const;
 
-  QualType getAttributedType(attr::Kind attrKind,
+  QualType getAttributedType(AttributedType::Kind attrKind,
  QualType modifiedType,
  QualType equivalentType);
 

Modified: cfe/trunk/include/clang/AST/Attr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=339638=339637=339638=diff
==
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Mon Aug 13 18:55:37 2018
@@ -113,19 +113,6 @@ public:
   void printPretty(raw_ostream , const PrintingPolicy ) const;
 };
 
-class TypeAttr : public Attr {
-protected:
-  TypeAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex,
-   bool IsLateParsed)
-  : Attr(AK, R, SpellingListIndex, IsLateParsed) {}
-
-public:
-  static bool classof(const Attr *A) {
-return A->getKind() >= attr::FirstTypeAttr &&
-   A->getKind() <= attr::LastTypeAttr;
-  }
-};
-
 class StmtAttr : public Attr {
 protected:
   StmtAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex,

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=339638=339637=339638=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Aug 13 18:55:37 2018
@@ -21,7 +21,6 @@
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/Basic/AddressSpaces.h"
-#include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
 #include "clang/Basic/LLVM.h"
@@ -1871,16 +1870,7 @@ public:
   bool isObjCQualifiedClassType() const;// Class
   bool isObjCObjectOrInterfaceType() const;
   bool isObjCIdType() const;// id
-
-  /// Was this type written with the special inert-in-ARC __unsafe_unretained
-  /// qualifier?
-  ///
-  /// This approximates the answer to the following question: if this
-  /// translation unit were compiled in ARC, would this type be qualified
-  /// with __unsafe_unretained?
-  bool isObjCInertUnsafeUnretainedType() const {
-return hasAttr(attr::ObjCInertUnsafeUnretained);
-  }
+  bool isObjCInertUnsafeUnretainedType() const;
 
   /// Whether the type is Objective-C 'id' or a __kindof type of an
   /// object type, e.g., __kindof NSView * or __kindof id
@@ -2094,10 +2084,6 @@ public:
   /// qualifiers from the outermost type.
   const ArrayType *castAsArrayTypeUnsafe() const;
 
-  /// Determine whether this type had the specified attribute applied to it
-  /// (looking through 

[PATCH] D50526: Model type attributes as regular Attrs

2018-08-13 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I suspect that somehow this change broke compiling ATL:
https://ci.chromium.org/buildbot/chromium.clang/ToTWin64%28dbg%29/993
https://logs.chromium.org/v/?s=chromium%2Fbb%2Fchromium.clang%2FToTWin64_dbg_%2F995%2F%2B%2Frecipes%2Fsteps%2Fcompile%2F0%2Flogs%2Fraw_io.output_failure_summary_%2F0

Now we get these diagnostics:

  [1011/50166] CXX obj/chrome/chrome_cleaner/http/http/error_utils.obj
  FAILED: obj/chrome/chrome_cleaner/http/http/error_utils.obj
  ...
  In file included from ../../chrome/chrome_cleaner/http/error_utils.cc:11:
  In file included from ../..\base/win/atl.h:18:
  In file included from 
..\..\third_party\depot_tools\win_toolchain\vs_files\3bc0ec615cf20ee342f3bc29bc991b5ad66d8d2c\VC\Tools\MSVC\14.14.26428\atlmfc\include\atlctl.h:33:
  In file included from 
..\..\third_party\depot_tools\win_toolchain\vs_files\3bc0ec615cf20ee342f3bc29bc991b5ad66d8d2c\VC\Tools\MSVC\14.14.26428\atlmfc\include\atlwin.h:5107:
  
..\..\third_party\depot_tools\win_toolchain\vs_files\3bc0ec615cf20ee342f3bc29bc991b5ad66d8d2c\VC\Tools\MSVC\14.14.26428\atlmfc\include\atlhost.h(2777,9):
  error: no matching function for call to 'AtlAxDialogCreateT'
  return AtlAxDialogCreateT(
  
^~~~
  
..\..\third_party\depot_tools\win_toolchain\vs_files\3bc0ec615cf20ee342f3bc29bc991b5ad66d8d2c\VC\Tools\MSVC\14.14.26428\atlmfc\include\atlhost.h(2715,29):
  note: candidate template ignored: invalid explicitly-specified argument for 
template parameter 'pFunc'
  typename Helper::ReturnType AtlAxDialogCreateT(
  ^
  
..\..\third_party\depot_tools\win_toolchain\vs_files\3bc0ec615cf20ee342f3bc29bc991b5ad66d8d2c\VC\Tools\MSVC\14.14.26428\atlmfc\include\atlhost.h(2788,9):
  error: no matching function for call to 'AtlAxDialogCreateT'
  return AtlAxDialogCreateT(
  
^~~
  
..\..\third_party\depot_tools\win_toolchain\vs_files\3bc0ec615cf20ee342f3bc29bc991b5ad66d8d2c\VC\Tools\MSVC\14.14.26428\atlmfc\include\atlhost.h(2715,29):
  note: candidate template ignored: invalid explicitly-specified argument for 
template parameter 'pFunc'
  typename Helper::ReturnType AtlAxDialogCreateT(
  ^
  
..\..\third_party\depot_tools\win_toolchain\vs_files\3bc0ec615cf20ee342f3bc29bc991b5ad66d8d2c\VC\Tools\MSVC\14.14.26428\atlmfc\include\atlhost.h(2799,9):
  error: no matching function for call to 'AtlAxDialogCreateT'
  return AtlAxDialogCreateT(
  
^~~~
  
..\..\third_party\depot_tools\win_toolchain\vs_files\3bc0ec615cf20ee342f3bc29bc991b5ad66d8d2c\VC\Tools\MSVC\14.14.26428\atlmfc\include\atlhost.h(2715,29):
  note: candidate template ignored: invalid explicitly-specified argument for 
template parameter 'pFunc'
  typename Helper::ReturnType AtlAxDialogCreateT(
  ^
  
..\..\third_party\depot_tools\win_toolchain\vs_files\3bc0ec615cf20ee342f3bc29bc991b5ad66d8d2c\VC\Tools\MSVC\14.14.26428\atlmfc\include\atlhost.h(2810,9):
  error: no matching function for call to 'AtlAxDialogCreateT'
  return AtlAxDialogCreateT(hInstance, lpTemplateName, hWndParent, 
lpDialogProc, dwInitParam);
  
^~~
  
..\..\third_party\depot_tools\win_toolchain\vs_files\3bc0ec615cf20ee342f3bc29bc991b5ad66d8d2c\VC\Tools\MSVC\14.14.26428\atlmfc\include\atlhost.h(2715,29):
  note: candidate template ignored: invalid explicitly-specified argument for 
template parameter 'pFunc'
  typename Helper::ReturnType AtlAxDialogCreateT(
  ^
  4 errors generated.


Repository:
  rC Clang

https://reviews.llvm.org/D50526



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


[PATCH] D49885: Thread safety analysis: Allow relockable scopes

2018-08-13 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert reopened this revision.
aaronpuchert added a comment.
This revision is now accepted and ready to land.

This didn't cross my mind, because an `ACQUIRES` attribute with arguments on a 
function other than the constructor does not add the argument locks to the set 
of managed mutexes. So while I'm not sure why someone would do that, it's 
completely possible without warning. Indeed it would be possible to have 
`ACQUIRES` both with and without arguments on the same function.


Repository:
  rC Clang

https://reviews.llvm.org/D49885



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


[PATCH] D50678: [InlineAsm] Update the min-legal-vector-width function attribute based on inputs and outputs to inline assembly

2018-08-13 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D50678



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


[PATCH] D50549: [libcxx] [test] Repair thread unsafety in thread tests

2018-08-13 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal updated this revision to Diff 160498.
BillyONeal edited the summary of this revision.
BillyONeal added a comment.

Remove changes to detach tests.


https://reviews.llvm.org/D50549

Files:
  
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp


Index: 
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
===
--- 
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
+++ 
test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
@@ -157,8 +157,11 @@
 {
 assert(G::n_alive == 0);
 assert(!G::op_run);
-std::thread t((G()));
-t.join();
+{
+G g;
+std::thread t(g);
+t.join();
+}
 assert(G::n_alive == 0);
 assert(G::op_run);
 }
@@ -185,8 +188,11 @@
 {
 assert(G::n_alive == 0);
 assert(!G::op_run);
-std::thread t(G(), 5, 5.5);
-t.join();
+{
+G g;
+std::thread t(g, 5, 5.5);
+t.join();
+}
 assert(G::n_alive == 0);
 assert(G::op_run);
 }


Index: test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
===
--- test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
+++ test/std/thread/thread.threads/thread.thread.class/thread.thread.constr/F.pass.cpp
@@ -157,8 +157,11 @@
 {
 assert(G::n_alive == 0);
 assert(!G::op_run);
-std::thread t((G()));
-t.join();
+{
+G g;
+std::thread t(g);
+t.join();
+}
 assert(G::n_alive == 0);
 assert(G::op_run);
 }
@@ -185,8 +188,11 @@
 {
 assert(G::n_alive == 0);
 assert(!G::op_run);
-std::thread t(G(), 5, 5.5);
-t.join();
+{
+G g;
+std::thread t(g, 5, 5.5);
+t.join();
+}
 assert(G::n_alive == 0);
 assert(G::op_run);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50630: [AST] Update/correct the static_asserts for the bit-fields in Type

2018-08-13 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D50630#1198053, @riccibruno wrote:

> I actually did exactly this. My approach was to extend what is already done,
>  that is add nested classes SomethingBitfields in Type and add an instance of
>  each to the anonymous union. The classes which I have found so far benefiting
>  from this are FunctionProtoType, TemplateSpecializationType, 
> PackExpansionType,
>  DependentTemplateSpecializationType and SubstTemplateTypeParmPackType.
>
> For example the patch dealing with TemplateSpecializationType is
>  here https://reviews.llvm.org/D50643.


I see.  This is one of those rare cases where your changes probably would've 
been
clearer not broken up into multiple patches. :)  I only got CC'ed on two of 
them.

Anyway, I think we're all in agreement that this is the right thing to do now.

John.


Repository:
  rC Clang

https://reviews.llvm.org/D50630



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


[PATCH] D50549: [libcxx] [test] Repair thread unsafety in thread tests

2018-08-13 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal added inline comments.



Comment at: 
test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp:73
 assert(!t0.joinable());
 while (!done) {}
 assert(G::op_run);

dvyukov wrote:
> BillyONeal wrote:
> > dvyukov wrote:
> > > BillyONeal wrote:
> > > > BillyONeal wrote:
> > > > > dvyukov wrote:
> > > > > > BillyONeal wrote:
> > > > > > > BillyONeal wrote:
> > > > > > > > dvyukov wrote:
> > > > > > > > > I don't immediately see how the race on n_alive/op_run 
> > > > > > > > > happens. It seems that the modifications in the thread happen 
> > > > > > > > > before this line, and modifications in main happen after this 
> > > > > > > > > line. How can both of them modify the variables at the same 
> > > > > > > > > time?
> > > > > > > > The destruction of g here races with the destruction of the 
> > > > > > > > DECAY_COPY'd copy of G used as the parameter of operator(). 
> > > > > > > > That is, line 69 creates a copy of g, passes that to the 
> > > > > > > > started thread, the started thread calls gCopy(). gCopy() 
> > > > > > > > doesn't return until the done flag is set, but the destruction 
> > > > > > > > of the object on which op() is being called is not so 
> > > > > > > > synchronized. Most of the other thread tests avoid this problem 
> > > > > > > > by joining with the thread; joining waits for the destruction 
> > > > > > > > of the DECAY_COPY'd parameters, but this does not.
> > > > > > > > 
> > > > > > > > (This is one of the reasons detach() should basically never be 
> > > > > > > > called anywhere)
> > > > > > > > 
> > > > > > > (That is to say, there's nothing to prevent both threads from 
> > > > > > > executing G::!G() on the two different copies of g... making 
> > > > > > > op_run atomic is probably avoidable but I'm being paranoid given 
> > > > > > > that there was already thread unsafety here...)
> > > > > > What is gCopy? I don't see anything named gCopy in this file...
> > > > > > 
> > > > > > Do we care about completion of destruction? Why? We wait for done 
> > > > > > to be set, and other variables are already updated at that point. 
> > > > > > Why does it matter that "the destruction of the object on which 
> > > > > > op() is being called is not so synchronized."?
> > > > > Because the destructor does `--n_alive;`
> > > > >What is gCopy? I don't see anything named gCopy in this file...
> > > > 
> > > > The copy is made in the constructor of std::thread. std::thread makes a 
> > > > copy of all the input parameters, gives the copy to the started thread, 
> > > > and then std::invoke is called there.
> > > > 
> > > > >Why does it matter that "the destruction of the object on which op() 
> > > > >is being called is not so synchronized."?
> > > > 
> > > > Because the two dtors race on `--n_alive;` when `n_alive` is not atomic.
> > > But the first dtor runs before "while (!done) {}" line and the second 
> > > dtor runs after "while (!done) {}" line, no?
> > > Or there is third object involved? But then I don't see how joining the  
> > > thread would help either.
> > >But the first dtor runs before "while (!done) {}" line
> > 
> > No, both dtors are run after the while (!done) {} line. The first dtor runs 
> > on line 76 (when the local variable g is destroyed), and the second dtor 
> > runs after operator() returns in the constructed thread.  The constructed 
> > thread is morally doing:
> > 
> > ```
> > void threadproc(G * g) {
> > g->operator(); // setting done happens in here
> > delete g; // dtor of second copy runs here
> > }
> > ```
> > 
> > > I don't see how joining the thread would help either.
> > 
> > Joining with the thread would wait for the second dtor -- the one after 
> > op() returns -- to complete. Of course joining with the thread isn't doable 
> > here given that the point is to test thread::detach :)
> > No, both dtors are run after the while (!done) {} line.
> 
> But how do we get past while (!done) line before the desctructor in the 
> thread has finished? The destructor sets done. So after while (!done) line 
> the destructor is effectively finished. What am I missing?
>The destructor sets done.

Hmmm I thought done was getting set on 56 but that's done_ (with a trailing 
underscore). :sigh:


https://reviews.llvm.org/D50549



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


[PATCH] D50683: [Android] Set NewAlign for 64-bit Android to 8 bytes

2018-08-13 Thread Pirama Arumuga Nainar via Phabricator via cfe-commits
pirama created this revision.
pirama added reviewers: rsmith, srhines.

Android uses jemalloc allocator, which returns 8-byte-aligned pointers for
allocations smaller than 8 bytes for 64-bit architectures.  Set NewAlign
conservatively to 8 bytes.


Repository:
  rC Clang

https://reviews.llvm.org/D50683

Files:
  lib/Basic/TargetInfo.cpp
  test/Preprocessor/init.c


Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -9022,7 +9022,10 @@
 // I386-ANDROID-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8U
 //
 // RUN: %clang_cc1 -x c++ -triple x86_64-linux-android -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix X86_64-ANDROID-CXX %s
-// X86_64-ANDROID-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+// X86_64-ANDROID-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8UL
+//
+// RUN: %clang_cc1 -x c++ -triple aarch64-linux-android -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix AARCH64-ANDROID-CXX %s
+// AARCH64-ANDROID-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8UL
 //
 // RUN: %clang_cc1 -triple arm-linux-androideabi20 -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix ANDROID20 %s
 // ANDROID20:#define __ANDROID_API__ 20
Index: lib/Basic/TargetInfo.cpp
===
--- lib/Basic/TargetInfo.cpp
+++ lib/Basic/TargetInfo.cpp
@@ -64,10 +64,13 @@
   // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
   // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
   // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
-  // This alignment guarantee also applies to Windows and Android.
-  if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid())
+  // This alignment guarantee also applies to Windows.
+  if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment())
 NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
-  else
+  else if (T.isAndroid()) {
+// For 64-bit Android, alignment is 8 bytes for allocations <= 8 bytes.
+NewAlign = (Triple.isArch64Bit() || Triple.isArch32Bit()) ? 64 : 0;
+  } else
 NewAlign = 0; // Infer from basic type alignment.
   HalfWidth = 16;
   HalfAlign = 16;


Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -9022,7 +9022,10 @@
 // I386-ANDROID-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8U
 //
 // RUN: %clang_cc1 -x c++ -triple x86_64-linux-android -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix X86_64-ANDROID-CXX %s
-// X86_64-ANDROID-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+// X86_64-ANDROID-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8UL
+//
+// RUN: %clang_cc1 -x c++ -triple aarch64-linux-android -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix AARCH64-ANDROID-CXX %s
+// AARCH64-ANDROID-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8UL
 //
 // RUN: %clang_cc1 -triple arm-linux-androideabi20 -E -dM < /dev/null | FileCheck -match-full-lines -check-prefix ANDROID20 %s
 // ANDROID20:#define __ANDROID_API__ 20
Index: lib/Basic/TargetInfo.cpp
===
--- lib/Basic/TargetInfo.cpp
+++ lib/Basic/TargetInfo.cpp
@@ -64,10 +64,13 @@
   // From the glibc documentation, on GNU systems, malloc guarantees 16-byte
   // alignment on 64-bit systems and 8-byte alignment on 32-bit systems. See
   // https://www.gnu.org/software/libc/manual/html_node/Malloc-Examples.html.
-  // This alignment guarantee also applies to Windows and Android.
-  if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid())
+  // This alignment guarantee also applies to Windows.
+  if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment())
 NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
-  else
+  else if (T.isAndroid()) {
+// For 64-bit Android, alignment is 8 bytes for allocations <= 8 bytes.
+NewAlign = (Triple.isArch64Bit() || Triple.isArch32Bit()) ? 64 : 0;
+  } else
 NewAlign = 0; // Infer from basic type alignment.
   HalfWidth = 16;
   HalfAlign = 16;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339633 - [CodeGen] Before returning a copy/dispose helper function, bitcast it to

2018-08-13 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Aug 13 17:15:42 2018
New Revision: 339633

URL: http://llvm.org/viewvc/llvm-project?rev=339633=rev
Log:
[CodeGen] Before returning a copy/dispose helper function, bitcast it to
a void pointer type.

This fixes a bug introduced in r339438.

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/test/CodeGen/blocks.c
cfe/trunk/test/CodeGenObjC/arc-blocks.m

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=339633=339632=339633=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Mon Aug 13 17:15:42 2018
@@ -1816,7 +1816,7 @@ CodeGenFunction::GenerateCopyHelperFunct
/*IsCopyHelper*/ true, CGM);
 
   if (llvm::GlobalValue *Func = CGM.getModule().getNamedValue(FuncName))
-return Func;
+return llvm::ConstantExpr::getBitCast(Func, VoidPtrTy);
 
   ASTContext  = getContext();
 
@@ -2010,7 +2010,7 @@ CodeGenFunction::GenerateDestroyHelperFu
/*IsCopyHelper*/ false, CGM);
 
   if (llvm::GlobalValue *Func = CGM.getModule().getNamedValue(FuncName))
-return Func;
+return llvm::ConstantExpr::getBitCast(Func, VoidPtrTy);
 
   ASTContext  = getContext();
 

Modified: cfe/trunk/test/CodeGen/blocks.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/blocks.c?rev=339633=339632=339633=diff
==
--- cfe/trunk/test/CodeGen/blocks.c (original)
+++ cfe/trunk/test/CodeGen/blocks.c Mon Aug 13 17:15:42 2018
@@ -2,7 +2,8 @@
 
 // CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i32, i32 }
 
-// CHECK: @[[BLOCK_DESCRIPTOR_TMP21:.*]] = internal constant { i32, i32, void 
(i8*, i8*)*, void (i8*)*, i8*, i8* } { i32 0, i32 24, void (i8*, i8*)* 
@__copy_helper_block_4_20r, void (i8*)* @__destroy_helper_block_4_20r, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* null }, 
align 4
+// CHECK: @{{.*}} = internal constant { i32, i32, i8*, i8*, i8*, i8* } { i32 
0, i32 24, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_4_20r to i8*), 
i8* bitcast (void (i8*)* @__destroy_helper_block_4_20r to i8*), i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i8* null }, 
align 4
+// CHECK: @[[BLOCK_DESCRIPTOR_TMP21:.*]] = internal constant { i32, i32, i8*, 
i8*, i8*, i8* } { i32 0, i32 24, i8* bitcast (void (i8*, i8*)* 
@__copy_helper_block_4_20r to i8*), i8* bitcast (void (i8*)* 
@__destroy_helper_block_4_20r to i8*), i8* getelementptr inbounds ([6 x i8], [6 
x i8]* @{{.*}}, i32 0, i32 0), i8* null }, align 4
 
 void (^f)(void) = ^{};
 
@@ -118,6 +119,6 @@ void testConstCaptureInCopyAndDestroyHel
 }
 // CHECK-LABEL: define void @testConstCaptureInCopyAndDestroyHelpers(
 // CHECK: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, 
i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, <{ i8*, i32, i32, i8*, 
%[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %{{.*}}, i32 0, i32 4
-// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i32, i32, void (i8*, 
i8*)*, void (i8*)*, i8*, i8* }* @[[BLOCK_DESCRIPTOR_TMP21]] to 
%[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** 
%[[BLOCK_DESCRIPTOR]], align 4
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i32, i32, i8*, i8*, 
i8*, i8* }* @[[BLOCK_DESCRIPTOR_TMP21]] to %[[STRUCT_BLOCK_DESCRIPTOR]]*), 
%[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 4
 
 // CHECK-LABEL: define internal void 
@__testConstCaptureInCopyAndDestroyHelpers_block_invoke

Modified: cfe/trunk/test/CodeGenObjC/arc-blocks.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-blocks.m?rev=339633=339632=339633=diff
==
--- cfe/trunk/test/CodeGenObjC/arc-blocks.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-blocks.m Mon Aug 13 17:15:42 2018
@@ -3,14 +3,14 @@
 
 // CHECK-COMMON: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
 // CHECK-COMMON: @{{.*}} = internal constant { i64, i64, i8*, i8*, i8*, i64 } 
{ i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32r to 
i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32r to i8*), i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, 
align 8
-// CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP9:.*]] = internal constant { i64, i64, 
void (i8*, i8*)*, void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32r, void (i8*)* @__destroy_helper_block_8_32r, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, 
align 8
-// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, void (i8*, i8*)*, 
void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* @__destroy_helper_block_8_32s, i8* 

r339632 - Fix check strings in test/CodeGenObjC/arc-blocks.m in preperation for

2018-08-13 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Aug 13 17:15:41 2018
New Revision: 339632

URL: http://llvm.org/viewvc/llvm-project?rev=339632=rev
Log:
Fix check strings in test/CodeGenObjC/arc-blocks.m in preperation for
fixing a bug introduced in r339438.

Check the descriptor global variables in the IR at both -O0 and -O2.

Modified:
cfe/trunk/test/CodeGenObjC/arc-blocks.m

Modified: cfe/trunk/test/CodeGenObjC/arc-blocks.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-blocks.m?rev=339632=339631=339632=diff
==
--- cfe/trunk/test/CodeGenObjC/arc-blocks.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-blocks.m Mon Aug 13 17:15:41 2018
@@ -1,16 +1,16 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks 
-fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-passes -o - %s | FileCheck 
%s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks 
-fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck 
-check-prefix=CHECK-UNOPT %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks 
-fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-passes -o - %s | FileCheck 
-check-prefix=CHECK -check-prefix=CHECK-COMMON %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks 
-fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck 
-check-prefix=CHECK-UNOPT -check-prefix=CHECK-COMMON %s
 
-// CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
-// CHECK-UNOPT: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
-// CHECK: @[[BLOCK_DESCRIPTOR_TMP9:.*]] = internal constant { i64, i64, void 
(i8*, i8*)*, void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32r, void (i8*)* @__destroy_helper_block_8_32r, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, 
align 8
-// CHECK-UNOPT: @{{.*}} = internal constant { i64, i64, void (i8*, i8*)*, void 
(i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, 
align 8
-// CHECK-UNOPT: @{{.*}} = internal constant { i64, i64, void (i8*, i8*)*, void 
(i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, 
align 8
-// CHECK-UNOPT: @{{.*}} = internal constant { i64, i64, void (i8*, i8*)*, void 
(i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, 
align 8
-// CHECK-UNOPT: @{{.*}} = internal constant { i64, i64, void (i8*, i8*)*, void 
(i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, 
align 8
-// CHECK-UNOPT: @[[BLOCK_DESCRIPTOR_TMP44:.*]] = internal constant { i64, i64, 
void (i8*, i8*)*, void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, 
align 8
-// CHECK: @[[BLOCK_DESCRIPTOR_TMP46:.*]] = internal constant { i64, i64, void 
(i8*, i8*)*, void (i8*)*, i8*, i8* } { i64 0, i64 48, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i8* 
getelementptr inbounds ([3 x i8], [3 x i8]* @{{.*}}, i32 0, i32 0) }, align 8
-// CHECK: @[[BLOCK_DESCRIPTOR_TMP48:.*]] = internal constant { i64, i64, void 
(i8*, i8*)*, void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32b, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([9 x i8], [9 x i8]* @.str.47, i32 0, i32 0), i64 256 }, 
align 8
+// CHECK-COMMON: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
+// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, i8*, i8*, i8*, i64 } 
{ i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32r to 
i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32r to i8*), i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, 
align 8
+// CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP9:.*]] = internal constant { i64, i64, 
void (i8*, i8*)*, void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32r, void (i8*)* @__destroy_helper_block_8_32r, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, 
align 8
+// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, void (i8*, i8*)*, 
void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* 

[PATCH] D50547: [Driver] Use normalized triples for multiarch runtime path

2018-08-13 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Would it be to much to check both the normalized and non-normalized?


Repository:
  rC Clang

https://reviews.llvm.org/D50547



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


[PATCH] D50678: [InlineAsm] Update the min-legal-vector-width function attribute based on inputs and outputs to inline assembly

2018-08-13 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc added a comment.

This makes sense to me, but definitely wait for someone more familiar w/ 
Clang's IR gen to review...


https://reviews.llvm.org/D50678



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


[PATCH] D50678: [InlineAsm] Update the min-legal-vector-width function attribute based on inputs and outputs to inline assembly

2018-08-13 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: chandlerc, rsmith, rnk.
Herald added a subscriber: eraman.

Another piece of my ongoing to work for prefer-vector-width.

min-legal-vector-width will eventually be used by the X86 backend to know 
whether it needs to make 512 bits type legal when prefer-vector-width=256. If 
the user used inline assembly that passed in/out a 512-bit register, we need to 
make sure 512 bits are considered legal. Otherwise we'll get an assert failure 
when we try to wire up the inline assembly to the rest of the code.

This patch just checks the LLVM IR types to see if they are vectors and then 
updates the attribute based on their total width. I'm not sure if this is the 
best way to do this or if there's any subtlety I might have missed. So if 
anyone has other opinions on how to do this I'm open to suggestions.


https://reviews.llvm.org/D50678

Files:
  lib/CodeGen/CGStmt.cpp
  test/CodeGen/x86-inline-asm-min-vector-width.c


Index: test/CodeGen/x86-inline-asm-min-vector-width.c
===
--- /dev/null
+++ test/CodeGen/x86-inline-asm-min-vector-width.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm 
-target-feature +avx512f -o - | FileCheck %s
+
+typedef long long __m128i __attribute__ ((vector_size (16)));
+typedef long long __m256i __attribute__ ((vector_size (32)));
+typedef long long __m512i __attribute__ ((vector_size (64)));
+
+// CHECK: define <2 x i64> @testXMMout(<2 x i64>* %p) #0
+__m128i testXMMout(__m128i *p) {
+  __m128i xmm0;
+  __asm__("vmovdqu %1, %0" :"=v"(xmm0) : "m"(*(__m128i*)p));
+  return xmm0;
+}
+
+// CHECK: define <4 x i64> @testYMMout(<4 x i64>* %p) #1
+__m256i testYMMout(__m256i *p) {
+  __m256i ymm0;
+  __asm__("vmovdqu %1, %0" :"=v"(ymm0) : "m"(*(__m256i*)p));
+  return ymm0;
+}
+
+// CHECK: define <8 x i64> @testZMMout(<8 x i64>* %p) #2
+__m512i testZMMout(__m512i *p) {
+  __m512i zmm0;
+  __asm__("vmovdqu64 %1, %0" :"=v"(zmm0) : "m"(*(__m512i*)p));
+  return zmm0;
+}
+
+// CHECK: define void @testXMMin(<2 x i64> %xmm0, <2 x i64>* %p) #0
+void testXMMin(__m128i xmm0, __m128i *p) {
+  __asm__("vmovdqu %0, %1" : : "v"(xmm0), "m"(*(__m128i*)p));
+}
+
+// CHECK: define void @testYMMin(<4 x i64> %ymm0, <4 x i64>* %p) #1
+void testYMMin(__m256i ymm0, __m256i *p) {
+  __asm__("vmovdqu %0, %1" : : "v"(ymm0), "m"(*(__m256i*)p));
+}
+
+// CHECK: define void @testZMMin(<8 x i64> %zmm0, <8 x i64>* %p) #2
+void testZMMin(__m512i zmm0, __m512i *p) {
+  __asm__("vmovdqu64 %0, %1" : : "v"(zmm0), "m"(*(__m512i*)p));
+}
+
+// CHECK: attributes #0 = {{.*}}"min-legal-vector-width"="128"
+// CHECK: attributes #1 = {{.*}}"min-legal-vector-width"="256"
+// CHECK: attributes #2 = {{.*}}"min-legal-vector-width"="512"
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1979,6 +1979,11 @@
   diag::err_asm_invalid_type_in_input)
 << OutExpr->getType() << OutputConstraint;
   }
+
+  // Update largest vector width for any vector types.
+  if (auto *VT = dyn_cast(ResultRegTypes.back()))
+LargestVectorWidth = std::max(LargestVectorWidth,
+  VT->getPrimitiveSizeInBits());
 } else {
   ArgTypes.push_back(Dest.getAddress().getType());
   Args.push_back(Dest.getPointer());
@@ -2000,6 +2005,10 @@
Arg->getType()))
 Arg = Builder.CreateBitCast(Arg, AdjTy);
 
+  // Update largest vector width for any vector types.
+  if (auto *VT = dyn_cast(Arg->getType()))
+LargestVectorWidth = std::max(LargestVectorWidth,
+  VT->getPrimitiveSizeInBits());
   if (Info.allowsRegister())
 InOutConstraints += llvm::utostr(i);
   else
@@ -2080,6 +2089,11 @@
   CGM.getDiags().Report(S.getAsmLoc(), diag::err_asm_invalid_type_in_input)
   << InputExpr->getType() << InputConstraint;
 
+// Update largest vector width for any vector types.
+if (auto *VT = dyn_cast(Arg->getType()))
+  LargestVectorWidth = std::max(LargestVectorWidth,
+VT->getPrimitiveSizeInBits());
+
 ArgTypes.push_back(Arg->getType());
 Args.push_back(Arg);
 Constraints += InputConstraint;


Index: test/CodeGen/x86-inline-asm-min-vector-width.c
===
--- /dev/null
+++ test/CodeGen/x86-inline-asm-min-vector-width.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm -target-feature +avx512f -o - | FileCheck %s
+
+typedef long long __m128i __attribute__ ((vector_size (16)));
+typedef long long __m256i __attribute__ ((vector_size (32)));
+typedef long long __m512i __attribute__ ((vector_size (64)));
+
+// CHECK: define <2 x i64> 

[PATCH] D50549: [libcxx] [test] Repair thread unsafety in thread tests

2018-08-13 Thread Dmitry Vyukov via Phabricator via cfe-commits
dvyukov added inline comments.



Comment at: 
test/std/thread/thread.threads/thread.thread.class/thread.thread.member/detach.pass.cpp:73
 assert(!t0.joinable());
 while (!done) {}
 assert(G::op_run);

BillyONeal wrote:
> dvyukov wrote:
> > BillyONeal wrote:
> > > BillyONeal wrote:
> > > > dvyukov wrote:
> > > > > BillyONeal wrote:
> > > > > > BillyONeal wrote:
> > > > > > > dvyukov wrote:
> > > > > > > > I don't immediately see how the race on n_alive/op_run happens. 
> > > > > > > > It seems that the modifications in the thread happen before 
> > > > > > > > this line, and modifications in main happen after this line. 
> > > > > > > > How can both of them modify the variables at the same time?
> > > > > > > The destruction of g here races with the destruction of the 
> > > > > > > DECAY_COPY'd copy of G used as the parameter of operator(). That 
> > > > > > > is, line 69 creates a copy of g, passes that to the started 
> > > > > > > thread, the started thread calls gCopy(). gCopy() doesn't return 
> > > > > > > until the done flag is set, but the destruction of the object on 
> > > > > > > which op() is being called is not so synchronized. Most of the 
> > > > > > > other thread tests avoid this problem by joining with the thread; 
> > > > > > > joining waits for the destruction of the DECAY_COPY'd parameters, 
> > > > > > > but this does not.
> > > > > > > 
> > > > > > > (This is one of the reasons detach() should basically never be 
> > > > > > > called anywhere)
> > > > > > > 
> > > > > > (That is to say, there's nothing to prevent both threads from 
> > > > > > executing G::!G() on the two different copies of g... making op_run 
> > > > > > atomic is probably avoidable but I'm being paranoid given that 
> > > > > > there was already thread unsafety here...)
> > > > > What is gCopy? I don't see anything named gCopy in this file...
> > > > > 
> > > > > Do we care about completion of destruction? Why? We wait for done to 
> > > > > be set, and other variables are already updated at that point. Why 
> > > > > does it matter that "the destruction of the object on which op() is 
> > > > > being called is not so synchronized."?
> > > > Because the destructor does `--n_alive;`
> > > >What is gCopy? I don't see anything named gCopy in this file...
> > > 
> > > The copy is made in the constructor of std::thread. std::thread makes a 
> > > copy of all the input parameters, gives the copy to the started thread, 
> > > and then std::invoke is called there.
> > > 
> > > >Why does it matter that "the destruction of the object on which op() is 
> > > >being called is not so synchronized."?
> > > 
> > > Because the two dtors race on `--n_alive;` when `n_alive` is not atomic.
> > But the first dtor runs before "while (!done) {}" line and the second dtor 
> > runs after "while (!done) {}" line, no?
> > Or there is third object involved? But then I don't see how joining the  
> > thread would help either.
> >But the first dtor runs before "while (!done) {}" line
> 
> No, both dtors are run after the while (!done) {} line. The first dtor runs 
> on line 76 (when the local variable g is destroyed), and the second dtor runs 
> after operator() returns in the constructed thread.  The constructed thread 
> is morally doing:
> 
> ```
> void threadproc(G * g) {
> g->operator(); // setting done happens in here
> delete g; // dtor of second copy runs here
> }
> ```
> 
> > I don't see how joining the thread would help either.
> 
> Joining with the thread would wait for the second dtor -- the one after op() 
> returns -- to complete. Of course joining with the thread isn't doable here 
> given that the point is to test thread::detach :)
> No, both dtors are run after the while (!done) {} line.

But how do we get past while (!done) line before the desctructor in the thread 
has finished? The destructor sets done. So after while (!done) line the 
destructor is effectively finished. What am I missing?


https://reviews.llvm.org/D50549



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


r339631 - [analyzer] Fix UninitializedObjectChecker to not crash on uninitialized "id" fields

2018-08-13 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Aug 13 16:32:15 2018
New Revision: 339631

URL: http://llvm.org/viewvc/llvm-project?rev=339631=rev
Log:
[analyzer] Fix UninitializedObjectChecker to not crash on uninitialized "id" 
fields

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

Modified:

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
cfe/trunk/test/Analysis/objcpp-uninitialized-object.mm

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp?rev=339631=339630=339631=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 Mon Aug 13 16:32:15 2018
@@ -265,7 +265,7 @@ bool FindUninitializedFields::isNonUnion
   continue;
 }
 
-if (T->isPointerType() || T->isReferenceType() || T->isBlockPointerType()) 
{
+if (T->isAnyPointerType() || T->isReferenceType() || 
T->isBlockPointerType()) {
   if (isPointerOrReferenceUninit(FR, LocalChain))
 ContainsUninitField = true;
   continue;

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp?rev=339631=339630=339631=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
 Mon Aug 13 16:32:15 2018
@@ -78,7 +78,7 @@ static bool isVoidPointer(QualType T);
 bool FindUninitializedFields::isPointerOrReferenceUninit(
 const FieldRegion *FR, FieldChainInfo LocalChain) {
 
-  assert((FR->getDecl()->getType()->isPointerType() ||
+  assert((FR->getDecl()->getType()->isAnyPointerType() ||
   FR->getDecl()->getType()->isReferenceType() ||
   FR->getDecl()->getType()->isBlockPointerType()) &&
  "This method only checks pointer/reference objects!");

Modified: cfe/trunk/test/Analysis/objcpp-uninitialized-object.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/objcpp-uninitialized-object.mm?rev=339631=339630=339631=diff
==
--- cfe/trunk/test/Analysis/objcpp-uninitialized-object.mm (original)
+++ cfe/trunk/test/Analysis/objcpp-uninitialized-object.mm Mon Aug 13 16:32:15 
2018
@@ -20,3 +20,13 @@ void warnOnUninitializedBlock() {
 void noWarningWhenInitialized() {
   StructWithBlock a;
 }
+
+struct StructWithId {
+  int a;
+  id z; // expected-note{{uninitialized pointer 'this->z'}}
+  StructWithId() : a(0) {} // expected-warning{{1 uninitialized field at the 
end of the constructor call}}
+};
+
+void warnOnUninitializedId() {
+  StructWithId s;
+}


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


[PATCH] D50673: [analyzer] Fix UninitializedObjectChecker to not crash on uninitialized "id" fields

2018-08-13 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339631: [analyzer] Fix UninitializedObjectChecker to not 
crash on uninitialized id… (authored by george.karpenkov, committed 
by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50673?vs=160473=160482#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50673

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
  test/Analysis/objcpp-uninitialized-object.mm


Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
@@ -78,7 +78,7 @@
 bool FindUninitializedFields::isPointerOrReferenceUninit(
 const FieldRegion *FR, FieldChainInfo LocalChain) {
 
-  assert((FR->getDecl()->getType()->isPointerType() ||
+  assert((FR->getDecl()->getType()->isAnyPointerType() ||
   FR->getDecl()->getType()->isReferenceType() ||
   FR->getDecl()->getType()->isBlockPointerType()) &&
  "This method only checks pointer/reference objects!");
Index: 
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
===
--- 
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -265,7 +265,7 @@
   continue;
 }
 
-if (T->isPointerType() || T->isReferenceType() || T->isBlockPointerType()) 
{
+if (T->isAnyPointerType() || T->isReferenceType() || 
T->isBlockPointerType()) {
   if (isPointerOrReferenceUninit(FR, LocalChain))
 ContainsUninitField = true;
   continue;
Index: test/Analysis/objcpp-uninitialized-object.mm
===
--- test/Analysis/objcpp-uninitialized-object.mm
+++ test/Analysis/objcpp-uninitialized-object.mm
@@ -20,3 +20,13 @@
 void noWarningWhenInitialized() {
   StructWithBlock a;
 }
+
+struct StructWithId {
+  int a;
+  id z; // expected-note{{uninitialized pointer 'this->z'}}
+  StructWithId() : a(0) {} // expected-warning{{1 uninitialized field at the 
end of the constructor call}}
+};
+
+void warnOnUninitializedId() {
+  StructWithId s;
+}


Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
@@ -78,7 +78,7 @@
 bool FindUninitializedFields::isPointerOrReferenceUninit(
 const FieldRegion *FR, FieldChainInfo LocalChain) {
 
-  assert((FR->getDecl()->getType()->isPointerType() ||
+  assert((FR->getDecl()->getType()->isAnyPointerType() ||
   FR->getDecl()->getType()->isReferenceType() ||
   FR->getDecl()->getType()->isBlockPointerType()) &&
  "This method only checks pointer/reference objects!");
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -265,7 +265,7 @@
   continue;
 }
 
-if (T->isPointerType() || T->isReferenceType() || T->isBlockPointerType()) {
+if (T->isAnyPointerType() || T->isReferenceType() || T->isBlockPointerType()) {
   if (isPointerOrReferenceUninit(FR, LocalChain))
 ContainsUninitField = true;
   continue;
Index: test/Analysis/objcpp-uninitialized-object.mm
===
--- test/Analysis/objcpp-uninitialized-object.mm
+++ test/Analysis/objcpp-uninitialized-object.mm
@@ -20,3 +20,13 @@
 void noWarningWhenInitialized() {
   StructWithBlock a;
 }
+
+struct StructWithId {
+  int a;
+  id z; // expected-note{{uninitialized pointer 'this->z'}}
+  StructWithId() : a(0) {} // expected-warning{{1 uninitialized field at the end of the constructor call}}
+};
+
+void warnOnUninitializedId() {
+  StructWithId s;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50594: [analyzer] [NFC] Introduce separate targets for testing the analyzer: check-clang-analyzer and check-clang-analyzer-z3

2018-08-13 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339629: [analyzer] [NFC] Introduce separate targets for 
testing the analyzer: check… (authored by george.karpenkov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50594?vs=160388=160479#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50594

Files:
  test/Analysis/analyzer_test.py
  test/Analysis/lit.local.cfg
  test/CMakeLists.txt
  test/lit.site.cfg.py.in

Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -88,8 +88,15 @@
 
 set(CLANG_TEST_PARAMS
   clang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  USE_Z3_SOLVER=0
   )
 
+set(ANALYZER_TEST_PARAMS
+  USE_Z3_SOLVER=0)
+
+set(ANALYZER_TEST_PARAMS_Z3
+  USE_Z3_SOLVER=1)
+
 if( NOT CLANG_BUILT_STANDALONE )
   list(APPEND CLANG_TEST_DEPS
 llvm-config
@@ -126,6 +133,24 @@
   )
 set_target_properties(check-clang PROPERTIES FOLDER "Clang tests")
 
+if (CLANG_ENABLE_STATIC_ANALYZER)
+  add_lit_testsuite(check-clang-analyzer "Running the Clang analyzer tests"
+${CMAKE_CURRENT_BINARY_DIR}/Analysis
+PARAMS ${ANALYZER_TEST_PARAMS}
+DEPENDS ${CLANG_TEST_DEPS})
+  set_target_properties(check-clang-analyzer PROPERTIES FOLDER "Clang tests")
+
+
+  if (CLANG_ANALYZER_WITH_Z3)
+add_lit_testsuite(check-clang-analyzer-z3 "Running the Clang analyzer tests, using Z3 as a solver"
+  ${CMAKE_CURRENT_BINARY_DIR}/Analysis
+  PARAMS ${ANALYZER_TEST_PARAMS_Z3}
+  DEPENDS ${CLANG_TEST_DEPS})
+set_target_properties(check-clang-analyzer-z3 PROPERTIES FOLDER "Clang tests")
+  endif()
+
+endif()
+
 add_lit_testsuites(CLANG ${CMAKE_CURRENT_SOURCE_DIR}
   PARAMS ${CLANG_TEST_PARAMS}
   DEPENDS ${CLANG_TEST_DEPS}
Index: test/lit.site.cfg.py.in
===
--- test/lit.site.cfg.py.in
+++ test/lit.site.cfg.py.in
@@ -26,14 +26,16 @@
 config.enable_backtrace = @ENABLE_BACKTRACES@
 config.host_arch = "@HOST_ARCH@"
 config.python_executable = "@PYTHON_EXECUTABLE@"
+config.use_z3_solver = "@USE_Z3_SOLVER@"
 
 # Support substitution of the tools and libs dirs with user parameters. This is
 # used when we can't determine the tool dir at configuration time.
 try:
 config.clang_tools_dir = config.clang_tools_dir % lit_config.params
 config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params
 config.llvm_shlib_dir = config.llvm_shlib_dir % lit_config.params
 config.llvm_libs_dir = config.llvm_libs_dir % lit_config.params
+config.use_z3_solver = lit_config.params['USE_Z3_SOLVER']
 except KeyError:
 e = sys.exc_info()[1]
 key, = e.args
Index: test/Analysis/lit.local.cfg
===
--- test/Analysis/lit.local.cfg
+++ test/Analysis/lit.local.cfg
@@ -7,7 +7,7 @@
 site.addsitedir(os.path.dirname(__file__))
 import analyzer_test
 config.test_format = analyzer_test.AnalyzerTest(
-config.test_format.execute_external)
+config.test_format.execute_external, config.use_z3_solver)
 
 if not config.root.clang_staticanalyzer:
 config.unsupported = True
Index: test/Analysis/analyzer_test.py
===
--- test/Analysis/analyzer_test.py
+++ test/Analysis/analyzer_test.py
@@ -4,6 +4,10 @@
 # Custom format class for static analyzer tests
 class AnalyzerTest(lit.formats.ShTest):
 
+def __init__(self, execute_external, use_z3_solver=False):
+super(AnalyzerTest, self).__init__(execute_external)
+self.use_z3_solver = use_z3_solver
+
 def execute(self, test, litConfig):
 results = []
 
@@ -19,7 +23,8 @@
 return results[-1]
 
 # If z3 backend available, add an additional run line for it
-if test.config.clang_staticanalyzer_z3 == '1':
+if self.use_z3_solver == '1':
+assert(test.config.clang_staticanalyzer_z3 == '1')
 results.append(self.executeWithAnalyzeSubstitution(
 saved_test, litConfig, '-analyzer-constraints=z3 -DANALYZER_CM_Z3'))
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r339629 - [analyzer] [NFC] Introduce separate targets for testing the analyzer: check-clang-analyzer and check-clang-analyzer-z3

2018-08-13 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Aug 13 16:12:43 2018
New Revision: 339629

URL: http://llvm.org/viewvc/llvm-project?rev=339629=rev
Log:
[analyzer] [NFC] Introduce separate targets for testing the analyzer: 
check-clang-analyzer and check-clang-analyzer-z3

Current testing setup for analyzer tests with Z3 is rather inconvenient:

There's no way to run the analyzer tests separately (I use
LIT_FILTER=Analysis ninja check-clang, but a direct target is nicer).

When Clang is built with Z3 support, there's no way to *not* run tests
with Z3 solver, and this is often desired, as tests with Z3 solver take
a very long time.

This patch introduces two extra targets:

 - check-clang-analyzer
 - check-clang-analyzer-z3

which solve those problems.

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

Modified:
cfe/trunk/test/Analysis/analyzer_test.py
cfe/trunk/test/Analysis/lit.local.cfg
cfe/trunk/test/CMakeLists.txt
cfe/trunk/test/lit.site.cfg.py.in

Modified: cfe/trunk/test/Analysis/analyzer_test.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer_test.py?rev=339629=339628=339629=diff
==
--- cfe/trunk/test/Analysis/analyzer_test.py (original)
+++ cfe/trunk/test/Analysis/analyzer_test.py Mon Aug 13 16:12:43 2018
@@ -4,6 +4,10 @@ import lit.TestRunner
 # Custom format class for static analyzer tests
 class AnalyzerTest(lit.formats.ShTest):
 
+def __init__(self, execute_external, use_z3_solver=False):
+super(AnalyzerTest, self).__init__(execute_external)
+self.use_z3_solver = use_z3_solver
+
 def execute(self, test, litConfig):
 results = []
 
@@ -19,7 +23,8 @@ class AnalyzerTest(lit.formats.ShTest):
 return results[-1]
 
 # If z3 backend available, add an additional run line for it
-if test.config.clang_staticanalyzer_z3 == '1':
+if self.use_z3_solver == '1':
+assert(test.config.clang_staticanalyzer_z3 == '1')
 results.append(self.executeWithAnalyzeSubstitution(
 saved_test, litConfig, '-analyzer-constraints=z3 
-DANALYZER_CM_Z3'))
 

Modified: cfe/trunk/test/Analysis/lit.local.cfg
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/lit.local.cfg?rev=339629=339628=339629=diff
==
--- cfe/trunk/test/Analysis/lit.local.cfg (original)
+++ cfe/trunk/test/Analysis/lit.local.cfg Mon Aug 13 16:12:43 2018
@@ -7,7 +7,7 @@ import site
 site.addsitedir(os.path.dirname(__file__))
 import analyzer_test
 config.test_format = analyzer_test.AnalyzerTest(
-config.test_format.execute_external)
+config.test_format.execute_external, config.use_z3_solver)
 
 if not config.root.clang_staticanalyzer:
 config.unsupported = True

Modified: cfe/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=339629=339628=339629=diff
==
--- cfe/trunk/test/CMakeLists.txt (original)
+++ cfe/trunk/test/CMakeLists.txt Mon Aug 13 16:12:43 2018
@@ -88,8 +88,15 @@ endif ()
 
 set(CLANG_TEST_PARAMS
   clang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
+  USE_Z3_SOLVER=0
   )
 
+set(ANALYZER_TEST_PARAMS
+  USE_Z3_SOLVER=0)
+
+set(ANALYZER_TEST_PARAMS_Z3
+  USE_Z3_SOLVER=1)
+
 if( NOT CLANG_BUILT_STANDALONE )
   list(APPEND CLANG_TEST_DEPS
 llvm-config
@@ -126,6 +133,24 @@ add_lit_testsuite(check-clang "Running t
   )
 set_target_properties(check-clang PROPERTIES FOLDER "Clang tests")
 
+if (CLANG_ENABLE_STATIC_ANALYZER)
+  add_lit_testsuite(check-clang-analyzer "Running the Clang analyzer tests"
+${CMAKE_CURRENT_BINARY_DIR}/Analysis
+PARAMS ${ANALYZER_TEST_PARAMS}
+DEPENDS ${CLANG_TEST_DEPS})
+  set_target_properties(check-clang-analyzer PROPERTIES FOLDER "Clang tests")
+
+
+  if (CLANG_ANALYZER_WITH_Z3)
+add_lit_testsuite(check-clang-analyzer-z3 "Running the Clang analyzer 
tests, using Z3 as a solver"
+  ${CMAKE_CURRENT_BINARY_DIR}/Analysis
+  PARAMS ${ANALYZER_TEST_PARAMS_Z3}
+  DEPENDS ${CLANG_TEST_DEPS})
+set_target_properties(check-clang-analyzer-z3 PROPERTIES FOLDER "Clang 
tests")
+  endif()
+
+endif()
+
 add_lit_testsuites(CLANG ${CMAKE_CURRENT_SOURCE_DIR}
   PARAMS ${CLANG_TEST_PARAMS}
   DEPENDS ${CLANG_TEST_DEPS}

Modified: cfe/trunk/test/lit.site.cfg.py.in
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/lit.site.cfg.py.in?rev=339629=339628=339629=diff
==
--- cfe/trunk/test/lit.site.cfg.py.in (original)
+++ cfe/trunk/test/lit.site.cfg.py.in Mon Aug 13 16:12:43 2018
@@ -26,6 +26,7 @@ config.enable_shared = @ENABLE_SHARED@
 config.enable_backtrace = @ENABLE_BACKTRACES@
 config.host_arch = "@HOST_ARCH@"
 config.python_executable = "@PYTHON_EXECUTABLE@"

[PATCH] D50630: [AST] Update/correct the static_asserts for the bit-fields in Type

2018-08-13 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

(Just writing up my archaeology and research so no-one else needs to do it...)

We used to intentionally keep the `Type` bitfields 32 bits long. However, these 
commits (accidentally, as far as I can tell) took us past 32 bits for the type 
bitfields: https://reviews.llvm.org/rL270834 https://reviews.llvm.org/rL285849 
https://reviews.llvm.org/rL301535 https://reviews.llvm.org/rL327768

For a target with 32-bit-aligned pointers, these changes will have made all 
`Type` objects 4 bytes larger.

For a target with 64-bit-aligned pointers, most `Type` subclasses would not be 
made any smaller by reducing the bitfields from 64 bits to 32 bits. The 
following types could be made smaller with some additional effort:

- `DependentAddressSpaceType`, `DependentSizedExtVectorType`, and 
`DependentVectorType` could each be made 8 bytes smaller by moving their 
`SourceLocation` member to the start and reordering the bases so 
`FoldingSetNode` is first. (But we should also remove the `ASTContext&` members 
if we care about how big these nodes are.)
- `UnaryTransformType` could be made 8 bytes smaller by moving its `UTTKind` 
member to the start. But it could be made 8 bytes smaller today by just 
removing that member, because its value is always zero. Or moving that member 
to the `Type` bitfields.
- `SubstTemplateTypeParmPackType`, `TemplateSpecializationType`, 
`DependentTemplateSpecializationType`, and `PackExpansionType` could be made 8 
bytes smaller by reordering the bases and moving an `unsigned` to the start. Or 
by moving the member into the `Type` bitfields.
- `ObjCTypeParamType` could be made 8 bytes smaller by reordering bases, but we 
could get the same benefit by just moving its bitfield member into the `Type` 
bitfields.
- `PipeType` could similarly be made 8 bytes smaller, but again it'd be easiest 
to just move its bool member into the type bitfields if we care.

(End archaeology.)

Does anyone still care about the memory uasge of 32-bit clang? (How much effort 
should we go to to pack our data efficiently for such targets?) Given that 
there are no `Type` nodes that could be made smaller on a 64-bit system by 
packing into the tail-padding of `Type` that could not more easily be made 
smaller in other ways, if we're past the point where 32-bit memory usage is a 
concern, I think we should just accept that the `Type` bit-fields are 64 bits 
long now.


Repository:
  rC Clang

https://reviews.llvm.org/D50630



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


[PATCH] D44100: [ASTImporter] Reorder fields after structure import is finished

2018-08-13 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin marked 2 inline comments as done.
a_sidorin added inline comments.



Comment at: lib/AST/ASTImporter.cpp:1029
+
+  RecordDecl *ToRD = cast(Importer.Import(cast(FromDC)));
+

martong wrote:
> Can't we just import the `FromRD`, why we need that cast at the end? 
> `auto *ToRD = cast(Importer.Import(FromRD)));` 
We need to cast it to DeclContext anyway, so I don't think that a narrower type 
will be worse



Comment at: lib/AST/ASTImporter.cpp:1032
+  for (auto *FromField : FromRD->fields()) {
+Decl *ToField = Importer.GetAlreadyImportedOrNull(FromField);
+assert(ToRD == ToField->getDeclContext() && ToRD->containsDecl(ToField));

martong wrote:
> I think `ToField` can be a nullptr, and if so, then 
> `ToField->getDeclContext()` is UB.
> Same could happen at line 1040.
> Perhaps we should have and explicit check about the nullptr value:
> `if (!ToField) continue;`
> 
I have added a check for the return result into the import loop. So, after the 
import is finished, all nested decls should be non-null.


Repository:
  rC Clang

https://reviews.llvm.org/D44100



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


[PATCH] D44100: [ASTImporter] Reorder fields after structure import is finished

2018-08-13 Thread Aleksei Sidorin via Phabricator via cfe-commits
a_sidorin updated this revision to Diff 160477.
a_sidorin edited the summary of this revision.
a_sidorin added a comment.

All declarations are reordered now, not only fields. Also some review comments 
were addressed.


Repository:
  rC Clang

https://reviews.llvm.org/D44100

Files:
  lib/AST/ASTImporter.cpp
  unittests/AST/ASTImporterTest.cpp


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -1428,7 +1428,7 @@
 }
 
 TEST_P(ASTImporterTestBase,
-   DISABLED_CXXRecordDeclFieldOrderShouldNotDependOnImportOrder) {
+   CXXRecordDeclFieldOrderShouldNotDependOnImportOrder) {
   Decl *From, *To;
   std::tie(From, To) = getImportedDecl(
   // The original recursive algorithm of ASTImporter first imports 'c' then
@@ -2995,5 +2995,16 @@
 ImportFunctionTemplateSpecializations,
 DefaultTestValuesForRunOptions, );
 
+TEST_P(ImportDecl, ImportFieldOrder) {
+  MatchVerifier Verifier;
+  testImport("struct declToImport {"
+ "  int b = a + 2;"
+ "  int a = 5;"
+ "};",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ recordDecl(hasFieldOrder({"b", "a"})));
+}
+
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -1299,6 +1299,36 @@
 if (!Importer.Import(From))
   return true;
 
+  // Reorder declarations in RecordDecls because they may have another
+  // order. Keeping field order is vitable because it determines structure
+  // layout.
+  // FIXME: This is an ugly fix. Unfortunately, I cannot come with better
+  // solution for this issue. We cannot defer expression import here because
+  // type import can depend on them.
+  const auto *FromRD = dyn_cast(FromDC);
+  if (!FromRD)
+return false;
+
+  auto ImportedDC = Importer.Import(cast(FromDC));
+  assert(ImportedDC);
+  auto *ToRD = cast(*ImportedDC);
+
+  for (auto *D : FromRD->decls()) {
+Decl *ToD = Importer.GetAlreadyImportedOrNull(D);
+assert(ToRD == ToD->getDeclContext() && ToRD->containsDecl(ToD));
+ToRD->removeDecl(ToD);
+  }
+
+  assert(ToRD->decls_empty());
+
+  for (auto *D : FromRD->decls()) {
+Decl *ToD = Importer.GetAlreadyImportedOrNull(D);
+assert(ToRD == ToD->getDeclContext());
+assert(ToRD == ToD->getLexicalDeclContext());
+assert(!ToRD->containsDecl(ToD));
+ToRD->addDeclInternal(ToD);
+  }
+
   return false;
 }
 


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -1428,7 +1428,7 @@
 }
 
 TEST_P(ASTImporterTestBase,
-   DISABLED_CXXRecordDeclFieldOrderShouldNotDependOnImportOrder) {
+   CXXRecordDeclFieldOrderShouldNotDependOnImportOrder) {
   Decl *From, *To;
   std::tie(From, To) = getImportedDecl(
   // The original recursive algorithm of ASTImporter first imports 'c' then
@@ -2995,5 +2995,16 @@
 ImportFunctionTemplateSpecializations,
 DefaultTestValuesForRunOptions, );
 
+TEST_P(ImportDecl, ImportFieldOrder) {
+  MatchVerifier Verifier;
+  testImport("struct declToImport {"
+ "  int b = a + 2;"
+ "  int a = 5;"
+ "};",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ recordDecl(hasFieldOrder({"b", "a"})));
+}
+
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -1299,6 +1299,36 @@
 if (!Importer.Import(From))
   return true;
 
+  // Reorder declarations in RecordDecls because they may have another
+  // order. Keeping field order is vitable because it determines structure
+  // layout.
+  // FIXME: This is an ugly fix. Unfortunately, I cannot come with better
+  // solution for this issue. We cannot defer expression import here because
+  // type import can depend on them.
+  const auto *FromRD = dyn_cast(FromDC);
+  if (!FromRD)
+return false;
+
+  auto ImportedDC = Importer.Import(cast(FromDC));
+  assert(ImportedDC);
+  auto *ToRD = cast(*ImportedDC);
+
+  for (auto *D : FromRD->decls()) {
+Decl *ToD = Importer.GetAlreadyImportedOrNull(D);
+assert(ToRD == ToD->getDeclContext() && ToRD->containsDecl(ToD));
+ToRD->removeDecl(ToD);
+  }
+
+  assert(ToRD->decls_empty());
+
+  for (auto *D : FromRD->decls()) {
+Decl *ToD = Importer.GetAlreadyImportedOrNull(D);
+assert(ToRD == ToD->getDeclContext());
+assert(ToRD == ToD->getLexicalDeclContext());
+assert(!ToRD->containsDecl(ToD));
+ToRD->addDeclInternal(ToD);
+  }
+
   return false;
 }
 

[PATCH] D50674: [libc++] Add missing #include in C11 features tests

2018-08-13 Thread Louis Dionne via Phabricator via cfe-commits
ldionne created this revision.
ldionne added a reviewer: mclow.lists.
Herald added a reviewer: EricWF.
Herald added subscribers: cfe-commits, dexonsmith, christof.

These #includes are quite important, since otherwise any

  #if TEST_STD_VER > 14 && defined(TEST_HAS_C11_FEATURES)

checks are always false, and so we don't actually test for C11 support
in the standard library.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50674

Files:
  libcxx/test/libcxx/language.support/has_c11_features.pass.cpp
  libcxx/test/std/depr/depr.c.headers/float_h.pass.cpp
  libcxx/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp


Index: libcxx/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
===
--- libcxx/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
+++ libcxx/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
@@ -11,6 +11,8 @@
 
 #include 
 
+#include "test_macros.h"
+
 #ifndef FLT_ROUNDS
 #error FLT_ROUNDS not defined
 #endif
Index: libcxx/test/std/depr/depr.c.headers/float_h.pass.cpp
===
--- libcxx/test/std/depr/depr.c.headers/float_h.pass.cpp
+++ libcxx/test/std/depr/depr.c.headers/float_h.pass.cpp
@@ -11,6 +11,8 @@
 
 #include 
 
+#include "test_macros.h"
+
 #ifndef FLT_ROUNDS
 #error FLT_ROUNDS not defined
 #endif
Index: libcxx/test/libcxx/language.support/has_c11_features.pass.cpp
===
--- libcxx/test/libcxx/language.support/has_c11_features.pass.cpp
+++ libcxx/test/libcxx/language.support/has_c11_features.pass.cpp
@@ -14,6 +14,9 @@
 // _LIBCPP_HAS_C11_FEATURES - which is defined in <__config>
 // They should always be the same
 
+#include <__config>
+#include "test_macros.h"
+
 #ifdef TEST_HAS_C11_FEATURES
 # ifndef _LIBCPP_HAS_C11_FEATURES
 #  error "TEST_HAS_C11_FEATURES is defined, but _LIBCPP_HAS_C11_FEATURES is 
not"


Index: libcxx/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
===
--- libcxx/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
+++ libcxx/test/std/language.support/support.limits/c.limits/cfloat.pass.cpp
@@ -11,6 +11,8 @@
 
 #include 
 
+#include "test_macros.h"
+
 #ifndef FLT_ROUNDS
 #error FLT_ROUNDS not defined
 #endif
Index: libcxx/test/std/depr/depr.c.headers/float_h.pass.cpp
===
--- libcxx/test/std/depr/depr.c.headers/float_h.pass.cpp
+++ libcxx/test/std/depr/depr.c.headers/float_h.pass.cpp
@@ -11,6 +11,8 @@
 
 #include 
 
+#include "test_macros.h"
+
 #ifndef FLT_ROUNDS
 #error FLT_ROUNDS not defined
 #endif
Index: libcxx/test/libcxx/language.support/has_c11_features.pass.cpp
===
--- libcxx/test/libcxx/language.support/has_c11_features.pass.cpp
+++ libcxx/test/libcxx/language.support/has_c11_features.pass.cpp
@@ -14,6 +14,9 @@
 //		_LIBCPP_HAS_C11_FEATURES - which is defined in <__config>
 //	They should always be the same
 
+#include <__config>
+#include "test_macros.h"
+
 #ifdef TEST_HAS_C11_FEATURES
 # ifndef _LIBCPP_HAS_C11_FEATURES
 #  error "TEST_HAS_C11_FEATURES is defined, but _LIBCPP_HAS_C11_FEATURES is not"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50670: Implementation of multiple loops in cxx_loop_proto

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

Does having multiple loops one after another change any coverage in the 
vectorizer?


Repository:
  rC Clang

https://reviews.llvm.org/D50670



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


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

2018-08-13 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

You could use //Differential revision: // in commit description to 
close review automatically.


https://reviews.llvm.org/D48909



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


[PATCH] D50670: Implementation of multiple loops in cxx_loop_proto

2018-08-13 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman created this revision.
emmettneyman added reviewers: morehouse, kcc.
Herald added a subscriber: cfe-commits.

Extended `cxx_loop_proto` to have multiple for loops. Modified 
`loop_proto_to_llvm` and `loop_proto_to_cxx` to handle the new protos. In 
`loop_proto_to_llvm`, I only translate the first ten loops from the protobuf 
into IR. This will keep down the runtime of each fuzzer run.


Repository:
  rC Clang

https://reviews.llvm.org/D50670

Files:
  clang/tools/clang-fuzzer/cxx_loop_proto.proto
  clang/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp

Index: clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
===
--- clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
+++ clang/tools/clang-fuzzer/proto-to-llvm/loop_proto_to_llvm.cpp
@@ -30,11 +30,21 @@
 std::string StateSeqToString(std::ostream , const StatementSeq );
 
 // Counter variable to generate new LLVM IR variable names and wrapper function
-std::string get_var() {
+static std::string get_var() {
   static int ctr = 0;
   return "%var" + std::to_string(ctr++);
 }
 
+static int loop_ctr = 0;
+
+static std::string get_loop_num() {
+  return std::to_string(loop_ctr);
+}
+
+static void new_loop() {
+  loop_ctr++;
+}
+
 // Proto to LLVM.
 
 std::string ConstToString(const Const ) {
@@ -54,7 +64,8 @@
 break;
   }
   std::string ptr_var = get_var();
-  os << ptr_var << " = getelementptr inbounds i32, i32* " << arr << ", i64 %ct\n";
+  os << ptr_var << " = getelementptr inbounds i32, i32* " << arr
+ << ", i64 %ct_" << get_loop_num() << "\n";
   return ptr_var;
 }
 std::string RvalueToString(std::ostream , const Rvalue ) {
@@ -122,25 +133,50 @@
   }
   return os;
 }
-std::ostream <<(std::ostream , const LoopFunction ) {
-  return os << "target triple = \"x86_64-unknown-linux-gnu\"\n"
-<< "define void @foo(i32* %a, i32* %b, i32* %c, i64 %s) {\n"
-<< "%1 = icmp sgt i64 %s, 0\n"
-<< "br i1 %1, label %start, label %end\n"
-<< "start:\n"
-<< "br label %loop\n"
-<< "end:\n"
-<< "ret void\n"
-<< "loop:\n"
-<< " %ct   = phi i64 [ %ctnew, %loop ], [ 0, %start ]\n"
+std::ostream <<(std::ostream , const Loop ) {
+  new_loop();
+  std::string lnum = get_loop_num();
+  std::string next_lnum = std::to_string(stoi(lnum) + 1);
+  if (!lnum.compare("1")) {
+os << "%cmp_" << lnum << " = icmp sgt i64 %s, 0\n"
+   << "br i1 %cmp_" << lnum << ", label %loop_start_" << lnum 
+   << ", label %end\n";
+  }
+  return os << "loop_start_" << lnum << ":\n"
+<< "br label %loop_" << lnum << "\n"
+<< "loop_end_" << lnum << ":\n"
+<< "%cmp_" << next_lnum << " = icmp sgt i64 %s, 0\n"
+<< "br i1 %cmp_" << next_lnum << ", label %loop_start_" << next_lnum
+<< ", label %end\n"
+<< "loop_" << lnum << ":\n"
+<< " %ct_" << lnum << "   = phi i64 [ %ctnew_" << lnum
+<< ", %loop_" << lnum << " ], [ 0, %loop_start_" << lnum << " ]\n"
 << x.statements()
-<< "%ctnew = add i64 %ct, 1\n"
-<< "%j = icmp eq i64 %ctnew, %s\n"
-<< "br i1 %j, label %end, label %loop, !llvm.loop !0\n}\n"
-<< "!0 = distinct !{!0, !1, !2}\n"
-<< "!1 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n"
-<< "!2 = !{!\"llvm.loop.vectorize.width\", i32 " << kArraySize
-<< "}\n";
+<< "%ctnew_" << lnum << " = add i64 %ct_" << lnum << ", 1\n"
+<< "%j_" << lnum << " = icmp eq i64 %ctnew_" << lnum << ", %s\n"
+<< "br i1 %j_" << lnum << ", label %loop_end_" << lnum
+<< ", label %loop_" << lnum << ", !llvm.loop !0\n";
+
+}
+std::ostream <<(std::ostream , const LoopFunction ) {
+  os << "target triple = \"x86_64-unknown-linux-gnu\"\n"
+ << "define void @foo(i32* %a, i32* %b, i32* %c, i64 %s) {\n";
+  for (auto  : x.loops()) {
+os << lp;
+// No matter how many loops the protobuf has, only translate 10 of them
+if (!get_loop_num().compare("10"))
+  break;
+  }
+  new_loop();
+  std::string lnum = get_loop_num();
+  os << "loop_start_" << lnum << ":\n"
+ << "br label %end\n"
+ << "end:\n"
+ << "ret void\n}\n"
+ << "!0 = distinct !{!0, !1, !2}\n"
+ << "!1 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n"
+ << "!2 = !{!\"llvm.loop.vectorize.width\", i32 " << kArraySize << "}\n";
+  return os;
 }
 
 // -
Index: clang/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
===
--- clang/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
+++ clang/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
@@ -108,10 +108,15 @@
 os << st;
   return os;
 }
+std::ostream <<(std::ostream , 

[PATCH] D50630: [AST] Update/correct the static_asserts for the bit-fields in Type

2018-08-13 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

In https://reviews.llvm.org/D50630#1197930, @rjmccall wrote:

> In https://reviews.llvm.org/D50630#1197795, @riccibruno wrote:
>
> > @rjmccall
> >
> > I would argue that we should make these bit-fields take 8 bytes for the 
> > following reasons:
> >
> > 1. On 64 bits archs, this is free since we have already a little less than 
> > 8 bytes of padding here, assuming Type keep its 18 bits.
>
>
> First, `Type` is not 16-byte aligned as far as the compiler is concerned; it 
> is merely
>  dynamically aligned to a 16-byte boundary when allocated.  You actually 
> verified this
>  when you did your experiment of printing out the sizes of various `Type` 
> subclasses,
>  because the value of `sizeof` is always rounded up to the alignment, meaning 
> that a
>  size of 40 would not be legal if `Type` were actually 16-byte-aligned.
>
> Because `Type` is only 4/8-byte aligned, its only tail padding is what's 
> needed to
>  fill up a pointer after these bit-fields, which is supposed to be 4 bytes 
> but is
>  instead apparently 0 bytes because we overflowed one of the bit-fields.
>
> Not officially aligning `Type` to 16 bytes is fairly important for memory 
> efficiency
>  even on 64-bit hosts because many of our types use tail-allocated storage, 
> which
>  naturally starts at `sizeof(T)` bytes from the address point; if we formally 
> aligned
>  `Type` subclasses to 16 bytes, we'd often waste a pointer of that storage.


Right,

> Second, tail padding of base classes is not necessarily wasted under the 
> Itanium C++ ABI.
>  Itanium will start placing sub-objects in the tail-padding of the last 
> non-empty base class
>  as long as that base is POD under the rules of C++03; `Type` is not POD 
> because it has a
>  user-provided constructor.

I just realized that something like this was happening when playing with 
various classes on godbolt.
I should go read the Itanium spec ! However as you say the condition for this 
happening are
not necessarily satisfied and moreover other ABIs might not do this packing 
(but you almost
certainly are more familiar with this than me)

> Looking at `Type.h`, we don't seem to be taking advantage of this as much as 
> I thought,
>  at least in the `Type` hierarchy (maybe we do in the `Stmt` or `Decl` 
> hierarchies).  We
>  have a lot of subclasses that have 32 bits of miscellaneous storage but 
> either (1) don't
>  order their fields correctly to allow subclasses to fit in or (2) also 
> subclass `FoldingSetNode`,
>  which breaks up the optimization.
> 
> Since we do care primarily about 64-bit hosts, I'm leaning towards agreeing 
> that we should
>  just accept that we have 64 bits of storage here, 46 of which are available 
> to subclasses.
>  If you're interested in optimizing this, it would be nice if you could go 
> through all the
>  subclasses looking for 32-bit chunks that could be profitably moved up into 
> `Type`.
> 
>> 2. On 32 bits archs, this a priori increase the size of each Type by 4 
>> bytes. However, types are aligned to 16 bytes because of the fast CVR 
>> qualifiers. Doing an fsyntax-only on all of Boost with -print-stats I get 
>> that by far the most commonly used Types have size 40 or 48 (on a 64 bits 
>> arch). That is 5 or 6 pointers. This would be 20 or 24 bytes on 32 bits 
>> archs if we assume that every member of the most commonly used types are 
>> pointers and that we shrink the bitfields to 32 bits. But since Types are 
>> aligned to 16 bytes we do not gain anything.
> 
> Types aren't the only thing allocated in the ASTContext, so allocating a 
> 16-byte-aligned
>  chunk with a non-multiple-of-16 size doesn't mean that any difference 
> between the size
>  and the next 16-byte boundary is necessarily wasted.  But you're probably 
> right that the
>  difference between `Type` being 12 and 16 bytes is probably not a big deal.
> 
> John.

I actually did exactly this. My approach was to extend what is already done,
that is add nested classes SomethingBitfields in Type and add an instance of
each to the anonymous union. The classes which I have found so far benefiting
from this are FunctionProtoType, TemplateSpecializationType, PackExpansionType,
DependentTemplateSpecializationType and SubstTemplateTypeParmPackType.

For example the patch dealing with TemplateSpecializationType is
here https://reviews.llvm.org/D50643.


Repository:
  rC Clang

https://reviews.llvm.org/D50630



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


[PATCH] D50641: [clangd][test] Fix exit messages in tests

2018-08-13 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Thanks for fixing this!

You're right we should try to fix it properly to avoid such mistakes in the 
future. Checking for stderr from Clangd might work, but I don't think it's the 
most optimal solution. What do you think about Clangd exiting with failure on 
malformed JSON input when running in `-lit` mode?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50641



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


[PATCH] D50341: [libcxx] Fix XFAILs for aligned allocation tests on older OSX versions

2018-08-13 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added inline comments.



Comment at: libcxx/test/libcxx/memory/aligned_allocation_macro.pass.cpp:18
+// XFAIL: macosx10.8
+// XFAIL: macosx10.7
 

mclow.lists wrote:
> These should probably be `UNSUPPORTED` as well.
I think the correct thing for those is `XFAIL`, since this test is actually 
testing that the macro is defined or not defined for specific platforms. 
Equivalently, we could have two tests -- one 
`aligned_allocation_macro.pass.cpp` which is `UNSUPPORTED` on `macosx10.7` ... 
`macosx10.12`, and one `aligned_allocation_macro.fail.cpp` which `REQUIRES` one 
of `macosx10.7`, ..., `macosx10.12`. Does that make sense?



Comment at: 
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align.fail.cpp:15
 
 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, 
clang-3.8

mclow.lists wrote:
> ldionne wrote:
> > vsapsai wrote:
> > > In what cases are we supposed to run these tests? Such extensive 
> > > collection of unsupported C++ standards looks suspicious and I guess that 
> > > is the reason why I haven't seen test failures with older libc++ dylibs.
> > That's an excellent question. I would assume those should be enabled in 
> > C++17 and above, I'm not sure why they're disabled. @mclow.lists was the 
> > one to introduce those tests, perhaps he can shed light on why they were 
> > disabled in C++17?
> IIRC, this call - `operator new(std::size_t, std::align_val_t);` was 
> introduced for C++17, and `[[nodiscard]]` was added for C++20.
> 
> this test is making sure that we get a warning when you call this and don't 
> use the return value. It requires C++20 and above, hence the massive 
> UNSUPPORTED list
Wouldn't it be sufficient to list the standard required? Why do we have 
`UNSUPPORTED` compilers too?


Repository:
  rCXX libc++

https://reviews.llvm.org/D50341



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


[PATCH] D50341: [libcxx] Fix XFAILs for aligned allocation tests on older OSX versions

2018-08-13 Thread Louis Dionne via Phabricator via cfe-commits
ldionne updated this revision to Diff 160465.
ldionne marked an inline comment as done.
ldionne added a comment.

Replace more XFAILs by UNSUPPORTEDs, per Marshall's comment.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50341

Files:
  libcxx/test/libcxx/memory/aligned_allocation_macro.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/delete_align_val_t_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_nothrow.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_nothrow_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align_nothrow.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align_nothrow.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_nothrow.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_nothrow.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/delete_align_val_t_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.sh.cpp

Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.sh.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.sh.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.sh.cpp
@@ -15,11 +15,12 @@
 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
 
-#include 
+// REQUIRES: -faligned-allocation
+// RUN: %compile %verify -faligned-allocation
 
-#include "test_macros.h"
+#include 
 
 int main ()
 {
-::operator new(4, std::align_val_t{4}, std::nothrow);  // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
+::operator new(4, std::align_val_t{4}, std::nothrow);  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 }
Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.sh.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.sh.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.sh.cpp
@@ -10,16 +10,17 @@
 
 // 
 
-// void* operator new[](std::size_t, std::align_val_t);
+// void* operator new(std::size_t, std::align_val_t);
 
 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
 
-#include 
+// REQUIRES: -faligned-allocation
+// RUN: %compile %verify -faligned-allocation
 
-#include "test_macros.h"
+#include 
 
 int main ()
 {
-::operator new[](4, std::align_val_t{4});  // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
+::operator new(4, std::align_val_t{4});  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 }
Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.fail.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.fail.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-// -*- C++ -*-

[PATCH] D50666: Fix Stmt::ignoreImplicit

2018-08-13 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/AST/Stmt.cpp:121-122
 
-  if (auto *bte = dyn_cast(s))
-s = bte->getSubExpr();
+if (auto *ewc = dyn_cast(s))
+  s = ewc->getSubExpr();
 

`ExprWithCleanups` can only appear at the top level. But... maybe it's not 
worth treating that as a special case.


Repository:
  rC Clang

https://reviews.llvm.org/D50666



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


[PATCH] D50571: [clangd] add an extension field to LSP to transfer the diagnostic's category

2018-08-13 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 160464.
arphaman marked 2 inline comments as done.
arphaman added a comment.

Address review comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50571

Files:
  clangd/ClangdLSPServer.cpp
  clangd/Diagnostics.cpp
  clangd/Diagnostics.h
  clangd/Protocol.h
  test/clangd/compile-commands-path-in-initialize.test
  test/clangd/compile-commands-path.test
  test/clangd/diagnostics.test
  test/clangd/did-change-configuration-params.test
  test/clangd/execute-command.test
  test/clangd/extra-flags.test
  test/clangd/fixits.test

Index: test/clangd/fixits.test
===
--- test/clangd/fixits.test
+++ test/clangd/fixits.test
@@ -6,6 +6,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
+# CHECK-NEXT:"category": "Semantic Issue",
 # CHECK-NEXT:"message": "Using the result of an assignment as a condition without parentheses",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
Index: test/clangd/extra-flags.test
===
--- test/clangd/extra-flags.test
+++ test/clangd/extra-flags.test
@@ -6,6 +6,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
+# CHECK-NEXT:"category": "Semantic Issue",
 # CHECK-NEXT:"message": "Variable 'i' is uninitialized when used here",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
@@ -28,6 +29,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
+# CHECK-NEXT:"category": "Semantic Issue",
 # CHECK-NEXT:"message": "Variable 'i' is uninitialized when used here",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
Index: test/clangd/execute-command.test
===
--- test/clangd/execute-command.test
+++ test/clangd/execute-command.test
@@ -6,6 +6,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
+# CHECK-NEXT:"category": "Semantic Issue",
 # CHECK-NEXT:"message": "Using the result of an assignment as a condition without parentheses",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
Index: test/clangd/did-change-configuration-params.test
===
--- test/clangd/did-change-configuration-params.test
+++ test/clangd/did-change-configuration-params.test
@@ -24,6 +24,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
+# CHECK-NEXT:"category": "Semantic Issue",
 # CHECK-NEXT:"message": "Variable 'i' is uninitialized when used here",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
Index: test/clangd/diagnostics.test
===
--- test/clangd/diagnostics.test
+++ test/clangd/diagnostics.test
@@ -6,6 +6,7 @@
 # CHECK-NEXT:  "params": {
 # CHECK-NEXT:"diagnostics": [
 # CHECK-NEXT:  {
+# CHECK-NEXT:"category": "Semantic Issue",
 # CHECK-NEXT:"message": "Return type of 'main' is not 'int'",
 # CHECK-NEXT:"range": {
 # CHECK-NEXT:  "end": {
Index: test/clangd/compile-commands-path.test
===
--- test/clangd/compile-commands-path.test
+++ test/clangd/compile-commands-path.test
@@ -23,20 +23,23 @@
 # CHECK-NEXT:   "params": {
 # CHECK-NEXT: "diagnostics": [
 # CHECK-NEXT:   {
+# CHECK-NEXT: "category": "#pragma message Directive",
 # CHECK-NEXT: "message": "MACRO is not defined",
 ---
 {"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-1"}}}
 # CHECK:   "method": "textDocument/publishDiagnostics",
 # CHECK-NEXT:   "params": {
 # CHECK-NEXT: "diagnostics": [
 # CHECK-NEXT:   {
+# CHECK-NEXT: "category": "#pragma message Directive",
 # CHECK-NEXT: "message": "MACRO is one",
 ---
 {"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-2"}}}
 # CHECK:   "method": "textDocument/publishDiagnostics",
 # CHECK-NEXT:   "params": {
 # CHECK-NEXT: "diagnostics": [
 # CHECK-NEXT:   {
+# CHECK-NEXT: "category": "#pragma message Directive",
 # CHECK-NEXT: "message": "MACRO is two",
 ---
 {"jsonrpc":"2.0","id":1,"method":"shutdown"}
Index: test/clangd/compile-commands-path-in-initialize.test
===
--- test/clangd/compile-commands-path-in-initialize.test
+++ test/clangd/compile-commands-path-in-initialize.test
@@ -23,13 +23,15 @@
 # CHECK-NEXT:   "params": {
 # CHECK-NEXT: "diagnostics": [
 # CHECK-NEXT:   {
+# CHECK-NEXT:   

[PATCH] D50341: [libcxx] Fix XFAILs for aligned allocation tests on older OSX versions

2018-08-13 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added inline comments.



Comment at: libcxx/test/libcxx/memory/aligned_allocation_macro.pass.cpp:18
+// XFAIL: macosx10.8
+// XFAIL: macosx10.7
 

These should probably be `UNSUPPORTED` as well.



Comment at: 
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/delete_align_val_t_replace.pass.cpp:15
 // Older Clang versions do not support this
 // XFAIL: clang-3, apple-clang-7, apple-clang-8
 

These should probably be `UNSUPPORTED` as well (though this is less important)




Comment at: 
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align.fail.cpp:15
 
 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, 
clang-3.8

ldionne wrote:
> vsapsai wrote:
> > In what cases are we supposed to run these tests? Such extensive collection 
> > of unsupported C++ standards looks suspicious and I guess that is the 
> > reason why I haven't seen test failures with older libc++ dylibs.
> That's an excellent question. I would assume those should be enabled in C++17 
> and above, I'm not sure why they're disabled. @mclow.lists was the one to 
> introduce those tests, perhaps he can shed light on why they were disabled in 
> C++17?
IIRC, this call - `operator new(std::size_t, std::align_val_t);` was introduced 
for C++17, and `[[nodiscard]]` was added for C++20.

this test is making sure that we get a warning when you call this and don't use 
the return value. It requires C++20 and above, hence the massive UNSUPPORTED 
list


Repository:
  rCXX libc++

https://reviews.llvm.org/D50341



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


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

2018-08-13 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 160458.
lebedev.ri added a comment.

Ping.

Rebased, now that the https://reviews.llvm.org/D50465 has landed, and we are 
now able to properly optimize the ugliest case:

> This comes with `Implicit Conversion Sanitizer - integer sign change` 
> (https://reviews.llvm.org/D50250):
> 
>   signed char test(unsigned int x) { return x; }
> 
> 
> `clang++ -fsanitize=implicit-conversion -S -emit-llvm -o - /tmp/test.cpp -O3`
> 
> - Old: F6904292: old.ll 
> - With this patch: F6904294: new.ll 


Repository:
  rC Clang

https://reviews.llvm.org/D50250

Files:
  docs/ReleaseNotes.rst
  docs/UndefinedBehaviorSanitizer.rst
  include/clang/Basic/Sanitizers.def
  lib/CodeGen/CGExprScalar.cpp
  test/CodeGen/catch-implicit-integer-conversions-basics.c
  test/CodeGen/catch-implicit-integer-conversions.c
  test/CodeGen/catch-implicit-integer-sign-changes-basics.c
  test/CodeGen/catch-implicit-integer-sign-changes-true-negatives.c
  test/CodeGen/catch-implicit-integer-sign-changes.c
  test/CodeGen/catch-implicit-integer-truncations-basics.c
  test/CodeGen/catch-implicit-integer-truncations.c
  test/CodeGenCXX/catch-implicit-integer-sign-changes-true-negatives.cpp
  test/Driver/fsanitize.c

Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -29,22 +29,22 @@
 // CHECK-COVERAGE-WIN64: "--dependent-lib={{[^"]*}}ubsan_standalone-x86_64.lib"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=integer %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-INTEGER -implicit-check-not="-fsanitize-address-use-after-scope"
-// CHECK-INTEGER: "-fsanitize={{((signed-integer-overflow|unsigned-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent|implicit-integer-truncation),?){6}"}}
+// CHECK-INTEGER: "-fsanitize={{((signed-integer-overflow|unsigned-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent|implicit-integer-truncation|implicit-integer-sign-change),?){7}"}}
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=implicit-conversion %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-implicit-conversion,CHECK-implicit-conversion-RECOVER
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=implicit-conversion -fsanitize-recover=implicit-conversion %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-implicit-conversion,CHECK-implicit-conversion-RECOVER
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=implicit-conversion -fno-sanitize-recover=implicit-conversion %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-implicit-conversion,CHECK-implicit-conversion-NORECOVER
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=implicit-conversion -fsanitize-trap=implicit-conversion %s -### 2>&1 | FileCheck %s --check-prefixes=CHECK-implicit-conversion,CHECK-implicit-conversion-TRAP
-// CHECK-implicit-conversion: "-fsanitize={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-RECOVER: "-fsanitize-recover={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-RECOVER-NOT: "-fno-sanitize-recover={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-RECOVER-NOT: "-fsanitize-trap={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-NORECOVER-NOT: "-fno-sanitize-recover={{((implicit-integer-truncation),?){1}"}} // ???
-// CHECK-implicit-conversion-NORECOVER-NOT: "-fsanitize-recover={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-NORECOVER-NOT: "-fsanitize-trap={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-TRAP: "-fsanitize-trap={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-TRAP-NOT: "-fsanitize-recover={{((implicit-integer-truncation),?){1}"}}
-// CHECK-implicit-conversion-TRAP-NOT: "-fno-sanitize-recover={{((implicit-integer-truncation),?){1}"}}
+// CHECK-implicit-conversion: "-fsanitize={{((implicit-integer-truncation|implicit-integer-sign-change),?){2}"}}
+// CHECK-implicit-conversion-RECOVER: "-fsanitize-recover={{((implicit-integer-truncation|implicit-integer-sign-change),?){2}"}}
+// CHECK-implicit-conversion-RECOVER-NOT: "-fno-sanitize-recover={{((implicit-integer-truncation|implicit-integer-sign-change),?){2}"}}
+// CHECK-implicit-conversion-RECOVER-NOT: "-fsanitize-trap={{((implicit-integer-truncation|implicit-integer-sign-change),?){2}"}}
+// CHECK-implicit-conversion-NORECOVER-NOT: "-fno-sanitize-recover={{((implicit-integer-truncation|implicit-integer-sign-change),?){2}"}} // ???
+// CHECK-implicit-conversion-NORECOVER-NOT: "-fsanitize-recover={{((implicit-integer-truncation|implicit-integer-sign-change),?){2}"}}
+// CHECK-implicit-conversion-NORECOVER-NOT: "-fsanitize-trap={{((implicit-integer-truncation|implicit-integer-sign-change),?){2}"}}
+// CHECK-implicit-conversion-TRAP: 

r339623 - Model type attributes as regular Attrs.

2018-08-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Aug 13 15:07:09 2018
New Revision: 339623

URL: http://llvm.org/viewvc/llvm-project?rev=339623=rev
Log:
Model type attributes as regular Attrs.

Specifically, AttributedType now tracks a regular attr::Kind rather than
having its own parallel Kind enumeration, and AttributedTypeLoc now
holds an Attr* instead of holding an ad-hoc collection of Attr fields.

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

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Attr.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp
cfe/trunk/lib/ARCMigrate/Transforms.cpp
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CheckerHelpers.cpp
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=339623=339622=339623=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Aug 13 15:07:09 2018
@@ -31,6 +31,7 @@
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/AddressSpaces.h"
+#include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
@@ -1422,7 +1423,7 @@ public:
 
   QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const;
 
-  QualType getAttributedType(AttributedType::Kind attrKind,
+  QualType getAttributedType(attr::Kind attrKind,
  QualType modifiedType,
  QualType equivalentType);
 

Modified: cfe/trunk/include/clang/AST/Attr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=339623=339622=339623=diff
==
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Mon Aug 13 15:07:09 2018
@@ -113,6 +113,19 @@ public:
   void printPretty(raw_ostream , const PrintingPolicy ) const;
 };
 
+class TypeAttr : public Attr {
+protected:
+  TypeAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex,
+   bool IsLateParsed)
+  : Attr(AK, R, SpellingListIndex, IsLateParsed) {}
+
+public:
+  static bool classof(const Attr *A) {
+return A->getKind() >= attr::FirstTypeAttr &&
+   A->getKind() <= attr::LastTypeAttr;
+  }
+};
+
 class StmtAttr : public Attr {
 protected:
   StmtAttr(attr::Kind AK, SourceRange R, unsigned SpellingListIndex,

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=339623=339622=339623=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Aug 13 15:07:09 2018
@@ -21,6 +21,7 @@
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/Basic/AddressSpaces.h"
+#include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
 #include "clang/Basic/LLVM.h"
@@ -1870,7 +1871,16 @@ public:
   bool isObjCQualifiedClassType() const;// Class
   bool isObjCObjectOrInterfaceType() const;
   bool isObjCIdType() const;// id
-  bool isObjCInertUnsafeUnretainedType() const;
+
+  /// Was this type written with the special inert-in-ARC __unsafe_unretained
+  /// qualifier?
+  ///
+  /// This approximates the answer to the following question: if this
+  /// translation unit were compiled in ARC, would this type be qualified
+  /// with __unsafe_unretained?
+  bool isObjCInertUnsafeUnretainedType() const {
+return hasAttr(attr::ObjCInertUnsafeUnretained);
+  }
 
   /// Whether the type is Objective-C 'id' or a __kindof type of an
   /// object type, e.g., __kindof NSView * or __kindof id
@@ -2084,6 +2094,10 @@ public:
   /// qualifiers from the outermost type.
   const ArrayType *castAsArrayTypeUnsafe() const;
 
+  /// Determine whether this type had the specified 

r339624 - Fix Clang warnings and bad #include filenames in r339595 and r339599.

2018-08-13 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Mon Aug 13 15:07:11 2018
New Revision: 339624

URL: http://llvm.org/viewvc/llvm-project?rev=339624=rev
Log:
Fix Clang warnings and bad #include filenames in r339595 and r339599.

Modified:

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h?rev=339624=339623=339624=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h 
(original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h 
Mon Aug 13 15:07:11 2018
@@ -32,6 +32,8 @@ class FieldNode {
 protected:
   const FieldRegion *FR;
 
+  ~FieldNode() = default;
+
 public:
   FieldNode(const FieldRegion *FR) : FR(FR) { assert(FR); }
 

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp?rev=339624=339623=339624=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 Mon Aug 13 15:07:11 2018
@@ -46,7 +46,7 @@
 //
 
//===--===//
 
-#include "ClangSACheckers.h"
+#include "../ClangSACheckers.h"
 #include "UninitializedObject.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -74,7 +74,7 @@ public:
 
 /// A basic field type, that is not a pointer or a reference, it's dynamic and
 /// static type is the same.
-class RegularField : public FieldNode {
+class RegularField final : public FieldNode {
 public:
   RegularField(const FieldRegion *FR) : FieldNode(FR) {}
 
@@ -84,7 +84,7 @@ public:
 
   virtual void printPrefix(llvm::raw_ostream ) const override {}
 
-  virtual void printNode(llvm::raw_ostream ) const {
+  virtual void printNode(llvm::raw_ostream ) const override {
 Out << getVariableName(getDecl());
   }
 

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp?rev=339624=339623=339624=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
 Mon Aug 13 15:07:11 2018
@@ -18,7 +18,7 @@
 //
 
//===--===//
 
-#include "ClangSACheckers.h"
+#include "../ClangSACheckers.h"
 #include "UninitializedObject.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -31,7 +31,7 @@ using namespace clang::ento;
 namespace {
 
 /// Represents a pointer or a reference field.
-class LocField : public FieldNode {
+class LocField final : public FieldNode {
   /// We'll store whether the pointee or the pointer itself is uninitialited.
   const bool IsDereferenced;
 


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


[PATCH] D50341: [libcxx] Fix XFAILs for aligned allocation tests on older OSX versions

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

Switch from XFAIL to UNSUPPORTED, per Marshall's offline comment.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50341

Files:
  libcxx/test/libcxx/memory/aligned_allocation_macro.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/delete_align_val_t_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_nothrow.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_nothrow_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align_nothrow.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align_nothrow.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_nothrow.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_nothrow.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/delete_align_val_t_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.sh.cpp

Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.sh.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.sh.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.sh.cpp
@@ -15,11 +15,12 @@
 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
 
-#include 
+// REQUIRES: -faligned-allocation
+// RUN: %compile %verify -faligned-allocation
 
-#include "test_macros.h"
+#include 
 
 int main ()
 {
-::operator new(4, std::align_val_t{4}, std::nothrow);  // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
+::operator new(4, std::align_val_t{4}, std::nothrow);  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 }
Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.sh.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.sh.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.sh.cpp
@@ -10,16 +10,17 @@
 
 // 
 
-// void* operator new[](std::size_t, std::align_val_t);
+// void* operator new(std::size_t, std::align_val_t);
 
 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
 
-#include 
+// REQUIRES: -faligned-allocation
+// RUN: %compile %verify -faligned-allocation
 
-#include "test_macros.h"
+#include 
 
 int main ()
 {
-::operator new[](4, std::align_val_t{4});  // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
+::operator new(4, std::align_val_t{4});  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 }
Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.fail.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.fail.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-// -*- C++ -*-
-//===--===//
-//
-// 

[clang-tools-extra] r339620 - Revert "[clang-doc] Updating BitcodeReader to use llvm::Error"

2018-08-13 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Mon Aug 13 14:51:48 2018
New Revision: 339620

URL: http://llvm.org/viewvc/llvm-project?rev=339620=rev
Log:
Revert "[clang-doc] Updating BitcodeReader to use llvm::Error"

This reverts commit r339617 for breaking bots.

Modified:
clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
clang-tools-extra/trunk/clang-doc/BitcodeReader.h

Modified: clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp?rev=339620=339619=339620=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp Mon Aug 13 14:51:48 2018
@@ -10,7 +10,6 @@
 #include "BitcodeReader.h"
 #include "llvm/ADT/IndexedMap.h"
 #include "llvm/ADT/Optional.h"
-#include "llvm/Support/Error.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
@@ -18,53 +17,49 @@ namespace doc {
 
 using Record = llvm::SmallVector;
 
-llvm::Error decodeRecord(Record R, llvm::SmallVectorImpl ,
- llvm::StringRef Blob) {
+bool decodeRecord(Record R, llvm::SmallVectorImpl ,
+  llvm::StringRef Blob) {
   Field.assign(Blob.begin(), Blob.end());
-  return llvm::Error::success();
+  return true;
 }
 
-llvm::Error decodeRecord(Record R, SymbolID , llvm::StringRef Blob) {
+bool decodeRecord(Record R, SymbolID , llvm::StringRef Blob) {
   if (R[0] != BitCodeConstants::USRHashSize)
-return llvm::make_error("Incorrect USR size.\n",
-   llvm::inconvertibleErrorCode());
+return false;
 
   // First position in the record is the length of the following array, so we
   // copy the following elements to the field.
   for (int I = 0, E = R[0]; I < E; ++I)
 Field[I] = R[I + 1];
-  return llvm::Error::success();
+  return true;
 }
 
-llvm::Error decodeRecord(Record R, bool , llvm::StringRef Blob) {
+bool decodeRecord(Record R, bool , llvm::StringRef Blob) {
   Field = R[0] != 0;
-  return llvm::Error::success();
+  return true;
 }
 
-llvm::Error decodeRecord(Record R, int , llvm::StringRef Blob) {
+bool decodeRecord(Record R, int , llvm::StringRef Blob) {
   if (R[0] > INT_MAX)
-return llvm::make_error("Integer too large to parse.\n",
-   llvm::inconvertibleErrorCode());
+return false;
   Field = (int)R[0];
-  return llvm::Error::success();
+  return true;
 }
 
-llvm::Error decodeRecord(Record R, AccessSpecifier ,
- llvm::StringRef Blob) {
+bool decodeRecord(Record R, AccessSpecifier , llvm::StringRef Blob) {
   switch (R[0]) {
   case AS_public:
   case AS_private:
   case AS_protected:
   case AS_none:
 Field = (AccessSpecifier)R[0];
-return llvm::Error::success();
+return true;
   default:
-return llvm::make_error(
-"Invalid value for AccessSpecifier.\n", 
llvm::inconvertibleErrorCode());
+return false;
   }
 }
 
-llvm::Error decodeRecord(Record R, TagTypeKind , llvm::StringRef Blob) {
+bool decodeRecord(Record R, TagTypeKind , llvm::StringRef Blob) {
   switch (R[0]) {
   case TTK_Struct:
   case TTK_Interface:
@@ -72,23 +67,21 @@ llvm::Error decodeRecord(Record R, TagTy
   case TTK_Class:
   case TTK_Enum:
 Field = (TagTypeKind)R[0];
-return llvm::Error::success();
+return true;
   default:
-return llvm::make_error(
-"Invalid value for TagTypeKind.\n", llvm::inconvertibleErrorCode());
+return false;
   }
 }
 
-llvm::Error decodeRecord(Record R, llvm::Optional ,
- llvm::StringRef Blob) {
+bool decodeRecord(Record R, llvm::Optional ,
+  llvm::StringRef Blob) {
   if (R[0] > INT_MAX)
-return llvm::make_error("Integer too large to parse.\n",
-   llvm::inconvertibleErrorCode());
+return false;
   Field.emplace((int)R[0], Blob);
-  return llvm::Error::success();
+  return true;
 }
 
-llvm::Error decodeRecord(Record R, InfoType , llvm::StringRef Blob) {
+bool decodeRecord(Record R, InfoType , llvm::StringRef Blob) {
   switch (auto IT = static_cast(R[0])) {
   case InfoType::IT_namespace:
   case InfoType::IT_record:
@@ -96,13 +89,12 @@ llvm::Error decodeRecord(Record R, InfoT
   case InfoType::IT_default:
   case InfoType::IT_enum:
 Field = IT;
-return llvm::Error::success();
+return true;
   }
-  return llvm::make_error("Invalid value for InfoType.\n",
- llvm::inconvertibleErrorCode());
+  return false;
 }
 
-llvm::Error decodeRecord(Record R, FieldId , llvm::StringRef Blob) {
+bool decodeRecord(Record R, FieldId , llvm::StringRef Blob) {
   switch (auto F = static_cast(R[0])) {
   case FieldId::F_namespace:
   case FieldId::F_parent:
@@ -112,51 +104,45 @@ llvm::Error decodeRecord(Record R, Field
   case FieldId::F_child_record:
   case 

[PATCH] D49511: [Sema/Attribute] Check for noderef attribute

2018-08-13 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:14249
+
+if (Sema::TypeHasNoDeref(Inner))
+  DeclRef = E;

aaron.ballman wrote:
> leonardchan wrote:
> > aaron.ballman wrote:
> > > The sugar was stripped off at the pointer level, but not at the pointee 
> > > level. e.g.,
> > > ```
> > > typedef int (bobble);
> > > typedef bobble * (frobble);
> > > typedef frobble * yobble;
> > > 
> > > yobble gobble;
> > > ```
> > > I think you can handle this within `TypeHasNoDeref()` and that should fix 
> > > up all the callers.
> > So `TypeHasNoDeref()` checks for the attribute on the base type already and 
> > is called after the pointer is stripped off. Attempting to desugar via 
> > `getDesugaredType()` here also removes the `address_space` attribute from 
> > the type I'm checking.
> > 
> > Do you know another method that essentially "expands" the typedefs without 
> > stripping the qualifiers? Otherwise I think I do need do the desugaring at 
> > the pointer level. Alternatively I could also change this method such that 
> > it accepts pointers instead of pointees since it appears I already call 
> > `getDesugaredType()` for almost every pointer who's pointee I'm passing to 
> > `TypeHasNoDeref()`.
> > 
> > Also I tested with your example and the warning still seems to be thrown 
> > appropriately. 
> I think you have to do the desugaring manually in a loop with 
> `getSingleStepDesugaredType()` so that you don't strip off attributed type 
> information along with the rest of the type sugar.
> 
> > Also I tested with your example and the warning still seems to be thrown 
> > appropriately.
> 
> The example may depend on where you put the attribute (inside the parens vs 
> outside the parens, for instance); it was an off-the-cuff example, so it may 
> need some tweaking.
Done. Also added different variations of your example to the tests.


Repository:
  rC Clang

https://reviews.llvm.org/D49511



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


[PATCH] D49511: [Sema/Attribute] Check for noderef attribute

2018-08-13 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 160451.
leonardchan marked 3 inline comments as done.
leonardchan added a comment.

- Remove sugar from pointee types


Repository:
  rC Clang

https://reviews.llvm.org/D49511

Files:
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaExprMember.cpp
  lib/Sema/SemaType.cpp
  test/Frontend/noderef.c
  test/Frontend/noderef_on_non_pointers.cpp
  test/Frontend/noderef_on_non_pointers.m

Index: test/Frontend/noderef_on_non_pointers.m
===
--- /dev/null
+++ test/Frontend/noderef_on_non_pointers.m
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -verify %s
+
+#define NODEREF __attribute__((noderef))
+
+@interface NSObject
++ (id)new;
+@end
+
+void func() {
+  id NODEREF obj = [NSObject new]; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+}
Index: test/Frontend/noderef_on_non_pointers.cpp
===
--- /dev/null
+++ test/Frontend/noderef_on_non_pointers.cpp
@@ -0,0 +1,88 @@
+// RUN: %clang_cc1 -fblocks -verify %s
+
+/**
+ * Test 'noderef' attribute against other pointer-like types.
+ */
+
+#define NODEREF __attribute__((noderef))
+
+void Normal() {
+  int NODEREF i;// expected-warning{{'noderef' can only be used on an array or pointer type}}
+  int NODEREF *i_ptr;   // ok
+  int NODEREF **i_ptr2; // ok
+  int *NODEREF i_ptr3;  // expected-warning{{'noderef' can only be used on an array or pointer type}}
+  int *NODEREF *i_ptr4; // ok
+
+  auto NODEREF *auto_i_ptr = i_ptr;
+  auto NODEREF auto_i = i; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+
+  struct {
+int x;
+int y;
+  } NODEREF *s;
+
+  int __attribute__((noderef(10))) * no_args; // expected-error{{'noderef' attribute takes no arguments}}
+}
+
+const int NODEREF *const_i_ptr;
+static int NODEREF *static_i_ptr;
+
+void ParenTypes() {
+  int NODEREF(*i_ptr);// ok (same as `int NODEREF *`)
+  int NODEREF *(*i_ptr2); // ok (same as `int NODEREF **`)
+}
+
+// Function declarations
+int NODEREF func();   // expected-warning{{'noderef' can only be used on an array or pointer type}}
+int NODEREF *func2(); // ok (returning pointer)
+
+typedef int NODEREF (*func3)(int); // expected-warning{{'noderef' can only be used on an array or pointer type}}
+typedef int NODEREF *(*func4)(int);
+
+void Arrays() {
+  int NODEREF i_arr[10];  // ok
+  int NODEREF i_arr2[10][10]; // ok
+  int NODEREF *i_arr3[10];// ok
+  int NODEREF i_arr4[] = {1, 2};
+}
+
+void ParenArrays() {
+  int NODEREF(i_ptr[10]);
+  int NODEREF(i_ptr2[10])[10];
+}
+
+typedef int NODEREF *(*func5[10])(int);
+
+// Arguments
+void func6(int NODEREF x); // expected-warning{{'noderef' can only be used on an array or pointer type}}
+void func7(int NODEREF *x);
+void func8() NODEREF;
+
+void References() {
+  int x = 2;
+  int NODEREF  = x; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+  int *xp = 
+  int NODEREF * = xp; // ok (reference to a NODEREF *)
+  int *NODEREF  = xp; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+}
+
+void BlockPointers() {
+  typedef int NODEREF (^IntBlock)(); // expected-warning{{'noderef' can only be used on an array or pointer type}}
+}
+
+class A {
+public:
+  int member;
+  int NODEREF *member2;
+  int NODEREF member3; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+};
+
+void MemberPointer() {
+  int NODEREF A::*var = ::member; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+}
+
+template 
+class B {
+  Ty NODEREF *member;
+  Ty NODEREF member2; // expected-warning{{'noderef' can only be used on an array or pointer type}}
+};
Index: test/Frontend/noderef.c
===
--- /dev/null
+++ test/Frontend/noderef.c
@@ -0,0 +1,205 @@
+// RUN: %clang_cc1 -Wno-unused-value -verify %s
+
+#define NODEREF __attribute__((noderef))
+
+struct S {
+  int a;
+  int b;
+};
+
+struct S2 {
+  int a[2];
+  int NODEREF a2[2];
+  int *b;
+  int NODEREF *b2;
+  struct S *s;
+  struct S NODEREF *s2;
+};
+
+int NODEREF *func(int NODEREF *arg) {  // expected-note{{arg declared here}}
+  int y = *arg; // expected-warning{{dereferencing arg; was declared with a 'noderef' type}}
+  return arg;
+}
+
+void func2(int x) {}
+
+int test() {
+  int NODEREF *p; // expected-note 37 {{p declared here}}
+  int *p2;
+
+  int x = *p;   // expected-warning{{dereferencing p; was declared with a 'noderef' type}}
+  x = *((int NODEREF *)p2); // expected-warning{{dereferencing expression marked as 'noderef'}}
+
+  int NODEREF **q;
+  

[PATCH] D50666: Fix Stmt::ignoreImplicit

2018-08-13 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added reviewers: rsmith, dblaikie, klimek.
Herald added a subscriber: cfe-commits.

A CXXBindTemporaryExpr can appear inside an ImplicitCastExpr, and was
not ignored previously.

Fixes the case reported in PR37327.


Repository:
  rC Clang

https://reviews.llvm.org/D50666

Files:
  lib/AST/Stmt.cpp
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp


Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1302,6 +1302,45 @@
   varDecl(has(ignoringImplicit(cxxConstructExpr());
 }
 
+TEST(IgnoringImplicit, MatchesNestedImplicit) {
+  EXPECT_TRUE(matches(R"(
+
+struct OtherType;
+
+struct SomeType
+{
+SomeType() {}
+SomeType(const OtherType&) {}
+SomeType& operator=(OtherType const&) { return *this; }
+};
+
+struct OtherType
+{
+OtherType() {}
+~OtherType() {}
+};
+
+OtherType something()
+{
+return {};
+}
+
+int main()
+{
+SomeType i = something();
+}
+)"
+  , varDecl(
+  hasName("i"),
+  hasInitializer(exprWithCleanups(has(
+cxxConstructExpr(has(expr(ignoringImplicit(cxxConstructExpr(
+  has(expr(ignoringImplicit(callExpr(
+  )
+)))
+  )
+  ));
+}
+
 TEST(IgnoringImplicit, DoesNotMatchIncorrectly) {
   EXPECT_TRUE(
   notMatches("class C {}; C a = C();", varDecl(has(cxxConstructExpr();
Index: lib/AST/Stmt.cpp
===
--- lib/AST/Stmt.cpp
+++ lib/AST/Stmt.cpp
@@ -113,17 +113,23 @@
 Stmt *Stmt::IgnoreImplicit() {
   Stmt *s = this;
 
-  if (auto *ewc = dyn_cast(s))
-s = ewc->getSubExpr();
+  Stmt *lasts = nullptr;
 
-  if (auto *mte = dyn_cast(s))
-s = mte->GetTemporaryExpr();
+  while (s != lasts) {
+lasts = s;
 
-  if (auto *bte = dyn_cast(s))
-s = bte->getSubExpr();
+if (auto *ewc = dyn_cast(s))
+  s = ewc->getSubExpr();
 
-  while (auto *ice = dyn_cast(s))
-s = ice->getSubExpr();
+if (auto *mte = dyn_cast(s))
+  s = mte->GetTemporaryExpr();
+
+if (auto *bte = dyn_cast(s))
+  s = bte->getSubExpr();
+
+if (auto *ice = dyn_cast(s))
+  s = ice->getSubExpr();
+  }
 
   return s;
 }


Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1302,6 +1302,45 @@
   varDecl(has(ignoringImplicit(cxxConstructExpr());
 }
 
+TEST(IgnoringImplicit, MatchesNestedImplicit) {
+  EXPECT_TRUE(matches(R"(
+
+struct OtherType;
+
+struct SomeType
+{
+SomeType() {}
+SomeType(const OtherType&) {}
+SomeType& operator=(OtherType const&) { return *this; }
+};
+
+struct OtherType
+{
+OtherType() {}
+~OtherType() {}
+};
+
+OtherType something()
+{
+return {};
+}
+
+int main()
+{
+SomeType i = something();
+}
+)"
+  , varDecl(
+  hasName("i"),
+  hasInitializer(exprWithCleanups(has(
+cxxConstructExpr(has(expr(ignoringImplicit(cxxConstructExpr(
+  has(expr(ignoringImplicit(callExpr(
+  )
+)))
+  )
+  ));
+}
+
 TEST(IgnoringImplicit, DoesNotMatchIncorrectly) {
   EXPECT_TRUE(
   notMatches("class C {}; C a = C();", varDecl(has(cxxConstructExpr();
Index: lib/AST/Stmt.cpp
===
--- lib/AST/Stmt.cpp
+++ lib/AST/Stmt.cpp
@@ -113,17 +113,23 @@
 Stmt *Stmt::IgnoreImplicit() {
   Stmt *s = this;
 
-  if (auto *ewc = dyn_cast(s))
-s = ewc->getSubExpr();
+  Stmt *lasts = nullptr;
 
-  if (auto *mte = dyn_cast(s))
-s = mte->GetTemporaryExpr();
+  while (s != lasts) {
+lasts = s;
 
-  if (auto *bte = dyn_cast(s))
-s = bte->getSubExpr();
+if (auto *ewc = dyn_cast(s))
+  s = ewc->getSubExpr();
 
-  while (auto *ice = dyn_cast(s))
-s = ice->getSubExpr();
+if (auto *mte = dyn_cast(s))
+  s = mte->GetTemporaryExpr();
+
+if (auto *bte = dyn_cast(s))
+  s = bte->getSubExpr();
+
+if (auto *ice = dyn_cast(s))
+  s = ice->getSubExpr();
+  }
 
   return s;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-08-13 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett closed this revision.
juliehockett added a comment.

Closed in https://reviews.llvm.org/rL339617.


https://reviews.llvm.org/D48909



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


[clang-tools-extra] r339617 - [clang-doc] Updating BitcodeReader to use llvm::Error

2018-08-13 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Mon Aug 13 14:39:03 2018
New Revision: 339617

URL: http://llvm.org/viewvc/llvm-project?rev=339617=rev
Log:
[clang-doc] Updating BitcodeReader to use llvm::Error

Modified:
clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
clang-tools-extra/trunk/clang-doc/BitcodeReader.h

Modified: clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp?rev=339617=339616=339617=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp Mon Aug 13 14:39:03 2018
@@ -10,6 +10,7 @@
 #include "BitcodeReader.h"
 #include "llvm/ADT/IndexedMap.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
@@ -17,49 +18,53 @@ namespace doc {
 
 using Record = llvm::SmallVector;
 
-bool decodeRecord(Record R, llvm::SmallVectorImpl ,
-  llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, llvm::SmallVectorImpl ,
+ llvm::StringRef Blob) {
   Field.assign(Blob.begin(), Blob.end());
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, SymbolID , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, SymbolID , llvm::StringRef Blob) {
   if (R[0] != BitCodeConstants::USRHashSize)
-return false;
+return llvm::make_error("Incorrect USR size.\n",
+   llvm::inconvertibleErrorCode());
 
   // First position in the record is the length of the following array, so we
   // copy the following elements to the field.
   for (int I = 0, E = R[0]; I < E; ++I)
 Field[I] = R[I + 1];
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, bool , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, bool , llvm::StringRef Blob) {
   Field = R[0] != 0;
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, int , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, int , llvm::StringRef Blob) {
   if (R[0] > INT_MAX)
-return false;
+return llvm::make_error("Integer too large to parse.\n",
+   llvm::inconvertibleErrorCode());
   Field = (int)R[0];
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, AccessSpecifier , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, AccessSpecifier ,
+ llvm::StringRef Blob) {
   switch (R[0]) {
   case AS_public:
   case AS_private:
   case AS_protected:
   case AS_none:
 Field = (AccessSpecifier)R[0];
-return true;
+return llvm::Error::success();
   default:
-return false;
+return llvm::make_error(
+"Invalid value for AccessSpecifier.\n", 
llvm::inconvertibleErrorCode());
   }
 }
 
-bool decodeRecord(Record R, TagTypeKind , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, TagTypeKind , llvm::StringRef Blob) {
   switch (R[0]) {
   case TTK_Struct:
   case TTK_Interface:
@@ -67,21 +72,23 @@ bool decodeRecord(Record R, TagTypeKind
   case TTK_Class:
   case TTK_Enum:
 Field = (TagTypeKind)R[0];
-return true;
+return llvm::Error::success();
   default:
-return false;
+return llvm::make_error(
+"Invalid value for TagTypeKind.\n", llvm::inconvertibleErrorCode());
   }
 }
 
-bool decodeRecord(Record R, llvm::Optional ,
-  llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, llvm::Optional ,
+ llvm::StringRef Blob) {
   if (R[0] > INT_MAX)
-return false;
+return llvm::make_error("Integer too large to parse.\n",
+   llvm::inconvertibleErrorCode());
   Field.emplace((int)R[0], Blob);
-  return true;
+  return llvm::Error::success();
 }
 
-bool decodeRecord(Record R, InfoType , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, InfoType , llvm::StringRef Blob) {
   switch (auto IT = static_cast(R[0])) {
   case InfoType::IT_namespace:
   case InfoType::IT_record:
@@ -89,12 +96,13 @@ bool decodeRecord(Record R, InfoType 
   case InfoType::IT_default:
   case InfoType::IT_enum:
 Field = IT;
-return true;
+return llvm::Error::success();
   }
-  return false;
+  return llvm::make_error("Invalid value for InfoType.\n",
+ llvm::inconvertibleErrorCode());
 }
 
-bool decodeRecord(Record R, FieldId , llvm::StringRef Blob) {
+llvm::Error decodeRecord(Record R, FieldId , llvm::StringRef Blob) {
   switch (auto F = static_cast(R[0])) {
   case FieldId::F_namespace:
   case FieldId::F_parent:
@@ -104,45 +112,51 @@ bool decodeRecord(Record R, FieldId 
   case FieldId::F_child_record:
   case FieldId::F_default:
 Field = F;
-return true;
+return 

[PATCH] D50630: [AST] Update/correct the static_asserts for the bit-fields in Type

2018-08-13 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D50630#1197795, @riccibruno wrote:

> @rjmccall
>
> I would argue that we should make these bit-fields take 8 bytes for the 
> following reasons:
>
> 1. On 64 bits archs, this is free since we have already a little less than 8 
> bytes of padding here, assuming Type keep its 18 bits.


First, `Type` is not 16-byte aligned as far as the compiler is concerned; it is 
merely
dynamically aligned to a 16-byte boundary when allocated.  You actually 
verified this
when you did your experiment of printing out the sizes of various `Type` 
subclasses,
because the value of `sizeof` is always rounded up to the alignment, meaning 
that a
size of 40 would not be legal if `Type` were actually 16-byte-aligned.

Because `Type` is only 4/8-byte aligned, its only tail padding is what's needed 
to
fill up a pointer after these bit-fields, which is supposed to be 4 bytes but is
instead apparently 0 bytes because we overflowed one of the bit-fields.

Not officially aligning `Type` to 16 bytes is fairly important for memory 
efficiency
even on 64-bit hosts because many of our types use tail-allocated storage, which
naturally starts at `sizeof(T)` bytes from the address point; if we formally 
aligned
`Type` subclasses to 16 bytes, we'd often waste a pointer of that storage.

Second, tail padding of base classes is not necessarily wasted under the 
Itanium C++ ABI.
Itanium will start placing sub-objects in the tail-padding of the last 
non-empty base class
as long as that base is POD under the rules of C++03; `Type` is not POD because 
it has a
user-provided constructor.

Looking at `Type.h`, we don't seem to be taking advantage of this as much as I 
thought,
at least in the `Type` hierarchy (maybe we do in the `Stmt` or `Decl` 
hierarchies).  We
have a lot of subclasses that have 32 bits of miscellaneous storage but either 
(1) don't
order their fields correctly to allow subclasses to fit in or (2) also subclass 
`FoldingSetNode`,
which breaks up the optimization.

Since we do care primarily about 64-bit hosts, I'm leaning towards agreeing 
that we should
just accept that we have 64 bits of storage here, 46 of which are available to 
subclasses.
If you're interested in optimizing this, it would be nice if you could go 
through all the
subclasses looking for 32-bit chunks that could be profitably moved up into 
`Type`.

> 2. On 32 bits archs, this a priori increase the size of each Type by 4 bytes. 
> However, types are aligned to 16 bytes because of the fast CVR qualifiers. 
> Doing an fsyntax-only on all of Boost with -print-stats I get that by far the 
> most commonly used Types have size 40 or 48 (on a 64 bits arch). That is 5 or 
> 6 pointers. This would be 20 or 24 bytes on 32 bits archs if we assume that 
> every member of the most commonly used types are pointers and that we shrink 
> the bitfields to 32 bits. But since Types are aligned to 16 bytes we do not 
> gain anything.

Types aren't the only thing allocated in the ASTContext, so allocating a 
16-byte-aligned
chunk with a non-multiple-of-16 size doesn't mean that any difference between 
the size
and the next 16-byte boundary is necessarily wasted.  But you're probably right 
that the
difference between `Type` being 12 and 16 bytes is probably not a big deal.

John.


Repository:
  rC Clang

https://reviews.llvm.org/D50630



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


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

2018-08-13 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added inline comments.



Comment at: lib/AST/DeclBase.cpp:854-859
+  auto I = Attrs.begin(), E = Attrs.end();
+  for (; I != E; ++I) {
+if (!(*I)->isInherited())
+  break;
+  }
+  Attrs.insert(I, A);

aaron.ballman wrote:
> The unfortunate part about this is that inherited attributes are fairly 
> common, so this extra searching may happen more often than we'd like. I 
> wonder how bad it would be to keep track of the location within the list 
> where the inherited attributes start. Then again, the list of attributes 
> should be relatively short in most cases, so this search isn't likely to be 
> too expensive.
> 
> Having some performance measurements might help decide this, too.
Timed clang-compilation using perf (`perf stat bin/clang 
llvm/unittests/IR/InstructionsTest.cpp ...`), before this patch (r339574):
```
   7647.415800  task-clock (msec) #0.983 CPUs utilized
   289  context-switches  #0.038 K/sec
26  cpu-migrations#0.003 K/sec
86,494  page-faults   #0.011 M/sec
19,068,741,863  cycles#2.493 GHz
26,581,355,844  instructions  #1.39  insn per cycle
 6,242,394,037  branches  #  816.275 M/sec
   128,405,656  branch-misses #2.06% of all branches

   7.779848330 seconds time elapsed
```

With this patch:
```
   7679.173467  task-clock (msec) #0.987 CPUs utilized
   321  context-switches  #0.042 K/sec
23  cpu-migrations#0.003 K/sec
86,071  page-faults   #0.011 M/sec
19,150,248,538  cycles#2.494 GHz
26,667,465,697  instructions  #1.39  insn per cycle
 6,262,381,898  branches  #  815.502 M/sec
   128,527,669  branch-misses #2.05% of all branches

   7.779477815 seconds time elapsed
```
(Intel(R) Xeon(R) Platinum 8180M CPU @ 2.50GHz)

The vector insert operation is also be `O(n)`. If the number of non-inherited 
is expected to be smaller, we can instead search for the first inherited 
attribute starting at the end of the vector. If we want to avoid the `O(n)` 
entirely, we need one list for inherited and another for non-inherited 
attributes.


Repository:
  rC Clang

https://reviews.llvm.org/D50214



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


[PATCH] D41217: [Concepts] Concept Specialization Expressions

2018-08-13 Thread Saar Raz via Phabricator via cfe-commits
saar.raz added inline comments.



Comment at: include/clang/AST/DeclTemplate.h:3063
   SourceRange getSourceRange() const override LLVM_READONLY {
-return SourceRange(getLocation(), getLocation());
+return SourceRange(getLocation(), getConstraintExpr()->getLocEnd());
   }

steveire wrote:
> `getLocEnd` is deprecated and will be removed soon. See 
> http://clang-developers.42468.n3.nabble.com/API-Removal-Notice-4-weeks-getStartLoc-getLocStart-getLocEnd-td4061566.html
Good to know, but I'm not yet merged against trunk so getEndLoc isn't here yet 
(will soon post a merged version of this patch)


Repository:
  rC Clang

https://reviews.llvm.org/D41217



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


r339613 - Convert if/else to a switch. NFC.

2018-08-13 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Aug 13 13:59:57 2018
New Revision: 339613

URL: http://llvm.org/viewvc/llvm-project?rev=339613=rev
Log:
Convert if/else to a switch. NFC.

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

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=339613=339612=339613=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Mon Aug 13 13:59:57 2018
@@ -1874,57 +1874,65 @@ CodeGenFunction::GenerateCopyHelperFunct
 Address srcField = Builder.CreateStructGEP(src, index, 
capture.getOffset());
 Address dstField = Builder.CreateStructGEP(dst, index, 
capture.getOffset());
 
-// If there's an explicit copy expression, we do that.
-if (CI.getCopyExpr()) {
-  assert(CopiedCapture.Kind == BlockCaptureEntityKind::CXXRecord);
+switch (CopiedCapture.Kind) {
+case BlockCaptureEntityKind::CXXRecord:
+  // If there's an explicit copy expression, we do that.
+  assert(CI.getCopyExpr() && "copy expression for variable is missing");
   EmitSynthesizedCXXCopyCtor(dstField, srcField, CI.getCopyExpr());
-} else if (CopiedCapture.Kind == BlockCaptureEntityKind::ARCWeak) {
+  break;
+case BlockCaptureEntityKind::ARCWeak:
   EmitARCCopyWeak(dstField, srcField);
-// If this is a C struct that requires non-trivial copy construction, emit 
a
-// call to its copy constructor.
-} else if (CopiedCapture.Kind ==
-   BlockCaptureEntityKind::NonTrivialCStruct) {
+  break;
+case BlockCaptureEntityKind::NonTrivialCStruct: {
+  // If this is a C struct that requires non-trivial copy construction,
+  // emit a call to its copy constructor.
   QualType varType = CI.getVariable()->getType();
   callCStructCopyConstructor(MakeAddrLValue(dstField, varType),
  MakeAddrLValue(srcField, varType));
-} else {
+  break;
+}
+case BlockCaptureEntityKind::ARCStrong: {
   llvm::Value *srcValue = Builder.CreateLoad(srcField, "blockcopy.src");
-  if (CopiedCapture.Kind == BlockCaptureEntityKind::ARCStrong) {
-// At -O0, store null into the destination field (so that the
-// storeStrong doesn't over-release) and then call storeStrong.
-// This is a workaround to not having an initStrong call.
-if (CGM.getCodeGenOpts().OptimizationLevel == 0) {
-  auto *ty = cast(srcValue->getType());
-  llvm::Value *null = llvm::ConstantPointerNull::get(ty);
-  Builder.CreateStore(null, dstField);
-  EmitARCStoreStrongCall(dstField, srcValue, true);
-
-// With optimization enabled, take advantage of the fact that
-// the blocks runtime guarantees a memcpy of the block data, and
-// just emit a retain of the src field.
-} else {
-  EmitARCRetainNonBlock(srcValue);
+  // At -O0, store null into the destination field (so that the
+  // storeStrong doesn't over-release) and then call storeStrong.
+  // This is a workaround to not having an initStrong call.
+  if (CGM.getCodeGenOpts().OptimizationLevel == 0) {
+auto *ty = cast(srcValue->getType());
+llvm::Value *null = llvm::ConstantPointerNull::get(ty);
+Builder.CreateStore(null, dstField);
+EmitARCStoreStrongCall(dstField, srcValue, true);
 
-  // Unless EH cleanup is required, we don't need this anymore, so kill
-  // it. It's not quite worth the annoyance to avoid creating it in the
-  // first place.
-  if (!needsEHCleanup(captureType.isDestructedType()))
-cast(dstField.getPointer())->eraseFromParent();
-}
+  // With optimization enabled, take advantage of the fact that
+  // the blocks runtime guarantees a memcpy of the block data, and
+  // just emit a retain of the src field.
   } else {
-assert(CopiedCapture.Kind == BlockCaptureEntityKind::BlockObject);
-srcValue = Builder.CreateBitCast(srcValue, VoidPtrTy);
-llvm::Value *dstAddr =
-  Builder.CreateBitCast(dstField.getPointer(), VoidPtrTy);
-llvm::Value *args[] = {
-  dstAddr, srcValue, llvm::ConstantInt::get(Int32Ty, 
flags.getBitMask())
-};
+EmitARCRetainNonBlock(srcValue);
 
-if (CI.isByRef() && C.getBlockVarCopyInit(CI.getVariable()).canThrow())
-  EmitRuntimeCallOrInvoke(CGM.getBlockObjectAssign(), args);
-else
-  EmitNounwindRuntimeCall(CGM.getBlockObjectAssign(), args);
+// Unless EH cleanup is required, we don't need this anymore, so kill
+// it. It's not quite worth the annoyance to avoid creating it in the
+// first place.
+if (!needsEHCleanup(captureType.isDestructedType()))
+  cast(dstField.getPointer())->eraseFromParent();
   }
+  break;

[PATCH] D41217: [Concepts] Concept Specialization Expressions

2018-08-13 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added inline comments.



Comment at: include/clang/AST/DeclTemplate.h:3063
   SourceRange getSourceRange() const override LLVM_READONLY {
-return SourceRange(getLocation(), getLocation());
+return SourceRange(getLocation(), getConstraintExpr()->getLocEnd());
   }

`getLocEnd` is deprecated and will be removed soon. See 
http://clang-developers.42468.n3.nabble.com/API-Removal-Notice-4-weeks-getStartLoc-getLocStart-getLocEnd-td4061566.html


Repository:
  rC Clang

https://reviews.llvm.org/D41217



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


[PATCH] D50652: [libcxx] By default, do not use internal_linkage to hide symbols from the ABI

2018-08-13 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

In https://reviews.llvm.org/D50652#1197830, @rnk wrote:

> In https://reviews.llvm.org/D50652#1197780, @ldionne wrote:
>
> > One thing to keep in mind is that we do not have a solution that allows 
> > removing both `internal_linkage` and `always_inline`. It's either 
> > `internal_linkage` or `always_inline`, but you can't get rid of both until 
> > we fix some problems with extern template declarations and visibility 
> > attributes. What I can do, however, is reverse the default to use 
> > `internal_linkage`, and then have a temporary hook that allows Chromium to 
> > stay on `always_inline`. In the future, we'd remove that hook and the 
> > choice would be between `internal_linkage` and nothing at all.
>
>
> It's probably worth it to me to debug and understand that problem. Is there a 
> good explanation of it?


http://lists.llvm.org/pipermail/llvm-dev/2018-July/124549.html

This is understood, it just needs more work than we can reasonably expect to 
get into LLVM 7.

> Also, if a user could define _LIBCPP_ABI_UNSTABLE, does this problem still 
> apply? Could we remove the problematic visibility attributes if the ABI is 
> unstable?

I guess in that case, we could simply remove _all_ visibility attributes (and 
linkage attributes). libc++ may end up exporting more symbols than we want, but 
defining `_LIBCPP_ABI_UNSTABLE` would explicitly state that we don't care about 
that. Doing this is a possibility, but don't think this is the way we want to 
solve the problem at hand.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50652



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


[PATCH] D50341: [libcxx] Fix XFAILs for aligned allocation tests on older OSX versions

2018-08-13 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

This works with all the dylibs I have locally, with various combinations of 
availability enabled/disabled and all standards. I've asked Marshall to check 
on his system, where he initially reported some failures.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50341



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


[PATCH] D50663: [libunwind] [cmake] Add MINGW_LIBRARIES to the linker flags

2018-08-13 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added reviewers: rnk, compnerd, phosek, smeenai.
Herald added subscribers: chrib, mgorny.

This is essential when building with -nodefaultlibs.

In some CMake versions (noticed in 3.5.1), the same libraries are picked up 
from CMAKE_REQUIRED_LIBRARIES in some exceptional situations (if CXX probing 
failed, due to libc++ not being built yet, the libraries from 
CMAKE_REQUIRED_LIBRARIES are used for linking the target library), but not at 
all in other newer CMake versions (3.10).

This is similar to what already is done in libcxxabi in SVN r302760 and libcxx 
in SVN r312498.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D50663

Files:
  src/CMakeLists.txt


Index: src/CMakeLists.txt
===
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -62,6 +62,9 @@
 
 append_if(LIBUNWIND_LINK_FLAGS LIBUNWIND_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
 
+# MINGW_LIBRARIES is defined in config-ix.cmake
+append_if(libraries MINGW "${MINGW_LIBRARIES}")
+
 if (LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG AND LIBUNWIND_HAS_FUNWIND_TABLES)
   list(APPEND LIBUNWIND_COMPILE_FLAGS -fno-exceptions)
   list(APPEND LIBUNWIND_COMPILE_FLAGS -funwind-tables)


Index: src/CMakeLists.txt
===
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -62,6 +62,9 @@
 
 append_if(LIBUNWIND_LINK_FLAGS LIBUNWIND_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs)
 
+# MINGW_LIBRARIES is defined in config-ix.cmake
+append_if(libraries MINGW "${MINGW_LIBRARIES}")
+
 if (LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG AND LIBUNWIND_HAS_FUNWIND_TABLES)
   list(APPEND LIBUNWIND_COMPILE_FLAGS -fno-exceptions)
   list(APPEND LIBUNWIND_COMPILE_FLAGS -funwind-tables)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50341: [libcxx] Mark aligned allocation tests as XFAIL on old OSX versions

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

Rewrite all XFAILs in light of issues brought up by Marshall.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50341

Files:
  libcxx/test/libcxx/memory/aligned_allocation_macro.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/delete_align_val_t_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_nothrow.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_align_val_t_nothrow_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align_nothrow.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_align_nothrow.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_nothrow.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/new_size_nothrow.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/delete_align_val_t_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_align_val_t_nothrow_replace.pass.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.sh.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.fail.cpp
  
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.sh.cpp

Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.sh.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.sh.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align_nothrow.sh.cpp
@@ -15,11 +15,12 @@
 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
 
-#include 
+// REQUIRES: -faligned-allocation
+// RUN: %compile %verify -faligned-allocation
 
-#include "test_macros.h"
+#include 
 
 int main ()
 {
-::operator new(4, std::align_val_t{4}, std::nothrow);  // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
+::operator new(4, std::align_val_t{4}, std::nothrow);  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 }
Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.sh.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.sh.cpp
+++ libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.sh.cpp
@@ -10,16 +10,17 @@
 
 // 
 
-// void* operator new[](std::size_t, std::align_val_t);
+// void* operator new(std::size_t, std::align_val_t);
 
 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
 
-#include 
+// REQUIRES: -faligned-allocation
+// RUN: %compile %verify -faligned-allocation
 
-#include "test_macros.h"
+#include 
 
 int main ()
 {
-::operator new[](4, std::align_val_t{4});  // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
+::operator new(4, std::align_val_t{4});  // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
 }
Index: libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.fail.cpp
===
--- libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/new_size_align.fail.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-// -*- C++ -*-
-//===--===//
-//
-// 

[PATCH] D50594: [analyzer] [NFC] Introduce separate targets for testing the analyzer: check-clang-analyzer and check-clang-analyzer-z3

2018-08-13 Thread Justin Bogner via Phabricator via cfe-commits
bogner added a comment.

The cmake and lit bits all look correct


https://reviews.llvm.org/D50594



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


[PATCH] D41217: [Concepts] Concept Specialization Expressions

2018-08-13 Thread Saar Raz via Phabricator via cfe-commits
saar.raz updated this revision to Diff 160437.
saar.raz added a comment.

Address Arthur's comments, add missing CorrectDelayedTyposInExpr


Repository:
  rC Clang

https://reviews.llvm.org/D41217

Files:
  include/clang/AST/DeclTemplate.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/StmtNodes.td
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/Expr.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseTemplate.cpp
  lib/Sema/CMakeLists.txt
  lib/Sema/SemaConcept.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp
  test/Parser/cxx-concept-declaration.cpp
  tools/libclang/CXCursor.cpp

Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -231,6 +231,7 @@
   case Stmt::TypeTraitExprClass:
   case Stmt::CoroutineBodyStmtClass:
   case Stmt::CoawaitExprClass:
+  case Stmt::ConceptSpecializationExprClass:
   case Stmt::DependentCoawaitExprClass:
   case Stmt::CoreturnStmtClass:
   case Stmt::CoyieldExprClass:
Index: test/Parser/cxx-concept-declaration.cpp
===
--- test/Parser/cxx-concept-declaration.cpp
+++ test/Parser/cxx-concept-declaration.cpp
@@ -9,8 +9,6 @@
 
 template concept D1 = true; // expected-error {{expected template parameter}}
 
-template concept C2 = 0.f; // expected-error {{constraint expression must be 'bool'}}
-
 struct S1 {
   template concept C1 = true; // expected-error {{concept declarations may only appear in global or namespace scope}}
 };
@@ -29,3 +27,31 @@
 
 // TODO: Add test to prevent explicit specialization, partial specialization
 // and explicit instantiation of concepts.
+
+template concept C7 = 2; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}}
+template concept C8 = 2 && x; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}}
+template concept C9 = x || 2 || x; // expected-error {{atomic constraint must be of type 'bool' (found 'int')}}
+template concept C10 = 8ull && x || x; // expected-error {{atomic constraint must be of type 'bool' (found 'unsigned long long')}}
+template concept C11 = sizeof(T); // expected-error {{atomic constraint must be of type 'bool' (found 'unsigned long')}}
+template concept C12 = T{};
+static_assert(!C12);
+template concept C13 = (bool&&)true;
+static_assert(C13);
+template concept C14 = (const bool&)true;
+static_assert(C14);
+template concept C15 = (const bool)true;
+static_assert(C15);
+
+template
+struct integral_constant { static constexpr T value = v; };
+
+template  concept C16 = integral_constant::value && true;
+static_assert(C16);
+static_assert(!C16);
+template  concept C17 = integral_constant::value;
+static_assert(C17);
+static_assert(!C17);
+
+template  concept C18 = integral_constant::value;
+// expected-error@-1{{use of undeclared identifier 'wor'; did you mean 'word'?}}
+// expected-note@-2{{'word' declared here}}
\ No newline at end of file
Index: test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp
===
--- test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp
+++ test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp
@@ -1,5 +1,146 @@
 // RUN:  %clang_cc1 -std=c++2a -fconcepts-ts -verify %s
-// expected-no-diagnostics
 
-template concept C = true;
-static_assert(C);
+template concept C1 = true;
+static_assert(C1);
+
+template concept C2 = sizeof(T) == 4;
+static_assert(C2);
+static_assert(!C2);
+static_assert(C2);
+static_assert(!C2);
+
+template concept C3 = sizeof(*T{}) == 4;
+static_assert(C3);
+static_assert(!C3);
+
+struct A {
+  static constexpr int add(int a, int b) {
+return a + b;
+  }
+};
+struct B {
+  static int add(int a, int b) {
+return a + b;
+  }
+};
+template
+concept C4 = U::add(1, 2) == 3; // expected-error {{substitution into constraint expression resulted in a non-constant expression}}
+static_assert(C4);
+static_assert(!C4); // expected-note {{while checking the satisfaction of concept 'C4' requested here}}
+
+template
+constexpr bool is_same_v = false;
+
+template
+constexpr bool is_same_v = true;
+
+template
+concept Same = is_same_v;
+
+static_assert(Same);
+static_assert(Same);
+static_assert(!Same);
+static_assert(!Same);
+static_assert(Same);
+
+static_assert(Same)>);
+static_assert(Same)>);
+static_assert(Same)>);

[PATCH] D50630: [AST] Update/correct the static_asserts for the bit-fields in Type

2018-08-13 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

Also I don't understand to comment about the bit-fields of FunctionType fitting 
in the padding of Type:

If we have something like

  struct Base {
void *p1;
void *p2;
unsigned x;
  };
  
  struct Der : Base {
unsigned x;
  };

Then on my machine (64 bit linux) I get that

  sizeof(Base) == 24
  sizeof(Der) == 32

and not `sizeof(Der) == sizeof(Base)` like if the unsigned of `Der` was fitting 
into the padding of `Base`.


Repository:
  rC Clang

https://reviews.llvm.org/D50630



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


[PATCH] D50662: Add dump() method for SourceRange

2018-08-13 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D50662

Files:
  include/clang/Basic/SourceLocation.h
  lib/Basic/SourceLocation.cpp


Index: lib/Basic/SourceLocation.cpp
===
--- lib/Basic/SourceLocation.cpp
+++ lib/Basic/SourceLocation.cpp
@@ -80,6 +80,14 @@
   llvm::errs() << '\n';
 }
 
+LLVM_DUMP_METHOD void SourceRange::dump(const SourceManager ) const {
+  llvm::errs() << '[';
+  B.print(llvm::errs(), SM);
+  llvm::errs() << ",\n ";
+  E.print(llvm::errs(), SM);
+  llvm::errs() << "]\n";
+}
+
 
//===--===//
 // FullSourceLoc
 
//===--===//
Index: include/clang/Basic/SourceLocation.h
===
--- include/clang/Basic/SourceLocation.h
+++ include/clang/Basic/SourceLocation.h
@@ -220,6 +220,8 @@
   bool operator!=(const SourceRange ) const {
 return B != X.B || E != X.E;
   }
+
+  void dump(const SourceManager ) const;
 };
 
 /// Represents a character-granular source range.


Index: lib/Basic/SourceLocation.cpp
===
--- lib/Basic/SourceLocation.cpp
+++ lib/Basic/SourceLocation.cpp
@@ -80,6 +80,14 @@
   llvm::errs() << '\n';
 }
 
+LLVM_DUMP_METHOD void SourceRange::dump(const SourceManager ) const {
+  llvm::errs() << '[';
+  B.print(llvm::errs(), SM);
+  llvm::errs() << ",\n ";
+  E.print(llvm::errs(), SM);
+  llvm::errs() << "]\n";
+}
+
 //===--===//
 // FullSourceLoc
 //===--===//
Index: include/clang/Basic/SourceLocation.h
===
--- include/clang/Basic/SourceLocation.h
+++ include/clang/Basic/SourceLocation.h
@@ -220,6 +220,8 @@
   bool operator!=(const SourceRange ) const {
 return B != X.B || E != X.E;
   }
+
+  void dump(const SourceManager ) const;
 };
 
 /// Represents a character-granular source range.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50661: Add a newline to SourceLocation dump output

2018-08-13 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
Herald added a subscriber: cfe-commits.

Migrate callers to print().

dump() should be useful to downstreams and third parties as a debugging
aid.  Everyone trips up on this and creates confusing output.


Repository:
  rC Clang

https://reviews.llvm.org/D50661

Files:
  lib/ARCMigrate/TransGCAttrs.cpp
  lib/AST/CommentLexer.cpp
  lib/Analysis/LiveVariables.cpp
  lib/Basic/Diagnostic.cpp
  lib/Basic/SourceLocation.cpp
  lib/Lex/Preprocessor.cpp


Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -250,7 +250,7 @@
 }
 
 void Preprocessor::DumpLocation(SourceLocation Loc) const {
-  Loc.dump(SourceMgr);
+  Loc.print(llvm::errs(), SourceMgr);
 }
 
 void Preprocessor::DumpMacro(const MacroInfo ) const {
Index: lib/Basic/SourceLocation.cpp
===
--- lib/Basic/SourceLocation.cpp
+++ lib/Basic/SourceLocation.cpp
@@ -77,6 +77,7 @@
 
 LLVM_DUMP_METHOD void SourceLocation::dump(const SourceManager ) const {
   print(llvm::errs(), SM);
+  llvm::errs() << '\n';
 }
 
 
//===--===//
Index: lib/Basic/Diagnostic.cpp
===
--- lib/Basic/Diagnostic.cpp
+++ lib/Basic/Diagnostic.cpp
@@ -239,7 +239,7 @@
 void DiagnosticsEngine::DiagStateMap::dump(SourceManager ,
StringRef DiagName) const {
   llvm::errs() << "diagnostic state at ";
-  CurDiagStateLoc.dump(SrcMgr);
+  CurDiagStateLoc.print(llvm::errs(), SrcMgr);
   llvm::errs() << ": " << CurDiagState << "\n";
 
   for (auto  : Files) {
@@ -261,7 +261,7 @@
  << Decomp.first.getHashValue() << "> ";
 SrcMgr.getLocForStartOfFile(Decomp.first)
   .getLocWithOffset(Decomp.second)
-  .dump(SrcMgr);
+  .print(llvm::errs(), SrcMgr);
   }
   if (File.HasLocalTransitions)
 llvm::errs() << " has_local_transitions";
@@ -281,7 +281,7 @@
 llvm::errs() << "  ";
 SrcMgr.getLocForStartOfFile(ID)
   .getLocWithOffset(Transition.Offset)
-  .dump(SrcMgr);
+  .print(llvm::errs(), SrcMgr);
 llvm::errs() << ": state " << Transition.State << ":\n";
   };
 
Index: lib/Analysis/LiveVariables.cpp
===
--- lib/Analysis/LiveVariables.cpp
+++ lib/Analysis/LiveVariables.cpp
@@ -626,7 +626,7 @@
  de = declVec.end(); di != de; ++di) {
   llvm::errs() << " " << (*di)->getDeclName().getAsString()
<< " <";
-  (*di)->getLocation().dump(M);
+  (*di)->getLocation().print(llvm::errs(), M);
   llvm::errs() << ">\n";
 }
   }
Index: lib/AST/CommentLexer.cpp
===
--- lib/AST/CommentLexer.cpp
+++ lib/AST/CommentLexer.cpp
@@ -21,7 +21,7 @@
 
 void Token::dump(const Lexer , const SourceManager ) const {
   llvm::errs() << "comments::Token Kind=" << Kind << " ";
-  Loc.dump(SM);
+  Loc.print(llvm::errs(), SM);
   llvm::errs() << " " << Length << " \"" << L.getSpelling(*this, SM) << "\"\n";
 }
 
Index: lib/ARCMigrate/TransGCAttrs.cpp
===
--- lib/ARCMigrate/TransGCAttrs.cpp
+++ lib/ARCMigrate/TransGCAttrs.cpp
@@ -340,7 +340,7 @@
 llvm::errs() << "KIND: "
 << (Attr.Kind == GCAttrOccurrence::Strong ? "strong" : "weak");
 llvm::errs() << "\nLOC: ";
-Attr.Loc.dump(Pass.Ctx.getSourceManager());
+Attr.Loc.print(llvm::errs(), Pass.Ctx.getSourceManager());
 llvm::errs() << "\nTYPE: ";
 Attr.ModifiedType.dump();
 if (Attr.Dcl) {


Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -250,7 +250,7 @@
 }
 
 void Preprocessor::DumpLocation(SourceLocation Loc) const {
-  Loc.dump(SourceMgr);
+  Loc.print(llvm::errs(), SourceMgr);
 }
 
 void Preprocessor::DumpMacro(const MacroInfo ) const {
Index: lib/Basic/SourceLocation.cpp
===
--- lib/Basic/SourceLocation.cpp
+++ lib/Basic/SourceLocation.cpp
@@ -77,6 +77,7 @@
 
 LLVM_DUMP_METHOD void SourceLocation::dump(const SourceManager ) const {
   print(llvm::errs(), SM);
+  llvm::errs() << '\n';
 }
 
 //===--===//
Index: lib/Basic/Diagnostic.cpp
===
--- lib/Basic/Diagnostic.cpp
+++ lib/Basic/Diagnostic.cpp
@@ -239,7 +239,7 @@
 void DiagnosticsEngine::DiagStateMap::dump(SourceManager ,
StringRef DiagName) const {
   llvm::errs() << "diagnostic state at ";
-  

[PATCH] D50542: [clang-tidy] Add abseil-no-internal-deps check

2018-08-13 Thread Hugo Gonzalez via Phabricator via cfe-commits
hugoeg updated this revision to Diff 160432.
hugoeg marked an inline comment as done.
hugoeg added a comment.

applied corrections from comments


https://reviews.llvm.org/D50542

Files:
  clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tidy/abseil/CMakeLists.txt
  clang-tidy/abseil/NoInternalDepsCheck.cpp
  clang-tidy/abseil/NoInternalDepsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/abseil-no-internal-deps.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/abseil-fake-declarations.h
  test/clang-tidy/abseil-no-internal-deps.cpp

Index: test/clang-tidy/abseil-no-internal-deps.cpp
===
--- test/clang-tidy/abseil-no-internal-deps.cpp
+++ test/clang-tidy/abseil-no-internal-deps.cpp
@@ -0,0 +1,34 @@
+// RUN: %check_clang_tidy %s abseil-no-internal-deps %t
+
+#include "abseil-fake-declarations.h"
+
+void DirectAcess(){
+  absl::strings_internal::InternalFunction();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
+
+  absl::strings_internal::InternalTemplateFunction ("a");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
+}
+
+class FriendUsage{
+  friend struct absl::container_internal::InternalStruct;
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
+};
+
+namespace absl{
+  void OpeningNamespace(){
+strings_internal::InternalFunction();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not reference any 'internal' namespaces; those implementation details are reserved to Abseil
+  }
+} // namespace absl
+
+// should not trigger warnings
+void CorrectUsage(){
+  std::string Str = absl::StringsFunction("a");
+  absl::SomeContainer b;
+}
+
+namespace absl {
+  SomeContainer b;
+  std::string Str = absl::StringsFunction("a");
+} // namespace absl
Index: test/clang-tidy/abseil-fake-declarations.h
===
--- test/clang-tidy/abseil-fake-declarations.h
+++ test/clang-tidy/abseil-fake-declarations.h
@@ -0,0 +1,24 @@
+namespace std {
+struct string {
+  string(const char *);
+  ~string();
+};
+} // namepsace std
+
+namespace absl {
+std::string StringsFunction (std::string s1){
+  return s1;
+}
+class SomeContainer{
+
+};
+namespace strings_internal{
+  void InternalFunction(){}
+  template 
+  P InternalTemplateFunction (P a) {}
+} // namespace strings_internal
+
+namespace container_internal{
+  struct InternalStruct{};
+} // namespace container_internal
+} // namespace absl
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -5,6 +5,7 @@
 
 .. toctree::
abseil-string-find-startswith
+   abseil-no-internal-deps
android-cloexec-accept
android-cloexec-accept4
android-cloexec-creat
Index: docs/clang-tidy/checks/abseil-no-internal-deps.rst
===
--- docs/clang-tidy/checks/abseil-no-internal-deps.rst
+++ docs/clang-tidy/checks/abseil-no-internal-deps.rst
@@ -0,0 +1,21 @@
+subl.. title:: clang-tidy - abseil-no-internal-deps
+
+abseil-no-internal-deps
+===
+
+Gives a warning if code using Abseil depends on internal details. If something
+is in a namespace that includes the word “internal”, code is not allowed to 
+depend upon it beaucse it’s an implementation detail. They cannot friend it, 
+include it, you mention it or refer to it in any way. Doing so violates 
+Abseil's compatibility guidelines and may result in breakage. See 
+https://abseil.io/about/compatibility for more information.
+
+The following cases will result in warnings:
+
+.. code-block:: c++
+
+  absl::strings_internal::foo();
+  class foo{
+friend struct absl::container_internal::faa;
+  };
+  absl::memory_internal::MakeUniqueResult();
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -52,7 +52,10 @@
 Improvements to clang-rename
 
 
-The improvements are...
+- New :doc:`abseil-no-internal-deps
+  ` check.
+  
+  Gives a warning if code using Abseil depends on internal details.
 
 Improvements to clang-tidy
 --
Index: clang-tidy/abseil/NoInternalDepsCheck.h
===
--- clang-tidy/abseil/NoInternalDepsCheck.h
+++ clang-tidy/abseil/NoInternalDepsCheck.h
@@ -0,0 +1,37 @@
+//===--- NoInternalDepsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// 

[PATCH] D50652: [libcxx] By default, do not use internal_linkage to hide symbols from the ABI

2018-08-13 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In https://reviews.llvm.org/D50652#1197780, @ldionne wrote:

> One thing to keep in mind is that we do not have a solution that allows 
> removing both `internal_linkage` and `always_inline`. It's either 
> `internal_linkage` or `always_inline`, but you can't get rid of both until we 
> fix some problems with extern template declarations and visibility 
> attributes. What I can do, however, is reverse the default to use 
> `internal_linkage`, and then have a temporary hook that allows Chromium to 
> stay on `always_inline`. In the future, we'd remove that hook and the choice 
> would be between `internal_linkage` and nothing at all.


It's probably worth it to me to debug and understand that problem. Is there a 
good explanation of it?

Also, if a user could define _LIBCPP_ABI_UNSTABLE, does this problem still 
apply? Could we remove the problematic visibility attributes if the ABI is 
unstable?


Repository:
  rCXX libc++

https://reviews.llvm.org/D50652



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


[PATCH] D50594: [analyzer] [NFC] Introduce separate targets for testing the analyzer: check-clang-analyzer and check-clang-analyzer-z3

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

Yup, i hope it'll be comfy now.


https://reviews.llvm.org/D50594



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


[PATCH] D50594: [analyzer] [NFC] Introduce separate targets for testing the analyzer: check-clang-analyzer and check-clang-analyzer-z3

2018-08-13 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho added a comment.

I can't comment on the code but it works correctly for me.

I wish I had it a couple of months ago :)


https://reviews.llvm.org/D50594



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


[PATCH] D49511: [Sema/Attribute] Check for noderef attribute

2018-08-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:14249
+
+if (Sema::TypeHasNoDeref(Inner))
+  DeclRef = E;

leonardchan wrote:
> aaron.ballman wrote:
> > The sugar was stripped off at the pointer level, but not at the pointee 
> > level. e.g.,
> > ```
> > typedef int (bobble);
> > typedef bobble * (frobble);
> > typedef frobble * yobble;
> > 
> > yobble gobble;
> > ```
> > I think you can handle this within `TypeHasNoDeref()` and that should fix 
> > up all the callers.
> So `TypeHasNoDeref()` checks for the attribute on the base type already and 
> is called after the pointer is stripped off. Attempting to desugar via 
> `getDesugaredType()` here also removes the `address_space` attribute from the 
> type I'm checking.
> 
> Do you know another method that essentially "expands" the typedefs without 
> stripping the qualifiers? Otherwise I think I do need do the desugaring at 
> the pointer level. Alternatively I could also change this method such that it 
> accepts pointers instead of pointees since it appears I already call 
> `getDesugaredType()` for almost every pointer who's pointee I'm passing to 
> `TypeHasNoDeref()`.
> 
> Also I tested with your example and the warning still seems to be thrown 
> appropriately. 
I think you have to do the desugaring manually in a loop with 
`getSingleStepDesugaredType()` so that you don't strip off attributed type 
information along with the rest of the type sugar.

> Also I tested with your example and the warning still seems to be thrown 
> appropriately.

The example may depend on where you put the attribute (inside the parens vs 
outside the parens, for instance); it was an off-the-cuff example, so it may 
need some tweaking.


Repository:
  rC Clang

https://reviews.llvm.org/D49511



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


[PATCH] D50413: [libunwind][include] Add some missing definitions to .

2018-08-13 Thread Charles Davis via Phabricator via cfe-commits
cdavis5x added a comment.

Ping.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D50413



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


[PATCH] D50542: [clang-tidy] Add abseil-no-internal-deps check

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



Comment at: test/clang-tidy/abseil-no-internal-deps.cpp:2
+// RUN: %check_clang_tidy %s abseil-no-internal-deps %t
+
+

hugoeg wrote:
> JonasToth wrote:
> > hugoeg wrote:
> > > hokein wrote:
> > > > nit: please make sure the code follow LLVM code style, even for test 
> > > > code :)
> > > what is this in reference too?
> > > Will the test still work if I wrap the CHECK MESSAGE lines?
> > CHECK-MESSAGE can be on one line, even if its longer (that is common in the 
> > clang-tidy tests).
> > 
> > But dont use many empty lines and respect naming conventions and run 
> > clang-format over the code (except there is a valid reason that the 
> > formatting would infer with the tested logic).
> Do my function names have to be verbs, they're not doing anything.
> 
> I could rename InternalFunction to something like InternallyProcessString 
> annd StringFunction to process String
> Would this be preferred?
It helps if you somehow show the "topic of the function". But I wrote some 
tests, that did not strictly follow and they passed review too ;)

Foo is just too generic, sth like `DirectAccess`, `FriendUsage`, 
`OpeningNamespace` or so is already telling and I guess good enough :)


https://reviews.llvm.org/D50542



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


[PATCH] D50580: [clang-tidy] Abseil: no namespace check

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



Comment at: clang-tidy/abseil/NoNamespaceCheck.cpp:23
+
+  Finder->addMatcher(namespaceDecl(hasName("absl")).bind("absl_namespace"),
+ this);

hugoeg wrote:
> deannagarcia wrote:
> > aaron.ballman wrote:
> > > hokein wrote:
> > > > aaron.ballman wrote:
> > > > > I think this needs a `not(isExpansionInSystemHeader())` in there, as 
> > > > > this is going to trigger on code that includes a header file using an 
> > > > > `absl` namespace. If I'm incorrect and users typically include abseil 
> > > > > as something other than system includes, you'll have to find a 
> > > > > different way to solve this.
> > > > Yeah, we have discussed this issue internally.  abseil-user code 
> > > > usually includes abseil header like `#include 
> > > > "whatever/abseil/base/optimization.h"`, so `IsExpansionInSystemHeader` 
> > > > doesn't work for most cases. 
> > > > 
> > > > We need a way to filter out all headers being a part of abseil library. 
> > > > I think we can create a matcher `InExpansionInAbseilHeader` -- 
> > > > basically using `IsExpansionInFileMatching` with a regex expression 
> > > > that matches typical abseil include path. What do you think?
> > > > 
> > > > And we'll have more abseil checks (e.g.  `abseil-no-internal-deps`) 
> > > > that use `InExpansionInAbseilHeader`, we should put it to a common 
> > > > header.
> > > I think that is a sensible approach.
> > We will begin working on this, I think it will first be implemented in 
> > abseil-no-internal-deps but once it looks good I will add it to this patch.
> I'm going to go ahead a implement this in ASTMatchers.h and include it on the 
> patch for **abseil-no-internal-dep**s
In principle it is ok, but I don't think ASTMatchers.h is the correct place, 
because it is only of use to clang-tidy.

There is a `util` directory in clang-tidy for this kind of stuff. Defining you 
own matchers works the same as in ASTMatchers, you can grep through clang-tidy 
checks (e.g. `AST_MATCHER`) to have some examples of private matchers.


https://reviews.llvm.org/D50580



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


Re: r339581 - [SEMA] add more -Wfloat-conversion to compound assigment analysis

2018-08-13 Thread Nick Desaulniers via cfe-commits
https://reviews.llvm.org/D50647
On Mon, Aug 13, 2018 at 12:50 PM Vitaly Buka  wrote:
>
> Looks like this patch:
>
> http://lab.llvm.org:8011/builders/clang-ppc64le-linux-lnt/builds/13867/steps/ninja%20check%201/logs/stdio
>
>
> FAIL: Clang :: Sema/conversion.c (12530 of 44133)
>  TEST 'Clang :: Sema/conversion.c' FAILED 
> 
> Script:
> --
> : 'RUN: at line 1';   
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/bin/clang 
> -cc1 -internal-isystem 
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/lib/clang/8.0.0/include
>  -nostdsysteminc -fsyntax-only -verify -Wconversion-nostdsysteminc 
> -nobuiltininc -isystem 
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/tools/clang/test/Sema/Inputs
> -triple x86_64-apple-darwin 
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/tools/clang/test/Sema/conversion.c
>  -Wno-unreachable-code
> --
> Exit Code: 1
>
> Command Output (stderr):
> --
> error: 'warning' diagnostics seen but not expected:
>   File 
> /home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/tools/clang/test/Sema/conversion.c
>  Line 362: implicit conversion turns floating-point number into integer: 
> 'char' to 'float'
> 1 error generated.
>
> --
>
>
> On Mon, Aug 13, 2018 at 9:46 AM Nick Desaulniers via cfe-commits 
>  wrote:
>>
>> Author: nickdesaulniers
>> Date: Mon Aug 13 09:38:07 2018
>> New Revision: 339581
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=339581=rev
>> Log:
>> [SEMA] add more -Wfloat-conversion to compound assigment analysis
>>
>> Summary: Fixes Bug: https://bugs.llvm.org/show_bug.cgi?id=27061
>>
>> Reviewers: aaron.ballman, acoomans
>>
>> Reviewed By: aaron.ballman, acoomans
>>
>> Subscribers: acoomans, cfe-commits, srhines, pirama
>>
>> Differential Revision: https://reviews.llvm.org/D50467
>>
>> Modified:
>> cfe/trunk/lib/Sema/SemaChecking.cpp
>> cfe/trunk/test/SemaCXX/warn-float-conversion.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=339581=339580=339581=diff
>> ==
>> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Aug 13 09:38:07 2018
>> @@ -10282,33 +10282,6 @@ static void DiagnoseImpCast(Sema , Exp
>>DiagnoseImpCast(S, E, E->getType(), T, CContext, diag, pruneControlFlow);
>>  }
>>
>> -/// Analyze the given compound assignment for the possible losing of
>> -/// floating-point precision.
>> -static void AnalyzeCompoundAssignment(Sema , BinaryOperator *E) {
>> -  assert(isa(E) &&
>> - "Must be compound assignment operation");
>> -  // Recurse on the LHS and RHS in here
>> -  AnalyzeImplicitConversions(S, E->getLHS(), E->getOperatorLoc());
>> -  AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
>> -
>> -  // Now check the outermost expression
>> -  const auto *ResultBT = E->getLHS()->getType()->getAs();
>> -  const auto *RBT = cast(E)
>> -->getComputationResultType()
>> -->getAs();
>> -
>> -  // If both source and target are floating points.
>> -  if (ResultBT && ResultBT->isFloatingPoint() && RBT && 
>> RBT->isFloatingPoint())
>> -// Builtin FP kinds are ordered by increasing FP rank.
>> -if (ResultBT->getKind() < RBT->getKind())
>> -  // We don't want to warn for system macro.
>> -  if (!S.SourceMgr.isInSystemMacro(E->getOperatorLoc()))
>> -// warn about dropping FP rank.
>> -DiagnoseImpCast(S, E->getRHS(), E->getLHS()->getType(),
>> -E->getOperatorLoc(),
>> -diag::warn_impcast_float_result_precision);
>> -}
>> -
>>  /// Diagnose an implicit cast from a floating point value to an integer 
>> value.
>>  static void DiagnoseFloatingImpCast(Sema , Expr *E, QualType T,
>>  SourceLocation CContext) {
>> @@ -10411,6 +10384,39 @@ static void DiagnoseFloatingImpCast(Sema
>>}
>>  }
>>
>> +/// Analyze the given compound assignment for the possible losing of
>> +/// floating-point precision.
>> +static void AnalyzeCompoundAssignment(Sema , BinaryOperator *E) {
>> +  assert(isa(E) &&
>> + "Must be compound assignment operation");
>> +  // Recurse on the LHS and RHS in here
>> +  AnalyzeImplicitConversions(S, E->getLHS(), E->getOperatorLoc());
>> +  AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
>> +
>> +  // Now check the outermost expression
>> +  const auto *ResultBT = E->getLHS()->getType()->getAs();
>> +  const auto *RBT = cast(E)
>> +->getComputationResultType()
>> +->getAs();
>> +
>> +  // The below checks assume source is floating point.
>> +  if (!ResultBT || !RBT || !RBT->isFloatingPoint()) return;
>> +
>> +  // If source is floating point but target is not.
>> 

[PATCH] D50630: [AST] Update/correct the static_asserts for the bit-fields in Type

2018-08-13 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

@rjmccall

I would argue that we should make these bit-fields take 8 bytes for the 
following reasons:

1. On 64 bits archs, this is free since we have already 8 bytes of padding here.
2. On 32 bits archs, this a priori increase the size of each Type by 4 bytes. 
However, types are aligned to 16 bytes because of the fast CVR qualifiers. 
Doing an fsyntax-only on all of Boost with -print-stats I get that by far the 
most commonly used Types have size 40 or 48 (on a 64 bits arch). That is 5 or 6 
pointers. This would be 20 or 24 bytes on 32 bits archs if we assume that every 
member of the most commonly used types are pointers and that we shrink the 
bitfields to 32 bits. But since Types are aligned to 16 bytes we do not gain 
anything.


Repository:
  rC Clang

https://reviews.llvm.org/D50630



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


Re: r339581 - [SEMA] add more -Wfloat-conversion to compound assigment analysis

2018-08-13 Thread Vitaly Buka via cfe-commits
Looks like this patch:

http://lab.llvm.org:8011/builders/clang-ppc64le-linux-lnt/builds/13867/steps/ninja%20check%201/logs/stdio


FAIL: Clang :: Sema/conversion.c (12530 of 44133)
 TEST 'Clang :: Sema/conversion.c' FAILED

Script:
--
: 'RUN: at line 1';
/home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/bin/clang
-cc1 -internal-isystem
/home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/stage1/lib/clang/8.0.0/include
-nostdsysteminc -fsyntax-only -verify -Wconversion-nostdsysteminc
-nobuiltininc -isystem
/home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/tools/clang/test/Sema/Inputs
   -triple x86_64-apple-darwin
/home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/tools/clang/test/Sema/conversion.c
-Wno-unreachable-code
--
Exit Code: 1

Command Output (stderr):
--
error: 'warning' diagnostics seen but not expected:
  File 
/home/buildbots/ppc64le-clang-lnt-test/clang-ppc64le-lnt/llvm/tools/clang/test/Sema/conversion.c
Line 362: implicit conversion turns floating-point number into
integer: 'char' to 'float'
1 error generated.

--


On Mon, Aug 13, 2018 at 9:46 AM Nick Desaulniers via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: nickdesaulniers
> Date: Mon Aug 13 09:38:07 2018
> New Revision: 339581
>
> URL: http://llvm.org/viewvc/llvm-project?rev=339581=rev
> Log:
> [SEMA] add more -Wfloat-conversion to compound assigment analysis
>
> Summary: Fixes Bug: https://bugs.llvm.org/show_bug.cgi?id=27061
>
> Reviewers: aaron.ballman, acoomans
>
> Reviewed By: aaron.ballman, acoomans
>
> Subscribers: acoomans, cfe-commits, srhines, pirama
>
> Differential Revision: https://reviews.llvm.org/D50467
>
> Modified:
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/test/SemaCXX/warn-float-conversion.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=339581=339580=339581=diff
>
> ==
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Aug 13 09:38:07 2018
> @@ -10282,33 +10282,6 @@ static void DiagnoseImpCast(Sema , Exp
>DiagnoseImpCast(S, E, E->getType(), T, CContext, diag,
> pruneControlFlow);
>  }
>
> -/// Analyze the given compound assignment for the possible losing of
> -/// floating-point precision.
> -static void AnalyzeCompoundAssignment(Sema , BinaryOperator *E) {
> -  assert(isa(E) &&
> - "Must be compound assignment operation");
> -  // Recurse on the LHS and RHS in here
> -  AnalyzeImplicitConversions(S, E->getLHS(), E->getOperatorLoc());
> -  AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
> -
> -  // Now check the outermost expression
> -  const auto *ResultBT = E->getLHS()->getType()->getAs();
> -  const auto *RBT = cast(E)
> -->getComputationResultType()
> -->getAs();
> -
> -  // If both source and target are floating points.
> -  if (ResultBT && ResultBT->isFloatingPoint() && RBT &&
> RBT->isFloatingPoint())
> -// Builtin FP kinds are ordered by increasing FP rank.
> -if (ResultBT->getKind() < RBT->getKind())
> -  // We don't want to warn for system macro.
> -  if (!S.SourceMgr.isInSystemMacro(E->getOperatorLoc()))
> -// warn about dropping FP rank.
> -DiagnoseImpCast(S, E->getRHS(), E->getLHS()->getType(),
> -E->getOperatorLoc(),
> -diag::warn_impcast_float_result_precision);
> -}
> -
>  /// Diagnose an implicit cast from a floating point value to an integer
> value.
>  static void DiagnoseFloatingImpCast(Sema , Expr *E, QualType T,
>  SourceLocation CContext) {
> @@ -10411,6 +10384,39 @@ static void DiagnoseFloatingImpCast(Sema
>}
>  }
>
> +/// Analyze the given compound assignment for the possible losing of
> +/// floating-point precision.
> +static void AnalyzeCompoundAssignment(Sema , BinaryOperator *E) {
> +  assert(isa(E) &&
> + "Must be compound assignment operation");
> +  // Recurse on the LHS and RHS in here
> +  AnalyzeImplicitConversions(S, E->getLHS(), E->getOperatorLoc());
> +  AnalyzeImplicitConversions(S, E->getRHS(), E->getOperatorLoc());
> +
> +  // Now check the outermost expression
> +  const auto *ResultBT = E->getLHS()->getType()->getAs();
> +  const auto *RBT = cast(E)
> +->getComputationResultType()
> +->getAs();
> +
> +  // The below checks assume source is floating point.
> +  if (!ResultBT || !RBT || !RBT->isFloatingPoint()) return;
> +
> +  // If source is floating point but target is not.
> +  if (!ResultBT->isFloatingPoint())
> +return DiagnoseFloatingImpCast(S, E, E->getRHS()->getType(),
> +   E->getExprLoc());
> +
> +  // If both source and target are floating points.
> +  // 

[PATCH] D38320: [clang] Fix serializers for `TypeTemplateParmDecl` + related types

2018-08-13 Thread Steve O'Brien via Phabricator via cfe-commits
elsteveogrande abandoned this revision.
elsteveogrande added a comment.

Dropped in favor of other fix as mentioned above


Repository:
  rC Clang

https://reviews.llvm.org/D38320



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


[PATCH] D21767: Fix instantiation of friend function templates

2018-08-13 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Shouldn't there just be a link in the AST from the instantiated 
`FunctionTemplateDecl ` back to the original pattern?  Maybe a generalization 
of `InstantiatedFromMember` in `RedeclarablableTemplateDecl`?


Repository:
  rC Clang

https://reviews.llvm.org/D21767



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


[PATCH] D50652: [libcxx] By default, do not use internal_linkage to hide symbols from the ABI

2018-08-13 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

In https://reviews.llvm.org/D50652#1197775, @rnk wrote:

> I'd prefer not to do this, since internal_linkage generates smaller, more 
> debuggable code by default. I think the symbol table size increase may be 
> specific to MachO, and it may be possible to work around this by changing 
> ld64 to pool strings for symbols by default. I don't know enough about MachO 
> to say if this is possible.
>
> I also think the symbol table size problem may be limited to "large" users of 
> C++: people with 500+ object files using libc++ in a DSO. I'm more 
> comfortable imposing a cost on these users to ask them to opt in to some 
> setting that disables internal_linkage and always_inline than I am leaving 
> always_inline on by default, which adversely affects all users.


One thing to keep in mind is that we do not have a solution that allows 
removing both `internal_linkage` and `always_inline`. It's either 
`internal_linkage` or `always_inline`, but you can't get rid of both until we 
fix some problems with extern template declarations and visibility attributes. 
What I can do, however, is reverse the default to use `internal_linkage`, and 
then have a temporary hook that allows Chromium to stay on `always_inline`. In 
the future, we'd remove that hook and the choice would be between 
`internal_linkage` and nothing at all.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50652



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


[PATCH] D50630: [AST] Update/correct the static_asserts for the bit-fields in Type

2018-08-13 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Oh, I missed that there was a separate review for this.  A lot of the important 
subclasses that need extra storage have been designed with the expectation that 
these bit-fields fit within 32 bits.  For example, `FunctionType` starts with a 
bunch of bit-fields because the expectation is that they'll fit into the 
tail-padding of `Type`.  So this assertion should really be testing <= 4, and 
if we need to land a few patches first to make that true, we should do so.


Repository:
  rC Clang

https://reviews.llvm.org/D50630



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


[PATCH] D50652: [libcxx] By default, do not use internal_linkage to hide symbols from the ABI

2018-08-13 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I'd prefer not to do this, since internal_linkage generates smaller, more 
debuggable code by default. I think the symbol table size increase may be 
specific to MachO, and it may be possible to work around this by changing ld64 
to pool strings for symbols by default. I don't know enough about MachO to say 
if this is possible.

I also think the symbol table size problem may be limited to "large" users of 
C++: people with 500+ object files using libc++ in a DSO. I'm more comfortable 
imposing a cost on these users to ask them to opt in to some setting that 
disables internal_linkage and always_inline than I am leaving always_inline on 
by default, which adversely affects all users.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50652



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


[PATCH] D50631: [AST] Stuff more data into FunctionTypeBitfields

2018-08-13 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

We should absolutely have static assertions to check that these bit-field types 
don't get larger than 32 bits.  A lot of the subclass layouts have been tweaked 
to fit that (packing into the tail padding of `Type` on 64-bit targets), so 
accidentally overflowing to use more bits in the base is going to lead to a lot 
of bloat.


Repository:
  rC Clang

https://reviews.llvm.org/D50631



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


[PATCH] D49511: [Sema/Attribute] Check for noderef attribute

2018-08-13 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

@rsmith




Comment at: lib/Sema/SemaExpr.cpp:14249
+
+if (Sema::TypeHasNoDeref(Inner))
+  DeclRef = E;

aaron.ballman wrote:
> The sugar was stripped off at the pointer level, but not at the pointee 
> level. e.g.,
> ```
> typedef int (bobble);
> typedef bobble * (frobble);
> typedef frobble * yobble;
> 
> yobble gobble;
> ```
> I think you can handle this within `TypeHasNoDeref()` and that should fix up 
> all the callers.
So `TypeHasNoDeref()` checks for the attribute on the base type already and is 
called after the pointer is stripped off. Attempting to desugar via 
`getDesugaredType()` here also removes the `address_space` attribute from the 
type I'm checking.

Do you know another method that essentially "expands" the typedefs without 
stripping the qualifiers? Otherwise I think I do need do the desugaring at the 
pointer level. Alternatively I could also change this method such that it 
accepts pointers instead of pointees since it appears I already call 
`getDesugaredType()` for almost every pointer who's pointee I'm passing to 
`TypeHasNoDeref()`.

Also I tested with your example and the warning still seems to be thrown 
appropriately. 


Repository:
  rC Clang

https://reviews.llvm.org/D49511



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


r339603 - [OPENMP] Fix emission of the loop doacross constructs.

2018-08-13 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Aug 13 12:04:24 2018
New Revision: 339603

URL: http://llvm.org/viewvc/llvm-project?rev=339603=rev
Log:
[OPENMP] Fix emission of the loop doacross constructs.

The number of loops associated with the OpenMP loop constructs should
not be considered as the number loops to collapse.

Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/lib/AST/OpenMPClause.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/OpenMP/ordered_doacross_codegen.c
cfe/trunk/test/OpenMP/ordered_doacross_codegen.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_ast_print.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=339603=339602=339603=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Mon Aug 13 12:04:24 2018
@@ -930,8 +930,11 @@ public:
 /// \endcode
 /// In this example directive '#pragma omp for' has 'ordered' clause with
 /// parameter 2.
-class OMPOrderedClause : public OMPClause {
+class OMPOrderedClause final
+: public OMPClause,
+  private llvm::TrailingObjects {
   friend class OMPClauseReader;
+  friend TrailingObjects;
 
   /// Location of '('.
   SourceLocation LParenLoc;
@@ -939,6 +942,26 @@ class OMPOrderedClause : public OMPClaus
   /// Number of for-loops.
   Stmt *NumForLoops = nullptr;
 
+  /// Real number of loops.
+  unsigned NumberOfLoops = 0;
+
+  /// Build 'ordered' clause.
+  ///
+  /// \param Num Expression, possibly associated with this clause.
+  /// \param NumLoops Number of loops, associated with this clause.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  OMPOrderedClause(Expr *Num, unsigned NumLoops, SourceLocation StartLoc,
+   SourceLocation LParenLoc, SourceLocation EndLoc)
+  : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
+NumForLoops(Num), NumberOfLoops(NumLoops) {}
+
+  /// Build an empty clause.
+  explicit OMPOrderedClause(unsigned NumLoops)
+  : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()),
+NumberOfLoops(NumLoops) {}
+
   /// Set the number of associated for-loops.
   void setNumForLoops(Expr *Num) { NumForLoops = Num; }
 
@@ -946,17 +969,17 @@ public:
   /// Build 'ordered' clause.
   ///
   /// \param Num Expression, possibly associated with this clause.
+  /// \param NumLoops Number of loops, associated with this clause.
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
-  OMPOrderedClause(Expr *Num, SourceLocation StartLoc,
-SourceLocation LParenLoc, SourceLocation EndLoc)
-  : OMPClause(OMPC_ordered, StartLoc, EndLoc), LParenLoc(LParenLoc),
-NumForLoops(Num) {}
+  static OMPOrderedClause *Create(const ASTContext , Expr *Num,
+  unsigned NumLoops, SourceLocation StartLoc,
+  SourceLocation LParenLoc,
+  SourceLocation EndLoc);
 
   /// Build an empty clause.
-  explicit OMPOrderedClause()
-  : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()) {}
+  static OMPOrderedClause* CreateEmpty(const ASTContext , unsigned NumLoops);
 
   /// Sets the location of '('.
   void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
@@ -967,6 +990,17 @@ public:
   /// Return the number of associated for-loops.
   Expr *getNumForLoops() const { return cast_or_null(NumForLoops); }
 
+  /// Set number of iterations for the specified loop.
+  void setLoopNumIterations(unsigned NumLoop, Expr *NumIterations);
+  /// Get number of iterations for all the loops.
+  ArrayRef getLoopNumIterations() const;
+
+  /// Set loop counter for the specified loop.
+  void setLoopCounter(unsigned NumLoop, Expr *Counter);
+  /// Get loops counter for the specified loop.
+  Expr *getLoopCunter(unsigned NumLoop);
+  const Expr *getLoopCunter(unsigned NumLoop) const;
+
   child_range children() { return child_range(,  + 1); 
}
 
   static bool classof(const OMPClause *T) {
@@ -3095,24 +3129,32 @@ class OMPDependClause final
   /// Colon location.
   SourceLocation ColonLoc;
 
+  /// Number of loops, associated with the depend clause.
+  unsigned NumLoops = 0;
+
   /// Build clause with number of variables \a N.
   ///
   /// \param StartLoc Starting location of the clause.
   /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
   /// \param N Number of 

[PATCH] D50559: [gnu-objc] Make selector order deterministic.

2018-08-13 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.

Thanks.  I appreciate the fact that you spelled it all out in the test, too.

LGTM.




Comment at: lib/CodeGen/CGObjCGNU.cpp:3547
+  allSelectors.push_back(entry.first);
+llvm::sort(allSelectors.begin(), allSelectors.end());
 

theraven wrote:
> bmwiedemann wrote:
> > compilation failed here:
> > ../tools/clang/lib/CodeGen/CGObjCGNU.cpp:2444:11: error: 'sort' is not a 
> > member of 'llvm'
> > 
> > it suggested std::sort
> I'm not sure `llvm::sort` was part of the 6.0 release, it was added in April 
> and so should be in 7.0.  I don't expect a patch against the 8 branch to 
> apply cleanly to 6...
`array_pod_sort` has been around forever if we need a variant of the patch for 
that branch.


Repository:
  rC Clang

https://reviews.llvm.org/D50559



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


[PATCH] D50616: [Fixed Point Arithmetic] FixedPointCast

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



Comment at: lib/CodeGen/CGExprScalar.cpp:1016
+  if (DstScale > SrcScale) {
+// Need to allocate space before shifting left
+ResultWidth = SrcWidth + DstScale - SrcScale;

In IR, this isn't really "allocating" space.



Comment at: lib/CodeGen/CGExprScalar.cpp:1034
+  if (DstFPSema.isSaturated() &&
+  (CGF.getContext().getCorrespondingSaturatedType(SrcTy) != DstTy)) {
+auto Mask = APInt::getBitsSetFrom(

Why is this condition based on the formal types exactly matching rather than 
something about the FP semantics being different?  Formal types can correspond 
to the same format, right?

We need to check for saturation if we're either (1) decreasing the magnitude of 
the highest usable bit or (2) going signed->unsigned, (2) we're going 
signed->unsigned, or (3) we're going unsigned->signed without increasing the 
number of integral bits.  And I'd expect the checks we have to do in each case 
to be different.



Comment at: lib/Sema/SemaExpr.cpp:5889
+case Type::STK_MemberPointer:
+  llvm_unreachable("Unimplemented conversion from FixedPoint to type");
+}

Is there something I'm missing that actually diagnoses the unimplemented cases 
here?  There's a lot of code that seems to assume that any two arithmetic types 
can be converted to each other, and we do prefer not to crash the compiler, 
especially on valid code.


Repository:
  rC Clang

https://reviews.llvm.org/D50616



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


[PATCH] D50652: [libcxx] By default, do not use internal_linkage to hide symbols from the ABI

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

I suspect this might deserve a wider discussion. At least cfe-dev, perhaps?


Repository:
  rCXX libc++

https://reviews.llvm.org/D50652



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


[PATCH] D50508: [analyzer][UninitializedObjectChecker] Refactoring p5.: Handle pedantic mode in the checker class only

2018-08-13 Thread Umann Kristóf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339601: [analyzer][UninitializedObjectChecker] Refactoring 
p5.: Handle pedantic mode in… (authored by Szelethus, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50508?vs=159901=160420#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50508

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp


Index: 
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
===
--- 
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -136,14 +136,20 @@
   if (!Object)
 return;
 
-  FindUninitializedFields F(Context.getState(), Object->getRegion(), 
IsPedantic,
+  FindUninitializedFields F(Context.getState(), Object->getRegion(),
 CheckPointeeInitialization);
 
   const UninitFieldMap  = F.getUninitFields();
 
   if (UninitFields.empty())
 return;
 
+  // In non-pedantic mode, if Object's region doesn't contain a single
+  // initialized field, we'll assume that Object was intentionally left
+  // uninitialized.
+  if (!IsPedantic && !F.isAnyFieldInitialized())
+return;
+
   // There are uninitialized fields in the record.
 
   ExplodedNode *Node = Context.generateNonFatalErrorNode(Context.getState());
@@ -192,18 +198,12 @@
 
//===--===//
 
 FindUninitializedFields::FindUninitializedFields(
-ProgramStateRef State, const TypedValueRegion *const R, bool IsPedantic,
+ProgramStateRef State, const TypedValueRegion *const R,
 bool CheckPointeeInitialization)
-: State(State), ObjectR(R), IsPedantic(IsPedantic),
-  CheckPointeeInitialization(CheckPointeeInitialization) {}
+: State(State), ObjectR(R),
+  CheckPointeeInitialization(CheckPointeeInitialization) {
 
-const UninitFieldMap ::getUninitFields() {
   isNonUnionUninit(ObjectR, FieldChainInfo(ChainFactory));
-
-  if (!IsPedantic && !IsAnyFieldInitialized)
-UninitFields.clear();
-
-  return UninitFields;
 }
 
 bool FindUninitializedFields::addFieldToUninits(FieldChainInfo Chain) {
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
@@ -111,9 +111,7 @@
   ProgramStateRef State;
   const TypedValueRegion *const ObjectR;
 
-  const bool IsPedantic;
   const bool CheckPointeeInitialization;
-
   bool IsAnyFieldInitialized = false;
 
   FieldChainInfo::FieldChain::Factory ChainFactory;
@@ -131,10 +129,17 @@
   UninitFieldMap UninitFields;
 
 public:
+  /// Constructs the FindUninitializedField object, searches for and stores
+  /// uninitialized fields in R.
   FindUninitializedFields(ProgramStateRef State,
-  const TypedValueRegion *const R, bool IsPedantic,
+  const TypedValueRegion *const R,
   bool CheckPointeeInitialization);
-  const UninitFieldMap ();
+
+  const UninitFieldMap () { return UninitFields; }
+
+  /// Returns whether the analyzed region contains at least one initialized
+  /// field.
+  bool isAnyFieldInitialized() { return IsAnyFieldInitialized; }
 
 private:
   // For the purposes of this checker, we'll regard the object under checking 
as


Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -136,14 +136,20 @@
   if (!Object)
 return;
 
-  FindUninitializedFields F(Context.getState(), Object->getRegion(), IsPedantic,
+  FindUninitializedFields F(Context.getState(), Object->getRegion(),
 CheckPointeeInitialization);
 
   const UninitFieldMap  = F.getUninitFields();
 
   if (UninitFields.empty())
 return;
 
+  // In non-pedantic mode, if Object's region doesn't contain a single
+  // initialized field, we'll assume that Object was intentionally left
+  // uninitialized.
+  if (!IsPedantic && !F.isAnyFieldInitialized())
+return;
+
   // There are uninitialized fields in the record.
 
   ExplodedNode *Node = Context.generateNonFatalErrorNode(Context.getState());
@@ -192,18 +198,12 @@
 //===--===//
 
 FindUninitializedFields::FindUninitializedFields(
-ProgramStateRef State, const TypedValueRegion *const R, bool IsPedantic,
+ 

r339601 - [analyzer][UninitializedObjectChecker] Refactoring p5.: Handle pedantic mode in the checker class only

2018-08-13 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Mon Aug 13 11:48:34 2018
New Revision: 339601

URL: http://llvm.org/viewvc/llvm-project?rev=339601=rev
Log:
[analyzer][UninitializedObjectChecker] Refactoring p5.: Handle pedantic mode in 
the checker class only

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

Modified:

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h?rev=339601=339600=339601=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h 
(original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h 
Mon Aug 13 11:48:34 2018
@@ -111,9 +111,7 @@ class FindUninitializedFields {
   ProgramStateRef State;
   const TypedValueRegion *const ObjectR;
 
-  const bool IsPedantic;
   const bool CheckPointeeInitialization;
-
   bool IsAnyFieldInitialized = false;
 
   FieldChainInfo::FieldChain::Factory ChainFactory;
@@ -131,10 +129,17 @@ class FindUninitializedFields {
   UninitFieldMap UninitFields;
 
 public:
+  /// Constructs the FindUninitializedField object, searches for and stores
+  /// uninitialized fields in R.
   FindUninitializedFields(ProgramStateRef State,
-  const TypedValueRegion *const R, bool IsPedantic,
+  const TypedValueRegion *const R,
   bool CheckPointeeInitialization);
-  const UninitFieldMap ();
+
+  const UninitFieldMap () { return UninitFields; }
+
+  /// Returns whether the analyzed region contains at least one initialized
+  /// field.
+  bool isAnyFieldInitialized() { return IsAnyFieldInitialized; }
 
 private:
   // For the purposes of this checker, we'll regard the object under checking 
as

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp?rev=339601=339600=339601=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 Mon Aug 13 11:48:34 2018
@@ -136,7 +136,7 @@ void UninitializedObjectChecker::checkEn
   if (!Object)
 return;
 
-  FindUninitializedFields F(Context.getState(), Object->getRegion(), 
IsPedantic,
+  FindUninitializedFields F(Context.getState(), Object->getRegion(),
 CheckPointeeInitialization);
 
   const UninitFieldMap  = F.getUninitFields();
@@ -144,6 +144,12 @@ void UninitializedObjectChecker::checkEn
   if (UninitFields.empty())
 return;
 
+  // In non-pedantic mode, if Object's region doesn't contain a single
+  // initialized field, we'll assume that Object was intentionally left
+  // uninitialized.
+  if (!IsPedantic && !F.isAnyFieldInitialized())
+return;
+
   // There are uninitialized fields in the record.
 
   ExplodedNode *Node = Context.generateNonFatalErrorNode(Context.getState());
@@ -192,18 +198,12 @@ void UninitializedObjectChecker::checkEn
 
//===--===//
 
 FindUninitializedFields::FindUninitializedFields(
-ProgramStateRef State, const TypedValueRegion *const R, bool IsPedantic,
+ProgramStateRef State, const TypedValueRegion *const R,
 bool CheckPointeeInitialization)
-: State(State), ObjectR(R), IsPedantic(IsPedantic),
-  CheckPointeeInitialization(CheckPointeeInitialization) {}
+: State(State), ObjectR(R),
+  CheckPointeeInitialization(CheckPointeeInitialization) {
 
-const UninitFieldMap ::getUninitFields() {
   isNonUnionUninit(ObjectR, FieldChainInfo(ChainFactory));
-
-  if (!IsPedantic && !IsAnyFieldInitialized)
-UninitFields.clear();
-
-  return UninitFields;
 }
 
 bool FindUninitializedFields::addFieldToUninits(FieldChainInfo Chain) {


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


r339599 - [analyzer][UninitializedObjectChecker] Refactoring p4.: Wrap FieldRegions and reduce weight on FieldChainInfo

2018-08-13 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Mon Aug 13 11:43:08 2018
New Revision: 339599

URL: http://llvm.org/viewvc/llvm-project?rev=339599=rev
Log:
[analyzer][UninitializedObjectChecker] Refactoring p4.: Wrap FieldRegions and 
reduce weight on FieldChainInfo

Before this patch, FieldChainInfo used a spaghetti: it took care of way too 
many cases,
even though it was always meant as a lightweight wrapper around
ImmutableList.
This problem is solved by introducing a lightweight polymorphic wrapper around 
const
FieldRegion *, FieldNode. It is an interface that abstracts away special cases 
like
pointers/references, objects that need to be casted to another type for a 
proper note
messages.

Changes to FieldChainInfo:

  * Now wraps ImmutableList.
  * Any pointer/reference related fields and methods were removed
  * Got a new add method. This replaces it's former constructors as a way to 
create a
new FieldChainInfo objects with a new element.

Changes to FindUninitializedField:

  * In order not to deal with dynamic memory management, when an uninitialized 
field is
found, the note message for it is constructed and is stored instead of a
FieldChainInfo object. (see doc around addFieldToUninits).

Some of the test files are changed too, from now on uninitialized pointees of 
references
always print "uninitialized pointee" instead of "uninitialized field" (which 
should've
really been like this from the beginning).

I also updated every comment according to these changes.

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

Modified:

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
cfe/trunk/test/Analysis/cxx-uninitialized-object.cpp
cfe/trunk/test/Analysis/objcpp-uninitialized-object.mm

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h?rev=339599=339598=339599=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h 
(original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h 
Mon Aug 13 11:43:08 2018
@@ -26,58 +26,85 @@
 namespace clang {
 namespace ento {
 
+/// Represent a single field. This is only an interface to abstract away 
special
+/// cases like pointers/references.
+class FieldNode {
+protected:
+  const FieldRegion *FR;
+
+public:
+  FieldNode(const FieldRegion *FR) : FR(FR) { assert(FR); }
+
+  FieldNode() = delete;
+  FieldNode(const FieldNode &) = delete;
+  FieldNode(FieldNode &&) = delete;
+  FieldNode =(const FieldNode &) = delete;
+  FieldNode =(const FieldNode &&) = delete;
+
+  /// Profile - Used to profile the contents of this object for inclusion in a
+  /// FoldingSet.
+  void Profile(llvm::FoldingSetNodeID ) const { ID.AddPointer(this); }
+
+  bool operator<(const FieldNode ) const { return FR < Other.FR; }
+  bool isSameRegion(const FieldRegion *OtherFR) const { return FR == OtherFR; }
+
+  const FieldRegion *getRegion() const { return FR; }
+  const FieldDecl *getDecl() const { return FR->getDecl(); }
+
+  // When a fieldchain is printed (a list of FieldNode objects), it will have
+  // the following format:
+  // 'this->...'
+
+  /// If this is the last element of the fieldchain, this method will be 
called.
+  /// The note message should state something like "uninitialized field" or
+  /// "uninitialized pointee" etc.
+  virtual void printNoteMsg(llvm::raw_ostream ) const = 0;
+
+  /// Print any prefixes before the fieldchain.
+  virtual void printPrefix(llvm::raw_ostream ) const = 0;
+
+  /// Print the node. Should contain the name of the field stored in getRegion.
+  virtual void printNode(llvm::raw_ostream ) const = 0;
+
+  /// Print the separator. For example, fields may be separated with '.' or
+  /// "->".
+  virtual void printSeparator(llvm::raw_ostream ) const = 0;
+};
+
+/// Returns with Field's name. This is a helper function to get the correct 
name
+/// even if Field is a captured lambda variable.
+StringRef getVariableName(const FieldDecl *Field);
+
 /// Represents a field chain. A field chain is a vector of fields where the
 /// first element of the chain is the object under checking (not stored), and
 /// every other element is a field, and the element that precedes it is the
 /// object that contains it.
 ///
-/// Note that this class is immutable, and new fields may only be added through
-/// constructor calls.
+/// Note that this class is immutable (essentially a wrapper around an
+/// ImmutableList), and new elements can only be added by creating new
+/// FieldChainInfo objects through add().
 class FieldChainInfo {
 public:
-  using 

[PATCH] D50506: [analyzer][UninitializedObjectChecker] Refactoring p4.: Wrap FieldRegions and reduce weight on FieldChainInfo

2018-08-13 Thread Umann Kristóf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339599: [analyzer][UninitializedObjectChecker] Refactoring 
p4.: Wrap FieldRegions and… (authored by Szelethus, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50506?vs=159896=160417#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50506

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
  test/Analysis/cxx-uninitialized-object.cpp
  test/Analysis/objcpp-uninitialized-object.mm

Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -72,6 +72,27 @@
   void checkEndFunction(const ReturnStmt *RS, CheckerContext ) const;
 };
 
+/// A basic field type, that is not a pointer or a reference, it's dynamic and
+/// static type is the same.
+class RegularField : public FieldNode {
+public:
+  RegularField(const FieldRegion *FR) : FieldNode(FR) {}
+
+  virtual void printNoteMsg(llvm::raw_ostream ) const override {
+Out << "uninitialized field ";
+  }
+
+  virtual void printPrefix(llvm::raw_ostream ) const override {}
+
+  virtual void printNode(llvm::raw_ostream ) const {
+Out << getVariableName(getDecl());
+  }
+
+  virtual void printSeparator(llvm::raw_ostream ) const override {
+Out << '.';
+  }
+};
+
 } // end of anonymous namespace
 
 // Utility function declarations.
@@ -89,14 +110,6 @@
 static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
   CheckerContext );
 
-/// Constructs a note message for a given FieldChainInfo object.
-static void printNoteMessage(llvm::raw_ostream ,
- const FieldChainInfo );
-
-/// Returns with Field's name. This is a helper function to get the correct name
-/// even if Field is a captured lambda variable.
-static StringRef getVariableName(const FieldDecl *Field);
-
 //===--===//
 //  Methods for UninitializedObjectChecker.
 //===--===//
@@ -126,7 +139,7 @@
   FindUninitializedFields F(Context.getState(), Object->getRegion(), IsPedantic,
 CheckPointeeInitialization);
 
-  const UninitFieldSet  = F.getUninitFields();
+  const UninitFieldMap  = F.getUninitFields();
 
   if (UninitFields.empty())
 return;
@@ -146,14 +159,10 @@
   // For Plist consumers that don't support notes just yet, we'll convert notes
   // to warnings.
   if (ShouldConvertNotesToWarnings) {
-for (const auto  : UninitFields) {
-  SmallString<100> WarningBuf;
-  llvm::raw_svector_ostream WarningOS(WarningBuf);
-
-  printNoteMessage(WarningOS, Chain);
+for (const auto  : UninitFields) {
 
   auto Report = llvm::make_unique(
-  *BT_uninitField, WarningOS.str(), Node, LocUsedForUniqueing,
+  *BT_uninitField, Pair.second, Node, LocUsedForUniqueing,
   Node->getLocationContext()->getDecl());
   Context.emitReport(std::move(Report));
 }
@@ -170,14 +179,9 @@
   *BT_uninitField, WarningOS.str(), Node, LocUsedForUniqueing,
   Node->getLocationContext()->getDecl());
 
-  for (const auto  : UninitFields) {
-SmallString<200> NoteBuf;
-llvm::raw_svector_ostream NoteOS(NoteBuf);
-
-printNoteMessage(NoteOS, Chain);
-
-Report->addNote(NoteOS.str(),
-PathDiagnosticLocation::create(Chain.getEndOfChain(),
+  for (const auto  : UninitFields) {
+Report->addNote(Pair.second,
+PathDiagnosticLocation::create(Pair.first->getDecl(),
Context.getSourceManager()));
   }
   Context.emitReport(std::move(Report));
@@ -193,8 +197,8 @@
 : State(State), ObjectR(R), IsPedantic(IsPedantic),
   CheckPointeeInitialization(CheckPointeeInitialization) {}
 
-const UninitFieldSet ::getUninitFields() {
-  isNonUnionUninit(ObjectR, FieldChainInfo(Factory));
+const UninitFieldMap ::getUninitFields() {
+  isNonUnionUninit(ObjectR, FieldChainInfo(ChainFactory));
 
   if (!IsPedantic && !IsAnyFieldInitialized)
 UninitFields.clear();
@@ -204,10 +208,15 @@
 
 bool FindUninitializedFields::addFieldToUninits(FieldChainInfo Chain) {
   if (State->getStateManager().getContext().getSourceManager().isInSystemHeader(
-  Chain.getEndOfChain()->getLocation()))
+  Chain.getUninitRegion()->getDecl()->getLocation()))
 return false;
 
-  return UninitFields.insert(Chain).second;
+  UninitFieldMap::mapped_type NoteMsgBuf;
+  

[PATCH] D50580: [clang-tidy] Abseil: no namespace check

2018-08-13 Thread Hugo Gonzalez via Phabricator via cfe-commits
hugoeg added inline comments.



Comment at: clang-tidy/abseil/NoNamespaceCheck.cpp:23
+
+  Finder->addMatcher(namespaceDecl(hasName("absl")).bind("absl_namespace"),
+ this);

deannagarcia wrote:
> aaron.ballman wrote:
> > hokein wrote:
> > > aaron.ballman wrote:
> > > > I think this needs a `not(isExpansionInSystemHeader())` in there, as 
> > > > this is going to trigger on code that includes a header file using an 
> > > > `absl` namespace. If I'm incorrect and users typically include abseil 
> > > > as something other than system includes, you'll have to find a 
> > > > different way to solve this.
> > > Yeah, we have discussed this issue internally.  abseil-user code usually 
> > > includes abseil header like `#include 
> > > "whatever/abseil/base/optimization.h"`, so `IsExpansionInSystemHeader` 
> > > doesn't work for most cases. 
> > > 
> > > We need a way to filter out all headers being a part of abseil library. I 
> > > think we can create a matcher `InExpansionInAbseilHeader` -- basically 
> > > using `IsExpansionInFileMatching` with a regex expression that matches 
> > > typical abseil include path. What do you think?
> > > 
> > > And we'll have more abseil checks (e.g.  `abseil-no-internal-deps`) that 
> > > use `InExpansionInAbseilHeader`, we should put it to a common header.
> > I think that is a sensible approach.
> We will begin working on this, I think it will first be implemented in 
> abseil-no-internal-deps but once it looks good I will add it to this patch.
I'm going to go ahead a implement this in ASTMatchers.h and include it on the 
patch for **abseil-no-internal-dep**s


https://reviews.llvm.org/D50580



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


[PATCH] D49511: [Sema/Attribute] Check for noderef attribute

2018-08-13 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:14249
+
+if (Sema::TypeHasNoDeref(Inner))
+  DeclRef = E;

The sugar was stripped off at the pointer level, but not at the pointee level. 
e.g.,
```
typedef int (bobble);
typedef bobble * (frobble);
typedef frobble * yobble;

yobble gobble;
```
I think you can handle this within `TypeHasNoDeref()` and that should fix up 
all the callers.


Repository:
  rC Clang

https://reviews.llvm.org/D49511



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


[PATCH] D50652: [libcxx] By default, do not use internal_linkage to hide symbols from the ABI

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

Update documentation for _LIBCPP_HIDE_FROM_ABI


Repository:
  rCXX libc++

https://reviews.llvm.org/D50652

Files:
  libcxx/docs/DesignDocs/VisibilityMacros.rst
  libcxx/include/__config


Index: libcxx/include/__config
===
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -796,7 +796,11 @@
 #endif
 
 #ifndef _LIBCPP_HIDE_FROM_ABI
-#  define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
+#  ifdef _LIBCPP_HIDE_FROM_ABI_PER_TU
+#define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
+#  else
+#define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_ALWAYS_INLINE
+#  endif
 #endif
 
 #ifdef _LIBCPP_BUILDING_LIBRARY
Index: libcxx/docs/DesignDocs/VisibilityMacros.rst
===
--- libcxx/docs/DesignDocs/VisibilityMacros.rst
+++ libcxx/docs/DesignDocs/VisibilityMacros.rst
@@ -42,9 +42,7 @@
 
 **_LIBCPP_HIDE_FROM_ABI**
   Mark a function as not being part of the ABI of any final linked image that
-  uses it, and also as being internal to each TU that uses that function. In
-  other words, the address of a function marked with this attribute is not
-  guaranteed to be the same across translation units.
+  uses it.
 
 **_LIBCPP_HIDE_FROM_ABI_AFTER_V1**
   Mark a function as being hidden from the ABI (per `_LIBCPP_HIDE_FROM_ABI`)
@@ -61,6 +59,21 @@
   ABI, we should create a new _LIBCPP_HIDE_FROM_ABI_AFTER_XXX macro, and we can
   use it to start removing symbols from the ABI after that stable version.
 
+**_LIBCPP_HIDE_FROM_ABI_PER_TU**
+  This macro controls whether symbols hidden from the ABI with 
`_LIBCPP_HIDE_FROM_ABI`
+  are local to each translation unit in addition to being local to each final
+  linked image. When enabled, this means that translation units compiled
+  with different versions of libc++ can be linked together, since all non
+  ABI-facing functions are local to each translation unit. This allows static
+  archives built with different versions of libc++ to be linked together. This
+  also means that functions marked with `_LIBCPP_HIDE_FROM_ABI` are not 
guaranteed
+  to have the same address across translation unit boundaries.
+
+  When the macro is not defined (the default), there is no guarantee that
+  translation units compiled with different versions of libc++ can 
interoperate.
+  However, this leads to code size improvements, since non ABI-facing functions
+  can be deduplicated across translation unit boundaries.
+
 **_LIBCPP_TYPE_VIS**
   Mark a type's typeinfo, vtable and members as having default visibility.
   This attribute cannot be used on class templates.


Index: libcxx/include/__config
===
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -796,7 +796,11 @@
 #endif
 
 #ifndef _LIBCPP_HIDE_FROM_ABI
-#  define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
+#  ifdef _LIBCPP_HIDE_FROM_ABI_PER_TU
+#define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
+#  else
+#define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_ALWAYS_INLINE
+#  endif
 #endif
 
 #ifdef _LIBCPP_BUILDING_LIBRARY
Index: libcxx/docs/DesignDocs/VisibilityMacros.rst
===
--- libcxx/docs/DesignDocs/VisibilityMacros.rst
+++ libcxx/docs/DesignDocs/VisibilityMacros.rst
@@ -42,9 +42,7 @@
 
 **_LIBCPP_HIDE_FROM_ABI**
   Mark a function as not being part of the ABI of any final linked image that
-  uses it, and also as being internal to each TU that uses that function. In
-  other words, the address of a function marked with this attribute is not
-  guaranteed to be the same across translation units.
+  uses it.
 
 **_LIBCPP_HIDE_FROM_ABI_AFTER_V1**
   Mark a function as being hidden from the ABI (per `_LIBCPP_HIDE_FROM_ABI`)
@@ -61,6 +59,21 @@
   ABI, we should create a new _LIBCPP_HIDE_FROM_ABI_AFTER_XXX macro, and we can
   use it to start removing symbols from the ABI after that stable version.
 
+**_LIBCPP_HIDE_FROM_ABI_PER_TU**
+  This macro controls whether symbols hidden from the ABI with `_LIBCPP_HIDE_FROM_ABI`
+  are local to each translation unit in addition to being local to each final
+  linked image. When enabled, this means that translation units compiled
+  with different versions of libc++ can be linked together, since all non
+  ABI-facing functions are local to each translation unit. This allows static
+  archives built with different versions of libc++ to be linked together. This
+  also means that functions marked with `_LIBCPP_HIDE_FROM_ABI` are not guaranteed
+  to have the same address across translation unit boundaries.
+
+  When the macro is not defined (the default), there is no guarantee that
+  translation units compiled with different versions of libc++ can interoperate.
+  However, this 

r339597 - Enforce instantiation of template multiversion functions

2018-08-13 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Mon Aug 13 11:33:20 2018
New Revision: 339597

URL: http://llvm.org/viewvc/llvm-project?rev=339597=rev
Log:
Enforce instantiation of template multiversion functions

Multiversioned member functions inside of a template type were 
not properly being emitted.  The solution to this is to simply 
ensure that their bodies are correctly evaluated/assigned during
template instantiation.

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/CodeGenCXX/attr-target-mv-member-funcs.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=339597=339596=339597=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Aug 13 11:33:20 2018
@@ -2743,7 +2743,7 @@ public:
   /// predicate.
   void forEachMultiversionedFunctionVersion(
   const FunctionDecl *FD,
-  llvm::function_ref Pred) const;
+  llvm::function_ref Pred) const;
 
   const CXXConstructorDecl *
   getCopyConstructorForExceptionObject(CXXRecordDecl *RD);

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=339597=339596=339597=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Aug 13 11:33:20 2018
@@ -9819,7 +9819,7 @@ bool ASTContext::DeclMustBeEmitted(const
 
 void ASTContext::forEachMultiversionedFunctionVersion(
 const FunctionDecl *FD,
-llvm::function_ref Pred) const {
+llvm::function_ref Pred) const {
   assert(FD->isMultiVersion() && "Only valid for multiversioned functions");
   llvm::SmallDenseSet SeenDecls;
   FD = FD->getCanonicalDecl();

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=339597=339596=339597=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Aug 13 11:33:20 2018
@@ -5175,10 +5175,20 @@ void Sema::PerformPendingInstantiations(
 if (FunctionDecl *Function = dyn_cast(Inst.first)) {
   bool DefinitionRequired = Function->getTemplateSpecializationKind() ==
 TSK_ExplicitInstantiationDefinition;
-  InstantiateFunctionDefinition(/*FIXME:*/Inst.second, Function, true,
-DefinitionRequired, true);
-  if (Function->isDefined())
-Function->setInstantiationIsPending(false);
+  if (Function->isMultiVersion()) {
+getASTContext().forEachMultiversionedFunctionVersion(
+Function, [this, Inst, DefinitionRequired](FunctionDecl *CurFD) {
+  InstantiateFunctionDefinition(/*FIXME:*/ Inst.second, CurFD, 
true,
+DefinitionRequired, true);
+  if (CurFD->isDefined())
+CurFD->setInstantiationIsPending(false);
+});
+  } else {
+InstantiateFunctionDefinition(/*FIXME:*/ Inst.second, Function, true,
+  DefinitionRequired, true);
+if (Function->isDefined())
+  Function->setInstantiationIsPending(false);
+  }
   continue;
 }
 

Modified: cfe/trunk/test/CodeGenCXX/attr-target-mv-member-funcs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/attr-target-mv-member-funcs.cpp?rev=339597=339596=339597=diff
==
--- cfe/trunk/test/CodeGenCXX/attr-target-mv-member-funcs.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/attr-target-mv-member-funcs.cpp Mon Aug 13 
11:33:20 2018
@@ -111,13 +111,12 @@ int templ_use() {
 // CHECK:  call i32 @_ZN5templIiE3fooEi.ifunc
 // CHECK:  call i32 @_ZN5templIdE3fooEi.ifunc
 
-
 // CHECK: define i32 (%struct.templ*, i32)* @_ZN5templIiE3fooEi.resolver() 
comdat
 // CHECK: ret i32 (%struct.templ*, i32)* @_ZN5templIiE3fooEi.arch_sandybridge
 // CHECK: ret i32 (%struct.templ*, i32)* @_ZN5templIiE3fooEi.arch_ivybridge
 // CHECK: ret i32 (%struct.templ*, i32)* @_ZN5templIiE3fooEi.sse4.2
 // CHECK: ret i32 (%struct.templ*, i32)* @_ZN5templIiE3fooEi
-//
+
 // CHECK: define i32 (%struct.templ.0*, i32)* @_ZN5templIdE3fooEi.resolver() 
comdat
 // CHECK: ret i32 (%struct.templ.0*, i32)* @_ZN5templIdE3fooEi.arch_sandybridge
 // CHECK: ret i32 (%struct.templ.0*, i32)* @_ZN5templIdE3fooEi.arch_ivybridge
@@ -135,3 +134,12 @@ int templ_use() {
 // CHECK: define linkonce_odr i32 @_ZN1S3fooEi(%struct.S* %this, i32)
 // CHECK: ret i32 2
 
+// CHECK: define 

[PATCH] D50652: [libcxx] By default, do not use internal_linkage to hide symbols from the ABI

2018-08-13 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

The intent is for this patch to be cherry-picked onto the LLVM 7 release.

This is a straw man proposal to fix issues raised in 
https://reviews.llvm.org/D49240. The idea is that in the future, we would 
probably want the non-`internal_linkage` case to be the default. By introducing 
the `_LIBCPP_HIDE_FROM_ABI_PER_TU` setting, we're setting up libc++ users for 
the right default (i.e. no insane guarantee of being able to link TUs built 
with different libc++ versions), without actually changing any behavior for the 
LLVM 7 release. Once we have a solution that allows us to drop 
`_LIBCPP_ALWAYS_INLINE` from `_LIBCPP_HIDE_FROM_ABI` (in LLVM 8), we can just 
do it and everybody should see code size improvements, without a crazy increase 
in the number of symbols (as reported by Chromium). In LLVM8, the few projects 
that actually need to link TUs built with different libc++ versions can then 
just define `_LIBCPP_HIDE_FROM_ABI_PER_TU` to keep today's behavior.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50652



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


[PATCH] D49240: [libc++] Introduce _LIBCPP_HIDE_FROM_ABI to replace _LIBCPP_INLINE_VISIBILITY

2018-08-13 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

I opened a straw man proposal to fix this at https://reviews.llvm.org/D50652.


Repository:
  rCXX libc++

https://reviews.llvm.org/D49240



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


[PATCH] D50652: [libcxx] By default, do not use internal_linkage to hide symbols from the ABI

2018-08-13 Thread Louis Dionne via Phabricator via cfe-commits
ldionne created this revision.
ldionne added reviewers: EricWF, mclow.lists, dexonsmith, hans, rnk.
Herald added subscribers: cfe-commits, christof.

This led to symbol size problems in Chromium, and we expect this may be
the case in other projects built in debug mode too. Instead, unless users
explicitly ask for internal_linkage, we use always_inline like we used to.

In the future, when we have a solution that allows us to drop always_inline
without falling back on internal_linkage, we can replace always_inline by
that.

Note that this commit introduces a change in contract for existing libc++
users: by default, libc++ used to guarantee that TUs built with different
versions of libc++ could be linked together. With the introduction of the
_LIBCPP_HIDE_FROM_ABI_PER_TU macro, the default behavior is that TUs built
with different libc++ versions are not guaranteed to link. This is a change
in contract but not a change in behavior, since the current implementation
still allows linking TUs built with different libc++ versions together.


Repository:
  rCXX libc++

https://reviews.llvm.org/D50652

Files:
  libcxx/docs/DesignDocs/VisibilityMacros.rst
  libcxx/include/__config


Index: libcxx/include/__config
===
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -796,7 +796,11 @@
 #endif
 
 #ifndef _LIBCPP_HIDE_FROM_ABI
-#  define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
+#  ifdef _LIBCPP_HIDE_FROM_ABI_PER_TU
+#define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
+#  else
+#define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_ALWAYS_INLINE
+#  endif
 #endif
 
 #ifdef _LIBCPP_BUILDING_LIBRARY
Index: libcxx/docs/DesignDocs/VisibilityMacros.rst
===
--- libcxx/docs/DesignDocs/VisibilityMacros.rst
+++ libcxx/docs/DesignDocs/VisibilityMacros.rst
@@ -61,6 +61,18 @@
   ABI, we should create a new _LIBCPP_HIDE_FROM_ABI_AFTER_XXX macro, and we can
   use it to start removing symbols from the ABI after that stable version.
 
+**_LIBCPP_HIDE_FROM_ABI_PER_TU**
+  This macro controls whether symbols hidden from the ABI are local to each
+  translation unit. When enabled, this means that translation units compiled
+  with different versions of libc++ can be linked together, since all non
+  ABI-facing functions are local to each translation unit. This allows static
+  archives built with different versions of libc++ to be linked together.
+
+  When the macro is not defined (the default), there is no guarantee that
+  translation units compiled with different versions of libc++ can 
interoperate.
+  However, this leads to code size improvements, since non ABI-facing functions
+  can be deduplicated across translation unit boundaries.
+
 **_LIBCPP_TYPE_VIS**
   Mark a type's typeinfo, vtable and members as having default visibility.
   This attribute cannot be used on class templates.


Index: libcxx/include/__config
===
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -796,7 +796,11 @@
 #endif
 
 #ifndef _LIBCPP_HIDE_FROM_ABI
-#  define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
+#  ifdef _LIBCPP_HIDE_FROM_ABI_PER_TU
+#define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
+#  else
+#define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_ALWAYS_INLINE
+#  endif
 #endif
 
 #ifdef _LIBCPP_BUILDING_LIBRARY
Index: libcxx/docs/DesignDocs/VisibilityMacros.rst
===
--- libcxx/docs/DesignDocs/VisibilityMacros.rst
+++ libcxx/docs/DesignDocs/VisibilityMacros.rst
@@ -61,6 +61,18 @@
   ABI, we should create a new _LIBCPP_HIDE_FROM_ABI_AFTER_XXX macro, and we can
   use it to start removing symbols from the ABI after that stable version.
 
+**_LIBCPP_HIDE_FROM_ABI_PER_TU**
+  This macro controls whether symbols hidden from the ABI are local to each
+  translation unit. When enabled, this means that translation units compiled
+  with different versions of libc++ can be linked together, since all non
+  ABI-facing functions are local to each translation unit. This allows static
+  archives built with different versions of libc++ to be linked together.
+
+  When the macro is not defined (the default), there is no guarantee that
+  translation units compiled with different versions of libc++ can interoperate.
+  However, this leads to code size improvements, since non ABI-facing functions
+  can be deduplicated across translation unit boundaries.
+
 **_LIBCPP_TYPE_VIS**
   Mark a type's typeinfo, vtable and members as having default visibility.
   This attribute cannot be used on class templates.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50505: [analyzer][UninitializedObjectChecker] Refactoring p3.: printTail moved out from FieldChainInfo

2018-08-13 Thread Umann Kristóf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339596: [analyzer][UninitializedObjectChecker] Refactoring 
p3.: printTail moved out… (authored by Szelethus, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50505?vs=159891=160406#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50505

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
  lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp

Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
@@ -18,8 +18,8 @@
 //
 //===--===//
 
-#include "UninitializedObject.h"
 #include "ClangSACheckers.h"
+#include "UninitializedObject.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -46,8 +46,8 @@
 //
 //===--===//
 
-#include "UninitializedObject.h"
 #include "ClangSACheckers.h"
+#include "UninitializedObject.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
@@ -87,7 +87,7 @@
 /// (e.g. if the object is a field of another object, in which case we'd check
 /// it multiple times).
 static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
-   CheckerContext );
+  CheckerContext );
 
 /// Constructs a note message for a given FieldChainInfo object.
 static void printNoteMessage(llvm::raw_ostream ,
@@ -346,6 +346,13 @@
   return (*Chain.begin())->getDecl();
 }
 
+/// Prints every element except the last to `Out`. Since ImmutableLists store
+/// elements in reverse order, and have no reverse iterators, we use a
+/// recursive function to print the fieldchain correctly. The last element in
+/// the chain is to be printed by `print`.
+static void printTail(llvm::raw_ostream ,
+  const FieldChainInfo::FieldChainImpl *L);
+
 // TODO: This function constructs an incorrect string if a void pointer is a
 // part of the chain:
 //
@@ -383,15 +390,13 @@
   if (Chain.isEmpty())
 return;
 
-  const llvm::ImmutableListImpl *L =
-  Chain.getInternalPointer();
+  const FieldChainImpl *L = Chain.getInternalPointer();
   printTail(Out, L->getTail());
   Out << getVariableName(L->getHead()->getDecl());
 }
 
-void FieldChainInfo::printTail(
-llvm::raw_ostream ,
-const llvm::ImmutableListImpl *L) {
+static void printTail(llvm::raw_ostream ,
+  const FieldChainInfo::FieldChainImpl *L) {
   if (!L)
 return;
 
@@ -420,7 +425,7 @@
 }
 
 static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
-   CheckerContext ) {
+  CheckerContext ) {
 
   Optional CurrentObject = getObjectVal(Ctor, Context);
   if (!CurrentObject)
Index: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
===
--- lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
+++ lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
@@ -35,6 +35,7 @@
 /// constructor calls.
 class FieldChainInfo {
 public:
+  using FieldChainImpl = llvm::ImmutableListImpl;
   using FieldChain = llvm::ImmutableList;
 
 private:
@@ -48,7 +49,8 @@
   FieldChainInfo(FieldChain::Factory ) : Factory(F) {}
 
   FieldChainInfo(const FieldChainInfo , const bool IsDereferenced)
-  : Factory(Other.Factory), Chain(Other.Chain), IsDereferenced(IsDereferenced) {}
+  : Factory(Other.Factory), Chain(Other.Chain),
+IsDereferenced(IsDereferenced) {}
 
   FieldChainInfo(const FieldChainInfo , const FieldRegion *FR,
  const bool IsDereferenced = false);
@@ -64,12 +66,6 @@
   void print(llvm::raw_ostream ) const;
 
 private:
-  /// Prints every element except the last to `Out`. Since ImmutableLists store
-  /// elements in reverse order, and have no reverse iterators, we use a
-  /// recursive function to print the fieldchain correctly. The last element in
-  /// the chain 

r339596 - [analyzer][UninitializedObjectChecker] Refactoring p3.: printTail moved out from FieldChainInfo

2018-08-13 Thread Kristof Umann via cfe-commits
Author: szelethus
Date: Mon Aug 13 11:22:22 2018
New Revision: 339596

URL: http://llvm.org/viewvc/llvm-project?rev=339596=rev
Log:
[analyzer][UninitializedObjectChecker] Refactoring p3.: printTail moved out 
from FieldChainInfo

This is a standalone part of the effort to reduce FieldChainInfos inteerface.

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

Modified:

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp

cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h?rev=339596=339595=339596=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h 
(original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h 
Mon Aug 13 11:22:22 2018
@@ -35,6 +35,7 @@ namespace ento {
 /// constructor calls.
 class FieldChainInfo {
 public:
+  using FieldChainImpl = llvm::ImmutableListImpl;
   using FieldChain = llvm::ImmutableList;
 
 private:
@@ -48,7 +49,8 @@ public:
   FieldChainInfo(FieldChain::Factory ) : Factory(F) {}
 
   FieldChainInfo(const FieldChainInfo , const bool IsDereferenced)
-  : Factory(Other.Factory), Chain(Other.Chain), 
IsDereferenced(IsDereferenced) {}
+  : Factory(Other.Factory), Chain(Other.Chain),
+IsDereferenced(IsDereferenced) {}
 
   FieldChainInfo(const FieldChainInfo , const FieldRegion *FR,
  const bool IsDereferenced = false);
@@ -64,12 +66,6 @@ public:
   void print(llvm::raw_ostream ) const;
 
 private:
-  /// Prints every element except the last to `Out`. Since ImmutableLists store
-  /// elements in reverse order, and have no reverse iterators, we use a
-  /// recursive function to print the fieldchain correctly. The last element in
-  /// the chain is to be printed by `print`.
-  static void printTail(llvm::raw_ostream ,
-const llvm::ImmutableListImpl *L);
   friend struct FieldChainInfoComparator;
 };
 

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp?rev=339596=339595=339596=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 (original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 Mon Aug 13 11:22:22 2018
@@ -46,8 +46,8 @@
 //
 
//===--===//
 
-#include "UninitializedObject.h"
 #include "ClangSACheckers.h"
+#include "UninitializedObject.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
@@ -87,7 +87,7 @@ getObjectVal(const CXXConstructorDecl *C
 /// (e.g. if the object is a field of another object, in which case we'd check
 /// it multiple times).
 static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
-   CheckerContext );
+  CheckerContext );
 
 /// Constructs a note message for a given FieldChainInfo object.
 static void printNoteMessage(llvm::raw_ostream ,
@@ -346,6 +346,13 @@ const FieldDecl *FieldChainInfo::getEndO
   return (*Chain.begin())->getDecl();
 }
 
+/// Prints every element except the last to `Out`. Since ImmutableLists store
+/// elements in reverse order, and have no reverse iterators, we use a
+/// recursive function to print the fieldchain correctly. The last element in
+/// the chain is to be printed by `print`.
+static void printTail(llvm::raw_ostream ,
+  const FieldChainInfo::FieldChainImpl *L);
+
 // TODO: This function constructs an incorrect string if a void pointer is a
 // part of the chain:
 //
@@ -383,15 +390,13 @@ void FieldChainInfo::print(llvm::raw_ost
   if (Chain.isEmpty())
 return;
 
-  const llvm::ImmutableListImpl *L =
-  Chain.getInternalPointer();
+  const FieldChainImpl *L = Chain.getInternalPointer();
   printTail(Out, L->getTail());
   Out << getVariableName(L->getHead()->getDecl());
 }
 
-void FieldChainInfo::printTail(
-llvm::raw_ostream ,
-const llvm::ImmutableListImpl *L) {
+static void printTail(llvm::raw_ostream ,
+  const FieldChainInfo::FieldChainImpl *L) {
   if (!L)
 return;
 
@@ -420,7 +425,7 @@ getObjectVal(const CXXConstructorDecl *C
 }
 
 static bool 

[PATCH] D47757: [Sema] Produce diagnostics when unavailable aligned allocation/deallocation functions are called

2018-08-13 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: test/SemaCUDA/call-host-fn-from-device.cu:88
 __host__ __device__ void class_specific_delete(T *t, U *u) {
-  delete t; // ok, call sized device delete even though host has preferable 
non-sized version
+  delete t; // expected-error {{reference to __host__ function 'operator 
delete' in __host__ __device__ function}}
   delete u; // ok, call non-sized HD delete rather than sized D delete

rsmith wrote:
> rsmith wrote:
> > tra wrote:
> > > The C++ magic is way above my paygrade, but as far as CUDA goes this is a 
> > > regression, compared to what nvcc does. This code in NVCC produced a 
> > > warning and clang should not error out at this point in time either as 
> > > it's not an error to call a host function from HD unless we use HD in a 
> > > host function, and we would not know how it's used until later. I think 
> > > the error should be postponed until codegen. 
> > > 
> > > 
> > > 
> > > 
> > We're in `-fcuda-is-device` mode, so IIUC it's correct to reject a call to 
> > a host function here (because `__host__ __device__` is treated as basically 
> > meaning `__device__` in that mode for the purpose of checking whether a 
> > call is valid), right?
> > 
> > However, the comment suggests that the intent was that this would instead 
> > call the device version. Did that actually previously happen (in which case 
> > this patch is somehow affecting overload resolution and should be fixed), 
> > or is the comment prior to this patch wrong and we were silently calling a 
> > host function from a device function (in which case this patch is fine, but 
> > we should add a FIXME here to select the device delete function if we think 
> > that's appropriate)?
> OK, I see from prior review comments (that phab is helpfully hiding from 
> view) that this is just adding a diagnostic and the overload resolution 
> behavior is unchanged. So I think this change is correct. @tra, can you 
> confirm? My testing shows that
> 
> ```
> __host__ void f(); __host__ __device__ void g() { f(); }
> ```
> 
> is accepted by default but rejected in `-fcuda-is-device` mode, which is 
> consistent with the behavior after this patch is applied.
"-fcuda-is-device" does not necessarily mean that the __host__ __device__ 
function will be used.

In the example above the error is indeed correct, as g() is considered to be 
externally visible and we will attempt to generate code for it, and we can't 
call f() on device.

However, if you make it static, there should be no error:
```
__host__ void f(); 
static __host__ __device__ void g() { f(); }
```

CUDA is somewhat weird when it comes to what's considered available and what is 
not.
If you want some of the gory details, see D12453 and https://goo.gl/EXnymm

@jlebar has details on how we handle the errors in cases like that:
https://github.com/llvm-mirror/clang/blob/master/lib/Sema/SemaCUDA.cpp#L590



Repository:
  rC Clang

https://reviews.llvm.org/D47757



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


  1   2   3   >