[PATCH] D87615: [X86] Fix stack alignment on 32-bit Solaris/x86

2020-09-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.

> This patch avoid the issue by defaulting to -mstackrealign, just like gcc.

This sentence from the description should be removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87615

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


[PATCH] D87812: [FPEnv] Use typed accessors in FPOptions

2020-09-16 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff created this revision.
sepavloff added reviewers: rjmccall, kpn, mibintc.
Herald added subscribers: llvm-commits, dexonsmith.
Herald added projects: clang, LLVM.
sepavloff requested review of this revision.

Previously methods `FPOptions::get*` returned unsigned value even if the
corresponding property was represented by specific enumeration type. With
this change such methods return actual type of the property. It also
allows printing value of a property as text rather than integer code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87812

Files:
  clang/include/clang/Basic/FPOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/test/AST/ast-dump-fpfeatures.cpp
  llvm/include/llvm/ADT/FloatingPointMode.h

Index: llvm/include/llvm/ADT/FloatingPointMode.h
===
--- llvm/include/llvm/ADT/FloatingPointMode.h
+++ llvm/include/llvm/ADT/FloatingPointMode.h
@@ -44,6 +44,24 @@
   Invalid = -1///< Denotes invalid value.
 };
 
+/// Returns text representation of the given rounding mode.
+inline StringRef spell(RoundingMode RM) {
+  switch (RM) {
+  case RoundingMode::TowardZero: return "towardzero";
+  case RoundingMode::NearestTiesToEven: return "tonearest";
+  case RoundingMode::TowardPositive: return "upward";
+  case RoundingMode::TowardNegative: return "downward";
+  case RoundingMode::NearestTiesToAway: return "tonearestaway";
+  case RoundingMode::Dynamic: return "dynamic";
+  default: return "invalid";
+  }
+}
+
+inline raw_ostream  << (raw_ostream , RoundingMode RM) {
+  OS << spell(RM);
+  return OS;
+}
+
 /// Represent subnormal handling kind for floating point instruction inputs and
 /// outputs.
 struct DenormalMode {
Index: clang/test/AST/ast-dump-fpfeatures.cpp
===
--- clang/test/AST/ast-dump-fpfeatures.cpp
+++ clang/test/AST/ast-dump-fpfeatures.cpp
@@ -87,7 +87,7 @@
 }
 
 // CHECK-LABEL: FunctionDecl {{.*}} func_10 'float (float, float)'
-// CHECK: BinaryOperator {{.*}} 'float' '+' RoundingMode=3
+// CHECK: BinaryOperator {{.*}} 'float' '+' RoundingMode=downward
 
 float func_11(float x, float y) {
   if (x < 0) {
@@ -98,8 +98,8 @@
 }
 
 // CHECK-LABEL: FunctionDecl {{.*}} func_11 'float (float, float)'
-// CHECK: BinaryOperator {{.*}} 'float' '+' RoundingMode=2
-// CHECK: BinaryOperator {{.*}} 'float' '-' RoundingMode=3
+// CHECK: BinaryOperator {{.*}} 'float' '+' RoundingMode=upward
+// CHECK: BinaryOperator {{.*}} 'float' '-' RoundingMode=downward
 
 
 #pragma STDC FENV_ROUND FE_DYNAMIC
@@ -109,7 +109,7 @@
 }
 
 // CHECK-LABEL: FunctionDecl {{.*}} func_12 'float (float, float)'
-// CHECK: BinaryOperator {{.*}} 'float' '+' RoundingMode=1
+// CHECK: BinaryOperator {{.*}} 'float' '+' RoundingMode=tonearest
 
 #pragma STDC FENV_ROUND FE_TONEAREST
 
@@ -118,7 +118,7 @@
 }
 
 // CHECK-LABEL: FunctionDecl {{.*}} func_13 'float (float, float)'
-// CHECK: BinaryOperator {{.*}} 'float' '+' RoundingMode=1
+// CHECK: BinaryOperator {{.*}} 'float' '+' RoundingMode=tonearest
 
 
 template 
@@ -136,8 +136,8 @@
 // CHECK: FunctionDecl {{.*}} func_14 'T (T, T)'
 // CHECK:   CompoundStmt
 // CHECK-NEXT:ReturnStmt
-// CHECK-NEXT:  BinaryOperator {{.*}} '+' RoundingMode=0
+// CHECK-NEXT:  BinaryOperator {{.*}} '+' RoundingMode=towardzero
 // CHECK: FunctionDecl {{.*}} func_14 'float (float, float)'
 // CHECK:   CompoundStmt
 // CHECK-NEXT:ReturnStmt
-// CHECK-NEXT:  BinaryOperator {{.*}} 'float' '+' RoundingMode=0
+// CHECK-NEXT:  BinaryOperator {{.*}} 'float' '+' RoundingMode=towardzero
Index: clang/include/clang/Basic/LangOptions.h
===
--- clang/include/clang/Basic/LangOptions.h
+++ clang/include/clang/Basic/LangOptions.h
@@ -432,8 +432,7 @@
   }
 
   bool isFPConstrained() const {
-return getRoundingMode() !=
-   static_cast(RoundingMode::NearestTiesToEven) ||
+return getRoundingMode() != llvm::RoundingMode::NearestTiesToEven ||
getFPExceptionMode() != LangOptions::FPE_Ignore ||
getAllowFEnvAccess();
   }
@@ -453,8 +452,8 @@
 
   // We can define most of the accessors automatically:
 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS)\
-  unsigned get##NAME() const { \
-return static_cast(TYPE((Value & NAME##Mask) >> NAME##Shift));   \
+  TYPE get##NAME() const { \
+return static_cast((Value & NAME##Mask) >> NAME##Shift); \
   }\
   void set##NAME(TYPE value) { \
 Value = (Value & ~NAME##Mask) | 

[PATCH] D87791: [CUDA][HIP] Fix -gsplit-dwarf option

2020-09-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added a comment.

In D87791#2277887 , @tra wrote:

> Does this naming scheme the same as used for `.o` files? We may want to keep 
> them in sync.
>
> Other than that, LGTM.

.o file is different story.

For -fno-gpu-rdc, the .o files for device compilation are temporary files which 
are deleted after the device ISA are generated and embedded in host .o file. 
There is only one output .o file which is the host object file.

For -fgpu-rdc, the .o files for device compilation are also temporary files 
which are bundled into the clang-offload-bundle. There is only one output .o 
file which is a bundle.

Therefore in either case there is no need to rename the intermediate .o files 
since they are temporary files which have unique names.

The .dwo files are not temporary files. They are supposed to be shipped with .o 
files for debugging info.

Since .dwo files are not temporary files, it is not necessary to follow the 
-save-temps name convention. For the host object, we keep the original .dwo 
file name. For the device object, we add '_' and GPU arch to the stem, which is 
sufficient and concise.




Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:909
+  auto AddPostfix = [JA](auto ) {
+if (JA.getOffloadingDeviceKind() == Action::OFK_HIP)
+  F += (Twine("_") + JA.getOffloadingArch()).str();

tra wrote:
> I think the same approach would make sense for CUDA, too. 
will include OFK_CUDA.


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

https://reviews.llvm.org/D87791

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


[PATCH] D87629: Thread safety analysis: Improve documentation for ASSERT_CAPABILITY

2020-09-16 Thread Anthony Towns via Phabricator via cfe-commits
ajtowns added a comment.

In D87629#2272676 , @aaronpuchert 
wrote:

> (The existing `LockAssertion` class that the change removed looks like it 
> should use `ASSERT_CAPABILITY` instead—please don't use `ACQUIRE` when the 
> capability is assumed to be held previously.)

Not sure the `try { AssertHeld } catch (...) { a = 0; }` example reveals very 
much: it seems like thread safety annotations aren't checked within a catch 
block at all?

  Mutex m;
  int i GUARDED_BY(m);
  
  static void thrower() { throw std::exception(); }
  void f() { i = 1; }
  void g() {
  try {
  thrower();
  } catch (...) {
  i = 5;
  }
  i = 6;
  }

gives me warnings for `i=1` and `i=6` but not `i=5` ?

Extending the above with:

  void AssertHeld() ASSERT_CAPABILITY(m) { return; }
  void h(bool b) {
  try {
  if (b) thrower();
  i = 7;
  AssertHeld();
  i = 8;
 } catch (...) { }
 i = 9;
  }

only gives me a warning for `i = 7`, even though when `b` is true `i = 9` is 
just as bad as the `i = 6` assignment that did generate a warning.

Using a dummy RAII class with SCOPED_CAPABILITY that does ACQUIRE/RELEASE 
without modifying the actual mutex seems like it behaves more sensibly to me...

  class SCOPED_LOCKABLE assumer
  {
  public:
  assumer(Mutex& m_) EXCLUSIVE_LOCK_FUNCTION(m_) { }
  ~assumer() UNLOCK_FUNCTION() { }
  };
  
  void h(bool b) {
  try {
  if (b) thrower();
  i = 7;
  assumer a(m);
  i = 8;
  } catch (...) { }
  i = 9;
  }

gives me warnings for both `i=7` and `i=9` but allows `i=8`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87629

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


[libunwind] fb1abe0 - [libunwind][DWARF] Fix end of .eh_frame calculation

2020-09-16 Thread Ryan Prichard via cfe-commits

Author: Ryan Prichard
Date: 2020-09-16T19:00:57-07:00
New Revision: fb1abe00635c1ec28e55921709904d5ca2e86a74

URL: 
https://github.com/llvm/llvm-project/commit/fb1abe00635c1ec28e55921709904d5ca2e86a74
DIFF: 
https://github.com/llvm/llvm-project/commit/fb1abe00635c1ec28e55921709904d5ca2e86a74.diff

LOG: [libunwind][DWARF] Fix end of .eh_frame calculation

 * When .eh_frame is located using .eh_frame_hdr (PT_GNU_EH_FRAME), the
   start of .eh_frame is known, but not the size. In this case, the
   unwinder must rely on a terminator present at the end of .eh_frame.
   Set dwarf_section_length to UINTPTR_MAX to indicate this.

 * Add a new field, text_segment_length, that the FrameHeaderCache uses
   to track the size of the PT_LOAD segment indicated by dso_base.

 * Compute ehSectionEnd by adding sectionLength to ehSectionStart,
   never to fdeHint.

Fixes PR46829.

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

Added: 


Modified: 
libunwind/src/AddressSpace.hpp
libunwind/src/DwarfParser.hpp
libunwind/src/FrameHeaderCache.hpp
libunwind/src/UnwindCursor.hpp
libunwind/test/frameheadercache_test.pass.cpp

Removed: 




diff  --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index eccc2153c697..26397c28798e 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -119,6 +119,10 @@ struct UnwindInfoSections {
   // No dso_base for SEH or ARM EHABI.
   uintptr_t   dso_base;
 #endif
+#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR) && 
\
+defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
+  uintptr_t   text_segment_length;
+#endif
 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
   uintptr_t   dwarf_section;
   uintptr_t   dwarf_section_length;
@@ -410,7 +414,7 @@ static bool checkAddrInSegment(const Elf_Phdr *phdr, size_t 
image_base,
 uintptr_t end = begin + phdr->p_memsz;
 if (cbdata->targetAddr >= begin && cbdata->targetAddr < end) {
   cbdata->sects->dso_base = begin;
-  cbdata->sects->dwarf_section_length = phdr->p_memsz;
+  cbdata->sects->text_segment_length = phdr->p_memsz;
   return true;
 }
   }
@@ -450,8 +454,12 @@ static int findUnwindSectionsByPhdr(struct dl_phdr_info 
*pinfo,
   found_hdr = EHHeaderParser::decodeEHHdr(
   *cbdata->addressSpace, eh_frame_hdr_start, phdr->p_memsz,
   hdrInfo);
-  if (found_hdr)
+  if (found_hdr) {
+// .eh_frame_hdr records the start of .eh_frame, but not its size.
+// Rely on a zero terminator to find the end of the section.
 cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr;
+cbdata->sects->dwarf_section_length = UINTPTR_MAX;
+  }
 } else if (!found_obj) {
   found_obj = checkAddrInSegment(phdr, image_base, cbdata);
 }
@@ -462,7 +470,6 @@ static int findUnwindSectionsByPhdr(struct dl_phdr_info 
*pinfo,
   return 1;
 }
   }
-  cbdata->sects->dwarf_section_length = 0;
   return 0;
 }
 

diff  --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index 1ce2cf2943a2..86c0522afd3f 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -136,7 +136,7 @@ class CFI_Parser {
   };
 
   static bool findFDE(A , pint_t pc, pint_t ehSectionStart,
-  uint32_t sectionLength, pint_t fdeHint, FDE_Info 
*fdeInfo,
+  uintptr_t sectionLength, pint_t fdeHint, FDE_Info 
*fdeInfo,
   CIE_Info *cieInfo);
   static const char *decodeFDE(A , pint_t fdeStart,
FDE_Info *fdeInfo, CIE_Info *cieInfo);
@@ -167,7 +167,7 @@ const char *CFI_Parser::decodeFDE(A , 
pint_t fdeStart,
 p += 8;
   }
   if (cfiLength == 0)
-return "FDE has zero length"; // end marker
+return "FDE has zero length"; // zero terminator
   uint32_t ciePointer = addressSpace.get32(p);
   if (ciePointer == 0)
 return "FDE is really a CIE"; // this is a CIE not an FDE
@@ -212,11 +212,13 @@ const char *CFI_Parser::decodeFDE(A , 
pint_t fdeStart,
 /// Scan an eh_frame section to find an FDE for a pc
 template 
 bool CFI_Parser::findFDE(A , pint_t pc, pint_t ehSectionStart,
-uint32_t sectionLength, pint_t fdeHint,
+uintptr_t sectionLength, pint_t fdeHint,
 FDE_Info *fdeInfo, CIE_Info *cieInfo) {
   //fprintf(stderr, "findFDE(0x%llX)\n", (long long)pc);
   pint_t p = (fdeHint != 0) ? fdeHint : ehSectionStart;
-  const pint_t ehSectionEnd = p + sectionLength;
+  const pint_t ehSectionEnd = (sectionLength == UINTPTR_MAX)
+  ? static_cast(-1)
+  : (ehSectionStart + sectionLength);
   while (p < ehSectionEnd) {
 pint_t currentCFI = p;
 //fprintf(stderr, "findFDE() CFI at 0x%llX\n", (long long)p);
@@ -228,7 +230,7 @@ bool 

[clang] 7337f29 - PR47555: Inheriting constructors are implicitly definable.

2020-09-16 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-09-16T18:11:18-07:00
New Revision: 7337f296194483e0959ff980049e2835e226f396

URL: 
https://github.com/llvm/llvm-project/commit/7337f296194483e0959ff980049e2835e226f396
DIFF: 
https://github.com/llvm/llvm-project/commit/7337f296194483e0959ff980049e2835e226f396.diff

LOG: PR47555: Inheriting constructors are implicitly definable.

Don't forget to define them if they're constexpr and used inside a
template; we might try to evaluate a call to them before the template is
instantiated.

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx11-inheriting-ctors.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9a4b3e31e850..c82febdbf3a7 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16582,8 +16582,13 @@ static OdrUseContext isOdrUseContext(Sema ) {
 }
 
 static bool isImplicitlyDefinableConstexprFunction(FunctionDecl *Func) {
-  return Func->isConstexpr() &&
- (Func->isImplicitlyInstantiable() || !Func->isUserProvided());
+  if (!Func->isConstexpr())
+return false;
+
+  if (Func->isImplicitlyInstantiable() || !Func->isUserProvided())
+return true;
+  auto *CCD = dyn_cast(Func);
+  return CCD && CCD->getInheritedConstructor();
 }
 
 /// Mark a function referenced, and check whether it is odr-used

diff  --git a/clang/test/SemaCXX/cxx11-inheriting-ctors.cpp 
b/clang/test/SemaCXX/cxx11-inheriting-ctors.cpp
index 7d6f4f09f09c..5be428401fa0 100644
--- a/clang/test/SemaCXX/cxx11-inheriting-ctors.cpp
+++ b/clang/test/SemaCXX/cxx11-inheriting-ctors.cpp
@@ -133,3 +133,12 @@ namespace implicit_member_srcloc {
 S0 s0;
   }
 }
+
+namespace PR47555 {
+  struct A { constexpr A(int) {} };
+  struct B : A { using A::A; };
+  template void f() {
+constexpr B b = 0;
+  };
+  template void f();
+}



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


[clang] 905b9ca - Canonicalize declaration pointers when forming APValues.

2020-09-16 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2020-09-16T18:11:18-07:00
New Revision: 905b9ca26c94fa86339451a528cedde5004fc1bb

URL: 
https://github.com/llvm/llvm-project/commit/905b9ca26c94fa86339451a528cedde5004fc1bb
DIFF: 
https://github.com/llvm/llvm-project/commit/905b9ca26c94fa86339451a528cedde5004fc1bb.diff

LOG: Canonicalize declaration pointers when forming APValues.

References to different declarations of the same entity aren't different
values, so shouldn't have different representations.

Recommit of e6393ee813178e9d3306b8e3c6949a4f32f8a2cb with fixed
handling for weak declarations. We now look for attributes on the most
recent declaration when determining whether a declaration is weak.

Added: 


Modified: 
clang/include/clang/AST/APValue.h
clang/lib/AST/APValue.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclBase.cpp
clang/lib/AST/ExprConstant.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp
clang/test/OpenMP/ordered_messages.cpp

Removed: 




diff  --git a/clang/include/clang/AST/APValue.h 
b/clang/include/clang/AST/APValue.h
index 5103cfa8604e..6307f8a92e5a 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -174,6 +174,7 @@ class APValue {
   return !(LHS == RHS);
 }
 friend llvm::hash_code hash_value(const LValueBase );
+friend struct llvm::DenseMapInfo;
 
   private:
 PtrTy Ptr;
@@ -201,8 +202,7 @@ class APValue {
 
   public:
 LValuePathEntry() : Value() {}
-LValuePathEntry(BaseOrMemberType BaseOrMember)
-: Value{reinterpret_cast(BaseOrMember.getOpaqueValue())} {}
+LValuePathEntry(BaseOrMemberType BaseOrMember);
 static LValuePathEntry ArrayIndex(uint64_t Index) {
   LValuePathEntry Result;
   Result.Value = Index;

diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 08ae0ff3c67d..32d3ff7ce1d0 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -38,7 +38,7 @@ static_assert(
 "Type is insufficiently aligned");
 
 APValue::LValueBase::LValueBase(const ValueDecl *P, unsigned I, unsigned V)
-: Ptr(P), Local{I, V} {}
+: Ptr(P ? cast(P->getCanonicalDecl()) : nullptr), Local{I, V} {}
 APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V)
 : Ptr(P), Local{I, V} {}
 
@@ -82,13 +82,19 @@ bool operator==(const APValue::LValueBase ,
 const APValue::LValueBase ) {
   if (LHS.Ptr != RHS.Ptr)
 return false;
-  if (LHS.is())
+  if (LHS.is() || LHS.is())
 return true;
   return LHS.Local.CallIndex == RHS.Local.CallIndex &&
  LHS.Local.Version == RHS.Local.Version;
 }
 }
 
+APValue::LValuePathEntry::LValuePathEntry(BaseOrMemberType BaseOrMember) {
+  if (const Decl *D = BaseOrMember.getPointer())
+BaseOrMember.setPointer(D->getCanonicalDecl());
+  Value = reinterpret_cast(BaseOrMember.getOpaqueValue());
+}
+
 namespace {
   struct LVBase {
 APValue::LValueBase Base;
@@ -113,14 +119,16 @@ APValue::LValueBase::operator bool () const {
 
 clang::APValue::LValueBase
 llvm::DenseMapInfo::getEmptyKey() {
-  return clang::APValue::LValueBase(
-  DenseMapInfo::getEmptyKey());
+  clang::APValue::LValueBase B;
+  B.Ptr = DenseMapInfo::getEmptyKey();
+  return B;
 }
 
 clang::APValue::LValueBase
 llvm::DenseMapInfo::getTombstoneKey() {
-  return clang::APValue::LValueBase(
-  DenseMapInfo::getTombstoneKey());
+  clang::APValue::LValueBase B;
+  B.Ptr = DenseMapInfo::getTombstoneKey();
+  return B;
 }
 
 namespace clang {
@@ -773,8 +781,10 @@ void APValue::MakeMemberPointer(const ValueDecl *Member, 
bool IsDerivedMember,
   assert(isAbsent() && "Bad state change");
   MemberPointerData *MPD = new ((void*)(char*)Data.buffer) MemberPointerData;
   Kind = MemberPointer;
-  MPD->MemberAndIsDerivedMember.setPointer(Member);
+  MPD->MemberAndIsDerivedMember.setPointer(
+  Member ? cast(Member->getCanonicalDecl()) : nullptr);
   MPD->MemberAndIsDerivedMember.setInt(IsDerivedMember);
   MPD->resizePath(Path.size());
-  memcpy(MPD->getPath(), Path.data(), Path.size()*sizeof(const 
CXXRecordDecl*));
+  for (unsigned I = 0; I != Path.size(); ++I)
+MPD->getPath()[I] = Path[I]->getCanonicalDecl();
 }

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 9815f0648ad7..b446bf0bef30 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4706,7 +4706,7 @@ char *Buffer = new (getASTContext(), 1) char[Name.size() 
+ 1];
 void ValueDecl::anchor() {}
 
 bool ValueDecl::isWeak() const {
-  for (const auto *I : attrs())
+  for (const auto *I : getMostRecentDecl()->attrs())
 if (isa(I) || isa(I))
   return true;
 

diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index f4314d0bd961..ab2b55c0762e 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -720,7 +720,7 @@ bool Decl::isWeakImported() const {
   if 

[PATCH] D82118: [clang][module] Improve incomplete-umbrella warning

2020-09-16 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai accepted this revision.
vsapsai added a comment.
This revision is now accepted and ready to land.

Looks good to me. I would wait a few days before committing in case other 
reviewers have comments but not too long as you can address extra comments 
post-commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82118

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


[PATCH] D87808: [DebugInfo] Fix bug in constructor homing where it would use ctor homing when a class only has copy/move constructors

2020-09-16 Thread Amy Huang via Phabricator via cfe-commits
akhuang created this revision.
akhuang added a reviewer: dblaikie.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
akhuang requested review of this revision.

Basically, the code was checking if there were no constructors at all,
but didn't check that there were any non copy/move constructors.

I _think_ the code now reflects what the logic for ctor homing was intended to 
be.
It would be nice to have more test cases but I guess I also don't have a great
understanding of what sorts of situations can happen with constructors.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87808

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-limited-ctor.cpp


Index: clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
===
--- clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
+++ clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -31,3 +31,16 @@
   F(int) {}
   int i;
 } TestF;
+
+// CHECK-DAG: ![[G:.*]] ={{.*}}!DICompositeType({{.*}}name: 
"G"{{.*}}DIFlagTypePassByValue
+// CHECK-DAG: !DICompositeType({{.*}}scope: ![[G]], {{.*}}DIFlagTypePassByValue
+// The inner struct only has copy/move constructors so it shouldn't be subject
+// to constructor homing.
+struct G {
+  G() : g_(0) {}
+  struct {
+int g_;
+  };
+} TestG;
+
+
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2289,14 +2289,15 @@
   isClassOrMethodDLLImport(RD))
 return false;
 
-  if (RD->ctors().empty())
-return false;
-
-  for (const auto *Ctor : RD->ctors())
+  bool hasCtor = false;
+  for (const auto *Ctor : RD->ctors()) {
 if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
   return false;
+if (!Ctor->isCopyOrMoveConstructor())
+  hasCtor = true;
+  }
 
-  return true;
+  return hasCtor;
 }
 
 static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,


Index: clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
===
--- clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
+++ clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -31,3 +31,16 @@
   F(int) {}
   int i;
 } TestF;
+
+// CHECK-DAG: ![[G:.*]] ={{.*}}!DICompositeType({{.*}}name: "G"{{.*}}DIFlagTypePassByValue
+// CHECK-DAG: !DICompositeType({{.*}}scope: ![[G]], {{.*}}DIFlagTypePassByValue
+// The inner struct only has copy/move constructors so it shouldn't be subject
+// to constructor homing.
+struct G {
+  G() : g_(0) {}
+  struct {
+int g_;
+  };
+} TestG;
+
+
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2289,14 +2289,15 @@
   isClassOrMethodDLLImport(RD))
 return false;
 
-  if (RD->ctors().empty())
-return false;
-
-  for (const auto *Ctor : RD->ctors())
+  bool hasCtor = false;
+  for (const auto *Ctor : RD->ctors()) {
 if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
   return false;
+if (!Ctor->isCopyOrMoveConstructor())
+  hasCtor = true;
+  }
 
-  return true;
+  return hasCtor;
 }
 
 static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87528: Enable '#pragma STDC FENV_ACCESS' in frontend cf. D69272 - Work in Progress

2020-09-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:2683
   }
+  if (const BinaryOperator *BE = dyn_cast(E)) {
+if (BE->getFPFeaturesInEffect(Info.Ctx.getLangOpts()).isFPConstrained()) {

`E` here is only intended for use in determining diagnostic locations, and 
isn't intended to necessarily be the expression being evaluated. Instead of 
assuming that this is the right expression to inspect, please either query the 
FP features in the caller and pass them into here or change this function to 
take a `const BinaryOperator*`.



Comment at: clang/lib/AST/ExprConstant.cpp:2685
+if (BE->getFPFeaturesInEffect(Info.Ctx.getLangOpts()).isFPConstrained()) {
+  Info.CCEDiag(E, diag::note_constexpr_float_arithmetic_strict);
+  return false;

This should be an `FFDiag` not a `CCEDiag` because we want to suppress all 
constant folding, not only treating the value as a core constant expression. 
Also we should check this before checking for a NaN result, because if both 
happen at once, this is the diagnostic we want to produce.



Comment at: clang/lib/AST/ExprConstant.cpp:13283-13286
+if (E->getFPFeaturesInEffect(Info.Ctx.getLangOpts()).isFPConstrained()) {
+  Info.CCEDiag(E, diag::note_constexpr_float_arithmetic_strict);
+  return false;
+}

Hm, does `fabs` depend on the floating-point environment? Is the concern the 
interaction with signaling NaNs?



Comment at: clang/lib/AST/ExprConstant.cpp:13372-13376
+  if (E->getFPFeaturesInEffect(Info.Ctx.getLangOpts()).isFPConstrained()) {
+// In C lang ref, footnote, cast may raise inexact exception.
+Info.CCEDiag(E, diag::note_constexpr_float_arithmetic_strict);
+return false;
+  }

Is it feasible to only reject cases that would actually be inexact, rather than 
disallowing all conversions to floating-point types? It would seem preferable 
to allow at least widening FP conversions and complex -> real, since they never 
depend on the FP environment (right?).



Comment at: clang/test/CodeGen/pragma-fenv_access.c:1
+// xxx: %clang_cc1 -ffp-exception-behavior=strict -frounding-math -triple 
%itanium_abi_triple -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -ffp-exception-behavior=strict -triple %itanium_abi_triple 
-emit-llvm %s -o - | FileCheck %s

Is this RUN line intentionally disabled?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87528

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


[PATCH] D87561: [Sema] List conversion validate character array

2020-09-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:4989
+if (ToType->isArrayType() && ToType->isCharType() &&
+isa(From->getInit(0))) {
   InitializedEntity Entity =

Mordante wrote:
> rsmith wrote:
> > This is too narrow a check in two ways: we should allow parenthesized 
> > string literals here, and we should allow `ObjCEncodeExpr`.
> Actually it seems the code isn't behaving properly at all. It seems the 
> conversion is done by
> https://github.com/llvm/llvm-project/blob/master/clang/lib/Sema/SemaOverload.cpp#L5174
> resulting in an array-to-pointer conversion instead of an identity conversion.
> 
> It can solve it by manually removing the decay like:
> ```
> if (const auto *DT = dyn_cast(ToType))
>   if (const auto *AT = S.Context.getAsArrayType(DT->getOriginalType()))
> if (S.IsStringInit(From->getInit(0), AT) {
>...
> ```
> This code works and results in an identity conversion. But it feels a bit odd 
> to manually peel away the array-to-pointer decay. Is this the best solution 
> or do you have a better suggestions?
>   
> 
I think this is a bug in your testcases. I'll comment below.



Comment at: clang/test/CXX/drs/dr14xx.cpp:411-414
+  void f(const char[4]);
+  void f(const wchar_t[4]);
+  void f(const char16_t[4]);
+  void f(const char32_t[4]);

These should presumably be references to arrays, rather than arrays, or the 
parameter type is as if you wrote (for example) `void f(const char *)`, which 
shouldn't get the special treatment here.

[over.ics.list]p4 mentions this in its footnote:

"Otherwise, if the parameter type is a character array [Footnote: Since there 
are no parameters of array type, this will only occur as the referenced type of 
a reference parameter.] and the initializer list has a single element that is 
an appropriately-typed string-literal (9.4.3), the implicit conversion sequence 
is the identity conversion."


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87561

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


[PATCH] D84414: [RISCV] Support Shadow Call Stack

2020-09-16 Thread Z. Zheng via Phabricator via cfe-commits
zzheng updated this revision to Diff 292378.
zzheng marked 2 inline comments as done.
zzheng added a comment.

Fixed comment and lint


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84414

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/test/CodeGen/shadowcallstack-attr.c
  clang/test/Driver/sanitizer-ld.c
  llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
  llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.h
  llvm/test/CodeGen/RISCV/shadowcallstack.ll

Index: llvm/test/CodeGen/RISCV/shadowcallstack.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/shadowcallstack.ll
@@ -0,0 +1,174 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv32 -mattr=+reserve-x18 -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s --check-prefix=RV32
+; RUN: llc -mtriple=riscv64 -mattr=+reserve-x18 -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s --check-prefix=RV64
+
+define void @f1() shadowcallstack {
+; RV32-LABEL: f1:
+; RV32:   # %bb.0:
+; RV32-NEXT:ret
+;
+; RV64-LABEL: f1:
+; RV64:   # %bb.0:
+; RV64-NEXT:ret
+  ret void
+}
+
+declare void @foo()
+
+define void @f2() shadowcallstack {
+; RV32-LABEL: f2:
+; RV32:   # %bb.0:
+; RV32-NEXT:tail foo
+;
+; RV64-LABEL: f2:
+; RV64:   # %bb.0:
+; RV64-NEXT:tail foo
+  tail call void @foo()
+  ret void
+}
+
+declare i32 @bar()
+
+define i32 @f3() shadowcallstack {
+; RV32-LABEL: f3:
+; RV32:   # %bb.0:
+; RV32-NEXT:sw ra, 0(s2)
+; RV32-NEXT:addi s2, s2, 4
+; RV32-NEXT:addi sp, sp, -16
+; RV32-NEXT:.cfi_def_cfa_offset 16
+; RV32-NEXT:sw ra, 12(sp)
+; RV32-NEXT:.cfi_offset ra, -4
+; RV32-NEXT:call bar
+; RV32-NEXT:lw ra, 12(sp)
+; RV32-NEXT:addi sp, sp, 16
+; RV32-NEXT:lw ra, -4(s2)
+; RV32-NEXT:addi s2, s2, -4
+; RV32-NEXT:ret
+;
+; RV64-LABEL: f3:
+; RV64:   # %bb.0:
+; RV64-NEXT:sd ra, 0(s2)
+; RV64-NEXT:addi s2, s2, 8
+; RV64-NEXT:addi sp, sp, -16
+; RV64-NEXT:.cfi_def_cfa_offset 16
+; RV64-NEXT:sd ra, 8(sp)
+; RV64-NEXT:.cfi_offset ra, -8
+; RV64-NEXT:call bar
+; RV64-NEXT:ld ra, 8(sp)
+; RV64-NEXT:addi sp, sp, 16
+; RV64-NEXT:ld ra, -8(s2)
+; RV64-NEXT:addi s2, s2, -8
+; RV64-NEXT:ret
+  %res = call i32 @bar()
+  %res1 = add i32 %res, 1
+  ret i32 %res
+}
+
+define i32 @f4() shadowcallstack {
+; RV32-LABEL: f4:
+; RV32:   # %bb.0:
+; RV32-NEXT:sw ra, 0(s2)
+; RV32-NEXT:addi s2, s2, 4
+; RV32-NEXT:addi sp, sp, -16
+; RV32-NEXT:.cfi_def_cfa_offset 16
+; RV32-NEXT:sw ra, 12(sp)
+; RV32-NEXT:sw s0, 8(sp)
+; RV32-NEXT:sw s1, 4(sp)
+; RV32-NEXT:sw s3, 0(sp)
+; RV32-NEXT:.cfi_offset ra, -4
+; RV32-NEXT:.cfi_offset s0, -8
+; RV32-NEXT:.cfi_offset s1, -12
+; RV32-NEXT:.cfi_offset s3, -16
+; RV32-NEXT:call bar
+; RV32-NEXT:mv s3, a0
+; RV32-NEXT:call bar
+; RV32-NEXT:mv s1, a0
+; RV32-NEXT:call bar
+; RV32-NEXT:mv s0, a0
+; RV32-NEXT:call bar
+; RV32-NEXT:add a1, s3, s1
+; RV32-NEXT:add a0, s0, a0
+; RV32-NEXT:add a0, a1, a0
+; RV32-NEXT:lw s3, 0(sp)
+; RV32-NEXT:lw s1, 4(sp)
+; RV32-NEXT:lw s0, 8(sp)
+; RV32-NEXT:lw ra, 12(sp)
+; RV32-NEXT:addi sp, sp, 16
+; RV32-NEXT:lw ra, -4(s2)
+; RV32-NEXT:addi s2, s2, -4
+; RV32-NEXT:ret
+;
+; RV64-LABEL: f4:
+; RV64:   # %bb.0:
+; RV64-NEXT:sd ra, 0(s2)
+; RV64-NEXT:addi s2, s2, 8
+; RV64-NEXT:addi sp, sp, -32
+; RV64-NEXT:.cfi_def_cfa_offset 32
+; RV64-NEXT:sd ra, 24(sp)
+; RV64-NEXT:sd s0, 16(sp)
+; RV64-NEXT:sd s1, 8(sp)
+; RV64-NEXT:sd s3, 0(sp)
+; RV64-NEXT:.cfi_offset ra, -8
+; RV64-NEXT:.cfi_offset s0, -16
+; RV64-NEXT:.cfi_offset s1, -24
+; RV64-NEXT:.cfi_offset s3, -32
+; RV64-NEXT:call bar
+; RV64-NEXT:mv s3, a0
+; RV64-NEXT:call bar
+; RV64-NEXT:mv s1, a0
+; RV64-NEXT:call bar
+; RV64-NEXT:mv s0, a0
+; RV64-NEXT:call bar
+; RV64-NEXT:add a1, s3, s1
+; RV64-NEXT:add a0, s0, a0
+; RV64-NEXT:addw a0, a1, a0
+; RV64-NEXT:ld s3, 0(sp)
+; RV64-NEXT:ld s1, 8(sp)
+; RV64-NEXT:ld s0, 16(sp)
+; RV64-NEXT:ld ra, 24(sp)
+; RV64-NEXT:addi sp, sp, 32
+; RV64-NEXT:ld ra, -8(s2)
+; RV64-NEXT:addi s2, s2, -8
+; RV64-NEXT:ret
+  %res1 = call i32 @bar()
+  %res2 = call i32 @bar()
+  %res3 = call i32 @bar()
+  %res4 = call i32 @bar()
+  %res12 = add i32 %res1, %res2
+  %res34 = add i32 %res3, %res4
+  %res1234 = add i32 %res12, %res34
+  ret i32 %res1234
+}
+
+define i32 @f5() shadowcallstack nounwind {
+; RV32-LABEL: f5:
+; RV32:   # %bb.0:
+; RV32-NEXT:sw ra, 0(s2)
+; RV32-NEXT:addi s2, s2, 4
+; RV32-NEXT:addi sp, sp, -16
+; RV32-NEXT:sw ra, 12(sp)
+; RV32-NEXT:call bar
+; 

[PATCH] D87349: [clang] adapt c++17 behavior for dependent decltype-specifiers

2020-09-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/test/CodeGenCXX/mangle.cpp:805
 
-  // CHECK-LABEL: define weak_odr void 
@_ZN6test341fIiEEvDTstDTplcvT__EcvS1__EEE
+  // CHECK-LABEL: define weak_odr void @_ZN6test341fIiEEvm
   template void f(decltype(sizeof(1)));

rsmith wrote:
> sammccall wrote:
> > sammccall wrote:
> > > GCC mangles this as `_ZN6test341fIiEEvDTstDTplcvT__EcvS1__EEE`, so we're 
> > > breaking compat here :-\
> > > 
> > > And in fact we're just incorrect. 
> > > https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling:
> > > 
> > > > If the operand expression of decltype is not instantiation-dependent 
> > > > then the resulting type is encoded directly.
> > > 
> > > Here, instantiation-dependent *is* explicitly defined as "type-dependent 
> > > or value-dependent or ...". And therefore these cases must not be 
> > > "encoded directly", including the motivating case (decltype(N) where N is 
> > > a typed constant whose initializer is value-dependent).
> > > 
> > > We could consider not two but *three* types of decltypetypes:
> > >  - decltype(type-dependent), which is sugar for a canonical 
> > > DependentDeclTypeType
> > >  - decltype(instantiation-but-not-type-dependent), which is still sugar 
> > > for a concrete canonical type (per C++17) but mangles using the expr (per 
> > > cxxabi)
> > >  - decltype(non-dependent), which is sugar for a concrete canonical type 
> > > and mangles directly
> > > 
> > > This only works if it's OK for mangling to depend on non-canonical type 
> > > details - I don't know whether this is the case. @rsmith - any hints here?
> > Hmm, my naive reading of the mangle code matches what I described.
> > 
> > The big comment in ItaniumMangle talks about related issues: 
> > https://github.com/llvm/llvm-project/blob/24238f09edb98b0f460aa41139874ae5d4e5cd8d/clang/lib/AST/ItaniumMangle.cpp#L2541-L2572
> > 
> > I don't really understand what's going on here, sorry.
> Looks like we need the single-step-desugaring loop below the big comment you 
> quoted to stop when it hits a `decltype` type. That's presumably where we 
> step from the instantiation-dependent-but-not-type-dependent `decltype` node 
> to its desugared type.
Also... the FIXME from that comment will apply here too. Given:
```
template void f(decltype(sizeof(T)), decltype(sizeof(T))) {}
template void f(unsigned long, unsigned long);
```
we currently (correctly, as far as I can see) use a substitution for the second 
parameter type, but with the change here, I don't think we will do so any more. 
We could fix that by deduplicating `DecltypeType`s when they're instantiation 
dependent but not dependent; that's what we do for `ConstantArrayType`'s size 
expression, for example. If we do that, we'll need to store the actual 
expression on the `DecltypeTypeLoc`, since we can't rely on the `DecltypeType` 
having the right expression any more (only an expression that's equivalent to 
it).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87349

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


[PATCH] D87349: [clang] adapt c++17 behavior for dependent decltype-specifiers

2020-09-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/test/CodeGenCXX/mangle-exprs.cpp:218
   template void a(decltype(noexcept(int(;
-  // CHECK: void @_ZN5test51aIiEEvDTnxcvT__EE(
+  // CHECK: void @_ZN5test51aIiEEvb
 }

As with the other case, the expression here is instantiation-dependent so 
should be mangled.



Comment at: clang/test/CodeGenCXX/mangle.cpp:805
 
-  // CHECK-LABEL: define weak_odr void 
@_ZN6test341fIiEEvDTstDTplcvT__EcvS1__EEE
+  // CHECK-LABEL: define weak_odr void @_ZN6test341fIiEEvm
   template void f(decltype(sizeof(1)));

sammccall wrote:
> sammccall wrote:
> > GCC mangles this as `_ZN6test341fIiEEvDTstDTplcvT__EcvS1__EEE`, so we're 
> > breaking compat here :-\
> > 
> > And in fact we're just incorrect. 
> > https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling:
> > 
> > > If the operand expression of decltype is not instantiation-dependent then 
> > > the resulting type is encoded directly.
> > 
> > Here, instantiation-dependent *is* explicitly defined as "type-dependent or 
> > value-dependent or ...". And therefore these cases must not be "encoded 
> > directly", including the motivating case (decltype(N) where N is a typed 
> > constant whose initializer is value-dependent).
> > 
> > We could consider not two but *three* types of decltypetypes:
> >  - decltype(type-dependent), which is sugar for a canonical 
> > DependentDeclTypeType
> >  - decltype(instantiation-but-not-type-dependent), which is still sugar for 
> > a concrete canonical type (per C++17) but mangles using the expr (per 
> > cxxabi)
> >  - decltype(non-dependent), which is sugar for a concrete canonical type 
> > and mangles directly
> > 
> > This only works if it's OK for mangling to depend on non-canonical type 
> > details - I don't know whether this is the case. @rsmith - any hints here?
> Hmm, my naive reading of the mangle code matches what I described.
> 
> The big comment in ItaniumMangle talks about related issues: 
> https://github.com/llvm/llvm-project/blob/24238f09edb98b0f460aa41139874ae5d4e5cd8d/clang/lib/AST/ItaniumMangle.cpp#L2541-L2572
> 
> I don't really understand what's going on here, sorry.
Looks like we need the single-step-desugaring loop below the big comment you 
quoted to stop when it hits a `decltype` type. That's presumably where we step 
from the instantiation-dependent-but-not-type-dependent `decltype` node to its 
desugared type.



Comment at: clang/test/SemaTemplate/dependent-expr.cpp:132
   }
-  template void f(); // expected-note {{instantiation of}}
+  template void f();
 

sammccall wrote:
> Took me a while to understand this, I think this is an improvement as we now 
> diagnose when we see the template rather than when we see the instantiation.
Right. We treat statement-expressions in a template as always being value- and 
instantiation-dependent, in part to match GCC and in part to avoid needing to 
define value- and instantiation-dependence for all statements and block-scope 
declarations, so decltype(statement expression) would have been a dependent 
type before.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87349

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


[PATCH] D87607: [clang][aarch64] Support implicit casts between GNU and SVE vectors

2020-09-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D87607

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


[PATCH] D84414: [RISCV] Support Shadow Call Stack

2020-09-16 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:38
+  // Do not save RA to the SCS if it's not saved to the regular stack,
+  // i.e. RA is not at risk of being to overwritten.
+  std::vector  = MF.getFrameInfo().getCalleeSavedInfo();





Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:60
+  // sw   ra, 0(s2)
+  // addi s2, s2, 4
+  BuildMI(MBB, MI, DL, TII->get(IsRV64 ? RISCV::SD : RISCV::SW))

zzheng wrote:
> jrtc27 wrote:
> > Is it intended that the shadow call stack grows *up* unlike the normal 
> > stack?
> No. Which direction the SCS grows on is trivial.
> 
> The memory area hosting SCS is independent of the regular stack; and it's 
> provided by the runtime.
> mmap/malloc returns the low address of newly mapped/allocated area. Making 
> the SCS growing down requires the runtime to return upper bound of the SCS. 
> On AArch64, the SCS grows up as well.
Ok. Wasn't saying there was anything wrong with it, was just something that 
jumped out at me. Having it grow up makes more sense (the only real advantage 
to the normal stack growing down these days is that doing aligned allocations 
is slightly cheaper).



Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:79-80
+
+  // Do not restore RA from SCS if it's not saved to regular stack, i.e.
+  // RA is not subject to overwritten.
+  std::vector  = MF.getFrameInfo().getCalleeSavedInfo();

jrtc27 wrote:
> No need to repeat ourselves.
This still holds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84414

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


[PATCH] D87804: [PowerPC][Power10] Implement Vector signed/unsigned __int128 overloads for the comparison builtins

2020-09-16 Thread Albion Fung via Phabricator via cfe-commits
Conanap created this revision.
Conanap added reviewers: PowerPC, saghir, nemanjai, hfinkel.
Conanap added projects: LLVM, PowerPC, clang.
Herald added a subscriber: kbarton.
Conanap requested review of this revision.

This patch implements Vector signed/unsigned __int128 overloads for the 
comparison builtins.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87804

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-p10vector.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/vec_cmpq.ll

Index: llvm/test/CodeGen/PowerPC/vec_cmpq.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/vec_cmpq.ll
@@ -0,0 +1,233 @@
+; Test the quadword comparison instructions that were added in POWER10.
+;
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN: -mcpu=pwr10 < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu \
+; RUN: -mcpu=pwr10 -mattr=-vsx < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN: -mcpu=pwr10 < %s | FileCheck %s
+define <1 x i128> @v1si128_cmp(<1 x i128> %x, <1 x i128> %y) nounwind readnone {
+   %cmp = icmp eq <1 x i128> %x, %y
+   %result = sext <1 x i1> %cmp to <1 x i128>
+   ret <1 x i128> %result
+; CHECK-LABEL: v1si128_cmp:
+; CHECK: vcmpequq 2, 2, 3
+}
+
+define <2 x i128> @v2si128_cmp(<2 x i128> %x, <2 x i128> %y) nounwind readnone {
+   %cmp = icmp eq <2 x i128> %x, %y
+   %result = sext <2 x i1> %cmp to <2 x i128>
+   ret <2 x i128> %result
+; CHECK-LABEL: v2si128_cmp
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+}
+
+define <4 x i128> @v4si128_cmp(<4 x i128> %x, <4 x i128> %y) nounwind readnone {
+   %cmp = icmp eq <4 x i128> %x, %y
+   %result = sext <4 x i1> %cmp to <4 x i128>
+   ret <4 x i128> %result
+; CHECK-LABEL: v4si128_cmp
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+}
+
+define <8 x i128> @v8si128_cmp(<8 x i128> %x, <8 x i128> %y) nounwind readnone {
+   %cmp = icmp eq <8 x i128> %x, %y
+   %result = sext <8 x i1> %cmp to <8 x i128>
+   ret <8 x i128> %result
+; CHECK-LABEL: v8si128_cmp
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+}
+
+define <16 x i128> @v16si128_cmp(<16 x i128> %x, <16 x i128> %y) nounwind readnone {
+   %cmp = icmp eq <16 x i128> %x, %y
+   %result = sext <16 x i1> %cmp to <16 x i128>
+   ret <16 x i128> %result
+; CHECK-LABEL: v16si128_cmp
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpequq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+}
+
+; Greater than signed
+define <1 x i128> @v1si128_cmp_gt(<1 x i128> %x, <1 x i128> %y) nounwind readnone {
+   %cmp = icmp sgt <1 x i128> %x, %y
+   %result = sext <1 x i1> %cmp to <1 x i128>
+   ret <1 x i128> %result
+; CHECK-LABEL: v1si128_cmp_gt
+; CHECK: vcmpgtsq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+}
+
+define <2 x i128> @v2si128_cmp_gt(<2 x i128> %x, <2 x i128> %y) nounwind readnone {
+   %cmp = icmp sgt <2 x i128> %x, %y
+   %result = sext <2 x i1> %cmp to <2 x i128>
+   ret <2 x i128> %result
+; CHECK-LABEL: v2si128_cmp_gt
+; CHECK: vcmpgtsq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+; CHECK: vcmpgtsq {{[0-9]+}}, {{[0-9]+}}, {{[0-9]+}}
+}
+
+define <4 x i128> @v4si128_cmp_gt(<4 x i128> %x, <4 x i128> %y) nounwind readnone {
+   %cmp = icmp sgt <4 x i128> %x, %y
+   %result = sext <4 x i1> 

[PATCH] D84414: [RISCV] Support Shadow Call Stack

2020-09-16 Thread Z. Zheng via Phabricator via cfe-commits
zzheng marked 2 inline comments as done.
zzheng added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:60
+  // sw   ra, 0(s2)
+  // addi s2, s2, 4
+  BuildMI(MBB, MI, DL, TII->get(IsRV64 ? RISCV::SD : RISCV::SW))

jrtc27 wrote:
> Is it intended that the shadow call stack grows *up* unlike the normal stack?
No. Which direction the SCS grows on is trivial.

The memory area hosting SCS is independent of the regular stack; and it's 
provided by the runtime.
mmap/malloc returns the low address of newly mapped/allocated area. Making the 
SCS growing down requires the runtime to return upper bound of the SCS. On 
AArch64, the SCS grows up as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84414

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


[PATCH] D84414: [RISCV] Support Shadow Call Stack

2020-09-16 Thread Z. Zheng via Phabricator via cfe-commits
zzheng updated this revision to Diff 292372.
zzheng marked 9 inline comments as done.
zzheng added a comment.

Addressed comments by @jrtc27


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84414

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/test/CodeGen/shadowcallstack-attr.c
  clang/test/Driver/sanitizer-ld.c
  llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
  llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.h
  llvm/test/CodeGen/RISCV/shadowcallstack.ll

Index: llvm/test/CodeGen/RISCV/shadowcallstack.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/shadowcallstack.ll
@@ -0,0 +1,174 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv32 -mattr=+reserve-x18 -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s --check-prefix=RV32
+; RUN: llc -mtriple=riscv64 -mattr=+reserve-x18 -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s --check-prefix=RV64
+
+define void @f1() shadowcallstack {
+; RV32-LABEL: f1:
+; RV32:   # %bb.0:
+; RV32-NEXT:ret
+;
+; RV64-LABEL: f1:
+; RV64:   # %bb.0:
+; RV64-NEXT:ret
+  ret void
+}
+
+declare void @foo()
+
+define void @f2() shadowcallstack {
+; RV32-LABEL: f2:
+; RV32:   # %bb.0:
+; RV32-NEXT:tail foo
+;
+; RV64-LABEL: f2:
+; RV64:   # %bb.0:
+; RV64-NEXT:tail foo
+  tail call void @foo()
+  ret void
+}
+
+declare i32 @bar()
+
+define i32 @f3() shadowcallstack {
+; RV32-LABEL: f3:
+; RV32:   # %bb.0:
+; RV32-NEXT:sw ra, 0(s2)
+; RV32-NEXT:addi s2, s2, 4
+; RV32-NEXT:addi sp, sp, -16
+; RV32-NEXT:.cfi_def_cfa_offset 16
+; RV32-NEXT:sw ra, 12(sp)
+; RV32-NEXT:.cfi_offset ra, -4
+; RV32-NEXT:call bar
+; RV32-NEXT:lw ra, 12(sp)
+; RV32-NEXT:addi sp, sp, 16
+; RV32-NEXT:lw ra, -4(s2)
+; RV32-NEXT:addi s2, s2, -4
+; RV32-NEXT:ret
+;
+; RV64-LABEL: f3:
+; RV64:   # %bb.0:
+; RV64-NEXT:sd ra, 0(s2)
+; RV64-NEXT:addi s2, s2, 8
+; RV64-NEXT:addi sp, sp, -16
+; RV64-NEXT:.cfi_def_cfa_offset 16
+; RV64-NEXT:sd ra, 8(sp)
+; RV64-NEXT:.cfi_offset ra, -8
+; RV64-NEXT:call bar
+; RV64-NEXT:ld ra, 8(sp)
+; RV64-NEXT:addi sp, sp, 16
+; RV64-NEXT:ld ra, -8(s2)
+; RV64-NEXT:addi s2, s2, -8
+; RV64-NEXT:ret
+  %res = call i32 @bar()
+  %res1 = add i32 %res, 1
+  ret i32 %res
+}
+
+define i32 @f4() shadowcallstack {
+; RV32-LABEL: f4:
+; RV32:   # %bb.0:
+; RV32-NEXT:sw ra, 0(s2)
+; RV32-NEXT:addi s2, s2, 4
+; RV32-NEXT:addi sp, sp, -16
+; RV32-NEXT:.cfi_def_cfa_offset 16
+; RV32-NEXT:sw ra, 12(sp)
+; RV32-NEXT:sw s0, 8(sp)
+; RV32-NEXT:sw s1, 4(sp)
+; RV32-NEXT:sw s3, 0(sp)
+; RV32-NEXT:.cfi_offset ra, -4
+; RV32-NEXT:.cfi_offset s0, -8
+; RV32-NEXT:.cfi_offset s1, -12
+; RV32-NEXT:.cfi_offset s3, -16
+; RV32-NEXT:call bar
+; RV32-NEXT:mv s3, a0
+; RV32-NEXT:call bar
+; RV32-NEXT:mv s1, a0
+; RV32-NEXT:call bar
+; RV32-NEXT:mv s0, a0
+; RV32-NEXT:call bar
+; RV32-NEXT:add a1, s3, s1
+; RV32-NEXT:add a0, s0, a0
+; RV32-NEXT:add a0, a1, a0
+; RV32-NEXT:lw s3, 0(sp)
+; RV32-NEXT:lw s1, 4(sp)
+; RV32-NEXT:lw s0, 8(sp)
+; RV32-NEXT:lw ra, 12(sp)
+; RV32-NEXT:addi sp, sp, 16
+; RV32-NEXT:lw ra, -4(s2)
+; RV32-NEXT:addi s2, s2, -4
+; RV32-NEXT:ret
+;
+; RV64-LABEL: f4:
+; RV64:   # %bb.0:
+; RV64-NEXT:sd ra, 0(s2)
+; RV64-NEXT:addi s2, s2, 8
+; RV64-NEXT:addi sp, sp, -32
+; RV64-NEXT:.cfi_def_cfa_offset 32
+; RV64-NEXT:sd ra, 24(sp)
+; RV64-NEXT:sd s0, 16(sp)
+; RV64-NEXT:sd s1, 8(sp)
+; RV64-NEXT:sd s3, 0(sp)
+; RV64-NEXT:.cfi_offset ra, -8
+; RV64-NEXT:.cfi_offset s0, -16
+; RV64-NEXT:.cfi_offset s1, -24
+; RV64-NEXT:.cfi_offset s3, -32
+; RV64-NEXT:call bar
+; RV64-NEXT:mv s3, a0
+; RV64-NEXT:call bar
+; RV64-NEXT:mv s1, a0
+; RV64-NEXT:call bar
+; RV64-NEXT:mv s0, a0
+; RV64-NEXT:call bar
+; RV64-NEXT:add a1, s3, s1
+; RV64-NEXT:add a0, s0, a0
+; RV64-NEXT:addw a0, a1, a0
+; RV64-NEXT:ld s3, 0(sp)
+; RV64-NEXT:ld s1, 8(sp)
+; RV64-NEXT:ld s0, 16(sp)
+; RV64-NEXT:ld ra, 24(sp)
+; RV64-NEXT:addi sp, sp, 32
+; RV64-NEXT:ld ra, -8(s2)
+; RV64-NEXT:addi s2, s2, -8
+; RV64-NEXT:ret
+  %res1 = call i32 @bar()
+  %res2 = call i32 @bar()
+  %res3 = call i32 @bar()
+  %res4 = call i32 @bar()
+  %res12 = add i32 %res1, %res2
+  %res34 = add i32 %res3, %res4
+  %res1234 = add i32 %res12, %res34
+  ret i32 %res1234
+}
+
+define i32 @f5() shadowcallstack nounwind {
+; RV32-LABEL: f5:
+; RV32:   # %bb.0:
+; RV32-NEXT:sw ra, 0(s2)
+; RV32-NEXT:addi s2, s2, 4
+; RV32-NEXT:addi sp, sp, -16
+; RV32-NEXT:sw ra, 12(sp)
+; RV32-NEXT:call 

[clang] f70baaf - [AArch64] Add -mmark-bti-property flag.

2020-09-16 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-09-17T01:18:36+02:00
New Revision: f70baaf71f62ba8623b3522345527271add74f6b

URL: 
https://github.com/llvm/llvm-project/commit/f70baaf71f62ba8623b3522345527271add74f6b
DIFF: 
https://github.com/llvm/llvm-project/commit/f70baaf71f62ba8623b3522345527271add74f6b.diff

LOG: [AArch64] Add -mmark-bti-property flag.

Writing the .note.gnu.property manually is error prone and hard to
maintain in the assembly files.
The -mmark-bti-property is for the assembler to emit the section with the
GNU_PROPERTY_AARCH64_FEATURE_1_BTI. To be used when C/C++ is compiled
with -mbranch-protection=bti.

This patch refactors the .note.gnu.property handling.

Reviewed By: chill, nickdesaulniers

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

Reland with test dependency on aarch64 target.

Added: 
clang/test/Driver/arm64-markbti.S

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5b39ea513b24..d7c2496b8a5d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2385,6 +2385,9 @@ def mfix_cortex_a53_835769 : Flag<["-"], 
"mfix-cortex-a53-835769">,
 def mno_fix_cortex_a53_835769 : Flag<["-"], "mno-fix-cortex-a53-835769">,
   Group,
   HelpText<"Don't workaround Cortex-A53 erratum 835769 (AArch64 only)">;
+def mmark_bti_property : Flag<["-"], "mmark-bti-property">,
+  Group,
+  HelpText<"Add .note.gnu.property with BTI to assembly files (AArch64 only)">;
 foreach i = {1-31} in
   def ffixed_x#i : Flag<["-"], "ffixed-x"#i>, Group,
 HelpText<"Reserve the x"#i#" register (AArch64/RISC-V only)">;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 51056960761d..e13ffe67af89 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7018,6 +7018,15 @@ void ClangAs::ConstructJob(Compilation , const 
JobAction ,
 }
 break;
 
+  case llvm::Triple::aarch64:
+  case llvm::Triple::aarch64_32:
+  case llvm::Triple::aarch64_be:
+if (Args.hasArg(options::OPT_mmark_bti_property)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-aarch64-mark-bti-property");
+}
+break;
+
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
 AddRISCVTargetArgs(Args, CmdArgs);

diff  --git a/clang/test/Driver/arm64-markbti.S 
b/clang/test/Driver/arm64-markbti.S
new file mode 100644
index ..8eeed74810d2
--- /dev/null
+++ b/clang/test/Driver/arm64-markbti.S
@@ -0,0 +1,26 @@
+// REQUIRES: aarch64-registered-target
+
+// When -mmark-bti-property is passed the generated file object gets BTI 
marking.
+// RUN: %clang -target arm64-linux-none -mmark-bti-property -c -o - %s | 
llvm-readobj -n - | FileCheck -check-prefix=CHECK  -check-prefix=CHECK_GEN %s
+// RUN: %clang -target arm64-linux-none -DNOTE_PRESENT -c %s -o - | 
llvm-readobj -n - | FileCheck -check-prefix=CHECK  -check-prefix=CHECK_PRESET %s
+// RUN: %clang -target arm64-linux-none -mmark-bti-property -DNOTE_PRESENT -c 
%s -o - | llvm-readobj -n - | FileCheck -check-prefix=CHECK  
-check-prefix=CHECK_PRESET %s
+// RUN: %clang -target arm64-linux-none -mmark-bti-property -DNOTE_PRESENT -c 
%s -o - 2>&1 |  FileCheck -check-prefix=CHECK_WARNING %s
+//
+// CHECK_WARNING: The .note.gnu.property is not emitted because it is already 
present.
+// CHECK: Name: .note.gnu.property
+// CHECK: Type: NT_GNU_PROPERTY_TYPE_0
+// CHECK_GEN: aarch64 feature: BTI
+// CHECK_PRESET: aarch64 feature: BTI, PAC
+
+#ifdef NOTE_PRESENT
+  .section .note.gnu.property, "a";
+  .balign 8;
+  .long 4;
+  .long 0x10;
+  .long 0x5
+  .asciz "GNU"
+  .long 0xc000
+  .long 4
+  .long 3
+  .long 0
+#endif

diff  --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp 
b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 8cbd60d74970..30ac7f4c0d2e 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -223,26 +223,9 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module ) {
 return;
 
   // Emit a .note.gnu.property section with the flags.
-  MCSection *Cur = OutStreamer->getCurrentSectionOnly();
-  MCSection *Nt = MMI->getContext().getELFSection(
-  ".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
-  OutStreamer->SwitchSection(Nt);
-
-  // Emit the note header.
-  emitAlignment(Align(8));
-  OutStreamer->emitInt32(4); // data size for "GNU\0"
-  OutStreamer->emitInt32(4 * 4); // Elf_Prop size
-  OutStreamer->emitInt32(ELF::NT_GNU_PROPERTY_TYPE_0);
-  OutStreamer->emitBytes(StringRef("GNU", 4)); // note name
-
-  // Emit 

[PATCH] D87534: Sema: introduce `__attribute__((__swift_name__))`

2020-09-16 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 292369.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87534

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaObjC/attr-swift_name.m

Index: clang/test/SemaObjC/attr-swift_name.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_name.m
@@ -0,0 +1,177 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc %s
+
+#define SWIFT_NAME(name) __attribute__((__swift_name__(name)))
+
+typedef struct {
+  float x, y, z;
+} Point3D;
+
+__attribute__((__swift_name__("PType")))
+@protocol P
+@end
+
+__attribute__((__swift_name__("IClass")))
+@interface I
+- (instancetype)init SWIFT_NAME("init()");
+- (instancetype)initWithValue:(int)value SWIFT_NAME("iWithValue(_:)");
+
++ (void)refresh SWIFT_NAME("refresh()");
+
+- (instancetype)i SWIFT_NAME("i()");
+
+- (I *)iWithValue:(int)value SWIFT_NAME("i(value:)");
+- (I *)iWithValue:(int)value value:(int)value2 SWIFT_NAME("i(value:extra:)");
+- (I *)iWithValueConvertingValue:(int)value value:(int)value2 SWIFT_NAME("i(_:extra:)");
+
++ (I *)iWithOtheValue:(int)value SWIFT_NAME("init");
+// expected-warning@-1 {{parameter of '__swift_name__' attribute must be a Swift function name string}}
+
++ (I *)iWithAnotherValue:(int)value SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (I *)iWithYetAnotherValue:(int)value SWIFT_NAME("i(value:extra:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 1; got 2}}
+
++ (I *)iAndReturnErrorCode:(int *)errorCode SWIFT_NAME("i()"); // no-warning
++ (I *)iWithValue:(int)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(value:)"); // no-warning
+
++ (I *)iFromErrorCode:(const int *)errorCode SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (I *)iWithPointerA:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i()"); // no-warning
++ (I *)iWithPointerB:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(pointer:)"); // no-warning
++ (I *)iWithPointerC:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(pointer:errorCode:)"); // no-warning
+
++ (I *)iWithOtherI:(I *)other SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (instancetype)specialI SWIFT_NAME("init(options:)");
++ (instancetype)specialJ SWIFT_NAME("init(options:extra:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 2)}}
++ (instancetype)specialK SWIFT_NAME("init(_:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 1)}}
++ (instancetype)specialL SWIFT_NAME("i(options:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 1)}}
+
++ (instancetype)trailingParen SWIFT_NAME("foo(");
+// expected-warning@-1 {{parameter of '__swift_name__' attribute must be a Swift function name string}}
++ (instancetype)trailingColon SWIFT_NAME("foo:");
+// expected-warning@-1 {{parameter of '__swift_name__' attribute must be a Swift function name string}}
++ (instancetype)initialIgnore:(int)value SWIFT_NAME("_(value:)");
+// expected-warning@-1 {{'__swift_name__' attribute has invalid identifier for base name}}
++ (instancetype)middleOmitted:(int)value SWIFT_NAME("i(:)");
+// expected-warning@-1 {{'__swift_name__' attribute has invalid identifier for parameter name}}
+
+@property(strong) id someProp SWIFT_NAME("prop");
+@end
+
+enum SWIFT_NAME("E") E {
+  value1,
+  value2,
+  value3 SWIFT_NAME("three"),
+  value4 SWIFT_NAME("four()"), // expected-warning {{'__swift_name__' attribute has invalid identifier for base name}}
+};
+
+struct SWIFT_NAME("TStruct") SStruct {
+  int i, j, k SWIFT_NAME("kay");
+};
+
+int i SWIFT_NAME("g_i");
+
+void f0(int i) SWIFT_NAME("f_0");
+// expected-warning@-1 {{parameter of '__swift_name__' attribute must be a Swift function name string}}
+
+void f1(int i) SWIFT_NAME("f_1()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
+void f2(int i) SWIFT_NAME("f_2(a:b:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 1; got 2)}}
+
+void f3(int x, int y) SWIFT_NAME("fWithX(_:y:)");
+void f4(int x, int *error) SWIFT_NAME("fWithX(_:)");
+
+typedef int int_t SWIFT_NAME("IntType");
+
+struct Point3D createPoint3D(float x, float y, float z) SWIFT_NAME("Point3D.init(x:y:z:)");
+struct Point3D rotatePoint3D(Point3D point, float radians) 

[clang] 60e244f - Revert "[AArch64] Add -mmark-bti-property flag."

2020-09-16 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-09-17T01:17:23+02:00
New Revision: 60e244f82c1f97c1b7d65c06d2b0b4f634f8d696

URL: 
https://github.com/llvm/llvm-project/commit/60e244f82c1f97c1b7d65c06d2b0b4f634f8d696
DIFF: 
https://github.com/llvm/llvm-project/commit/60e244f82c1f97c1b7d65c06d2b0b4f634f8d696.diff

LOG: Revert "[AArch64] Add -mmark-bti-property flag."

This reverts commit 95e43f84b7b9c61011aece7583c0367297dd67d8.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h

Removed: 
clang/test/Driver/arm64-markbti.S



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d7c2496b8a5d..5b39ea513b24 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2385,9 +2385,6 @@ def mfix_cortex_a53_835769 : Flag<["-"], 
"mfix-cortex-a53-835769">,
 def mno_fix_cortex_a53_835769 : Flag<["-"], "mno-fix-cortex-a53-835769">,
   Group,
   HelpText<"Don't workaround Cortex-A53 erratum 835769 (AArch64 only)">;
-def mmark_bti_property : Flag<["-"], "mmark-bti-property">,
-  Group,
-  HelpText<"Add .note.gnu.property with BTI to assembly files (AArch64 only)">;
 foreach i = {1-31} in
   def ffixed_x#i : Flag<["-"], "ffixed-x"#i>, Group,
 HelpText<"Reserve the x"#i#" register (AArch64/RISC-V only)">;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index e13ffe67af89..51056960761d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7018,15 +7018,6 @@ void ClangAs::ConstructJob(Compilation , const 
JobAction ,
 }
 break;
 
-  case llvm::Triple::aarch64:
-  case llvm::Triple::aarch64_32:
-  case llvm::Triple::aarch64_be:
-if (Args.hasArg(options::OPT_mmark_bti_property)) {
-  CmdArgs.push_back("-mllvm");
-  CmdArgs.push_back("-aarch64-mark-bti-property");
-}
-break;
-
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
 AddRISCVTargetArgs(Args, CmdArgs);

diff  --git a/clang/test/Driver/arm64-markbti.S 
b/clang/test/Driver/arm64-markbti.S
deleted file mode 100644
index 68c81d31afa3..
--- a/clang/test/Driver/arm64-markbti.S
+++ /dev/null
@@ -1,24 +0,0 @@
-// When -mmark-bti-property is passed the generated file object gets BTI 
marking.
-// RUN: %clang -target arm64-linux-none -mmark-bti-property -c -o - %s | 
llvm-readobj -n - | FileCheck -check-prefix=CHECK  -check-prefix=CHECK_GEN %s
-// RUN: %clang -target arm64-linux-none -DNOTE_PRESENT -c %s -o - | 
llvm-readobj -n - | FileCheck -check-prefix=CHECK  -check-prefix=CHECK_PRESET %s
-// RUN: %clang -target arm64-linux-none -mmark-bti-property -DNOTE_PRESENT -c 
%s -o - | llvm-readobj -n - | FileCheck -check-prefix=CHECK  
-check-prefix=CHECK_PRESET %s
-// RUN: %clang -target arm64-linux-none -mmark-bti-property -DNOTE_PRESENT -c 
%s -o - 2>&1 |  FileCheck -check-prefix=CHECK_WARNING %s
-//
-// CHECK_WARNING: The .note.gnu.property is not emitted because it is already 
present.
-// CHECK: Name: .note.gnu.property
-// CHECK: Type: NT_GNU_PROPERTY_TYPE_0
-// CHECK_GEN: aarch64 feature: BTI
-// CHECK_PRESET: aarch64 feature: BTI, PAC
-
-#ifdef NOTE_PRESENT
-  .section .note.gnu.property, "a";
-  .balign 8;
-  .long 4;
-  .long 0x10;
-  .long 0x5
-  .asciz "GNU"
-  .long 0xc000
-  .long 4
-  .long 3
-  .long 0
-#endif

diff  --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp 
b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 30ac7f4c0d2e..8cbd60d74970 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -223,9 +223,26 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module ) {
 return;
 
   // Emit a .note.gnu.property section with the flags.
-  if (auto *TS = static_cast(
-  OutStreamer->getTargetStreamer()))
-TS->emitNoteSection(Flags);
+  MCSection *Cur = OutStreamer->getCurrentSectionOnly();
+  MCSection *Nt = MMI->getContext().getELFSection(
+  ".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
+  OutStreamer->SwitchSection(Nt);
+
+  // Emit the note header.
+  emitAlignment(Align(8));
+  OutStreamer->emitInt32(4); // data size for "GNU\0"
+  OutStreamer->emitInt32(4 * 4); // Elf_Prop size
+  OutStreamer->emitInt32(ELF::NT_GNU_PROPERTY_TYPE_0);
+  OutStreamer->emitBytes(StringRef("GNU", 4)); // note name
+
+  // Emit the PAC/BTI properties.
+  OutStreamer->emitInt32(ELF::GNU_PROPERTY_AARCH64_FEATURE_1_AND);
+  OutStreamer->emitInt32(4); // data size
+  OutStreamer->emitInt32(Flags); // data
+  OutStreamer->emitInt32(0); // pad
+
+  OutStreamer->endSection(Nt);
+  OutStreamer->SwitchSection(Cur);
 }
 
 void 

[PATCH] D87534: Sema: introduce `__attribute__((__swift_name__))`

2020-09-16 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 292368.
compnerd added a comment.

Change diagnostics for conflicting `swift_name`, add a test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87534

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaObjC/attr-swift_name.m

Index: clang/test/SemaObjC/attr-swift_name.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_name.m
@@ -0,0 +1,170 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc %s
+
+#define SWIFT_NAME(name) __attribute__((__swift_name__(name)))
+
+typedef struct {
+  float x, y, z;
+} Point3D;
+
+__attribute__((__swift_name__("PType")))
+@protocol P
+@end
+
+__attribute__((__swift_name__("IClass")))
+@interface I
+- (instancetype)init SWIFT_NAME("init()");
+- (instancetype)initWithValue:(int)value SWIFT_NAME("iWithValue(_:)");
+
++ (void)refresh SWIFT_NAME("refresh()");
+
+- (instancetype)i SWIFT_NAME("i()");
+
+- (I *)iWithValue:(int)value SWIFT_NAME("i(value:)");
+- (I *)iWithValue:(int)value value:(int)value2 SWIFT_NAME("i(value:extra:)");
+- (I *)iWithValueConvertingValue:(int)value value:(int)value2 SWIFT_NAME("i(_:extra:)");
+
++ (I *)iWithOtheValue:(int)value SWIFT_NAME("init");
+// expected-warning@-1 {{parameter of '__swift_name__' attribute must be a Swift function name string}}
+
++ (I *)iWithAnotherValue:(int)value SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (I *)iWithYetAnotherValue:(int)value SWIFT_NAME("i(value:extra:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 1; got 2}}
+
++ (I *)iAndReturnErrorCode:(int *)errorCode SWIFT_NAME("i()"); // no-warning
++ (I *)iWithValue:(int)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(value:)"); // no-warning
+
++ (I *)iFromErrorCode:(const int *)errorCode SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (I *)iWithPointerA:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i()"); // no-warning
++ (I *)iWithPointerB:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(pointer:)"); // no-warning
++ (I *)iWithPointerC:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(pointer:errorCode:)"); // no-warning
+
++ (I *)iWithOtherI:(I *)other SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (instancetype)specialI SWIFT_NAME("init(options:)");
++ (instancetype)specialJ SWIFT_NAME("init(options:extra:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 2)}}
++ (instancetype)specialK SWIFT_NAME("init(_:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 1)}}
++ (instancetype)specialL SWIFT_NAME("i(options:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 1)}}
+
++ (instancetype)trailingParen SWIFT_NAME("foo(");
+// expected-warning@-1 {{parameter of '__swift_name__' attribute must be a Swift function name string}}
++ (instancetype)trailingColon SWIFT_NAME("foo:");
+// expected-warning@-1 {{parameter of '__swift_name__' attribute must be a Swift function name string}}
++ (instancetype)initialIgnore:(int)value SWIFT_NAME("_(value:)");
+// expected-warning@-1 {{'__swift_name__' attribute has invalid identifier for base name}}
++ (instancetype)middleOmitted:(int)value SWIFT_NAME("i(:)");
+// expected-warning@-1 {{'__swift_name__' attribute has invalid identifier for parameter name}}
+
+@property(strong) id someProp SWIFT_NAME("prop");
+@end
+
+enum SWIFT_NAME("E") E {
+  value1,
+  value2,
+  value3 SWIFT_NAME("three"),
+  value4 SWIFT_NAME("four()"), // expected-warning {{'__swift_name__' attribute has invalid identifier for base name}}
+};
+
+struct SWIFT_NAME("TStruct") SStruct {
+  int i, j, k SWIFT_NAME("kay");
+};
+
+int i SWIFT_NAME("g_i");
+
+void f0(int i) SWIFT_NAME("f_0");
+// expected-warning@-1 {{parameter of '__swift_name__' attribute must be a Swift function name string}}
+
+void f1(int i) SWIFT_NAME("f_1()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
+void f2(int i) SWIFT_NAME("f_2(a:b:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 1; got 2)}}
+
+void f3(int x, int y) SWIFT_NAME("fWithX(_:y:)");
+void f4(int x, int *error) SWIFT_NAME("fWithX(_:)");
+
+typedef int int_t SWIFT_NAME("IntType");
+
+struct Point3D createPoint3D(float x, float y, float z) 

[PATCH] D87629: Thread safety analysis: Improve documentation for ASSERT_CAPABILITY

2020-09-16 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D87629#2275639 , @ryanofsky wrote:

> The mistakes about exceptions came from me taking "(no return)" in the 
> previous documentation too literally thinking it was referring to 
> https://en.cppreference.com/w/cpp/language/attributes/noreturn.

The key here is the word "assumed". We treat the function as if it looks like 
this:

  [[noreturn]] void error();
  
  void assertHeld(Mutex ) ASSERT_CAPABILITY(mu) {
if (!mu.isLocked())
  error();
  }

So we assume that the function doesn't return if the mutex isn't held. (For the 
analysis, not for generating code.)

But the idea—as usual with assertions—is that they just verify assumptions that 
should hold anyway, so they are not integral part of the code and can be 
dropped , like the standard assert 
 when `NDEBUG` is defined. And 
that's what we might clarify here. The right model is that this function 
converts dynamically held capabilities into statically held capabilities. It 
doesn't have to actually do anything, instead it's a marker for a promise: the 
programmer can't prove that the capability is held but promises it. And in some 
build profiles we might check that the promise is satisfied, but we don't 
guarantee that we do.

Which obviously means that an `ASSERT_CAPABILITY` function should only be used 
as a last resort, and it makes some sense to me that some bitcoin contributors 
want to have the standard assertion annotated with `EXCLUSIVE_LOCKS_REQUIRED` 
so that people don't accidentally defeat the Analysis by adding assertions. I 
can't really speak as to whether that's a valid concern, but there is certainly 
no misunderstanding.

> Re: "I got the impression that you want both runtime checks and compile-time 
> checks in parallel". Personally I only want the compile checks, and would 
> like to drop all the runtime checks except in handful of places where compile 
> time checks don't work.

Indeed, now that I've re-read the discussion I see that the argument about 
guarding against compiler bugs 
 wasn't 
yours. I guess you have to discuss in the bitcoin community how much to trust 
the compiler, although you might just end up with Ken Thompson's “Reflections 
on Trusting Trust” 
. In my 
view you're probably better off testing with ThreadSanitizer 
 than adding runtime checks 
where the Analysis says the lock is held, but I do see the point 
 of 
nudging people to add annotations when they have an assertion. No 
misunderstanding there as well.

> ASSERT_CAPABILITY does a great job in these places so I don't want people to 
> be scared off from using it unduly because of documentation!

If you're referring to @vasild's comment 
 I hope 
that we cleared this up. The attribute is meant to mirror the behavior of the 
standard `assert` macro.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87629

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


[PATCH] D85685: Support dwarf fission for wasm object files

2020-09-16 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 accepted this revision.
sbc100 added a comment.

I don't really grok the `TargetFrameLowering::DwarfFrameBase` part but 
everything else LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85685

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


[PATCH] D81930: [AArch64] Add -mmark-bti-property flag.

2020-09-16 Thread Daniel Kiss via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG95e43f84b7b9: [AArch64] Add -mmark-bti-property flag. 
(authored by danielkiss).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81930

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/arm64-markbti.S
  llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h

Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h
===
--- llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h
+++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h
@@ -33,6 +33,9 @@
   /// Emit contents of constant pool for the current section.
   void emitCurrentConstantPool();
 
+  /// Callback used to implement the .note.gnu.property section.
+  void emitNoteSection(unsigned Flags);
+
   /// Callback used to implement the .inst directive.
   virtual void emitInst(uint32_t Inst);
 
Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp
===
--- llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp
+++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp
@@ -11,12 +11,23 @@
 //===--===//
 
 #include "AArch64TargetStreamer.h"
+#include "AArch64MCAsmInfo.h"
+#include "AArch64Subtarget.h"
+#include "llvm/BinaryFormat/ELF.h"
 #include "llvm/MC/ConstantPools.h"
+#include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCSection.h"
+#include "llvm/MC/MCSectionELF.h"
 #include "llvm/MC/MCSubtargetInfo.h"
+#include "llvm/Support/CommandLine.h"
 
 using namespace llvm;
 
+static cl::opt MarkBTIProperty(
+"aarch64-mark-bti-property", cl::Hidden,
+cl::desc("Add .note.gnu.property with BTI to assembly files"),
+cl::init(false));
+
 //
 // AArch64TargetStreamer Implemenation
 //
@@ -37,8 +48,50 @@
   ConstantPools->emitForCurrentSection(Streamer);
 }
 
-// finish() - write out any non-empty assembler constant pools.
-void AArch64TargetStreamer::finish() { ConstantPools->emitAll(Streamer); }
+// finish() - write out any non-empty assembler constant pools and
+//   write out note.gnu.properties if need.
+void AArch64TargetStreamer::finish() {
+  ConstantPools->emitAll(Streamer);
+
+  if (MarkBTIProperty)
+emitNoteSection(ELF::GNU_PROPERTY_AARCH64_FEATURE_1_BTI);
+}
+
+void AArch64TargetStreamer::emitNoteSection(unsigned Flags) {
+  if (Flags == 0)
+return;
+
+  MCStreamer  = getStreamer();
+  MCContext  = OutStreamer.getContext();
+  // Emit a .note.gnu.property section with the flags.
+  MCSectionELF *Nt = Context.getELFSection(".note.gnu.property", ELF::SHT_NOTE,
+   ELF::SHF_ALLOC);
+  if (Nt->isRegistered()) {
+SMLoc Loc;
+Context.reportWarning(
+Loc,
+"The .note.gnu.property is not emitted because it is already present.");
+return;
+  }
+  MCSection *Cur = OutStreamer.getCurrentSectionOnly();
+  OutStreamer.SwitchSection(Nt);
+
+  // Emit the note header.
+  OutStreamer.emitValueToAlignment(Align(8).value());
+  OutStreamer.emitIntValue(4, 4); // data size for "GNU\0"
+  OutStreamer.emitIntValue(4 * 4, 4); // Elf_Prop size
+  OutStreamer.emitIntValue(ELF::NT_GNU_PROPERTY_TYPE_0, 4);
+  OutStreamer.emitBytes(StringRef("GNU", 4)); // note name
+
+  // Emit the PAC/BTI properties.
+  OutStreamer.emitIntValue(ELF::GNU_PROPERTY_AARCH64_FEATURE_1_AND, 4);
+  OutStreamer.emitIntValue(4, 4); // data size
+  OutStreamer.emitIntValue(Flags, 4); // data
+  OutStreamer.emitIntValue(0, 4); // pad
+
+  OutStreamer.endSection(Nt);
+  OutStreamer.SwitchSection(Cur);
+}
 
 void AArch64TargetStreamer::emitInst(uint32_t Inst) {
   char Buffer[4];
Index: llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
===
--- llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -223,26 +223,9 @@
 return;
 
   // Emit a .note.gnu.property section with the flags.
-  MCSection *Cur = OutStreamer->getCurrentSectionOnly();
-  MCSection *Nt = MMI->getContext().getELFSection(
-  ".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
-  OutStreamer->SwitchSection(Nt);
-
-  // Emit the note header.
-  emitAlignment(Align(8));
-  OutStreamer->emitInt32(4); // data size for "GNU\0"
-  OutStreamer->emitInt32(4 * 4); // Elf_Prop size
-  OutStreamer->emitInt32(ELF::NT_GNU_PROPERTY_TYPE_0);
-  OutStreamer->emitBytes(StringRef("GNU", 4)); // note name
-
-  // Emit the PAC/BTI properties.
-  OutStreamer->emitInt32(ELF::GNU_PROPERTY_AARCH64_FEATURE_1_AND);
-  OutStreamer->emitInt32(4); // data 

[clang] 95e43f8 - [AArch64] Add -mmark-bti-property flag.

2020-09-16 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-09-17T00:24:14+02:00
New Revision: 95e43f84b7b9c61011aece7583c0367297dd67d8

URL: 
https://github.com/llvm/llvm-project/commit/95e43f84b7b9c61011aece7583c0367297dd67d8
DIFF: 
https://github.com/llvm/llvm-project/commit/95e43f84b7b9c61011aece7583c0367297dd67d8.diff

LOG: [AArch64] Add -mmark-bti-property flag.

Writing the .note.gnu.property manually is error prone and hard to
maintain in the assembly files.
The -mmark-bti-property is for the assembler to emit the section with the
GNU_PROPERTY_AARCH64_FEATURE_1_BTI. To be used when C/C++ is compiled
with -mbranch-protection=bti.

This patch refactors the .note.gnu.property handling.

Reviewed By: chill, nickdesaulniers

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

Added: 
clang/test/Driver/arm64-markbti.S

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64TargetStreamer.h

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5b39ea513b24..d7c2496b8a5d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2385,6 +2385,9 @@ def mfix_cortex_a53_835769 : Flag<["-"], 
"mfix-cortex-a53-835769">,
 def mno_fix_cortex_a53_835769 : Flag<["-"], "mno-fix-cortex-a53-835769">,
   Group,
   HelpText<"Don't workaround Cortex-A53 erratum 835769 (AArch64 only)">;
+def mmark_bti_property : Flag<["-"], "mmark-bti-property">,
+  Group,
+  HelpText<"Add .note.gnu.property with BTI to assembly files (AArch64 only)">;
 foreach i = {1-31} in
   def ffixed_x#i : Flag<["-"], "ffixed-x"#i>, Group,
 HelpText<"Reserve the x"#i#" register (AArch64/RISC-V only)">;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 51056960761d..e13ffe67af89 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7018,6 +7018,15 @@ void ClangAs::ConstructJob(Compilation , const 
JobAction ,
 }
 break;
 
+  case llvm::Triple::aarch64:
+  case llvm::Triple::aarch64_32:
+  case llvm::Triple::aarch64_be:
+if (Args.hasArg(options::OPT_mmark_bti_property)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-aarch64-mark-bti-property");
+}
+break;
+
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
 AddRISCVTargetArgs(Args, CmdArgs);

diff  --git a/clang/test/Driver/arm64-markbti.S 
b/clang/test/Driver/arm64-markbti.S
new file mode 100644
index ..68c81d31afa3
--- /dev/null
+++ b/clang/test/Driver/arm64-markbti.S
@@ -0,0 +1,24 @@
+// When -mmark-bti-property is passed the generated file object gets BTI 
marking.
+// RUN: %clang -target arm64-linux-none -mmark-bti-property -c -o - %s | 
llvm-readobj -n - | FileCheck -check-prefix=CHECK  -check-prefix=CHECK_GEN %s
+// RUN: %clang -target arm64-linux-none -DNOTE_PRESENT -c %s -o - | 
llvm-readobj -n - | FileCheck -check-prefix=CHECK  -check-prefix=CHECK_PRESET %s
+// RUN: %clang -target arm64-linux-none -mmark-bti-property -DNOTE_PRESENT -c 
%s -o - | llvm-readobj -n - | FileCheck -check-prefix=CHECK  
-check-prefix=CHECK_PRESET %s
+// RUN: %clang -target arm64-linux-none -mmark-bti-property -DNOTE_PRESENT -c 
%s -o - 2>&1 |  FileCheck -check-prefix=CHECK_WARNING %s
+//
+// CHECK_WARNING: The .note.gnu.property is not emitted because it is already 
present.
+// CHECK: Name: .note.gnu.property
+// CHECK: Type: NT_GNU_PROPERTY_TYPE_0
+// CHECK_GEN: aarch64 feature: BTI
+// CHECK_PRESET: aarch64 feature: BTI, PAC
+
+#ifdef NOTE_PRESENT
+  .section .note.gnu.property, "a";
+  .balign 8;
+  .long 4;
+  .long 0x10;
+  .long 0x5
+  .asciz "GNU"
+  .long 0xc000
+  .long 4
+  .long 3
+  .long 0
+#endif

diff  --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp 
b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 8cbd60d74970..30ac7f4c0d2e 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -223,26 +223,9 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module ) {
 return;
 
   // Emit a .note.gnu.property section with the flags.
-  MCSection *Cur = OutStreamer->getCurrentSectionOnly();
-  MCSection *Nt = MMI->getContext().getELFSection(
-  ".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
-  OutStreamer->SwitchSection(Nt);
-
-  // Emit the note header.
-  emitAlignment(Align(8));
-  OutStreamer->emitInt32(4); // data size for "GNU\0"
-  OutStreamer->emitInt32(4 * 4); // Elf_Prop size
-  OutStreamer->emitInt32(ELF::NT_GNU_PROPERTY_TYPE_0);
-  OutStreamer->emitBytes(StringRef("GNU", 4)); // note name
-
-  // Emit the PAC/BTI properties.
-  OutStreamer->emitInt32(ELF::GNU_PROPERTY_AARCH64_FEATURE_1_AND);

[PATCH] D86660: Modifying ImportDeclContext(...) to ensure that we also handle the case when the FieldDecl is an ArrayType whose ElementType is a RecordDecl

2020-09-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.
Herald added a reviewer: JDevlieghere.

We are going to move forward with this approach (after dealing with the 
multi-dimensional array case) temporarily. We are seeing crash bugs from this 
from users and we want to fix it while we explore the solution space more.

This PR has brought up a lot of great questions and I have spent some time 
looking various approaches to fixing this and while I believe I have a better 
understanding of the underlying problem there are some pieces I still need to 
understand better. Mainly how other `ExternalSource` implementations work. Do 
they ever end up in the situation where they have a record that is defined but 
not complete.

My impression at this point is that because expression parsing is not really 
generating well-formed translation units, we are relying on clang calling back 
into us to do name look-ups and then during that process LLDB and the 
ASTImporter needs to be clever enough to figure out when a record should be 
completed. Expression paring can end up in non-trivial cases where we have not 
seen the complete type yet (because we are being lazy) but we need it and we 
have not figured that out.


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

https://reviews.llvm.org/D86660

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


[PATCH] D87615: [X86] Fix stack alignment on 32-bit Solaris/x86

2020-09-16 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg accepted this revision.
joerg added a comment.
This revision is now accepted and ready to land.

I'm still curious about the source of the vptr diff, but that's a minor 
question, otherwise. LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87615

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


[PATCH] D85685: Support dwarf fission for wasm object files

2020-09-16 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added a comment.

In D85685#2277998 , @dschuff wrote:

> 



> Yeah, ELF splits ELFWriter out from ELFObjectWriter, and then instantiates it 
> twice. It's all because ELFObjectWriter has to derive from MCObjectWriter 
> which was clearly not designed with this in mind. I found the class split to 
> be a bit awkward, but I don't really have strong feelings about it either way.

I should add that what I do instead is just have one instance, and just reset 
the relevant state before calling writeOneObject again. So the structure is 
cleaner but the downside of that is that the state has to be manually reset.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85685

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


[PATCH] D85685: Support dwarf fission for wasm object files

2020-09-16 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added a comment.

In D85685#2275585 , @sbc100 wrote:

> Seems reasonable.   Do you think this way is cleaner than the way elf does 
> it?   Looks like ELF creates two different ELFWriter inside the 
> ELFDwoObjectWriter subclass right?

Yeah, ELF splits ELFWriter out from ELFObjectWriter, and then instantiates it 
twice. It's all because ELFObjectWriter has to derive from MCObjectWriter which 
was clearly not designed with this in mind. I found the class split to be a bit 
awkward, but I don't really have strong feelings about it either way.

> Are we going need to wasm-ld tests to followup or is this really independent 
> of the linker?

It should be independent of the linker because the dwo files don't get linked 
by the linker. They can be used independently (or combined by the `dwp` tool 
but AFAIK it's simpler than the linker). And the object files are just the same 
as usual from the linker's perspective.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85685

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


[PATCH] D84470: [OpenMP 5.0] Fix user-defined mapper privatization in tasks

2020-09-16 Thread Ron Lieberman via Phabricator via cfe-commits
ronlieb added a comment.

The latest patch applied cleanly to our downstream port.
builds fine, tests very nicely as well. All the failing SOLLVE task wait depend 
tests now pass.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84470

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


[PATCH] D31413: [libc++] Use __attribute__((init_priority(101))) to ensure streams get initialized early

2020-09-16 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

In D31413#2277630 , @smeenai wrote:

> What was the conclusion for the comments about the priority level (100 vs. 
> 101)?

My understanding is that values below `101` are literally not allowed:

  <...>/llvm/libcxx/src/iostream.cpp:80:66: error: 'init_priority' attribute 
requires integer constant between 101 and 65535 inclusive
  _LIBCPP_HIDDEN ios_base::Init __start_std_streams 
__attribute__((init_priority(100)));
   ^
 ~~~
  1 error generated.

If there's a way around that, and if values below 101 are reserved for the 
implementation, then I agree `100` is what we should use. @aaron.ballman where 
did you read that values below 101 were reserved for the implementation? The 
GCC docs at https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html 
don't imply that -- they say the attribute starts at 101. I agree it's a fairly 
logical thing to think values before that would be reserved, but it doesn't say 
explicitly.

Is it possible that GCC reserves values before 101 for the implementation, but 
Clang implemented the attribute "naively" and just errors out?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D31413

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


[libunwind] 23bef7e - [libunwind] Support for leaf function unwinding.

2020-09-16 Thread Daniel Kiss via cfe-commits

Author: Daniel Kiss
Date: 2020-09-16T23:53:36+02:00
New Revision: 23bef7ee9923b1262326981960397e8cd95d6923

URL: 
https://github.com/llvm/llvm-project/commit/23bef7ee9923b1262326981960397e8cd95d6923
DIFF: 
https://github.com/llvm/llvm-project/commit/23bef7ee9923b1262326981960397e8cd95d6923.diff

LOG: [libunwind] Support for leaf function unwinding.

Unwinding leaf function is useful in cases when the backtrace finds a
leaf function for example when it caused a signal.
This patch also add the support for the DW_CFA_undefined because it marks
the end of the frames.

Ryan Prichard provided code for the tests.

Reviewed By: #libunwind, mstorsjo

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

Added: 
libunwind/test/signal_unwind.pass.cpp
libunwind/test/unwind_leaffunction.pass.cpp

Modified: 
libunwind/src/DwarfInstructions.hpp
libunwind/src/DwarfParser.hpp
libunwind/test/lit.site.cfg.in

Removed: 




diff  --git a/libunwind/src/DwarfInstructions.hpp 
b/libunwind/src/DwarfInstructions.hpp
index ee98f538d437..c39cabe1f783 100644
--- a/libunwind/src/DwarfInstructions.hpp
+++ b/libunwind/src/DwarfInstructions.hpp
@@ -93,7 +93,8 @@ typename A::pint_t DwarfInstructions::getSavedRegister(
 
   case CFI_Parser::kRegisterInRegister:
 return registers.getRegister((int)savedReg.value);
-
+  case CFI_Parser::kRegisterUndefined:
+return 0;
   case CFI_Parser::kRegisterUnused:
   case CFI_Parser::kRegisterOffsetFromCFA:
 // FIX ME
@@ -117,6 +118,7 @@ double DwarfInstructions::getSavedFloatRegister(
 
   case CFI_Parser::kRegisterIsExpression:
   case CFI_Parser::kRegisterUnused:
+  case CFI_Parser::kRegisterUndefined:
   case CFI_Parser::kRegisterOffsetFromCFA:
   case CFI_Parser::kRegisterInRegister:
 // FIX ME
@@ -140,6 +142,7 @@ v128 DwarfInstructions::getSavedVectorRegister(
 
   case CFI_Parser::kRegisterIsExpression:
   case CFI_Parser::kRegisterUnused:
+  case CFI_Parser::kRegisterUndefined:
   case CFI_Parser::kRegisterOffsetFromCFA:
   case CFI_Parser::kRegisterInRegister:
 // FIX ME
@@ -190,6 +193,10 @@ int DwarfInstructions::stepWithDwarf(A 
, pint_t pc,
 prolog.savedRegisters[i]));
   else
 return UNW_EBADREG;
+} else if (i == (int)cieInfo.returnAddressRegister) {
+// Leaf function keeps the return address in register and there is 
no
+// explicit intructions how to restore it.
+returnAddress = 
registers.getRegister(cieInfo.returnAddressRegister);
 }
   }
 

diff  --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index c98c4f92a6ad..1ce2cf2943a2 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -69,6 +69,7 @@ class CFI_Parser {
   };
   enum RegisterSavedWhere {
 kRegisterUnused,
+kRegisterUndefined,
 kRegisterInCFA,
 kRegisterOffsetFromCFA,
 kRegisterInRegister,
@@ -503,7 +504,7 @@ bool CFI_Parser::parseInstructions(A , 
pint_t instructions,
 "malformed DW_CFA_undefined DWARF unwind, reg too big");
 return false;
   }
-  results->setRegisterLocation(reg, kRegisterUnused, initialState);
+  results->setRegisterLocation(reg, kRegisterUndefined, initialState);
   _LIBUNWIND_TRACE_DWARF("DW_CFA_undefined(reg=%" PRIu64 ")\n", reg);
   break;
 case DW_CFA_same_value:

diff  --git a/libunwind/test/lit.site.cfg.in b/libunwind/test/lit.site.cfg.in
index 8ff770fe29bc..84dae3c2bfb0 100644
--- a/libunwind/test/lit.site.cfg.in
+++ b/libunwind/test/lit.site.cfg.in
@@ -44,6 +44,10 @@ config.test_source_root = 
os.path.join(config.libunwind_src_root, 'test')
 # Allow expanding substitutions that are based on other substitutions
 config.recursiveExpansionLimit = 10
 
+# Make symbols available in the tests.
+config.test_compiler_flags += " -funwind-tables "
+config.test_linker_flags += " -Wl,--export-dynamic "
+
 # Infer the test_exec_root from the build directory.
 config.test_exec_root = os.path.join(config.libunwind_obj_root, 'test')
 

diff  --git a/libunwind/test/signal_unwind.pass.cpp 
b/libunwind/test/signal_unwind.pass.cpp
new file mode 100644
index ..295dd75bb726
--- /dev/null
+++ b/libunwind/test/signal_unwind.pass.cpp
@@ -0,0 +1,44 @@
+// -*- C++ -*-
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Ensure that the unwinder can cope with the signal handler.
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+_Unwind_Reason_Code frame_handler(struct _Unwind_Context* 

[PATCH] D87652: Sema: add support for `__attribute__((__swift_newtype__))`

2020-09-16 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added subscribers: dexonsmith, doug.gregor.
compnerd added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2179
+def SwiftNewType : InheritableAttr {
+  let Spellings = [GNU<"swift_newtype">, GNU<"swift_wrapper">];
+  let Args = [EnumArgument<"NewtypeKind", "NewtypeKind",

aaron.ballman wrote:
> We don't ever document `swift_wrapper`, is that intentional?
> 
> (Do you have code elsewhere that's looking at the spelling of the AST 
> attribute object? Should you add an `AdditionalMembers` to this declaration 
> to make that easier to distinguish?)
Yes, that was intentional.  I believe that `swift_wrapper` predates 
`swift_newtype` and is only kept for compatibility.  People should gravitate 
towards `swift_newtype`.

I don't understand the need for `AdditionalMembers`.



Comment at: clang/include/clang/Basic/Attr.td:2183
+  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+  let Documentation = [SwiftNewTypeDocs];
+}

aaron.ballman wrote:
> You should also set: `let HasCustomParsing = 1;` since this uses a custom 
> parser.
> 
> Is the custom parser actually needed though? Or is it only needed because the 
> enum names selected are keywords? If it's only because of the keyword nature, 
> should the parser be improved in `Parser::ParseAttributeArgsCommon()` instead?
It's for the keyword handling.  I'll take a look and see if I can convert this 
to the `ParseAttributeArgsCommon` path.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:4038
+def warn_swift_newtype_attribute_non_typedef
+  : Warning<"%0 attribute may be put on a typedef only; attribute is ignored">,
+InGroup>;

aaron.ballman wrote:
> Hrm, we already have existing diagnostics to cover this 
> (`warn_attribute_wrong_decl_type_str`) but it's in the `IgnoredAttributes` 
> group. Do you need a new warning group specific to this? Is there a reason 
> that group is not a subset of `IgnoredAttributes`?
Hmm, Im okay with changing the group, but I do wonder if Apple is going to 
worry about diagnostic compatibility.  @doug.gregor, @rjmccall, or @dexonsmith 
would be better suited to answer the question about command line compatibility.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87652

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


[PATCH] D84362: [NFC] Refactor DiagnosticBuilder and PartialDiagnostic

2020-09-16 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGee5519d32357: [NFC] Refactor DiagnosticBuilder and 
PartialDiagnostic (authored by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84362

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Attr.h
  clang/include/clang/AST/CanonicalType.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/DeclarationName.h
  clang/include/clang/AST/NestedNameSpecifier.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Diagnostic.h
  clang/include/clang/Basic/PartialDiagnostic.h
  clang/include/clang/Sema/Ownership.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/Basic/Diagnostic.cpp

Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -40,8 +40,9 @@
 
 using namespace clang;
 
-const DiagnosticBuilder ::operator<<(const DiagnosticBuilder ,
-   DiagNullabilityKind nullability) {
+const StreamableDiagnosticBase ::
+operator<<(const StreamableDiagnosticBase ,
+   DiagNullabilityKind nullability) {
   StringRef string;
   switch (nullability.first) {
   case NullabilityKind::NonNull:
@@ -61,8 +62,8 @@
   return DB;
 }
 
-const DiagnosticBuilder ::operator<<(const DiagnosticBuilder ,
-   llvm::Error &) {
+const StreamableDiagnosticBase ::
+operator<<(const StreamableDiagnosticBase , llvm::Error &) {
   DB.AddString(toString(std::move(E)));
   return DB;
 }
Index: clang/lib/AST/TemplateName.cpp
===
--- clang/lib/AST/TemplateName.cpp
+++ clang/lib/AST/TemplateName.cpp
@@ -254,8 +254,8 @@
   }
 }
 
-const DiagnosticBuilder ::operator<<(const DiagnosticBuilder ,
-   TemplateName N) {
+const StreamableDiagnosticBase ::
+operator<<(const StreamableDiagnosticBase , TemplateName N) {
   std::string NameStr;
   llvm::raw_string_ostream OS(NameStr);
   LangOptions LO;
@@ -268,20 +268,6 @@
   return DB << NameStr;
 }
 
-const PartialDiagnostic::operator<<(const PartialDiagnostic ,
-   TemplateName N) {
-  std::string NameStr;
-  llvm::raw_string_ostream OS(NameStr);
-  LangOptions LO;
-  LO.CPlusPlus = true;
-  LO.Bool = true;
-  OS << '\'';
-  N.print(OS, PrintingPolicy(LO));
-  OS << '\'';
-  OS.flush();
-  return PD << NameStr;
-}
-
 void TemplateName::dump(raw_ostream ) const {
   LangOptions LO;  // FIXME!
   LO.CPlusPlus = true;
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -448,8 +448,8 @@
   llvm_unreachable("Invalid TemplateArgument Kind!");
 }
 
-const DiagnosticBuilder ::operator<<(const DiagnosticBuilder ,
-   const TemplateArgument ) {
+template 
+static const T (const T , const TemplateArgument ) {
   switch (Arg.getKind()) {
   case TemplateArgument::Null:
 // This is bad, but not as bad as crashing because of argument
@@ -502,6 +502,11 @@
   llvm_unreachable("Invalid TemplateArgument Kind!");
 }
 
+const StreamableDiagnosticBase ::
+operator<<(const StreamableDiagnosticBase , const TemplateArgument ) {
+  return DiagTemplateArg(DB, Arg);
+}
+
 const ASTTemplateArgumentListInfo *
 ASTTemplateArgumentListInfo::Create(const ASTContext ,
 const TemplateArgumentListInfo ) {
Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -3301,12 +3301,7 @@
   llvm_unreachable("Invalid access specifier!");
 }
 
-const DiagnosticBuilder ::operator<<(const DiagnosticBuilder ,
-   AccessSpecifier AS) {
-  return DB << getAccessName(AS);
-}
-
-const PartialDiagnostic ::operator<<(const PartialDiagnostic ,
-   AccessSpecifier AS) {
+const StreamableDiagnosticBase ::
+operator<<(const StreamableDiagnosticBase , AccessSpecifier AS) {
   return DB << getAccessName(AS);
 }
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -11294,9 +11294,9 @@
   return *OMPTraitInfoVector.back();
 }
 
-const DiagnosticBuilder &
-clang::operator<<(const 

[clang] ee5519d - [NFC] Refactor DiagnosticBuilder and PartialDiagnostic

2020-09-16 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2020-09-16T17:35:28-04:00
New Revision: ee5519d323571c4a9a7d92cb817023c9b95334cd

URL: 
https://github.com/llvm/llvm-project/commit/ee5519d323571c4a9a7d92cb817023c9b95334cd
DIFF: 
https://github.com/llvm/llvm-project/commit/ee5519d323571c4a9a7d92cb817023c9b95334cd.diff

LOG: [NFC] Refactor DiagnosticBuilder and PartialDiagnostic

PartialDiagnostic misses some functions compared to DiagnosticBuilder.

This patch refactors DiagnosticBuilder and PartialDiagnostic, extracts
the common functionality so that the streaming << operators are
shared.

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Attr.h
clang/include/clang/AST/CanonicalType.h
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/DeclarationName.h
clang/include/clang/AST/NestedNameSpecifier.h
clang/include/clang/AST/TemplateBase.h
clang/include/clang/AST/TemplateName.h
clang/include/clang/AST/Type.h
clang/include/clang/Basic/Diagnostic.h
clang/include/clang/Basic/PartialDiagnostic.h
clang/include/clang/Sema/Ownership.h
clang/include/clang/Sema/ParsedAttr.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/AST/TemplateName.cpp
clang/lib/Basic/Diagnostic.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index de0d1198b6d4..397fee4d866b 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -3064,8 +3064,9 @@ OPT_LIST(V)
 };
 
 /// Insertion operator for diagnostics.
-const DiagnosticBuilder <<(const DiagnosticBuilder ,
-const ASTContext::SectionInfo );
+const StreamableDiagnosticBase &
+operator<<(const StreamableDiagnosticBase ,
+   const ASTContext::SectionInfo );
 
 /// Utility function for constructing a nullary selector.
 inline Selector GetNullarySelector(StringRef name, ASTContext ) {

diff  --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index b3729b2e0d99..b4dce8f41c67 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -350,19 +350,12 @@ struct ParsedTargetAttr {
 
 #include "clang/AST/Attrs.inc"
 
-inline const DiagnosticBuilder <<(const DiagnosticBuilder ,
-   const Attr *At) {
+inline const StreamableDiagnosticBase &
+operator<<(const StreamableDiagnosticBase , const Attr *At) {
   DB.AddTaggedVal(reinterpret_cast(At),
   DiagnosticsEngine::ak_attr);
   return DB;
 }
-
-inline const PartialDiagnostic <<(const PartialDiagnostic ,
-   const Attr *At) {
-  PD.AddTaggedVal(reinterpret_cast(At),
-  DiagnosticsEngine::ak_attr);
-  return PD;
-}
 }  // end namespace clang
 
 #endif

diff  --git a/clang/include/clang/AST/CanonicalType.h 
b/clang/include/clang/AST/CanonicalType.h
index 488284713bce..b6d9b69db09a 100644
--- a/clang/include/clang/AST/CanonicalType.h
+++ b/clang/include/clang/AST/CanonicalType.h
@@ -215,8 +215,8 @@ inline CanQualType Type::getCanonicalTypeUnqualified() 
const {
   return CanQualType::CreateUnsafe(getCanonicalTypeInternal());
 }
 
-inline const DiagnosticBuilder <<(const DiagnosticBuilder ,
-   CanQualType T) {
+inline const StreamableDiagnosticBase &
+operator<<(const StreamableDiagnosticBase , CanQualType T) {
   DB << static_cast(T);
   return DB;
 }

diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index c2511514fe72..852ba2316f82 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4513,14 +4513,8 @@ class EmptyDecl : public Decl {
 
 /// Insertion operator for diagnostics.  This allows sending NamedDecl's
 /// into a diagnostic with <<.
-inline const DiagnosticBuilder <<(const DiagnosticBuilder ,
-   const NamedDecl* ND) {
-  DB.AddTaggedVal(reinterpret_cast(ND),
-  DiagnosticsEngine::ak_nameddecl);
-  return DB;
-}
-inline const PartialDiagnostic <<(const PartialDiagnostic ,
-   const NamedDecl* ND) {
+inline const StreamableDiagnosticBase &
+operator<<(const StreamableDiagnosticBase , const NamedDecl *ND) {
   PD.AddTaggedVal(reinterpret_cast(ND),
   DiagnosticsEngine::ak_nameddecl);
   return PD;

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 20f058b87e7f..065a7413e7e7 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -4070,11 +4070,8 @@ class MSGuidDecl : public ValueDecl,
 
 /// Insertion operator for 

[PATCH] D87528: Enable '#pragma STDC FENV_ACCESS' in frontend cf. D69272 - Work in Progress

2020-09-16 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:13197-13198
   assert(E->isRValue() && E->getType()->isRealFloatingType());
+  if (Info.isStrictFP)
+return false;
   return FloatExprEvaluator(Info, Result).Visit(E);

rsmith wrote:
> I think we should be able to evaluate (for example) `constexpr float f = 
> 1.0f;` even in a strict FP context. I think only floating point operations 
> that depend on the rounding mode should be disabled, not all floating-point 
> evaluation. Perhaps we should propagate the `FPOptions` into 
> `handleFloatFloatBinOp` and perform the check there, along with any other 
> places that care (I think we probably have some builtins that we can 
> constant-evaluate that care about rounding modes.)
> 
> You also need to produce a diagnostic when you treat an expression as 
> non-constant -- please read the comment at the top of the file for details.
> I think we should be able to evaluate (for example) `constexpr float f = 
> 1.0f;` even in a strict FP context. I think only floating point operations 
> that depend on the rounding mode should be disabled, not all floating-point 
> evaluation. Perhaps we should propagate the `FPOptions` into 
> `handleFloatFloatBinOp` and perform the check there, along with any other 
> places that care (I think we probably have some builtins that we can 
> constant-evaluate that care about rounding modes.)
> 
> You also need to produce a diagnostic when you treat an expression as 
> non-constant -- please read the comment at the top of the file for details.

It's not just rounding mode, right? If fp exceptions are unmasked then we 
should inhibit the folding in particular cases?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87528

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


[PATCH] D87528: Enable '#pragma STDC FENV_ACCESS' in frontend cf. D69272 - Work in Progress

2020-09-16 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 292343.
mibintc added a comment.

I pulled out the isStrictFP boolean from EvalInfo and used the FPOptions when 
visiting floating point BinaryOperator, CastExpr and builtin CallExpr. I 
created the diagnostic note explaining why constant evaluation failed.  Not 
certain about the language rules C vs C++.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87528

Files:
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CXX/expr/expr.const/p2-0x.cpp
  clang/test/CodeGen/fp-floatcontrol-pragma.cpp
  clang/test/CodeGen/pragma-fenv_access.c
  clang/test/Parser/fp-floatcontrol-syntax.cpp
  clang/test/Parser/pragma-fenv_access.c
  clang/test/Preprocessor/pragma_unknown.c

Index: clang/test/Preprocessor/pragma_unknown.c
===
--- clang/test/Preprocessor/pragma_unknown.c
+++ clang/test/Preprocessor/pragma_unknown.c
@@ -16,15 +16,6 @@
 // CHECK: {{^}}#pragma STDC FP_CONTRACT DEFAULT{{$}}
 // CHECK: {{^}}#pragma STDC FP_CONTRACT IN_BETWEEN{{$}}
 
-#pragma STDC FENV_ACCESS ON  // expected-warning {{pragma STDC FENV_ACCESS ON is not supported, ignoring pragma}}
-#pragma STDC FENV_ACCESS OFF
-#pragma STDC FENV_ACCESS DEFAULT
-#pragma STDC FENV_ACCESS IN_BETWEEN   // expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
-// CHECK: {{^}}#pragma STDC FENV_ACCESS ON{{$}}
-// CHECK: {{^}}#pragma STDC FENV_ACCESS OFF{{$}}
-// CHECK: {{^}}#pragma STDC FENV_ACCESS DEFAULT{{$}}
-// CHECK: {{^}}#pragma STDC FENV_ACCESS IN_BETWEEN{{$}}
-
 #pragma STDC CX_LIMITED_RANGE ON
 #pragma STDC CX_LIMITED_RANGE OFF
 #pragma STDC CX_LIMITED_RANGE DEFAULT 
Index: clang/test/Parser/pragma-fenv_access.c
===
--- /dev/null
+++ clang/test/Parser/pragma-fenv_access.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#pragma STDC FENV_ACCESS IN_BETWEEN   // expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
+
+#pragma STDC FENV_ACCESS OFF
+
+float func_04(int x, float y) {
+  if (x)
+return y + 2;
+  #pragma STDC FENV_ACCESS ON // expected-error{{'#pragma STDC FENV_ACCESS' can only appear at file scope or at the start of a compound statement}}
+  return x + y;
+}
Index: clang/test/Parser/fp-floatcontrol-syntax.cpp
===
--- clang/test/Parser/fp-floatcontrol-syntax.cpp
+++ clang/test/Parser/fp-floatcontrol-syntax.cpp
@@ -26,19 +26,14 @@
 double a = 0.0;
 double b = 1.0;
 
-//FIXME At some point this warning will be removed, until then
-//  document the warning
-#ifdef FAST
-// expected-warning@+1{{pragma STDC FENV_ACCESS ON is not supported, ignoring pragma}}
-#pragma STDC FENV_ACCESS ON
-#else
-#pragma STDC FENV_ACCESS ON // expected-warning{{pragma STDC FENV_ACCESS ON is not supported, ignoring pragma}}
-#endif
 #ifdef STRICT
 #pragma float_control(precise, off) // expected-error {{'#pragma float_control(precise, off)' is illegal when except is enabled}}
 #else
+#ifndef FAST
 // Currently FENV_ACCESS cannot be enabled by pragma, skip error check
-#pragma float_control(precise, off) // not-expected-error {{'#pragma float_control(precise, off)' is illegal when fenv_access is enabled}}
+#pragma STDC FENV_ACCESS ON
+#pragma float_control(precise, off) // expected-error {{'#pragma float_control(precise, off)' is illegal when fenv_access is enabled}}
+#endif
 #endif
 
 #pragma float_control(precise, on)
Index: clang/test/CodeGen/pragma-fenv_access.c
===
--- /dev/null
+++ clang/test/CodeGen/pragma-fenv_access.c
@@ -0,0 +1,66 @@
+// xxx: %clang_cc1 -ffp-exception-behavior=strict -frounding-math -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck %s
+
+#pragma STDC FENV_ACCESS ON
+
+float func_01(float x, float y) {
+  return x + y;
+}
+// CHECK-LABEL: @func_01
+// CHECK: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
+
+
+float func_02(float x, float y) {
+  #pragma float_control(except, off)
+  #pragma STDC FENV_ACCESS OFF
+  return x + y;
+}
+// CHECK-LABEL: @func_02
+// CHECK: fadd float {{.*}}
+
+
+float func_03(float x, float y) {
+  return x + y;
+}
+// CHECK-LABEL: @func_03
+// CHECK: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata 

[PATCH] D87791: [CUDA][HIP] Fix -gsplit-dwarf option

2020-09-16 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

Does this naming scheme the same as used for `.o` files? We may want to keep 
them in sync.

Other than that, LGTM.




Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:909
+  auto AddPostfix = [JA](auto ) {
+if (JA.getOffloadingDeviceKind() == Action::OFK_HIP)
+  F += (Twine("_") + JA.getOffloadingArch()).str();

I think the same approach would make sense for CUDA, too. 


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

https://reviews.llvm.org/D87791

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


[PATCH] D86156: [BFI] Make BFI information available through loop passes inside LoopStandardAnalysisResults

2020-09-16 Thread Di Mo via Phabricator via cfe-commits
modimo added a comment.

Thanks @asbirlea!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86156

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


[clang] bebfc3b - Revert "Do not apply calling conventions to MSVC entry points"

2020-09-16 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-09-16T13:52:29-07:00
New Revision: bebfc3b92d5e8dd1b1d75d40d5d03975957eec14

URL: 
https://github.com/llvm/llvm-project/commit/bebfc3b92d5e8dd1b1d75d40d5d03975957eec14
DIFF: 
https://github.com/llvm/llvm-project/commit/bebfc3b92d5e8dd1b1d75d40d5d03975957eec14.diff

LOG: Revert "Do not apply calling conventions to MSVC entry points"

This reverts commit 4cff1b40dacf6a5489b09657d94ea4757b8cd3b0.

Caused "undefined symbol: _WinMain@16" link errors.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGenCXX/default_calling_conv.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 416a75fa4323..f78f7ac246bb 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11095,11 +11095,6 @@ void Sema::CheckMSVCRTEntryPoint(FunctionDecl *FD) {
 if (FD->getName() != "DllMain")
   FD->setHasImplicitReturnZero(true);
 
-  if (FT->getCallConv() != CC_C) {
-FT = Context.adjustFunctionType(FT, 
FT->getExtInfo().withCallingConv(CC_C));
-FD->setType(QualType(FT, 0));
-  }
-
   if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) {
 Diag(FD->getLocation(), diag::err_mainlike_template_decl) << FD;
 FD->setInvalidDecl();

diff  --git a/clang/test/CodeGenCXX/default_calling_conv.cpp 
b/clang/test/CodeGenCXX/default_calling_conv.cpp
index 16b623c30197..b5b0f47ceb98 100644
--- a/clang/test/CodeGenCXX/default_calling_conv.cpp
+++ b/clang/test/CodeGenCXX/default_calling_conv.cpp
@@ -1,14 +1,10 @@
-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fdefault-calling-conv=cdecl 
-emit-llvm -o - %s -DMAIN | FileCheck %s --check-prefix=CDECL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i786-unknown-linux-gnu -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=FASTCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i486-unknown-linux-gnu 
-fdefault-calling-conv=stdcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=STDCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s 
-DMAIN | FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=vectorcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=VECTORCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=regcall -emit-llvm -o - %s -DMAIN | FileCheck %s 
--check-prefix=REGCALL --check-prefix=ALL
-// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWMAIN | FileCheck %s  
--check-prefix=WMAIN
-// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWINMAIN | FileCheck %s  
--check-prefix=WINMAIN
-// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DWWINMAIN | FileCheck %s  
--check-prefix=WWINMAIN
-// RUN: %clang_cc1 -triple i386-pc-win32  -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s -DDLLMAIN | FileCheck %s  
--check-prefix=DLLMAIN
-//
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -fdefault-calling-conv=cdecl 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CDECL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i786-unknown-linux-gnu -target-feature +sse4.2 
-fdefault-calling-conv=fastcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=FASTCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i486-unknown-linux-gnu 
-fdefault-calling-conv=stdcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=STDCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i486-unknown-linux-gnu -mrtd -emit-llvm -o - %s | 
FileCheck %s --check-prefix=STDCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=vectorcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VECTORCALL --check-prefix=ALL
+// RUN: %clang_cc1 -triple i986-unknown-linux-gnu 
-fdefault-calling-conv=regcall -emit-llvm -o - %s | FileCheck %s 
--check-prefix=REGCALL --check-prefix=ALL
+
 // CDECL: define void @_Z5test1v
 // FASTCALL: define x86_fastcallcc void @_Z5test1v
 // STDCALL: define x86_stdcallcc void @_Z5test1v
@@ -50,37 +46,7 @@ void test() {
   a.test_member();
 }
 
-#ifdef MAIN
 // ALL: define i32 @main
 int main() {
   return 1;
 }
-#endif // main
-
-#ifdef WMAIN
-// WMAIN: define dso_local i32 @wmain
-int wmain() {
-  return 1;
-}
-#endif // wmain
-
-#ifdef WINMAIN
-// WINMAIN: define dso_local i32 @WinMain
-int WinMain() {
-  return 1;
-}
-#endif // WinMain
-
-#ifdef WWINMAIN
-// WWINMAIN: define dso_local i32 @wWinMain
-int wWinMain() {
-  return 1;
-}
-#endif // wWinMain
-
-#ifdef DLLMAIN
-// DLLMAIN: define dso_local i32 @DllMain
-int DllMain() {
-  return 1;
-}
-#endif // 

[PATCH] D87701: Do not apply calling conventions to MSVC entry points

2020-09-16 Thread Amy Huang via Phabricator via cfe-commits
akhuang added a comment.

whoops, sorry for weird formatting in the previous comment.

I'll revert for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87701

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


[PATCH] D87701: Do not apply calling conventions to MSVC entry points

2020-09-16 Thread Amy Huang via Phabricator via cfe-commits
akhuang added a comment.

This is causing a link error in the windows chromium build:

lld-link: error: undefined symbol: _WinMain@16

>>> referenced by 
>>> D:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:102
>>>
>>>   msvcrtd.lib(exe_winmain.obj):(int __cdecl invoke_main(void))


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87701

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


[PATCH] D87534: Sema: introduce `__attribute__((__swift_name__))`

2020-09-16 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:4289
+if (Inline->getName() != Name && !Inline->isImplicit()) {
+  Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline;
+  Diag(CI.getLoc(), diag::note_conflicting_attribute);

compnerd wrote:
> aaron.ballman wrote:
> > compnerd wrote:
> > > aaron.ballman wrote:
> > > > I think it would be more helpful if the diagnostic said why the 
> > > > attribute is being ignored (because the arguments don't match).
> > > Does the note below not accomplish that?
> > Not really, no. The warning diagnostic itself just says that the attribute 
> > is ignored, which is the effect but not the rationale. The note (which is 
> > easier for folks to ignore) says the attribute is conflicting, but 
> > conflicting with *what* (there could be a half dozen attributes on the same 
> > declaration, for instance).
> Okay, I don't think that there is an existing warning, but I should be able 
> to add one.
The existing diagnostic is actually more inline with the existing attribute 
handling for `__attribute__((__optnone__))`, `__attribute__((__minsize__))`, 
and `__attribute__((__always_inline__))` which merge similarly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87534

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


[PATCH] D83154: clang: Add -fcoverage-prefix-map

2020-09-16 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D83154#2277539 , @rnk wrote:

> Yeah, my goal is for the build system to be able to avoid having to embed PWD 
> into the compiler flags. For example, I believe it is a goal of the LLVM gn 
> build system for the build tree to be relocatable. If the compiler command 
> lines need to contain absolute paths to make the paths in the coverage 
> relative, we won't be able to achieve that goal.
>
> Based on all the comments that have gone before, it sounds like we want a 
> `-fprofile-compilation-dir=` flag. Once we have that, would this logic work?
>
> - if profile compilation dir set, absolutize with that as the root
> - if no profile compilation dir, absolutize with CWD
> - apply profile prefix map
>
> Should `-no-canonical-prefixes` also be involved here? Unclear.

I originally considered `-fprofile-compilation-dir=` and perhaps 
`-ffile-compilation-dir=` to also handle cases like `__FILE__` macro 
(`-ffile-prefix-map` and `-fmacro-prefix-map` suffer from the same issue as 
`-fprofile-prefix-map`), but I'm not sure if specifying compilation dir is the 
right approach. It makes sense for debug info because `-fdebug-compilation-dir` 
is used directly as `DW_AT_comp_dir` and also because it's a convention for 
source file paths in debug info to be relative to build directory, but it's not 
the case for paths in coverage mapping or `__FILE__`.

So what I'm considering now and started prototyping is a `-fsource-dir`flag (or 
maybe `-fsource-root-dir`, I'm open to suggestions for the name) where the 
semantics would be that if this flag is set, all source paths will be made 
relative to this directory. There's an open question whether this should also 
apply to sources outside of that directory, for example system header paths.

The example use case, assuming source is in `/path/to/source` and build is in 
`/path/to/build`, would be: `clang -fdebug-compilation-dir . -fsource-dir 
../source ../source/dir/file.c`. In this case `__FILE__` would expand to 
`dir/file.c` and that path would be also stored in coverage mapping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83154

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


[PATCH] D86020: [MemCpyOptimizer] Optimize passing byref function arguments down the stack

2020-09-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D86020#103 , @atrosinenko wrote:

> @rjmccall
>
> Maybe I overestimated similarity of `byval` and recently introduced 
> `byref`... Looks like some aliasing restrictions are not mentioned in LLVM 
> Language Reference . 
> For example, the only way for Clang to emit the `byref` attribute to LLVM IR 
> I know about is via `ABIArgInfo` with `Kind == IndirectAliased` introduced in 
> D79744: clang: Use byref for aggregate kernel arguments 
>  - and it has a note that "The object is 
> known to not be through any other references for the duration of the call, 
> and the callee must not itself modify the object". This seems to be necessary 
> for correctness of this transformation. If LLVM Language Reference does not 
> mention such restrictions intentionally, then it may be clang that should be 
> responsible for such optimizations.

I think this lost the word written or stored




Comment at: llvm/test/Transforms/MemCpyOpt/byref-memcpy.ll:8
+; A caller of this function has to arrange everything for the pointer it passes
+; to be usable with byref attrbiute anyway, so just pass the pointer through.
+define void @function_with_byref_arg(%struct.S* byref(%struct.S) align 4 %0) {

Typo attrbiute



Comment at: llvm/test/Transforms/MemCpyOpt/byref-memcpy.ll:55
+; CHECK-NEXT:[[V2:%.+]] = bitcast %struct.S* [[V0]] to i8*
+; CHECK-NEXT:call void @llvm.memcpy.p0i8.p0i8.i16(i8* align 4 [[V1]], i8* 
align 2 [[V2]], i16 16, i1 false)
+; CHECK-NEXT:call void @leaf(%struct.S* byref(%struct.S) align 4 
[[ALLOCA]])

atrosinenko wrote:
> Interestingly, if I change the alignment of the second argument from 2 back 
> to 4, then memcpy() is successfully dropped (as if everything has big-enough 
> alignment) while it seemingly shouldn't be. Is it just due to the code being 
> ill-formed?
I'm not sure I follow, if you change it to 4 it is big enough?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86020

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


[PATCH] D84470: [OpenMP 5.0] Fix user-defined mapper privatization in tasks

2020-09-16 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 292330.
ABataev added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Updated + added clang test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84470

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_depend_codegen.cpp

Index: clang/test/OpenMP/target_depend_codegen.cpp
===
--- clang/test/OpenMP/target_depend_codegen.cpp
+++ clang/test/OpenMP/target_depend_codegen.cpp
@@ -43,8 +43,8 @@
 
 // TCHECK: [[ENTTY:%.+]] = type { i8*, i8*, i{{32|64}}, i32, i32 }
 
-// CHECK-DAG: [[SIZET:@.+]] = private unnamed_addr constant [2 x i64] [i64 0, i64 4]
-// CHECK-DAG: [[MAPT:@.+]] = private unnamed_addr constant [2 x i64] [i64 544, i64 800]
+// CHECK-DAG: [[SIZET:@.+]] = private unnamed_addr constant [3 x i64] [i64 0, i64 4, i64 {{16|12}}]
+// CHECK-DAG: [[MAPT:@.+]] = private unnamed_addr constant [3 x i64] [i64 544, i64 800, i64 3]
 // CHECK-DAG: @{{.*}} = weak constant i8 0
 
 // TCHECK: @{{.+}} = weak constant [[ENTTY]]
@@ -61,6 +61,9 @@
   ty Y;
 };
 
+#pragma omp declare mapper(id \
+   : TT  \
+   s) map(s.X, s.Y)
 int global;
 extern int global;
 
@@ -102,29 +105,75 @@
   // CHECK:   [[BOOL:%.+]] = icmp ne i32 %{{.+}}, 0
   // CHECK:   br i1 [[BOOL]], label %[[THEN:.+]], label %[[ELSE:.+]]
   // CHECK:   [[THEN]]:
-  // CHECK-DAG:   [[BPADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP:%.+]], i32 0, i32 0
-  // CHECK-DAG:   [[PADDR0:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[P:%.+]], i32 0, i32 0
+  // CHECK-DAG:   [[BPADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP:%.+]], i32 0, i32 0
+  // CHECK-DAG:   [[PADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P:%.+]], i32 0, i32 0
+  // CHECK-DAG:   [[MADDR0:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[M:%.+]], i[[SZ]] 0, i[[SZ]] 0
   // CHECK-DAG:   [[CBPADDR0:%.+]] = bitcast i8** [[BPADDR0]] to i[[SZ]]**
   // CHECK-DAG:   [[CPADDR0:%.+]] = bitcast i8** [[PADDR0]] to i[[SZ]]**
   // CHECK-DAG:   store i[[SZ]]* [[BP0:%[^,]+]], i[[SZ]]** [[CBPADDR0]]
   // CHECK-DAG:   store i[[SZ]]* [[BP0]], i[[SZ]]** [[CPADDR0]]
+  // CHECK-DAG:   store i8* null, i8** [[MADDR0]],
 
-  // CHECK-DAG:   [[BPADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP]], i32 0, i32 1
-  // CHECK-DAG:   [[PADDR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[P]], i32 0, i32 1
+  // CHECK-DAG:   [[BPADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 1
+  // CHECK-DAG:   [[PADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 1
+  // CHECK-DAG:   [[MADDR1:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[M]], i[[SZ]] 0, i[[SZ]] 1
   // CHECK-DAG:   [[CBPADDR1:%.+]] = bitcast i8** [[BPADDR1]] to i[[SZ]]*
   // CHECK-DAG:   [[CPADDR1:%.+]] = bitcast i8** [[PADDR1]] to i[[SZ]]*
   // CHECK-DAG:   store i[[SZ]] [[BP1:%[^,]+]], i[[SZ]]* [[CBPADDR1]]
   // CHECK-DAG:   store i[[SZ]] [[BP1]], i[[SZ]]* [[CPADDR1]]
-  // CHECK-DAG:   getelementptr inbounds [2 x i8*], [2 x i8*]* [[BP]], i32 0, i32 0
-  // CHECK-DAG:   getelementptr inbounds [2 x i8*], [2 x i8*]* [[P]], i32 0, i32 0
+  // CHECK-DAG:   store i8* null, i8** [[MADDR1]],
+
+  // CHECK-DAG:   [[BPADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 2
+  // CHECK-DAG:   [[PADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 2
+  // CHECK-DAG:   [[MADDR2:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[M]], i[[SZ]] 0, i[[SZ]] 2
+  // CHECK-DAG:   [[CBPADDR2:%.+]] = bitcast i8** [[BPADDR2]] to [[STRUCT_TT:%.+]]**
+  // CHECK-DAG:   [[CPADDR2:%.+]] = bitcast i8** [[PADDR2]] to [[STRUCT_TT]]**
+  // CHECK-DAG:   store [[STRUCT_TT]]* [[D_ADDR:%.+]], [[STRUCT_TT]]** [[CBPADDR2]]
+  // CHECK-DAG:   store [[STRUCT_TT]]* [[D_ADDR]], [[STRUCT_TT]]** [[CPADDR2]]
+  // CHECK-DAG:   store i8* bitcast (void (i8*, i8*, i8*, i64, i64)* [[MAPPER_ID:@.+]] to i8*), i8** [[MADDR2]],
+
+  // CHECK-DAG:   [[BP_START:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BP]], i32 0, i32 0
+  // CHECK-DAG:   [[P_START:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[P]], i32 0, i32 0
+  // CHECK-DAG:   [[M_START:%.+]] = bitcast [3 x i8*]* [[M]] to i8**
   // CHECK:   [[GEP:%.+]] = getelementptr inbounds %{{.+}}, %{{.+}}* %{{.+}}, i32 0, i32 2
   // CHECK:   [[DEV:%.+]] = load i32, i32* [[DEVICE_CAP]],
   // CHECK:   store i32 [[DEV]], i32* [[GEP]],
   // CHECK:   [[DEV1:%.+]] = load i32, i32* [[DEVICE_CAP]],
   // CHECK:   [[DEV2:%.+]] = sext i32 [[DEV1]] to i64
 
-  // CHECK:   [[TASK:%.+]] = call i8* @__kmpc_omp_target_task_alloc(%struct.ident_t* @{{.*}}, i32 [[GTID]], i32 1, i[[SZ]] {{120|68}}, i[[SZ]] {{16|12}}, 

[PATCH] D87791: [CUDA][HIP] Fix -gsplit option

2020-09-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: tra, MaskRay.
yaxunl requested review of this revision.

when -gsplit option is used with clang driver, clang driver will create
a filename with .dwo option based on the input file name and pass
it to clang -cc1. This file is used for storing the debug info. Since
CUDA/HIP generate separate object files for different GPU arch's,
this file should be different for different GPU arch. This patch
adds `_` and GPU arch to the stem of the dwo file.


https://reviews.llvm.org/D87791

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/test/Driver/hip-gsplit-dwarf-options.hip

Index: clang/test/Driver/hip-gsplit-dwarf-options.hip
===
--- /dev/null
+++ clang/test/Driver/hip-gsplit-dwarf-options.hip
@@ -0,0 +1,25 @@
+// REQUIRES: zlib, clang-driver, amdgpu-registered-target
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -c \
+// RUN:   --offload-arch=gfx906:xnack+ %s -nogpulib -nogpuinc \
+// RUN:   --offload-arch=gfx900 \
+// RUN:   -ggdb -gsplit-dwarf 2>&1 | FileCheck %s
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -c \
+// RUN:   -fgpu-rdc --offload-arch=gfx906:xnack+ %s -nogpulib -nogpuinc \
+// RUN:   --offload-arch=gfx900 \
+// RUN:   -ggdb -gsplit-dwarf 2>&1 | FileCheck %s
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu \
+// RUN:   --offload-arch=gfx906:xnack+ %s -nogpulib -nogpuinc \
+// RUN:   --offload-arch=gfx900 \
+// RUN:   -ggdb -gsplit-dwarf 2>&1 | FileCheck %s
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu \
+// RUN:   -fgpu-rdc --offload-arch=gfx906:xnack+ %s -nogpulib -nogpuinc \
+// RUN:   --offload-arch=gfx900 \
+// RUN:   -ggdb -gsplit-dwarf 2>&1 | FileCheck %s
+
+// CHECK-DAG: {{".*clang.*".* "-target-cpu" "gfx906".* "-split-dwarf-output" "hip-gsplit-dwarf-options_gfx906:xnack\+.dwo"}}
+// CHECK-DAG: {{".*clang.*".* "-target-cpu" "gfx900".* "-split-dwarf-output" "hip-gsplit-dwarf-options_gfx900.dwo"}}
+// CHECK-DAG: {{".*clang.*".* "-target-cpu" "x86-64".* "-split-dwarf-output" "hip-gsplit-dwarf-options.dwo"}}
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -55,7 +55,7 @@
 
   if (Args.hasArg(options::OPT_gsplit_dwarf))
 SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
-   SplitDebugName(Args, Inputs[0], Output));
+   SplitDebugName(JA, Args, Inputs[0], Output));
 }
 
 void tools::MinGW::Linker::AddLibGCC(const ArgList ,
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -939,7 +939,7 @@
   if (Args.hasArg(options::OPT_gsplit_dwarf) &&
   getToolChain().getTriple().isOSLinux())
 SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
-   SplitDebugName(Args, Inputs[0], Output));
+   SplitDebugName(JA, Args, Inputs[0], Output));
 }
 
 namespace {
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===
--- clang/lib/Driver/ToolChains/CommonArgs.h
+++ clang/lib/Driver/ToolChains/CommonArgs.h
@@ -49,7 +49,7 @@
 llvm::opt::ArgStringList ,
 const llvm::opt::ArgList );
 
-const char *SplitDebugName(const llvm::opt::ArgList ,
+const char *SplitDebugName(const JobAction , const llvm::opt::ArgList ,
const InputInfo , const InputInfo );
 
 void SplitDebugInfo(const ToolChain , Compilation , const Tool ,
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -902,15 +902,21 @@
   return false;
 }
 
-const char *tools::SplitDebugName(const ArgList , const InputInfo ,
+const char *tools::SplitDebugName(const JobAction , const ArgList ,
+  const InputInfo ,
   const InputInfo ) {
+  auto AddPostfix = [JA](auto ) {
+if (JA.getOffloadingDeviceKind() == Action::OFK_HIP)
+  F += (Twine("_") + JA.getOffloadingArch()).str();
+  };
   if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
 if (StringRef(A->getValue()) == "single")
   return Args.MakeArgString(Output.getFilename());
 
   Arg *FinalOutput = Args.getLastArg(options::OPT_o);
   if (FinalOutput && Args.hasArg(options::OPT_c)) {
-SmallString<128> T(FinalOutput->getValue());
+SmallString<128> T(llvm::sys::path::stem(FinalOutput->getValue()));
+AddPostfix(T);
 

[PATCH] D84362: [NFC] Refactor DiagnosticBuilder and PartialDiagnostic

2020-09-16 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

This is a very nice cleanup. Thank you, Sam.


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

https://reviews.llvm.org/D84362

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


[PATCH] D75574: RFC: Implement objc_direct_protocol attribute to remove protocol metadata

2020-09-16 Thread Nathan Lanza via Phabricator via cfe-commits
lanza added a comment.

> Hmm, I thought we actually just generated a bogus definition for the protocol 
> when it was forward-declared; really, this is better behavior that I 
> expected. Regardless, I don't think it's worthwhile to diagnose this more 
> strongly than a warning because of the history of not doing so.

That's fair!

> Not really important for this PR anyway. Was your question answered well 
> enough to move forward?

Yea sure, I'm okay with leaving it as a warning and moving forward and fixing 
your suggestions. I just wanted to make sure to cover any possible concerns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75574

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


[PATCH] D84362: [NFC] Refactor DiagnosticBuilder and PartialDiagnostic

2020-09-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 292319.
yaxunl retitled this revision from "[NFC] Add missing functions to 
PartialDiagnostic" to "[NFC] Refactor DiagnosticBuilder and PartialDiagnostic".
yaxunl edited the summary of this revision.
yaxunl added a comment.

Revised by Artem's comments. Extracted the common code of DiagnosticBuilder and 
PartialDiagnostic
and removed redundant code.


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

https://reviews.llvm.org/D84362

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Attr.h
  clang/include/clang/AST/CanonicalType.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/DeclarationName.h
  clang/include/clang/AST/NestedNameSpecifier.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/Diagnostic.h
  clang/include/clang/Basic/PartialDiagnostic.h
  clang/include/clang/Sema/Ownership.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/Basic/Diagnostic.cpp

Index: clang/lib/Basic/Diagnostic.cpp
===
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -40,8 +40,9 @@
 
 using namespace clang;
 
-const DiagnosticBuilder ::operator<<(const DiagnosticBuilder ,
-   DiagNullabilityKind nullability) {
+const StreamableDiagnosticBase ::
+operator<<(const StreamableDiagnosticBase ,
+   DiagNullabilityKind nullability) {
   StringRef string;
   switch (nullability.first) {
   case NullabilityKind::NonNull:
@@ -61,8 +62,8 @@
   return DB;
 }
 
-const DiagnosticBuilder ::operator<<(const DiagnosticBuilder ,
-   llvm::Error &) {
+const StreamableDiagnosticBase ::
+operator<<(const StreamableDiagnosticBase , llvm::Error &) {
   DB.AddString(toString(std::move(E)));
   return DB;
 }
Index: clang/lib/AST/TemplateName.cpp
===
--- clang/lib/AST/TemplateName.cpp
+++ clang/lib/AST/TemplateName.cpp
@@ -254,8 +254,8 @@
   }
 }
 
-const DiagnosticBuilder ::operator<<(const DiagnosticBuilder ,
-   TemplateName N) {
+const StreamableDiagnosticBase ::
+operator<<(const StreamableDiagnosticBase , TemplateName N) {
   std::string NameStr;
   llvm::raw_string_ostream OS(NameStr);
   LangOptions LO;
@@ -268,20 +268,6 @@
   return DB << NameStr;
 }
 
-const PartialDiagnostic::operator<<(const PartialDiagnostic ,
-   TemplateName N) {
-  std::string NameStr;
-  llvm::raw_string_ostream OS(NameStr);
-  LangOptions LO;
-  LO.CPlusPlus = true;
-  LO.Bool = true;
-  OS << '\'';
-  N.print(OS, PrintingPolicy(LO));
-  OS << '\'';
-  OS.flush();
-  return PD << NameStr;
-}
-
 void TemplateName::dump(raw_ostream ) const {
   LangOptions LO;  // FIXME!
   LO.CPlusPlus = true;
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -448,8 +448,8 @@
   llvm_unreachable("Invalid TemplateArgument Kind!");
 }
 
-const DiagnosticBuilder ::operator<<(const DiagnosticBuilder ,
-   const TemplateArgument ) {
+template 
+static const T (const T , const TemplateArgument ) {
   switch (Arg.getKind()) {
   case TemplateArgument::Null:
 // This is bad, but not as bad as crashing because of argument
@@ -502,6 +502,11 @@
   llvm_unreachable("Invalid TemplateArgument Kind!");
 }
 
+const StreamableDiagnosticBase ::
+operator<<(const StreamableDiagnosticBase , const TemplateArgument ) {
+  return DiagTemplateArg(DB, Arg);
+}
+
 const ASTTemplateArgumentListInfo *
 ASTTemplateArgumentListInfo::Create(const ASTContext ,
 const TemplateArgumentListInfo ) {
Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -3301,12 +3301,7 @@
   llvm_unreachable("Invalid access specifier!");
 }
 
-const DiagnosticBuilder ::operator<<(const DiagnosticBuilder ,
-   AccessSpecifier AS) {
-  return DB << getAccessName(AS);
-}
-
-const PartialDiagnostic ::operator<<(const PartialDiagnostic ,
-   AccessSpecifier AS) {
+const StreamableDiagnosticBase ::
+operator<<(const StreamableDiagnosticBase , AccessSpecifier AS) {
   return DB << getAccessName(AS);
 }
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ 

[PATCH] D31413: [libc++] Use __attribute__((init_priority(101))) to ensure streams get initialized early

2020-09-16 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

What was the conclusion for the comments about the priority level (100 vs. 101)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D31413

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


[PATCH] D87785: [analyzer][StdLibraryFunctionsChecker] Fix a BufferSize constraint crash

2020-09-16 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:219-226
   if (V.isUndef())
-return State;
+return {State, State};
 
   DefinedOrUnknownSVal L = V.castAs();
   if (!L.getAs())
-return State;
-
-  return State->assume(L, CannotBeNull);
-}
+return {State, State};
 

I suggest the same //simpler// version for the similar code segments as well.

By the same token, why do you return `{State, State}`?
Shouldn't you return `{State, nullptr}` there?
In general, one would not expect the **same** State being returned, IMO it's 
advised to avoid doing that.
Same applies for the other cases.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:299-300
 SvalBuilder.getContext().BoolTy);
   if (auto F = Feasible.getAs())
-return State->assume(*F, true);
+return State->assume(*F);
 

Why don't you `castAs`? That also has the corresponding assert inside.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87785

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


[PATCH] D86694: [scudo] Allow -fsanitize=scudo on Linux and Windows (WIP, don't land as is)

2020-09-16 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

In D86694#2277456 , @cryptoad wrote:

> I didn't try to make the Exclusive version work, mostly because I was using 
> the Windows TLS API and the Shared fit right in with those, but it would get 
> rid of a lot of the contention.

That sounds good. Right now, the delta between rpmalloc/mimalloc/snmalloc is 
less than 5 sec (for a run of 2 min 15 sec), I would assume with the Exclusive 
mode, SCUDO would fall in the same ballpark. Any other allocator that I've 
tried that does some level of locking (Hoard, ptmalloc, tcmalloc2) does not 
scale (is much slower) on many-cores machines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86694

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


[PATCH] D83004: [UpdateCCTestChecks] Include generated functions if asked

2020-09-16 Thread David Greene via Phabricator via cfe-commits
greened added a comment.

In D83004#2274687 , @jdoerfert wrote:

> 



>> Do you mean a test for recognizing the option in `common.py`?  I'm not sure 
>> what you're asking for here.
>
> The function is recognized in common.py, right? Can't you run the 
> update_test_check.py it with that option now? If so, we could have a test for 
> it, using, for example, hot-cold splitting or attributor with the 
> `-attributor-allow-deep-wrappers` and a `linkonce_odr` function that is 
> called.

Makes sense.  I'll work on it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83004

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


[PATCH] D83154: clang: Add -fcoverage-prefix-map

2020-09-16 Thread Reid "Away June-Sep" Kleckner via Phabricator via cfe-commits
rnk added a comment.

Yeah, my goal is for the build system to be able to avoid having to embed PWD 
into the compiler flags. For example, I believe it is a goal of the LLVM gn 
build system for the build tree to be relocatable. If the compiler command 
lines need to contain absolute paths to make the paths in the coverage 
relative, we won't be able to achieve that goal.

Based on all the comments that have gone before, it sounds like we want a 
`-fprofile-compilation-dir=` flag. Once we have that, would this logic work?

- if profile compilation dir set, absolutize with that as the root
- if no profile compilation dir, absolutize with CWD
- apply profile prefix map

Should `-no-canonical-prefixes` also be involved here? Unclear.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83154

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


[PATCH] D87785: [analyzer][StdLibraryFunctionsChecker] Fix a BufferSize constraint crash

2020-09-16 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:694
   // execution continues on a code whose behaviour is undefined.
   assert(SuccessSt);
   NewState = SuccessSt;

This is where we crashed before this fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87785

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


[PATCH] D87785: [analyzer][StdLibraryFunctionsChecker] Fix a BufferSize constraint crash

2020-09-16 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: steakhal, balazske, Szelethus, NoQ.
Herald added subscribers: cfe-commits, ASDenysPetrov, Charusso, gamesh411, 
dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware, xazax.hun, whisperity.
Herald added a project: clang.
martong requested review of this revision.

It could happen that both the satisfied and unsatisfied constraints gave
a NULL state. This happened probably because the negate() functionality
was not perfect. The solution is to return both states from the `assume`
calls where it makes sense.
This way the code becomes cleaner, there is no need anymore for the
controversial `negate()`.

Note that this causes a regression in our CTU builds.
http://codechecker-buildbot.eastus.cloudapp.azure.com:8080/job/ctu_pipeline_clang-master-monorepo/1720/
The error itself is not CTU related, however, the coverage and thus the path is 
different in that mode.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87785

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/std-c-library-functions.c

Index: clang/test/Analysis/std-c-library-functions.c
===
--- clang/test/Analysis/std-c-library-functions.c
+++ clang/test/Analysis/std-c-library-functions.c
@@ -126,6 +126,25 @@
   (void)fread(ptr, sz, nmem, fp); // expected-warning {{1st function call argument is an uninitialized value}}
 }
 
+static void test_fread_buffer_size_constraint_no_crash(FILE *f, size_t n) {
+  size_t rlen; /* how much to read */
+  size_t nr;   /* number of chars actually read */
+  char b[8192];
+  rlen = 8192;
+  do {
+char *p = b;
+if (rlen > n)
+  rlen = n; /* cannot read more than asked */
+nr = fread(p, sizeof(char), rlen, f);
+n -= nr; /* still have to read `n' chars */
+  } while (n > 0 && nr == rlen); /* until end of count or eof */
+}
+// Test that we do not crash here.
+void test_fread_buffer_size_constraint_no_crash_caller(FILE *f) {
+  /* read MAX_SIZE_T chars */
+  test_fread_buffer_size_constraint_no_crash(f, ~((size_t)0));
+}
+
 ssize_t getline(char **, size_t *, FILE *);
 void test_getline(FILE *fp) {
   char *line = 0;
Index: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -104,14 +104,13 @@
   public:
 ValueConstraint(ArgNo ArgN) : ArgN(ArgN) {}
 virtual ~ValueConstraint() {}
-/// Apply the effects of the constraint on the given program state. If null
-/// is returned then the constraint is not feasible.
-virtual ProgramStateRef apply(ProgramStateRef State, const CallEvent ,
-  const Summary ,
-  CheckerContext ) const = 0;
-virtual ValueConstraintPtr negate() const {
-  llvm_unreachable("Not implemented");
-};
+
+/// Apply the effects of the constraint on the given program state. Returns
+/// the program states for the cases when the constraint is satisfiable and
+/// non satisfiable.
+virtual std::pair
+apply(ProgramStateRef State, const CallEvent , const Summary ,
+  CheckerContext ) const = 0;
 
 // Check whether the constraint is malformed or not. It is malformed if the
 // specified argument has a mismatch with the given FunctionDecl (e.g. the
@@ -169,31 +168,20 @@
const Summary ) const;
 
   public:
-ProgramStateRef apply(ProgramStateRef State, const CallEvent ,
-  const Summary ,
-  CheckerContext ) const override {
+std::pair
+apply(ProgramStateRef State, const CallEvent , const Summary ,
+  CheckerContext ) const override {
   switch (Kind) {
   case OutOfRange:
-return applyAsOutOfRange(State, Call, Summary);
+return {applyAsOutOfRange(State, Call, Summary),
+applyAsWithinRange(State, Call, Summary)};
   case WithinRange:
-return applyAsWithinRange(State, Call, Summary);
+return {applyAsWithinRange(State, Call, Summary),
+applyAsOutOfRange(State, Call, Summary)};
   }
   llvm_unreachable("Unknown range kind!");
 }
 
-ValueConstraintPtr negate() const override {
-  RangeConstraint Tmp(*this);
-  switch (Kind) {
-  case OutOfRange:
-Tmp.Kind = WithinRange;
-break;
-  case WithinRange:
-Tmp.Kind = OutOfRange;
-break;
-  }
-  return std::make_shared(Tmp);
-}
-
 bool checkSpecificValidity(const FunctionDecl *FD) const override {
   const bool ValidArg =
   getArgType(FD, ArgN)->isIntegralType(FD->getASTContext());
@@ -214,36 +202,28 @@
 : 

[PATCH] D87534: Sema: introduce `__attribute__((__swift_name__))`

2020-09-16 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 292299.
compnerd marked 2 inline comments as done.
compnerd added a comment.

Address everything but warning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87534

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaObjC/attr-swift_name.m

Index: clang/test/SemaObjC/attr-swift_name.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_name.m
@@ -0,0 +1,170 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc %s
+
+#define SWIFT_NAME(name) __attribute__((__swift_name__(name)))
+
+typedef struct {
+  float x, y, z;
+} Point3D;
+
+__attribute__((__swift_name__("PType")))
+@protocol P
+@end
+
+__attribute__((__swift_name__("IClass")))
+@interface I
+- (instancetype)init SWIFT_NAME("init()");
+- (instancetype)initWithValue:(int)value SWIFT_NAME("iWithValue(_:)");
+
++ (void)refresh SWIFT_NAME("refresh()");
+
+- (instancetype)i SWIFT_NAME("i()");
+
+- (I *)iWithValue:(int)value SWIFT_NAME("i(value:)");
+- (I *)iWithValue:(int)value value:(int)value2 SWIFT_NAME("i(value:extra:)");
+- (I *)iWithValueConvertingValue:(int)value value:(int)value2 SWIFT_NAME("i(_:extra:)");
+
++ (I *)iWithOtheValue:(int)value SWIFT_NAME("init");
+// expected-warning@-1 {{parameter of '__swift_name__' attribute must be a Swift function name string}}
+
++ (I *)iWithAnotherValue:(int)value SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (I *)iWithYetAnotherValue:(int)value SWIFT_NAME("i(value:extra:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 1; got 2}}
+
++ (I *)iAndReturnErrorCode:(int *)errorCode SWIFT_NAME("i()"); // no-warning
++ (I *)iWithValue:(int)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(value:)"); // no-warning
+
++ (I *)iFromErrorCode:(const int *)errorCode SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (I *)iWithPointerA:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i()"); // no-warning
++ (I *)iWithPointerB:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(pointer:)"); // no-warning
++ (I *)iWithPointerC:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(pointer:errorCode:)"); // no-warning
+
++ (I *)iWithOtherI:(I *)other SWIFT_NAME("i()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
++ (instancetype)specialI SWIFT_NAME("init(options:)");
++ (instancetype)specialJ SWIFT_NAME("init(options:extra:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 2)}}
++ (instancetype)specialK SWIFT_NAME("init(_:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 1)}}
++ (instancetype)specialL SWIFT_NAME("i(options:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 0; got 1)}}
+
++ (instancetype)trailingParen SWIFT_NAME("foo(");
+// expected-warning@-1 {{parameter of '__swift_name__' attribute must be a Swift function name string}}
++ (instancetype)trailingColon SWIFT_NAME("foo:");
+// expected-warning@-1 {{parameter of '__swift_name__' attribute must be a Swift function name string}}
++ (instancetype)initialIgnore:(int)value SWIFT_NAME("_(value:)");
+// expected-warning@-1 {{'__swift_name__' attribute has invalid identifier for base name}}
++ (instancetype)middleOmitted:(int)value SWIFT_NAME("i(:)");
+// expected-warning@-1 {{'__swift_name__' attribute has invalid identifier for parameter name}}
+
+@property(strong) id someProp SWIFT_NAME("prop");
+@end
+
+enum SWIFT_NAME("E") E {
+  value1,
+  value2,
+  value3 SWIFT_NAME("three"),
+  value4 SWIFT_NAME("four()"), // expected-warning {{'__swift_name__' attribute has invalid identifier for base name}}
+};
+
+struct SWIFT_NAME("TStruct") SStruct {
+  int i, j, k SWIFT_NAME("kay");
+};
+
+int i SWIFT_NAME("g_i");
+
+void f0(int i) SWIFT_NAME("f_0");
+// expected-warning@-1 {{parameter of '__swift_name__' attribute must be a Swift function name string}}
+
+void f1(int i) SWIFT_NAME("f_1()");
+// expected-warning@-1 {{too few parameters in '__swift_name__' attribute (expected 1; got 0)}}
+
+void f2(int i) SWIFT_NAME("f_2(a:b:)");
+// expected-warning@-1 {{too many parameters in '__swift_name__' attribute (expected 1; got 2)}}
+
+void f3(int x, int y) SWIFT_NAME("fWithX(_:y:)");
+void f4(int x, int *error) SWIFT_NAME("fWithX(_:)");
+
+typedef int int_t SWIFT_NAME("IntType");
+
+struct Point3D createPoint3D(float x, float y, float z) 

[PATCH] D87534: Sema: introduce `__attribute__((__swift_name__))`

2020-09-16 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd marked 3 inline comments as done.
compnerd added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:104
 
+def ObjCClassMethod
+: SubsetSubjectisInstanceMethod()}],

aaron.ballman wrote:
> This change is no longer needed.
Ah, right, I'll move it to the `swift_private` change.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:4289
+if (Inline->getName() != Name && !Inline->isImplicit()) {
+  Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline;
+  Diag(CI.getLoc(), diag::note_conflicting_attribute);

aaron.ballman wrote:
> compnerd wrote:
> > aaron.ballman wrote:
> > > I think it would be more helpful if the diagnostic said why the attribute 
> > > is being ignored (because the arguments don't match).
> > Does the note below not accomplish that?
> Not really, no. The warning diagnostic itself just says that the attribute is 
> ignored, which is the effect but not the rationale. The note (which is easier 
> for folks to ignore) says the attribute is conflicting, but conflicting with 
> *what* (there could be a half dozen attributes on the same declaration, for 
> instance).
Okay, I don't think that there is an existing warning, but I should be able to 
add one.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5804-5805
+if (const auto *Method = dyn_cast(D)) {
+  ParamCount = Method->getSelector().getNumArgs();
+  Params = Method->parameters().slice(0, ParamCount);
+} else {

aaron.ballman wrote:
> compnerd wrote:
> > aaron.ballman wrote:
> > > Do you have to worry about functions with `...` variadic parameters and 
> > > how those impact counts (for either ObjC or regular methods)?
> > No, they are currently not auto-imported AFAIK.
> Should such function signatures be rejected here though? (If so, can you add 
> a test for that case as well as a test using a K C declaration like `void 
> f()`?)
I'll add a test case demonstrating that, it is indeed missing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87534

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


[PATCH] D86694: [scudo] Allow -fsanitize=scudo on Linux and Windows (WIP, don't land as is)

2020-09-16 Thread Kostya Kortchinsky via Phabricator via cfe-commits
cryptoad added a comment.

In D86694#2277371 , @aganea wrote:

> @cryptoad What happens if the primary was much smaller? Or if pages were 
> //reserved// in much smaller ranges?

The Primary can be made smaller, but this works better with the Standalone 
version as some code was added to fallback to larger class sizes if a region is 
full (Android uses 256mb per region).

> @cryptoad Does SCUDO standalone differs in any of these aspects from this 
> version?

So this requires a bit of background.
There are two models for the Thread Specific Data that holds the cached 
pointers: Shared (a pool of N caches is shared between all threads) and 
Exclusive (1 exclusive cache per thread).
For my initial port to Windows, I used the Shared model, with a pool of 32 
caches max (it's a define in the platform header). If there is more than 32 
cores, this can be increased.
I didn't try to make the Exclusive version work, mostly because I was using the 
Windows TLS API and the Shared fit right in with those, but it would get rid of 
a lot of the contention.

Overall with regard to the Standalone, it should be better on all accounts: 
faster (as we got rid of some of the quirks of sanitizer_common), lesser memory 
footprint, better reclaiming, more configurable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86694

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


[clang] 2240ca0 - [SystemZ][z/OS] Set aligned allocation unavailable by default for z/OS

2020-09-16 Thread Abhina Sreeskantharajan via cfe-commits

Author: Fanbo Meng
Date: 2020-09-16T14:49:03-04:00
New Revision: 2240ca0bd1502d7baa098da7cb4aca64a6f979d4

URL: 
https://github.com/llvm/llvm-project/commit/2240ca0bd1502d7baa098da7cb4aca64a6f979d4
DIFF: 
https://github.com/llvm/llvm-project/commit/2240ca0bd1502d7baa098da7cb4aca64a6f979d4.diff

LOG: [SystemZ][z/OS] Set aligned allocation unavailable by default for z/OS

Aligned allocation is not supported on z/OS. This patch sets 
-faligned-alloc-unavailable as default in z/OS toolchain.

Reviewed By: abhina.sreeskantharajan, hubert.reinterpretcast

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

Added: 


Modified: 
clang/include/clang/Basic/AlignedAllocation.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Basic/Targets/OSTargets.h
clang/lib/Driver/ToolChains/ZOS.cpp
clang/lib/Driver/ToolChains/ZOS.h
clang/lib/Sema/SemaExprCXX.cpp
clang/test/Driver/unavailable_aligned_allocation.cpp
clang/test/Lexer/aligned-allocation.cpp
clang/test/SemaCXX/unavailable_aligned_allocation.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/AlignedAllocation.h 
b/clang/include/clang/Basic/AlignedAllocation.h
index 88410c5cb51f..ab9f19da5d59 100644
--- a/clang/include/clang/Basic/AlignedAllocation.h
+++ b/clang/include/clang/Basic/AlignedAllocation.h
@@ -33,6 +33,8 @@ inline llvm::VersionTuple 
alignedAllocMinVersion(llvm::Triple::OSType OS) {
 return llvm::VersionTuple(11U);
   case llvm::Triple::WatchOS: // Earliest supporting version is 4.0.0.
 return llvm::VersionTuple(4U);
+  case llvm::Triple::ZOS:
+return llvm::VersionTuple(); // All z/OS versions have no support.
   }
 
   llvm_unreachable("Unexpected OS");

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index adef5b6a4495..628649a6998d 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -825,6 +825,7 @@ static llvm::StringRef 
getPlatformNameSourceSpelling(llvm::StringRef Platform) {
  .Case("macos_app_extension", "macOSApplicationExtension")
  .Case("tvos_app_extension", "tvOSApplicationExtension")
  .Case("watchos_app_extension", "watchOSApplicationExtension")
+ .Case("zos", "z/OS")
  .Default(Platform);
 }
 static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a9bd448ba026..2e265e114191 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7219,8 +7219,8 @@ def warn_overaligned_type : Warning<
   "guarantees %2 bytes">,
   InGroup, DefaultIgnore;
 def err_aligned_allocation_unavailable : Error<
-  "aligned %select{allocation|deallocation}0 function of type '%1' is only "
-  "available on %2 %3 or newer">;
+  "aligned %select{allocation|deallocation}0 function of type '%1' is "
+  "%select{only|not}4 available on %2%select{ %3 or newer|}4">;
 def note_silence_aligned_allocation_unavailable : Note<
   "if you supply your own aligned allocation functions, use "
   "-faligned-allocation to silence this diagnostic">;

diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 9c206fc7e6a4..0c06ac3cd035 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -770,6 +770,8 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo {
   // type is not declared as a typedef in system headers.
   Builder.defineMacro("__wchar_t");
 }
+
+this->PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
   }
 
 public:

diff  --git a/clang/lib/Driver/ToolChains/ZOS.cpp 
b/clang/lib/Driver/ToolChains/ZOS.cpp
index d57686b8930a..f921227076a5 100644
--- a/clang/lib/Driver/ToolChains/ZOS.cpp
+++ b/clang/lib/Driver/ToolChains/ZOS.cpp
@@ -21,3 +21,13 @@ ZOS::ZOS(const Driver , const llvm::Triple , const 
ArgList )
 : ToolChain(D, Triple, Args) {}
 
 ZOS::~ZOS() {}
+
+void ZOS::addClangTargetOptions(const ArgList ,
+ArgStringList ,
+Action::OffloadKind DeviceOffloadKind) const {
+  // Pass "-faligned-alloc-unavailable" only when the user hasn't manually
+  // enabled or disabled aligned allocations.
+  if (!DriverArgs.hasArgNoClaim(options::OPT_faligned_allocation,
+options::OPT_fno_aligned_allocation))
+CC1Args.push_back("-faligned-alloc-unavailable");
+}

diff  --git a/clang/lib/Driver/ToolChains/ZOS.h 
b/clang/lib/Driver/ToolChains/ZOS.h
index 3a90f4a12428..cace85d6da77 100644
--- a/clang/lib/Driver/ToolChains/ZOS.h
+++ b/clang/lib/Driver/ToolChains/ZOS.h
@@ -27,6 +27,10 @@ class LLVM_LIBRARY_VISIBILITY ZOS : public ToolChain {
   bool 

[PATCH] D87611: [SystemZ][z/OS] Set aligned allocation unavailable by default for z/OS

2020-09-16 Thread Abhina Sree via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2240ca0bd150: [SystemZ][z/OS] Set aligned allocation 
unavailable by default for z/OS (authored by fanbo-meng, committed by 
abhina.sreeskantharajan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87611

Files:
  clang/include/clang/Basic/AlignedAllocation.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Driver/ToolChains/ZOS.cpp
  clang/lib/Driver/ToolChains/ZOS.h
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/Driver/unavailable_aligned_allocation.cpp
  clang/test/Lexer/aligned-allocation.cpp
  clang/test/SemaCXX/unavailable_aligned_allocation.cpp

Index: clang/test/SemaCXX/unavailable_aligned_allocation.cpp
===
--- clang/test/SemaCXX/unavailable_aligned_allocation.cpp
+++ clang/test/SemaCXX/unavailable_aligned_allocation.cpp
@@ -1,12 +1,15 @@
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DMACOS %s
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DMACOS %s
 // RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DIOS %s
 // RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
 // RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DTVOS %s
 // RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
 // RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DWATCHOS %s
 // RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
+// RUN: %clang_cc1 -triple s390x-none-zos -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DZOS %s
+// RUN: %clang_cc1 -triple s390x-none-zos -fexceptions -std=c++1z -verify -DNO_ERRORS %s
+// RUN: %clang_cc1 -triple s390x-none-zos -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DZOS %s
 
 namespace std {
   typedef decltype(sizeof(0)) size_t;
@@ -62,40 +65,40 @@
 #ifdef NO_ERRORS
 // expected-no-diagnostics
 #else
-// expected-error@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
+// expected-error-re@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
 // expected-note@-17 {{if you supply your own aligned allocation functions}}
-// expected-error@-18 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-error-re@-18 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
 // expected-note@-19 {{if you supply your own aligned allocation functions}}
 
-// expected-error@-20 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
+// expected-error-re@-20 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
 // expected-note@-21 {{if you supply your own aligned allocation functions}}
-// expected-error@-22 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-error-re@-22 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
 // expected-note@-23 {{if you supply your own aligned allocation functions}}
 
-// expected-error@-24 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-error-re@-24 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
 // expected-note@-25 {{if you supply your own aligned allocation functions}}
 
-// expected-error@-26 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' is only available on}}
+// expected-error-re@-26 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' is {{only|not}} available on}}
 // expected-note@-27 {{if you supply your own 

[clang] 5c1084e - [OpenMP] Context selector extensions for template functions

2020-09-16 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2020-09-16T13:37:10-05:00
New Revision: 5c1084e8840b02d410ba125cbba466465242d820

URL: 
https://github.com/llvm/llvm-project/commit/5c1084e8840b02d410ba125cbba466465242d820
DIFF: 
https://github.com/llvm/llvm-project/commit/5c1084e8840b02d410ba125cbba466465242d820.diff

LOG: [OpenMP] Context selector extensions for template functions

With this extension the effects of `omp begin declare variant` will be
applied to template function declarations. The behavior is opt-in and
controlled by the `extension(allow_templates)` trait. While generally
useful, this will enable us to implement complex math function calls by
overloading the templates of the standard library with the ones in
libc++.

Reviewed By: JonChesterfield

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

Added: 
clang/test/AST/ast-dump-openmp-begin-declare-variant_template_2.cpp

Modified: 
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Sema/Sema.h
clang/lib/Headers/openmp_wrappers/cmath
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index e0f875a905b7..aab337a4e24a 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3679,6 +3679,7 @@ Clang provides the following context selector extensions, 
used via
 match_any
 match_none
 disable_implicit_base
+allow_templates
 
 The match extensions change when the *entire* context selector is considered a
 match for an OpenMP context. The default is ``all``, with ``none`` no trait in 
the
@@ -3690,6 +3691,11 @@ applied to a definition. If ``disable_implicit_base`` is 
given, we will not
 introduce an implicit base function for a variant if no base function was
 found. The variant is still generated but will never be called, due to the
 absence of a base function and consequently calls to a base function.
+The allow extensions change when the ``begin declare variant`` effect is
+applied to a definition. If ``allow_templates`` is given, template function
+definitions are considered as specializations of existing or assumed template
+declarations with the same name. The template parameters for the base functions
+are used to instantiate the specialization.
 
   }];
 }

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9502c104be68..9ee8e338e732 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10031,15 +10031,15 @@ class Sema final {
   /// The declarator \p D defines a function in the scope \p S which is nested
   /// in an `omp begin/end declare variant` scope. In this method we create a
   /// declaration for \p D and rename \p D according to the OpenMP context
-  /// selector of the surrounding scope.
-  FunctionDecl *
-  ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(Scope *S,
-Declarator );
+  /// selector of the surrounding scope. Return all base functions in \p Bases.
+  void ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(
+  Scope *S, Declarator , MultiTemplateParamsArg TemplateParameterLists,
+  SmallVectorImpl );
 
-  /// Register \p FD as specialization of \p BaseFD in the current `omp
-  /// begin/end declare variant` scope.
+  /// Register \p D as specialization of all base functions in \p Bases in the
+  /// current `omp begin/end declare variant` scope.
   void ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope(
-  FunctionDecl *FD, FunctionDecl *BaseFD);
+  Decl *D, SmallVectorImpl );
 
 public:
 

diff  --git a/clang/lib/Headers/openmp_wrappers/cmath 
b/clang/lib/Headers/openmp_wrappers/cmath
index bd6011eb6f6d..1aff66af7d52 100644
--- a/clang/lib/Headers/openmp_wrappers/cmath
+++ b/clang/lib/Headers/openmp_wrappers/cmath
@@ -24,8 +24,11 @@
 // which might live in cstdlib.
 #include 
 
+// We need limits because __clang_cuda_cmath.h below uses `std::numeric_limit`.
+#include 
+
 #pragma omp begin declare variant match(   
\
-device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any)})
+device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any, 
allow_templates)})
 
 #define __CUDA__
 #define __OPENMP_NVPTX__

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 184dd48c391c..34bddd2e10d7 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -939,6 +939,10 @@ static bool checkExtensionProperty(Parser , 
SourceLocation Loc,
   TraitProperty::implementation_extension_disable_implicit_base)
 return true;
 
+  

[PATCH] D85878: [OpenMP] Context selector extensions for return value overloading

2020-09-16 Thread Johannes Doerfert via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc4b7a1da9d87: [OpenMP] Context selector extensions for 
return value overloading (authored by jdoerfert).

Changed prior to commit:
  https://reviews.llvm.org/D85878?vs=285262=292291#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85878

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant-varying-return.c
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -1118,6 +1118,7 @@
 __OMP_TRAIT_PROPERTY(implementation, extension, match_all)
 __OMP_TRAIT_PROPERTY(implementation, extension, match_any)
 __OMP_TRAIT_PROPERTY(implementation, extension, match_none)
+__OMP_TRAIT_PROPERTY(implementation, extension, disable_implicit_base)
 
 __OMP_TRAIT_SET(user)
 
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant-varying-return.c
===
--- /dev/null
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant-varying-return.c
@@ -0,0 +1,401 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s-DUSE_FLOAT | FileCheck %s --check-prefix=C_FLOAT
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s -x c++ -DUSE_FLOAT | FileCheck %s --check-prefix=CXX_FLOAT
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s| FileCheck %s --check-prefix=C_INT
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s -x c++ | FileCheck %s --check-prefix=CXX_INT
+// expected-no-diagnostics
+
+#ifdef __cplusplus
+#define OVERLOADABLE
+#else
+#define OVERLOADABLE __attribute__((overloadable))
+#endif
+
+#ifdef USE_FLOAT
+#define RETURN_TY float
+#define BEFORE_BASE_RETURN_VALUE 0
+#define BEFORE_VARIANT_RETURN_VALUE 1
+#define AFTER__BASE_RETURN_VALUE 1
+#define AFTER__VARIANT_RETURN_VALUE 0
+#else
+#define RETURN_TY int
+#define BEFORE_BASE_RETURN_VALUE 1
+#define BEFORE_VARIANT_RETURN_VALUE 0
+#define AFTER__BASE_RETURN_VALUE 0
+#define AFTER__VARIANT_RETURN_VALUE 1
+#endif
+
+OVERLOADABLE
+RETURN_TY also_before(void) {
+  return BEFORE_BASE_RETURN_VALUE;
+}
+OVERLOADABLE
+RETURN_TY also_before(int i) {
+  return BEFORE_BASE_RETURN_VALUE;
+}
+
+#pragma omp begin declare variant match(implementation = {extension(disable_implicit_base)})
+OVERLOADABLE
+int also_before(void) {
+  return BEFORE_VARIANT_RETURN_VALUE;
+}
+OVERLOADABLE
+int also_before(int i) {
+  return BEFORE_VARIANT_RETURN_VALUE;
+}
+
+OVERLOADABLE
+int also_after(double d) {
+  return AFTER__VARIANT_RETURN_VALUE;
+}
+OVERLOADABLE
+int also_after(long l) {
+  return AFTER__VARIANT_RETURN_VALUE;
+}
+#pragma omp end declare variant
+
+OVERLOADABLE
+RETURN_TY also_after(double d) {
+  return AFTER__BASE_RETURN_VALUE;
+}
+OVERLOADABLE
+RETURN_TY also_after(long l) {
+  return AFTER__BASE_RETURN_VALUE;
+}
+
+int main() {
+  // Should return 0.
+  return also_before() + also_before(1) + also_before(2.0f) + also_after(3.0) + also_after(4L);
+}
+
+// Make sure we see base calls in the FLOAT versions, that is no
+// PseudoObjectExpr in those. In the INT versions we want PseudoObjectExpr (=
+// variant calls) for the `*_before` functions but not the `*_after` ones
+// (first 3 vs 2 last ones).
+
+// C_FLOAT:  |-FunctionDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, line:30:1> line:28:11 used also_before 'float ({{.*}})'
+// C_FLOAT-NEXT: | |-CompoundStmt [[ADDR_1:0x[a-z0-9]*]] 
+// C_FLOAT-NEXT: | | `-ReturnStmt [[ADDR_2:0x[a-z0-9]*]] 
+// C_FLOAT-NEXT: | |   `-ImplicitCastExpr [[ADDR_3:0x[a-z0-9]*]]  'float' 
+// C_FLOAT-NEXT: | | `-IntegerLiteral [[ADDR_4:0x[a-z0-9]*]]  'int' 0
+// C_FLOAT-NEXT: | `-OverloadableAttr [[ADDR_5:0x[a-z0-9]*]] 
+// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_6:0x[a-z0-9]*]]  line:32:11 used also_before 'float (int)'
+// C_FLOAT-NEXT: | |-ParmVarDecl [[ADDR_7:0x[a-z0-9]*]]  col:27 i 'int'
+// C_FLOAT-NEXT: | |-CompoundStmt [[ADDR_8:0x[a-z0-9]*]] 
+// C_FLOAT-NEXT: | | `-ReturnStmt [[ADDR_9:0x[a-z0-9]*]] 
+// C_FLOAT-NEXT: | |   `-ImplicitCastExpr [[ADDR_10:0x[a-z0-9]*]]  'float' 
+// C_FLOAT-NEXT: | | `-IntegerLiteral [[ADDR_11:0x[a-z0-9]*]]  'int' 0
+// C_FLOAT-NEXT: | `-OverloadableAttr [[ADDR_12:0x[a-z0-9]*]] 
+// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_13:0x[a-z0-9]*]]  line:10:22 also_before[implementation={extension(disable_implicit_base)}] 'int ({{.*}})'
+// C_FLOAT-NEXT: | |-CompoundStmt [[ADDR_14:0x[a-z0-9]*]] 
+// C_FLOAT-NEXT: | | `-ReturnStmt [[ADDR_15:0x[a-z0-9]*]] 
+// C_FLOAT-NEXT: | |   

[PATCH] D85879: [OpenMP] Overload `std::isnan` and friends multiple times for the GPU

2020-09-16 Thread Johannes Doerfert via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG97652202d1e6: [OpenMP] Overload `std::isnan` and friends 
multiple times for the GPU (authored by jdoerfert).

Changed prior to commit:
  https://reviews.llvm.org/D85879?vs=285385=292292#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85879

Files:
  clang/lib/Headers/__clang_cuda_cmath.h
  clang/test/Headers/Inputs/include/cmath
  clang/test/Headers/openmp_device_math_isnan.cpp

Index: clang/test/Headers/openmp_device_math_isnan.cpp
===
--- /dev/null
+++ clang/test/Headers/openmp_device_math_isnan.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -x c++ -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix=BOOL_RETURN
+// RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc -ffast-math -ffp-contract=fast
+// RUN: %clang_cc1 -x c++ -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -ffast-math -ffp-contract=fast | FileCheck %s --check-prefix=BOOL_RETURN
+// RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc -DUSE_ISNAN_WITH_INT_RETURN
+// RUN: %clang_cc1 -x c++ -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -DUSE_ISNAN_WITH_INT_RETURN | FileCheck %s --check-prefix=INT_RETURN
+// RUN: %clang_cc1 -x c++ -internal-isystem %S/Inputs/include -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc -ffast-math -ffp-contract=fast -DUSE_ISNAN_WITH_INT_RETURN
+// RUN: %clang_cc1 -x c++ -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -ffast-math -ffp-contract=fast -DUSE_ISNAN_WITH_INT_RETURN | FileCheck %s --check-prefix=INT_RETURN
+// expected-no-diagnostics
+
+#include 
+
+double math(float f, double d) {
+  double r = 0;
+  // INT_RETURN: call i32 @__nv_isnanf(float
+  // BOOL_RETURN: call i32 @__nv_isnanf(float
+  r += std::isnan(f);
+  // INT_RETURN: call i32 @__nv_isnand(double
+  // BOOL_RETURN: call i32 @__nv_isnand(double
+  r += std::isnan(d);
+  return r;
+}
+
+long double foo(float f, double d, long double ld) {
+  double r = ld;
+  r += math(f, d);
+#pragma omp target map(r)
+  { r += math(f, d); }
+  return r;
+}
Index: clang/test/Headers/Inputs/include/cmath
===
--- clang/test/Headers/Inputs/include/cmath
+++ clang/test/Headers/Inputs/include/cmath
@@ -82,8 +82,13 @@
 bool islessgreater(double, double);
 bool islessgreater(float, float);
 bool isnan(long double);
+#ifdef USE_ISNAN_WITH_INT_RETURN
+int isnan(double);
+int isnan(float);
+#else
 bool isnan(double);
 bool isnan(float);
+#endif
 bool isnormal(double);
 bool isnormal(float);
 bool isunordered(double, double);
Index: clang/lib/Headers/__clang_cuda_cmath.h
===
--- clang/lib/Headers/__clang_cuda_cmath.h
+++ clang/lib/Headers/__clang_cuda_cmath.h
@@ -66,10 +66,38 @@
 }
 
 // For inscrutable reasons, the CUDA headers define these functions for us on
-// Windows. For OpenMP we omit these as some old system headers have
-// non-conforming `isinf(float)` and `isnan(float)` implementations that return
-// an `int`. The system versions of these functions should be fine anyway.
-#if !defined(_MSC_VER) && !defined(__OPENMP_NVPTX__)
+// 

[PATCH] D85877: [OpenMP] Support nested OpenMP context selectors (declare variant)

2020-09-16 Thread Johannes Doerfert via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5c63ae156e96: [OpenMP] Support nested OpenMP context 
selectors (declare variant) (authored by jdoerfert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85877

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_nested.c
  clang/test/OpenMP/declare_variant_messages.c

Index: clang/test/OpenMP/declare_variant_messages.c
===
--- clang/test/OpenMP/declare_variant_messages.c
+++ clang/test/OpenMP/declare_variant_messages.c
@@ -153,3 +153,17 @@
 #pragma omp declare variant // expected-error {{function declaration is expected after 'declare variant' directive}}
 
 #pragma omp declare variant // expected-error {{function declaration is expected after 'declare variant' directive}}
+
+// FIXME: If the scores are equivalent we should detect that and allow it.
+#pragma omp begin declare variant match(implementation = {vendor(score(2) \
+ : llvm)})
+#pragma omp declare variant(foo) match(implementation = {vendor(score(2) \
+: llvm)}) // expected-error@-1 {{nested OpenMP context selector contains duplicated trait 'llvm' in selector 'vendor' and set 'implementation' with different score}}
+int conflicting_nested_score(void);
+#pragma omp end declare variant
+
+// FIXME: We should build the conjuction of different conditions, see also the score fixme above.
+#pragma omp begin declare variant match(user = {condition(1)})
+#pragma omp declare variant(foo) match(user = {condition(1)}) // expected-error {{nested user conditions in OpenMP context selector not supported (yet)}}
+int conflicting_nested_condition(void);
+#pragma omp end declare variant
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_nested.c
===
--- /dev/null
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_nested.c
@@ -0,0 +1,87 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s   | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s -x c++| FileCheck %s
+// expected-no-diagnostics
+
+int also_before(void) {
+  return 1;
+}
+
+#pragma omp begin declare variant match(user = {condition(1)}, device = {kind(cpu)}, implementation = {vendor(llvm)})
+#pragma omp begin declare variant match(device = {kind(cpu)}, implementation = {vendor(llvm, pgi), extension(match_any)})
+#pragma omp begin declare variant match(device = {kind(any)}, implementation = {dynamic_allocators})
+int also_after(void) {
+  return 0;
+}
+int also_before(void) {
+  return 0;
+}
+#pragma omp end declare variant
+#pragma omp end declare variant
+#pragma omp end declare variant
+
+int also_after(void) {
+  return 2;
+}
+
+int test() {
+  // Should return 0.
+  return also_after() + also_before();
+}
+
+#pragma omp begin declare variant match(device = {isa("sse")})
+#pragma omp declare variant(test) match(device = {isa(sse)})
+int equivalent_isa_trait(void);
+#pragma omp end declare variant
+
+#pragma omp begin declare variant match(device = {isa("sse")})
+#pragma omp declare variant(test) match(device = {isa("sse2")})
+int non_equivalent_isa_trait(void);
+#pragma omp end declare variant
+
+// CHECK:  |-FunctionDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, line:7:1> line:5:5 used also_before 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_1:0x[a-z0-9]*]] 
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_2:0x[a-z0-9]*]] 
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_3:0x[a-z0-9]*]]  'int' 1
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_4:0x[a-z0-9]*]] <> Implicit device={kind(any, cpu)}, implementation={dynamic_allocators, vendor(llvm, pgi), extension(match_any)}, user={condition(1)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_5:0x[a-z0-9]*]]  'int ({{.*}})' {{.*}}Function [[ADDR_6:0x[a-z0-9]*]] 'also_before[device={kind(any, cpu)}, implementation={dynamic_allocators, vendor(llvm, pgi), extension(match_any)}, user={condition(...)}]' 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_7:0x[a-z0-9]*]]  col:5 implicit used also_after 'int ({{.*}})'
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_8:0x[a-z0-9]*]] <> Implicit device={kind(any, cpu)}, implementation={dynamic_allocators, vendor(llvm, pgi), extension(match_any)}, user={condition(1)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_9:0x[a-z0-9]*]]  'int ({{.*}})' {{.*}}Function [[ADDR_10:0x[a-z0-9]*]] 'also_after[device={kind(any, 

[clang] 9765220 - [OpenMP] Overload `std::isnan` and friends multiple times for the GPU

2020-09-16 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2020-09-16T13:37:09-05:00
New Revision: 97652202d1e6964d5d7a1c03a257452c7ad95233

URL: 
https://github.com/llvm/llvm-project/commit/97652202d1e6964d5d7a1c03a257452c7ad95233
DIFF: 
https://github.com/llvm/llvm-project/commit/97652202d1e6964d5d7a1c03a257452c7ad95233.diff

LOG: [OpenMP] Overload `std::isnan` and friends multiple times for the GPU

`std::isnan` and friends can be found in two variants in the wild, one
returns `bool`, as the standard defines it, one returns `int`, as the C
macros do. So far we kinda hoped the system versions of these functions
will work for people, e.g. they are definitions that can be compiled for
the target. We know that is not the case always so we leverage the
`disable_implicit_base` OpenMP context extension to specialize both
versions of these functions without causing an invalid redeclaration.

Reviewed By: JonChesterfield, tra

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

Added: 
clang/test/Headers/openmp_device_math_isnan.cpp

Modified: 
clang/lib/Headers/__clang_cuda_cmath.h
clang/test/Headers/Inputs/include/cmath

Removed: 




diff  --git a/clang/lib/Headers/__clang_cuda_cmath.h 
b/clang/lib/Headers/__clang_cuda_cmath.h
index 8ba182689a4f..f49463d72e04 100644
--- a/clang/lib/Headers/__clang_cuda_cmath.h
+++ b/clang/lib/Headers/__clang_cuda_cmath.h
@@ -66,10 +66,38 @@ __DEVICE__ float frexp(float __arg, int *__exp) {
 }
 
 // For inscrutable reasons, the CUDA headers define these functions for us on
-// Windows. For OpenMP we omit these as some old system headers have
-// non-conforming `isinf(float)` and `isnan(float)` implementations that return
-// an `int`. The system versions of these functions should be fine anyway.
-#if !defined(_MSC_VER) && !defined(__OPENMP_NVPTX__)
+// Windows.
+#if !defined(_MSC_VER) || defined(__OPENMP_NVPTX__)
+
+// For OpenMP we work around some old system headers that have non-conforming
+// `isinf(float)` and `isnan(float)` implementations that return an `int`. We 
do
+// this by providing two versions of these functions, 
diff ering only in the
+// return type. To avoid conflicting definitions we disable implicit base
+// function generation. That means we will end up with two specializations, one
+// per type, but only one has a base function defined by the system header.
+#if defined(__OPENMP_NVPTX__)
+#pragma omp begin declare variant match(   
\
+implementation = {extension(disable_implicit_base)})
+
+// FIXME: We lack an extension to customize the mangling of the variants, e.g.,
+//add a suffix. This means we would clash with the names of the 
variants
+//(note that we do not create implicit base functions here). To avoid
+//this clash we add a new trait to some of them that is always true
+//(this is LLVM after all ;)). It will only influence the mangled name
+//of the variants inside the inner region and avoid the clash.
+#pragma omp begin declare variant match(implementation = {vendor(llvm)})
+
+__DEVICE__ int isinf(float __x) { return ::__isinff(__x); }
+__DEVICE__ int isinf(double __x) { return ::__isinf(__x); }
+__DEVICE__ int isfinite(float __x) { return ::__finitef(__x); }
+__DEVICE__ int isfinite(double __x) { return ::__isfinited(__x); }
+__DEVICE__ int isnan(float __x) { return ::__isnanf(__x); }
+__DEVICE__ int isnan(double __x) { return ::__isnan(__x); }
+
+#pragma omp end declare variant
+
+#endif
+
 __DEVICE__ bool isinf(float __x) { return ::__isinff(__x); }
 __DEVICE__ bool isinf(double __x) { return ::__isinf(__x); }
 __DEVICE__ bool isfinite(float __x) { return ::__finitef(__x); }
@@ -79,6 +107,11 @@ __DEVICE__ bool isfinite(float __x) { return 
::__finitef(__x); }
 __DEVICE__ bool isfinite(double __x) { return ::__isfinited(__x); }
 __DEVICE__ bool isnan(float __x) { return ::__isnanf(__x); }
 __DEVICE__ bool isnan(double __x) { return ::__isnan(__x); }
+
+#if defined(__OPENMP_NVPTX__)
+#pragma omp end declare variant
+#endif
+
 #endif
 
 __DEVICE__ bool isgreater(float __x, float __y) {

diff  --git a/clang/test/Headers/Inputs/include/cmath 
b/clang/test/Headers/Inputs/include/cmath
index 5e4e8b67514f..20e34898b553 100644
--- a/clang/test/Headers/Inputs/include/cmath
+++ b/clang/test/Headers/Inputs/include/cmath
@@ -82,8 +82,13 @@ bool isless(float, float);
 bool islessgreater(double, double);
 bool islessgreater(float, float);
 bool isnan(long double);
+#ifdef USE_ISNAN_WITH_INT_RETURN
+int isnan(double);
+int isnan(float);
+#else
 bool isnan(double);
 bool isnan(float);
+#endif
 bool isnormal(double);
 bool isnormal(float);
 bool isunordered(double, double);

diff  --git a/clang/test/Headers/openmp_device_math_isnan.cpp 
b/clang/test/Headers/openmp_device_math_isnan.cpp
new file mode 100644
index ..35443dbdebea
--- /dev/null
+++ b/clang/test/Headers/openmp_device_math_isnan.cpp

[clang] 56069b5 - [OpenMP] Support `std::complex` math functions in target regions

2020-09-16 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2020-09-16T13:37:10-05:00
New Revision: 56069b5c71ca78749aa983c1e9de6f1e4c049f4b

URL: 
https://github.com/llvm/llvm-project/commit/56069b5c71ca78749aa983c1e9de6f1e4c049f4b
DIFF: 
https://github.com/llvm/llvm-project/commit/56069b5c71ca78749aa983c1e9de6f1e4c049f4b.diff

LOG: [OpenMP] Support `std::complex` math functions in target regions

The last (big) missing piece to get "math" working in OpenMP target
regions (that I know of) was complex math functions, e.g.,
`std::sin(std::complex)`. With this patch we overload the system
template functions for these operations with versions that have been
distilled from `libcxx/include/complex`. We use the same
  `omp begin/end declare variant`
mechanism we use for other math functions before, except that we this
time overload templates (via D85735).

Reviewed By: JonChesterfield

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

Added: 
clang/lib/Headers/openmp_wrappers/complex_cmath.h
clang/test/Headers/Inputs/include/type_traits

Modified: 
clang/lib/Headers/CMakeLists.txt
clang/lib/Headers/openmp_wrappers/complex
clang/test/Headers/Inputs/include/complex
clang/test/Headers/nvptx_device_math_complex.cpp

Removed: 




diff  --git a/clang/lib/Headers/CMakeLists.txt 
b/clang/lib/Headers/CMakeLists.txt
index 0692fe75a441..a9761f049067 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -154,6 +154,7 @@ set(openmp_wrapper_files
   openmp_wrappers/complex.h
   openmp_wrappers/complex
   openmp_wrappers/__clang_openmp_device_functions.h
+  openmp_wrappers/complex_cmath.h
   openmp_wrappers/new
 )
 

diff  --git a/clang/lib/Headers/openmp_wrappers/complex 
b/clang/lib/Headers/openmp_wrappers/complex
index 1ed0b14879ef..306ffe208053 100644
--- a/clang/lib/Headers/openmp_wrappers/complex
+++ b/clang/lib/Headers/openmp_wrappers/complex
@@ -23,3 +23,28 @@
 
 // Grab the host header too.
 #include_next 
+
+
+#ifdef __cplusplus
+
+// If we are compiling against libc++, the macro _LIBCPP_STD_VER should be set
+// after including  above. Since the complex header we use is a
+// simplified version of the libc++, we don't need it in this case. If we
+// compile against libstdc++, or any other standard library, we will overload
+// the (hopefully template) functions in the  header with the ones we
+// got from libc++ which decomposes math functions, like `std::sin`, into
+// arithmetic and calls to non-complex functions, all of which we can then
+// handle.
+#ifndef _LIBCPP_STD_VER
+
+#pragma omp begin declare variant match(   
\
+device = {arch(nvptx, nvptx64)},   
\
+implementation = {extension(match_any, allow_templates)})
+
+#include 
+
+#pragma omp end declare variant
+
+#endif
+
+#endif

diff  --git a/clang/lib/Headers/openmp_wrappers/complex_cmath.h 
b/clang/lib/Headers/openmp_wrappers/complex_cmath.h
new file mode 100644
index ..e3d9aebbbc24
--- /dev/null
+++ b/clang/lib/Headers/openmp_wrappers/complex_cmath.h
@@ -0,0 +1,388 @@
+//===- __complex_cmath.h 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// std::complex header copied from the libcxx source and simplified for use in
+// OpenMP target offload regions.
+//
+//===--===//
+
+#ifndef _OPENMP
+#error "This file is for OpenMP compilation only."
+#endif
+
+#ifndef __cplusplus
+#error "This file is for C++ compilation only."
+#endif
+
+#ifndef _LIBCPP_COMPLEX
+#define _LIBCPP_COMPLEX
+
+#include 
+#include 
+
+#define __DEVICE__ static constexpr __attribute__((nothrow))
+
+namespace std {
+
+// abs
+
+template  __DEVICE__ _Tp abs(const std::complex<_Tp> &__c) {
+  return hypot(__c.real(), __c.imag());
+}
+
+// arg
+
+template  __DEVICE__ _Tp arg(const std::complex<_Tp> &__c) {
+  return atan2(__c.imag(), __c.real());
+}
+
+template 
+typename enable_if::value || is_same<_Tp, double>::value,
+   double>::type
+arg(_Tp __re) {
+  return atan2(0., __re);
+}
+
+template 
+typename enable_if::value, float>::type arg(_Tp __re) {
+  return atan2f(0.F, __re);
+}
+
+// norm
+
+template  __DEVICE__ _Tp norm(const std::complex<_Tp> &__c) {
+  if (std::isinf(__c.real()))
+return abs(__c.real());
+  if (std::isinf(__c.imag()))
+return abs(__c.imag());
+  return __c.real() * __c.real() + __c.imag() * __c.imag();
+}
+
+// conj
+
+template  std::complex<_Tp> conj(const std::complex<_Tp> &__c) {
+  return std::complex<_Tp>(__c.real(), -__c.imag());
+}
+
+// proj
+

[PATCH] D85735: [OpenMP] Context selector extensions for template functions

2020-09-16 Thread Johannes Doerfert via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
jdoerfert marked 2 inline comments as done.
Closed by commit rG5c1084e8840b: [OpenMP] Context selector extensions for 
template functions (authored by jdoerfert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85735

Files:
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Headers/openmp_wrappers/cmath
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_template_2.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -1119,6 +1119,7 @@
 __OMP_TRAIT_PROPERTY(implementation, extension, match_any)
 __OMP_TRAIT_PROPERTY(implementation, extension, match_none)
 __OMP_TRAIT_PROPERTY(implementation, extension, disable_implicit_base)
+__OMP_TRAIT_PROPERTY(implementation, extension, allow_templates)
 
 __OMP_TRAIT_SET(user)
 
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_template_2.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_template_2.cpp
@@ -0,0 +1,264 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s -x c++ | FileCheck %s
+// expected-no-diagnostics
+
+template 
+int also_before(T) {
+  return 1;
+}
+template 
+int also_before_mismatch(void) {
+  return 0;
+}
+int also_before_non_template(void) {
+  return 0;
+}
+
+#pragma omp begin declare variant match(implementation = {extension(allow_templates)})
+template 
+int also_before(T) {
+  return 0;
+}
+template 
+int also_after(T) {
+  return 0;
+}
+template 
+int also_after_mismatch(T, Q) {
+  return 2;
+}
+template 
+int also_before_mismatch(T) {
+  return 3;
+}
+template 
+int also_before_non_template(T) {
+  return 4;
+}
+template 
+int only_def(void) {
+  return 0;
+}
+#pragma omp end declare variant
+
+template 
+int also_after(T) {
+  return 6;
+}
+template 
+int also_after_mismatch(T) {
+  return 0;
+}
+
+int test() {
+  // Should return 0.
+  return also_before(0.) + also_before_mismatch<0>() + also_before_non_template() + also_after(0) + also_after_mismatch(0) + only_def<0>();
+}
+
+// CHECK:  |-FunctionTemplateDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, line:7:1> line:5:5 also_before
+// CHECK-NEXT: | |-TemplateTypeParmDecl [[ADDR_1:0x[a-z0-9]*]]  col:20 referenced typename depth 0 index 0 T
+// CHECK-NEXT: | |-FunctionDecl [[ADDR_2:0x[a-z0-9]*]]  line:5:5 also_before 'int (T)'
+// CHECK-NEXT: | | |-ParmVarDecl [[ADDR_3:0x[a-z0-9]*]]  col:18 'T'
+// CHECK-NEXT: | | |-CompoundStmt [[ADDR_4:0x[a-z0-9]*]] 
+// CHECK-NEXT: | | | `-ReturnStmt [[ADDR_5:0x[a-z0-9]*]] 
+// CHECK-NEXT: | | |   `-IntegerLiteral [[ADDR_6:0x[a-z0-9]*]]  'int' 1
+// CHECK-NEXT: | | `-OMPDeclareVariantAttr [[ADDR_7:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)}
+// CHECK-NEXT: | |   `-DeclRefExpr [[ADDR_8:0x[a-z0-9]*]]  'int (T)' {{.*}}Function [[ADDR_9:0x[a-z0-9]*]] 'also_before[implementation={extension(allow_templates)}]' 'int (T)'
+// CHECK-NEXT: | `-FunctionDecl [[ADDR_10:0x[a-z0-9]*]]  line:5:5 used also_before 'int (double)'
+// CHECK-NEXT: |   |-TemplateArgument type 'double'
+// CHECK-NEXT: |   | `-BuiltinType [[ADDR_11:0x[a-z0-9]*]] 'double'
+// CHECK-NEXT: |   |-ParmVarDecl [[ADDR_12:0x[a-z0-9]*]]  col:18 'double':'double'
+// CHECK-NEXT: |   |-CompoundStmt [[ADDR_13:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   | `-ReturnStmt [[ADDR_14:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   |   `-IntegerLiteral [[ADDR_6]]  'int' 1
+// CHECK-NEXT: |   `-OMPDeclareVariantAttr [[ADDR_15:0x[a-z0-9]*]] <> Implicit implementation={extension(allow_templates)}
+// CHECK-NEXT: | `-DeclRefExpr [[ADDR_16:0x[a-z0-9]*]]  'int (double)' {{.*}}Function [[ADDR_17:0x[a-z0-9]*]] 'also_before[implementation={extension(allow_templates)}]' 'int (double)'
+// CHECK-NEXT: |-FunctionTemplateDecl [[ADDR_18:0x[a-z0-9]*]]  line:9:5 also_before_mismatch
+// CHECK-NEXT: | |-NonTypeTemplateParmDecl [[ADDR_19:0x[a-z0-9]*]]  col:15 'int' depth 0 index 0 V
+// CHECK-NEXT: | |-FunctionDecl [[ADDR_20:0x[a-z0-9]*]]  line:9:5 also_before_mismatch 'int ({{.*}})'
+// CHECK-NEXT: | | `-CompoundStmt [[ADDR_21:0x[a-z0-9]*]] 
+// CHECK-NEXT: | |   `-ReturnStmt [[ADDR_22:0x[a-z0-9]*]] 
+// CHECK-NEXT: | | `-IntegerLiteral [[ADDR_23:0x[a-z0-9]*]]  'int' 0
+// CHECK-NEXT: | `-FunctionDecl [[ADDR_24:0x[a-z0-9]*]]  line:9:5 used also_before_mismatch 'int ({{.*}})'
+// CHECK-NEXT: |   |-TemplateArgument integral 0
+// CHECK-NEXT: |   `-CompoundStmt 

[clang] c4b7a1d - [OpenMP] Context selector extensions for return value overloading

2020-09-16 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2020-09-16T13:37:09-05:00
New Revision: c4b7a1da9d872ed075ce99c80a90b11a135577a0

URL: 
https://github.com/llvm/llvm-project/commit/c4b7a1da9d872ed075ce99c80a90b11a135577a0
DIFF: 
https://github.com/llvm/llvm-project/commit/c4b7a1da9d872ed075ce99c80a90b11a135577a0.diff

LOG: [OpenMP] Context selector extensions for return value overloading

This extension allows to declare variants in between `omp begin/end
declare variant` that do not match the type of the existing function
with that name. Without this extension we would not find a base function
(with a compatible type), therefore create a new one, which would
cause conflicting declarations. With this extension we will not create
"missing" base functions, which basically renders these specializations
harmless. They will be generated but never called.

Reviewed By: JonChesterfield

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

Added: 
clang/test/AST/ast-dump-openmp-begin-declare-variant-varying-return.c

Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/Basic/AttrDocs.td
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 35ab8ff39efa..d101fcf214b5 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -7856,6 +7856,23 @@ class OMPTraitInfo {
   /// Return a string representation identifying this context selector.
   std::string getMangledName() const;
 
+  /// Check the extension trait \p TP is active.
+  bool isExtensionActive(llvm::omp::TraitProperty TP) {
+for (const OMPTraitSet  : Sets) {
+  if (Set.Kind != llvm::omp::TraitSet::implementation)
+continue;
+  for (const OMPTraitSelector  : Set.Selectors) {
+if (Selector.Kind != 
llvm::omp::TraitSelector::implementation_extension)
+  continue;
+for (const OMPTraitProperty  : Selector.Properties) {
+  if (Property.Kind == TP)
+return true;
+}
+  }
+}
+return false;
+  }
+
   /// Print a human readable representation into \p OS.
   void print(llvm::raw_ostream , const PrintingPolicy ) const;
 };

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 8706a3f4578c..e0f875a905b7 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3678,12 +3678,18 @@ Clang provides the following context selector 
extensions, used via
 match_all
 match_any
 match_none
+disable_implicit_base
 
 The match extensions change when the *entire* context selector is considered a
 match for an OpenMP context. The default is ``all``, with ``none`` no trait in 
the
 selector is allowed to be in the OpenMP context, with ``any`` a single trait in
 both the selector and OpenMP context is sufficient. Only a single match
 extension trait is allowed per context selector.
+The disable extensions remove default effects of the ``begin declare variant``
+applied to a definition. If ``disable_implicit_base`` is given, we will not
+introduce an implicit base function for a variant if no base function was
+found. The variant is still generated but will never be called, due to the
+absence of a base function and consequently calls to a base function.
 
   }];
 }

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 40124264fdb9..184dd48c391c 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -935,6 +935,10 @@ static bool checkExtensionProperty(Parser , 
SourceLocation Loc,
   if (TIProperty.Kind == TraitProperty::invalid)
 return false;
 
+  if (TIProperty.Kind ==
+  TraitProperty::implementation_extension_disable_implicit_base)
+return true;
+
   auto IsMatchExtension = [](OMPTraitProperty ) {
 return (TP.Kind ==
 llvm::omp::TraitProperty::implementation_extension_match_all ||

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index aef043b06299..36c257440a48 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5871,6 +5871,7 @@ 
Sema::OMPDeclareVariantScope::OMPDeclareVariantScope(OMPTraitInfo )
 FunctionDecl *
 Sema::ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(Scope *S,
 Declarator ) 
{
+  OMPDeclareVariantScope  = OMPDeclareVariantScopes.back();
   IdentifierInfo *BaseII = D.getIdentifier();
   LookupResult Lookup(*this, DeclarationName(BaseII), D.getIdentifierLoc(),
   LookupOrdinaryName);
@@ -5905,12 +5906,15 @@ 
Sema::ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(Scope *S,
 BaseFD = UDecl;
 break;
   }
-  

[PATCH] D85777: [OpenMP] Support std::complex math functions in target regions

2020-09-16 Thread Johannes Doerfert via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG56069b5c71ca: [OpenMP] Support `std::complex` math functions 
in target regions (authored by jdoerfert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85777

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/openmp_wrappers/complex
  clang/lib/Headers/openmp_wrappers/complex_cmath.h
  clang/test/Headers/Inputs/include/complex
  clang/test/Headers/Inputs/include/type_traits
  clang/test/Headers/nvptx_device_math_complex.cpp

Index: clang/test/Headers/nvptx_device_math_complex.cpp
===
--- clang/test/Headers/nvptx_device_math_complex.cpp
+++ clang/test/Headers/nvptx_device_math_complex.cpp
@@ -3,6 +3,7 @@
 // RUN: %clang_cc1 -verify -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem %S/Inputs/include -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -aux-triple powerpc64le-unknown-unknown -o - | FileCheck %s
 // expected-no-diagnostics
 
+#include 
 #include 
 
 // CHECK: define weak {{.*}} @__muldc3
@@ -33,6 +34,12 @@
 // CHECK-DAG: call float @__nv_fabsf(
 // CHECK-DAG: call float @__nv_logbf(
 
+// We actually check that there are no declarations of non-OpenMP functions.
+// That is, as long as we don't call an unkown function with a name that
+// doesn't start with '__' we are good :)
+
+// CHECK-NOT: declare.*@[^_]
+
 void test_scmplx(std::complex a) {
 #pragma omp target
   {
@@ -46,3 +53,35 @@
 (void)(a * (a / a));
   }
 }
+
+template 
+std::complex test_template_math_calls(std::complex a) {
+  decltype(a) r = a;
+#pragma omp target
+  {
+r = std::sin(r);
+r = std::cos(r);
+r = std::exp(r);
+r = std::atan(r);
+r = std::acos(r);
+  }
+  return r;
+}
+
+std::complex test_scall(std::complex a) {
+  decltype(a) r;
+#pragma omp target
+  {
+r = std::sin(a);
+  }
+  return test_template_math_calls(r);
+}
+
+std::complex test_dcall(std::complex a) {
+  decltype(a) r;
+#pragma omp target
+  {
+r = std::exp(a);
+  }
+  return test_template_math_calls(r);
+}
Index: clang/test/Headers/Inputs/include/type_traits
===
--- /dev/null
+++ clang/test/Headers/Inputs/include/type_traits
@@ -0,0 +1,43 @@
+/// Copied from libcxx type_traits and simplified
+
+#pragma once
+
+namespace std {
+
+template 
+struct integral_constant {
+  static const _Tp value = __v;
+  typedef _Tp value_type;
+  typedef integral_constant type;
+};
+
+typedef integral_constant true_type;
+typedef integral_constant false_type;
+
+// is_same, functional
+template  struct is_same : public false_type {};
+template  struct is_same<_Tp, _Tp> : public true_type {};
+
+// is_integral, for some types.
+template  struct is_integral
+: public integral_constant {};
+template <> struct is_integral
+: public integral_constant {};
+template <> struct is_integral
+: public integral_constant {};
+template <> struct is_integral
+: public integral_constant {};
+template <> struct is_integral
+: public integral_constant {};
+template <> struct is_integral
+: public integral_constant {};
+template <> struct is_integral
+: public integral_constant {};
+
+// enable_if, functional
+template  struct enable_if{};
+template  struct enable_if{
+  using type = _Tp;
+};
+
+}
Index: clang/test/Headers/Inputs/include/complex
===
--- clang/test/Headers/Inputs/include/complex
+++ clang/test/Headers/Inputs/include/complex
@@ -3,6 +3,7 @@
 #include 
 
 #define INFINITY (__builtin_inff())
+#define NAN (__builtin_nanf (""))
 
 namespace std {
 
@@ -298,4 +299,114 @@
   return !(__x == __y);
 }
 
+template  _Tp abs(const std::complex<_Tp> &__c);
+
+// arg
+
+template  _Tp arg(const std::complex<_Tp> &__c);
+
+// norm
+
+template  _Tp norm(const std::complex<_Tp> &__c);
+
+// conj
+
+template  std::complex<_Tp> conj(const std::complex<_Tp> &__c);
+
+// proj
+
+template  std::complex<_Tp> proj(const std::complex<_Tp> &__c);
+
+// polar
+
+template 
+complex<_Tp> polar(const _Tp &__rho, const _Tp &__theta = _Tp());
+
+// log
+
+template  std::complex<_Tp> log(const std::complex<_Tp> &__x);
+
+// log10
+
+template  std::complex<_Tp> log10(const std::complex<_Tp> &__x);
+
+// sqrt
+
+template 
+std::complex<_Tp> sqrt(const std::complex<_Tp> &__x);
+
+// exp
+
+template 
+std::complex<_Tp> exp(const std::complex<_Tp> &__x);
+
+// pow
+
+template 
+std::complex<_Tp> pow(const std::complex<_Tp> &__x,
+  const std::complex<_Tp> &__y);
+
+// __sqr, computes pow(x, 2)
+
+template  std::complex<_Tp> __sqr(const 

[PATCH] D85876: [OpenMP][FIX] Do not drop a '$' while demangling declare variant names

2020-09-16 Thread Johannes Doerfert via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG05fd04eda4b2: [OpenMP][FIX] Do not drop a $ 
while demangling declare variant names (authored by jdoerfert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85876

Files:
  clang/lib/AST/OpenMPClause.cpp
  clang/test/AST/ast-dump-openmp-declare-variant-extensions.c


Index: clang/test/AST/ast-dump-openmp-declare-variant-extensions.c
===
--- clang/test/AST/ast-dump-openmp-declare-variant-extensions.c
+++ clang/test/AST/ast-dump-openmp-declare-variant-extensions.c
@@ -200,8 +200,8 @@
 // CHECK-NEXT: |   `-DeclRefExpr [[ADDR_111:0x[a-z0-9]*]]  'int 
({{.*}})' {{.*}}Function [[ADDR_18]] 'picked7' 'int ({{.*}})' 
non_odr_use_unevaluated
 // CHECK-NEXT: |-FunctionDecl [[ADDR_112:0x[a-z0-9]*]]  
col:5 implicit used overloaded1 'int ({{.*}})'
 // CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_113:0x[a-z0-9]*]] <> Implicit implementation={extension(match_any)}, device={kind(cpu, gpu)}
-// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_114:0x[a-z0-9]*]]  'int 
({{.*}})' Function [[ADDR_115:0x[a-z0-9]*]] 
'overloaded1[implementation={extension(match_any)}]' 'int ({{.*}})'
-// CHECK-NEXT: |-FunctionDecl [[ADDR_115]]  col:1 
overloaded1[implementation={extension(match_any)}] 'int ({{.*}})'
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_114:0x[a-z0-9]*]]  'int 
({{.*}})' {{.*}}Function [[ADDR_115:0x[a-z0-9]*]] 
'overloaded1[implementation={extension(match_any)}, device={kind(cpu, gpu)}]' 
'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_115]]  col:1 
overloaded1[implementation={extension(match_any)}, device={kind(cpu, gpu)}] 
'int ({{.*}})'
 // CHECK-NEXT: | `-CompoundStmt [[ADDR_116:0x[a-z0-9]*]] 
 // CHECK-NEXT: |   `-ReturnStmt [[ADDR_117:0x[a-z0-9]*]] 
 // CHECK-NEXT: | `-IntegerLiteral [[ADDR_118:0x[a-z0-9]*]]  'int' 0
@@ -210,8 +210,8 @@
 // CHECK-NEXT: | | `-ReturnStmt [[ADDR_121:0x[a-z0-9]*]] 
 // CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_122:0x[a-z0-9]*]]  'int' 1
 // CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_123:0x[a-z0-9]*]] <> Implicit implementation={extension(match_none)}, device={kind(fpga, gpu)}
-// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_124:0x[a-z0-9]*]]  'int 
({{.*}})' Function [[ADDR_125:0x[a-z0-9]*]] 
'overloaded2[implementation={extension(match_none)}]' 'int ({{.*}})'
-// CHECK-NEXT: |-FunctionDecl [[ADDR_125]]  col:1 
overloaded2[implementation={extension(match_none)}] 'int ({{.*}})'
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_124:0x[a-z0-9]*]]  'int 
({{.*}})' {{.*}}Function [[ADDR_125:0x[a-z0-9]*]] 
'overloaded2[implementation={extension(match_none)}, device={kind(fpga, gpu)}]' 
'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_125]]  col:1 
overloaded2[implementation={extension(match_none)}, device={kind(fpga, gpu)}] 
'int ({{.*}})'
 // CHECK-NEXT: | `-CompoundStmt [[ADDR_126:0x[a-z0-9]*]] 
 // CHECK-NEXT: |   `-ReturnStmt [[ADDR_127:0x[a-z0-9]*]] 
 // CHECK-NEXT: | `-IntegerLiteral [[ADDR_128:0x[a-z0-9]*]]  'int' 0
@@ -333,11 +333,11 @@
 // CHECK-NEXT: |   |   `-DeclRefExpr [[ADDR_236:0x[a-z0-9]*]]  
'int ({{.*}})' {{.*}}Function [[ADDR_112]] 'overloaded1' 'int ({{.*}})'
 // CHECK-NEXT: |   `-CallExpr [[ADDR_237:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: | `-ImplicitCastExpr [[ADDR_238:0x[a-z0-9]*]] 
 'int (*)({{.*}})' 
-// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_114]]  'int 
({{.*}})' Function [[ADDR_115]] 
'overloaded1[implementation={extension(match_any)}]' 'int ({{.*}})'
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_114]]  'int 
({{.*}})' {{.*}}Function [[ADDR_115]] 
'overloaded1[implementation={extension(match_any)}, device={kind(cpu, gpu)}]' 
'int ({{.*}})'
 // CHECK-NEXT: `-PseudoObjectExpr [[ADDR_239:0x[a-z0-9]*]] 
 'int'
 // CHECK-NEXT:   |-CallExpr [[ADDR_240:0x[a-z0-9]*]]  
'int'
 // CHECK-NEXT:   | `-ImplicitCastExpr [[ADDR_241:0x[a-z0-9]*]] 
 'int (*)({{.*}})' 
 // CHECK-NEXT:   |   `-DeclRefExpr [[ADDR_242:0x[a-z0-9]*]]  
'int ({{.*}})' {{.*}}Function [[ADDR_119]] 'overloaded2' 'int ({{.*}})'
 // CHECK-NEXT:   `-CallExpr [[ADDR_243:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: `-ImplicitCastExpr [[ADDR_244:0x[a-z0-9]*]] 
 'int (*)({{.*}})' 
-// CHECK-NEXT:   `-DeclRefExpr [[ADDR_124]]  'int ({{.*}})' 
Function [[ADDR_125]] 'overloaded2[implementation={extension(match_none)}]' 
'int ({{.*}})'
+// CHECK-NEXT:   `-DeclRefExpr [[ADDR_124]]  'int ({{.*}})' 
{{.*}}Function [[ADDR_125]] 
'overloaded2[implementation={extension(match_none)}, device={kind(fpga, gpu)}]' 
'int ({{.*}})'
Index: clang/lib/AST/OpenMPClause.cpp
===
--- clang/lib/AST/OpenMPClause.cpp
+++ clang/lib/AST/OpenMPClause.cpp
@@ -2281,7 +2281,7 @@
 Property.RawString = PropRestPair.first;
 Property.Kind = 

[PATCH] D85875: [OpenMP][FIX] Do not crash trying to print a missing (demangled) user condition

2020-09-16 Thread Johannes Doerfert via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6a02932becae: [OpenMP][FIX] Do not crash trying to print a 
missing (demangled) user condition (authored by jdoerfert).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85875

Files:
  clang/lib/AST/OpenMPClause.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_13.c


Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_13.c
===
--- /dev/null
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_13.c
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump 
%s   | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump 
%s -x c++| FileCheck %s
+// expected-no-diagnostics
+
+int also_before(void) {
+  return 1;
+}
+
+#pragma omp begin declare variant match(user = {condition(1)})
+int also_after(void) {
+  return 0;
+}
+int also_before(void) {
+  return 0;
+}
+#pragma omp end declare variant
+
+int also_after(void) {
+  return 2;
+}
+
+int test() {
+  // Should return 0.
+  return also_after() + also_before();
+}
+
+// CHECK:  |-FunctionDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, line:7:1> 
line:5:5 used also_before 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_1:0x[a-z0-9]*]] 
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_2:0x[a-z0-9]*]] 
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_3:0x[a-z0-9]*]]  'int' 1
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_4:0x[a-z0-9]*]] <> Implicit user={condition(1)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_5:0x[a-z0-9]*]]  'int 
({{.*}})' {{.*}}Function [[ADDR_6:0x[a-z0-9]*]] 
'also_before[user={condition(...)}]' 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_7:0x[a-z0-9]*]]  col:5 
implicit used also_after 'int ({{.*}})'
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_8:0x[a-z0-9]*]] <> Implicit user={condition(1)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_9:0x[a-z0-9]*]]  'int ({{.*}})' 
{{.*}}Function [[ADDR_10:0x[a-z0-9]*]] 'also_after[user={condition(...)}]' 'int 
({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_10]]  line:10:1 
also_after[user={condition(...)}] 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_11:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_12:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-IntegerLiteral [[ADDR_13:0x[a-z0-9]*]]  'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_6]]  line:13:1 
also_before[user={condition(...)}] 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_14:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_15:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-IntegerLiteral [[ADDR_16:0x[a-z0-9]*]]  'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_17:0x[a-z0-9]*]] prev [[ADDR_7]] 
 line:18:5 used also_after 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_18:0x[a-z0-9]*]] 
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_19:0x[a-z0-9]*]] 
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_20:0x[a-z0-9]*]]  'int' 2
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_21:0x[a-z0-9]*]] <> Inherited Implicit user={condition(1)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_9]]  'int ({{.*}})' 
{{.*}}Function [[ADDR_10]] 'also_after[user={condition(...)}]' 'int ({{.*}})'
+// CHECK-NEXT: `-FunctionDecl [[ADDR_22:0x[a-z0-9]*]]  
line:22:5 test 'int ({{.*}})'
+// CHECK-NEXT:   `-CompoundStmt [[ADDR_23:0x[a-z0-9]*]] 
+// CHECK-NEXT: `-ReturnStmt [[ADDR_24:0x[a-z0-9]*]] 
+// CHECK-NEXT:   `-BinaryOperator [[ADDR_25:0x[a-z0-9]*]]  
'int' '+'
+// CHECK-NEXT: |-PseudoObjectExpr [[ADDR_26:0x[a-z0-9]*]]  'int'
+// CHECK-NEXT: | |-CallExpr [[ADDR_27:0x[a-z0-9]*]]  
'int'
+// CHECK-NEXT: | | `-ImplicitCastExpr [[ADDR_28:0x[a-z0-9]*]]  
'int (*)({{.*}})' 
+// CHECK-NEXT: | |   `-DeclRefExpr [[ADDR_29:0x[a-z0-9]*]]  
'int ({{.*}})' {{.*}}Function [[ADDR_17]] 'also_after' 'int ({{.*}})'
+// CHECK-NEXT: | `-CallExpr [[ADDR_30:0x[a-z0-9]*]]  'int'
+// CHECK-NEXT: |   `-ImplicitCastExpr [[ADDR_31:0x[a-z0-9]*]] 
 'int (*)({{.*}})' 
+// CHECK-NEXT: | `-DeclRefExpr [[ADDR_9]]  'int ({{.*}})' 
{{.*}}Function [[ADDR_10]] 'also_after[user={condition(...)}]' 'int ({{.*}})'
+// CHECK-NEXT: `-PseudoObjectExpr [[ADDR_32:0x[a-z0-9]*]]  'int'
+// CHECK-NEXT:   |-CallExpr [[ADDR_33:0x[a-z0-9]*]]  
'int'
+// CHECK-NEXT:   | `-ImplicitCastExpr [[ADDR_34:0x[a-z0-9]*]]  
'int (*)({{.*}})' 
+// CHECK-NEXT:   |   `-DeclRefExpr [[ADDR_35:0x[a-z0-9]*]]  
'int ({{.*}})' {{.*}}Function [[ADDR_0]] 'also_before' 'int ({{.*}})'
+// CHECK-NEXT:   `-CallExpr [[ADDR_36:0x[a-z0-9]*]]  'int'
+// CHECK-NEXT: `-ImplicitCastExpr [[ADDR_37:0x[a-z0-9]*]] 
 'int (*)({{.*}})' 
+// CHECK-NEXT:   `-DeclRefExpr [[ADDR_5]]  'int ({{.*}})' 
{{.*}}Function [[ADDR_6]] 'also_before[user={condition(...)}]' 'int ({{.*}})'
Index: 

[clang] 5c63ae1 - [OpenMP] Support nested OpenMP context selectors (declare variant)

2020-09-16 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2020-09-16T13:37:09-05:00
New Revision: 5c63ae156e96a20ce96570d4bd2c48a9c8170a9d

URL: 
https://github.com/llvm/llvm-project/commit/5c63ae156e96a20ce96570d4bd2c48a9c8170a9d
DIFF: 
https://github.com/llvm/llvm-project/commit/5c63ae156e96a20ce96570d4bd2c48a9c8170a9d.diff

LOG: [OpenMP] Support nested OpenMP context selectors (declare variant)

Due to `omp begin/end declare variant`, OpenMP context selectors can be
nested. This patch adds initial support for this so we can use it for
target math variants. We should improve the detection of "equivalent"
scores and user conditions, we should also revisit the data structures
of the OMPTraitInfo object, however, both are not pressing issues right
now.

Reviewed By: JonChesterfield

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

Added: 
clang/test/AST/ast-dump-openmp-begin-declare-variant_nested.c

Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/declare_variant_messages.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 1c8d741ab54f..1ac1e9d10a7a 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1293,6 +1293,11 @@ def err_omp_mapper_expected_declarator : Error<
   "expected declarator on 'omp declare mapper' directive">;
 def err_omp_declare_variant_wrong_clause : Error<
   "expected '%0' clause on 'omp declare variant' directive">;
+def err_omp_declare_variant_duplicate_nested_trait : Error<
+  "nested OpenMP context selector contains duplicated trait '%0'"
+  " in selector '%1' and set '%2' with 
diff erent score">;
+def err_omp_declare_variant_nested_user_condition : Error<
+  "nested user conditions in OpenMP context selector not supported (yet)">;
 def warn_omp_declare_variant_string_literal_or_identifier
 : Warning<"expected identifier or string literal describing a context "
   "%select{set|selector|property}0; "

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f6ded1b4ee26..a9bd448ba026 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10367,10 +10367,6 @@ def err_omp_non_lvalue_in_map_or_motion_clauses: Error<
   "expected addressable lvalue in '%0' clause">;
 def err_omp_var_expected : Error<
   "expected variable of the '%0' type%select{|, not %2}1">;
-def warn_nested_declare_variant
-: Warning<"nesting `omp begin/end declare variant` is not supported yet; "
-  "nested context ignored">,
-  InGroup;
 def warn_unknown_declare_variant_isa_trait
 : Warning<"isa trait '%0' is not known to the current target; verify the "
   "spelling or consider restricting the context selector with the "

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index af8cf47e5667..211827e99de8 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3098,7 +3098,8 @@ class Parser : public CodeCompletionHandler {
 
   /// Parse a `match` clause for an '#pragma omp declare variant'. Return true
   /// if there was an error.
-  bool parseOMPDeclareVariantMatchClause(SourceLocation Loc, OMPTraitInfo );
+  bool parseOMPDeclareVariantMatchClause(SourceLocation Loc, OMPTraitInfo ,
+ OMPTraitInfo *ParentTI);
 
   /// Parse clauses for '#pragma omp declare variant'.
   void ParseOMPDeclareVariantClauses(DeclGroupPtrTy Ptr, CachedTokens ,

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 129ac0355c87..9502c104be68 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10019,6 +10019,12 @@ class Sema final {
 OMPDeclareVariantScope(OMPTraitInfo );
   };
 
+  /// Return the OMPTraitInfo for the surrounding scope, if any.
+  OMPTraitInfo *getOMPTraitInfoForSurroundingScope() {
+return OMPDeclareVariantScopes.empty() ? nullptr
+   : OMPDeclareVariantScopes.back().TI;
+  }
+
   /// The current `omp begin/end declare variant` scopes.
   SmallVector OMPDeclareVariantScopes;
 

diff  --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index ceb91dce186c..40124264fdb9 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -1385,8 +1385,10 @@ void 
Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr,
 return;
   }
 
-  OMPTraitInfo  = Actions.getASTContext().getNewOMPTraitInfo();
-  if 

[clang] 05fd04e - [OpenMP][FIX] Do not drop a '$' while demangling declare variant names

2020-09-16 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2020-09-16T13:37:09-05:00
New Revision: 05fd04eda4b22b09e33753132cbf037a1265c7e2

URL: 
https://github.com/llvm/llvm-project/commit/05fd04eda4b22b09e33753132cbf037a1265c7e2
DIFF: 
https://github.com/llvm/llvm-project/commit/05fd04eda4b22b09e33753132cbf037a1265c7e2.diff

LOG: [OpenMP][FIX] Do not drop a '$' while demangling declare variant names

Reviewed By: ABataev

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

Added: 


Modified: 
clang/lib/AST/OpenMPClause.cpp
clang/test/AST/ast-dump-openmp-declare-variant-extensions.c

Removed: 




diff  --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index ff9e9b2b3453..6590738268c6 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -2281,7 +2281,7 @@ OMPTraitInfo::OMPTraitInfo(StringRef MangledName) {
 Property.RawString = PropRestPair.first;
 Property.Kind = getOpenMPContextTraitPropertyKind(
 Set.Kind, Selector.Kind, PropRestPair.first);
-MangledName = PropRestPair.second;
+MangledName = MangledName.drop_front(PropRestPair.first.size());
   } while (true);
 } while (true);
   } while (true);

diff  --git a/clang/test/AST/ast-dump-openmp-declare-variant-extensions.c 
b/clang/test/AST/ast-dump-openmp-declare-variant-extensions.c
index 4a755282e39d..577abbc5fe0b 100644
--- a/clang/test/AST/ast-dump-openmp-declare-variant-extensions.c
+++ b/clang/test/AST/ast-dump-openmp-declare-variant-extensions.c
@@ -200,8 +200,8 @@ int test() {
 // CHECK-NEXT: |   `-DeclRefExpr [[ADDR_111:0x[a-z0-9]*]]  'int 
({{.*}})' {{.*}}Function [[ADDR_18]] 'picked7' 'int ({{.*}})' 
non_odr_use_unevaluated
 // CHECK-NEXT: |-FunctionDecl [[ADDR_112:0x[a-z0-9]*]]  
col:5 implicit used overloaded1 'int ({{.*}})'
 // CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_113:0x[a-z0-9]*]] <> Implicit implementation={extension(match_any)}, device={kind(cpu, gpu)}
-// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_114:0x[a-z0-9]*]]  'int 
({{.*}})' Function [[ADDR_115:0x[a-z0-9]*]] 
'overloaded1[implementation={extension(match_any)}]' 'int ({{.*}})'
-// CHECK-NEXT: |-FunctionDecl [[ADDR_115]]  col:1 
overloaded1[implementation={extension(match_any)}] 'int ({{.*}})'
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_114:0x[a-z0-9]*]]  'int 
({{.*}})' {{.*}}Function [[ADDR_115:0x[a-z0-9]*]] 
'overloaded1[implementation={extension(match_any)}, device={kind(cpu, gpu)}]' 
'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_115]]  col:1 
overloaded1[implementation={extension(match_any)}, device={kind(cpu, gpu)}] 
'int ({{.*}})'
 // CHECK-NEXT: | `-CompoundStmt [[ADDR_116:0x[a-z0-9]*]] 
 // CHECK-NEXT: |   `-ReturnStmt [[ADDR_117:0x[a-z0-9]*]] 
 // CHECK-NEXT: | `-IntegerLiteral [[ADDR_118:0x[a-z0-9]*]]  'int' 0
@@ -210,8 +210,8 @@ int test() {
 // CHECK-NEXT: | | `-ReturnStmt [[ADDR_121:0x[a-z0-9]*]] 
 // CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_122:0x[a-z0-9]*]]  'int' 1
 // CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_123:0x[a-z0-9]*]] <> Implicit implementation={extension(match_none)}, device={kind(fpga, gpu)}
-// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_124:0x[a-z0-9]*]]  'int 
({{.*}})' Function [[ADDR_125:0x[a-z0-9]*]] 
'overloaded2[implementation={extension(match_none)}]' 'int ({{.*}})'
-// CHECK-NEXT: |-FunctionDecl [[ADDR_125]]  col:1 
overloaded2[implementation={extension(match_none)}] 'int ({{.*}})'
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_124:0x[a-z0-9]*]]  'int 
({{.*}})' {{.*}}Function [[ADDR_125:0x[a-z0-9]*]] 
'overloaded2[implementation={extension(match_none)}, device={kind(fpga, gpu)}]' 
'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_125]]  col:1 
overloaded2[implementation={extension(match_none)}, device={kind(fpga, gpu)}] 
'int ({{.*}})'
 // CHECK-NEXT: | `-CompoundStmt [[ADDR_126:0x[a-z0-9]*]] 
 // CHECK-NEXT: |   `-ReturnStmt [[ADDR_127:0x[a-z0-9]*]] 
 // CHECK-NEXT: | `-IntegerLiteral [[ADDR_128:0x[a-z0-9]*]]  'int' 0
@@ -333,11 +333,11 @@ int test() {
 // CHECK-NEXT: |   |   `-DeclRefExpr [[ADDR_236:0x[a-z0-9]*]]  
'int ({{.*}})' {{.*}}Function [[ADDR_112]] 'overloaded1' 'int ({{.*}})'
 // CHECK-NEXT: |   `-CallExpr [[ADDR_237:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: | `-ImplicitCastExpr [[ADDR_238:0x[a-z0-9]*]] 
 'int (*)({{.*}})' 
-// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_114]]  'int 
({{.*}})' Function [[ADDR_115]] 
'overloaded1[implementation={extension(match_any)}]' 'int ({{.*}})'
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_114]]  'int 
({{.*}})' {{.*}}Function [[ADDR_115]] 
'overloaded1[implementation={extension(match_any)}, device={kind(cpu, gpu)}]' 
'int ({{.*}})'
 // CHECK-NEXT: `-PseudoObjectExpr [[ADDR_239:0x[a-z0-9]*]] 
 'int'
 // CHECK-NEXT:   |-CallExpr [[ADDR_240:0x[a-z0-9]*]]  
'int'
 // CHECK-NEXT:   | `-ImplicitCastExpr [[ADDR_241:0x[a-z0-9]*]] 
 'int (*)({{.*}})' 
 // 

[clang] 6a02932 - [OpenMP][FIX] Do not crash trying to print a missing (demangled) user condition

2020-09-16 Thread Johannes Doerfert via cfe-commits

Author: Johannes Doerfert
Date: 2020-09-16T13:37:08-05:00
New Revision: 6a02932becaeaeb02eddfaed567f3dad3719dd1c

URL: 
https://github.com/llvm/llvm-project/commit/6a02932becaeaeb02eddfaed567f3dad3719dd1c
DIFF: 
https://github.com/llvm/llvm-project/commit/6a02932becaeaeb02eddfaed567f3dad3719dd1c.diff

LOG: [OpenMP][FIX] Do not crash trying to print a missing (demangled) user 
condition

Reviewed By: JonChesterfield

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

Added: 
clang/test/AST/ast-dump-openmp-begin-declare-variant_13.c

Modified: 
clang/lib/AST/OpenMPClause.cpp

Removed: 




diff  --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index e846d325560d..ff9e9b2b3453 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -2201,7 +2201,10 @@ void OMPTraitInfo::print(llvm::raw_ostream ,
 
   OS << "(";
   if (Selector.Kind == TraitSelector::user_condition) {
-Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
+if (Selector.ScoreOrCondition)
+  Selector.ScoreOrCondition->printPretty(OS, nullptr, Policy);
+else
+  OS << "...";
   } else {
 
 if (Selector.ScoreOrCondition) {

diff  --git a/clang/test/AST/ast-dump-openmp-begin-declare-variant_13.c 
b/clang/test/AST/ast-dump-openmp-begin-declare-variant_13.c
new file mode 100644
index ..93d847a0
--- /dev/null
+++ b/clang/test/AST/ast-dump-openmp-begin-declare-variant_13.c
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump 
%s   | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump 
%s -x c++| FileCheck %s
+// expected-no-diagnostics
+
+int also_before(void) {
+  return 1;
+}
+
+#pragma omp begin declare variant match(user = {condition(1)})
+int also_after(void) {
+  return 0;
+}
+int also_before(void) {
+  return 0;
+}
+#pragma omp end declare variant
+
+int also_after(void) {
+  return 2;
+}
+
+int test() {
+  // Should return 0.
+  return also_after() + also_before();
+}
+
+// CHECK:  |-FunctionDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, line:7:1> 
line:5:5 used also_before 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_1:0x[a-z0-9]*]] 
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_2:0x[a-z0-9]*]] 
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_3:0x[a-z0-9]*]]  'int' 1
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_4:0x[a-z0-9]*]] <> Implicit user={condition(1)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_5:0x[a-z0-9]*]]  'int 
({{.*}})' {{.*}}Function [[ADDR_6:0x[a-z0-9]*]] 
'also_before[user={condition(...)}]' 'int ({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_7:0x[a-z0-9]*]]  col:5 
implicit used also_after 'int ({{.*}})'
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_8:0x[a-z0-9]*]] <> Implicit user={condition(1)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_9:0x[a-z0-9]*]]  'int ({{.*}})' 
{{.*}}Function [[ADDR_10:0x[a-z0-9]*]] 'also_after[user={condition(...)}]' 'int 
({{.*}})'
+// CHECK-NEXT: |-FunctionDecl [[ADDR_10]]  line:10:1 
also_after[user={condition(...)}] 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_11:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_12:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-IntegerLiteral [[ADDR_13:0x[a-z0-9]*]]  'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_6]]  line:13:1 
also_before[user={condition(...)}] 'int ({{.*}})'
+// CHECK-NEXT: | `-CompoundStmt [[ADDR_14:0x[a-z0-9]*]] 
+// CHECK-NEXT: |   `-ReturnStmt [[ADDR_15:0x[a-z0-9]*]] 
+// CHECK-NEXT: | `-IntegerLiteral [[ADDR_16:0x[a-z0-9]*]]  'int' 0
+// CHECK-NEXT: |-FunctionDecl [[ADDR_17:0x[a-z0-9]*]] prev [[ADDR_7]] 
 line:18:5 used also_after 'int ({{.*}})'
+// CHECK-NEXT: | |-CompoundStmt [[ADDR_18:0x[a-z0-9]*]] 
+// CHECK-NEXT: | | `-ReturnStmt [[ADDR_19:0x[a-z0-9]*]] 
+// CHECK-NEXT: | |   `-IntegerLiteral [[ADDR_20:0x[a-z0-9]*]]  'int' 2
+// CHECK-NEXT: | `-OMPDeclareVariantAttr [[ADDR_21:0x[a-z0-9]*]] <> Inherited Implicit user={condition(1)}
+// CHECK-NEXT: |   `-DeclRefExpr [[ADDR_9]]  'int ({{.*}})' 
{{.*}}Function [[ADDR_10]] 'also_after[user={condition(...)}]' 'int ({{.*}})'
+// CHECK-NEXT: `-FunctionDecl [[ADDR_22:0x[a-z0-9]*]]  
line:22:5 test 'int ({{.*}})'
+// CHECK-NEXT:   `-CompoundStmt [[ADDR_23:0x[a-z0-9]*]] 
+// CHECK-NEXT: `-ReturnStmt [[ADDR_24:0x[a-z0-9]*]] 
+// CHECK-NEXT:   `-BinaryOperator [[ADDR_25:0x[a-z0-9]*]]  
'int' '+'
+// CHECK-NEXT: |-PseudoObjectExpr [[ADDR_26:0x[a-z0-9]*]]  'int'
+// CHECK-NEXT: | |-CallExpr [[ADDR_27:0x[a-z0-9]*]]  
'int'
+// CHECK-NEXT: | | `-ImplicitCastExpr [[ADDR_28:0x[a-z0-9]*]]  
'int (*)({{.*}})' 
+// CHECK-NEXT: | |   `-DeclRefExpr [[ADDR_29:0x[a-z0-9]*]]  
'int ({{.*}})' {{.*}}Function [[ADDR_17]] 'also_after' 'int ({{.*}})'
+// CHECK-NEXT: | `-CallExpr [[ADDR_30:0x[a-z0-9]*]]  'int'
+// CHECK-NEXT: |   

[PATCH] D87615: [X86] Fix stack alignment on 32-bit Solaris/x86

2020-09-16 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

@joerg Are you alright with this now? If so please can you accept it to unblock 
it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87615

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


[PATCH] D86694: [scudo] Allow -fsanitize=scudo on Linux and Windows (WIP, don't land as is)

2020-09-16 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a subscriber: maniccoder.
aganea added a comment.

In D86694#2274682 , @cryptoad wrote:

> In D86694#2274548 , @russell.gallop 
> wrote:
>
>> I guess using scudo as a general purpose allocator that could set a limit on 
>> the number of cores that can be used at once as @aganea found. Would there 
>> be any problem with making this very small (e.g. a couple of GB)?
>
> You can reduce the size of the Primary for Windows with an additional define 
> in the platform file. You probably want to make sure there is at least a few 
> gigs per region (eg: the total size could be 256G).
>
> Once again the memory is reserved but not committed, and this is on a 
> per-process basis. There shouldn't be more than one Primary, and as such we 
> shouldn't run out of VA space. We could possibly run out of memory if we 
> allocate past the amount of RAM (+swap), but this is the committed amount.

I think reserving 4 TB hits a pathological case in the Windows NT Kernel, where 
for some reason, the application's VAD (Virtual Address Descriptor) tree is not 
cleared right away, but deferred to the system zero thread. Since that thread 
is low-priority, the VAD trees are accumulating in the "Active List", until it 
hits the physical memory limit, then it goes to swap, then at some point the 
`VirtualAllocs` calls in the application fail. This looks like an edge case 
that wouldn't happen normally (lots of applications that start, reserve several 
TB of vRAM, then shutdown)
+ @maniccoder

F12971303: linking_clang_with_lld_thinlto_scudo_hardware_crc8.PNG 


As soon as I pause the `ninja check-llvm` tests (by blocking the console 
output), the zero thread now has more time and the free memory goes down again.

F12971361: image.png 

@cryptoad What happens if the primary was much smaller? Or if pages were 
//reserved// in much smaller ranges?

In D86694#2271825 , @russell.gallop 
wrote:

>> (a hardware CRC or AES implemention will certainly help for Scudo)
>
> Actually this wasn't too hard to try out. I added "-msse4.2" to CMAKE_C_FLAGS 
> and CMAKE_CXX_FLAGS (as suggested in scudo_allocator.cpp). This helps, but 
> scudo is still a bit behind the default allocator for me on 6 cores

This improves things a bit, wall clock 145 sec before -> 136 sec after.

Scudo+options+hardware-crc32 - 5,997 cumulated seconds (all threads) - //before 
it was 6,337 seconds//
F12971472: linking_clang_with_lld_thinlto_scudo_hardware_crc.PNG 


Time spent in the allocator itself:

Scudo+options - 761 cumulated seconds - //before it was 1,171 seconds//
F12971504: linking_clang_with_lld_thinlto_scudo_hardware_crc2.PNG 


There's one more thing. I think the difference in performance, as when compared 
with competing allocators, is that SCUDO still does some level of locking. Like 
I mentionned previously, this doesn't scale on many-core machine for 
allocation-intensive applications like LLVM. Every waiting lock gives up its 
time slice to the OS scheduler, and that's bad for performance. The more core 
there are, the more we wait for the lock to become free.
F12971551: linking_clang_with_lld_thinlto_scudo_hardware_crc5.PNG 

Here you can see a Scudo-enabled LLD doing 10x more context-switches that the 
Rpmalloc-enabled LLD:
F12971754: linking_clang_with_lld_thinlto_scudo_hardware_crc3.PNG 


One thing that is in favor of Scudo though, is that it commits memory in much 
smaller blocks than Rpmalloc (peak LLD commit is 5 GB for Scudo, 11 GB for 
Rpmalloc). Mimalloc employs the same kind of strategy, with similar benefits.
F12971632: linking_clang_with_lld_thinlto_scudo_hardware_crc4.PNG 


@cryptoad Does SCUDO standalone differs in any of these aspects from this 
version?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86694

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


[PATCH] D84414: [RISCV] Support Shadow Call Stack

2020-09-16 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:86
+
+  // Get shadow call stack pointer register.
+  Register SCSPReg = RISCVABI::getSCSPReg();

Pointless comment; remove



Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:89
+
+  // Emit an error message and bail out.
+  if (!STI.isRegisterReservedByUser(SCSPReg)) {

Pointless comment; remove


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84414

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


[PATCH] D78075: [WIP][Clang][OpenMP] Added support for nowait target in CodeGen

2020-09-16 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 292280.
tianshilei1992 added a comment.

Fixed an issue that one wildcard is missing in the CHECK line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78075

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_mapper_codegen.cpp

Index: clang/test/OpenMP/declare_mapper_codegen.cpp
===
--- clang/test/OpenMP/declare_mapper_codegen.cpp
+++ clang/test/OpenMP/declare_mapper_codegen.cpp
@@ -22,6 +22,13 @@
 #ifdef CK0
 // Mapper function code generation and runtime interface.
 
+// CK0: [[IDENT_T:%.+]] = type { i32, i32, i32, i32, i8* }
+// CK0: [[ANON_T:%.+]] = type { %class.C* }
+// CK0: [[ANON_T_0:%.+]] = type { %class.C* }
+// CK0: [[KMP_TASK_T_WITH_PRIVATES:%.+]] = type { [[KMP_TASK_T:%.+]], [[KMP_PRIVATES_T:%.+]] }
+// CK0: [[KMP_TASK_T]] = type { i8*, i32 (i32, i8*)*, i32, %union{{.+}}, %union{{.+}} }
+// CK0: [[KMP_TASK_T_WITH_PRIVATES_1:%.+]] = type { [[KMP_TASK_T]], [[KMP_PRIVATES_T_1:%.+]] }
+
 // CK0-LABEL: @.__omp_offloading_{{.*}}foo{{.*}}.region_id = weak constant i8 0
 // CK0-64: [[SIZES:@.+]] = {{.+}}constant [1 x i64] [i64 16]
 // CK0-32: [[SIZES:@.+]] = {{.+}}constant [1 x i64] [i64 8]
@@ -248,25 +255,18 @@
   // CK0-DAG: store %class.C* [[VAL:%[^,]+]], %class.C** [[CBP1]]
   // CK0-DAG: store %class.C* [[VAL]], %class.C** [[CP1]]
   // CK0-DAG: store i8* bitcast (void (i8*, i8*, i8*, i64, i64)* [[MPRFUNC]] to i8*), i8** [[MPR1]]
-  // CK0: call void [[KERNEL:@.+]](%class.C* [[VAL]])
+  // CK0: call void [[KERNEL_1:@.+]](%class.C* [[VAL]])
   #pragma omp target map(mapper(id),tofrom: c)
   {
 ++c.a;
   }
 
-  // CK0-DAG: call i32 @__tgt_target_nowait_mapper(i64 {{.+}}, i8* {{.+}}, i32 1, i8** [[BPGEP:%[0-9]+]], i8** [[PGEP:%[0-9]+]], {{.+}}[[NWSIZES]]{{.+}}, {{.+}}[[NWTYPES]]{{.+}}, i8** [[MPRGEP:%.+]])
-  // CK0-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BPS:%[^,]+]], i32 0, i32 0
-  // CK0-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0
-  // CK0-DAG: [[MPRGEP]] = bitcast [1 x i8*]* [[MPR:%[^,]+]] to i8**
-  // CK0-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0
-  // CK0-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0
-  // CK0-DAG: [[MPR1:%.+]] = getelementptr inbounds {{.+}}[[MPR]], i[[sz]] 0, i[[sz]] 0
-  // CK0-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to %class.C**
-  // CK0-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to %class.C**
-  // CK0-DAG: store %class.C* [[VAL:%[^,]+]], %class.C** [[CBP1]]
-  // CK0-DAG: store %class.C* [[VAL]], %class.C** [[CP1]]
-  // CK0-DAG: store i8* bitcast (void (i8*, i8*, i8*, i64, i64)* [[MPRFUNC]] to i8*), i8** [[MPR1]]
-  // CK0: call void [[KERNEL:@.+]](%class.C* [[VAL]])
+  // CK0-32: [[TASK:%.+]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* {{@.+}}, i32 {{%.+}}, i32 1, i32 40, i32 4, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CK0-64: [[TASK:%.+]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* {{@.+}}, i32 {{%.+}}, i32 1, i64 72, i64 8, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CK0: [[TASK_CAST:%.+]] = bitcast i8* [[TASK]] to [[KMP_TASK_T_WITH_PRIVATES]]*
+  // CK0: [[TASK_CAST_GET:%.+]] = getelementptr inbounds [[KMP_TASK_T_WITH_PRIVATES]], [[KMP_TASK_T_WITH_PRIVATES]]* [[TASK_CAST]], i32 0, i32 0
+  // CK0: {{.+}} = getelementptr inbounds [[KMP_TASK_T]], [[KMP_TASK_T]]* [[TASK_CAST_GET]], i32 0, i32 0
+  // CK0: {{.+}} = call i32 @__kmpc_omp_task([[IDENT_T]]* @1, i32 {{.+}}, i8* [[TASK]])
   #pragma omp target map(mapper(id),tofrom: c) nowait
   {
 ++c.a;
@@ -284,25 +284,18 @@
   // CK0-DAG: store %class.C* [[VAL:%[^,]+]], %class.C** [[CBP1]]
   // CK0-DAG: store %class.C* [[VAL]], %class.C** [[CP1]]
   // CK0-DAG: store i8* bitcast (void (i8*, i8*, i8*, i64, i64)* [[MPRFUNC]] to i8*), i8** [[MPR1]]
-  // CK0: call void [[KERNEL:@.+]](%class.C* [[VAL]])
+  // CK0: call void [[KERNEL_3:@.+]](%class.C* [[VAL]])
   #pragma omp target teams map(mapper(id),to: c)
   {
 ++c.a;
   }
 
-  // CK0-DAG: call i32 @__tgt_target_teams_nowait_mapper(i64 {{.+}}, i8* {{.+}}, i32 1, i8** [[BPGEP:%[0-9]+]], i8** [[PGEP:%[0-9]+]], {{.+}}[[TEAMNWSIZES]]{{.+}}, {{.+}}[[TEAMNWTYPES]]{{.+}}, i8** [[MPRGEP:%.+]], i32 0, i32 0)
-  // CK0-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BPS:%[^,]+]], i32 0, i32 0
-  // CK0-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0
-  // CK0-DAG: [[MPRGEP]] = bitcast [1 x i8*]* [[MPR:%[^,]+]] to i8**
-  // CK0-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0
-  // CK0-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0
-  // CK0-DAG: [[MPR1:%.+]] = getelementptr inbounds {{.+}}[[MPR]], i[[sz]] 0, i[[sz]] 0
-  // 

[PATCH] D84414: [RISCV] Support Shadow Call Stack

2020-09-16 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 requested changes to this revision.
jrtc27 added a comment.
This revision now requires changes to proceed.

This is currently incompatible with the save/restore libcalls, and I don't 
think there's any way to avoid that (the restore libcall both loads ra and 
jumps to it). We should ensure combining them give an error.




Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:36-37
+
+  // Do not save RA to SCS if it's not saved to regular stack, i.e.
+  // RA is not subject to overwritten.
+  std::vector  = MF.getFrameInfo().getCalleeSavedInfo();





Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:43
+
+  // Get shadow call stack pointer register.
+  Register SCSPReg = RISCVABI::getSCSPReg();

Pointless comment; remove



Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:46
+
+  // Emit an error message and bail out.
+  if (!STI.isRegisterReservedByUser(SCSPReg)) {

Pointless comment; remove



Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:53
+
+  DebugLoc DL = MI != MBB.end() ? MI->getDebugLoc() : DebugLoc();
+

This should be passed in as an argument IMO (same for the epilogue) given the 
standard prologue/epilogue code already has a DebugLoc lying around.



Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:59-60
+  // Store return address to shadow call stack
+  // sw   ra, 0(s2)
+  // addi s2, s2, 4
+  BuildMI(MBB, MI, DL, TII->get(IsRV64 ? RISCV::SD : RISCV::SW))





Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:60
+  // sw   ra, 0(s2)
+  // addi s2, s2, 4
+  BuildMI(MBB, MI, DL, TII->get(IsRV64 ? RISCV::SD : RISCV::SW))

Is it intended that the shadow call stack grows *up* unlike the normal stack?



Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:79-80
+
+  // Do not restore RA from SCS if it's not saved to regular stack, i.e.
+  // RA is not subject to overwritten.
+  std::vector  = MF.getFrameInfo().getCalleeSavedInfo();

No need to repeat ourselves.



Comment at: llvm/lib/Target/RISCV/RISCVFrameLowering.cpp:102-103
+  // Load return address from shadow call stack
+  // addi s2, s2, -4
+  // lw   ra, 0(s2)
+  BuildMI(MBB, MI, DL, TII->get(RISCV::ADDI))

Although in fact you have both a bug and a minor performance issue with this, 
and it should be:

```
  // l[w|d] ra, [-4|-8](s2)
  // addi   s2, s2, -[4|8]
```

Then there's no read-after-write dependency chain, which is better for 
out-of-order cores.

The bug is that, currently, you risk a signal handler clobbering your SCS slot 
in between the two instructions, since you deallocate the frame before you read 
from it. Will be rare in practice, but a possibility.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84414

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


[PATCH] D87615: [X86] Fix stack alignment on 32-bit Solaris/x86

2020-09-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87615

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


[clang] 4d4f092 - [clang][codegen] Skip adding default function attributes on intrinsics.

2020-09-16 Thread Michael Liao via cfe-commits

Author: Michael Liao
Date: 2020-09-16T14:10:05-04:00
New Revision: 4d4f0922837de3f1aa9862ae8a8d941b3b6e5f78

URL: 
https://github.com/llvm/llvm-project/commit/4d4f0922837de3f1aa9862ae8a8d941b3b6e5f78
DIFF: 
https://github.com/llvm/llvm-project/commit/4d4f0922837de3f1aa9862ae8a8d941b3b6e5f78.diff

LOG: [clang][codegen] Skip adding default function attributes on intrinsics.

- After loading builtin bitcode for linking, skip adding default
  function attributes on LLVM intrinsics as their attributes are
  well-defined and retrieved directly from internal definitions. Adding
  extra attributes on intrinsics results in inconsistent result when
  `-save-temps` is present. Also, that makes few optimizations
  conservative.

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

Added: 
clang/test/CodeGenCUDA/Inputs/device-lib-code.ll
clang/test/CodeGenCUDA/dft-func-attr-skip-intrinsic.hip

Modified: 
clang/lib/CodeGen/CodeGenAction.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 5a6ce0f5dbd5..eda4beff78b7 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -245,8 +245,13 @@ namespace clang {
 bool LinkInModules() {
   for (auto  : LinkModules) {
 if (LM.PropagateAttrs)
-  for (Function  : *LM.Module)
+  for (Function  : *LM.Module) {
+// Skip intrinsics. Keep consistent with how intrinsics are created
+// in LLVM IR.
+if (F.isIntrinsic())
+  continue;
 Gen->CGM().addDefaultFunctionDefinitionAttributes(F);
+  }
 
 CurLinkModule = LM.Module.get();
 

diff  --git a/clang/test/CodeGenCUDA/Inputs/device-lib-code.ll 
b/clang/test/CodeGenCUDA/Inputs/device-lib-code.ll
new file mode 100644
index ..43ec911fb02c
--- /dev/null
+++ b/clang/test/CodeGenCUDA/Inputs/device-lib-code.ll
@@ -0,0 +1,5 @@
+define linkonce_odr protected float @__ocml_fma_f32(float %0, float %1, float 
%2) local_unnamed_addr {
+  %4 = tail call float @llvm.fma.f32(float %0, float %1, float %2)
+  ret float %4
+}
+declare float @llvm.fma.f32(float, float, float)

diff  --git a/clang/test/CodeGenCUDA/dft-func-attr-skip-intrinsic.hip 
b/clang/test/CodeGenCUDA/dft-func-attr-skip-intrinsic.hip
new file mode 100644
index ..9e3e436200fc
--- /dev/null
+++ b/clang/test/CodeGenCUDA/dft-func-attr-skip-intrinsic.hip
@@ -0,0 +1,18 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -x ir -fcuda-is-device -triple amdgcn-amd-amdhsa 
-emit-llvm-bc -disable-llvm-passes -o %t.bc %S/Inputs/device-lib-code.ll
+// RUN: %clang_cc1 -x hip -fcuda-is-device -triple amdgcn-amd-amdhsa 
-mlink-builtin-bitcode %t.bc -emit-llvm -disable-llvm-passes -o - %s | 
FileCheck %s
+
+#include "Inputs/cuda.h"
+
+extern "C" __device__ float __ocml_fma_f32(float x, float y, float z);
+
+__device__ float foo(float x) {
+  return __ocml_fma_f32(x, x, x);
+}
+
+// CHECK: {{^}}define{{.*}} @__ocml_fma_f32{{.*}} [[ATTR1:#[0-9]+]]
+// CHECK: {{^}}declare{{.*}} @llvm.fma.f32{{.*}} [[ATTR2:#[0-9]+]]
+// CHECK: attributes [[ATTR1]] = { convergent
+// CHECK: attributes [[ATTR2]] = {
+// CHECK-NOT: convergent
+// CHECK: }



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


[PATCH] D87761: [clang][codegen] Skip adding default function attributes on intrinsics.

2020-09-16 Thread Michael Liao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4d4f0922837d: [clang][codegen] Skip adding default function 
attributes on intrinsics. (authored by hliao).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87761

Files:
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGenCUDA/Inputs/device-lib-code.ll
  clang/test/CodeGenCUDA/dft-func-attr-skip-intrinsic.hip


Index: clang/test/CodeGenCUDA/dft-func-attr-skip-intrinsic.hip
===
--- /dev/null
+++ clang/test/CodeGenCUDA/dft-func-attr-skip-intrinsic.hip
@@ -0,0 +1,18 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -x ir -fcuda-is-device -triple amdgcn-amd-amdhsa 
-emit-llvm-bc -disable-llvm-passes -o %t.bc %S/Inputs/device-lib-code.ll
+// RUN: %clang_cc1 -x hip -fcuda-is-device -triple amdgcn-amd-amdhsa 
-mlink-builtin-bitcode %t.bc -emit-llvm -disable-llvm-passes -o - %s | 
FileCheck %s
+
+#include "Inputs/cuda.h"
+
+extern "C" __device__ float __ocml_fma_f32(float x, float y, float z);
+
+__device__ float foo(float x) {
+  return __ocml_fma_f32(x, x, x);
+}
+
+// CHECK: {{^}}define{{.*}} @__ocml_fma_f32{{.*}} [[ATTR1:#[0-9]+]]
+// CHECK: {{^}}declare{{.*}} @llvm.fma.f32{{.*}} [[ATTR2:#[0-9]+]]
+// CHECK: attributes [[ATTR1]] = { convergent
+// CHECK: attributes [[ATTR2]] = {
+// CHECK-NOT: convergent
+// CHECK: }
Index: clang/test/CodeGenCUDA/Inputs/device-lib-code.ll
===
--- /dev/null
+++ clang/test/CodeGenCUDA/Inputs/device-lib-code.ll
@@ -0,0 +1,5 @@
+define linkonce_odr protected float @__ocml_fma_f32(float %0, float %1, float 
%2) local_unnamed_addr {
+  %4 = tail call float @llvm.fma.f32(float %0, float %1, float %2)
+  ret float %4
+}
+declare float @llvm.fma.f32(float, float, float)
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -245,8 +245,13 @@
 bool LinkInModules() {
   for (auto  : LinkModules) {
 if (LM.PropagateAttrs)
-  for (Function  : *LM.Module)
+  for (Function  : *LM.Module) {
+// Skip intrinsics. Keep consistent with how intrinsics are created
+// in LLVM IR.
+if (F.isIntrinsic())
+  continue;
 Gen->CGM().addDefaultFunctionDefinitionAttributes(F);
+  }
 
 CurLinkModule = LM.Module.get();
 


Index: clang/test/CodeGenCUDA/dft-func-attr-skip-intrinsic.hip
===
--- /dev/null
+++ clang/test/CodeGenCUDA/dft-func-attr-skip-intrinsic.hip
@@ -0,0 +1,18 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -x ir -fcuda-is-device -triple amdgcn-amd-amdhsa -emit-llvm-bc -disable-llvm-passes -o %t.bc %S/Inputs/device-lib-code.ll
+// RUN: %clang_cc1 -x hip -fcuda-is-device -triple amdgcn-amd-amdhsa -mlink-builtin-bitcode %t.bc -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
+
+#include "Inputs/cuda.h"
+
+extern "C" __device__ float __ocml_fma_f32(float x, float y, float z);
+
+__device__ float foo(float x) {
+  return __ocml_fma_f32(x, x, x);
+}
+
+// CHECK: {{^}}define{{.*}} @__ocml_fma_f32{{.*}} [[ATTR1:#[0-9]+]]
+// CHECK: {{^}}declare{{.*}} @llvm.fma.f32{{.*}} [[ATTR2:#[0-9]+]]
+// CHECK: attributes [[ATTR1]] = { convergent
+// CHECK: attributes [[ATTR2]] = {
+// CHECK-NOT: convergent
+// CHECK: }
Index: clang/test/CodeGenCUDA/Inputs/device-lib-code.ll
===
--- /dev/null
+++ clang/test/CodeGenCUDA/Inputs/device-lib-code.ll
@@ -0,0 +1,5 @@
+define linkonce_odr protected float @__ocml_fma_f32(float %0, float %1, float %2) local_unnamed_addr {
+  %4 = tail call float @llvm.fma.f32(float %0, float %1, float %2)
+  ret float %4
+}
+declare float @llvm.fma.f32(float, float, float)
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -245,8 +245,13 @@
 bool LinkInModules() {
   for (auto  : LinkModules) {
 if (LM.PropagateAttrs)
-  for (Function  : *LM.Module)
+  for (Function  : *LM.Module) {
+// Skip intrinsics. Keep consistent with how intrinsics are created
+// in LLVM IR.
+if (F.isIntrinsic())
+  continue;
 Gen->CGM().addDefaultFunctionDefinitionAttributes(F);
+  }
 
 CurLinkModule = LM.Module.get();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87779: [SyntaxTree] Test `findFirstLeaf` and `findLastLeaf`

2020-09-16 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.
eduucaldas requested review of this revision.

- Introduce `TreeTest.cpp` to unit test `Tree.h`
- Add `generateAllTreesWithShape` to generating test cases
- Add tests for `findFirstLeaf` and `findLastLeaf`
- Fix implementations of `findFirstLeaf` and `findLastLeaf` that had

been broken when empty `Tree` were present.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87779

Files:
  clang/lib/Tooling/Syntax/Tree.cpp
  clang/unittests/Tooling/Syntax/CMakeLists.txt
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -0,0 +1,141 @@
+//===- TreeTest.cpp -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file tests the Syntax Tree base API.
+//
+//===--===//
+
+#include "clang/Tooling/Syntax/Tree.h"
+#include "TreeTestBase.h"
+#include "clang/Tooling/Syntax/BuildTree.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace clang::syntax;
+
+namespace {
+
+class TreeTest : public SyntaxTreeTest {
+protected:
+  ::testing::AssertionResult treeDumpEqual(const syntax::Node *Root,
+   StringRef Dump) {
+if (!Root)
+  return ::testing::AssertionFailure()
+ << "Root was not built successfully.";
+
+auto Actual = StringRef(Root->dump(Arena->getSourceManager())).trim().str();
+auto Expected = Dump.trim().str();
+// EXPECT_EQ shows the diff between the two strings if they are different.
+EXPECT_EQ(Expected, Actual);
+if (Actual != Expected) {
+  return ::testing::AssertionFailure();
+}
+return ::testing::AssertionSuccess();
+  }
+
+  Tree *createTree(ArrayRef Children) {
+auto ChildrenWithRoles = std::vector>();
+ChildrenWithRoles.reserve(Children.size());
+for (const auto *Child : Children) {
+  ChildrenWithRoles.push_back(
+  std::make_pair(deepCopy(*Arena, Child), NodeRole::Unknown));
+}
+return clang::syntax::createTree(*Arena, ChildrenWithRoles,
+ NodeKind::UnknownExpression);
+  }
+
+  // Generate Forests by combining `Children` under `ParentCount` Trees.
+  //
+  // We do this recursively.
+  std::vector>
+  generateAllForests(ArrayRef Children, unsigned ParentCount) {
+assert(ParentCount > 0);
+// If there is only one Parent node, we need to combine `Children` under
+// this Parent.
+if (ParentCount == 1)
+  return {{createTree(Children)}};
+
+// Otherwise, we combine `ChildrenCount` children under the last parent and
+// solve the smaller problem without these children and this parent. Finally
+// we combine the results for every possible `ChildrenCount`.
+auto AllForests = std::vector>();
+for (unsigned ChildrenCount = 0; ChildrenCount <= Children.size();
+ ++ChildrenCount) {
+  auto *LastParent = createTree(Children.take_back(ChildrenCount));
+  for (auto  : generateAllForests(Children.drop_back(ChildrenCount),
+ ParentCount - 1)) {
+Forest.push_back(LastParent);
+AllForests.push_back(Forest);
+  }
+}
+return AllForests;
+  }
+
+  // Generates all trees with a `Base` layer of `Node`s and `NodeCountPerLayer`
+  // `Node`s per layer. An example of Tree with `Base` = {`(`, `)`} and
+  // `NodeCountPerLayer` = {2, 2}:
+  //  Tree
+  //  |-Tree
+  //  `-Tree
+  //|-Tree
+  //| `-'('
+  //`-Tree
+  //  `-')'
+  std::vector
+  generateAllTreesWithShape(ArrayRef Base,
+ArrayRef NodeCountPerLayer) {
+auto GenerateNextLayers = [this](ArrayRef> Bases,
+ unsigned NodeCount) {
+  auto NextLayers = std::vector>();
+  for (const auto  : Bases) {
+for (const auto  : generateAllForests(Base, NodeCount)) {
+  NextLayers.push_back(
+  std::vector(NextLayer.begin(), NextLayer.end()));
+}
+  }
+  return NextLayers;
+};
+
+auto Layers = std::vector>({Base});
+for (auto NodeCount : NodeCountPerLayer) {
+  Layers = GenerateNextLayers(Layers, NodeCount);
+}
+
+auto AllTrees = std::vector();
+AllTrees.reserve(Layers.size());
+for (const auto  : Layers) {
+  AllTrees.push_back(createTree(Layer));
+}
+return AllTrees;
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(TreeTests, TreeTest,
+ 

[clang] 4d43734 - fix test no-rtti.cpp

2020-09-16 Thread Zequan Wu via cfe-commits

Author: Zequan Wu
Date: 2020-09-16T11:03:15-07:00
New Revision: 4d437348d24d6342bdeb3ad84a64e57a889a0ea2

URL: 
https://github.com/llvm/llvm-project/commit/4d437348d24d6342bdeb3ad84a64e57a889a0ea2
DIFF: 
https://github.com/llvm/llvm-project/commit/4d437348d24d6342bdeb3ad84a64e57a889a0ea2.diff

LOG: fix test no-rtti.cpp

Added: 


Modified: 
clang/test/SemaCXX/no-rtti.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/no-rtti.cpp b/clang/test/SemaCXX/no-rtti.cpp
index e0b57153c24c..8082da219d5a 100644
--- a/clang/test/SemaCXX/no-rtti.cpp
+++ b/clang/test/SemaCXX/no-rtti.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -fno-rtti %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsyntax-only -verify 
-fno-rtti %s
 
 namespace std {
   class type_info;



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


[PATCH] D87163: [DSE] Switch to MemorySSA-backed DSE by default.

2020-09-16 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.



In D87163#2276899 , @dmajor wrote:

> In D87163#2275896 , @asbirlea wrote:
>
>> I checked in a fix in https://reviews.llvm.org/rGfc8200633122, but I haven't 
>> yet verified it addresses all the failures reported.
>
> Thanks, I've confirmed that this fixes our tests in their original form (not 
> reduced).
>
> Our day-to-day testing of LLVM trunk is limited though, maybe one-tenth of 
> our full suite. Since this code has some risks, I could start a full run to 
> throw more testing at it. But that takes more machine capacity and human 
> effort to remove flaky failures, so I'd prefer to wait until the odds are 
> good that there won't be further changes. Let me know when you think it's 
> ready.

I think I managed to come up with another test case that unfortunately is not 
covered by the recent fix. I think we might need to be even more conservative 
when walking across MemoryPhis and put up D87778 
, which includes the test case, which is 
crafted so that the result of PHI translation dominate the relevant blocks 
during translation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87163

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


[PATCH] D78979: OpenCL: Include builtin header by default

2020-09-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 292275.
arsenm added a comment.
Herald added subscribers: wenlei, dang.

Rebase


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

https://reviews.llvm.org/D78979

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
  clang/test/CodeGenOpenCL/atomic-ops-libcall.cl
  clang/test/CodeGenOpenCL/atomic-ops.cl
  clang/test/CodeGenOpenCL/bool_cast.cl
  clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
  clang/test/CodeGenOpenCL/enqueue-kernel-non-entry-block.cl
  clang/test/CodeGenOpenCL/ext-int-shift.cl
  clang/test/CodeGenOpenCL/fpmath.cl
  clang/test/CodeGenOpenCL/half.cl
  clang/test/CodeGenOpenCL/null_queue.cl
  clang/test/CodeGenOpenCL/overload.cl
  clang/test/Driver/nostdinc.cl
  clang/test/Parser/opencl-atomics-cl20.cl
  clang/test/SemaOpenCL/atomic-ops.cl
  clang/test/SemaOpenCL/cl20-device-side-enqueue.cl
  clang/test/SemaOpenCL/extensions.cl
  clang/test/SemaOpenCL/half.cl
  clang/test/SemaOpenCL/null_queue.cl
  clang/test/SemaOpenCL/sampler_t.cl
  clang/unittests/AST/MatchVerifier.h

Index: clang/unittests/AST/MatchVerifier.h
===
--- clang/unittests/AST/MatchVerifier.h
+++ clang/unittests/AST/MatchVerifier.h
@@ -117,6 +117,7 @@
 FileName = "input.cc";
 break;
   case Lang_OpenCL:
+Args.push_back("-nostdinc");
 FileName = "input.cl";
 break;
   case Lang_OBJCXX:
Index: clang/test/SemaOpenCL/sampler_t.cl
===
--- clang/test/SemaOpenCL/sampler_t.cl
+++ clang/test/SemaOpenCL/sampler_t.cl
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple amdgcn--amdhsa
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -triple spir-unknown-unknown
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple amdgcn--amdhsa
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -triple spir-unknown-unknown
+// RUN: %clang_cc1 %s -fno-include-default-header -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -fno-include-default-header -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple amdgcn--amdhsa
+// RUN: %clang_cc1 %s -fno-include-default-header -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -triple spir-unknown-unknown
+// RUN: %clang_cc1 %s -fno-include-default-header -cl-std=CL2.0 -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -fno-include-default-header -cl-std=CL2.0 -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -Wspir-compat -triple amdgcn--amdhsa
+// RUN: %clang_cc1 %s -fno-include-default-header -cl-std=CL2.0 -verify -pedantic -fsyntax-only -DCHECK_SAMPLER_VALUE -triple spir-unknown-unknown
 
 #define CLK_ADDRESS_CLAMP_TO_EDGE   2
 #define CLK_NORMALIZED_COORDS_TRUE  1
Index: clang/test/SemaOpenCL/null_queue.cl
===
--- clang/test/SemaOpenCL/null_queue.cl
+++ clang/test/SemaOpenCL/null_queue.cl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -fno-include-default-header -cl-std=CL2.0 -verify -pedantic -fsyntax-only
 extern queue_t get_default_queue();
 
 void queue_arg(queue_t); // expected-note {{passing argument to parameter here}}
Index: clang/test/SemaOpenCL/half.cl
===
--- clang/test/SemaOpenCL/half.cl
+++ clang/test/SemaOpenCL/half.cl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -Wno-unused-value -triple spir-unknown-unknown
+// RUN: %clang_cc1 %s -fno-include-default-header -verify -pedantic -fsyntax-only -Wno-unused-value -triple spir-unknown-unknown
 
 #pragma OPENCL EXTENSION cl_khr_fp16 : disable
 constant float f = 1.0h; // expected-error{{half precision constant requires cl_khr_fp16}}
Index: clang/test/SemaOpenCL/extensions.cl
===
--- clang/test/SemaOpenCL/extensions.cl
+++ clang/test/SemaOpenCL/extensions.cl
@@ -1,33 +1,33 @@
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.2 -DFP64
+// RUN: %clang_cc1 %s -fno-include-default-header -triple spir-unknown-unknown -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -fno-include-default-header -triple spir-unknown-unknown -verify -pedantic -fsyntax-only -cl-std=CL1.1
+// 

[PATCH] D84414: [RISCV] Support Shadow Call Stack

2020-09-16 Thread Z. Zheng via Phabricator via cfe-commits
zzheng updated this revision to Diff 292274.
zzheng added a comment.

rebase & ping..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84414

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/test/CodeGen/shadowcallstack-attr.c
  clang/test/Driver/sanitizer-ld.c
  llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
  llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.h
  llvm/test/CodeGen/RISCV/shadowcallstack.ll

Index: llvm/test/CodeGen/RISCV/shadowcallstack.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/shadowcallstack.ll
@@ -0,0 +1,174 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv32 -mattr=+reserve-x18 -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s --check-prefix=RV32
+; RUN: llc -mtriple=riscv64 -mattr=+reserve-x18 -verify-machineinstrs < %s \
+; RUN:   | FileCheck %s --check-prefix=RV64
+
+define void @f1() shadowcallstack {
+; RV32-LABEL: f1:
+; RV32:   # %bb.0:
+; RV32-NEXT:ret
+;
+; RV64-LABEL: f1:
+; RV64:   # %bb.0:
+; RV64-NEXT:ret
+  ret void
+}
+
+declare void @foo()
+
+define void @f2() shadowcallstack {
+; RV32-LABEL: f2:
+; RV32:   # %bb.0:
+; RV32-NEXT:tail foo
+;
+; RV64-LABEL: f2:
+; RV64:   # %bb.0:
+; RV64-NEXT:tail foo
+  tail call void @foo()
+  ret void
+}
+
+declare i32 @bar()
+
+define i32 @f3() shadowcallstack {
+; RV32-LABEL: f3:
+; RV32:   # %bb.0:
+; RV32-NEXT:sw ra, 0(s2)
+; RV32-NEXT:addi s2, s2, 4
+; RV32-NEXT:addi sp, sp, -16
+; RV32-NEXT:.cfi_def_cfa_offset 16
+; RV32-NEXT:sw ra, 12(sp)
+; RV32-NEXT:.cfi_offset ra, -4
+; RV32-NEXT:call bar
+; RV32-NEXT:lw ra, 12(sp)
+; RV32-NEXT:addi sp, sp, 16
+; RV32-NEXT:addi s2, s2, -4
+; RV32-NEXT:lw ra, 0(s2)
+; RV32-NEXT:ret
+;
+; RV64-LABEL: f3:
+; RV64:   # %bb.0:
+; RV64-NEXT:sd ra, 0(s2)
+; RV64-NEXT:addi s2, s2, 8
+; RV64-NEXT:addi sp, sp, -16
+; RV64-NEXT:.cfi_def_cfa_offset 16
+; RV64-NEXT:sd ra, 8(sp)
+; RV64-NEXT:.cfi_offset ra, -8
+; RV64-NEXT:call bar
+; RV64-NEXT:ld ra, 8(sp)
+; RV64-NEXT:addi sp, sp, 16
+; RV64-NEXT:addi s2, s2, -8
+; RV64-NEXT:ld ra, 0(s2)
+; RV64-NEXT:ret
+  %res = call i32 @bar()
+  %res1 = add i32 %res, 1
+  ret i32 %res
+}
+
+define i32 @f4() shadowcallstack {
+; RV32-LABEL: f4:
+; RV32:   # %bb.0:
+; RV32-NEXT:sw ra, 0(s2)
+; RV32-NEXT:addi s2, s2, 4
+; RV32-NEXT:addi sp, sp, -16
+; RV32-NEXT:.cfi_def_cfa_offset 16
+; RV32-NEXT:sw ra, 12(sp)
+; RV32-NEXT:sw s0, 8(sp)
+; RV32-NEXT:sw s1, 4(sp)
+; RV32-NEXT:sw s3, 0(sp)
+; RV32-NEXT:.cfi_offset ra, -4
+; RV32-NEXT:.cfi_offset s0, -8
+; RV32-NEXT:.cfi_offset s1, -12
+; RV32-NEXT:.cfi_offset s3, -16
+; RV32-NEXT:call bar
+; RV32-NEXT:mv s3, a0
+; RV32-NEXT:call bar
+; RV32-NEXT:mv s1, a0
+; RV32-NEXT:call bar
+; RV32-NEXT:mv s0, a0
+; RV32-NEXT:call bar
+; RV32-NEXT:add a1, s3, s1
+; RV32-NEXT:add a0, s0, a0
+; RV32-NEXT:add a0, a1, a0
+; RV32-NEXT:lw s3, 0(sp)
+; RV32-NEXT:lw s1, 4(sp)
+; RV32-NEXT:lw s0, 8(sp)
+; RV32-NEXT:lw ra, 12(sp)
+; RV32-NEXT:addi sp, sp, 16
+; RV32-NEXT:addi s2, s2, -4
+; RV32-NEXT:lw ra, 0(s2)
+; RV32-NEXT:ret
+;
+; RV64-LABEL: f4:
+; RV64:   # %bb.0:
+; RV64-NEXT:sd ra, 0(s2)
+; RV64-NEXT:addi s2, s2, 8
+; RV64-NEXT:addi sp, sp, -32
+; RV64-NEXT:.cfi_def_cfa_offset 32
+; RV64-NEXT:sd ra, 24(sp)
+; RV64-NEXT:sd s0, 16(sp)
+; RV64-NEXT:sd s1, 8(sp)
+; RV64-NEXT:sd s3, 0(sp)
+; RV64-NEXT:.cfi_offset ra, -8
+; RV64-NEXT:.cfi_offset s0, -16
+; RV64-NEXT:.cfi_offset s1, -24
+; RV64-NEXT:.cfi_offset s3, -32
+; RV64-NEXT:call bar
+; RV64-NEXT:mv s3, a0
+; RV64-NEXT:call bar
+; RV64-NEXT:mv s1, a0
+; RV64-NEXT:call bar
+; RV64-NEXT:mv s0, a0
+; RV64-NEXT:call bar
+; RV64-NEXT:add a1, s3, s1
+; RV64-NEXT:add a0, s0, a0
+; RV64-NEXT:addw a0, a1, a0
+; RV64-NEXT:ld s3, 0(sp)
+; RV64-NEXT:ld s1, 8(sp)
+; RV64-NEXT:ld s0, 16(sp)
+; RV64-NEXT:ld ra, 24(sp)
+; RV64-NEXT:addi sp, sp, 32
+; RV64-NEXT:addi s2, s2, -8
+; RV64-NEXT:ld ra, 0(s2)
+; RV64-NEXT:ret
+  %res1 = call i32 @bar()
+  %res2 = call i32 @bar()
+  %res3 = call i32 @bar()
+  %res4 = call i32 @bar()
+  %res12 = add i32 %res1, %res2
+  %res34 = add i32 %res3, %res4
+  %res1234 = add i32 %res12, %res34
+  ret i32 %res1234
+}
+
+define i32 @f5() shadowcallstack nounwind {
+; RV32-LABEL: f5:
+; RV32:   # %bb.0:
+; RV32-NEXT:sw ra, 0(s2)
+; RV32-NEXT:addi s2, s2, 4
+; RV32-NEXT:addi sp, sp, -16
+; RV32-NEXT:sw ra, 12(sp)
+; RV32-NEXT:call bar
+; RV32-NEXT:lw ra, 12(sp)
+; RV32-NEXT:addi 

[PATCH] D87532: Sema: add support for `__attribute__((__swift_bridge__))`

2020-09-16 Thread Saleem Abdulrasool via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG77a01d9498a7: Sema: add support for 
`__attribute__((__swift_bridge__))` (authored by compnerd).

Changed prior to commit:
  https://reviews.llvm.org/D87532?vs=292018=292273#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87532

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/AST/attr-swift_bridge.m
  clang/test/SemaObjC/attr-swift_bridge.m

Index: clang/test/SemaObjC/attr-swift_bridge.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridge.m
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+// expected-error@+1 {{'__swift_bridge__' attribute takes one argument}}
+__attribute__((__swift_bridge__))
+@interface I
+@end
+
+// expected-error@+1 {{'__swift_bridge__' attribute requires a string}}
+__attribute__((__swift_bridge__(1)))
+@interface J
+@end
+
+// expected-error@+1 {{'__swift_bridge__' attribute takes one argument}}
+__attribute__((__swift_bridge__("K", 1)))
+@interface K
+@end
+
+@interface L
+// expected-error@+1 {{'__swift_bridge__' attribute only applies to tag types, typedefs, Objective-C interfaces, and Objective-C protocols}}
+- (void)method __attribute__((__swift_bridge__("method")));
+@end
+
+__attribute__((__swift_bridge__("Array")))
+@interface NSArray
+@end
+
+__attribute__((__swift_bridge__("ProtocolP")))
+@protocol P
+@end
+
+typedef NSArray *NSArrayAlias __attribute__((__swift_bridge__("ArrayAlias")));
+
+struct __attribute__((__swift_bridge__("StructT"))) T {};
Index: clang/test/AST/attr-swift_bridge.m
===
--- /dev/null
+++ clang/test/AST/attr-swift_bridge.m
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -ast-dump %s | FileCheck %s
+
+struct __attribute__((__swift_bridge__("BridgedS"))) S;
+// CHECK: RecordDecl {{.*}} struct S
+// CHECK: SwiftBridgeAttr {{.*}} "BridgedS"
+
+struct S {
+};
+
+// CHECK: RecordDecl {{.*}} struct S definition
+// CHECK: SwiftBridgeAttr {{.*}} Inherited "BridgedS"
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5524,6 +5524,22 @@
   D->addAttr(::new (S.Context) ObjCPreciseLifetimeAttr(S.Context, AL));
 }
 
+static void handleSwiftBridge(Sema , Decl *D, const ParsedAttr ) {
+  // Make sure that there is a string literal as the annotation's single
+  // argument.
+  StringRef BT;
+  if (!S.checkStringLiteralArgumentAttr(AL, 0, BT))
+return;
+
+  // Don't duplicate annotations that are already set.
+  if (D->hasAttr()) {
+S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
+return;
+  }
+
+  D->addAttr(::new (S.Context) SwiftBridgeAttr(S.Context, AL, BT));
+}
+
 static bool isErrorParameter(Sema , QualType QT) {
   const auto *PT = QT->getAs();
   if (!PT)
@@ -7533,6 +7549,9 @@
 break;
 
   // Swift attributes.
+  case ParsedAttr::AT_SwiftBridge:
+handleSwiftBridge(S, D, AL);
+break;
   case ParsedAttr::AT_SwiftBridgedTypedef:
 handleSimpleAttribute(S, D, AL);
 break;
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -3476,6 +3476,30 @@
   }];
 }
 
+def SwiftBridgeDocs : Documentation {
+  let Category = SwiftDocs;
+  let Heading = "swift_bridge";
+  let Content = [{
+The ``swift_bridge`` attribute indicates that the declaration to which the
+attribute appertains is bridged to the named Swift type.
+
+  .. code-block:: c
+
+__attribute__((__objc_root__))
+@interface Base
+- (instancetype)init;
+@end
+
+__attribute__((__swift_bridge__("BridgedI")))
+@interface I : Base
+@end
+
+In this example, the Objective-C interface ``I`` will be made available to Swift
+with the name ``BridgedI``.  It would be possible for the compiler to refer to
+``I`` still in order to bridge the type back to Objective-C.
+  }];
+}
+
 def SwiftBridgedTypedefDocs : Documentation {
   let Category = SwiftDocs;
   let Heading = "swift_bridged";
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2130,6 +2130,14 @@
   let ASTNode = 0;
 }
 
+def SwiftBridge : InheritableAttr {
+  let Spellings = [GNU<"swift_bridge">];
+  let Args = [StringArgument<"SwiftType">];
+  let Subjects = SubjectList<[Tag, TypedefName, ObjCInterface, ObjCProtocol],
+ ErrorDiag>;
+  let Documentation = [SwiftBridgeDocs];
+}
+
 def SwiftBridgedTypedef : InheritableAttr {
   let Spellings = 

[clang] 77a01d9 - Sema: add support for `__attribute__((__swift_bridge__))`

2020-09-16 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2020-09-16T17:54:57Z
New Revision: 77a01d9498a79d2e6e3f366fdb363928f188ec11

URL: 
https://github.com/llvm/llvm-project/commit/77a01d9498a79d2e6e3f366fdb363928f188ec11
DIFF: 
https://github.com/llvm/llvm-project/commit/77a01d9498a79d2e6e3f366fdb363928f188ec11.diff

LOG: Sema: add support for `__attribute__((__swift_bridge__))`

This extends semantic analysis of attributes for Swift interoperability
by introducing the `swift_bridge` attribute.  This attribute enables
bridging Objective-C types to Swift specific types.

This is based on the work of the original changes in
https://github.com/llvm/llvm-project-staging/commit/8afaf3aad2af43cfedca7a24cd817848c4e95c0c

Differential Revision: https://reviews.llvm.org/D87532
Reviewed By: Aaron Ballman

Added: 
clang/test/AST/attr-swift_bridge.m
clang/test/SemaObjC/attr-swift_bridge.m

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 6df348618260..adef5b6a4495 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2130,6 +2130,14 @@ def Regparm : TypeAttr {
   let ASTNode = 0;
 }
 
+def SwiftBridge : InheritableAttr {
+  let Spellings = [GNU<"swift_bridge">];
+  let Args = [StringArgument<"SwiftType">];
+  let Subjects = SubjectList<[Tag, TypedefName, ObjCInterface, ObjCProtocol],
+ ErrorDiag>;
+  let Documentation = [SwiftBridgeDocs];
+}
+
 def SwiftBridgedTypedef : InheritableAttr {
   let Spellings = [GNU<"swift_bridged_typedef">];
   let Subjects = SubjectList<[TypedefName], ErrorDiag>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 7aff443e9a12..8706a3f4578c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3476,6 +3476,30 @@ Swift.
   }];
 }
 
+def SwiftBridgeDocs : Documentation {
+  let Category = SwiftDocs;
+  let Heading = "swift_bridge";
+  let Content = [{
+The ``swift_bridge`` attribute indicates that the declaration to which the
+attribute appertains is bridged to the named Swift type.
+
+  .. code-block:: c
+
+__attribute__((__objc_root__))
+@interface Base
+- (instancetype)init;
+@end
+
+__attribute__((__swift_bridge__("BridgedI")))
+@interface I : Base
+@end
+
+In this example, the Objective-C interface ``I`` will be made available to 
Swift
+with the name ``BridgedI``.  It would be possible for the compiler to refer to
+``I`` still in order to bridge the type back to Objective-C.
+  }];
+}
+
 def SwiftBridgedTypedefDocs : Documentation {
   let Category = SwiftDocs;
   let Heading = "swift_bridged";

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 02ffd752233d..5efc989db576 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5524,6 +5524,22 @@ static void handleObjCPreciseLifetimeAttr(Sema , Decl 
*D,
   D->addAttr(::new (S.Context) ObjCPreciseLifetimeAttr(S.Context, AL));
 }
 
+static void handleSwiftBridge(Sema , Decl *D, const ParsedAttr ) {
+  // Make sure that there is a string literal as the annotation's single
+  // argument.
+  StringRef BT;
+  if (!S.checkStringLiteralArgumentAttr(AL, 0, BT))
+return;
+
+  // Don't duplicate annotations that are already set.
+  if (D->hasAttr()) {
+S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
+return;
+  }
+
+  D->addAttr(::new (S.Context) SwiftBridgeAttr(S.Context, AL, BT));
+}
+
 static bool isErrorParameter(Sema , QualType QT) {
   const auto *PT = QT->getAs();
   if (!PT)
@@ -7533,6 +7549,9 @@ static void ProcessDeclAttribute(Sema , Scope *scope, 
Decl *D,
 break;
 
   // Swift attributes.
+  case ParsedAttr::AT_SwiftBridge:
+handleSwiftBridge(S, D, AL);
+break;
   case ParsedAttr::AT_SwiftBridgedTypedef:
 handleSimpleAttribute(S, D, AL);
 break;

diff  --git a/clang/test/AST/attr-swift_bridge.m 
b/clang/test/AST/attr-swift_bridge.m
new file mode 100644
index ..2caa86bef4c0
--- /dev/null
+++ b/clang/test/AST/attr-swift_bridge.m
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -ast-dump %s | FileCheck %s
+
+struct __attribute__((__swift_bridge__("BridgedS"))) S;
+// CHECK: RecordDecl {{.*}} struct S
+// CHECK: SwiftBridgeAttr {{.*}} "BridgedS"
+
+struct S {
+};
+
+// CHECK: RecordDecl {{.*}} struct S definition
+// CHECK: SwiftBridgeAttr {{.*}} Inherited "BridgedS"

diff  --git a/clang/test/SemaObjC/attr-swift_bridge.m 
b/clang/test/SemaObjC/attr-swift_bridge.m
new file mode 100644
index ..1c8259a6a2e7
--- /dev/null
+++ b/clang/test/SemaObjC/attr-swift_bridge.m
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+// expected-error@+1 {{'__swift_bridge__' 

[PATCH] D87534: Sema: introduce `__attribute__((__swift_name__))`

2020-09-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:104
 
+def ObjCClassMethod
+: SubsetSubjectisInstanceMethod()}],

This change is no longer needed.



Comment at: clang/include/clang/Basic/AttrDocs.td:3584
+The name may be a compound Swift name.  For a type, enum constant, property, or
+variable declaration, the name must be a simple or qualified identifier.
+  }];

A code example showing proper usage would be appreciated.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:4289
+if (Inline->getName() != Name && !Inline->isImplicit()) {
+  Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline;
+  Diag(CI.getLoc(), diag::note_conflicting_attribute);

compnerd wrote:
> aaron.ballman wrote:
> > I think it would be more helpful if the diagnostic said why the attribute 
> > is being ignored (because the arguments don't match).
> Does the note below not accomplish that?
Not really, no. The warning diagnostic itself just says that the attribute is 
ignored, which is the effect but not the rationale. The note (which is easier 
for folks to ignore) says the attribute is conflicting, but conflicting with 
*what* (there could be a half dozen attributes on the same declaration, for 
instance).



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5804-5805
+if (const auto *Method = dyn_cast(D)) {
+  ParamCount = Method->getSelector().getNumArgs();
+  Params = Method->parameters().slice(0, ParamCount);
+} else {

compnerd wrote:
> aaron.ballman wrote:
> > Do you have to worry about functions with `...` variadic parameters and how 
> > those impact counts (for either ObjC or regular methods)?
> No, they are currently not auto-imported AFAIK.
Should such function signatures be rejected here though? (If so, can you add a 
test for that case as well as a test using a K C declaration like `void f()`?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87534

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


[PATCH] D78075: [WIP][Clang][OpenMP] Added support for nowait target in CodeGen

2020-09-16 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

> If I remember correctly, you may yield the thread inside a target region 
> after enqueuing kernels and transfers. So even with 1 thread, there is chance 
> to run other tasks without finishing this target. Isn't that possible?

I assume you were referring to `taskyield` because thread yield doesn't make 
sense here. I don't think it can help. Where should we insert the task yield? 
What's more, yielding current task means "blocking" the encountering thread, so 
it has no difference from executing it immediately. Besides, we do 
synchronization at the end of wrapped task.

The only way to make things right w/o using unshackled task when we only have 
one regular OpenMP thread, or say user-visible thread, is to use detached task. 
However, like we talked in the paper, it has some drawbacks so that we decided 
to use unshackled tasks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78075

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


[PATCH] D78075: [WIP][Clang][OpenMP] Added support for nowait target in CodeGen

2020-09-16 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 292271.
tianshilei1992 added a comment.

Fixed `declare_mapper_codegen.cpp` with `CK0`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78075

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_mapper_codegen.cpp

Index: clang/test/OpenMP/declare_mapper_codegen.cpp
===
--- clang/test/OpenMP/declare_mapper_codegen.cpp
+++ clang/test/OpenMP/declare_mapper_codegen.cpp
@@ -22,6 +22,13 @@
 #ifdef CK0
 // Mapper function code generation and runtime interface.
 
+// CK0: [[IDENT_T:%.+]] = type { i32, i32, i32, i32, i8* }
+// CK0: [[ANON_T:%.+]] = type { %class.C* }
+// CK0: [[ANON_T_0:%.+]] = type { %class.C* }
+// CK0: [[KMP_TASK_T_WITH_PRIVATES:%.+]] = type { [[KMP_TASK_T:%.+]], [[KMP_PRIVATES_T:%.+]] }
+// CK0: [[KMP_TASK_T]] = type { i8*, i32 (i32, i8*)*, i32, %union{{.+}}, %union{{.+}} }
+// CK0: [[KMP_TASK_T_WITH_PRIVATES_1:%.+]] = type { [[KMP_TASK_T]], [[KMP_PRIVATES_T_1:%.+]] }
+
 // CK0-LABEL: @.__omp_offloading_{{.*}}foo{{.*}}.region_id = weak constant i8 0
 // CK0-64: [[SIZES:@.+]] = {{.+}}constant [1 x i64] [i64 16]
 // CK0-32: [[SIZES:@.+]] = {{.+}}constant [1 x i64] [i64 8]
@@ -248,25 +255,18 @@
   // CK0-DAG: store %class.C* [[VAL:%[^,]+]], %class.C** [[CBP1]]
   // CK0-DAG: store %class.C* [[VAL]], %class.C** [[CP1]]
   // CK0-DAG: store i8* bitcast (void (i8*, i8*, i8*, i64, i64)* [[MPRFUNC]] to i8*), i8** [[MPR1]]
-  // CK0: call void [[KERNEL:@.+]](%class.C* [[VAL]])
+  // CK0: call void [[KERNEL_1:@.+]](%class.C* [[VAL]])
   #pragma omp target map(mapper(id),tofrom: c)
   {
 ++c.a;
   }
 
-  // CK0-DAG: call i32 @__tgt_target_nowait_mapper(i64 {{.+}}, i8* {{.+}}, i32 1, i8** [[BPGEP:%[0-9]+]], i8** [[PGEP:%[0-9]+]], {{.+}}[[NWSIZES]]{{.+}}, {{.+}}[[NWTYPES]]{{.+}}, i8** [[MPRGEP:%.+]])
-  // CK0-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BPS:%[^,]+]], i32 0, i32 0
-  // CK0-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0
-  // CK0-DAG: [[MPRGEP]] = bitcast [1 x i8*]* [[MPR:%[^,]+]] to i8**
-  // CK0-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0
-  // CK0-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0
-  // CK0-DAG: [[MPR1:%.+]] = getelementptr inbounds {{.+}}[[MPR]], i[[sz]] 0, i[[sz]] 0
-  // CK0-DAG: [[CBP1:%.+]] = bitcast i8** [[BP1]] to %class.C**
-  // CK0-DAG: [[CP1:%.+]] = bitcast i8** [[P1]] to %class.C**
-  // CK0-DAG: store %class.C* [[VAL:%[^,]+]], %class.C** [[CBP1]]
-  // CK0-DAG: store %class.C* [[VAL]], %class.C** [[CP1]]
-  // CK0-DAG: store i8* bitcast (void (i8*, i8*, i8*, i64, i64)* [[MPRFUNC]] to i8*), i8** [[MPR1]]
-  // CK0: call void [[KERNEL:@.+]](%class.C* [[VAL]])
+  // CK0-32: [[TASK:%.+]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* {{@.+}}, i32 {{%.+}}, i32 1, i32 40, i32 4, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CK0-64: [[TASK:%.+]] = call i8* @__kmpc_omp_target_task_alloc([[IDENT_T]]* {{@.+}}, i32 {{%.+}}, i32 1, i64 72, i64 8, i32 (i32, i8*)* bitcast (i32 (i32, [[KMP_TASK_T_WITH_PRIVATES]]*)* [[TASK_ENTRY:@.+]] to i32 (i32, i8*)*), i64 -1)
+  // CK0: [[TASK_CAST:%.+]] = bitcast i8* [[TASK]] to [[KMP_TASK_T_WITH_PRIVATES]]*
+  // CK0: [[TASK_CAST_GET:%.+]] = getelementptr inbounds [[KMP_TASK_T_WITH_PRIVATES]], [[KMP_TASK_T_WITH_PRIVATES]]* [[TASK_CAST]], i32 0, i32 0
+  // CK0: {{.+}} = getelementptr inbounds [[KMP_TASK_T]], [[KMP_TASK_T]]* [[TASK_CAST_GET]], i32 0, i32 0
+  // CK0: {{.+}} = call i32 @__kmpc_omp_task([[IDENT_T]]* @1, i32 {{.+}}, i8* [[TASK]])
   #pragma omp target map(mapper(id),tofrom: c) nowait
   {
 ++c.a;
@@ -284,25 +284,18 @@
   // CK0-DAG: store %class.C* [[VAL:%[^,]+]], %class.C** [[CBP1]]
   // CK0-DAG: store %class.C* [[VAL]], %class.C** [[CP1]]
   // CK0-DAG: store i8* bitcast (void (i8*, i8*, i8*, i64, i64)* [[MPRFUNC]] to i8*), i8** [[MPR1]]
-  // CK0: call void [[KERNEL:@.+]](%class.C* [[VAL]])
+  // CK0: call void [[KERNEL_3:@.+]](%class.C* [[VAL]])
   #pragma omp target teams map(mapper(id),to: c)
   {
 ++c.a;
   }
 
-  // CK0-DAG: call i32 @__tgt_target_teams_nowait_mapper(i64 {{.+}}, i8* {{.+}}, i32 1, i8** [[BPGEP:%[0-9]+]], i8** [[PGEP:%[0-9]+]], {{.+}}[[TEAMNWSIZES]]{{.+}}, {{.+}}[[TEAMNWTYPES]]{{.+}}, i8** [[MPRGEP:%.+]], i32 0, i32 0)
-  // CK0-DAG: [[BPGEP]] = getelementptr inbounds {{.+}}[[BPS:%[^,]+]], i32 0, i32 0
-  // CK0-DAG: [[PGEP]] = getelementptr inbounds {{.+}}[[PS:%[^,]+]], i32 0, i32 0
-  // CK0-DAG: [[MPRGEP]] = bitcast [1 x i8*]* [[MPR:%[^,]+]] to i8**
-  // CK0-DAG: [[BP1:%.+]] = getelementptr inbounds {{.+}}[[BPS]], i32 0, i32 0
-  // CK0-DAG: [[P1:%.+]] = getelementptr inbounds {{.+}}[[PS]], i32 0, i32 0
-  // CK0-DAG: [[MPR1:%.+]] = getelementptr inbounds {{.+}}[[MPR]], i[[sz]] 0, i[[sz]] 0
-  // CK0-DAG: 

[PATCH] D87775: [clangd] Add option for disabling AddUsing tweak on some namespaces.

2020-09-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Nice!




Comment at: clang-tools-extra/clangd/Config.h:66
+
+  /// Style of the codebase.
+  struct {

describe elements more precisely?
They are namespaces with/without leading/trailing ::, and sub-namespaces are 
implicitly included.



Comment at: clang-tools-extra/clangd/ConfigCompile.cpp:215
+  for (auto  : F.FullyQualifiedNamespaces)
+FullyQualifiedNamespaces.push_back(std::move(*N));
+  Out.Apply.push_back([FullyQualifiedNamespaces(

this is a good place to validate and/or normalize (leading/trailing ::)



Comment at: clang-tools-extra/clangd/ConfigFragment.h:167
+  struct StyleBlock {
+// List of namespaces that should not appear in "using" declarations.
+std::vector> FullyQualifiedNamespaces;

Can we describe this positively first?

Namespaces whose members should be fully-qualified, rather than via using 
declarations or directives.
Affects availability of the "add using declaration" tweak.



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:197
+  std::string Buf;
+  llvm::raw_string_ostream NamespaceStream(Buf);
+  Namespace.print(NamespaceStream,

validate it's a namespace, and then call printNamespaceScope (AST.h)?

This handles the right spelling of anonymous/inline NSes.



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:208
+// that we do not prefix-match ::foo to ::foobar.
+Banned.consume_front("::");
+Banned.consume_back("::");

we should do this at config compile time instead I think - conceptually simpler 
if we store normalized data



Comment at: clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp:210
+Banned.consume_back("::");
+if (NamespaceStr.startswith(Banned.str() + "::"))
+  return true;

slightly silly, but can we take a stringref, consume Banned, and verify that 
the result is empty or begins with ::?

Avoids a silly string copy, explicitly handles the sub-namespace case, and is 
just more typical of the string code we write.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87775

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


[clang] ebf267b - [Sema][MSVC] warn at dynamic_cast/typeid when /GR- is given

2020-09-16 Thread Zequan Wu via cfe-commits

Author: Zequan Wu
Date: 2020-09-16T10:38:52-07:00
New Revision: ebf267b87d4b557dff488f87f66df3628e3da957

URL: 
https://github.com/llvm/llvm-project/commit/ebf267b87d4b557dff488f87f66df3628e3da957
DIFF: 
https://github.com/llvm/llvm-project/commit/ebf267b87d4b557dff488f87f66df3628e3da957.diff

LOG: [Sema][MSVC] warn at dynamic_cast/typeid when /GR- is given

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

Added: 
clang/test/SemaCXX/ms-no-rtti-data.cpp
clang/test/SemaCXX/no-rtti-data.cpp

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaExprCXX.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6b4dcc850612..a9bd52b8afcd 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1235,3 +1235,5 @@ in addition with the pragmas or -fmax-tokens flag to get 
any warnings.
 }
 
 def WebAssemblyExceptionSpec : DiagGroup<"wasm-exception-spec">;
+
+def RTTI : DiagGroup<"rtti">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e0d700c66724..f6ded1b4ee26 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7451,6 +7451,12 @@ def err_no_typeid_with_fno_rtti : Error<
   "use of typeid requires -frtti">;
 def err_no_dynamic_cast_with_fno_rtti : Error<
   "use of dynamic_cast requires -frtti">;
+def warn_no_dynamic_cast_with_rtti_disabled: Warning<
+  "dynamic_cast will not work since RTTI data is disabled by " 
+  "%select{-fno-rtti-data|/GR-}0">, InGroup;
+def warn_no_typeid_with_rtti_disabled: Warning<
+  "typeid will not work since RTTI data is disabled by "
+  "%select{-fno-rtti-data|/GR-}0">, InGroup;
 
 def err_cannot_form_pointer_to_member_of_reference_type : Error<
   "cannot form a pointer-to-member to member %0 of reference type %1">;

diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index f718154ce6db..d59f1880a7ff 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -889,6 +889,18 @@ void CastOperation::CheckDynamicCast() {
 return;
   }
 
+  // Warns when dynamic_cast is used with RTTI data disabled.
+  if (!Self.getLangOpts().RTTIData) {
+bool MicrosoftABI =
+Self.getASTContext().getTargetInfo().getCXXABI().isMicrosoft();
+bool isClangCL = Self.getDiagnostics().getDiagnosticOptions().getFormat() 
==
+ DiagnosticOptions::MSVC;
+if (MicrosoftABI || !DestPointee->isVoidType())
+  Self.Diag(OpRange.getBegin(),
+diag::warn_no_dynamic_cast_with_rtti_disabled)
+  << isClangCL;
+  }
+
   // Done. Everything else is run-time checks.
   Kind = CK_Dynamic;
 }

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index b5d4276f22b4..08b56413d8bf 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -663,7 +663,16 @@ Sema::ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation 
LParenLoc,
   }
 
   // The operand is an expression.
-  return BuildCXXTypeId(TypeInfoType, OpLoc, (Expr*)TyOrExpr, RParenLoc);
+  ExprResult Result =
+  BuildCXXTypeId(TypeInfoType, OpLoc, (Expr *)TyOrExpr, RParenLoc);
+
+  if (!getLangOpts().RTTIData && !Result.isInvalid())
+if (auto *CTE = dyn_cast(Result.get()))
+  if (CTE->isPotentiallyEvaluated() && !CTE->isMostDerived(Context))
+Diag(OpLoc, diag::warn_no_typeid_with_rtti_disabled)
+<< (getDiagnostics().getDiagnosticOptions().getFormat() ==
+DiagnosticOptions::MSVC);
+  return Result;
 }
 
 /// Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to

diff  --git a/clang/test/SemaCXX/ms-no-rtti-data.cpp 
b/clang/test/SemaCXX/ms-no-rtti-data.cpp
new file mode 100644
index ..aef167d8a373
--- /dev/null
+++ b/clang/test/SemaCXX/ms-no-rtti-data.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 %s -triple x86_64-windows-msvc -fdiagnostics-format msvc 
-fno-rtti-data -fsyntax-only -verify
+
+namespace std {
+struct type_info {};
+} // namespace std
+class B {
+public:
+  virtual ~B() = default;
+};
+
+class D1 : public B {
+public:
+  ~D1() = default;
+};
+
+void f() {
+  B *b = new D1();
+  auto d = dynamic_cast(b);// expected-warning{{dynamic_cast will 
not work since RTTI data is disabled by /GR-}}
+  void *v = dynamic_cast(b); // expected-warning{{dynamic_cast will 
not work since RTTI data is disabled by /GR-}}
+
+  (void)typeid(int);
+  (void)typeid(b);
+  (void)typeid(*b); // expected-warning{{typeid will not work since RTTI data 
is disabled by /GR-}}
+  B b2 = *b;
+  (void)typeid(b2);
+  (void)typeid(*); // expected-warning{{typeid will not work since RTTI 

[PATCH] D86369: [Sema][MSVC] warn at dynamic_cast when /GR- is given

2020-09-16 Thread Zequan Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGebf267b87d4b: [Sema][MSVC] warn at dynamic_cast/typeid when 
/GR- is given (authored by zequanwu).

Changed prior to commit:
  https://reviews.llvm.org/D86369?vs=292017=292269#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86369

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/ms-no-rtti-data.cpp
  clang/test/SemaCXX/no-rtti-data.cpp

Index: clang/test/SemaCXX/no-rtti-data.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/no-rtti-data.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 %s -triple x86_64-unknown-linux -fno-rtti-data -fsyntax-only -verify
+
+namespace std {
+struct type_info {};
+} // namespace std
+class B {
+public:
+  virtual ~B() = default;
+};
+
+class D1 : public B {
+public:
+  ~D1() = default;
+};
+
+void f() {
+  B *b = new D1();
+  auto d = dynamic_cast(b); // expected-warning{{dynamic_cast will not work since RTTI data is disabled by -fno-rtti-data}}
+  void *v = dynamic_cast(b);
+
+  (void)typeid(int);
+  (void)typeid(b);
+  (void)typeid(*b); // expected-warning{{typeid will not work since RTTI data is disabled by -fno-rtti-data}}
+  B b2 = *b;
+  (void)typeid(b2);
+  (void)typeid(*); // expected-warning{{typeid will not work since RTTI data is disabled by -fno-rtti-data}}
+  (void)typeid((B &)b2);
+
+  B  = b2;
+  (void)typeid(br); // expected-warning{{typeid will not work since RTTI data is disabled by -fno-rtti-data}}
+  (void)typeid();
+}
\ No newline at end of file
Index: clang/test/SemaCXX/ms-no-rtti-data.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ms-no-rtti-data.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 %s -triple x86_64-windows-msvc -fdiagnostics-format msvc -fno-rtti-data -fsyntax-only -verify
+
+namespace std {
+struct type_info {};
+} // namespace std
+class B {
+public:
+  virtual ~B() = default;
+};
+
+class D1 : public B {
+public:
+  ~D1() = default;
+};
+
+void f() {
+  B *b = new D1();
+  auto d = dynamic_cast(b);// expected-warning{{dynamic_cast will not work since RTTI data is disabled by /GR-}}
+  void *v = dynamic_cast(b); // expected-warning{{dynamic_cast will not work since RTTI data is disabled by /GR-}}
+
+  (void)typeid(int);
+  (void)typeid(b);
+  (void)typeid(*b); // expected-warning{{typeid will not work since RTTI data is disabled by /GR-}}
+  B b2 = *b;
+  (void)typeid(b2);
+  (void)typeid(*); // expected-warning{{typeid will not work since RTTI data is disabled by /GR-}}
+  (void)typeid((B &)b2);
+
+  B  = b2;
+  (void)typeid(br); // expected-warning{{typeid will not work since RTTI data is disabled by /GR-}}
+  (void)typeid();
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -663,7 +663,16 @@
   }
 
   // The operand is an expression.
-  return BuildCXXTypeId(TypeInfoType, OpLoc, (Expr*)TyOrExpr, RParenLoc);
+  ExprResult Result =
+  BuildCXXTypeId(TypeInfoType, OpLoc, (Expr *)TyOrExpr, RParenLoc);
+
+  if (!getLangOpts().RTTIData && !Result.isInvalid())
+if (auto *CTE = dyn_cast(Result.get()))
+  if (CTE->isPotentiallyEvaluated() && !CTE->isMostDerived(Context))
+Diag(OpLoc, diag::warn_no_typeid_with_rtti_disabled)
+<< (getDiagnostics().getDiagnosticOptions().getFormat() ==
+DiagnosticOptions::MSVC);
+  return Result;
 }
 
 /// Grabs __declspec(uuid()) off a type, or returns 0 if we cannot resolve to
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -889,6 +889,18 @@
 return;
   }
 
+  // Warns when dynamic_cast is used with RTTI data disabled.
+  if (!Self.getLangOpts().RTTIData) {
+bool MicrosoftABI =
+Self.getASTContext().getTargetInfo().getCXXABI().isMicrosoft();
+bool isClangCL = Self.getDiagnostics().getDiagnosticOptions().getFormat() ==
+ DiagnosticOptions::MSVC;
+if (MicrosoftABI || !DestPointee->isVoidType())
+  Self.Diag(OpRange.getBegin(),
+diag::warn_no_dynamic_cast_with_rtti_disabled)
+  << isClangCL;
+  }
+
   // Done. Everything else is run-time checks.
   Kind = CK_Dynamic;
 }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7451,6 +7451,12 @@
   "use of typeid 

[PATCH] D12689: [libc++][static linking] std streams are not initialized prior to their use in static object constructors

2020-09-16 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

In D12689#2277225 , @eastig wrote:

> Abandoned in favour of https://reviews.llvm.org/D31413

Sorry, we had a race condition :-)


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

https://reviews.llvm.org/D12689

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


  1   2   3   >