r361372 - [ARM][AArch64] Fix incorrect handling of alignment in va_arg code generation

2019-05-22 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Wed May 22 04:42:54 2019
New Revision: 361372

URL: http://llvm.org/viewvc/llvm-project?rev=361372&view=rev
Log:
[ARM][AArch64] Fix incorrect handling of alignment in va_arg code generation

Overaligned and underaligned types (i.e. types where the alignment has been
increased or decreased using the aligned and packed attributes) weren't being
correctly handled in all cases, as the unadjusted alignment should be used.

This patch also adjusts getTypeUnadjustedAlign to correctly handle typedefs of
non-aggregate types, which it appears it never had to handle before.

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

Added:
cfe/trunk/test/CodeGen/arm-varargs.c
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/test/CodeGen/aarch64-varargs.c

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=361372&r1=361371&r2=361372&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed May 22 04:42:54 2019
@@ -2130,7 +2130,7 @@ unsigned ASTContext::getTypeUnadjustedAl
 const ASTRecordLayout &Layout = 
getASTObjCInterfaceLayout(ObjCI->getDecl());
 UnadjustedAlign = toBits(Layout.getUnadjustedAlignment());
   } else {
-UnadjustedAlign = getTypeAlign(T);
+UnadjustedAlign = getTypeAlign(T->getUnqualifiedDesugaredType());
   }
 
   MemoizedUnadjustedAlign[T] = UnadjustedAlign;

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=361372&r1=361371&r2=361372&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Wed May 22 04:42:54 2019
@@ -5278,13 +5278,13 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(A
   llvm::BasicBlock *OnStackBlock = CGF.createBasicBlock("vaarg.on_stack");
   llvm::BasicBlock *ContBlock = CGF.createBasicBlock("vaarg.end");
 
-  auto TyInfo = getContext().getTypeInfoInChars(Ty);
-  CharUnits TyAlign = TyInfo.second;
+  CharUnits TySize = getContext().getTypeSizeInChars(Ty);
+  CharUnits TyAlign = getContext().getTypeUnadjustedAlignInChars(Ty);
 
   Address reg_offs_p = Address::invalid();
   llvm::Value *reg_offs = nullptr;
   int reg_top_index;
-  int RegSize = IsIndirect ? 8 : TyInfo.first.getQuantity();
+  int RegSize = IsIndirect ? 8 : TySize.getQuantity();
   if (!IsFPR) {
 // 3 is the field number of __gr_offs
 reg_offs_p = CGF.Builder.CreateStructGEP(VAListAddr, 3, "gr_offs_p");
@@ -5412,8 +5412,8 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(A
 CharUnits SlotSize = BaseAddr.getAlignment();
 if (CGF.CGM.getDataLayout().isBigEndian() && !IsIndirect &&
 (IsHFA || !isAggregateTypeForABI(Ty)) &&
-TyInfo.first < SlotSize) {
-  CharUnits Offset = SlotSize - TyInfo.first;
+TySize < SlotSize) {
+  CharUnits Offset = SlotSize - TySize;
   BaseAddr = CGF.Builder.CreateConstInBoundsByteGEP(BaseAddr, Offset);
 }
 
@@ -5455,7 +5455,7 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(A
   if (IsIndirect)
 StackSize = StackSlotSize;
   else
-StackSize = TyInfo.first.alignTo(StackSlotSize);
+StackSize = TySize.alignTo(StackSlotSize);
 
   llvm::Value *StackSizeC = CGF.Builder.getSize(StackSize);
   llvm::Value *NewStack =
@@ -5465,8 +5465,8 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(A
   CGF.Builder.CreateStore(NewStack, stack_p);
 
   if (CGF.CGM.getDataLayout().isBigEndian() && !isAggregateTypeForABI(Ty) &&
-  TyInfo.first < StackSlotSize) {
-CharUnits Offset = StackSlotSize - TyInfo.first;
+  TySize < StackSlotSize) {
+CharUnits Offset = StackSlotSize - TySize;
 OnStackAddr = CGF.Builder.CreateConstInBoundsByteGEP(OnStackAddr, Offset);
   }
 
@@ -5484,7 +5484,7 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(A
 
   if (IsIndirect)
 return Address(CGF.Builder.CreateLoad(ResAddr, "vaarg.addr"),
-   TyInfo.second);
+   TyAlign);
 
   return ResAddr;
 }
@@ -6210,19 +6210,19 @@ Address ARMABIInfo::EmitVAArg(CodeGenFun
 return Addr;
   }
 
-  auto TyInfo = getContext().getTypeInfoInChars(Ty);
-  CharUnits TyAlignForABI = TyInfo.second;
+  CharUnits TySize = getContext().getTypeSizeInChars(Ty);
+  CharUnits TyAlignForABI = getContext().getTypeUnadjustedAlignInChars(Ty);
 
   // Use indirect if size of the illegal vector is bigger than 16 bytes.
   bool IsIndirect = false;
   const Type *Base = nullptr;
   uint64_t Members = 0;
-  if (TyInfo.first > CharUnits::fromQuantity(16) && isIllegalVectorType(Ty)) {
+  if (TySize > CharUnits::fromQuantity(16) && isIllegalVectorType(Ty)) {
 IsIndirect = true;
 
   // ARMv7k passes structs bigger than 16 bytes indirectly, in space
   // allocated by the caller.
-  } else if (TyInfo.first

[libunwind] r373628 - [libunwind] Adjust libunwind_01.pass.cpp test for ARM EHABI

2019-10-03 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Thu Oct  3 10:01:04 2019
New Revision: 373628

URL: http://llvm.org/viewvc/llvm-project?rev=373628&view=rev
Log:
[libunwind] Adjust libunwind_01.pass.cpp test for ARM EHABI

ARM EHABI unwinding tables only store the start address of each function, so the
last function is assumed to cover the entire address space after it. The test
picks an address on the stack assuming that it's in no function, but because of
the above it's actually resolved to the last function. Fix this by using address
0 instead.

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

Modified:
libunwind/trunk/test/libunwind_01.pass.cpp

Modified: libunwind/trunk/test/libunwind_01.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/test/libunwind_01.pass.cpp?rev=373628&r1=373627&r2=373628&view=diff
==
--- libunwind/trunk/test/libunwind_01.pass.cpp (original)
+++ libunwind/trunk/test/libunwind_01.pass.cpp Thu Oct  3 10:01:04 2019
@@ -48,7 +48,7 @@ void test_no_info() {
 abort();
 
   // Set the IP to an address clearly outside any function.
-  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)&context);
+  unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)0);
 
   ret = unw_get_proc_info(&cursor, &info);
   if (ret != UNW_ENOINFO)


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


[clang] 6c906f7 - [Sema] Diagnose more cases of static data members in local or unnamed classes

2020-05-26 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2020-05-26T13:29:59+01:00
New Revision: 6c906f7785dad3a1dea5357cfde0762952c2a2bd

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

LOG: [Sema] Diagnose more cases of static data members in local or unnamed 
classes

We currently diagnose static data members directly contained in unnamed classes,
but we should also diagnose when they're in a class that is nested (directly or
indirectly) in an unnamed class. Do this by iterating up the list of parent
DeclContexts and checking if any is an unnamed class.

Similarly also check for function or method DeclContexts (which includes things
like blocks and openmp captured statements) as then the class is considered to
be a local class, which means static data members aren't allowed.

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/OpenMP/for_loop_messages.cpp
clang/test/SemaCXX/anonymous-struct.cpp
clang/test/SemaCXX/blocks.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 74a4fd8a06de..6fe48c860864 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6885,18 +6885,34 @@ NamedDecl *Sema::ActOnVariableDeclarator(
 
 if (SC == SC_Static && CurContext->isRecord()) {
   if (const CXXRecordDecl *RD = dyn_cast(DC)) {
-// C++ [class.static.data]p2:
-//   A static data member shall not be a direct member of an unnamed
-//   or local class
-// FIXME: or of a (possibly indirectly) nested class thereof.
-if (RD->isLocalClass()) {
+// Walk up the enclosing DeclContexts to check for any that are
+// incompatible with static data members.
+const DeclContext *FunctionOrMethod = nullptr;
+const CXXRecordDecl *AnonStruct = nullptr;
+for (DeclContext *Ctxt = DC; Ctxt; Ctxt = Ctxt->getParent()) {
+  if (Ctxt->isFunctionOrMethod()) {
+FunctionOrMethod = Ctxt;
+break;
+  }
+  const CXXRecordDecl *ParentDecl = dyn_cast(Ctxt);
+  if (ParentDecl && !ParentDecl->getDeclName()) {
+AnonStruct = ParentDecl;
+break;
+  }
+}
+if (FunctionOrMethod) {
+  // C++ [class.static.data]p5: A local class shall not have static 
data
+  // members.
   Diag(D.getIdentifierLoc(),
diag::err_static_data_member_not_allowed_in_local_class)
 << Name << RD->getDeclName() << RD->getTagKind();
-} else if (!RD->getDeclName()) {
+} else if (AnonStruct) {
+  // C++ [class.static.data]p4: Unnamed classes and classes contained
+  // directly or indirectly within unnamed classes shall not contain
+  // static data members.
   Diag(D.getIdentifierLoc(),
diag::err_static_data_member_not_allowed_in_anon_struct)
-<< Name << RD->getTagKind();
+<< Name << AnonStruct->getTagKind();
   Invalid = true;
 } else if (RD->isUnion()) {
   // C++98 [class.union]p1: If a union contains a static data member,

diff  --git a/clang/test/OpenMP/for_loop_messages.cpp 
b/clang/test/OpenMP/for_loop_messages.cpp
index 73c69ede6d12..087db755273a 100644
--- a/clang/test/OpenMP/for_loop_messages.cpp
+++ b/clang/test/OpenMP/for_loop_messages.cpp
@@ -831,3 +831,13 @@ void test_nowait() {
   for (int i = 0; i < 16; ++i)
 ;
 }
+
+void test_static_data_member() {
+#pragma omp parallel
+#pragma omp for
+  for (int i = 0; i < 16; ++i) {
+class X {
+  static int x; // expected-error {{static data member 'x' not allowed in 
local class 'X'}}
+};
+  }
+}

diff  --git a/clang/test/SemaCXX/anonymous-struct.cpp 
b/clang/test/SemaCXX/anonymous-struct.cpp
index 10f6711dd340..333b8f724f4e 100644
--- a/clang/test/SemaCXX/anonymous-struct.cpp
+++ b/clang/test/SemaCXX/anonymous-struct.cpp
@@ -153,3 +153,21 @@ typedef struct {
   const Empty E;
 } C;
 } // namespace ImplicitDecls
+
+struct {
+  static int x; // expected-error {{static data member 'x' not allowed in 
anonymous struct}}
+} static_member_1;
+
+class {
+  struct A {
+static int x; // expected-error {{static data member 'x' not allowed in 
anonymous class}}
+  } x;
+} static_member_2;
+
+union {
+  struct A {
+struct B {
+  static int x; // expected-error {{static data member 'x' not allowed in 
anonymous union}}
+} x;
+  } x;
+} static_member_3;

diff  --git a/clang/test/SemaCXX/blocks.cpp b/clang/test/SemaCXX/blocks.cpp
index aacf63cfab42..5d0aa2af7360 100644
--- a/clang/test/SemaCXX/blocks.cpp
+++ b/clang/test/SemaCXX/blocks.cpp
@@ -153,3 +153,16 @@ void f() {
   auto some_block = ^{ (void)s; };
 }
 }
+
+void static_data

[clang] ce1fa20 - [Driver] When forcing a crash print the bug report message

2020-06-29 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2020-06-29T13:13:12+01:00
New Revision: ce1fa201af77e60d31b48571ffa1f85b919f6245

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

LOG: [Driver] When forcing a crash print the bug report message

Commit a945037e8fd0c30e250a62211469eea6765a36ae moved the printing of the
"PLEASE submit a bug report" message to the crash handler, but that means we
don't print it when forcing a crash using FORCE_CLANG_DIAGNOSTICS_CRASH. Fix
this by adding a function to get the bug report message and printing it when
forcing a crash.

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

Added: 


Modified: 
clang/test/Driver/crash-report-crashfile.m
clang/test/Driver/crash-report-modules.m
clang/test/Driver/crash-report-null.test
clang/tools/driver/driver.cpp
llvm/include/llvm/Support/PrettyStackTrace.h
llvm/lib/Support/PrettyStackTrace.cpp

Removed: 




diff  --git a/clang/test/Driver/crash-report-crashfile.m 
b/clang/test/Driver/crash-report-crashfile.m
index 980b1acd9fed..fd26246073fa 100644
--- a/clang/test/Driver/crash-report-crashfile.m
+++ b/clang/test/Driver/crash-report-crashfile.m
@@ -18,6 +18,7 @@
 const int x = MODULE_MACRO;
 
 // CRASH_ENV: failing because environment variable 
'FORCE_CLANG_DIAGNOSTICS_CRASH' is set
+// CRASH_ENV: PLEASE submit a bug report to {{.*}} and include the crash 
backtrace, preprocessed source, and associated run script.
 // CRASH_ENV: Preprocessed source(s) and associated run script(s) are located 
at:
 // CRASH_ENV-NEXT: note: diagnostic msg: {{.*}}.m
 // CRASH_ENV-NEXT: note: diagnostic msg: {{.*}}.cache

diff  --git a/clang/test/Driver/crash-report-modules.m 
b/clang/test/Driver/crash-report-modules.m
index ded31b4ed4fe..e6d033533791 100644
--- a/clang/test/Driver/crash-report-modules.m
+++ b/clang/test/Driver/crash-report-modules.m
@@ -19,6 +19,7 @@
 @import simple;
 const int x = MODULE_MACRO;
 
+// CHECK: PLEASE submit a bug report to {{.*}} and include the crash 
backtrace, preprocessed source, and associated run script.
 // CHECK: Preprocessed source(s) and associated run script(s) are located at:
 // CHECK-NEXT: note: diagnostic msg: {{.*}}.m
 // CHECK-NEXT: note: diagnostic msg: {{.*}}.cache

diff  --git a/clang/test/Driver/crash-report-null.test 
b/clang/test/Driver/crash-report-null.test
index 7281f5309eb3..05309bf63f27 100644
--- a/clang/test/Driver/crash-report-null.test
+++ b/clang/test/Driver/crash-report-null.test
@@ -3,5 +3,6 @@
 // FIXME: Investigating. "fatal error: file 'nul' modified since it was first 
processed"
 // XFAIL: windows-gnu
 
+// CHECK: PLEASE submit a bug report to {{.*}} and include the crash 
backtrace, preprocessed source, and associated run script.
 // CHECK: Preprocessed source(s) and associated run script(s) are located at:
 // CHECK-NEXT: note: diagnostic msg: {{.*}}null-{{.*}}.c

diff  --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 5e92fc32e6f6..f24fd61e61a5 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -511,6 +511,11 @@ int main(int argc_, const char **argv_) {
   for (const auto &J : C->getJobs())
 if (const Command *C = dyn_cast(&J))
   FailingCommands.push_back(std::make_pair(-1, C));
+
+  // Print the bug report message that would be printed if we did actually
+  // crash, but only if we're crashing due to 
FORCE_CLANG_DIAGNOSTICS_CRASH.
+  if (::getenv("FORCE_CLANG_DIAGNOSTICS_CRASH"))
+llvm::dbgs() << llvm::getBugReportMsg();
 }
 
 for (const auto &P : FailingCommands) {

diff  --git a/llvm/include/llvm/Support/PrettyStackTrace.h 
b/llvm/include/llvm/Support/PrettyStackTrace.h
index 32975f3c5a35..ac25cffde051 100644
--- a/llvm/include/llvm/Support/PrettyStackTrace.h
+++ b/llvm/include/llvm/Support/PrettyStackTrace.h
@@ -41,6 +41,9 @@ namespace llvm {
   /// a crash.
   void setBugReportMsg(const char *Msg);
 
+  /// Get the bug report message that will be output upon a crash.
+  const char *getBugReportMsg();
+
   /// PrettyStackTraceEntry - This class is used to represent a frame of the
   /// "pretty" stack trace that is dumped when a program crashes. You can 
define
   /// subclasses of this and declare them on the program stack: when they are

diff  --git a/llvm/lib/Support/PrettyStackTrace.cpp 
b/llvm/lib/Support/PrettyStackTrace.cpp
index 3d310ed8916e..9072f9d2d2ee 100644
--- a/llvm/lib/Support/PrettyStackTrace.cpp
+++ b/llvm/lib/Support/PrettyStackTrace.cpp
@@ -33,6 +33,10 @@
 
 using namespace llvm;
 
+static const char *BugReportMsg =
+"PLEASE submit a bug report to " BUG_REPORT_URL
+" and include the crash backtrace.\n";
+
 // If backtrace support is not enabled, compile out support for pretty stack
 // traces.  This has the seconda

[clang] [llvm] [clang][AArch64] Add a -mbranch-protection option to enable GCS (PR #75486)

2023-12-14 Thread John Brawn via cfe-commits

https://github.com/john-brawn-arm created 
https://github.com/llvm/llvm-project/pull/75486

-mbranch-protection=gcs (enabled by -mbranch-protection=standard) causes 
generated objects to be marked with the gcs feature. This is done via the 
guarded-control-stack module flag, in a similar way to 
branch-target-enforcement and sign-return-address.

Enabling GCS causes the GNU_PROPERTY_AARCH64_FEATURE_1_GCS bit to be set on 
generated objects. No code generation changes are required, as GCS just 
requires that functions are called using BL and returned from using RET (or 
other similar variant instructions), which is already the case.

>From 2c942a5c2bb3847551d439a73e73b7df6b332b4c Mon Sep 17 00:00:00 2001
From: John Brawn 
Date: Wed, 13 Dec 2023 16:20:33 +
Subject: [PATCH] [clang][AArch64] Add a -mbranch-protection option to enable
 GCS

-mbranch-protection=gcs (enabled by -mbranch-protection=standard)
causes generated objects to be marked with the gcs feature. This is
done via the guarded-control-stack module flag, in a similar way to
branch-target-enforcement and sign-return-address.

Enabling GCS causes the GNU_PROPERTY_AARCH64_FEATURE_1_GCS bit to be
set on generated objects. No code generation changes are required, as
GCS just requires that functions are called using BL and returned from
using RET (or other similar variant instructions), which is already
the case.
---
 clang/include/clang/Basic/LangOptions.def |  1 +
 clang/include/clang/Basic/TargetInfo.h|  1 +
 clang/include/clang/Driver/Options.td |  2 ++
 clang/lib/Basic/Targets/AArch64.cpp   |  7 ++
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 ++
 clang/lib/CodeGen/Targets/AArch64.cpp |  2 ++
 clang/lib/Driver/ToolChains/Clang.cpp |  6 -
 .../CodeGen/aarch64-branch-protection-attr.c  | 22 ---
 clang/test/CodeGen/aarch64-targetattr.c   |  2 +-
 clang/test/Driver/aarch64-security-options.c  | 11 ++
 .../Preprocessor/aarch64-target-features.c| 15 +
 .../llvm/TargetParser/ARMTargetParserCommon.h |  1 +
 llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp |  5 +
 .../TargetParser/ARMTargetParserCommon.cpp|  7 +-
 .../CodeGen/AArch64/note-gnu-property-gcs.ll  | 20 +
 15 files changed, 89 insertions(+), 15 deletions(-)
 create mode 100644 llvm/test/CodeGen/AArch64/note-gnu-property-gcs.ll

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 152d9f65f86dbe..40ec13c345fad1 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -456,6 +456,7 @@ ENUM_LANGOPT(SignReturnAddressScope, 
SignReturnAddressScopeKind, 2, SignReturnAd
 ENUM_LANGOPT(SignReturnAddressKey, SignReturnAddressKeyKind, 1, 
SignReturnAddressKeyKind::AKey,
  "Key used for return address signing")
 LANGOPT(BranchTargetEnforcement, 1, 0, "Branch-target enforcement enabled")
+LANGOPT(GuardedControlStack, 1, 0, "Guarded control stack enabled")
 
 LANGOPT(SpeculativeLoadHardening, 1, 0, "Speculative load hardening enabled")
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ec0189627dfbd2..9e269d723a4174 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1372,6 +1372,7 @@ class TargetInfo : public TransferrableTargetInfo,
 LangOptions::SignReturnAddressKeyKind SignKey =
 LangOptions::SignReturnAddressKeyKind::AKey;
 bool BranchTargetEnforcement = false;
+bool GuardedControlStack = false;
   };
 
   /// Determine if the Architecture in this TargetInfo supports branch
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1b02087425b751..52743a1bb5c852 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6999,6 +6999,8 @@ def msign_return_address_key_EQ : Joined<["-"], 
"msign-return-address-key=">,
 Values<"a_key,b_key">;
 def mbranch_target_enforce : Flag<["-"], "mbranch-target-enforce">,
   MarshallingInfoFlag>;
+def mguarded_control_stack : Flag<["-"], "mguarded-control-stack">,
+  MarshallingInfoFlag>;
 def fno_dllexport_inlines : Flag<["-"], "fno-dllexport-inlines">,
   MarshallingInfoNegativeFlag>;
 def cfguard_no_checks : Flag<["-"], "cfguard-no-checks">,
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index def16c032c869e..4b073c34a26ecf 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -225,6 +225,7 @@ bool AArch64TargetInfo::validateBranchProtection(StringRef 
Spec, StringRef,
 BPI.SignKey = LangOptions::SignReturnAddressKeyKind::BKey;
 
   BPI.BranchTargetEnforcement = PBP.BranchTargetEnforcement;
+  BPI.GuardedControlStack = PBP.GuardedControlStack;
   return true;
 }
 
@@ -531,6 +532,9 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 

[clang] [llvm] [clang][AArch64] Add a -mbranch-protection option to enable GCS (PR #75486)

2024-01-02 Thread John Brawn via cfe-commits

https://github.com/john-brawn-arm updated 
https://github.com/llvm/llvm-project/pull/75486

>From cceb8766d2c93cadc940b45f0817abc5e6d0a225 Mon Sep 17 00:00:00 2001
From: John Brawn 
Date: Wed, 13 Dec 2023 16:20:33 +
Subject: [PATCH] [clang][AArch64] Add a -mbranch-protection option to enable
 GCS

-mbranch-protection=gcs (enabled by -mbranch-protection=standard)
causes generated objects to be marked with the gcs feature. This is
done via the guarded-control-stack module flag, in a similar way to
branch-target-enforcement and sign-return-address.

Enabling GCS causes the GNU_PROPERTY_AARCH64_FEATURE_1_GCS bit to be
set on generated objects. No code generation changes are required, as
GCS just requires that functions are called using BL and returned from
using RET (or other similar variant instructions), which is already
the case.
---
 clang/include/clang/Basic/LangOptions.def |  1 +
 clang/include/clang/Basic/TargetInfo.h|  1 +
 clang/include/clang/Driver/Options.td |  2 ++
 clang/lib/Basic/Targets/AArch64.cpp   |  7 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 ++
 clang/lib/CodeGen/Targets/AArch64.cpp |  2 ++
 clang/lib/Driver/ToolChains/Clang.cpp |  6 +++-
 .../CodeGen/aarch64-branch-protection-attr.c  | 28 +++
 clang/test/CodeGen/aarch64-targetattr.c   |  2 +-
 clang/test/Driver/aarch64-security-options.c  | 11 +---
 .../Preprocessor/aarch64-target-features.c| 15 ++
 .../llvm/TargetParser/ARMTargetParserCommon.h |  1 +
 llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp |  5 
 .../TargetParser/ARMTargetParserCommon.cpp|  5 
 .../CodeGen/AArch64/note-gnu-property-gcs.ll  | 20 +
 15 files changed, 90 insertions(+), 18 deletions(-)
 create mode 100644 llvm/test/CodeGen/AArch64/note-gnu-property-gcs.ll

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 21abc346cf17ac..0428b70c602062 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -457,6 +457,7 @@ ENUM_LANGOPT(SignReturnAddressKey, 
SignReturnAddressKeyKind, 1, SignReturnAddres
  "Key used for return address signing")
 LANGOPT(BranchTargetEnforcement, 1, 0, "Branch-target enforcement enabled")
 LANGOPT(BranchProtectionPAuthLR, 1, 0, "Use PC as a diversifier using PAuthLR 
NOP instructions.")
+LANGOPT(GuardedControlStack, 1, 0, "Guarded control stack enabled")
 
 LANGOPT(SpeculativeLoadHardening, 1, 0, "Speculative load hardening enabled")
 
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index ac3c324c6c29c4..3eb23ebdacf0ed 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1373,6 +1373,7 @@ class TargetInfo : public TransferrableTargetInfo,
 LangOptions::SignReturnAddressKeyKind::AKey;
 bool BranchTargetEnforcement = false;
 bool BranchProtectionPAuthLR = false;
+bool GuardedControlStack = false;
   };
 
   /// Determine if the Architecture in this TargetInfo supports branch
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..457e4e7a7e0c33 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -7002,6 +7002,8 @@ def mbranch_target_enforce : Flag<["-"], 
"mbranch-target-enforce">,
   MarshallingInfoFlag>;
 def mbranch_protection_pauth_lr : Flag<["-"], "mbranch-protection-pauth-lr">,
   MarshallingInfoFlag>;
+def mguarded_control_stack : Flag<["-"], "mguarded-control-stack">,
+  MarshallingInfoFlag>;
 def fno_dllexport_inlines : Flag<["-"], "fno-dllexport-inlines">,
   MarshallingInfoNegativeFlag>;
 def cfguard_no_checks : Flag<["-"], "cfguard-no-checks">,
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 2f8395cb8932f2..9ebaf4d40cd7e5 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -226,6 +226,7 @@ bool AArch64TargetInfo::validateBranchProtection(StringRef 
Spec, StringRef,
 
   BPI.BranchTargetEnforcement = PBP.BranchTargetEnforcement;
   BPI.BranchProtectionPAuthLR = PBP.BranchProtectionPAuthLR;
+  BPI.GuardedControlStack = PBP.GuardedControlStack;
   return true;
 }
 
@@ -532,6 +533,9 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (Opts.BranchTargetEnforcement)
 Builder.defineMacro("__ARM_FEATURE_BTI_DEFAULT", "1");
 
+  if (Opts.GuardedControlStack)
+Builder.defineMacro("__ARM_FEATURE_GCS_DEFAULT", "1");
+
   if (HasLS64)
 Builder.defineMacro("__ARM_FEATURE_LS64", "1");
 
@@ -544,6 +548,9 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasD128)
 Builder.defineMacro("__ARM_FEATURE_SYSREG128", "1");
 
+  if (HasGCS)
+Builder.defineMacro("__ARM_FEATURE_GCS", "1");
+
   if (*ArchInfo == llvm::AArch64::ARMV8_1A)
 getTargetDefinesARMV81

[llvm] [clang] [clang][AArch64] Add a -mbranch-protection option to enable GCS (PR #75486)

2024-01-10 Thread John Brawn via cfe-commits

john-brawn-arm wrote:

Ping.

https://github.com/llvm/llvm-project/pull/75486
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [clang][AArch64] Add a -mbranch-protection option to enable GCS (PR #75486)

2024-01-11 Thread John Brawn via cfe-commits

https://github.com/john-brawn-arm closed 
https://github.com/llvm/llvm-project/pull/75486
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1b1466c - [AArch64] Adjust aarch64 constrained intrinsics tests and un-XFAIL

2022-04-14 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2022-04-14T16:51:22+01:00
New Revision: 1b1466c346694c02ff0e30c96a50701b58bc4830

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

LOG: [AArch64] Adjust aarch64 constrained intrinsics tests and un-XFAIL

Remove the checking of the generated asm, as that's already tested
elsewhere, and adjust some tests that were expecting the wrong
intrinsic to be generated.

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

Added: 


Modified: 
clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c 
b/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
index fccafefd9d30c..e8c6b32128ffa 100644
--- a/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
+++ b/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
@@ -1,27 +1,15 @@
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
 // RUN:  -flax-vector-conversions=none -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=UNCONSTRAINED %s
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
-// RUN:  -ffp-exception-behavior=strict \
+// RUN:  -ffp-exception-behavior=strict -fexperimental-strict-floating-point \
 // RUN:  -flax-vector-conversions=none -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=CONSTRAINED %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
-// RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
-// RUN:  -flax-vector-conversions=none -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
-// RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
-// RUN:  -ffp-exception-behavior=strict \
-// RUN:  -flax-vector-conversions=none -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,CONSTRAINED %s
 
 // REQUIRES: aarch64-registered-target
 
-// Fails during instruction selection:
-// XFAIL: *
-
 // Test new aarch64 intrinsics and types but constrained
 
 #include 
@@ -29,7 +17,6 @@
 // COMMON-LABEL: test_vadd_f32
 // UNCONSTRAINED: [[ADD_I:%.*]] = fadd <2 x float> %v1, %v2
 // CONSTRAINED:   [[ADD_I:%.*]] = call <2 x float> 
@llvm.experimental.constrained.fadd.v2f32(<2 x float> %v1, <2 x float> %v2, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK-ASM: fadd v{{[0-9]+}}.2s, v{{[0-9]+}}.2s, v{{[0-9]+}}.2s
 // COMMONIR:  ret <2 x float> [[ADD_I]]
 float32x2_t test_vadd_f32(float32x2_t v1, float32x2_t v2) {
   return vadd_f32(v1, v2);
@@ -38,7 +25,6 @@ float32x2_t test_vadd_f32(float32x2_t v1, float32x2_t v2) {
 // COMMON-LABEL: test_vaddq_f32
 // UNCONSTRAINED: [[ADD_I:%.*]] = fadd <4 x float> %v1, %v2
 // CONSTRAINED:   [[ADD_I:%.*]] = call <4 x float> 
@llvm.experimental.constrained.fadd.v4f32(<4 x float> %v1, <4 x float> %v2, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK-ASM: fadd v{{[0-9]+}}.4s, v{{[0-9]+}}.4s, v{{[0-9]+}}.4s
 // COMMONIR:  ret <4 x float> [[ADD_I]]
 float32x4_t test_vaddq_f32(float32x4_t v1, float32x4_t v2) {
   return vaddq_f32(v1, v2);
@@ -47,7 +33,6 @@ float32x4_t test_vaddq_f32(float32x4_t v1, float32x4_t v2) {
 // COMMON-LABEL: test_vsub_f32
 // UNCONSTRAINED: [[SUB_I:%.*]] = fsub <2 x float> %v1, %v2
 // CONSTRAINED:   [[SUB_I:%.*]] = call <2 x float> 
@llvm.experimental.constrained.fsub.v2f32(<2 x float> %v1, <2 x float> %v2, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK-ASM: fsub v{{[0-9]+}}.2s, v{{[0-9]+}}.2s, v{{[0-9]+}}.2s
 // COMMONIR:  ret <2 x float> [[SUB_I]]
 float32x2_t test_vsub_f32(float32x2_t v1, float32x2_t v2) {
   return vsub_f32(v1, v2);
@@ -56,7 +41,6 @@ float32x2_t test_vsub_f32(float32x2_t v1, float32x2_t v2) {
 // COMMON-LABEL: test_vsubq_f32
 // UNCONSTRAINED: [[SUB_I:%.*]] = fsub <4 x float> %v1, %v2
 // CONSTRAINED:   [[SUB_I:%.*]] = call <4 x float> 
@llvm.experimental.constrained.fsub.v4f32(<4 x float> %v1, <4 x float> %v2, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK-ASM: fsub v{{[0-9]+}}.4s, v{{[0-9]+}}.4s, v{{[0-9]+}}.4s
 // COMMONIR:  ret <4 x float> [[SUB_I]]
 float32x4_t test_vsubq_f32(float32x4_t v1, float32x4_t v2) {
   return vsu

[clang] bca998e - [AArch64] Generate fcmps when appropriate for neon intrinsics

2022-02-04 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2022-02-04T12:55:38Z
New Revision: bca998ed3c9a2e520724baa5d9395f6a5d8ca49d

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

LOG: [AArch64] Generate fcmps when appropriate for neon intrinsics

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d071c7a5b4a47..a3905e0ea4105 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7294,7 +7294,10 @@ Value *CodeGenFunction::EmitAArch64CompareBuiltinExpr(
 
   Op = Builder.CreateBitCast(Op, OTy);
   if (OTy->getScalarType()->isFloatingPointTy()) {
-Op = Builder.CreateFCmp(Fp, Op, Constant::getNullValue(OTy));
+if (Fp == CmpInst::FCMP_OEQ)
+  Op = Builder.CreateFCmp(Fp, Op, Constant::getNullValue(OTy));
+else
+  Op = Builder.CreateFCmpS(Fp, Op, Constant::getNullValue(OTy));
   } else {
 Op = Builder.CreateICmp(Ip, Op, Constant::getNullValue(OTy));
   }
@@ -10299,7 +10302,10 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 Ops.push_back(EmitScalarExpr(E->getArg(1)));
 Ops[0] = Builder.CreateBitCast(Ops[0], DoubleTy);
 Ops[1] = Builder.CreateBitCast(Ops[1], DoubleTy);
-Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]);
+if (P == llvm::FCmpInst::FCMP_OEQ)
+  Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]);
+else
+  Ops[0] = Builder.CreateFCmpS(P, Ops[0], Ops[1]);
 return Builder.CreateSExt(Ops[0], Int64Ty, "vcmpd");
   }
   case NEON::BI__builtin_neon_vceqs_f32:
@@ -10319,7 +10325,10 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 Ops.push_back(EmitScalarExpr(E->getArg(1)));
 Ops[0] = Builder.CreateBitCast(Ops[0], FloatTy);
 Ops[1] = Builder.CreateBitCast(Ops[1], FloatTy);
-Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]);
+if (P == llvm::FCmpInst::FCMP_OEQ)
+  Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]);
+else
+  Ops[0] = Builder.CreateFCmpS(P, Ops[0], Ops[1]);
 return Builder.CreateSExt(Ops[0], Int32Ty, "vcmpd");
   }
   case NEON::BI__builtin_neon_vceqh_f16:
@@ -10339,7 +10348,10 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 Ops.push_back(EmitScalarExpr(E->getArg(1)));
 Ops[0] = Builder.CreateBitCast(Ops[0], HalfTy);
 Ops[1] = Builder.CreateBitCast(Ops[1], HalfTy);
-Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]);
+if (P == llvm::FCmpInst::FCMP_OEQ)
+  Ops[0] = Builder.CreateFCmp(P, Ops[0], Ops[1]);
+else
+  Ops[0] = Builder.CreateFCmpS(P, Ops[0], Ops[1]);
 return Builder.CreateSExt(Ops[0], Int16Ty, "vcmpd");
   }
   case NEON::BI__builtin_neon_vceqd_s64:

diff  --git a/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c 
b/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
index 25e205193ca79..fccafefd9d30c 100644
--- a/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
+++ b/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
@@ -585,7 +585,7 @@ uint64_t test_vceqzd_f64(float64_t a) {
 
 // COMMON-LABEL: test_vcges_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge float %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 
@llvm.experimental.constrained.fcmp.f32(float %a, float %b, metadata !"oge", 
metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 
@llvm.experimental.constrained.fcmps.f32(float %a, float %b, metadata !"oge", 
metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp s{{[0-9]+}}, s{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i32
@@ -596,7 +596,7 @@ uint32_t test_vcges_f32(float32_t a, float32_t b) {
 
 // COMMON-LABEL: test_vcged_f64
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge double %a, %b
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 
@llvm.experimental.constrained.fcmp.f64(double %a, double %b, metadata !"oge", 
metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 
@llvm.experimental.constrained.fcmps.f64(double %a, double %b, metadata !"oge", 
metadata !"fpexcept.strict")
 // CHECK-ASM: fcmp d{{[0-9]+}}, d{{[0-9]+}}
 // CHECK-ASM-NEXT:cset {{w[0-9]+}}, ge
 // COMMONIR:  [[VCMPD_I:%.*]] = sext i1 [[TMP0]] to i64
@@ -607,7 +607,7 @@ uint64_t test_vcged_f64(float64_t a, float64_t b) {
 
 // COMMON-LABEL: test_vcgezs_f32
 // UNCONSTRAINED: [[TMP0:%.*]] = fcmp oge float %a, 0.00e+00
-// CONSTRAINED:   [[TMP0:%.*]] = call i1 
@llvm.experimental.constrained.fcmp.f32(float %a, float 0.00e+00, metadata 
!"oge", metadata !"fpexcept.strict")
+// CONSTRAINED:   [[TMP0:%.*]] = call i1 
@llvm.experimental.constrained.fcmps.f32(float %a

[clang] [llvm] [DebugInfo] Use DW_op_bit_piece for structured bindings of bitfields (PR #85665)

2024-03-18 Thread John Brawn via cfe-commits

https://github.com/john-brawn-arm created 
https://github.com/llvm/llvm-project/pull/85665

Currently we use DW_OP_plus_uconst to handle the bitfield offset and handle the 
bitfield size by choosing a type size that matches, but this doesn't work if 
either offset or size aren't byte-aligned. Using DW_op_bit_piece means we can 
handle any offset and size.

>From 665d4034a1428d9b5cf1c4d4e89a16fa00b94fb5 Mon Sep 17 00:00:00 2001
From: John Brawn 
Date: Thu, 14 Mar 2024 16:17:03 +
Subject: [PATCH] [DebugInfo] Use DW_op_bit_piece for structured bindings of
 bitfields

Currently we use DW_OP_plus_uconst to handle the bitfield offset and
handle the bitfield size by choosing a type size that matches, but
this doesn't work if either offset or size aren't byte-aligned. Using
DW_op_bit_piece means we can handle any offset and size.
---
 clang/lib/CodeGen/CGDebugInfo.cpp |  52 ++--
 clang/lib/CodeGen/CGDebugInfo.h   |   3 -
 ...debug-info-structured-binding-bitfield.cpp | 118 +-
 .../CodeGen/AsmPrinter/DwarfExpression.cpp|   3 +
 llvm/lib/IR/DebugInfoMetadata.cpp |   2 +
 5 files changed, 70 insertions(+), 108 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index c2c01439f2dc99..bf142bdbbe0f99 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4777,40 +4777,6 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const 
VarDecl *VD,
   return D;
 }
 
-llvm::DIType *CGDebugInfo::CreateBindingDeclType(const BindingDecl *BD) {
-  llvm::DIFile *Unit = getOrCreateFile(BD->getLocation());
-
-  // If the declaration is bound to a bitfield struct field, its type may have 
a
-  // size that is different from its deduced declaration type's.
-  if (const MemberExpr *ME = dyn_cast(BD->getBinding())) {
-if (const FieldDecl *FD = dyn_cast(ME->getMemberDecl())) {
-  if (FD->isBitField()) {
-ASTContext &Context = CGM.getContext();
-const CGRecordLayout &RL =
-CGM.getTypes().getCGRecordLayout(FD->getParent());
-const CGBitFieldInfo &Info = RL.getBitFieldInfo(FD);
-
-// Find an integer type with the same bitwidth as the bitfield size. If
-// no suitable type is present in the target, give up on producing 
debug
-// information as it would be wrong. It is certainly possible to 
produce
-// correct debug info, but the logic isn't currently implemented.
-uint64_t BitfieldSizeInBits = Info.Size;
-QualType IntTy =
-Context.getIntTypeForBitwidth(BitfieldSizeInBits, Info.IsSigned);
-if (IntTy.isNull())
-  return nullptr;
-Qualifiers Quals = BD->getType().getQualifiers();
-QualType FinalTy = Context.getQualifiedType(IntTy, Quals);
-llvm::DIType *Ty = getOrCreateType(FinalTy, Unit);
-assert(Ty);
-return Ty;
-  }
-}
-  }
-
-  return getOrCreateType(BD->getType(), Unit);
-}
-
 llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
 llvm::Value *Storage,
 std::optional ArgNo,
@@ -4825,7 +4791,8 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const 
BindingDecl *BD,
   if (isa(BD->getBinding()))
 return nullptr;
 
-  llvm::DIType *Ty = CreateBindingDeclType(BD);
+  llvm::DIFile *Unit = getOrCreateFile(BD->getLocation());
+  llvm::DIType *Ty = getOrCreateType(BD->getType(), Unit);
 
   // If there is no debug info for this type then do not emit debug info
   // for this variable.
@@ -4851,7 +4818,6 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const 
BindingDecl *BD,
   unsigned Column = getColumnNumber(BD->getLocation());
   StringRef Name = BD->getName();
   auto *Scope = cast(LexicalBlockStack.back());
-  llvm::DIFile *Unit = getOrCreateFile(BD->getLocation());
   // Create the descriptor for the variable.
   llvm::DILocalVariable *D = DBuilder.createAutoVariable(
   Scope, Name, Unit, Line, Ty, CGM.getLangOpts().Optimize,
@@ -4865,13 +4831,13 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const 
BindingDecl *BD,
   const ASTRecordLayout &layout =
   CGM.getContext().getASTRecordLayout(parent);
   const uint64_t fieldOffset = layout.getFieldOffset(fieldIndex);
-
-  if (fieldOffset != 0) {
-// Currently if the field offset is not a multiple of byte, the 
produced
-// location would not be accurate. Therefore give up.
-if (fieldOffset % CGM.getContext().getCharWidth() != 0)
-  return nullptr;
-
+  if (FD->isBitField()) {
+Expr.push_back(llvm::dwarf::DW_OP_bit_piece);
+Expr.push_back(FD->getBitWidthValue(CGM.getContext()));
+Expr.push_back(fieldOffset);
+  } else if (fieldOffset != 0) {
+assert(fieldOffset % CGM.getContext().getCharWidth() == 0 &&
+   "Unexpected non-bitfield with non-byte-aligned offset

[clang] [llvm] [DebugInfo] Use DW_op_bit_piece for structured bindings of bitfields (PR #85665)

2024-03-19 Thread John Brawn via cfe-commits


@@ -8,8 +8,8 @@ struct S0 {
 // CHECK-LABEL: define dso_local void @_Z3fS0v
 // CHECK:alloca %struct.S0, align 4
 // CHECK-NEXT:[[TMP0:%.*]] = alloca %struct.S0, align 4
-// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata 
[[S0_A:![0-9]+]], metadata !DIExpression())
-// CHECK-NEXT:call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata 
[[S0_B:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 2))
+// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata 
[[S0_A:![0-9]+]], metadata !DIExpression(DW_OP_bit_piece, 16, 0))

john-brawn-arm wrote:

The LLVM langref says "Note that contrary to DW_OP_bit_piece, the offset is 
describing the location within the described source variable". What I think 
this means is that while DW_OP_bit_piece means "you get the source variable by 
extracting these bits of this location", DW_OP_LLVM_fragment means "the value 
of this location is these bits of the source variable".

Trying out DW_OP_LLVM_fragment in
```
struct {
  unsigned int a : 8;
  unsigned int b : 8;
} X = { 1, 2 };

int main() {
  auto [a, b] = X;
  return a + b;
}
```
the resulting dwarf info looks pretty strange
```
 <2><7f>: Abbrev Number: 7 (DW_TAG_variable)
<80>   DW_AT_location: 4 byte block: 93 1 91 78 (DW_OP_piece: 
1; DW_OP_fbreg: -8)
<85>   DW_AT_name: (indirect string, offset: 0x9c): a
<89>   DW_AT_decl_file   : 1
<8a>   DW_AT_decl_line   : 7
<8b>   DW_AT_type: <0x5f>
 <2><8f>: Abbrev Number: 7 (DW_TAG_variable)
<90>   DW_AT_location: 6 byte block: 93 1 91 78 93 1(DW_OP_piece: 
1; DW_OP_fbreg: -8; DW_OP_piece: 1)
<97>   DW_AT_name: (indirect string, offset: 0xab): b
<9b>   DW_AT_decl_file   : 1
<9c>   DW_AT_decl_line   : 7
<9d>   DW_AT_type: <0x5f>
```
lldb says (at line 8)
```
(lldb) p a
(unsigned int) 513
(lldb) p b
(unsigned int) 256
```
gdb appears to not like this dwarf info and just says
```
(gdb) p a
$1 = 
(gdb) p b
$2 = 
```

https://github.com/llvm/llvm-project/pull/85665
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0c66606 - [Driver] Incorporate -mfloat-abi in the computed triple on ARM

2020-10-21 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2020-10-21T11:19:38+01:00
New Revision: 0c66606230df39e0bf4190f1fc2c2e2fb37a81ea

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

LOG: [Driver] Incorporate -mfloat-abi in the computed triple on ARM

LLVM assumes that when it creates a call to a C library function it
can use the C calling convention. On ARM the effective calling
convention is determined from the target triple, however using
-mfloat-abi=hard on ARM means that calls to (and definitions of) C
library functions use the arm_aapcs_vfpcc calling convention which can
result in a mismatch.

Fix this by incorporating -mfloat-abi into the target triple, similar
to how -mbig-endian and -march/-mcpu are. This only works for EABI
targets and not Android or iOS, but there the float abi is fixed so
instead give an error.

Fixes PR45524

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

Added: 
clang/test/Driver/arm-float-abi-lto.c
clang/test/Driver/arm-triple.c

Modified: 
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/Arch/ARM.cpp
clang/lib/Driver/ToolChains/Arch/ARM.h
clang/test/Driver/arm-float-abi.c
clang/test/Driver/windows-thumbv7em.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 8991216da676..9fa53ce2dbeb 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -787,6 +787,37 @@ std::string ToolChain::ComputeLLVMTriple(const ArgList 
&Args,
 }
 Triple.setArchName(ArchName + Suffix.str());
 
+bool isHardFloat =
+(arm::getARMFloatABI(getDriver(), Triple, Args) == 
arm::FloatABI::Hard);
+switch (Triple.getEnvironment()) {
+case Triple::GNUEABI:
+case Triple::GNUEABIHF:
+  Triple.setEnvironment(isHardFloat ? Triple::GNUEABIHF : Triple::GNUEABI);
+  break;
+case Triple::EABI:
+case Triple::EABIHF:
+  Triple.setEnvironment(isHardFloat ? Triple::EABIHF : Triple::EABI);
+  break;
+case Triple::MuslEABI:
+case Triple::MuslEABIHF:
+  Triple.setEnvironment(isHardFloat ? Triple::MuslEABIHF
+: Triple::MuslEABI);
+  break;
+default: {
+  arm::FloatABI DefaultABI = arm::getDefaultFloatABI(Triple);
+  if (DefaultABI != arm::FloatABI::Invalid &&
+  isHardFloat != (DefaultABI == arm::FloatABI::Hard)) {
+Arg *ABIArg =
+Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
+options::OPT_mfloat_abi_EQ);
+assert(ABIArg && "Non-default float abi expected to be from arg");
+D.Diag(diag::err_drv_unsupported_opt_for_target)
+<< ABIArg->getAsString(Args) << Triple.getTriple();
+  }
+  break;
+}
+}
+
 return Triple.getTriple();
   }
   }

diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index d74d5db0c083..309a7298300f 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -134,6 +134,7 @@ bool arm::useAAPCSForMachO(const llvm::Triple &T) {
   // The backend is hardwired to assume AAPCS for M-class processors, ensure
   // the frontend matches that.
   return T.getEnvironment() == llvm::Triple::EABI ||
+ T.getEnvironment() == llvm::Triple::EABIHF ||
  T.getOS() == llvm::Triple::UnknownOS || isARMMProfile(T);
 }
 
@@ -160,11 +161,73 @@ arm::FloatABI arm::getARMFloatABI(const ToolChain &TC, 
const ArgList &Args) {
   return arm::getARMFloatABI(TC.getDriver(), TC.getEffectiveTriple(), Args);
 }
 
+arm::FloatABI arm::getDefaultFloatABI(const llvm::Triple &Triple) {
+  auto SubArch = getARMSubArchVersionNumber(Triple);
+  switch (Triple.getOS()) {
+  case llvm::Triple::Darwin:
+  case llvm::Triple::MacOSX:
+  case llvm::Triple::IOS:
+  case llvm::Triple::TvOS:
+// Darwin defaults to "softfp" for v6 and v7.
+if (Triple.isWatchABI())
+  return FloatABI::Hard;
+else
+  return (SubArch == 6 || SubArch == 7) ? FloatABI::SoftFP : 
FloatABI::Soft;
+
+  case llvm::Triple::WatchOS:
+return FloatABI::Hard;
+
+  // FIXME: this is invalid for WindowsCE
+  case llvm::Triple::Win32:
+return FloatABI::Hard;
+
+  case llvm::Triple::NetBSD:
+switch (Triple.getEnvironment()) {
+case llvm::Triple::EABIHF:
+case llvm::Triple::GNUEABIHF:
+  return FloatABI::Hard;
+default:
+  return FloatABI::Soft;
+}
+break;
+
+  case llvm::Triple::FreeBSD:
+switch (Triple.getEnvironment()) {
+case llvm::Triple::GNUEABIHF:
+  return FloatABI::Hard;
+default:
+  // FreeBSD defaults to soft float
+  return FloatABI::Soft;
+}
+break;
+
+  case llvm::Triple::OpenBSD:
+return FloatABI::SoftFP;
+
+  default:

[clang] ba60de5 - Use -### in arm-float-abi.c test

2020-10-21 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2020-10-21T17:40:02+01:00
New Revision: ba60de5250ce1c4baa4a7bb7098ac67349f88a99

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

LOG: Use -### in arm-float-abi.c test

This is needed to prevent the test from failing when llvm is
configured so that the arm target is not present, which is the case
for some buildbots.

Added: 


Modified: 
clang/test/Driver/arm-float-abi.c

Removed: 




diff  --git a/clang/test/Driver/arm-float-abi.c 
b/clang/test/Driver/arm-float-abi.c
index 294f02444769..806ef0fbd93e 100644
--- a/clang/test/Driver/arm-float-abi.c
+++ b/clang/test/Driver/arm-float-abi.c
@@ -20,9 +20,9 @@
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-ERROR %s
 // CHECK-ANDROID-ERROR: unsupported option '-mfloat-abi=hard' for target 
'armv7-unknown-linux-android21'
 
-// RUN: %clang -target armv7-linux-androideabi21 %s -S -o - -mfloat-abi=soft 
2>&1 \
+// RUN: %clang -target armv7-linux-androideabi21 %s -S -o - -mfloat-abi=soft 
-### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-NOERROR %s
-// RUN: %clang -target armv7-linux-androideabi21 %s -S -o - -mfloat-abi=softfp 
2>&1 \
+// RUN: %clang -target armv7-linux-androideabi21 %s -S -o - -mfloat-abi=softfp 
-### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-NOERROR %s
 // CHECK-ANDROID-NOERROR-NOT: unsupported option
 
@@ -34,6 +34,6 @@
 // RUN:   | FileCheck --check-prefix=CHECK-WATCHOS-ERROR2 %s
 // CHECK-WATCHOS-ERROR2: unsupported option '-mfloat-abi=softfp' for target 
'thumbv7-apple-watchos4'
 
-// RUN: %clang -target armv7-apple-watchos4 %s -S -o - -mfloat-abi=hard 2>&1 \
+// RUN: %clang -target armv7-apple-watchos4 %s -S -o - -mfloat-abi=hard -### 
2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-WATCHOS-NOERROR %s
 // CHECK-WATCHOS-NOERROR-NOT: unsupported option



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


[clang] dfca883 - [Sema] Fix handling of functions that hide classes

2023-07-24 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-07-24T13:11:30+01:00
New Revision: dfca88341794eec88c5009a93c569172fff62635

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

LOG: [Sema] Fix handling of functions that hide classes

When a function is declared in the same scope as a class with the same
name then the function hides that class. Currently this is done by a
single check after the main loop in LookupResult::resolveKind, but
this can give the wrong result when we have a using declaration in
multiple namespace scopes in two different ways:

 * When the using declaration is hidden in one namespace but not the
   other we can end up considering only the hidden one when deciding
   if the result is ambiguous, causing an incorrect "not ambiguous"
   result.

 * When two classes with the same name in different namespace scopes
   are both hidden by using declarations this can result in
   incorrectly deciding the result is ambiguous. There's currently a
   comment saying this is expected, but I don't think that's correct.

Solve this by checking each Decl to see if it's hidden by some other
Decl in the same scope. This means we have to delay removing anything
from Decls until after the main loop, in case a Decl is hidden by
another that is removed due to being non-unique.

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

Added: 
clang/test/SemaCXX/using-hiding.cpp

Modified: 
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index d1ff688c2a21d0..03f917d95275b6 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -513,21 +513,42 @@ void LookupResult::resolveKind() {
   const NamedDecl *HasNonFunction = nullptr;
 
   llvm::SmallVector EquivalentNonFunctions;
+  llvm::BitVector RemovedDecls(N);
 
-  unsigned UniqueTagIndex = 0;
-
-  unsigned I = 0;
-  while (I < N) {
+  for (unsigned I = 0; I < N; I++) {
 const NamedDecl *D = Decls[I]->getUnderlyingDecl();
 D = cast(D->getCanonicalDecl());
 
 // Ignore an invalid declaration unless it's the only one left.
 // Also ignore HLSLBufferDecl which not have name conflict with other 
Decls.
-if ((D->isInvalidDecl() || isa(D)) && !(I == 0 && N == 1)) 
{
-  Decls[I] = Decls[--N];
+if ((D->isInvalidDecl() || isa(D)) &&
+N - RemovedDecls.count() > 1) {
+  RemovedDecls.set(I);
   continue;
 }
 
+// C++ [basic.scope.hiding]p2:
+//   A class name or enumeration name can be hidden by the name of
+//   an object, function, or enumerator declared in the same
+//   scope. If a class or enumeration name and an object, function,
+//   or enumerator are declared in the same scope (in any order)
+//   with the same name, the class or enumeration name is hidden
+//   wherever the object, function, or enumerator name is visible.
+if (HideTags && isa(D)) {
+  bool Hidden = false;
+  for (auto *OtherDecl : Decls) {
+if (canHideTag(OtherDecl) &&
+getContextForScopeMatching(OtherDecl)->Equals(
+getContextForScopeMatching(Decls[I]))) {
+  RemovedDecls.set(I);
+  Hidden = true;
+  break;
+}
+  }
+  if (Hidden)
+continue;
+}
+
 std::optional ExistingI;
 
 // Redeclarations of types via typedef can occur both within a scope
@@ -559,8 +580,9 @@ void LookupResult::resolveKind() {
   // discard the other.
   if (isPreferredLookupResult(getSema(), getLookupKind(), Decls[I],
   Decls[*ExistingI]))
-Decls[*ExistingI] = Decls[I];
-  Decls[I] = Decls[--N];
+RemovedDecls.set(*ExistingI);
+  else
+RemovedDecls.set(I);
   continue;
 }
 
@@ -571,7 +593,6 @@ void LookupResult::resolveKind() {
 } else if (isa(D)) {
   if (HasTag)
 Ambiguous = true;
-  UniqueTagIndex = I;
   HasTag = true;
 } else if (isa(D)) {
   HasFunction = true;
@@ -587,7 +608,7 @@ void LookupResult::resolveKind() {
 if (getSema().isEquivalentInternalLinkageDeclaration(HasNonFunction,
  D)) {
   EquivalentNonFunctions.push_back(D);
-  Decls[I] = Decls[--N];
+  RemovedDecls.set(I);
   continue;
 }
 
@@ -595,28 +616,6 @@ void LookupResult::resolveKind() {
   }
   HasNonFunction = D;
 }
-I++;
-  }
-
-  // C++ [basic.scope.hiding]p2:
-  //   A class name or enumeration name can be hidden by the name of
-  //   an object, function, or enumerator declared in the same
-  //   scope. If a class or enumeration name and an object, function,
-  //   or enumerator are declared in the same scope (in any order)
-  /

[clang] dc3cd59 - Revert "[Sema] Fix handling of functions that hide classes"

2023-07-24 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-07-24T13:30:26+01:00
New Revision: dc3cd5926423c56d4673308617f035713aa024d6

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

LOG: Revert "[Sema] Fix handling of functions that hide classes"

This reverts commit dfca88341794eec88c5009a93c569172fff62635.

Causes clang/test/Modules/stress1.cpp to fail.

Added: 


Modified: 
clang/lib/Sema/SemaLookup.cpp

Removed: 
clang/test/SemaCXX/using-hiding.cpp



diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 03f917d95275b6..d1ff688c2a21d0 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -513,42 +513,21 @@ void LookupResult::resolveKind() {
   const NamedDecl *HasNonFunction = nullptr;
 
   llvm::SmallVector EquivalentNonFunctions;
-  llvm::BitVector RemovedDecls(N);
 
-  for (unsigned I = 0; I < N; I++) {
+  unsigned UniqueTagIndex = 0;
+
+  unsigned I = 0;
+  while (I < N) {
 const NamedDecl *D = Decls[I]->getUnderlyingDecl();
 D = cast(D->getCanonicalDecl());
 
 // Ignore an invalid declaration unless it's the only one left.
 // Also ignore HLSLBufferDecl which not have name conflict with other 
Decls.
-if ((D->isInvalidDecl() || isa(D)) &&
-N - RemovedDecls.count() > 1) {
-  RemovedDecls.set(I);
+if ((D->isInvalidDecl() || isa(D)) && !(I == 0 && N == 1)) 
{
+  Decls[I] = Decls[--N];
   continue;
 }
 
-// C++ [basic.scope.hiding]p2:
-//   A class name or enumeration name can be hidden by the name of
-//   an object, function, or enumerator declared in the same
-//   scope. If a class or enumeration name and an object, function,
-//   or enumerator are declared in the same scope (in any order)
-//   with the same name, the class or enumeration name is hidden
-//   wherever the object, function, or enumerator name is visible.
-if (HideTags && isa(D)) {
-  bool Hidden = false;
-  for (auto *OtherDecl : Decls) {
-if (canHideTag(OtherDecl) &&
-getContextForScopeMatching(OtherDecl)->Equals(
-getContextForScopeMatching(Decls[I]))) {
-  RemovedDecls.set(I);
-  Hidden = true;
-  break;
-}
-  }
-  if (Hidden)
-continue;
-}
-
 std::optional ExistingI;
 
 // Redeclarations of types via typedef can occur both within a scope
@@ -580,9 +559,8 @@ void LookupResult::resolveKind() {
   // discard the other.
   if (isPreferredLookupResult(getSema(), getLookupKind(), Decls[I],
   Decls[*ExistingI]))
-RemovedDecls.set(*ExistingI);
-  else
-RemovedDecls.set(I);
+Decls[*ExistingI] = Decls[I];
+  Decls[I] = Decls[--N];
   continue;
 }
 
@@ -593,6 +571,7 @@ void LookupResult::resolveKind() {
 } else if (isa(D)) {
   if (HasTag)
 Ambiguous = true;
+  UniqueTagIndex = I;
   HasTag = true;
 } else if (isa(D)) {
   HasFunction = true;
@@ -608,7 +587,7 @@ void LookupResult::resolveKind() {
 if (getSema().isEquivalentInternalLinkageDeclaration(HasNonFunction,
  D)) {
   EquivalentNonFunctions.push_back(D);
-  RemovedDecls.set(I);
+  Decls[I] = Decls[--N];
   continue;
 }
 
@@ -616,6 +595,28 @@ void LookupResult::resolveKind() {
   }
   HasNonFunction = D;
 }
+I++;
+  }
+
+  // C++ [basic.scope.hiding]p2:
+  //   A class name or enumeration name can be hidden by the name of
+  //   an object, function, or enumerator declared in the same
+  //   scope. If a class or enumeration name and an object, function,
+  //   or enumerator are declared in the same scope (in any order)
+  //   with the same name, the class or enumeration name is hidden
+  //   wherever the object, function, or enumerator name is visible.
+  // But it's still an error if there are distinct tag types found,
+  // even if they're not visible. (ref?)
+  if (N > 1 && HideTags && HasTag && !Ambiguous &&
+  (HasFunction || HasNonFunction || HasUnresolved)) {
+const NamedDecl *OtherDecl = Decls[UniqueTagIndex ? 0 : N - 1];
+if (isa(Decls[UniqueTagIndex]->getUnderlyingDecl()) &&
+getContextForScopeMatching(Decls[UniqueTagIndex])->Equals(
+getContextForScopeMatching(OtherDecl)) &&
+canHideTag(OtherDecl))
+  Decls[UniqueTagIndex] = Decls[--N];
+else
+  Ambiguous = true;
   }
 
   // FIXME: This diagnostic should really be delayed until we're done with
@@ -624,15 +625,9 @@ void LookupResult::resolveKind() {
 getSema().diagnoseEquivalentInternalLinkageDeclarations(
 getNameLoc(), HasNonFunction, EquivalentNonFunctions);
 
-  // Remove decls

[clang] d031ff3 - [Sema] Fix handling of functions that hide classes

2023-07-25 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-07-25T12:30:41+01:00
New Revision: d031ff38779bd688c514136dbdcce3169ee82b6e

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

LOG: [Sema] Fix handling of functions that hide classes

When a function is declared in the same scope as a class with the same
name then the function hides that class. Currently this is done by a
single check after the main loop in LookupResult::resolveKind, but
this can give the wrong result when we have a using declaration in
multiple namespace scopes in two different ways:

 * When the using declaration is hidden in one namespace but not the
   other we can end up considering only the hidden one when deciding
   if the result is ambiguous, causing an incorrect "not ambiguous"
   result.

 * When two classes with the same name in different namespace scopes
   are both hidden by using declarations this can result in
   incorrectly deciding the result is ambiguous. There's currently a
   comment saying this is expected, but I don't think that's correct.

Solve this by checking each Decl to see if it's hidden by some other
Decl in the same scope. This means we have to delay removing anything
from Decls until after the main loop, in case a Decl is hidden by
another that is removed due to being non-unique.

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

Added: 
clang/test/SemaCXX/using-hiding.cpp

Modified: 
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index d1ff688c2a21d0..c4f4edbcc1 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -513,21 +513,42 @@ void LookupResult::resolveKind() {
   const NamedDecl *HasNonFunction = nullptr;
 
   llvm::SmallVector EquivalentNonFunctions;
+  llvm::BitVector RemovedDecls(N);
 
-  unsigned UniqueTagIndex = 0;
-
-  unsigned I = 0;
-  while (I < N) {
+  for (unsigned I = 0; I < N; I++) {
 const NamedDecl *D = Decls[I]->getUnderlyingDecl();
 D = cast(D->getCanonicalDecl());
 
 // Ignore an invalid declaration unless it's the only one left.
 // Also ignore HLSLBufferDecl which not have name conflict with other 
Decls.
-if ((D->isInvalidDecl() || isa(D)) && !(I == 0 && N == 1)) 
{
-  Decls[I] = Decls[--N];
+if ((D->isInvalidDecl() || isa(D)) &&
+N - RemovedDecls.count() > 1) {
+  RemovedDecls.set(I);
   continue;
 }
 
+// C++ [basic.scope.hiding]p2:
+//   A class name or enumeration name can be hidden by the name of
+//   an object, function, or enumerator declared in the same
+//   scope. If a class or enumeration name and an object, function,
+//   or enumerator are declared in the same scope (in any order)
+//   with the same name, the class or enumeration name is hidden
+//   wherever the object, function, or enumerator name is visible.
+if (HideTags && isa(D)) {
+  bool Hidden = false;
+  for (auto *OtherDecl : Decls) {
+if (canHideTag(OtherDecl) &&
+getContextForScopeMatching(OtherDecl)->Equals(
+getContextForScopeMatching(Decls[I]))) {
+  RemovedDecls.set(I);
+  Hidden = true;
+  break;
+}
+  }
+  if (Hidden)
+continue;
+}
+
 std::optional ExistingI;
 
 // Redeclarations of types via typedef can occur both within a scope
@@ -560,7 +581,7 @@ void LookupResult::resolveKind() {
   if (isPreferredLookupResult(getSema(), getLookupKind(), Decls[I],
   Decls[*ExistingI]))
 Decls[*ExistingI] = Decls[I];
-  Decls[I] = Decls[--N];
+  RemovedDecls.set(I);
   continue;
 }
 
@@ -571,7 +592,6 @@ void LookupResult::resolveKind() {
 } else if (isa(D)) {
   if (HasTag)
 Ambiguous = true;
-  UniqueTagIndex = I;
   HasTag = true;
 } else if (isa(D)) {
   HasFunction = true;
@@ -587,7 +607,7 @@ void LookupResult::resolveKind() {
 if (getSema().isEquivalentInternalLinkageDeclaration(HasNonFunction,
  D)) {
   EquivalentNonFunctions.push_back(D);
-  Decls[I] = Decls[--N];
+  RemovedDecls.set(I);
   continue;
 }
 
@@ -595,28 +615,6 @@ void LookupResult::resolveKind() {
   }
   HasNonFunction = D;
 }
-I++;
-  }
-
-  // C++ [basic.scope.hiding]p2:
-  //   A class name or enumeration name can be hidden by the name of
-  //   an object, function, or enumerator declared in the same
-  //   scope. If a class or enumeration name and an object, function,
-  //   or enumerator are declared in the same scope (in any order)
-  //   with the same name, the class or enumeration name is hidden
-  //   wherever t

[clang] 6244e38 - [Sema] Add tests for handling of decls hidden by invalid decls

2023-08-17 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-08-17T15:25:53+01:00
New Revision: 6244e3840694e513ef885e8505e7744de8c9b959

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

LOG: [Sema] Add tests for handling of decls hidden by invalid decls

These tests check that invalid declarations don't hide any other
declarations, but valid declarations do hide invalid declarations.

Added: 
clang/test/SemaCXX/invalid-decl-hiding.cpp

Modified: 


Removed: 




diff  --git a/clang/test/SemaCXX/invalid-decl-hiding.cpp 
b/clang/test/SemaCXX/invalid-decl-hiding.cpp
new file mode 100644
index 00..a8c2e8ece06432
--- /dev/null
+++ b/clang/test/SemaCXX/invalid-decl-hiding.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Member Test1 hides class Test1
+class Test1 {
+  static int Test1; // expected-error {{member 'Test1' has the same name as 
its class}}
+// expected-note@-1 {{class 'Test1' is hidden by a 
non-type declaration of 'Test1' here}}
+  void fn1() {
+Test1 x; // expected-error {{must use 'class' tag to refer to type 'Test1' 
in this scope}}
+  }
+  int fn2() {
+return Test1;
+  }
+};
+
+// Member Test2 doesn't hide class Test2 as its declaration is invalid
+class Test2 { // expected-note {{declared here}}
+  static NoSuchType Test2; // expected-error {{unknown type name 'NoSuchType'}}
+   // expected-error@-1 {{member 'Test2' has the same 
name as its class}}
+  void fn1() {
+Test2 x;
+  }
+  int fn2() {
+return Test2; // expected-error {{'Test2' does not refer to a value}}
+  }
+};
+
+// Test3a::x doesn't hide Test3b::x as its declaration is invalid
+namespace Test3a {
+  NoSuchType x() { return 0; } // expected-error {{unknown type name 
'NoSuchType'}}
+}
+namespace Test3b {
+  class x; // expected-note {{declared here}}
+}
+using Test3a::x;
+using Test3b::x;
+int test3_fn() {
+  return x; // expected-error {{'x' does not refer to a value}}
+}
+
+// Function Test4 hides class Test4, whose declaration is invalid
+class Test4 : public NoSuchType { // expected-error {{expected class name}}
+
+};
+int Test4() { return 0; }
+
+int test4_fn() {
+  return Test4();
+}
+
+// Function Test5 doesn't hide class Test5 when both are invalid
+class Test5 : public NoSuchType { // expected-error {{expected class name}}
+
+};
+NoSuchType Test5() { return 0; } // expected-error {{unknown type name 
'NoSuchType'}}
+
+Test5 test5_fn() {
+  Test5 x;
+  return x;
+}



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


[clang] 9e11a6d - [Sema] Fix handling of functions that hide classes

2023-08-18 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-08-18T12:39:37+01:00
New Revision: 9e11a6d8fdd745f20bada10473b701d2e21492a5

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

LOG: [Sema] Fix handling of functions that hide classes

When a function is declared in the same scope as a class with the same
name then the function hides that class. Currently this is done by a
single check after the main loop in LookupResult::resolveKind, but
this can give the wrong result when we have a using declaration in
multiple namespace scopes in two different ways:

 * When the using declaration is hidden in one namespace but not the
   other we can end up considering only the hidden one when deciding
   if the result is ambiguous, causing an incorrect "not ambiguous"
   result.

 * When two classes with the same name in different namespace scopes
   are both hidden by using declarations this can result in
   incorrectly deciding the result is ambiguous. There's currently a
   comment saying this is expected, but I don't think that's correct.

Solve this by checking each Decl to see if it's hidden by some other
Decl in the same scope. This means we have to delay removing anything
from Decls until after the main loop, in case a Decl is hidden by
another that is removed due to being non-unique.

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

Added: 
clang/test/SemaCXX/using-hiding.cpp

Modified: 
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index a6c948da2b12fb..7dd96e3155e1dd 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -514,21 +514,42 @@ void LookupResult::resolveKind() {
   const NamedDecl *HasNonFunction = nullptr;
 
   llvm::SmallVector EquivalentNonFunctions;
+  llvm::BitVector RemovedDecls(N);
 
-  unsigned UniqueTagIndex = 0;
-
-  unsigned I = 0;
-  while (I < N) {
+  for (unsigned I = 0; I < N; I++) {
 const NamedDecl *D = Decls[I]->getUnderlyingDecl();
 D = cast(D->getCanonicalDecl());
 
 // Ignore an invalid declaration unless it's the only one left.
 // Also ignore HLSLBufferDecl which not have name conflict with other 
Decls.
-if ((D->isInvalidDecl() || isa(D)) && !(I == 0 && N == 1)) 
{
-  Decls[I] = Decls[--N];
+if ((D->isInvalidDecl() || isa(D)) &&
+N - RemovedDecls.count() > 1) {
+  RemovedDecls.set(I);
   continue;
 }
 
+// C++ [basic.scope.hiding]p2:
+//   A class name or enumeration name can be hidden by the name of
+//   an object, function, or enumerator declared in the same
+//   scope. If a class or enumeration name and an object, function,
+//   or enumerator are declared in the same scope (in any order)
+//   with the same name, the class or enumeration name is hidden
+//   wherever the object, function, or enumerator name is visible.
+if (HideTags && isa(D)) {
+  bool Hidden = false;
+  for (auto *OtherDecl : Decls) {
+if (canHideTag(OtherDecl) && !OtherDecl->isInvalidDecl() &&
+getContextForScopeMatching(OtherDecl)->Equals(
+getContextForScopeMatching(Decls[I]))) {
+  RemovedDecls.set(I);
+  Hidden = true;
+  break;
+}
+  }
+  if (Hidden)
+continue;
+}
+
 std::optional ExistingI;
 
 // Redeclarations of types via typedef can occur both within a scope
@@ -561,7 +582,7 @@ void LookupResult::resolveKind() {
   if (isPreferredLookupResult(getSema(), getLookupKind(), Decls[I],
   Decls[*ExistingI]))
 Decls[*ExistingI] = Decls[I];
-  Decls[I] = Decls[--N];
+  RemovedDecls.set(I);
   continue;
 }
 
@@ -572,7 +593,6 @@ void LookupResult::resolveKind() {
 } else if (isa(D)) {
   if (HasTag)
 Ambiguous = true;
-  UniqueTagIndex = I;
   HasTag = true;
 } else if (isa(D)) {
   HasFunction = true;
@@ -588,7 +608,7 @@ void LookupResult::resolveKind() {
 if (getSema().isEquivalentInternalLinkageDeclaration(HasNonFunction,
  D)) {
   EquivalentNonFunctions.push_back(D);
-  Decls[I] = Decls[--N];
+  RemovedDecls.set(I);
   continue;
 }
 if (D->isPlaceholderVar(getSema().getLangOpts()) &&
@@ -600,28 +620,6 @@ void LookupResult::resolveKind() {
   }
   HasNonFunction = D;
 }
-I++;
-  }
-
-  // C++ [basic.scope.hiding]p2:
-  //   A class name or enumeration name can be hidden by the name of
-  //   an object, function, or enumerator declared in the same
-  //   scope. If a class or enumeration name and an object, function,
-  //   or enumerator are declared in the same scope (in any ord

[clang] 4ade8b7 - [AST] Fix bug in UnresolvedSet::erase of last element

2023-07-05 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-07-05T16:02:40+01:00
New Revision: 4ade8b7ed9976303b23cff3525223826e65b46e7

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

LOG: [AST] Fix bug in UnresolvedSet::erase of last element

UnresolvedSet::erase works by popping the last element then replacing
the element to be erased with that element. When the element to be
erased is itself the last element this leads to writing past the end
of the set, causing an assertion failure.

Fix this by making erase of the last element just pop that element.

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

Added: 
clang/unittests/AST/UnresolvedSetTest.cpp

Modified: 
clang/include/clang/AST/UnresolvedSet.h
clang/unittests/AST/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/AST/UnresolvedSet.h 
b/clang/include/clang/AST/UnresolvedSet.h
index 17b47f6ab96bee..ee31be969b6e35 100644
--- a/clang/include/clang/AST/UnresolvedSet.h
+++ b/clang/include/clang/AST/UnresolvedSet.h
@@ -114,9 +114,17 @@ class UnresolvedSetImpl {
 I.I->set(New, AS);
   }
 
-  void erase(unsigned I) { decls()[I] = decls().pop_back_val(); }
+  void erase(unsigned I) {
+auto val = decls().pop_back_val();
+if (I < size())
+  decls()[I] = val;
+  }
 
-  void erase(iterator I) { *I.I = decls().pop_back_val(); }
+  void erase(iterator I) {
+auto val = decls().pop_back_val();
+if (I != end())
+  *I.I = val;
+  }
 
   void setAccess(iterator I, AccessSpecifier AS) { I.I->setAccess(AS); }
 

diff  --git a/clang/unittests/AST/CMakeLists.txt 
b/clang/unittests/AST/CMakeLists.txt
index b664b64070328e..12484be9206e23 100644
--- a/clang/unittests/AST/CMakeLists.txt
+++ b/clang/unittests/AST/CMakeLists.txt
@@ -35,6 +35,7 @@ add_clang_unittest(ASTTests
   StructuralEquivalenceTest.cpp
   TemplateNameTest.cpp
   TypePrinterTest.cpp
+  UnresolvedSetTest.cpp
   )
 
 clang_target_link_libraries(ASTTests

diff  --git a/clang/unittests/AST/UnresolvedSetTest.cpp 
b/clang/unittests/AST/UnresolvedSetTest.cpp
new file mode 100644
index 00..6c4d6db9092321
--- /dev/null
+++ b/clang/unittests/AST/UnresolvedSetTest.cpp
@@ -0,0 +1,115 @@
+#include "clang/AST/UnresolvedSet.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+class NamedDecl {
+  int dummy;
+
+public:
+  NamedDecl() {}
+};
+} // namespace clang
+
+using namespace clang;
+
+class UnresolvedSetTest : public ::testing::Test {
+protected:
+  NamedDecl n0, n1, n2, n3;
+  UnresolvedSet<2> set;
+
+  void SetUp() override {
+set.addDecl(&n0);
+set.addDecl(&n1);
+set.addDecl(&n2);
+set.addDecl(&n3);
+  }
+};
+
+TEST_F(UnresolvedSetTest, Size) { EXPECT_EQ(set.size(), 4u); }
+
+TEST_F(UnresolvedSetTest, ArrayOperator) {
+  EXPECT_EQ(set[0].getDecl(), &n0);
+  EXPECT_EQ(set[1].getDecl(), &n1);
+  EXPECT_EQ(set[2].getDecl(), &n2);
+  EXPECT_EQ(set[3].getDecl(), &n3);
+}
+
+TEST_F(UnresolvedSetTest, EraseIntegerFromStart) {
+  set.erase(0);
+  EXPECT_EQ(set.size(), 3u);
+  EXPECT_EQ(set[0].getDecl(), &n3);
+  EXPECT_EQ(set[1].getDecl(), &n1);
+  EXPECT_EQ(set[2].getDecl(), &n2);
+
+  set.erase(0);
+  EXPECT_EQ(set.size(), 2u);
+  EXPECT_EQ(set[0].getDecl(), &n2);
+  EXPECT_EQ(set[1].getDecl(), &n1);
+
+  set.erase(0);
+  EXPECT_EQ(set.size(), 1u);
+  EXPECT_EQ(set[0].getDecl(), &n1);
+
+  set.erase(0);
+  EXPECT_EQ(set.size(), 0u);
+}
+
+TEST_F(UnresolvedSetTest, EraseIntegerFromEnd) {
+  set.erase(3);
+  EXPECT_EQ(set.size(), 3u);
+  EXPECT_EQ(set[0].getDecl(), &n0);
+  EXPECT_EQ(set[1].getDecl(), &n1);
+  EXPECT_EQ(set[2].getDecl(), &n2);
+
+  set.erase(2);
+  EXPECT_EQ(set.size(), 2u);
+  EXPECT_EQ(set[0].getDecl(), &n0);
+  EXPECT_EQ(set[1].getDecl(), &n1);
+
+  set.erase(1);
+  EXPECT_EQ(set.size(), 1u);
+  EXPECT_EQ(set[0].getDecl(), &n0);
+
+  set.erase(0);
+  EXPECT_EQ(set.size(), 0u);
+}
+
+TEST_F(UnresolvedSetTest, EraseIteratorFromStart) {
+  set.erase(set.begin());
+  EXPECT_EQ(set.size(), 3u);
+  EXPECT_EQ(set[0].getDecl(), &n3);
+  EXPECT_EQ(set[1].getDecl(), &n1);
+  EXPECT_EQ(set[2].getDecl(), &n2);
+
+  set.erase(set.begin());
+  EXPECT_EQ(set.size(), 2u);
+  EXPECT_EQ(set[0].getDecl(), &n2);
+  EXPECT_EQ(set[1].getDecl(), &n1);
+
+  set.erase(set.begin());
+  EXPECT_EQ(set.size(), 1u);
+  EXPECT_EQ(set[0].getDecl(), &n1);
+
+  set.erase(set.begin());
+  EXPECT_EQ(set.size(), 0u);
+}
+
+TEST_F(UnresolvedSetTest, EraseIteratorFromEnd) {
+  set.erase(--set.end());
+  EXPECT_EQ(set.size(), 3u);
+  EXPECT_EQ(set[0].getDecl(), &n0);
+  EXPECT_EQ(set[1].getDecl(), &n1);
+  EXPECT_EQ(set[2].getDecl(), &n2);
+
+  set.erase(--set.end());
+  EXPECT_EQ(set.size(), 2u);
+  EXPECT_EQ(set[0].getDecl(), &n0);
+  EXPECT_EQ(set[1].getDecl(), &n1);
+
+  set.erase(--set.end());
+  EXPECT_EQ(set.size(), 1u);
+  EXPECT_EQ(set[0].getDecl(), &n0)

[clang] 2583221 - Fix compile error in UnresolvedSetTest.cpp with -Wall

2023-07-05 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-07-05T17:39:59+01:00
New Revision: 258322105892bd895a89ccbe89487885581f5a47

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

LOG: Fix compile error in UnresolvedSetTest.cpp with -Wall

A stage 2 buildbot that compiles with -Wall -Werror is showing a failure because
a dummy value is unused. Use the unused attribute to suppress the warning, and
add a comment about why we have this value.

Added: 


Modified: 
clang/unittests/AST/UnresolvedSetTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/UnresolvedSetTest.cpp 
b/clang/unittests/AST/UnresolvedSetTest.cpp
index 6c4d6db9092321..147c42e1fb0884 100644
--- a/clang/unittests/AST/UnresolvedSetTest.cpp
+++ b/clang/unittests/AST/UnresolvedSetTest.cpp
@@ -3,7 +3,9 @@
 
 namespace clang {
 class NamedDecl {
-  int dummy;
+  // DeclAccessPair assumes that NamedDecl is at least 4-byte aligned, so we
+  // we need to have a dummy value to make this dummy NamedDecl also be 
aligned.
+  int dummy __attribute__((unused));
 
 public:
   NamedDecl() {}



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


[clang] 25784cd - Fix compile error in UnresolvedSetTest.cpp, again

2023-07-05 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-07-05T17:54:50+01:00
New Revision: 25784cd6a962ac59e7bde07761fc3ba450da6628

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

LOG: Fix compile error in UnresolvedSetTest.cpp, again

My previous fix used a gcc-style attribute, but not all compilers will accept
that. Instead use [[maybe_unused]], which is what we use elsewhere for this
kind of thing.

Added: 


Modified: 
clang/unittests/AST/UnresolvedSetTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/UnresolvedSetTest.cpp 
b/clang/unittests/AST/UnresolvedSetTest.cpp
index 147c42e1fb0884..ada857e0e38260 100644
--- a/clang/unittests/AST/UnresolvedSetTest.cpp
+++ b/clang/unittests/AST/UnresolvedSetTest.cpp
@@ -5,7 +5,7 @@ namespace clang {
 class NamedDecl {
   // DeclAccessPair assumes that NamedDecl is at least 4-byte aligned, so we
   // we need to have a dummy value to make this dummy NamedDecl also be 
aligned.
-  int dummy __attribute__((unused));
+  [[maybe_unused]] int dummy;
 
 public:
   NamedDecl() {}



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


[clang] 626c789 - Fix compile error in UnresolvedSetTest.cpp, hopefully the last one

2023-07-06 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-07-06T11:54:45+01:00
New Revision: 626c789d92bc917e7db30478e9b6d4c9b567ee17

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

LOG: Fix compile error in UnresolvedSetTest.cpp, hopefully the last one

This test is failing to compile when LLVM_ENABLE_MODULES=ON due to
NamedDecl being multiply defined. Fix this by avoiding declaring our
own NamedDecl in the test and instead cast a struct of appropriate
size and alignment to NamedDecl.

Added: 


Modified: 
clang/unittests/AST/UnresolvedSetTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/UnresolvedSetTest.cpp 
b/clang/unittests/AST/UnresolvedSetTest.cpp
index ada857e0e38260..0d01eebe07e2f5 100644
--- a/clang/unittests/AST/UnresolvedSetTest.cpp
+++ b/clang/unittests/AST/UnresolvedSetTest.cpp
@@ -1,56 +1,56 @@
 #include "clang/AST/UnresolvedSet.h"
+#include "clang/AST/Decl.h"
 #include "gtest/gtest.h"
 
-namespace clang {
-class NamedDecl {
-  // DeclAccessPair assumes that NamedDecl is at least 4-byte aligned, so we
-  // we need to have a dummy value to make this dummy NamedDecl also be 
aligned.
-  [[maybe_unused]] int dummy;
-
-public:
-  NamedDecl() {}
-};
-} // namespace clang
-
 using namespace clang;
 
 class UnresolvedSetTest : public ::testing::Test {
 protected:
-  NamedDecl n0, n1, n2, n3;
+  // For this test we don't care about the contents of the NamedDecl,
+  // so just use a dummy struct of appropriate size and alignment.
+  struct alignas(NamedDecl) DummyDecl {
+char contents[sizeof(NamedDecl)];
+  };
+  DummyDecl d0, d1, d2, d3;
+  NamedDecl *n0, *n1, *n2, *n3;
   UnresolvedSet<2> set;
 
   void SetUp() override {
-set.addDecl(&n0);
-set.addDecl(&n1);
-set.addDecl(&n2);
-set.addDecl(&n3);
+n0 = reinterpret_cast(&d0);
+n1 = reinterpret_cast(&d1);
+n2 = reinterpret_cast(&d2);
+n3 = reinterpret_cast(&d3);
+set.addDecl(n0);
+set.addDecl(n1);
+set.addDecl(n2);
+set.addDecl(n3);
   }
 };
 
 TEST_F(UnresolvedSetTest, Size) { EXPECT_EQ(set.size(), 4u); }
 
 TEST_F(UnresolvedSetTest, ArrayOperator) {
-  EXPECT_EQ(set[0].getDecl(), &n0);
-  EXPECT_EQ(set[1].getDecl(), &n1);
-  EXPECT_EQ(set[2].getDecl(), &n2);
-  EXPECT_EQ(set[3].getDecl(), &n3);
+  EXPECT_EQ(set[0].getDecl(), n0);
+  EXPECT_EQ(set[1].getDecl(), n1);
+  EXPECT_EQ(set[2].getDecl(), n2);
+  EXPECT_EQ(set[3].getDecl(), n3);
 }
 
 TEST_F(UnresolvedSetTest, EraseIntegerFromStart) {
   set.erase(0);
   EXPECT_EQ(set.size(), 3u);
-  EXPECT_EQ(set[0].getDecl(), &n3);
-  EXPECT_EQ(set[1].getDecl(), &n1);
-  EXPECT_EQ(set[2].getDecl(), &n2);
+  EXPECT_EQ(set[0].getDecl(), n3);
+  EXPECT_EQ(set[1].getDecl(), n1);
+  EXPECT_EQ(set[2].getDecl(), n2);
 
   set.erase(0);
   EXPECT_EQ(set.size(), 2u);
-  EXPECT_EQ(set[0].getDecl(), &n2);
-  EXPECT_EQ(set[1].getDecl(), &n1);
+  EXPECT_EQ(set[0].getDecl(), n2);
+  EXPECT_EQ(set[1].getDecl(), n1);
 
   set.erase(0);
   EXPECT_EQ(set.size(), 1u);
-  EXPECT_EQ(set[0].getDecl(), &n1);
+  EXPECT_EQ(set[0].getDecl(), n1);
 
   set.erase(0);
   EXPECT_EQ(set.size(), 0u);
@@ -59,18 +59,18 @@ TEST_F(UnresolvedSetTest, EraseIntegerFromStart) {
 TEST_F(UnresolvedSetTest, EraseIntegerFromEnd) {
   set.erase(3);
   EXPECT_EQ(set.size(), 3u);
-  EXPECT_EQ(set[0].getDecl(), &n0);
-  EXPECT_EQ(set[1].getDecl(), &n1);
-  EXPECT_EQ(set[2].getDecl(), &n2);
+  EXPECT_EQ(set[0].getDecl(), n0);
+  EXPECT_EQ(set[1].getDecl(), n1);
+  EXPECT_EQ(set[2].getDecl(), n2);
 
   set.erase(2);
   EXPECT_EQ(set.size(), 2u);
-  EXPECT_EQ(set[0].getDecl(), &n0);
-  EXPECT_EQ(set[1].getDecl(), &n1);
+  EXPECT_EQ(set[0].getDecl(), n0);
+  EXPECT_EQ(set[1].getDecl(), n1);
 
   set.erase(1);
   EXPECT_EQ(set.size(), 1u);
-  EXPECT_EQ(set[0].getDecl(), &n0);
+  EXPECT_EQ(set[0].getDecl(), n0);
 
   set.erase(0);
   EXPECT_EQ(set.size(), 0u);
@@ -79,18 +79,18 @@ TEST_F(UnresolvedSetTest, EraseIntegerFromEnd) {
 TEST_F(UnresolvedSetTest, EraseIteratorFromStart) {
   set.erase(set.begin());
   EXPECT_EQ(set.size(), 3u);
-  EXPECT_EQ(set[0].getDecl(), &n3);
-  EXPECT_EQ(set[1].getDecl(), &n1);
-  EXPECT_EQ(set[2].getDecl(), &n2);
+  EXPECT_EQ(set[0].getDecl(), n3);
+  EXPECT_EQ(set[1].getDecl(), n1);
+  EXPECT_EQ(set[2].getDecl(), n2);
 
   set.erase(set.begin());
   EXPECT_EQ(set.size(), 2u);
-  EXPECT_EQ(set[0].getDecl(), &n2);
-  EXPECT_EQ(set[1].getDecl(), &n1);
+  EXPECT_EQ(set[0].getDecl(), n2);
+  EXPECT_EQ(set[1].getDecl(), n1);
 
   set.erase(set.begin());
   EXPECT_EQ(set.size(), 1u);
-  EXPECT_EQ(set[0].getDecl(), &n1);
+  EXPECT_EQ(set[0].getDecl(), n1);
 
   set.erase(set.begin());
   EXPECT_EQ(set.size(), 0u);
@@ -99,18 +99,18 @@ TEST_F(UnresolvedSetTest, EraseIteratorFromStart) {
 TEST_F(UnresolvedSetTest, EraseIteratorFromEnd) {
   set.erase(--set.end());
   EXPECT_

[clang] 9e3264a - [FPEnv] Enable strict fp for AArch64 in clang

2022-11-21 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2022-11-21T16:02:54Z
New Revision: 9e3264ab2021e07246e2cb491497d9cd514c213c

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

LOG: [FPEnv] Enable strict fp for AArch64 in clang

The AArch64 target now has the necessary support for strict fp, so
enable it in clang.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Basic/Targets/AArch64.cpp
clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
clang/test/CodeGen/aarch64-neon-misc-constrained.c
clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
clang/test/CodeGen/aarch64-strictfp-builtins.c
clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics-constrained.c
clang/test/CodeGen/arm-neon-directed-rounding-constrained.c
clang/test/CodeGen/arm64-vrnd-constrained.c
clang/test/CodeGen/fp16-ops-strictfp.c
clang/test/Parser/pragma-fp-warn.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b2b085409116a..6a98dd3b7da8d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -765,6 +765,9 @@ Arm and AArch64 Support in Clang
   * Arm Cortex-A715 (cortex-a715).
   * Arm Cortex-X3 (cortex-x3).
   * Arm Neoverse V2 (neoverse-v2)
+- Strict floating point has been enabled for AArch64, which means that
+  ``-ftrapping-math``, ``-frounding-math``, ``-ffp-model=strict``, and
+  ``-ffp-exception-behaviour=`` are now accepted.
 
 Floating Point Support in Clang
 ---

diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c283aca85f4e2..d85a21397abc1 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -84,6 +84,7 @@ AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple 
&Triple,
   HasLegalHalfType = true;
   HalfArgsAndReturns = true;
   HasFloat16 = true;
+  HasStrictFP = true;
 
   if (Triple.isArch64Bit())
 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;

diff  --git a/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c 
b/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
index 58af968725be9..33700f0d0d34c 100644
--- a/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
+++ b/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
@@ -4,7 +4,7 @@
 // RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN: -S -disable-O0-optnone \
-// RUN:  -ffp-exception-behavior=strict -fexperimental-strict-floating-point \
+// RUN:  -ffp-exception-behavior=strict \
 // RUN:  -flax-vector-conversions=none -emit-llvm -o - %s | opt -S 
-passes=mem2reg \
 // RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,CONSTRAINED %s
 

diff  --git a/clang/test/CodeGen/aarch64-neon-misc-constrained.c 
b/clang/test/CodeGen/aarch64-neon-misc-constrained.c
index dce36c392d63f..e24e129d2bc7d 100644
--- a/clang/test/CodeGen/aarch64-neon-misc-constrained.c
+++ b/clang/test/CodeGen/aarch64-neon-misc-constrained.c
@@ -3,7 +3,6 @@
 // RUN: | opt -S -passes=mem2reg | FileCheck --check-prefix=COMMON 
--check-prefix=COMMONIR --check-prefix=UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN:  -ffp-exception-behavior=strict \
-// RUN:  -fexperimental-strict-floating-point \
 // RUN:  -disable-O0-optnone -emit-llvm -o - %s \
 // RUN: | opt -S -passes=mem2reg | FileCheck --check-prefix=COMMON 
--check-prefix=COMMONIR --check-prefix=CONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
@@ -11,7 +10,6 @@
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN:  -ffp-exception-behavior=strict \
-// RUN:  -fexperimental-strict-floating-point \
 // RUN:  -disable-O0-optnone -S -o - %s \
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
 

diff  --git 
a/clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c 
b/clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
index bd0501b42dd6e..6371339f0a40d 100644
--- a/clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
+++ b/clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
@@ -3,7 +3,6 @@
 // RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon 
-target-cpu cyclone \
 // RUN: -ffp-exception-behavior=strict \
-// RUN: -fexperimental-strict-floating-point \
 // RUN: -disable-O0-optno

[clang] 6b8900f - [clang][CodeGen] Add default attributes to __clang_call_terminate

2022-11-29 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2022-11-29T13:09:52Z
New Revision: 6b8900f7f91de489302886c7e48033407d13f8c1

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

LOG: [clang][CodeGen] Add default attributes to __clang_call_terminate

When generating __clang_call_terminate use SetLLVMFunctionAttributes
to set the default function attributes, like we do for all the other
functions generated by clang. This fixes a problem where target
features from the command line weren't being applied to this function.

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

Added: 
clang/test/CodeGenCXX/arm-generated-fn-attr.cpp

Modified: 
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/test/CodeGenCXX/dllimport-runtime-fns.cpp
clang/test/CodeGenCXX/exceptions.cpp
clang/test/CodeGenCXX/runtime-dllstorage.cpp
clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp
clang/test/OpenMP/parallel_codegen.cpp
clang/test/OpenMP/parallel_for_codegen.cpp
clang/test/OpenMP/parallel_master_codegen.cpp
clang/test/OpenMP/parallel_sections_codegen.cpp
clang/test/OpenMP/single_codegen.cpp
clang/test/OpenMP/taskgroup_codegen.cpp
clang/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp
clang/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 224a019d2fd3..66bfbd79595e 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -4675,13 +4675,16 @@ void ItaniumCXXABI::emitBeginCatch(CodeGenFunction &CGF,
 ///   void @__clang_call_terminate(i8* %exn) nounwind noreturn
 /// This code is used only in C++.
 static llvm::FunctionCallee getClangCallTerminateFn(CodeGenModule &CGM) {
-  llvm::FunctionType *fnTy =
-llvm::FunctionType::get(CGM.VoidTy, CGM.Int8PtrTy, /*isVarArg=*/false);
+  ASTContext &C = CGM.getContext();
+  const CGFunctionInfo &FI = CGM.getTypes().arrangeBuiltinFunctionDeclaration(
+  C.VoidTy, {C.getPointerType(C.CharTy)});
+  llvm::FunctionType *fnTy = CGM.getTypes().GetFunctionType(FI);
   llvm::FunctionCallee fnRef = CGM.CreateRuntimeFunction(
   fnTy, "__clang_call_terminate", llvm::AttributeList(), /*Local=*/true);
   llvm::Function *fn =
   cast(fnRef.getCallee()->stripPointerCasts());
   if (fn->empty()) {
+CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, fn, /*IsThunk=*/false);
 fn->setDoesNotThrow();
 fn->setDoesNotReturn();
 

diff  --git a/clang/test/CodeGenCXX/arm-generated-fn-attr.cpp 
b/clang/test/CodeGenCXX/arm-generated-fn-attr.cpp
new file mode 100644
index ..4908e8366d02
--- /dev/null
+++ b/clang/test/CodeGenCXX/arm-generated-fn-attr.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -triple thumbv8.1m.main-none-eabi -target-feature +pacbti 
-fcxx-exceptions -fexceptions -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-PACBTI
+// RUN: %clang_cc1 -triple thumbv8.1m.main-none-eabi -target-feature -pacbti 
-fcxx-exceptions -fexceptions -emit-llvm %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-NOPACBTI
+
+// Check that functions generated by clang have the correct attributes
+
+class Example {
+public:
+  Example();
+  int fn();
+};
+
+// Initialization of var1 causes __cxx_global_var_init and __tls_init to be 
generated
+thread_local Example var1;
+extern thread_local Example var2;
+extern void fn();
+
+int testfn() noexcept {
+  // Calling fn in a noexcept function causes __clang_call_terminate to be 
generated
+  fn();
+  // Use of var1 and var2 causes TLS wrapper functions to be generated
+  return var1.fn() + var2.fn();
+}
+
+// CHECK: define {{.*}} @__cxx_global_var_init() [[ATTR1:#[0-9]+]]
+// CHECK: define {{.*}} @__clang_call_terminate({{.*}}) [[ATTR2:#[0-9]+]]
+// CHECK: define {{.*}} @_ZTW4var1() [[ATTR3:#[0-9]+]]
+// CHECK: define {{.*}} @_ZTW4var2() [[ATTR3]]
+// CHECK: define {{.*}} @__tls_init() [[ATTR1]]
+
+// CHECK-PACBTI: attributes [[ATTR1]] = { 
{{.*}}"target-features"="+armv8.1-m.main,+pacbti,+thumb-mode"{{.*}} }
+// CHECK-PACBTI: attributes [[ATTR2]] = { 
{{.*}}"target-features"="+armv8.1-m.main,+pacbti,+thumb-mode"{{.*}} }
+// CHECK-PACBTI: attributes [[ATTR3]] = { 
{{.*}}"target-features"="+armv8.1-m.main,+pacbti,+thumb-mode"{{.*}} }
+
+// CHECK-NOPACBTI: attributes [[ATTR1]] = { 
{{.*}}"target-features"="+armv8.1-m.main,+thumb-mode,-pacbti"{{.*}} }
+// CHECK-NOPACBTI: attributes [[ATTR2]] = { 
{{.*}}"target-features"="+armv8.1-m.main,+thumb-mode,-pacbti"{{.*}} }
+// CHECK-NOPACBTI: attributes [[ATTR3]] = { 
{{.*}}"target-features"="+armv8.1-m.main,+thumb-mode,-pacbti"{{.*}} }

diff  --git a/clang/test/CodeGenCXX/dllimport-runtime-fns.cpp 
b/clang/test/CodeGenCXX/dllimport-runtime-fns.cpp
index d589

[clang] fa0320d - Add ParsedAttrInfo::handleDeclAttribute

2020-03-23 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2020-03-23T13:23:11Z
New Revision: fa0320dd8d5aa6ea920ac78224d5044398ba50b4

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

LOG: Add ParsedAttrInfo::handleDeclAttribute

This makes it possible for plugin attributes to actually do something, and also
removes a lot of boilerplate for simple attributes in SemaDeclAttr.cpp.

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

Added: 


Modified: 
clang/docs/ClangPlugins.rst
clang/docs/InternalsManual.rst
clang/include/clang/Basic/Attr.td
clang/include/clang/Sema/ParsedAttr.h
clang/lib/Sema/ParsedAttr.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/docs/ClangPlugins.rst b/clang/docs/ClangPlugins.rst
index 23e037e197c9..7e33ea33c0df 100644
--- a/clang/docs/ClangPlugins.rst
+++ b/clang/docs/ClangPlugins.rst
@@ -63,6 +63,53 @@ registering it using ``PragmaHandlerRegistry::Add<>``:
 
   static PragmaHandlerRegistry::Add 
Y("example_pragma","example pragma description");
 
+Defining attributes
+===
+
+Plugins can define attributes by declaring a ``ParsedAttrInfo`` and registering
+it using ``ParsedAttrInfoRegister::Add<>``:
+
+.. code-block:: c++
+
+  class ExampleAttrInfo : public ParsedAttrInfo {
+  public:
+ExampleAttrInfo() {
+  Spellings.push_back({ParsedAttr::AS_GNU,"example"});
+}
+AttrHandling handleDeclAttribute(Sema &S, Decl *D,
+ const ParsedAttr &Attr) const override {
+  // Handle the attribute
+  return AttributeApplied;
+}
+  };
+
+  static ParsedAttrInfoRegistry::Add 
Z("example_attr","example attribute description");
+
+The members of ``ParsedAttrInfo`` that a plugin attribute must define are:
+
+ * ``Spellings``, which must be populated with every `Spelling
+   `_ of the
+   attribute, each of which consists of an attribute syntax and how the
+   attribute name is spelled for that syntax. If the syntax allows a scope then
+   the spelling must be "scope::attr" if a scope is present or "::attr" if not.
+ * ``handleDeclAttribute``, which is the function that applies the attribute to
+   a declaration. It is responsible for checking that the attribute's arguments
+   are valid, and typically applies the attribute by adding an ``Attr`` to the
+   ``Decl``. It returns either ``AttributeApplied``, to indicate that the
+   attribute was successfully applied, or ``AttributeNotApplied`` if it wasn't.
+
+The members of ``ParsedAttrInfo`` that may need to be defined, depending on the
+attribute, are:
+
+ * ``NumArgs`` and ``OptArgs``, which set the number of required and optional
+   arguments to the attribute.
+ * ``diagAppertainsToDecl``, which checks if the attribute has been used on the
+   right kind of declaration and issues a diagnostic if not.
+ * ``diagLangOpts``, which checks if the attribute is permitted for the current
+   language mode and issues a diagnostic if not.
+ * ``existsInTarget``, which checks if the attribute is permitted for the given
+   target.
+
 Putting it all together
 ===
 

diff  --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst
index 3681675a3244..09aec6df69f2 100644
--- a/clang/docs/InternalsManual.rst
+++ b/clang/docs/InternalsManual.rst
@@ -2455,6 +2455,9 @@ Attributes that do not require custom semantic handling 
should set the
 attributes are assumed to use a semantic handler by default. Attributes
 without a semantic handler are not given a parsed attribute ``Kind`` 
enumerator.
 
+"Simple" attributes, that require no custom semantic processing aside from what
+is automatically provided, should set the ``SimpleHandler`` field to ``1``.
+
 Target-specific attributes may share a spelling with other attributes in
 
diff erent targets. For instance, the ARM and MSP430 targets both have an
 attribute spelled ``GNU<"interrupt">``, but with 
diff erent parsing and semantic
@@ -2481,12 +2484,11 @@ Boilerplate
 All semantic processing of declaration attributes happens in 
`lib/Sema/SemaDeclAttr.cpp
 
`_,
 and generally starts in the ``ProcessDeclAttribute()`` function. If the
-attribute is a "simple" attribute -- meaning that it requires no custom 
semantic
-processing aside from what is automatically  provided, add a call to
-``handleSimpleAttribute(S, D, Attr);`` to the switch statement.
-Otherwise, write a new ``handleYourAttr()`` function, and add that to the 
switch
-statement. Please do not implement handling logic directly in the ``case`` for
-the attribute.
+attribute has the ``SimpleHandler`` field set to ``1`` then the function to
+process the attribute will be automaticall

[clang] bc3f171 - Don't normalise CXX11/C2X attribute names to start with ::

2020-03-25 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2020-03-25T14:33:44Z
New Revision: bc3f171090f6d9f84a5d7b333bc70a1e14afffd4

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

LOG: Don't normalise CXX11/C2X attribute names to start with ::

Currently square-bracket-style (CXX11/C2X) attribute names are normalised to
start with :: if they don't have a namespace. This is a bit odd, as such
names are rejected when parsing, so don't do this.

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

Added: 


Modified: 
clang/lib/Basic/Attributes.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index a860c9dba2ef..d479b39e149e 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -85,12 +85,12 @@ static SmallString<64> normalizeName(const IdentifierInfo 
*Name,
   StringRef ScopeName = normalizeAttrScopeName(Scope, SyntaxUsed);
   StringRef AttrName = normalizeAttrName(Name, ScopeName, SyntaxUsed);
 
-  // Ensure that in the case of C++11 attributes, we look for '::foo' if it is
-  // unscoped.
   SmallString<64> FullName = ScopeName;
-  if (Scope || SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
-  SyntaxUsed == AttributeCommonInfo::AS_C2x)
+  if (!ScopeName.empty()) {
+assert(SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
+   SyntaxUsed == AttributeCommonInfo::AS_C2X);
 FullName += "::";
+  }
   FullName += AttrName;
 
   return FullName;

diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index dcb2f323122c..32744f7579fb 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3739,10 +3739,8 @@ void EmitClangAttrParsedAttrImpl(RecordKeeper &Records, 
raw_ostream &OS) {
 for (const auto &S : GetFlattenedSpellings(Attr)) {
   const std::string &RawSpelling = S.name();
   std::string Spelling;
-  if (S.variety() == "CXX11" || S.variety() == "C2x") {
-Spelling += S.nameSpace();
-Spelling += "::";
-  }
+  if (!S.nameSpace().empty())
+Spelling += S.nameSpace() + "::";
   if (S.variety() == "GNU")
 Spelling += NormalizeGNUAttrSpelling(RawSpelling);
   else
@@ -3815,12 +3813,12 @@ void EmitClangAttrParsedAttrKinds(RecordKeeper 
&Records, raw_ostream &OS) {
 const std::string &Variety = S.variety();
 if (Variety == "CXX11") {
   Matches = &CXX11;
-  Spelling += S.nameSpace();
-  Spelling += "::";
+  if (!S.nameSpace().empty())
+Spelling += S.nameSpace() + "::";
 } else if (Variety == "C2x") {
   Matches = &C2x;
-  Spelling += S.nameSpace();
-  Spelling += "::";
+  if (!S.nameSpace().empty())
+Spelling += S.nameSpace() + "::";
 } else if (Variety == "GNU")
   Matches = &GNU;
 else if (Variety == "Declspec")



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


[clang] 3f03c12 - Add an attribute plugin example

2020-03-25 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2020-03-25T14:33:44Z
New Revision: 3f03c12a51be656c595301ace832c24a68601ee2

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

LOG: Add an attribute plugin example

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

Added: 
clang/examples/Attribute/Attribute.cpp
clang/examples/Attribute/CMakeLists.txt
clang/test/Frontend/plugin-attribute.cpp

Modified: 
clang/docs/ClangPlugins.rst
clang/examples/CMakeLists.txt
clang/test/CMakeLists.txt

Removed: 




diff  --git a/clang/docs/ClangPlugins.rst b/clang/docs/ClangPlugins.rst
index 7e33ea33c0df..4194491d396a 100644
--- a/clang/docs/ClangPlugins.rst
+++ b/clang/docs/ClangPlugins.rst
@@ -110,6 +110,9 @@ attribute, are:
  * ``existsInTarget``, which checks if the attribute is permitted for the given
target.
 
+To see a working example of an attribute plugin, see `the Attribute.cpp example
+`_.
+
 Putting it all together
 ===
 

diff  --git a/clang/examples/Attribute/Attribute.cpp 
b/clang/examples/Attribute/Attribute.cpp
new file mode 100644
index ..04e30e1bd21b
--- /dev/null
+++ b/clang/examples/Attribute/Attribute.cpp
@@ -0,0 +1,80 @@
+//===- Attribute.cpp 
--===//
+//
+// 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
+//
+//===--===//
+//
+// Example clang plugin which adds an an annotation to file-scope declarations
+// with the 'example' attribute.
+//
+//===--===//
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
+#include "clang/Sema/ParsedAttr.h"
+#include "clang/Sema/Sema.h"
+#include "clang/Sema/SemaDiagnostic.h"
+#include "llvm/IR/Attributes.h"
+using namespace clang;
+
+namespace {
+
+struct ExampleAttrInfo : public ParsedAttrInfo {
+  ExampleAttrInfo() {
+// Can take an optional string argument (the check that the argument
+// actually is a string happens in handleDeclAttribute).
+OptArgs = 1;
+// GNU-style __attribute__(("example")) and C++-style [[example]] and
+// [[plugin::example]] supported.
+Spellings.push_back({ParsedAttr::AS_GNU, "example"});
+Spellings.push_back({ParsedAttr::AS_CXX11, "example"});
+Spellings.push_back({ParsedAttr::AS_CXX11, "plugin::example"});
+  }
+
+  bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr,
+const Decl *D) const override {
+// This attribute appertains to functions only.
+if (!isa(D)) {
+  S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type_str)
+<< Attr << "functions";
+  return false;
+}
+return true;
+  }
+
+  AttrHandling handleDeclAttribute(Sema &S, Decl *D,
+   const ParsedAttr &Attr) const override {
+// Check if the decl is at file scope.
+if (!D->getDeclContext()->isFileContext()) {
+  unsigned ID = S.getDiagnostics().getCustomDiagID(
+  DiagnosticsEngine::Error,
+  "'example' attribute only allowed at file scope");
+  S.Diag(Attr.getLoc(), ID);
+  return AttributeNotApplied;
+}
+// Check if we have an optional string argument.
+StringRef Str = "";
+if (Attr.getNumArgs() > 0) {
+  Expr *ArgExpr = Attr.getArgAsExpr(0);
+  StringLiteral *Literal =
+  dyn_cast(ArgExpr->IgnoreParenCasts());
+  if (Literal) {
+Str = Literal->getString();
+  } else {
+S.Diag(ArgExpr->getExprLoc(), diag::err_attribute_argument_type)
+<< Attr.getAttrName() << AANT_ArgumentString;
+return AttributeNotApplied;
+  }
+}
+// Attach an annotate attribute to the Decl.
+D->addAttr(AnnotateAttr::Create(S.Context, "example(" + Str.str() + ")",
+Attr.getRange()));
+return AttributeApplied;
+  }
+};
+
+} // namespace
+
+static ParsedAttrInfoRegistry::Add X("example", "");

diff  --git a/clang/examples/Attribute/CMakeLists.txt 
b/clang/examples/Attribute/CMakeLists.txt
new file mode 100644
index ..19323bb0962b
--- /dev/null
+++ b/clang/examples/Attribute/CMakeLists.txt
@@ -0,0 +1,11 @@
+add_llvm_library(Attribute MODULE Attribute.cpp PLUGIN_TOOL clang)
+
+if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
+  target_link_libraries(AnnotateFunctions ${cmake_2_8_12_PRIVATE}
+clangAST
+clangBasic
+clangFrontend
+clangLex
+LLVMSupport
+)
+endif()

diff  --git a/cla

Re: [clang] c278e8f - Build fix: AttributeCommonInfo::AS_C2x

2020-03-25 Thread John Brawn via cfe-commits
Thanks, I was about to fix that myself (I was sure I'd built and tested 
everything before committing,
but it appears I failed somehow).

John


From: cfe-commits  on behalf of Hans 
Wennborg via cfe-commits 
Sent: 25 March 2020 14:43
To: cfe-commits@lists.llvm.org 
Subject: [clang] c278e8f - Build fix: AttributeCommonInfo::AS_C2x


Author: Hans Wennborg
Date: 2020-03-25T15:42:21+01:00
New Revision: c278e8f8f916fd8781f24e41a8685514cc448670

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

LOG: Build fix: AttributeCommonInfo::AS_C2x

Added:


Modified:
clang/lib/Basic/Attributes.cpp

Removed:




diff  --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index d479b39e149e..ff6dbf870fcf 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -88,7 +88,7 @@ static SmallString<64> normalizeName(const IdentifierInfo 
*Name,
   SmallString<64> FullName = ScopeName;
   if (!ScopeName.empty()) {
 assert(SyntaxUsed == AttributeCommonInfo::AS_CXX11 ||
-   SyntaxUsed == AttributeCommonInfo::AS_C2X);
+   SyntaxUsed == AttributeCommonInfo::AS_C2x);
 FullName += "::";
   }
   FullName += AttrName;



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


[clang] 0cff81c - Add a release note for attribute plugins

2020-03-26 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2020-03-26T15:01:57Z
New Revision: 0cff81cff05d8e0a24391e3dec5b97174351ea55

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

LOG: Add a release note for attribute plugins

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ad13fb1b3e95..a8163cad9fde 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -111,7 +111,9 @@ New Pragmas in Clang
 Attribute Changes in Clang
 --
 
-- ...
+- Attributes can now be specified by clang plugins. See the
+  `Clang Plugins `_ documentation for
+  details.
 
 Windows Support
 ---



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


[clang] 590dc8d - Use virtual functions in ParsedAttrInfo instead of function pointers

2020-02-26 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2020-02-26T17:24:30Z
New Revision: 590dc8d02cd781b110a87b82476c3557cb5957c3

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

LOG: Use virtual functions in ParsedAttrInfo instead of function pointers

This doesn't do anything on its own, but it's the first step towards
allowing plugins to define attributes. It does simplify the
ParsedAttrInfo generation in ClangAttrEmitter a little though.

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

Added: 


Modified: 
clang/lib/Sema/ParsedAttr.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index 5d0a734f237a..c814639f00ea 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -110,13 +110,26 @@ struct ParsedAttrInfo {
   unsigned IsKnownToGCC : 1;
   unsigned IsSupportedByPragmaAttribute : 1;
 
-  bool (*DiagAppertainsToDecl)(Sema &S, const ParsedAttr &Attr, const Decl *);
-  bool (*DiagLangOpts)(Sema &S, const ParsedAttr &Attr);
-  bool (*ExistsInTarget)(const TargetInfo &Target);
-  unsigned (*SpellingIndexToSemanticSpelling)(const ParsedAttr &Attr);
-  void (*GetPragmaAttributeMatchRules)(
-  llvm::SmallVectorImpl> &Rules,
-  const LangOptions &LangOpts);
+  virtual ~ParsedAttrInfo() = default;
+
+  virtual bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr,
+const Decl *) const {
+return true;
+  }
+  virtual bool diagLangOpts(Sema &S, const ParsedAttr &Attr) const {
+return true;
+  }
+  virtual bool existsInTarget(const TargetInfo &Target) const {
+return true;
+  }
+  virtual unsigned
+  spellingIndexToSemanticSpelling(const ParsedAttr &Attr) const {
+return UINT_MAX;
+  }
+  virtual void getPragmaAttributeMatchRules(
+llvm::SmallVectorImpl> &Rules,
+const LangOptions &LangOpts) const {
+  }
 };
 
 namespace {
@@ -126,7 +139,13 @@ namespace {
 } // namespace
 
 static const ParsedAttrInfo &getInfo(const ParsedAttr &A) {
-  return AttrInfoMap[A.getKind()];
+  // If we have a ParsedAttrInfo for this ParsedAttr then return that,
+  // otherwise return a default ParsedAttrInfo.
+  if (A.getKind() < llvm::array_lengthof(AttrInfoMap))
+return *AttrInfoMap[A.getKind()];
+
+  static ParsedAttrInfo DefaultParsedAttrInfo;
+  return DefaultParsedAttrInfo;
 }
 
 unsigned ParsedAttr::getMinArgs() const { return getInfo(*this).NumArgs; }
@@ -140,7 +159,7 @@ bool ParsedAttr::hasCustomParsing() const {
 }
 
 bool ParsedAttr::diagnoseAppertainsTo(Sema &S, const Decl *D) const {
-  return getInfo(*this).DiagAppertainsToDecl(S, *this, D);
+  return getInfo(*this).diagAppertainsToDecl(S, *this, D);
 }
 
 bool ParsedAttr::appliesToDecl(const Decl *D,
@@ -152,11 +171,11 @@ void ParsedAttr::getMatchRules(
 const LangOptions &LangOpts,
 SmallVectorImpl> &MatchRules)
 const {
-  return getInfo(*this).GetPragmaAttributeMatchRules(MatchRules, LangOpts);
+  return getInfo(*this).getPragmaAttributeMatchRules(MatchRules, LangOpts);
 }
 
 bool ParsedAttr::diagnoseLangOpts(Sema &S) const {
-  return getInfo(*this).DiagLangOpts(S, *this);
+  return getInfo(*this).diagLangOpts(S, *this);
 }
 
 bool ParsedAttr::isTargetSpecificAttr() const {
@@ -168,7 +187,7 @@ bool ParsedAttr::isTypeAttr() const { return 
getInfo(*this).IsType; }
 bool ParsedAttr::isStmtAttr() const { return getInfo(*this).IsStmt; }
 
 bool ParsedAttr::existsInTarget(const TargetInfo &Target) const {
-  return getInfo(*this).ExistsInTarget(Target);
+  return getInfo(*this).existsInTarget(Target);
 }
 
 bool ParsedAttr::isKnownToGCC() const { return getInfo(*this).IsKnownToGCC; }
@@ -178,7 +197,7 @@ bool ParsedAttr::isSupportedByPragmaAttribute() const {
 }
 
 unsigned ParsedAttr::getSemanticSpelling() const {
-  return getInfo(*this).SpellingIndexToSemanticSpelling(*this);
+  return getInfo(*this).spellingIndexToSemanticSpelling(*this);
 }
 
 bool ParsedAttr::hasVariadicArg() const {

diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 116c382c1e8f..251cbecd1c45 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1814,7 +1814,7 @@ struct PragmaClangAttributeSupport {
 
   void emitMatchRuleList(raw_ostream &OS);
 
-  std::string generateStrictConformsTo(const Record &Attr, raw_ostream &OS);
+  void generateStrictConformsTo(const Record &Attr, raw_ostream &OS);
 
   void generateParsingHelpers(raw_ostream &OS);
 };
@@ -1975,21 +1975,17 @@ static std::string 
GenerateTestExpression(ArrayRef LangOpts) {
   return Test;
 }
 
-std::string
+void
 PragmaClangAttributeSupport::generateStrictConformsTo(const Record &Attr,

[clang] 75d4d4b - Add an attribute registry so plugins can add attributes

2020-02-27 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2020-02-27T17:23:16Z
New Revision: 75d4d4bd028f6a5f24ef41dbbc45bed65b2305cf

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

LOG: Add an attribute registry so plugins can add attributes

When constructing a ParsedAttr the ParsedAttrInfo gets looked up in the
AttrInfoMap, which is auto-generated using tablegen. If that lookup fails then
we look through the ParsedAttrInfos that plugins have added to the registry and
check if any has a spelling that matches.

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

Added: 


Modified: 
clang/include/clang/Basic/AttributeCommonInfo.h
clang/include/clang/Sema/ParsedAttr.h
clang/lib/Basic/Attributes.cpp
clang/lib/Sema/ParsedAttr.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 545e7e9a2b47..f4a5db84aa9f 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -134,6 +134,11 @@ class AttributeCommonInfo {
   const IdentifierInfo *getScopeName() const { return ScopeName; }
   SourceLocation getScopeLoc() const { return ScopeLoc; }
 
+  /// Gets the normalized full name, which consists of both scope and name and
+  /// with surrounding underscores removed as appropriate (e.g.
+  /// __gnu__::__attr__ will be normalized to gnu::attr).
+  std::string getNormalizedFullName() const;
+
   bool isDeclspecAttribute() const { return SyntaxUsed == AS_Declspec; }
   bool isMicrosoftAttribute() const { return SyntaxUsed == AS_Microsoft; }
 

diff  --git a/clang/include/clang/Sema/ParsedAttr.h 
b/clang/include/clang/Sema/ParsedAttr.h
index d9d8585970d9..0e0d5cce6d3c 100644
--- a/clang/include/clang/Sema/ParsedAttr.h
+++ b/clang/include/clang/Sema/ParsedAttr.h
@@ -24,6 +24,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/Support/Allocator.h"
+#include "llvm/Support/Registry.h"
 #include "llvm/Support/VersionTuple.h"
 #include 
 #include 
@@ -37,6 +38,72 @@ class Decl;
 class Expr;
 class IdentifierInfo;
 class LangOptions;
+class ParsedAttr;
+class Sema;
+
+struct ParsedAttrInfo {
+  /// Corresponds to the Kind enum.
+  unsigned AttrKind : 16;
+  /// The number of required arguments of this attribute.
+  unsigned NumArgs : 4;
+  /// The number of optional arguments of this attributes.
+  unsigned OptArgs : 4;
+  /// True if the parsing does not match the semantic content.
+  unsigned HasCustomParsing : 1;
+  /// True if this attribute is only available for certain targets.
+  unsigned IsTargetSpecific : 1;
+  /// True if this attribute applies to types.
+  unsigned IsType : 1;
+  /// True if this attribute applies to statements.
+  unsigned IsStmt : 1;
+  /// True if this attribute has any spellings that are known to gcc.
+  unsigned IsKnownToGCC : 1;
+  /// True if this attribute is supported by #pragma clang attribute.
+  unsigned IsSupportedByPragmaAttribute : 1;
+  /// The syntaxes supported by this attribute and how they're spelled.
+  struct Spelling {
+AttributeCommonInfo::Syntax Syntax;
+std::string NormalizedFullName;
+  };
+  std::vector Spellings;
+
+  ParsedAttrInfo(AttributeCommonInfo::Kind AttrKind =
+ AttributeCommonInfo::UnknownAttribute)
+  : AttrKind(AttrKind), NumArgs(0), OptArgs(0), HasCustomParsing(0),
+IsTargetSpecific(0), IsType(0), IsStmt(0), IsKnownToGCC(0),
+IsSupportedByPragmaAttribute(0) {}
+
+  virtual ~ParsedAttrInfo() = default;
+
+  /// Check if this attribute appertains to D, and issue a diagnostic if not.
+  virtual bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr,
+const Decl *D) const {
+return true;
+  }
+  /// Check if this attribute is allowed by the language we are compiling, and
+  /// issue a diagnostic if not.
+  virtual bool diagLangOpts(Sema &S, const ParsedAttr &Attr) const {
+return true;
+  }
+  /// Check if this attribute is allowed when compiling for the given target.
+  virtual bool existsInTarget(const TargetInfo &Target) const {
+return true;
+  }
+  /// Convert the spelling index of Attr to a semantic spelling enum value.
+  virtual unsigned
+  spellingIndexToSemanticSpelling(const ParsedAttr &Attr) const {
+return UINT_MAX;
+  }
+  /// Populate Rules with the match rules of this attribute.
+  virtual void getPragmaAttributeMatchRules(
+  llvm::SmallVectorImpl> &Rules,
+  const LangOptions &LangOpts) const {
+  }
+
+  static const ParsedAttrInfo &get(const AttributeCommonInfo &A);
+};
+
+typedef llvm::Registry ParsedAttrInfoRegistry;
 
 /// Represents information about a change in availability for
 /// an enti

[clang] 2bb3fb0 - Handle PluginAttrInstances using ManagedStatic

2020-03-04 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2020-03-04T15:03:13Z
New Revision: 2bb3fb05e20e272790170e86fb76dac23a67f52c

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

LOG: Handle PluginAttrInstances using ManagedStatic

We need to make sure that PluginAttrInstances is deleted before shared libraries
are unloaded, because otherwise when deleting its contents we'll try to access
a virtual destructor which no longer exists.

As shared libraries are managed using ManagedStatic we can do this by also using
ManagedStatic for PluginAttrInstances as ManagedStatics are deleted in reverse
order of construction and we know that PluginAttrInstances will only be
accessed, and thus constructed, after shared libraries have been loaded.

Added: 


Modified: 
clang/lib/Sema/ParsedAttr.cpp

Removed: 




diff  --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index 45df8cf5a85c..fa7b59de3e31 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -19,6 +19,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/ManagedStatic.h"
 #include 
 #include 
 #include 
@@ -121,10 +122,11 @@ const ParsedAttrInfo &ParsedAttrInfo::get(const 
AttributeCommonInfo &A) {
 
   // Otherwise this may be an attribute defined by a plugin. First instantiate
   // all plugin attributes if we haven't already done so.
-  static std::list> PluginAttrInstances;
-  if (PluginAttrInstances.empty())
+  static llvm::ManagedStatic>>
+  PluginAttrInstances;
+  if (PluginAttrInstances->empty())
 for (auto It : ParsedAttrInfoRegistry::entries())
-  PluginAttrInstances.emplace_back(It.instantiate());
+  PluginAttrInstances->emplace_back(It.instantiate());
 
   // Search for a ParsedAttrInfo whose name and syntax match.
   std::string FullName = A.getNormalizedFullName();
@@ -132,7 +134,7 @@ const ParsedAttrInfo &ParsedAttrInfo::get(const 
AttributeCommonInfo &A) {
   if (SyntaxUsed == AttributeCommonInfo::AS_ContextSensitiveKeyword)
 SyntaxUsed = AttributeCommonInfo::AS_Keyword;
 
-  for (auto &Ptr : PluginAttrInstances)
+  for (auto &Ptr : *PluginAttrInstances)
 for (auto &S : Ptr->Spellings)
   if (S.Syntax == SyntaxUsed && S.NormalizedFullName == FullName)
 return *Ptr;



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


[clang] 72073fc - [Serialization] Place command line defines in the correct file

2023-03-20 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-03-20T17:36:01Z
New Revision: 72073fc95cd4793a853925ddc8cc3fb2118808a5

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

LOG: [Serialization] Place command line defines in the correct file

Fix several problems related to serialization causing command line
defines to be reported as being built-in defines:
 * When serializing the  and  files don't
   convert them into absolute paths.
 * When deserializing SM_SLOC_BUFFER_ENTRY we need to call
   setHasLineDirectives in the same way as we do for
   SM_SLOC_FILE_ENTRY.
 * When created suggested predefines based on the current command line
   options we need to add line markers in the same way that
   InitializePreprocessor does.
 * Adjust a place in clangd where it was implicitly relying on command
   line defines being treated as builtin.

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

Added: 
clang/test/PCH/macro-cmdline.c

Modified: 
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang/docs/ReleaseNotes.rst
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/PCH/ms-pch-macro.c

Removed: 




diff  --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 3179810b1b185..519aceec15a18 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -687,8 +687,10 @@ bool SymbolCollector::handleMacroOccurrence(const 
IdentifierInfo *Name,
 
   const auto &SM = PP->getSourceManager();
   auto DefLoc = MI->getDefinitionLoc();
-  // Also avoid storing predefined macros like __DBL_MIN__.
+  // Also avoid storing macros that aren't defined in any file, i.e. predefined
+  // macros like __DBL_MIN__ and those defined on the command line.
   if (SM.isWrittenInBuiltinFile(DefLoc) ||
+  SM.isWrittenInCommandLineFile(DefLoc) ||
   Name->getName() == "__GCC_HAVE_DWARF2_CFI_ASM")
 return true;
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 53001f651ea4b..78c57500568f9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -172,8 +172,8 @@ Improvements to Clang's diagnostics
 - Diagnostic notes and fix-its are now generated for ``ifunc``/``alias`` 
attributes
   which point to functions whose names are mangled.
 - Diagnostics relating to macros on the command line of a preprocessed assembly
-  file are now reported as coming from the file  instead of
-  .
+  file or precompiled header are now reported as coming from the file
+   instead of .
 - Clang constexpr evaluator now provides a more concise diagnostic when calling
   function pointer that is known to be null.
 - Clang now avoids duplicate warnings on unreachable ``[[fallthrough]];`` 
statements

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 0273fa1b839a5..6654df40010cb 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -654,6 +654,10 @@ static bool checkPreprocessorOptions(
   SmallVector ExistingMacroNames;
   collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames);
 
+  // Use a line marker to enter the  file, as the defines and
+  // undefines here will have come from the command line.
+  SuggestedPredefines += "# 1 \"\" 1\n";
+
   for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
 // Dig out the macro definition in the existing preprocessor options.
 StringRef MacroName = ExistingMacroNames[I];
@@ -713,6 +717,10 @@ static bool checkPreprocessorOptions(
 }
 return true;
   }
+
+  // Leave the  file and return to .
+  SuggestedPredefines += "# 1 \"\" 2\n";
+
   if (Validation == OptionValidateStrictMatches) {
 // If strict matches are requested, don't tolerate any extra defines in
 // the AST file that are missing on the command line.
@@ -1579,8 +1587,13 @@ bool ASTReader::ReadSLocEntry(int ID) {
 auto Buffer = ReadBuffer(SLocEntryCursor, Name);
 if (!Buffer)
   return true;
-SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
-   BaseOffset + Offset, IncludeLoc);
+FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
+BaseOffset + Offset, IncludeLoc);
+if (Record[3]) {
+  auto &FileInfo =
+  const_cast(SourceMgr.getSLocEntry(FID).getFile());
+  FileInfo.setHasLineDirectives();
+}
 break;
   }
 

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index f5691e99241c1..e8f390bc5b1dd 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Seriali

[clang] 128f7da - [Lex] Use line markers in preprocessed assembly predefines file

2023-03-07 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-03-07T16:20:43Z
New Revision: 128f7dac82ea4b996ddfd0db86edfdac4013b1da

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

LOG: [Lex] Use line markers in preprocessed assembly predefines file

GNU line marker directives are not recognised when preprocessing
assembly files, meaning they can't be used in the predefines file
meaning macros defined on the command line are reported as being
built-in.

Change this to permit line markers but only in the predefines file,
so we can correctly report command line macros as coming from the
command line.

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

Added: 
clang/test/Preprocessor/directives_asm.S
clang/test/Preprocessor/macro_redefined.S

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Lex/PPDirectives.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4bc2e54a85998..59c8c5c799f1a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -159,6 +159,9 @@ Improvements to Clang's diagnostics
   class if that class was first introduced with a forward declaration.
 - Diagnostic notes and fix-its are now generated for ``ifunc``/``alias`` 
attributes
   which point to functions whose names are mangled.
+- Diagnostics relating to macros on the command line of a preprocessed assembly
+  file are now reported as coming from the file  instead of
+  .
 
 Bug Fixes in This Version
 -

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 208c6a8db1598..ab00724af2fa9 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1317,11 +1317,10 @@ void clang::InitializePreprocessor(
   llvm::raw_string_ostream Predefines(PredefineBuffer);
   MacroBuilder Builder(Predefines);
 
-  // Emit line markers for various builtin sections of the file.  We don't do
-  // this in asm preprocessor mode, because "# 4" is not a line marker 
directive
-  // in this mode.
-  if (!PP.getLangOpts().AsmPreprocessor)
-Builder.append("# 1 \"\" 3");
+  // Emit line markers for various builtin sections of the file. The 3 here
+  // marks  as being a system header, which suppresses warnings when
+  // the same macro is defined multiple times.
+  Builder.append("# 1 \"\" 3");
 
   // Install things like __POWERPC__, __GNUC__, etc into the macro table.
   if (InitOpts.UsePredefines) {
@@ -1359,8 +1358,7 @@ void clang::InitializePreprocessor(
 
   // Add on the predefines from the driver.  Wrap in a #line directive to 
report
   // that they come from the command line.
-  if (!PP.getLangOpts().AsmPreprocessor)
-Builder.append("# 1 \"\" 1");
+  Builder.append("# 1 \"\" 1");
 
   // Process #define's and #undef's in the order they are given.
   for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i) {
@@ -1372,8 +1370,7 @@ void clang::InitializePreprocessor(
   }
 
   // Exit the command line and go back to  (2 is LC_LEAVE).
-  if (!PP.getLangOpts().AsmPreprocessor)
-Builder.append("# 1 \"\" 2");
+  Builder.append("# 1 \"\" 2");
 
   // If -imacros are specified, include them now.  These are processed before
   // any -include directives.

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 9e2392529ff53..bda9d0877612e 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1185,8 +1185,12 @@ void Preprocessor::HandleDirective(Token &Result) {
 CurPPLexer->getConditionalStackDepth() > 
0);
 return;
   case tok::numeric_constant:  // # 7  GNU line marker directive.
-if (getLangOpts().AsmPreprocessor)
-  break;  // # 4 is not a preprocessor directive in .S files.
+// In a .S file "# 4" may be a comment so don't treat it as a preprocessor
+// directive. However do permit it in the predefines file, as we use line
+// markers to mark the builtin macros as being in a system header.
+if (getLangOpts().AsmPreprocessor &&
+SourceMgr.getFileID(SavedHash.getLocation()) != getPredefinesFileID())
+  break;
 return HandleDigitDirective(Result);
   default:
 IdentifierInfo *II = Result.getIdentifierInfo();

diff  --git a/clang/test/Preprocessor/directives_asm.S 
b/clang/test/Preprocessor/directives_asm.S
new file mode 100644
index 0..55e71d621e341
--- /dev/null
+++ b/clang/test/Preprocessor/directives_asm.S
@@ -0,0 +1,25 @@
+// RUN: %clang -c %s -o /dev/null 2>&1 | FileCheck %s
+
+// Check that preprocessor directives are recognised as such, but lines 
starting
+// with a # that aren't directives are instead treated as comments.
+
+#define MACRO .wa

[clang] 9b28954 - Use explicit target in clang/test/Preprocessor/directives_asm.S

2023-03-07 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-03-07T18:06:41Z
New Revision: 9b2895469badad470dca186801fe025c52f5364c

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

LOG: Use explicit target in clang/test/Preprocessor/directives_asm.S

This prevents the test from failing when the default target doesn't
support the .warning directive.

Added: 


Modified: 
clang/test/Preprocessor/directives_asm.S

Removed: 




diff  --git a/clang/test/Preprocessor/directives_asm.S 
b/clang/test/Preprocessor/directives_asm.S
index 55e71d621e34..a384b911005f 100644
--- a/clang/test/Preprocessor/directives_asm.S
+++ b/clang/test/Preprocessor/directives_asm.S
@@ -1,4 +1,5 @@
-// RUN: %clang -c %s -o /dev/null 2>&1 | FileCheck %s
+// REQUIRES: x86-registered-target
+// RUN: %clang --target=i386-pc-linux -c %s -o /dev/null 2>&1 | FileCheck %s
 
 // Check that preprocessor directives are recognised as such, but lines 
starting
 // with a # that aren't directives are instead treated as comments.
@@ -6,7 +7,7 @@
 #define MACRO .warning "This is a macro"
 MACRO
 
-// CHECK: directives_asm.S:7:9: warning: This is a macro
+// CHECK: directives_asm.S:8:9: warning: This is a macro
 
 #not a preprocessing directive
 
@@ -16,7 +17,7 @@
 
 .warning "line number should not change"
 
-// CHECK: directives_asm.S:17:9: warning: line number should not change
+// CHECK: directives_asm.S:18:9: warning: line number should not change
 
 #line 100
 



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


[clang] 78bf8a0 - [clang] Don't define predefined macros multiple times

2023-05-24 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-05-24T17:28:41+01:00
New Revision: 78bf8a0a2212c1826ce2a9c0f98c73e9b9b16367

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

LOG: [clang] Don't define predefined macros multiple times

Fix several instances of macros being defined multiple times
in several targets. Most of these are just simple duplication in a
TargetInfo or OSTargetInfo of things already defined in
InitializePredefinedMacros or InitializeStandardPredefinedMacros,
but there are a few that aren't:
 * AArch64 defines a couple of feature macros for armv8.1a that are
   handled generically by getTargetDefines.
 * CSKY needs to take care when CPUName and ArchName are the same.
 * Many os/target combinations result in __ELF__ being defined twice.
   Instead define __ELF__ just once in InitPreprocessor based on
   the Triple, which already knows what the object format is based
   on os and target.

These changes shouldn't change the final result of which macros are
defined, with the exception of the changes to __ELF__ where if you
explicitly specify the object type in the triple then this affects
if __ELF__ is defined, e.g. --target=i686-windows-elf results in it
being defined where it wasn't before, but this is more accurate as an
ELF file is in fact generated.

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

Added: 
clang/test/Preprocessor/predefined-macros-no-warnings.c

Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/ARM.cpp
clang/lib/Basic/Targets/AVR.cpp
clang/lib/Basic/Targets/CSKY.cpp
clang/lib/Basic/Targets/Hexagon.cpp
clang/lib/Basic/Targets/Le64.cpp
clang/lib/Basic/Targets/MSP430.cpp
clang/lib/Basic/Targets/OSTargets.h
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/Basic/Targets/VE.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Preprocessor/init-ve.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 3840139d27434..ea9995fbe82ee 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -238,8 +238,6 @@ void AArch64TargetInfo::fillValidCPUList(
 void AArch64TargetInfo::getTargetDefinesARMV81A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_QRDMX", "1");
-  Builder.defineMacro("__ARM_FEATURE_ATOMICS", "1");
-  Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
 }
 
 void AArch64TargetInfo::getTargetDefinesARMV82A(const LangOptions &Opts,
@@ -335,16 +333,6 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   Builder.defineMacro("__aarch64__");
   // Inline assembly supports AArch64 flag outputs.
   Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
-  // For bare-metal.
-  if (getTriple().getOS() == llvm::Triple::UnknownOS &&
-  getTriple().isOSBinFormatELF())
-Builder.defineMacro("__ELF__");
-
-  // Target properties.
-  if (!getTriple().isOSWindows() && getTriple().isArch64Bit()) {
-Builder.defineMacro("_LP64");
-Builder.defineMacro("__LP64__");
-  }
 
   std::string CodeModel = getTargetOpts().CodeModel;
   if (CodeModel == "default")
@@ -1523,7 +1511,6 @@ void DarwinAArch64TargetInfo::getOSDefines(const 
LangOptions &Opts,
   else
 Builder.defineMacro("__ARM64_ARCH_8__");
   Builder.defineMacro("__ARM_NEON__");
-  Builder.defineMacro("__LITTLE_ENDIAN__");
   Builder.defineMacro("__REGISTER_PREFIX__", "");
   Builder.defineMacro("__arm64", "1");
   Builder.defineMacro("__arm64__", "1");

diff  --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 588357c83bfa8..6a57261c01789 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -711,10 +711,9 @@ void ARMTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   // For bare-metal none-eabi.
   if (getTriple().getOS() == llvm::Triple::UnknownOS &&
   (getTriple().getEnvironment() == llvm::Triple::EABI ||
-   getTriple().getEnvironment() == llvm::Triple::EABIHF)) {
-Builder.defineMacro("__ELF__");
-if (Opts.CPlusPlus)
-  Builder.defineMacro("_GNU_SOURCE");
+   getTriple().getEnvironment() == llvm::Triple::EABIHF) &&
+  Opts.CPlusPlus) {
+Builder.defineMacro("_GNU_SOURCE");
   }
 
   // Target properties.

diff  --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index 5c75bae2d8121..85ca4bc30c461 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -450,7 +450,6 @@ void AVRTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   Builder.defineMacro("AVR");
   Builder.defineMacro("__AVR");
   Builder.defineMacro("__AVR__");
-  Builder.defineMacro("__ELF__");
 
   if (ABI == "avrtiny")
  

[clang] 0123deb - [Lex] Warn when defining or undefining any builtin macro

2023-05-25 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-05-25T11:55:44+01:00
New Revision: 0123deb3a6f0a83095287f51b07c77b7b43ab847

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

LOG: [Lex] Warn when defining or undefining any builtin macro

Currently we warn when MI->isBuiltinMacro, but this is only true for
builtin macros that require processing when expanding. Checking
SourceMgr.isWrittenInBuiltinFile in addition to this will mean that
we catch all builtin macros, though we shouldn't warn on feature test
macros.

As part of doing this I've also moved the handling of undefining from
CheckMacroName to HandleUndefDirective, as it doesn't really make
sense to handle undefining in CheckMacroName but defining in
HandleDefineDirective. It would be nice to instead handle both in
CheckMacroName, but that isn't possible as the handling of defines
requires looking at what the name is being defined to.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Lex/PPDirectives.cpp
clang/test/Lexer/builtin_redef.c
clang/test/Preprocessor/macro-reserved.c
clang/test/Preprocessor/macro-reserved.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0075f94e344ee..6ee73aa3c96fe 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -305,6 +305,8 @@ Improvements to Clang's diagnostics
   (`#58601 `_)
 - Clang's `-Wshadow` warning now warns about shadowings by static local 
variables
   (`#62850: `_).
+- Clang now warns when any predefined macro is undefined or redefined, instead
+  of only some of them.
 
 Bug Fixes in This Version
 -

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 62e51e133b3af..2066c61748efa 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -109,52 +109,52 @@ enum PPElifDiag {
   PED_Elifndef
 };
 
+static bool isFeatureTestMacro(StringRef MacroName) {
+  // list from:
+  // * https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
+  // * 
https://docs.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt?view=msvc-160
+  // * man 7 feature_test_macros
+  // The list must be sorted for correct binary search.
+  static constexpr StringRef ReservedMacro[] = {
+  "_ATFILE_SOURCE",
+  "_BSD_SOURCE",
+  "_CRT_NONSTDC_NO_WARNINGS",
+  "_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES",
+  "_CRT_SECURE_NO_WARNINGS",
+  "_FILE_OFFSET_BITS",
+  "_FORTIFY_SOURCE",
+  "_GLIBCXX_ASSERTIONS",
+  "_GLIBCXX_CONCEPT_CHECKS",
+  "_GLIBCXX_DEBUG",
+  "_GLIBCXX_DEBUG_PEDANTIC",
+  "_GLIBCXX_PARALLEL",
+  "_GLIBCXX_PARALLEL_ASSERTIONS",
+  "_GLIBCXX_SANITIZE_VECTOR",
+  "_GLIBCXX_USE_CXX11_ABI",
+  "_GLIBCXX_USE_DEPRECATED",
+  "_GNU_SOURCE",
+  "_ISOC11_SOURCE",
+  "_ISOC95_SOURCE",
+  "_ISOC99_SOURCE",
+  "_LARGEFILE64_SOURCE",
+  "_POSIX_C_SOURCE",
+  "_REENTRANT",
+  "_SVID_SOURCE",
+  "_THREAD_SAFE",
+  "_XOPEN_SOURCE",
+  "_XOPEN_SOURCE_EXTENDED",
+  "__STDCPP_WANT_MATH_SPEC_FUNCS__",
+  "__STDC_FORMAT_MACROS",
+  };
+  return std::binary_search(std::begin(ReservedMacro), std::end(ReservedMacro),
+MacroName);
+}
+
 static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) {
   const LangOptions &Lang = PP.getLangOpts();
-  if (isReservedInAllContexts(II->isReserved(Lang))) {
-// list from:
-// - https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
-// - 
https://docs.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt?view=msvc-160
-// - man 7 feature_test_macros
-// The list must be sorted for correct binary search.
-static constexpr StringRef ReservedMacro[] = {
-"_ATFILE_SOURCE",
-"_BSD_SOURCE",
-"_CRT_NONSTDC_NO_WARNINGS",
-"_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES",
-"_CRT_SECURE_NO_WARNINGS",
-"_FILE_OFFSET_BITS",
-"_FORTIFY_SOURCE",
-"_GLIBCXX_ASSERTIONS",
-"_GLIBCXX_CONCEPT_CHECKS",
-"_GLIBCXX_DEBUG",
-"_GLIBCXX_DEBUG_PEDANTIC",
-"_GLIBCXX_PARALLEL",
-"_GLIBCXX_PARALLEL_ASSERTIONS",
-"_GLIBCXX_SANITIZE_VECTOR",
-"_GLIBCXX_USE_CXX11_ABI",
-"_GLIBCXX_USE_DEPRECATED",
-"_GNU_SOURCE",
-"_ISOC11_SOURCE",
-"_ISOC95_SOURCE",
-"_ISOC99_SOURCE",
-"_LARGEFILE64_SOURCE",
-"_POSIX_C_SOURCE",
-"_REENTRANT",
-"_SVID_SOURCE",
-"_THREAD_SAFE",
-"_XOPEN

[clang] 844e953 - [Lex] Only warn on defining or undefining language-defined builtins

2023-06-01 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-06-01T17:37:50+01:00
New Revision: 844e9534c6d99ddb6bada740839760fa24d17cb6

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

LOG: [Lex] Only warn on defining or undefining language-defined builtins

D144654 made it so that we warn on any defining or undefining of
builtin macros. However the C and C++ standards only forbid the
defining or undefining of macros defined in the language standard
itself, but clang defines more macros than those and warning on those
may not be helpful.

Resolve this by only warning if the builtin macro name is the name of
a macro defined by the language. This is done in a way that removes
some of the existing checks, as those were made redundant by
restricting the warning in this way.

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

Added: 
clang/test/Preprocessor/undef-x86.c

Modified: 
clang/lib/Lex/PPDirectives.cpp
clang/test/Preprocessor/macro-reserved.c

Removed: 




diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index e83da5c573871..f133a50dd2ab6 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -150,6 +150,30 @@ static bool isFeatureTestMacro(StringRef MacroName) {
 MacroName);
 }
 
+static bool isLanguageDefinedBuiltin(const SourceManager &SourceMgr,
+ const MacroInfo *MI,
+ const StringRef MacroName) {
+  // If this is a macro with special handling (like __LINE__) then it's 
language
+  // defined.
+  if (MI->isBuiltinMacro())
+return true;
+  // Builtin macros are defined in the builtin file
+  if (!SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc()))
+return false;
+  // C defines macros starting with __STDC, and C++ defines macros starting 
with
+  // __STDCPP
+  if (MacroName.startswith("__STDC"))
+return true;
+  // C++ defines the __cplusplus macro
+  if (MacroName == "__cplusplus")
+return true;
+  // C++ defines various feature-test macros starting with __cpp
+  if (MacroName.startswith("__cpp"))
+return true;
+  // Anything else isn't language-defined
+  return false;
+}
+
 static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) {
   const LangOptions &Lang = PP.getLangOpts();
   StringRef Text = II->getName();
@@ -3107,9 +3131,7 @@ void Preprocessor::HandleDefineDirective(
 
   // Warn if defining "__LINE__" and other builtins, per C99 6.10.8/4 and
   // C++ [cpp.predefined]p4, but allow it as an extension.
-  if (OtherMI->isBuiltinMacro() ||
-  (SourceMgr.isWrittenInBuiltinFile(OtherMI->getDefinitionLoc()) &&
-   !isFeatureTestMacro(MacroNameTok.getIdentifierInfo()->getName(
+  if (isLanguageDefinedBuiltin(SourceMgr, OtherMI, II->getName()))
 Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro);
   // Macros must be identical.  This means all tokens and whitespace
   // separation must be the same.  C99 6.10.3p2.
@@ -3190,11 +3212,8 @@ void Preprocessor::HandleUndefDirective() {
   Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
 
 // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4 and
-// C++ [cpp.predefined]p4, but allow it as an extension. Don't warn if this
-// is an Objective-C builtin macro though.
-if ((MI->isBuiltinMacro() ||
- SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc())) &&
-!(getLangOpts().ObjC && isObjCProtectedMacro(II)))
+// C++ [cpp.predefined]p4, but allow it as an extension.
+if (isLanguageDefinedBuiltin(SourceMgr, MI, II->getName()))
   Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
 
 if (MI->isWarnIfUnused())

diff  --git a/clang/test/Preprocessor/macro-reserved.c 
b/clang/test/Preprocessor/macro-reserved.c
index 14dbc9119943f..6026a9f60730e 100644
--- a/clang/test/Preprocessor/macro-reserved.c
+++ b/clang/test/Preprocessor/macro-reserved.c
@@ -7,6 +7,7 @@
 #define _HAVE_X 0
 #define X__Y
 #define __STDC__ 1 // expected-warning {{redefining builtin macro}}
+#define __clang__ 1
 
 #undef for
 #undef final
@@ -15,6 +16,12 @@
 #undef _HAVE_X
 #undef X__Y
 #undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
+#undef __INT32_TYPE__
+#undef __UINT32_TYPE__
+#undef __UINTPTR_TYPE__
+#undef __UINT64_TYPE__
+#undef __INT64_TYPE__
+#undef __OPTIMIZE__
 
 // allowlisted definitions
 #define while while

diff  --git a/clang/test/Preprocessor/undef-x86.c 
b/clang/test/Preprocessor/undef-x86.c
new file mode 100644
index 0..91f16d3aae3ab
--- /dev/null
+++ b/clang/test/Preprocessor/undef-x86.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple=i386-none-none -fsyntax-only -verify %s
+// RUN: %clang_cc1 -tri

[clang] 463fa25 - [clang][NFC] Adjust tests to not un/define predefined macros

2023-02-14 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-02-14T13:55:03Z
New Revision: 463fa25c34d6e569862a9b74b24db3aa5522d84b

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

LOG: [clang][NFC] Adjust tests to not un/define predefined macros

An upcoming patch will be making all defining or undefining of
predefined macros to be warning (currently only some give a warning).
In preparation for this adjust some tests that would emit a warning:
 * In thread-specifier.c the undefine is done to avoid a different
   warning, but we get that warning just because __thread and
   __private_extern__ are the wrong way around so we can just swap
   them.
 * There are a couple of objective-c tests that redefine IBAction to
   what it's already defined as, so we can just remove the define.

Added: 


Modified: 
clang/test/Sema/thread-specifier.c
clang/test/SemaObjC/method-attributes.m
clang/test/SemaObjC/super-dealloc-attribute.m

Removed: 




diff  --git a/clang/test/Sema/thread-specifier.c 
b/clang/test/Sema/thread-specifier.c
index af6dcd9cb8d90..66f1d0f26697a 100644
--- a/clang/test/Sema/thread-specifier.c
+++ b/clang/test/Sema/thread-specifier.c
@@ -6,11 +6,6 @@
 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern 
-verify=expected,thread-local -pedantic -x c++ %s -DC11 
-D__thread=_Thread_local -std=c++11 -Wno-deprecated
 // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern 
-verify=expected,thread-local -pedantic %s -std=c99 -D__thread=_Thread_local 
-DC99
 
-#ifdef __cplusplus
-// In C++, we define __private_extern__ to extern.
-#undef __private_extern__
-#endif
-
 __thread int t1; // thread-local-warning {{'_Thread_local' is a C11 extension}}
 __thread extern int t2; // thread-local-warning {{'_Thread_local' is a C11 
extension}}
 __thread static int t3; // thread-local-warning {{'_Thread_local' is a C11 
extension}}
@@ -19,7 +14,7 @@ __thread static int t3; // thread-local-warning 
{{'_Thread_local' is a C11 exten
 // expected-warning@-3 {{'__thread' before 'static'}}
 #endif
 
-__thread __private_extern__ int t4; // thread-local-warning {{'_Thread_local' 
is a C11 extension}}
+__private_extern__ __thread int t4; // thread-local-warning {{'_Thread_local' 
is a C11 extension}}
 struct t5 { __thread int x; }; // thread-local-warning {{'_Thread_local' is a 
C11 extension}}
 #ifdef __cplusplus
 // expected-error-re@-2 {{'{{__thread|_Thread_local|thread_local}}' is only 
allowed on variable declarations}}
@@ -47,7 +42,7 @@ int f(__thread int t7) { // expected-error {{' is only 
allowed on variable decla
 #endif
   extern __thread int t9; // thread-local-warning {{'_Thread_local' is a C11 
extension}}
   static __thread int t10; // thread-local-warning {{'_Thread_local' is a C11 
extension}}
-  __thread __private_extern__ int t11; // thread-local-warning 
{{'_Thread_local' is a C11 extension}}
+  __private_extern__ __thread int t11; // thread-local-warning 
{{'_Thread_local' is a C11 extension}}
 #if __cplusplus < 201103L
   __thread auto int t12a; // expected-error-re {{cannot combine with previous 
'{{__thread|_Thread_local}}' declaration specifier}} \
   // thread-local-warning {{'_Thread_local' is a C11 
extension}}

diff  --git a/clang/test/SemaObjC/method-attributes.m 
b/clang/test/SemaObjC/method-attributes.m
index 110e6811e0f8a..14e192637855d 100644
--- a/clang/test/SemaObjC/method-attributes.m
+++ b/clang/test/SemaObjC/method-attributes.m
@@ -37,7 +37,6 @@ - (void) dep __attribute__((deprecated)) { } // OK private 
methodn
 
 
 // rdar://10529259
-#define IBAction void)__attribute__((ibaction)
 
 @interface Foo 
 - (void)doSomething1:(id)sender;

diff  --git a/clang/test/SemaObjC/super-dealloc-attribute.m 
b/clang/test/SemaObjC/super-dealloc-attribute.m
index ecab109d3089e..37429cde0543e 100644
--- a/clang/test/SemaObjC/super-dealloc-attribute.m
+++ b/clang/test/SemaObjC/super-dealloc-attribute.m
@@ -87,7 +87,6 @@ + (void)registerClass:(id)name {
 @end
 
 // rdar://14251387
-#define IBAction void)__attribute__((ibaction)
 
 @interface UIViewController @end
 



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


[clang] 25d23b1 - [Clang][NFC] Remove pointless defines from test command lines

2023-02-23 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-02-23T16:18:24Z
New Revision: 25d23b1970ea023d83d462402fd43038b41c13a3

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

LOG: [Clang][NFC] Remove pointless defines from test command lines

A few tests use -D on the command line to define macros that are
already predefined. Remove these pointless defines, as an upcoming
patch will cause this to be a warning.

Added: 


Modified: 
clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilerw-bfloat.c
clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilewr-bfloat.c
clang/test/Rewriter/objc-modern-fast-enumeration.mm

Removed: 




diff  --git 
a/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilerw-bfloat.c 
b/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilerw-bfloat.c
index a775a13c7bb5f..78e47e07d2225 100644
--- a/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilerw-bfloat.c
+++ b/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilerw-bfloat.c
@@ -1,8 +1,8 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -triple aarch64-none-linux-gnu 
-target-feature +sve2 -target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o 
- %s | FileCheck %s
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -triple aarch64-none-linux-gnu 
-target-feature +sve2 -target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o 
- -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -DSVE_OVERLOADED_FORMS -triple 
aarch64-none-linux-gnu -target-feature +sve2 -target-feature +bf16 -S -O1 
-Werror -Wall -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -DSVE_OVERLOADED_FORMS -triple 
aarch64-none-linux-gnu -target-feature +sve2 -target-feature +bf16 -S -O1 
-Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2 
-target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2 
-target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2 -target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o 
- %s | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2 -target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o 
- -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
 
 // REQUIRES: aarch64-registered-target
 

diff  --git 
a/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilewr-bfloat.c 
b/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilewr-bfloat.c
index 3c59b2c9f3538..d7969f3fd6d85 100644
--- a/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilewr-bfloat.c
+++ b/clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_whilewr-bfloat.c
@@ -1,8 +1,8 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -triple aarch64-none-linux-gnu 
-target-feature +sve2 -target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o 
- %s | FileCheck %s
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -triple aarch64-none-linux-gnu 
-target-feature +sve2 -target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o 
- -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -DSVE_OVERLOADED_FORMS -triple 
aarch64-none-linux-gnu -target-feature +sve2 -target-feature +bf16 -S -O1 
-Werror -Wall -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -D__ARM_FEATURE_SVE -D__ARM_FEATURE_SVE2 
-D__ARM_FEATURE_BF16_SCALAR_ARITHMETIC -DSVE_OVERLOADED_FORMS -triple 
aarch64-none-linux-gnu -target-feature +sve2 -target-feature +bf16 -S -O1 
-Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2 
-target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2 
-target-feature +bf16 -S -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-g

[clang] 22e3f58 - [Lex] Warn when defining or undefining any builtin macro

2023-05-17 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-05-17T11:49:49+01:00
New Revision: 22e3f587fd1ff97185014cb1ba723579ed2150d3

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

LOG: [Lex] Warn when defining or undefining any builtin macro

Currently we warn when MI->isBuiltinMacro, but this is only true for
builtin macros that require processing when expanding. Checking
SourceMgr.isWrittenInBuiltinFile in addition to this will mean that
we catch all builtin macros, though we shouldn't warn on feature test
macros.

As part of doing this I've also moved the handling of undefining from
CheckMacroName to HandleUndefDirective, as it doesn't really make
sense to handle undefining in CheckMacroName but defining in
HandleDefineDirective. It would be nice to instead handle both in
CheckMacroName, but that isn't possible as the handling of defines
requires looking at what the name is being defined to.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Lex/PPDirectives.cpp
clang/test/Lexer/builtin_redef.c
clang/test/Preprocessor/macro-reserved.c
clang/test/Preprocessor/macro-reserved.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 77990f330e4bb..2f13ef96ba03f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -283,6 +283,8 @@ Improvements to Clang's diagnostics
 - Clang constexpr evaluator now prints subobject's name instead of its type in 
notes
   when a constexpr variable has uninitialized subobjects after its constructor 
call.
   (`#58601 `_)
+- Clang now warns when any predefined macro is undefined or redefined, instead
+  of only some of them.
 
 Bug Fixes in This Version
 -

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 62e51e133b3af..2066c61748efa 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -109,52 +109,52 @@ enum PPElifDiag {
   PED_Elifndef
 };
 
+static bool isFeatureTestMacro(StringRef MacroName) {
+  // list from:
+  // * https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
+  // * 
https://docs.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt?view=msvc-160
+  // * man 7 feature_test_macros
+  // The list must be sorted for correct binary search.
+  static constexpr StringRef ReservedMacro[] = {
+  "_ATFILE_SOURCE",
+  "_BSD_SOURCE",
+  "_CRT_NONSTDC_NO_WARNINGS",
+  "_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES",
+  "_CRT_SECURE_NO_WARNINGS",
+  "_FILE_OFFSET_BITS",
+  "_FORTIFY_SOURCE",
+  "_GLIBCXX_ASSERTIONS",
+  "_GLIBCXX_CONCEPT_CHECKS",
+  "_GLIBCXX_DEBUG",
+  "_GLIBCXX_DEBUG_PEDANTIC",
+  "_GLIBCXX_PARALLEL",
+  "_GLIBCXX_PARALLEL_ASSERTIONS",
+  "_GLIBCXX_SANITIZE_VECTOR",
+  "_GLIBCXX_USE_CXX11_ABI",
+  "_GLIBCXX_USE_DEPRECATED",
+  "_GNU_SOURCE",
+  "_ISOC11_SOURCE",
+  "_ISOC95_SOURCE",
+  "_ISOC99_SOURCE",
+  "_LARGEFILE64_SOURCE",
+  "_POSIX_C_SOURCE",
+  "_REENTRANT",
+  "_SVID_SOURCE",
+  "_THREAD_SAFE",
+  "_XOPEN_SOURCE",
+  "_XOPEN_SOURCE_EXTENDED",
+  "__STDCPP_WANT_MATH_SPEC_FUNCS__",
+  "__STDC_FORMAT_MACROS",
+  };
+  return std::binary_search(std::begin(ReservedMacro), std::end(ReservedMacro),
+MacroName);
+}
+
 static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) {
   const LangOptions &Lang = PP.getLangOpts();
-  if (isReservedInAllContexts(II->isReserved(Lang))) {
-// list from:
-// - https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
-// - 
https://docs.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt?view=msvc-160
-// - man 7 feature_test_macros
-// The list must be sorted for correct binary search.
-static constexpr StringRef ReservedMacro[] = {
-"_ATFILE_SOURCE",
-"_BSD_SOURCE",
-"_CRT_NONSTDC_NO_WARNINGS",
-"_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES",
-"_CRT_SECURE_NO_WARNINGS",
-"_FILE_OFFSET_BITS",
-"_FORTIFY_SOURCE",
-"_GLIBCXX_ASSERTIONS",
-"_GLIBCXX_CONCEPT_CHECKS",
-"_GLIBCXX_DEBUG",
-"_GLIBCXX_DEBUG_PEDANTIC",
-"_GLIBCXX_PARALLEL",
-"_GLIBCXX_PARALLEL_ASSERTIONS",
-"_GLIBCXX_SANITIZE_VECTOR",
-"_GLIBCXX_USE_CXX11_ABI",
-"_GLIBCXX_USE_DEPRECATED",
-"_GNU_SOURCE",
-"_ISOC11_SOURCE",
-"_ISOC95_SOURCE",
-"_ISOC99_SOURCE",
-"_LARGEFILE64_SOURCE",
-"_POSIX_C_SOURCE",
-"_REENTRANT",
-"_SVID_SOURCE",
-"_THREAD_SA

[clang] e55d52c - [AArch64] Don't redefine _LP64 and __LP64__

2023-05-17 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-05-17T15:21:20+01:00
New Revision: e55d52cd34fb7a6a6617639d147b9d0abaceeeab

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

LOG: [AArch64] Don't redefine _LP64 and __LP64__

Don't define these macros in AArch64TargetInfo::getTargetDefines, as
they're already defined in InitializePredefinedMacros and the
redefinition causes unwanted warnings with -Wsystem-headers.

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 3840139d27434..d661f25ea00f2 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -340,12 +340,6 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   getTriple().isOSBinFormatELF())
 Builder.defineMacro("__ELF__");
 
-  // Target properties.
-  if (!getTriple().isOSWindows() && getTriple().isArch64Bit()) {
-Builder.defineMacro("_LP64");
-Builder.defineMacro("__LP64__");
-  }
-
   std::string CodeModel = getTargetOpts().CodeModel;
   if (CodeModel == "default")
 CodeModel = "small";



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


[clang-tools-extra] 524ed4b - [Serialization] Place command line defines in the correct file

2023-04-24 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-04-24T14:07:41+01:00
New Revision: 524ed4b1ba518d5dd5d67fb9593e0864b0e664a4

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

LOG: [Serialization] Place command line defines in the correct file

Fix several problems related to serialization causing command line
defines to be reported as being built-in defines:
 * When serializing the  and  files don't
   convert them into absolute paths.
 * When deserializing SM_SLOC_BUFFER_ENTRY we need to call
   setHasLineDirectives in the same way as we do for
   SM_SLOC_FILE_ENTRY.
 * When created suggested predefines based on the current command line
   options we need to add line markers in the same way that
   InitializePreprocessor does.
 * Adjust a place in clangd where it was implicitly relying on command
   line defines being treated as builtin.

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

Added: 
clang/test/PCH/macro-cmdline.c

Modified: 
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang/docs/ReleaseNotes.rst
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/PCH/ms-pch-macro.c

Removed: 




diff  --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 5c8112e60b224..a2f8cd2a0cdaf 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -687,8 +687,10 @@ bool SymbolCollector::handleMacroOccurrence(const 
IdentifierInfo *Name,
 
   const auto &SM = PP->getSourceManager();
   auto DefLoc = MI->getDefinitionLoc();
-  // Also avoid storing predefined macros like __DBL_MIN__.
+  // Also avoid storing macros that aren't defined in any file, i.e. predefined
+  // macros like __DBL_MIN__ and those defined on the command line.
   if (SM.isWrittenInBuiltinFile(DefLoc) ||
+  SM.isWrittenInCommandLineFile(DefLoc) ||
   Name->getName() == "__GCC_HAVE_DWARF2_CFI_ASM")
 return true;
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7beae03247796..a1bb925e8ae24 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -207,8 +207,8 @@ Improvements to Clang's diagnostics
 - Diagnostic notes and fix-its are now generated for ``ifunc``/``alias`` 
attributes
   which point to functions whose names are mangled.
 - Diagnostics relating to macros on the command line of a preprocessed assembly
-  file are now reported as coming from the file  instead of
-  .
+  file or precompiled header are now reported as coming from the file
+   instead of .
 - Clang constexpr evaluator now provides a more concise diagnostic when calling
   function pointer that is known to be null.
 - Clang now avoids duplicate warnings on unreachable ``[[fallthrough]];`` 
statements

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index b27304deb33c9..098ce5314ab17 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -654,6 +654,10 @@ static bool checkPreprocessorOptions(
   SmallVector ExistingMacroNames;
   collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames);
 
+  // Use a line marker to enter the  file, as the defines and
+  // undefines here will have come from the command line.
+  SuggestedPredefines += "# 1 \"\" 1\n";
+
   for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
 // Dig out the macro definition in the existing preprocessor options.
 StringRef MacroName = ExistingMacroNames[I];
@@ -713,6 +717,10 @@ static bool checkPreprocessorOptions(
 }
 return true;
   }
+
+  // Leave the  file and return to .
+  SuggestedPredefines += "# 1 \"\" 2\n";
+
   if (Validation == OptionValidateStrictMatches) {
 // If strict matches are requested, don't tolerate any extra defines in
 // the AST file that are missing on the command line.
@@ -1579,8 +1587,13 @@ bool ASTReader::ReadSLocEntry(int ID) {
 auto Buffer = ReadBuffer(SLocEntryCursor, Name);
 if (!Buffer)
   return true;
-SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
-   BaseOffset + Offset, IncludeLoc);
+FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
+BaseOffset + Offset, IncludeLoc);
+if (Record[3]) {
+  auto &FileInfo =
+  const_cast(SourceMgr.getSLocEntry(FID).getFile());
+  FileInfo.setHasLineDirectives();
+}
 break;
   }
 

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 7c62aac9901f1..3d738149febcb 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Se

[clang] 78086af - [Serialization] Correctly handle special files when deserializing

2023-04-24 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-04-24T15:35:37+01:00
New Revision: 78086af43ade0c91546a2688bb6e97906eee6c2a

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

LOG: [Serialization] Correctly handle special files when deserializing

This was supposed to be part of my previous commit, but I accidentally
pushed an old version of the patch.

Added: 


Modified: 
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 098ce5314ab1..723dd99ffada 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -2523,7 +2523,8 @@ void ASTReader::ResolveImportedPath(ModuleFile &M, 
std::string &Filename) {
 }
 
 void ASTReader::ResolveImportedPath(std::string &Filename, StringRef Prefix) {
-  if (Filename.empty() || llvm::sys::path::is_absolute(Filename))
+  if (Filename.empty() || llvm::sys::path::is_absolute(Filename) ||
+  Filename == "" || Filename == "")
 return;
 
   SmallString<128> Buffer;



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


Re: [PATCH] D23662: [libclang] Control whether crash recovery is enabled/disabled using function argument.

2016-08-18 Thread John Brawn via cfe-commits
john.brawn added a subscriber: john.brawn.
john.brawn added a comment.

> When my Java application calls clang_createIndex() with crash recovery 
> enabled it replaces the JVM's segfault handler with 
> CrashRecoverySignalHandler and now this handler gets all the segfault signals 
> that would have normally been sent to the JVM and when it does and tries to 
> restore the previous segfault hanlder (which is the JVMs) it doesn't install 
> the right one because the JVM ends up crashing and producing a core dump.


Surely the fix then is to make sure CrashRecoveryContext::Disable //does// 
reinstall the right signal handler?

> The only way to correctly solve my problem is to set the environment variable 
> 'LIBCLANG_DISABLE_CRASH_RECOVERY' but I find this to not be a very nice way 
> to control the program behaviour


Why not? Also I notice that using environment variables to control behaviour is 
used in a bunch of places in libclang so you're introducing some inconsistency 
here.


Repository:
  rL LLVM

https://reviews.llvm.org/D23662



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


r297837 - [Driver] Restructure handling of -ffast-math and similar options

2017-03-15 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Wed Mar 15 09:03:32 2017
New Revision: 297837

URL: http://llvm.org/viewvc/llvm-project?rev=297837&view=rev
Log:
[Driver] Restructure handling of -ffast-math and similar options

The way -ffast-math and the various related options to tweak floating-point
handling are handled is inflexible and rather confusing. This patch restructures
things so that we go through the options adjusting our idea of what's enabled as
we go, instead of trying to figure each individual thing out by working
backwards from the end, as this makes the behaviour of each individual option
more clear.

Doing it this way also means we get gcc-compatible behaviour for when the
__FAST_MATH__ and __FINITE_MATH_ONLY__ macros are defined, as they should depend
on the final set of features that are enabled and not just on -ffast-math and
-ffinite-math-only specifically.

Differential Revision: http://reviews.llvm.org/D30582

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/fast-math.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=297837&r1=297836&r2=297837&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Mar 15 09:03:32 2017
@@ -2301,98 +2301,129 @@ void Clang::ConstructJob(Compilation &C,
   if (Args.hasArg(options::OPT_fsplit_stack))
 CmdArgs.push_back("-split-stacks");
 
-  // If -Ofast is the optimization level, then -ffast-math should be enabled.
-  // This alias option is being used to simplify the getLastArg logic.
-  OptSpecifier FastMathAliasOption =
-  OFastEnabled ? options::OPT_Ofast : options::OPT_ffast_math;
-
   // Handle various floating point optimization flags, mapping them to the
-  // appropriate LLVM code generation flags. The pattern for all of these is to
-  // default off the codegen optimizations, and if any flag enables them and no
-  // flag disables them after the flag enabling them, enable the codegen
-  // optimization. This is complicated by several "umbrella" flags.
-  if (Arg *A = Args.getLastArg(
-  options::OPT_ffast_math, FastMathAliasOption,
-  options::OPT_fno_fast_math, options::OPT_ffinite_math_only,
-  options::OPT_fno_finite_math_only, options::OPT_fhonor_infinities,
-  options::OPT_fno_honor_infinities))
-if (A->getOption().getID() != options::OPT_fno_fast_math &&
-A->getOption().getID() != options::OPT_fno_finite_math_only &&
-A->getOption().getID() != options::OPT_fhonor_infinities)
-  CmdArgs.push_back("-menable-no-infs");
-  if (Arg *A = Args.getLastArg(
-  options::OPT_ffast_math, FastMathAliasOption,
-  options::OPT_fno_fast_math, options::OPT_ffinite_math_only,
-  options::OPT_fno_finite_math_only, options::OPT_fhonor_nans,
-  options::OPT_fno_honor_nans))
-if (A->getOption().getID() != options::OPT_fno_fast_math &&
-A->getOption().getID() != options::OPT_fno_finite_math_only &&
-A->getOption().getID() != options::OPT_fhonor_nans)
-  CmdArgs.push_back("-menable-no-nans");
-
+  // appropriate LLVM code generation flags. This is complicated by several
+  // "umbrella" flags, so we do this by stepping through the flags 
incrementally
+  // adjusting what we think is enabled/disabled, then at the end settting the
+  // LLVM flags based on the final state.
+  bool HonorInfs = true;
+  bool HonorNans = true;
   // -fmath-errno is the default on some platforms, e.g. BSD-derived OSes.
   bool MathErrno = getToolChain().IsMathErrnoDefault();
-  if (Arg *A =
-  Args.getLastArg(options::OPT_ffast_math, FastMathAliasOption,
-  options::OPT_fno_fast_math, options::OPT_fmath_errno,
-  options::OPT_fno_math_errno)) {
-// Turning on -ffast_math (with either flag) removes the need for 
MathErrno.
-// However, turning *off* -ffast_math merely restores the toolchain default
-// (which may be false).
-if (A->getOption().getID() == options::OPT_fno_math_errno ||
-A->getOption().getID() == options::OPT_ffast_math ||
-A->getOption().getID() == options::OPT_Ofast)
-  MathErrno = false;
-else if (A->getOption().getID() == options::OPT_fmath_errno)
-  MathErrno = true;
-  }
-  if (MathErrno)
-CmdArgs.push_back("-fmath-errno");
-
-  // There are several flags which require disabling very specific
-  // optimizations. Any of these being disabled forces us to turn off the
-  // entire set of LLVM optimizations, so collect them through all the flag
-  // madness.
   bool AssociativeMath = false;
-  if (Arg *A = Args.getLastArg(
-  options::OPT_ffast_math, FastMathAliasOption,
-  options::OPT_fno_fast_math, options::OPT_funsafe_math_optimizations,
-  options::OPT_fno_unsafe_math_optimiz

RE: Potential self-hosting failure

2017-05-16 Thread John Brawn via cfe-commits
I've managed to reproduce this, but no luck so far in figuring out
what exactly is going wrong. I'll continue looking into it tomorrow.

John

> -Original Message-
> From: Renato Golin [mailto:renato.go...@linaro.org]
> Sent: 16 May 2017 12:18
> To: John Brawn
> Cc: James Molloy; Diana Picus; LLVM Commits; Clang Commits
> Subject: Potential self-hosting failure
> 
> Hi John,
> 
> It seems the LEApcrel patches have broken our self-hosting:
> 
> http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15-full-
> sh/builds/1550
> 
> http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost-
> neon/builds/1349
> 
> http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-
> selfhost/builds/1845
> 
> The range in each is big, but the overlapping range is actually just
> 303051 ~ 303054.
> 
> Since two of those patches are yours and since this is a self-hosting
> issue, my money is on your patches, not the Dwarf one. :)
> 
> The tests don't help much, unfortunately.
> 
> I have had problems like this in Clang, where the code assumed some
> ABI that wasn't as generic as initially assumed, and changes in
> relocation are normally the ones that expose those wrong assumptions.
> 
> Can you have a look on your side, while we're testing on our side, too?
> 
> Thanks!
> --renato
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


RE: Potential self-hosting failure

2017-05-17 Thread John Brawn via cfe-commits
I've now tracked this down to a problem with LEApcrel rematerialization
where the rematerialized LEApcrel can address a different literal pool
to the original. I've raised https://bugs.llvm.org/show_bug.cgi?id=33074

This is actually a bug that already existed before my patches, but because
my patches made LEApcrel be rematerialized in more situations they made it
more likely to trigger the bug. I'll continue looking into this to see if
I can figure out how to fix it.

John

> -Original Message-
> From: Renato Golin [mailto:renato.go...@linaro.org]
> Sent: 16 May 2017 19:13
> To: John Brawn
> Cc: James Molloy; Diana Picus; LLVM Commits; Clang Commits; nd
> Subject: Re: Potential self-hosting failure
> 
> On 16 May 2017 at 18:26, John Brawn  wrote:
> > I've managed to reproduce this, but no luck so far in figuring out
> > what exactly is going wrong. I'll continue looking into it tomorrow.
> 
> Thanks John,
> 
> I have reverted it for now on r303193, to get the bots green.
> 
> cheers,
> --renato
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D12903: Allow the -load option in the driver and pass it through to -cc1

2015-09-16 Thread John Brawn via cfe-commits
john.brawn created this revision.
john.brawn added a subscriber: cfe-commits.
john.brawn set the repository for this revision to rL LLVM.

Currently -load is only allowed in the -cc1 command, which makes it rather 
awkward to use. Allowing it in the driver and passing it through to -cc1 is 
much more convenient.

Repository:
  rL LLVM

http://reviews.llvm.org/D12903

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  lib/Driver/Tools.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5035,6 +5035,8 @@
   Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);
   // Forward -fparse-all-comments to -cc1.
   Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments);
+  // Forward -load to -cc1
+  Args.AddAllArgs(CmdArgs, options::OPT_load);
 
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1192,6 +1192,8 @@
 def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>;
 def lazy__framework : Separate<["-"], "lazy_framework">, Flags<[LinkerInput]>;
 def lazy__library : Separate<["-"], "lazy_library">, Flags<[LinkerInput]>;
+def load : Separate<["-"], "load">, Flags<[DriverOption,CC1Option]>, 
MetaVarName<"">,
+  HelpText<"Load the named plugin (dynamic shared object)">;
 def mlittle_endian : Flag<["-"], "mlittle-endian">, Flags<[DriverOption]>;
 def EL : Flag<["-"], "EL">, Alias;
 def mbig_endian : Flag<["-"], "mbig-endian">, Flags<[DriverOption]>;
Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -343,8 +343,6 @@
   HelpText<"Include brief documentation comments in code-completion results.">;
 def disable_free : Flag<["-"], "disable-free">,
   HelpText<"Disable freeing of memory on exit">;
-def load : Separate<["-"], "load">, MetaVarName<"">,
-  HelpText<"Load the named plugin (dynamic shared object)">;
 def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
   HelpText<"Use the named plugin action instead of the default action (use 
\"help\" to list available options)">;
 def plugin_arg : JoinedAndSeparate<["-"], "plugin-arg-">,


Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5035,6 +5035,8 @@
   Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);
   // Forward -fparse-all-comments to -cc1.
   Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments);
+  // Forward -load to -cc1
+  Args.AddAllArgs(CmdArgs, options::OPT_load);
 
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1192,6 +1192,8 @@
 def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>;
 def lazy__framework : Separate<["-"], "lazy_framework">, Flags<[LinkerInput]>;
 def lazy__library : Separate<["-"], "lazy_library">, Flags<[LinkerInput]>;
+def load : Separate<["-"], "load">, Flags<[DriverOption,CC1Option]>, MetaVarName<"">,
+  HelpText<"Load the named plugin (dynamic shared object)">;
 def mlittle_endian : Flag<["-"], "mlittle-endian">, Flags<[DriverOption]>;
 def EL : Flag<["-"], "EL">, Alias;
 def mbig_endian : Flag<["-"], "mbig-endian">, Flags<[DriverOption]>;
Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -343,8 +343,6 @@
   HelpText<"Include brief documentation comments in code-completion results.">;
 def disable_free : Flag<["-"], "disable-free">,
   HelpText<"Disable freeing of memory on exit">;
-def load : Separate<["-"], "load">, MetaVarName<"">,
-  HelpText<"Load the named plugin (dynamic shared object)">;
 def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
   HelpText<"Use the named plugin action instead of the default action (use \"help\" to list available options)">;
 def plugin_arg : JoinedAndSeparate<["-"], "plugin-arg-">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12903: Allow the -load option in the driver and pass it through to -cc1

2015-09-16 Thread John Brawn via cfe-commits
john.brawn added a comment.

In http://reviews.llvm.org/D12903#247055, @rengolin wrote:

> Hi John,
>
> Can you expand a bit more on why you need this, what's the use case, and 
> hopefully attach a test for them?


The use-case is loading llvm plugins that add optimization passes via the 
PassManagerBuilder::addGlobalExtension mechanism (i.e. just loading the plugin 
is enough and you don't have to add anything extra to the command-line). 
Currently you have to do clang -Xclang -load -Xclang plugin.so, and it would be 
nicer to be able to do clang -load plugin.so.

I'm not sure how to best add a test for this. Maybe I should add another pass 
to llvm that's built as a plugin like llvm/lib/Transforms/Hello but that uses 
PassManagerBuilder::addGlobalExtension and have a clang test that runs that?


Repository:
  rL LLVM

http://reviews.llvm.org/D12903



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


Re: [PATCH] D12903: Allow the -load option in the driver and pass it through to -cc1

2015-09-17 Thread John Brawn via cfe-commits
john.brawn updated this revision to Diff 34977.
john.brawn added a comment.

Add a test.


Repository:
  rL LLVM

http://reviews.llvm.org/D12903

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  lib/Driver/Tools.cpp
  test/Driver/load.c

Index: test/Driver/load.c
===
--- /dev/null
+++ test/Driver/load.c
@@ -0,0 +1,7 @@
+// Check that all -load arguments are passed through to the -cc1 command
+
+// RUN: %clang -c %s -load foo.so -### 2>&1  | FileCheck %s 
--check-prefix=CHECK1
+// RUN: %clang -c %s -load foo.so -load bar.so -### 2>&1 | FileCheck %s 
--check-prefix=CHECK2
+
+// CHECK1: "-load" "foo.so"
+// CHECK2: "-load" "foo.so" "-load" "bar.so"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5035,6 +5035,8 @@
   Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);
   // Forward -fparse-all-comments to -cc1.
   Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments);
+  // Forward -load to -cc1
+  Args.AddAllArgs(CmdArgs, options::OPT_load);
 
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1192,6 +1192,8 @@
 def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>;
 def lazy__framework : Separate<["-"], "lazy_framework">, Flags<[LinkerInput]>;
 def lazy__library : Separate<["-"], "lazy_library">, Flags<[LinkerInput]>;
+def load : Separate<["-"], "load">, Flags<[DriverOption,CC1Option]>, 
MetaVarName<"">,
+  HelpText<"Load the named plugin (dynamic shared object)">;
 def mlittle_endian : Flag<["-"], "mlittle-endian">, Flags<[DriverOption]>;
 def EL : Flag<["-"], "EL">, Alias;
 def mbig_endian : Flag<["-"], "mbig-endian">, Flags<[DriverOption]>;
Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -343,8 +343,6 @@
   HelpText<"Include brief documentation comments in code-completion results.">;
 def disable_free : Flag<["-"], "disable-free">,
   HelpText<"Disable freeing of memory on exit">;
-def load : Separate<["-"], "load">, MetaVarName<"">,
-  HelpText<"Load the named plugin (dynamic shared object)">;
 def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
   HelpText<"Use the named plugin action instead of the default action (use 
\"help\" to list available options)">;
 def plugin_arg : JoinedAndSeparate<["-"], "plugin-arg-">,


Index: test/Driver/load.c
===
--- /dev/null
+++ test/Driver/load.c
@@ -0,0 +1,7 @@
+// Check that all -load arguments are passed through to the -cc1 command
+
+// RUN: %clang -c %s -load foo.so -### 2>&1  | FileCheck %s --check-prefix=CHECK1
+// RUN: %clang -c %s -load foo.so -load bar.so -### 2>&1 | FileCheck %s --check-prefix=CHECK2
+
+// CHECK1: "-load" "foo.so"
+// CHECK2: "-load" "foo.so" "-load" "bar.so"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5035,6 +5035,8 @@
   Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);
   // Forward -fparse-all-comments to -cc1.
   Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments);
+  // Forward -load to -cc1
+  Args.AddAllArgs(CmdArgs, options::OPT_load);
 
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1192,6 +1192,8 @@
 def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>;
 def lazy__framework : Separate<["-"], "lazy_framework">, Flags<[LinkerInput]>;
 def lazy__library : Separate<["-"], "lazy_library">, Flags<[LinkerInput]>;
+def load : Separate<["-"], "load">, Flags<[DriverOption,CC1Option]>, MetaVarName<"">,
+  HelpText<"Load the named plugin (dynamic shared object)">;
 def mlittle_endian : Flag<["-"], "mlittle-endian">, Flags<[DriverOption]>;
 def EL : Flag<["-"], "EL">, Alias;
 def mbig_endian : Flag<["-"], "mbig-endian">, Flags<[DriverOption]>;
Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -343,8 +343,6 @@
   HelpText<"Include brief documentation comments in code-completion results.">;
 def disable_free : Flag<["-"], "disable-free">,
   HelpText<"Disable freeing of memory on exit">;
-def load : Separate<["-"], "load">, MetaVarName<"">,
-  HelpTex

Re: [PATCH] D12903: Allow the -load option in the driver and pass it through to -cc1

2015-09-17 Thread John Brawn via cfe-commits
john.brawn added a comment.

In http://reviews.llvm.org/D12903#247934, @compnerd wrote:

> While I agree that this makes the option much nicer to use, it collides with 
> the -l flag.  Since it was an internal only option until this point, we 
> should rename it before exposing it at the driver level.


Yes, you're right. GCC uses -fplugin=name.so for their plugin interface, which 
seems reasonable so I'll go with that to avoid having to think up something 
myself.


Repository:
  rL LLVM

http://reviews.llvm.org/D12903



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


Re: [PATCH] D12903: Add -fplugin=name.so option to the driver

2015-09-17 Thread John Brawn via cfe-commits
john.brawn retitled this revision from "Allow the -load option in the driver 
and pass it through to -cc1" to "Add -fplugin=name.so option to the driver".
john.brawn updated the summary for this revision.
john.brawn updated this revision to Diff 35014.
john.brawn added a comment.

Rename option from -load to -fplugin.


Repository:
  rL LLVM

http://reviews.llvm.org/D12903

Files:
  include/clang/Driver/Options.td
  lib/Driver/Tools.cpp
  test/Driver/fplugin.c

Index: test/Driver/fplugin.c
===
--- /dev/null
+++ test/Driver/fplugin.c
@@ -0,0 +1,7 @@
+// Check that all -fplugin arguments are converted to -load
+
+// RUN: %clang -c %s -fplugin=foo.so -### 2>&1 | FileCheck %s 
--check-prefix=CHECK1
+// RUN: %clang -c %s -fplugin=foo.so -fplugin=bar.so -### 2>&1 | FileCheck %s 
--check-prefix=CHECK2
+
+// CHECK1: "-load" "foo.so"
+// CHECK2: "-load" "foo.so" "-load" "bar.so"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5036,6 +5036,13 @@
   // Forward -fparse-all-comments to -cc1.
   Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments);
 
+  // Turn -fplugin=name.so into -load name.so
+  for (const Arg *A : Args.filtered(options::OPT_fplugin)) {
+CmdArgs.push_back("-load");
+CmdArgs.push_back(A->getValue());
+A->claim();
+  }
+
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
   Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -949,6 +949,8 @@
 def fno_pic : Flag<["-"], "fno-pic">, Group;
 def fpie : Flag<["-"], "fpie">, Group;
 def fno_pie : Flag<["-"], "fno-pie">, Group;
+def fplugin : Joined<["-"], "fplugin=">, Group, 
Flags<[DriverOption]>, MetaVarName<"">,
+  HelpText<"Load the named plugin (dynamic shared object)">;
 def fprofile_arcs : Flag<["-"], "fprofile-arcs">, Group;
 def fno_profile_arcs : Flag<["-"], "fno-profile-arcs">, Group;
 def framework : Separate<["-"], "framework">, Flags<[LinkerInput]>;


Index: test/Driver/fplugin.c
===
--- /dev/null
+++ test/Driver/fplugin.c
@@ -0,0 +1,7 @@
+// Check that all -fplugin arguments are converted to -load
+
+// RUN: %clang -c %s -fplugin=foo.so -### 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %clang -c %s -fplugin=foo.so -fplugin=bar.so -### 2>&1 | FileCheck %s --check-prefix=CHECK2
+
+// CHECK1: "-load" "foo.so"
+// CHECK2: "-load" "foo.so" "-load" "bar.so"
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5036,6 +5036,13 @@
   // Forward -fparse-all-comments to -cc1.
   Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments);
 
+  // Turn -fplugin=name.so into -load name.so
+  for (const Arg *A : Args.filtered(options::OPT_fplugin)) {
+CmdArgs.push_back("-load");
+CmdArgs.push_back(A->getValue());
+A->claim();
+  }
+
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
   Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -949,6 +949,8 @@
 def fno_pic : Flag<["-"], "fno-pic">, Group;
 def fpie : Flag<["-"], "fpie">, Group;
 def fno_pie : Flag<["-"], "fno-pie">, Group;
+def fplugin : Joined<["-"], "fplugin=">, Group, Flags<[DriverOption]>, MetaVarName<"">,
+  HelpText<"Load the named plugin (dynamic shared object)">;
 def fprofile_arcs : Flag<["-"], "fprofile-arcs">, Group;
 def fno_profile_arcs : Flag<["-"], "fno-profile-arcs">, Group;
 def framework : Separate<["-"], "framework">, Flags<[LinkerInput]>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12903: Add -fplugin=name.so option to the driver

2015-09-18 Thread John Brawn via cfe-commits
john.brawn added a comment.

In http://reviews.llvm.org/D12903#248453, @compnerd wrote:

> Do you know if GCC requires the = or can you do -fplugin name.so ?


GCC requires the =, or at least GCC 5.1.0 does when I tested it (you get "gcc: 
error: name.so: No such file or directory" and "gcc: error: unrecognized 
command line option '-fplugin'" if you do -fplugin name.so).


Repository:
  rL LLVM

http://reviews.llvm.org/D12903



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


Re: [PATCH] D12903: Add -fplugin=name.so option to the driver

2015-09-23 Thread John Brawn via cfe-commits
john.brawn added a comment.

In http://reviews.llvm.org/D12903#251361, @rengolin wrote:

> In http://reviews.llvm.org/D12903#249406, @thakis wrote:
>
> > Also also, this approach fundamentally doesn't work on Windows.
>
>
> I don't think it's supposed to, anyway. :)


Actually, I think it can work on Windows. Certainly -fplugin=foo.dll works on 
windows and the dll is correctly loaded, but the problem is building a dll that 
does something useful. Currently there's no way to build clang/llvm on windows 
so that LLVM_ENABLE_PLUGINS is true - setting BUILD_SHARED_LIBS sets it to 
true, but BUILD_SHARED_LIBS doesn't work (lots of linker errors). However I've 
managed to hack up a build of clang not using BUILD_SHARED_LIBS where it's 
possible to build plugin dlls that work (by sprinkling __declspec(dllexport) 
all over the place), so it doesn't look like there's a fundamental problem 
here. Also maybe it's possible to use llvm-readobj on the intermediate .lib 
files to generate a list of symbols to export and put that in a .def file for 
the link step and not have to do any modification to the source files at all, 
though I haven't been able to get that to work.

Anyway that's a bit of a digression. I've made naming change to OPT_fplugin_EQ, 
so I'll check that in.


Repository:
  rL LLVM

http://reviews.llvm.org/D12903



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


r248378 - Add -fplugin=name.so option to the driver

2015-09-23 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Wed Sep 23 08:55:40 2015
New Revision: 248378

URL: http://llvm.org/viewvc/llvm-project?rev=248378&view=rev
Log:
Add -fplugin=name.so option to the driver

This translates to -load name.so in the cc1 command. We can't name the driver
option -load, as that means "link against oad", so instead we follow GCC's lead
and name the option -fplugin.

Added:
cfe/trunk/test/Driver/fplugin.c
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=248378&r1=248377&r2=248378&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Sep 23 08:55:40 2015
@@ -949,6 +949,8 @@ def fpic : Flag<["-"], "fpic">, Group, Group;
 def fpie : Flag<["-"], "fpie">, Group;
 def fno_pie : Flag<["-"], "fno-pie">, Group;
+def fplugin_EQ : Joined<["-"], "fplugin=">, Group, 
Flags<[DriverOption]>, MetaVarName<"">,
+  HelpText<"Load the named plugin (dynamic shared object)">;
 def fprofile_arcs : Flag<["-"], "fprofile-arcs">, Group;
 def fno_profile_arcs : Flag<["-"], "fno-profile-arcs">, Group;
 def framework : Separate<["-"], "framework">, Flags<[LinkerInput]>;

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=248378&r1=248377&r2=248378&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Sep 23 08:55:40 2015
@@ -5037,6 +5037,13 @@ void Clang::ConstructJob(Compilation &C,
   // Forward -fparse-all-comments to -cc1.
   Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments);
 
+  // Turn -fplugin=name.so into -load name.so
+  for (const Arg *A : Args.filtered(options::OPT_fplugin_EQ)) {
+CmdArgs.push_back("-load");
+CmdArgs.push_back(A->getValue());
+A->claim();
+  }
+
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
   Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);

Added: cfe/trunk/test/Driver/fplugin.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fplugin.c?rev=248378&view=auto
==
--- cfe/trunk/test/Driver/fplugin.c (added)
+++ cfe/trunk/test/Driver/fplugin.c Wed Sep 23 08:55:40 2015
@@ -0,0 +1,7 @@
+// Check that all -fplugin arguments are converted to -load
+
+// RUN: %clang -c %s -fplugin=foo.so -### 2>&1 | FileCheck %s 
--check-prefix=CHECK1
+// RUN: %clang -c %s -fplugin=foo.so -fplugin=bar.so -### 2>&1 | FileCheck %s 
--check-prefix=CHECK2
+
+// CHECK1: "-load" "foo.so"
+// CHECK2: "-load" "foo.so" "-load" "bar.so"


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


Re: [PATCH] D12903: Add -fplugin=name.so option to the driver

2015-09-23 Thread John Brawn via cfe-commits
john.brawn closed this revision.
john.brawn added a comment.

Committed in r248378.


Repository:
  rL LLVM

http://reviews.llvm.org/D12903



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


[PATCH] D11980: Add test for PR24379

2015-08-12 Thread John Brawn via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: rafael, ab.
john.brawn added a subscriber: cfe-commits.
john.brawn set the repository for this revision to rL LLVM.

The fix for this is in LLVM but it depends on how clang handles the alias 
attribute, so add a test to the clang tests to make sure everything works 
together as expected.


Repository:
  rL LLVM

http://reviews.llvm.org/D11980

Files:
  test/CodeGen/alias.c

Index: test/CodeGen/alias.c
===
--- test/CodeGen/alias.c
+++ test/CodeGen/alias.c
@@ -1,19 +1,42 @@
 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECKBASIC %s
 // RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -emit-llvm -o - %s | 
FileCheck -check-prefix=CHECKCC %s
+// RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -S -o - %s | FileCheck 
-check-prefix=CHECKASM %s
 
 int g0;
-// CHECKBASIC: @g0 = common global i32 0
+// CHECKBASIC-DAG: @g0 = common global i32 0
+// CHECKASM-DAG: .comm g0,4,4
 __thread int TL_WITH_ALIAS;
 // CHECKBASIC-DAG: @TL_WITH_ALIAS = thread_local global i32 0, align 4
+// CHECKASM-DAG: .globl TL_WITH_ALIAS
+// CHECKASM-DAG: .size TL_WITH_ALIAS, 4
 static int bar1 = 42;
-// CHECKBASIC: @bar1 = internal global i32 42
+// CHECKBASIC-DAG: @bar1 = internal global i32 42
+// CHECKASM-DAG: bar1:
+// CHECKASM-DAG: .size bar1, 4
+
+// PR24379: alias variable expected to have same size as aliasee even when 
types differ
+const int wacom_usb_ids[] = {1, 1, 2, 3, 5, 8, 13, 0};
+// CHECKBASIC-DAG: @wacom_usb_ids = constant [8 x i32] [i32 1, i32 1, i32 2, 
i32 3, i32 5, i32 8, i32 13, i32 0], align 4
+// CHECKASM-DAG: .globl wacom_usb_ids
+// CHECKASM-DAG: .size wacom_usb_ids, 32
+extern const int __mod_usb_device_table __attribute__ 
((alias("wacom_usb_ids")));
+// CHECKBASIC-DAG: @__mod_usb_device_table = alias getelementptr inbounds ([8 
x i32], [8 x i32]* @wacom_usb_ids, i32 0, i32 0)
+// CHECKASM-DAG: .globl __mod_usb_device_table
+// CHECKASM-DAG: __mod_usb_device_table = wacom_usb_ids
+// CHECKASM-DAG-NOT: .size __mod_usb_device_table
 
 extern int g1;
 extern int g1 __attribute((alias("g0")));
 // CHECKBASIC-DAG: @g1 = alias i32* @g0
+// CHECKASM-DAG: .globl g1
+// CHECKASM-DAG: g1 = g0
+// CHECKASM-DAG-NOT: .size g1
 
 extern __thread int __libc_errno __attribute__ ((alias ("TL_WITH_ALIAS")));
 // CHECKBASIC-DAG: @__libc_errno = thread_local alias i32* @TL_WITH_ALIAS
+// CHECKASM-DAG: .globl __libc_errno
+// CHECKASM-DAG: __libc_errno = TL_WITH_ALIAS
+// CHECKASM-DAG-NOT: .size __libc_errno
 
 void f0(void) { }
 extern void f1(void);


Index: test/CodeGen/alias.c
===
--- test/CodeGen/alias.c
+++ test/CodeGen/alias.c
@@ -1,19 +1,42 @@
 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=CHECKBASIC %s
 // RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -emit-llvm -o - %s | FileCheck -check-prefix=CHECKCC %s
+// RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -S -o - %s | FileCheck -check-prefix=CHECKASM %s
 
 int g0;
-// CHECKBASIC: @g0 = common global i32 0
+// CHECKBASIC-DAG: @g0 = common global i32 0
+// CHECKASM-DAG: .comm g0,4,4
 __thread int TL_WITH_ALIAS;
 // CHECKBASIC-DAG: @TL_WITH_ALIAS = thread_local global i32 0, align 4
+// CHECKASM-DAG: .globl TL_WITH_ALIAS
+// CHECKASM-DAG: .size TL_WITH_ALIAS, 4
 static int bar1 = 42;
-// CHECKBASIC: @bar1 = internal global i32 42
+// CHECKBASIC-DAG: @bar1 = internal global i32 42
+// CHECKASM-DAG: bar1:
+// CHECKASM-DAG: .size bar1, 4
+
+// PR24379: alias variable expected to have same size as aliasee even when types differ
+const int wacom_usb_ids[] = {1, 1, 2, 3, 5, 8, 13, 0};
+// CHECKBASIC-DAG: @wacom_usb_ids = constant [8 x i32] [i32 1, i32 1, i32 2, i32 3, i32 5, i32 8, i32 13, i32 0], align 4
+// CHECKASM-DAG: .globl wacom_usb_ids
+// CHECKASM-DAG: .size wacom_usb_ids, 32
+extern const int __mod_usb_device_table __attribute__ ((alias("wacom_usb_ids")));
+// CHECKBASIC-DAG: @__mod_usb_device_table = alias getelementptr inbounds ([8 x i32], [8 x i32]* @wacom_usb_ids, i32 0, i32 0)
+// CHECKASM-DAG: .globl __mod_usb_device_table
+// CHECKASM-DAG: __mod_usb_device_table = wacom_usb_ids
+// CHECKASM-DAG-NOT: .size __mod_usb_device_table
 
 extern int g1;
 extern int g1 __attribute((alias("g0")));
 // CHECKBASIC-DAG: @g1 = alias i32* @g0
+// CHECKASM-DAG: .globl g1
+// CHECKASM-DAG: g1 = g0
+// CHECKASM-DAG-NOT: .size g1
 
 extern __thread int __libc_errno __attribute__ ((alias ("TL_WITH_ALIAS")));
 // CHECKBASIC-DAG: @__libc_errno = thread_local alias i32* @TL_WITH_ALIAS
+// CHECKASM-DAG: .globl __libc_errno
+// CHECKASM-DAG: __libc_errno = TL_WITH_ALIAS
+// CHECKASM-DAG-NOT: .size __libc_errno
 
 void f0(void) { }
 extern void f1(void);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/lis

r244756 - Add test for PR24379

2015-08-12 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Wed Aug 12 10:15:27 2015
New Revision: 244756

URL: http://llvm.org/viewvc/llvm-project?rev=244756&view=rev
Log:
Add test for PR24379

The fix for this is in LLVM but it depends on how clang handles the alias
attribute, so add a test to the clang tests to make sure everything works
together as expected.

Differential Revision: http://reviews.llvm.org/D11980

Modified:
cfe/trunk/test/CodeGen/alias.c

Modified: cfe/trunk/test/CodeGen/alias.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/alias.c?rev=244756&r1=244755&r2=244756&view=diff
==
--- cfe/trunk/test/CodeGen/alias.c (original)
+++ cfe/trunk/test/CodeGen/alias.c Wed Aug 12 10:15:27 2015
@@ -1,19 +1,42 @@
 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECKBASIC %s
 // RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -emit-llvm -o - %s | 
FileCheck -check-prefix=CHECKCC %s
+// RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -S -o - %s | FileCheck 
-check-prefix=CHECKASM %s
 
 int g0;
-// CHECKBASIC: @g0 = common global i32 0
+// CHECKBASIC-DAG: @g0 = common global i32 0
+// CHECKASM-DAG: .comm g0,4,4
 __thread int TL_WITH_ALIAS;
 // CHECKBASIC-DAG: @TL_WITH_ALIAS = thread_local global i32 0, align 4
+// CHECKASM-DAG: .globl TL_WITH_ALIAS
+// CHECKASM-DAG: .size TL_WITH_ALIAS, 4
 static int bar1 = 42;
-// CHECKBASIC: @bar1 = internal global i32 42
+// CHECKBASIC-DAG: @bar1 = internal global i32 42
+// CHECKASM-DAG: bar1:
+// CHECKASM-DAG: .size bar1, 4
+
+// PR24379: alias variable expected to have same size as aliasee even when 
types differ
+const int wacom_usb_ids[] = {1, 1, 2, 3, 5, 8, 13, 0};
+// CHECKBASIC-DAG: @wacom_usb_ids = constant [8 x i32] [i32 1, i32 1, i32 2, 
i32 3, i32 5, i32 8, i32 13, i32 0], align 4
+// CHECKASM-DAG: .globl wacom_usb_ids
+// CHECKASM-DAG: .size wacom_usb_ids, 32
+extern const int __mod_usb_device_table __attribute__ 
((alias("wacom_usb_ids")));
+// CHECKBASIC-DAG: @__mod_usb_device_table = alias getelementptr inbounds ([8 
x i32], [8 x i32]* @wacom_usb_ids, i32 0, i32 0)
+// CHECKASM-DAG: .globl __mod_usb_device_table
+// CHECKASM-DAG: __mod_usb_device_table = wacom_usb_ids
+// CHECKASM-DAG-NOT: .size __mod_usb_device_table
 
 extern int g1;
 extern int g1 __attribute((alias("g0")));
 // CHECKBASIC-DAG: @g1 = alias i32* @g0
+// CHECKASM-DAG: .globl g1
+// CHECKASM-DAG: g1 = g0
+// CHECKASM-DAG-NOT: .size g1
 
 extern __thread int __libc_errno __attribute__ ((alias ("TL_WITH_ALIAS")));
 // CHECKBASIC-DAG: @__libc_errno = thread_local alias i32* @TL_WITH_ALIAS
+// CHECKASM-DAG: .globl __libc_errno
+// CHECKASM-DAG: __libc_errno = TL_WITH_ALIAS
+// CHECKASM-DAG-NOT: .size __libc_errno
 
 void f0(void) { }
 extern void f1(void);


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


Re: [PATCH] D11980: Add test for PR24379

2015-08-12 Thread John Brawn via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL244756: Add test for PR24379 (authored by john.brawn).

Changed prior to commit:
  http://reviews.llvm.org/D11980?vs=31939&id=31942#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D11980

Files:
  cfe/trunk/test/CodeGen/alias.c

Index: cfe/trunk/test/CodeGen/alias.c
===
--- cfe/trunk/test/CodeGen/alias.c
+++ cfe/trunk/test/CodeGen/alias.c
@@ -1,19 +1,42 @@
 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECKBASIC %s
 // RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -emit-llvm -o - %s | 
FileCheck -check-prefix=CHECKCC %s
+// RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -S -o - %s | FileCheck 
-check-prefix=CHECKASM %s
 
 int g0;
-// CHECKBASIC: @g0 = common global i32 0
+// CHECKBASIC-DAG: @g0 = common global i32 0
+// CHECKASM-DAG: .comm g0,4,4
 __thread int TL_WITH_ALIAS;
 // CHECKBASIC-DAG: @TL_WITH_ALIAS = thread_local global i32 0, align 4
+// CHECKASM-DAG: .globl TL_WITH_ALIAS
+// CHECKASM-DAG: .size TL_WITH_ALIAS, 4
 static int bar1 = 42;
-// CHECKBASIC: @bar1 = internal global i32 42
+// CHECKBASIC-DAG: @bar1 = internal global i32 42
+// CHECKASM-DAG: bar1:
+// CHECKASM-DAG: .size bar1, 4
+
+// PR24379: alias variable expected to have same size as aliasee even when 
types differ
+const int wacom_usb_ids[] = {1, 1, 2, 3, 5, 8, 13, 0};
+// CHECKBASIC-DAG: @wacom_usb_ids = constant [8 x i32] [i32 1, i32 1, i32 2, 
i32 3, i32 5, i32 8, i32 13, i32 0], align 4
+// CHECKASM-DAG: .globl wacom_usb_ids
+// CHECKASM-DAG: .size wacom_usb_ids, 32
+extern const int __mod_usb_device_table __attribute__ 
((alias("wacom_usb_ids")));
+// CHECKBASIC-DAG: @__mod_usb_device_table = alias getelementptr inbounds ([8 
x i32], [8 x i32]* @wacom_usb_ids, i32 0, i32 0)
+// CHECKASM-DAG: .globl __mod_usb_device_table
+// CHECKASM-DAG: __mod_usb_device_table = wacom_usb_ids
+// CHECKASM-DAG-NOT: .size __mod_usb_device_table
 
 extern int g1;
 extern int g1 __attribute((alias("g0")));
 // CHECKBASIC-DAG: @g1 = alias i32* @g0
+// CHECKASM-DAG: .globl g1
+// CHECKASM-DAG: g1 = g0
+// CHECKASM-DAG-NOT: .size g1
 
 extern __thread int __libc_errno __attribute__ ((alias ("TL_WITH_ALIAS")));
 // CHECKBASIC-DAG: @__libc_errno = thread_local alias i32* @TL_WITH_ALIAS
+// CHECKASM-DAG: .globl __libc_errno
+// CHECKASM-DAG: __libc_errno = TL_WITH_ALIAS
+// CHECKASM-DAG-NOT: .size __libc_errno
 
 void f0(void) { }
 extern void f1(void);


Index: cfe/trunk/test/CodeGen/alias.c
===
--- cfe/trunk/test/CodeGen/alias.c
+++ cfe/trunk/test/CodeGen/alias.c
@@ -1,19 +1,42 @@
 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=CHECKBASIC %s
 // RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -emit-llvm -o - %s | FileCheck -check-prefix=CHECKCC %s
+// RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -S -o - %s | FileCheck -check-prefix=CHECKASM %s
 
 int g0;
-// CHECKBASIC: @g0 = common global i32 0
+// CHECKBASIC-DAG: @g0 = common global i32 0
+// CHECKASM-DAG: .comm g0,4,4
 __thread int TL_WITH_ALIAS;
 // CHECKBASIC-DAG: @TL_WITH_ALIAS = thread_local global i32 0, align 4
+// CHECKASM-DAG: .globl TL_WITH_ALIAS
+// CHECKASM-DAG: .size TL_WITH_ALIAS, 4
 static int bar1 = 42;
-// CHECKBASIC: @bar1 = internal global i32 42
+// CHECKBASIC-DAG: @bar1 = internal global i32 42
+// CHECKASM-DAG: bar1:
+// CHECKASM-DAG: .size bar1, 4
+
+// PR24379: alias variable expected to have same size as aliasee even when types differ
+const int wacom_usb_ids[] = {1, 1, 2, 3, 5, 8, 13, 0};
+// CHECKBASIC-DAG: @wacom_usb_ids = constant [8 x i32] [i32 1, i32 1, i32 2, i32 3, i32 5, i32 8, i32 13, i32 0], align 4
+// CHECKASM-DAG: .globl wacom_usb_ids
+// CHECKASM-DAG: .size wacom_usb_ids, 32
+extern const int __mod_usb_device_table __attribute__ ((alias("wacom_usb_ids")));
+// CHECKBASIC-DAG: @__mod_usb_device_table = alias getelementptr inbounds ([8 x i32], [8 x i32]* @wacom_usb_ids, i32 0, i32 0)
+// CHECKASM-DAG: .globl __mod_usb_device_table
+// CHECKASM-DAG: __mod_usb_device_table = wacom_usb_ids
+// CHECKASM-DAG-NOT: .size __mod_usb_device_table
 
 extern int g1;
 extern int g1 __attribute((alias("g0")));
 // CHECKBASIC-DAG: @g1 = alias i32* @g0
+// CHECKASM-DAG: .globl g1
+// CHECKASM-DAG: g1 = g0
+// CHECKASM-DAG-NOT: .size g1
 
 extern __thread int __libc_errno __attribute__ ((alias ("TL_WITH_ALIAS")));
 // CHECKBASIC-DAG: @__libc_errno = thread_local alias i32* @TL_WITH_ALIAS
+// CHECKASM-DAG: .globl __libc_errno
+// CHECKASM-DAG: __libc_errno = TL_WITH_ALIAS
+// CHECKASM-DAG-NOT: .size __libc_errno
 
 void f0(void) { }
 extern void f1(void);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r244760 - The alias.c test now requires arm-registered-target

2015-08-12 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Wed Aug 12 10:55:55 2015
New Revision: 244760

URL: http://llvm.org/viewvc/llvm-project?rev=244760&view=rev
Log:
The alias.c test now requires arm-registered-target

This should fix a buildbot failure

Modified:
cfe/trunk/test/CodeGen/alias.c

Modified: cfe/trunk/test/CodeGen/alias.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/alias.c?rev=244760&r1=244759&r2=244760&view=diff
==
--- cfe/trunk/test/CodeGen/alias.c (original)
+++ cfe/trunk/test/CodeGen/alias.c Wed Aug 12 10:55:55 2015
@@ -1,3 +1,4 @@
+// REQUIRES: arm-registered-target
 // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - %s | FileCheck 
-check-prefix=CHECKBASIC %s
 // RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -emit-llvm -o - %s | 
FileCheck -check-prefix=CHECKCC %s
 // RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -S -o - %s | FileCheck 
-check-prefix=CHECKASM %s


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


r244437 - [Driver] Fix handling of -fbuiltin/-fcommon when combined with -mkernel

2015-08-10 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Mon Aug 10 06:11:28 2015
New Revision: 244437

URL: http://llvm.org/viewvc/llvm-project?rev=244437&view=rev
Log:
[Driver] Fix handling of -fbuiltin/-fcommon when combined with -mkernel

-mkernel enables -fno-builtin and -fno-common by default, but allows -fbuiltin
and -fcommon to override that. However "-fbuiltin -fno-builtin" is treated the
same as "-fbuiltin" which is wrong, so fix that. Also fixes similar behaviour
when -fno-common is default.

Differential Revision: http://reviews.llvm.org/D11459

Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/apple-kext-mkernel.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=244437&r1=244436&r2=244437&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Mon Aug 10 06:11:28 2015
@@ -4145,7 +4145,8 @@ void Clang::ConstructJob(Compilation &C,
 options::OPT_fno_lax_vector_conversions))
 CmdArgs.push_back("-fno-lax-vector-conversions");
 
-  if (Args.getLastArg(options::OPT_fapple_kext))
+  if (Args.getLastArg(options::OPT_fapple_kext) ||
+  (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))
 CmdArgs.push_back("-fapple-kext");
 
   Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch);
@@ -4279,15 +4280,9 @@ void Clang::ConstructJob(Compilation &C,
   A->render(Args, CmdArgs);
   }
 
-  if (Args.hasArg(options::OPT_mkernel)) {
-if (!Args.hasArg(options::OPT_fapple_kext) && types::isCXX(InputType))
-  CmdArgs.push_back("-fapple-kext");
-if (!Args.hasArg(options::OPT_fbuiltin))
-  CmdArgs.push_back("-fno-builtin");
-Args.ClaimAllArgs(options::OPT_fno_builtin);
-  }
-  // -fbuiltin is default.
-  else if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin))
+  // -fbuiltin is default unless -mkernel is used
+  if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin,
+!Args.hasArg(options::OPT_mkernel)))
 CmdArgs.push_back("-fno-builtin");
 
   if (!Args.hasFlag(options::OPT_fassume_sane_operator_new,
@@ -4687,14 +4682,11 @@ void Clang::ConstructJob(Compilation &C,
 }
   }
 
-  if (KernelOrKext || isNoCommonDefault(getToolChain().getTriple())) {
-if (!Args.hasArg(options::OPT_fcommon))
-  CmdArgs.push_back("-fno-common");
-Args.ClaimAllArgs(options::OPT_fno_common);
-  }
-
-  // -fcommon is default, only pass non-default.
-  else if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common))
+  // -fcommon is the default unless compiling kernel code or the target says so
+  bool NoCommonDefault =
+  KernelOrKext || isNoCommonDefault(getToolChain().getTriple());
+  if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common,
+!NoCommonDefault))
 CmdArgs.push_back("-fno-common");
 
   // -fsigned-bitfields is default, and clang doesn't yet support

Modified: cfe/trunk/test/Driver/apple-kext-mkernel.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/apple-kext-mkernel.c?rev=244437&r1=244436&r2=244437&view=diff
==
--- cfe/trunk/test/Driver/apple-kext-mkernel.c (original)
+++ cfe/trunk/test/Driver/apple-kext-mkernel.c Mon Aug 10 06:11:28 2015
@@ -1,15 +1,20 @@
-// RUN: %clang -target x86_64-apple-darwin10 \
-// RUN:   -mkernel -### -fsyntax-only %s 2> %t
-// RUN: FileCheck --check-prefix=CHECK-X86 < %t %s
+// RUN: %clang -target x86_64-apple-darwin10 -mkernel -### -fsyntax-only %s 
2>&1 | FileCheck --check-prefix=CHECK-X86 %s
+// RUN: %clang -target x86_64-apple-darwin10 -mkernel -### -fsyntax-only 
-fbuiltin -fno-builtin -fcommon -fno-common %s 2>&1 | FileCheck 
--check-prefix=CHECK-X86 %s
 
 // CHECK-X86: "-disable-red-zone"
 // CHECK-X86: "-fno-builtin"
 // CHECK-X86: "-fno-rtti"
 // CHECK-X86: "-fno-common"
 
-// RUN: %clang -target x86_64-apple-darwin10 \
-// RUN:   -arch armv7 -mkernel -mstrict-align -### -fsyntax-only %s 2> %t
-// RUN: FileCheck --check-prefix=CHECK-ARM < %t %s
+// RUN: %clang -target x86_64-apple-darwin10 -mkernel -### -fsyntax-only 
-fbuiltin -fcommon %s 2>&1 | FileCheck --check-prefix=CHECK-X86-2 %s
+
+// CHECK-X86-2: "-disable-red-zone"
+// CHECK-X86-2-NOT: "-fno-builtin"
+// CHECK-X86-2: "-fno-rtti"
+// CHECK-X86-2-NOT: "-fno-common"
+
+// RUN: %clang -target x86_64-apple-darwin10 -arch armv7 -mkernel 
-mstrict-align -### -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-ARM 
%s
+// RUN: %clang -target x86_64-apple-darwin10 -arch armv7 -mkernel 
-mstrict-align -### -fsyntax-only -fbuiltin -fno-builtin -fcommon -fno-common 
%s 2>&1 | FileCheck --check-prefix=CHECK-ARM %s
 
 // CHECK-ARM: "-target-feature" "+long-calls"
 // CHECK-ARM: "-target-feature" "+strict-align"


___
cfe-commits mailing list
cfe-co

Re: [PATCH] D11459: [Driver] Fix handling of -fbuiltin/-fcommon when combined with -mkernel

2015-08-10 Thread John Brawn via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL244437: [Driver] Fix handling of -fbuiltin/-fcommon when 
combined with -mkernel (authored by john.brawn).

Changed prior to commit:
  http://reviews.llvm.org/D11459?vs=30478&id=31648#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D11459

Files:
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/test/Driver/apple-kext-mkernel.c

Index: cfe/trunk/test/Driver/apple-kext-mkernel.c
===
--- cfe/trunk/test/Driver/apple-kext-mkernel.c
+++ cfe/trunk/test/Driver/apple-kext-mkernel.c
@@ -1,15 +1,20 @@
-// RUN: %clang -target x86_64-apple-darwin10 \
-// RUN:   -mkernel -### -fsyntax-only %s 2> %t
-// RUN: FileCheck --check-prefix=CHECK-X86 < %t %s
+// RUN: %clang -target x86_64-apple-darwin10 -mkernel -### -fsyntax-only %s 
2>&1 | FileCheck --check-prefix=CHECK-X86 %s
+// RUN: %clang -target x86_64-apple-darwin10 -mkernel -### -fsyntax-only 
-fbuiltin -fno-builtin -fcommon -fno-common %s 2>&1 | FileCheck 
--check-prefix=CHECK-X86 %s
 
 // CHECK-X86: "-disable-red-zone"
 // CHECK-X86: "-fno-builtin"
 // CHECK-X86: "-fno-rtti"
 // CHECK-X86: "-fno-common"
 
-// RUN: %clang -target x86_64-apple-darwin10 \
-// RUN:   -arch armv7 -mkernel -mstrict-align -### -fsyntax-only %s 2> %t
-// RUN: FileCheck --check-prefix=CHECK-ARM < %t %s
+// RUN: %clang -target x86_64-apple-darwin10 -mkernel -### -fsyntax-only 
-fbuiltin -fcommon %s 2>&1 | FileCheck --check-prefix=CHECK-X86-2 %s
+
+// CHECK-X86-2: "-disable-red-zone"
+// CHECK-X86-2-NOT: "-fno-builtin"
+// CHECK-X86-2: "-fno-rtti"
+// CHECK-X86-2-NOT: "-fno-common"
+
+// RUN: %clang -target x86_64-apple-darwin10 -arch armv7 -mkernel 
-mstrict-align -### -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-ARM 
%s
+// RUN: %clang -target x86_64-apple-darwin10 -arch armv7 -mkernel 
-mstrict-align -### -fsyntax-only -fbuiltin -fno-builtin -fcommon -fno-common 
%s 2>&1 | FileCheck --check-prefix=CHECK-ARM %s
 
 // CHECK-ARM: "-target-feature" "+long-calls"
 // CHECK-ARM: "-target-feature" "+strict-align"
Index: cfe/trunk/lib/Driver/Tools.cpp
===
--- cfe/trunk/lib/Driver/Tools.cpp
+++ cfe/trunk/lib/Driver/Tools.cpp
@@ -4145,7 +4145,8 @@
 options::OPT_fno_lax_vector_conversions))
 CmdArgs.push_back("-fno-lax-vector-conversions");
 
-  if (Args.getLastArg(options::OPT_fapple_kext))
+  if (Args.getLastArg(options::OPT_fapple_kext) ||
+  (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType)))
 CmdArgs.push_back("-fapple-kext");
 
   Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch);
@@ -4279,15 +4280,9 @@
   A->render(Args, CmdArgs);
   }
 
-  if (Args.hasArg(options::OPT_mkernel)) {
-if (!Args.hasArg(options::OPT_fapple_kext) && types::isCXX(InputType))
-  CmdArgs.push_back("-fapple-kext");
-if (!Args.hasArg(options::OPT_fbuiltin))
-  CmdArgs.push_back("-fno-builtin");
-Args.ClaimAllArgs(options::OPT_fno_builtin);
-  }
-  // -fbuiltin is default.
-  else if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin))
+  // -fbuiltin is default unless -mkernel is used
+  if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin,
+!Args.hasArg(options::OPT_mkernel)))
 CmdArgs.push_back("-fno-builtin");
 
   if (!Args.hasFlag(options::OPT_fassume_sane_operator_new,
@@ -4687,14 +4682,11 @@
 }
   }
 
-  if (KernelOrKext || isNoCommonDefault(getToolChain().getTriple())) {
-if (!Args.hasArg(options::OPT_fcommon))
-  CmdArgs.push_back("-fno-common");
-Args.ClaimAllArgs(options::OPT_fno_common);
-  }
-
-  // -fcommon is default, only pass non-default.
-  else if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common))
+  // -fcommon is the default unless compiling kernel code or the target says so
+  bool NoCommonDefault =
+  KernelOrKext || isNoCommonDefault(getToolChain().getTriple());
+  if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common,
+!NoCommonDefault))
 CmdArgs.push_back("-fno-common");
 
   // -fsigned-bitfields is default, and clang doesn't yet support


Index: cfe/trunk/test/Driver/apple-kext-mkernel.c
===
--- cfe/trunk/test/Driver/apple-kext-mkernel.c
+++ cfe/trunk/test/Driver/apple-kext-mkernel.c
@@ -1,15 +1,20 @@
-// RUN: %clang -target x86_64-apple-darwin10 \
-// RUN:   -mkernel -### -fsyntax-only %s 2> %t
-// RUN: FileCheck --check-prefix=CHECK-X86 < %t %s
+// RUN: %clang -target x86_64-apple-darwin10 -mkernel -### -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-X86 %s
+// RUN: %clang -target x86_64-apple-darwin10 -mkernel -### -fsyntax-only -fbuiltin -fno-builtin -fcommon -fno-common %s 2>&1 | FileCheck --check-prefix=CHECK-X86 %s
 
 // CHECK-X86: "-disable-red-zone"
 // CHECK-X86: "-fno-builtin"
 // CHECK-X8

Re: [PATCH] D22221: Decide whether to enable plugin tests based on cmake variables

2016-07-22 Thread John Brawn via cfe-commits
john.brawn added a comment.

Ping.


Repository:
  rL LLVM

https://reviews.llvm.org/D1



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


Re: [PATCH] D21385: Adjust Registry interface to not require plugins to export a registry

2016-07-22 Thread John Brawn via cfe-commits
john.brawn added a comment.

Ping.


Repository:
  rL LLVM

https://reviews.llvm.org/D21385



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


Re: [PATCH] D21385: Adjust Registry interface to not require plugins to export a registry

2016-07-27 Thread John Brawn via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL276856: Adjust Registry interface to not require plugins to 
export a registry (authored by john.brawn).

Repository:
  rL LLVM

https://reviews.llvm.org/D21385

Files:
  cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
  cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
  cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
  cfe/trunk/include/clang/Lex/Preprocessor.h
  cfe/trunk/lib/Frontend/FrontendAction.cpp
  cfe/trunk/lib/Lex/Preprocessor.cpp
  cfe/trunk/lib/Tooling/CompilationDatabase.cpp
  llvm/trunk/include/llvm/Support/Registry.h
  llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
  llvm/trunk/lib/CodeGen/GCStrategy.cpp

Index: llvm/trunk/include/llvm/Support/Registry.h
===
--- llvm/trunk/include/llvm/Support/Registry.h
+++ llvm/trunk/include/llvm/Support/Registry.h
@@ -69,13 +69,14 @@
   node(const entry &V) : Next(nullptr), Val(V) {}
 };
 
-static void add_node(node *N) {
-  if (Tail)
-Tail->Next = N;
-  else
-Head = N;
-  Tail = N;
-}
+/// Add a node to the Registry: this is the interface between the plugin and
+/// the executable.
+///
+/// This function is exported by the executable and called by the plugin to
+/// add a node to the executable's registry. Therefore it's not defined here
+/// to avoid it being instantiated in the plugin and is instead defined in
+/// the executable (see LLVM_INSTANTIATE_REGISTRY below).
+static void add_node(node *N);
 
 /// Iterators for registry entries.
 ///
@@ -120,61 +121,23 @@
 add_node(&Node);
   }
 };
-
-/// A dynamic import facility.  This is used on Windows to
-/// import the entries added in the plugin.
-static void import(sys::DynamicLibrary &DL, const char *RegistryName) {
-  typedef void *(*GetRegistry)();
-  std::string Name("LLVMGetRegistry_");
-  Name.append(RegistryName);
-  GetRegistry Getter =
-  (GetRegistry)(intptr_t)DL.getAddressOfSymbol(Name.c_str());
-  if (Getter) {
-// Call the getter function in order to get the full copy of the
-// registry defined in the plugin DLL, and copy them over to the
-// current Registry.
-typedef std::pair Info;
-Info *I = static_cast(Getter());
-iterator begin(I->first);
-iterator end(I->second);
-for (++end; begin != end; ++begin) {
-  // This Node object needs to remain alive for the
-  // duration of the program.
-  add_node(new node(*begin));
-}
-  }
-}
-
-/// Retrieve the data to be passed across DLL boundaries when
-/// importing registries from another DLL on Windows.
-static void *exportRegistry() {
-  static std::pair Info(Head, Tail);
-  return &Info;
-}
   };
-
-  
-  // Since these are defined in a header file, plugins must be sure to export
-  // these symbols.
-  template 
-  typename Registry::node *Registry::Head;
-
-  template 
-  typename Registry::node *Registry::Tail;
 } // end namespace llvm
 
-#ifdef LLVM_ON_WIN32
-#define LLVM_EXPORT_REGISTRY(REGISTRY_CLASS)   \
-  extern "C" { \
-  __declspec(dllexport) void *__cdecl LLVMGetRegistry_##REGISTRY_CLASS() { \
-return REGISTRY_CLASS::exportRegistry();   \
-  }\
+/// Instantiate a registry class.
+///
+/// This instantiates add_node and the Head and Tail pointers.
+#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
+  namespace llvm { \
+  template<> void REGISTRY_CLASS::add_node(REGISTRY_CLASS::node *N) { \
+if (Tail) \
+ Tail->Next = N; \
+else \
+  Head = N; \
+Tail = N; \
+  } \
+  template<> typename REGISTRY_CLASS::node *REGISTRY_CLASS::Head = nullptr; \
+  template<> typename REGISTRY_CLASS::node *REGISTRY_CLASS::Tail = nullptr; \
   }
-#define LLVM_IMPORT_REGISTRY(REGISTRY_CLASS, DL)   \
-  REGISTRY_CLASS::import(DL, #REGISTRY_CLASS)
-#else
-#define LLVM_EXPORT_REGISTRY(REGISTRY_CLASS)
-#define LLVM_IMPORT_REGISTRY(REGISTRY_CLASS, DL)
-#endif
 
 #endif // LLVM_SUPPORT_REGISTRY_H
Index: llvm/trunk/lib/CodeGen/GCStrategy.cpp
===
--- llvm/trunk/lib/CodeGen/GCStrategy.cpp
+++ llvm/trunk/lib/CodeGen/GCStrategy.cpp
@@ -16,6 +16,8 @@
 
 using namespace llvm;
 
+LLVM_INSTANTIATE_REGISTRY(GCRegistry)
+
 GCStrategy::GCStrategy()
 : UseStatepoints(false), NeededSafePoints(0), CustomReadBarriers(false),
   CustomWriteBarriers(false), CustomRoots(false), InitRoots(true),
Index: llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
===
--

r276856 - Adjust Registry interface to not require plugins to export a registry

2016-07-27 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Wed Jul 27 06:18:38 2016
New Revision: 276856

URL: http://llvm.org/viewvc/llvm-project?rev=276856&view=rev
Log:
Adjust Registry interface to not require plugins to export a registry

Currently the Registry class contains the vestiges of a previous attempt to
allow plugins to be used on Windows without using BUILD_SHARED_LIBS, where a
plugin would have its own copy of a registry and export it to be imported by
the tool that's loading the plugin. This only works if the plugin is entirely
self-contained with the only interface between the plugin and tool being the
registry, and in particular this conflicts with how IR pass plugins work.

This patch changes things so that instead the add_node function of the registry
is exported by the tool and then imported by the plugin, which solves this
problem and also means that instead of every plugin having to export every
registry they use instead LLVM only has to export the add_node functions. This
allows plugins that use a registry to work on Windows if
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS is used.

Differential Revision: http://reviews.llvm.org/D21385

Modified:
cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Frontend/FrontendAction.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Tooling/CompilationDatabase.cpp

Modified: cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt?rev=276856&r1=276855&r2=276856&view=diff
==
--- cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt (original)
+++ cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt Wed Jul 27 06:18:38 2016
@@ -1,4 +1,4 @@
-add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp)
+add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp PLUGIN_TOOL 
clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(AnnotateFunctions PRIVATE

Modified: cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt?rev=276856&r1=276855&r2=276856&view=diff
==
--- cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt (original)
+++ cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt Wed Jul 27 06:18:38 
2016
@@ -9,7 +9,7 @@ if( NOT MSVC ) # MSVC mangles symbols di
   endif()
 endif()
 
-add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp)
+add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp PLUGIN_TOOL 
clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(PrintFunctionNames PRIVATE

Modified: cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h?rev=276856&r1=276855&r2=276856&view=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h Wed Jul 27 
06:18:38 2016
@@ -13,9 +13,6 @@
 #include "clang/Frontend/FrontendAction.h"
 #include "llvm/Support/Registry.h"
 
-// Instantiated in FrontendAction.cpp.
-extern template class llvm::Registry;
-
 namespace clang {
 
 /// The frontend plugin registry.

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=276856&r1=276855&r2=276856&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 27 06:18:38 2016
@@ -1956,6 +1956,4 @@ typedef llvm::Registry Pr
 
 }  // end namespace clang
 
-extern template class llvm::Registry;
-
 #endif

Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=276856&r1=276855&r2=276856&view=diff
==
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Wed Jul 27 06:18:38 2016
@@ -33,7 +33,7 @@
 #include 
 using namespace clang;
 
-template class llvm::Registry;
+LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry)
 
 namespace {
 

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=276856&r1=276855&r2=276856&view=diff
==
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
++

r276857 - Revert r276856 "Adjust Registry interface to not require plugins to export a registry"

2016-07-27 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Wed Jul 27 06:41:18 2016
New Revision: 276857

URL: http://llvm.org/viewvc/llvm-project?rev=276857&view=rev
Log:
Revert r276856 "Adjust Registry interface to not require plugins to export a 
registry"

This is causing a huge pile of buildbot failures.

Modified:
cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Frontend/FrontendAction.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Tooling/CompilationDatabase.cpp

Modified: cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt?rev=276857&r1=276856&r2=276857&view=diff
==
--- cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt (original)
+++ cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt Wed Jul 27 06:41:18 2016
@@ -1,4 +1,4 @@
-add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp PLUGIN_TOOL 
clang)
+add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(AnnotateFunctions PRIVATE

Modified: cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt?rev=276857&r1=276856&r2=276857&view=diff
==
--- cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt (original)
+++ cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt Wed Jul 27 06:41:18 
2016
@@ -9,7 +9,7 @@ if( NOT MSVC ) # MSVC mangles symbols di
   endif()
 endif()
 
-add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp PLUGIN_TOOL 
clang)
+add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(PrintFunctionNames PRIVATE

Modified: cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h?rev=276857&r1=276856&r2=276857&view=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h Wed Jul 27 
06:41:18 2016
@@ -13,6 +13,9 @@
 #include "clang/Frontend/FrontendAction.h"
 #include "llvm/Support/Registry.h"
 
+// Instantiated in FrontendAction.cpp.
+extern template class llvm::Registry;
+
 namespace clang {
 
 /// The frontend plugin registry.

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=276857&r1=276856&r2=276857&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 27 06:41:18 2016
@@ -1956,4 +1956,6 @@ typedef llvm::Registry Pr
 
 }  // end namespace clang
 
+extern template class llvm::Registry;
+
 #endif

Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=276857&r1=276856&r2=276857&view=diff
==
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Wed Jul 27 06:41:18 2016
@@ -33,7 +33,7 @@
 #include 
 using namespace clang;
 
-LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry)
+template class llvm::Registry;
 
 namespace {
 

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=276857&r1=276856&r2=276857&view=diff
==
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Wed Jul 27 06:41:18 2016
@@ -54,7 +54,7 @@
 #include 
 using namespace clang;
 
-LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry)
+template class llvm::Registry;
 
 
//===--===//
 ExternalPreprocessorSource::~ExternalPreprocessorSource() { }

Modified: cfe/trunk/lib/Tooling/CompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CompilationDatabase.cpp?rev=276857&r1=276856&r2=276857&view=diff
==
--- cfe/trunk/lib/Tooling/CompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/CompilationDatabase.cpp Wed Jul 27 06:41:18 2016
@@ -32,8 +32,6 @@
 using namespace clang;
 using namespace tooling;
 
-LLVM_INSTANTIATE_REGISTRY(Compilati

[clang-tools-extra] r276973 - Reapply r276856 "Adjust Registry interface to not require plugins to export a registry"

2016-07-28 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Thu Jul 28 07:48:17 2016
New Revision: 276973

URL: http://llvm.org/viewvc/llvm-project?rev=276973&view=rev
Log:
Reapply r276856 "Adjust Registry interface to not require plugins to export a 
registry"

This version has two fixes compared to the original:
 * In Registry.h the template static members are instantiated before they are
   used, as clang gives an error if you do it the other way around.
 * The use of the Registry template in clang-tidy is updated in the same way as
   has been done everywhere else.

Original commit message:

Currently the Registry class contains the vestiges of a previous attempt to
allow plugins to be used on Windows without using BUILD_SHARED_LIBS, where a
plugin would have its own copy of a registry and export it to be imported by
the tool that's loading the plugin. This only works if the plugin is entirely
self-contained with the only interface between the plugin and tool being the
registry, and in particular this conflicts with how IR pass plugins work.

This patch changes things so that instead the add_node function of the registry
is exported by the tool and then imported by the plugin, which solves this
problem and also means that instead of every plugin having to export every
registry they use instead LLVM only has to export the add_node functions. This
allows plugins that use a registry to work on Windows if
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS is used.

Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=276973&r1=276972&r2=276973&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Thu Jul 28 07:48:17 2016
@@ -47,7 +47,7 @@ using namespace clang::driver;
 using namespace clang::tooling;
 using namespace llvm;
 
-template class llvm::Registry;
+LLVM_INSTANTIATE_REGISTRY(clang::tidy::ClangTidyModuleRegistry)
 
 namespace clang {
 namespace tidy {

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h?rev=276973&r1=276972&r2=276973&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h Thu Jul 28 
07:48:17 2016
@@ -13,8 +13,6 @@
 #include "ClangTidyModule.h"
 #include "llvm/Support/Registry.h"
 
-extern template class llvm::Registry;
-
 namespace clang {
 namespace tidy {
 


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


r276973 - Reapply r276856 "Adjust Registry interface to not require plugins to export a registry"

2016-07-28 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Thu Jul 28 07:48:17 2016
New Revision: 276973

URL: http://llvm.org/viewvc/llvm-project?rev=276973&view=rev
Log:
Reapply r276856 "Adjust Registry interface to not require plugins to export a 
registry"

This version has two fixes compared to the original:
 * In Registry.h the template static members are instantiated before they are
   used, as clang gives an error if you do it the other way around.
 * The use of the Registry template in clang-tidy is updated in the same way as
   has been done everywhere else.

Original commit message:

Currently the Registry class contains the vestiges of a previous attempt to
allow plugins to be used on Windows without using BUILD_SHARED_LIBS, where a
plugin would have its own copy of a registry and export it to be imported by
the tool that's loading the plugin. This only works if the plugin is entirely
self-contained with the only interface between the plugin and tool being the
registry, and in particular this conflicts with how IR pass plugins work.

This patch changes things so that instead the add_node function of the registry
is exported by the tool and then imported by the plugin, which solves this
problem and also means that instead of every plugin having to export every
registry they use instead LLVM only has to export the add_node functions. This
allows plugins that use a registry to work on Windows if
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS is used.

Modified:
cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Frontend/FrontendAction.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Tooling/CompilationDatabase.cpp

Modified: cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt?rev=276973&r1=276972&r2=276973&view=diff
==
--- cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt (original)
+++ cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt Thu Jul 28 07:48:17 2016
@@ -1,4 +1,4 @@
-add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp)
+add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp PLUGIN_TOOL 
clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(AnnotateFunctions PRIVATE

Modified: cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt?rev=276973&r1=276972&r2=276973&view=diff
==
--- cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt (original)
+++ cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt Thu Jul 28 07:48:17 
2016
@@ -9,7 +9,7 @@ if( NOT MSVC ) # MSVC mangles symbols di
   endif()
 endif()
 
-add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp)
+add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp PLUGIN_TOOL 
clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(PrintFunctionNames PRIVATE

Modified: cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h?rev=276973&r1=276972&r2=276973&view=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h Thu Jul 28 
07:48:17 2016
@@ -13,9 +13,6 @@
 #include "clang/Frontend/FrontendAction.h"
 #include "llvm/Support/Registry.h"
 
-// Instantiated in FrontendAction.cpp.
-extern template class llvm::Registry;
-
 namespace clang {
 
 /// The frontend plugin registry.

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=276973&r1=276972&r2=276973&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Thu Jul 28 07:48:17 2016
@@ -1972,6 +1972,4 @@ typedef llvm::Registry Pr
 
 }  // end namespace clang
 
-extern template class llvm::Registry;
-
 #endif

Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=276973&r1=276972&r2=276973&view=diff
==
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Thu Jul 28 07:48:17 2016
@@ -33,7 +33,7 @@
 #include 
 using namespace clang;
 
-template class llvm::Registry;
+LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry)
 
 names

[clang-tools-extra] r277008 - Revert r276973 "Adjust Registry interface to not require plugins to export a registry"

2016-07-28 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Thu Jul 28 12:17:22 2016
New Revision: 277008

URL: http://llvm.org/viewvc/llvm-project?rev=277008&view=rev
Log:
Revert r276973 "Adjust Registry interface to not require plugins to export a 
registry"

Buildbot failures when building with clang -Werror. Reverting while I try to
figure this out.

Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=277008&r1=277007&r2=277008&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Thu Jul 28 12:17:22 2016
@@ -47,7 +47,7 @@ using namespace clang::driver;
 using namespace clang::tooling;
 using namespace llvm;
 
-LLVM_INSTANTIATE_REGISTRY(clang::tidy::ClangTidyModuleRegistry)
+template class llvm::Registry;
 
 namespace clang {
 namespace tidy {

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h?rev=277008&r1=277007&r2=277008&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h Thu Jul 28 
12:17:22 2016
@@ -13,6 +13,8 @@
 #include "ClangTidyModule.h"
 #include "llvm/Support/Registry.h"
 
+extern template class llvm::Registry;
+
 namespace clang {
 namespace tidy {
 


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


r277008 - Revert r276973 "Adjust Registry interface to not require plugins to export a registry"

2016-07-28 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Thu Jul 28 12:17:22 2016
New Revision: 277008

URL: http://llvm.org/viewvc/llvm-project?rev=277008&view=rev
Log:
Revert r276973 "Adjust Registry interface to not require plugins to export a 
registry"

Buildbot failures when building with clang -Werror. Reverting while I try to
figure this out.

Modified:
cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Frontend/FrontendAction.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Tooling/CompilationDatabase.cpp

Modified: cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt?rev=277008&r1=277007&r2=277008&view=diff
==
--- cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt (original)
+++ cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt Thu Jul 28 12:17:22 2016
@@ -1,4 +1,4 @@
-add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp PLUGIN_TOOL 
clang)
+add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(AnnotateFunctions PRIVATE

Modified: cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt?rev=277008&r1=277007&r2=277008&view=diff
==
--- cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt (original)
+++ cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt Thu Jul 28 12:17:22 
2016
@@ -9,7 +9,7 @@ if( NOT MSVC ) # MSVC mangles symbols di
   endif()
 endif()
 
-add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp PLUGIN_TOOL 
clang)
+add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(PrintFunctionNames PRIVATE

Modified: cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h?rev=277008&r1=277007&r2=277008&view=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h Thu Jul 28 
12:17:22 2016
@@ -13,6 +13,9 @@
 #include "clang/Frontend/FrontendAction.h"
 #include "llvm/Support/Registry.h"
 
+// Instantiated in FrontendAction.cpp.
+extern template class llvm::Registry;
+
 namespace clang {
 
 /// The frontend plugin registry.

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=277008&r1=277007&r2=277008&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Thu Jul 28 12:17:22 2016
@@ -1972,4 +1972,6 @@ typedef llvm::Registry Pr
 
 }  // end namespace clang
 
+extern template class llvm::Registry;
+
 #endif

Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=277008&r1=277007&r2=277008&view=diff
==
--- cfe/trunk/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendAction.cpp Thu Jul 28 12:17:22 2016
@@ -33,7 +33,7 @@
 #include 
 using namespace clang;
 
-LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry)
+template class llvm::Registry;
 
 namespace {
 

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=277008&r1=277007&r2=277008&view=diff
==
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Thu Jul 28 12:17:22 2016
@@ -54,7 +54,7 @@
 #include 
 using namespace clang;
 
-LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry)
+template class llvm::Registry;
 
 
//===--===//
 ExternalPreprocessorSource::~ExternalPreprocessorSource() { }

Modified: cfe/trunk/lib/Tooling/CompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CompilationDatabase.cpp?rev=277008&r1=277007&r2=277008&view=diff
==
--- cfe/trunk/lib/Tooling/CompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/CompilationDatabase.cpp Thu Jul 28 12:17:22 2016
@@ -32,8 +32,6 @@
 using namespace clang;
 using namespace too

r277806 - Reapply r276973 "Adjust Registry interface to not require plugins to export a registry"

2016-08-05 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Fri Aug  5 06:01:08 2016
New Revision: 277806

URL: http://llvm.org/viewvc/llvm-project?rev=277806&view=rev
Log:
Reapply r276973 "Adjust Registry interface to not require plugins to export a 
registry"

This differs from the previous version by being more careful about template
instantiation/specialization in order to prevent errors when building with
clang -Werror. Specifically:
 * begin is not defined in the template and is instead instantiated when Head
   is. I think the warning when we don't do that is wrong (PR28815) but for now
   at least do it this way to avoid the warning.
 * Instead of performing template specializations in LLVM_INSTANTIATE_REGISTRY
   instead provide a template definition then do explicit instantiation. No
   compiler I've tried has problems with doing it the other way, but strictly
   speaking it's not permitted by the C++ standard so better safe than sorry.

Original commit message:

Currently the Registry class contains the vestiges of a previous attempt to
allow plugins to be used on Windows without using BUILD_SHARED_LIBS, where a
plugin would have its own copy of a registry and export it to be imported by
the tool that's loading the plugin. This only works if the plugin is entirely
self-contained with the only interface between the plugin and tool being the
registry, and in particular this conflicts with how IR pass plugins work.

This patch changes things so that instead the add_node function of the registry
is exported by the tool and then imported by the plugin, which solves this
problem and also means that instead of every plugin having to export every
registry they use instead LLVM only has to export the add_node functions. This
allows plugins that use a registry to work on Windows if
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS is used.

Modified:
cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Frontend/FrontendAction.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Tooling/CompilationDatabase.cpp

Modified: cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt?rev=277806&r1=277805&r2=277806&view=diff
==
--- cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt (original)
+++ cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt Fri Aug  5 06:01:08 2016
@@ -1,4 +1,4 @@
-add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp)
+add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp PLUGIN_TOOL 
clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(AnnotateFunctions PRIVATE

Modified: cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt?rev=277806&r1=277805&r2=277806&view=diff
==
--- cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt (original)
+++ cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt Fri Aug  5 06:01:08 
2016
@@ -9,7 +9,7 @@ if( NOT MSVC ) # MSVC mangles symbols di
   endif()
 endif()
 
-add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp)
+add_llvm_loadable_module(PrintFunctionNames PrintFunctionNames.cpp PLUGIN_TOOL 
clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(PrintFunctionNames PRIVATE

Modified: cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h?rev=277806&r1=277805&r2=277806&view=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h Fri Aug  5 
06:01:08 2016
@@ -13,9 +13,6 @@
 #include "clang/Frontend/FrontendAction.h"
 #include "llvm/Support/Registry.h"
 
-// Instantiated in FrontendAction.cpp.
-extern template class llvm::Registry;
-
 namespace clang {
 
 /// The frontend plugin registry.

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=277806&r1=277805&r2=277806&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri Aug  5 06:01:08 2016
@@ -1972,6 +1972,4 @@ typedef llvm::Registry Pr
 
 }  // end namespace clang
 
-extern template class llvm::Registry;
-
 #endif

Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=27780

[clang-tools-extra] r277806 - Reapply r276973 "Adjust Registry interface to not require plugins to export a registry"

2016-08-05 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Fri Aug  5 06:01:08 2016
New Revision: 277806

URL: http://llvm.org/viewvc/llvm-project?rev=277806&view=rev
Log:
Reapply r276973 "Adjust Registry interface to not require plugins to export a 
registry"

This differs from the previous version by being more careful about template
instantiation/specialization in order to prevent errors when building with
clang -Werror. Specifically:
 * begin is not defined in the template and is instead instantiated when Head
   is. I think the warning when we don't do that is wrong (PR28815) but for now
   at least do it this way to avoid the warning.
 * Instead of performing template specializations in LLVM_INSTANTIATE_REGISTRY
   instead provide a template definition then do explicit instantiation. No
   compiler I've tried has problems with doing it the other way, but strictly
   speaking it's not permitted by the C++ standard so better safe than sorry.

Original commit message:

Currently the Registry class contains the vestiges of a previous attempt to
allow plugins to be used on Windows without using BUILD_SHARED_LIBS, where a
plugin would have its own copy of a registry and export it to be imported by
the tool that's loading the plugin. This only works if the plugin is entirely
self-contained with the only interface between the plugin and tool being the
registry, and in particular this conflicts with how IR pass plugins work.

This patch changes things so that instead the add_node function of the registry
is exported by the tool and then imported by the plugin, which solves this
problem and also means that instead of every plugin having to export every
registry they use instead LLVM only has to export the add_node functions. This
allows plugins that use a registry to work on Windows if
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS is used.

Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=277806&r1=277805&r2=277806&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Fri Aug  5 06:01:08 2016
@@ -47,7 +47,7 @@ using namespace clang::driver;
 using namespace clang::tooling;
 using namespace llvm;
 
-template class llvm::Registry;
+LLVM_INSTANTIATE_REGISTRY(clang::tidy::ClangTidyModuleRegistry)
 
 namespace clang {
 namespace tidy {

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h?rev=277806&r1=277805&r2=277806&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyModuleRegistry.h Fri Aug  5 
06:01:08 2016
@@ -13,8 +13,6 @@
 #include "ClangTidyModule.h"
 #include "llvm/Support/Registry.h"
 
-extern template class llvm::Registry;
-
 namespace clang {
 namespace tidy {
 


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


Re: [PATCH] D18319: Add a PragmaHandler Registry for plugins to add PragmaHandlers to

2016-03-31 Thread John Brawn via cfe-commits
john.brawn added a comment.

In http://reviews.llvm.org/D18319#379337, @rnk wrote:

> This seems reasonable.


OK to commit then?


Repository:
  rL LLVM

http://reviews.llvm.org/D18319



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


Re: [PATCH] D18319: Add a PragmaHandler Registry for plugins to add PragmaHandlers to

2016-04-04 Thread John Brawn via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL265295: Add a PragmaHandler Registry for plugins to add 
PragmaHandlers to (authored by john.brawn).

Changed prior to commit:
  http://reviews.llvm.org/D18319?vs=51168&id=52553#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18319

Files:
  cfe/trunk/docs/ClangPlugins.rst
  cfe/trunk/examples/AnnotateFunctions/AnnotateFunctions.cpp
  cfe/trunk/include/clang/Lex/Preprocessor.h
  cfe/trunk/lib/Lex/Pragma.cpp
  cfe/trunk/test/Frontend/plugin-annotate-functions.c

Index: cfe/trunk/docs/ClangPlugins.rst
===
--- cfe/trunk/docs/ClangPlugins.rst
+++ cfe/trunk/docs/ClangPlugins.rst
@@ -43,6 +43,26 @@
 
   static FrontendPluginRegistry::Add X("my-plugin-name", "my plugin description");
 
+Defining pragmas
+
+
+Plugins can also define pragmas by declaring a ``PragmaHandler`` and
+registering it using ``PragmaHandlerRegistry::Add<>``:
+
+.. code-block:: c++
+
+  // Define a pragma handler for #pragma example_pragma
+  class ExamplePragmaHandler : public PragmaHandler {
+  public:
+ExamplePragmaHandler() : PragmaHandler("example_pragma") { }
+void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
+  Token &PragmaTok) {
+  // Handle the pragma
+}
+  };
+
+  static PragmaHandlerRegistry::Add Y("example_pragma","example pragma description");
+
 Putting it all together
 ===
 
Index: cfe/trunk/include/clang/Lex/Preprocessor.h
===
--- cfe/trunk/include/clang/Lex/Preprocessor.h
+++ cfe/trunk/include/clang/Lex/Preprocessor.h
@@ -32,6 +32,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/Support/Allocator.h"
+#include "llvm/Support/Registry.h"
 #include 
 #include 
 
@@ -1937,6 +1938,9 @@
   virtual bool HandleComment(Preprocessor &PP, SourceRange Comment) = 0;
 };
 
+/// \brief Registry of pragma handlers added by plugins
+typedef llvm::Registry PragmaHandlerRegistry;
+
 }  // end namespace clang
 
 #endif
Index: cfe/trunk/test/Frontend/plugin-annotate-functions.c
===
--- cfe/trunk/test/Frontend/plugin-annotate-functions.c
+++ cfe/trunk/test/Frontend/plugin-annotate-functions.c
@@ -1,7 +1,25 @@
-// RUN: %clang -fplugin=%llvmshlibdir/AnnotateFunctions%pluginext -emit-llvm -S %s -o - | FileCheck %s
+// RUN: %clang -fplugin=%llvmshlibdir/AnnotateFunctions%pluginext -emit-llvm -DPRAGMA_ON -S %s -o - | FileCheck %s --check-prefix=PRAGMA
+// RUN: %clang -fplugin=%llvmshlibdir/AnnotateFunctions%pluginext -emit-llvm -S %s -o - | FileCheck %s --check-prefix=NOPRAGMA
+// RUN: not %clang -fplugin=%llvmshlibdir/AnnotateFunctions%pluginext -emit-llvm -DBAD_PRAGMA -S %s -o - 2>&1 | FileCheck %s --check-prefix=BADPRAGMA
 // REQUIRES: plugins, examples
 
-// CHECK: [[STR_VAR:@.+]] = private unnamed_addr constant [19 x i8] c"example_annotation\00"
-// CHECK: @llvm.global.annotations = {{.*}}@fn1{{.*}}[[STR_VAR]]{{.*}}@fn2{{.*}}[[STR_VAR]]
+#ifdef PRAGMA_ON
+#pragma enable_annotate
+#endif
+
+// BADPRAGMA: warning: extra tokens at end of #pragma directive
+#ifdef BAD_PRAGMA
+#pragma enable_annotate something
+#endif
+
+// PRAGMA: [[STR_VAR:@.+]] = private unnamed_addr constant [19 x i8] c"example_annotation\00"
+// PRAGMA: @llvm.global.annotations = {{.*}}@fn1{{.*}}[[STR_VAR]]{{.*}}@fn2{{.*}}[[STR_VAR]]
+// NOPRAGMA-NOT: [[STR_VAR:@.+]] = private unnamed_addr constant [19 x i8] c"example_annotation\00"
+// NOPRAGMA-NOT: @llvm.global.annotations = {{.*}}@fn1{{.*}}[[STR_VAR]]{{.*}}@fn2{{.*}}[[STR_VAR]]
 void fn1() { }
 void fn2() { }
+
+// BADPRAGMA: error: #pragma enable_annotate not allowed after declarations
+#ifdef BAD_PRAGMA
+#pragma enable_annotate
+#endif
Index: cfe/trunk/examples/AnnotateFunctions/AnnotateFunctions.cpp
===
--- cfe/trunk/examples/AnnotateFunctions/AnnotateFunctions.cpp
+++ cfe/trunk/examples/AnnotateFunctions/AnnotateFunctions.cpp
@@ -7,20 +7,29 @@
 //
 //===--===//
 //
-// Example clang plugin which adds an annotation to every function.
+// Example clang plugin which adds an annotation to every function in
+// translation units that start with #pragma enable_annotate.
 //
 //===--===//
 
 #include "clang/Frontend/FrontendPluginRegistry.h"
 #include "clang/AST/AST.h"
 #include "clang/AST/ASTConsumer.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/LexDiagnostic.h"
 using namespace clang;
 
 namespace {
 
+static bool EnableAnnotate = false;
+static bool HandledDecl = false;
+
 class AnnotateFunctionsConsumer : public ASTConsumer {
 public:
   bool HandleTopLevelDecl(DeclGroupRef DG) override {
+Hand

r265295 - Add a PragmaHandler Registry for plugins to add PragmaHandlers to

2016-04-04 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Mon Apr  4 09:22:58 2016
New Revision: 265295

URL: http://llvm.org/viewvc/llvm-project?rev=265295&view=rev
Log:
Add a PragmaHandler Registry for plugins to add PragmaHandlers to

This allows plugins which add AST passes to also define pragmas to do things
like only enable certain behaviour of the AST pass in files where a certain
pragma is used.

Differential Revision: http://reviews.llvm.org/D18319

Modified:
cfe/trunk/docs/ClangPlugins.rst
cfe/trunk/examples/AnnotateFunctions/AnnotateFunctions.cpp
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/test/Frontend/plugin-annotate-functions.c

Modified: cfe/trunk/docs/ClangPlugins.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangPlugins.rst?rev=265295&r1=265294&r2=265295&view=diff
==
--- cfe/trunk/docs/ClangPlugins.rst (original)
+++ cfe/trunk/docs/ClangPlugins.rst Mon Apr  4 09:22:58 2016
@@ -43,6 +43,26 @@ register a plugin in a library, use ``Fr
 
   static FrontendPluginRegistry::Add X("my-plugin-name", "my plugin 
description");
 
+Defining pragmas
+
+
+Plugins can also define pragmas by declaring a ``PragmaHandler`` and
+registering it using ``PragmaHandlerRegistry::Add<>``:
+
+.. code-block:: c++
+
+  // Define a pragma handler for #pragma example_pragma
+  class ExamplePragmaHandler : public PragmaHandler {
+  public:
+ExamplePragmaHandler() : PragmaHandler("example_pragma") { }
+void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
+  Token &PragmaTok) {
+  // Handle the pragma
+}
+  };
+
+  static PragmaHandlerRegistry::Add 
Y("example_pragma","example pragma description");
+
 Putting it all together
 ===
 

Modified: cfe/trunk/examples/AnnotateFunctions/AnnotateFunctions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/AnnotateFunctions/AnnotateFunctions.cpp?rev=265295&r1=265294&r2=265295&view=diff
==
--- cfe/trunk/examples/AnnotateFunctions/AnnotateFunctions.cpp (original)
+++ cfe/trunk/examples/AnnotateFunctions/AnnotateFunctions.cpp Mon Apr  4 
09:22:58 2016
@@ -7,20 +7,29 @@
 //
 
//===--===//
 //
-// Example clang plugin which adds an annotation to every function.
+// Example clang plugin which adds an annotation to every function in
+// translation units that start with #pragma enable_annotate.
 //
 
//===--===//
 
 #include "clang/Frontend/FrontendPluginRegistry.h"
 #include "clang/AST/AST.h"
 #include "clang/AST/ASTConsumer.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/LexDiagnostic.h"
 using namespace clang;
 
 namespace {
 
+static bool EnableAnnotate = false;
+static bool HandledDecl = false;
+
 class AnnotateFunctionsConsumer : public ASTConsumer {
 public:
   bool HandleTopLevelDecl(DeclGroupRef DG) override {
+HandledDecl = true;
+if (!EnableAnnotate)
+  return true;
 for (auto D : DG)
   if (FunctionDecl *FD = dyn_cast(D))
 FD->addAttr(AnnotateAttr::CreateImplicit(FD->getASTContext(),
@@ -46,7 +55,34 @@ public:
   }
 };
 
+class PragmaAnnotateHandler : public PragmaHandler {
+public:
+  PragmaAnnotateHandler() : PragmaHandler("enable_annotate") { }
+
+  void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
+Token &PragmaTok) override {
+
+Token Tok;
+PP.LexUnexpandedToken(Tok);
+if (Tok.isNot(tok::eod))
+  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
+
+if (HandledDecl) {
+  DiagnosticsEngine &D = PP.getDiagnostics();
+  unsigned ID = D.getCustomDiagID(
+DiagnosticsEngine::Error,
+"#pragma enable_annotate not allowed after declarations");
+  D.Report(PragmaTok.getLocation(), ID);
+}
+
+EnableAnnotate = true;
+  }
+};
+
 }
 
 static FrontendPluginRegistry::Add
 X("annotate-fns", "annotate functions");
+
+static PragmaHandlerRegistry::Add
+Y("enable_annotate","enable annotation");

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=265295&r1=265294&r2=265295&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Mon Apr  4 09:22:58 2016
@@ -32,6 +32,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/Support/Allocator.h"
+#include "llvm/Support/Registry.h"
 #include 
 #include 
 
@@ -1937,6 +1938,9 @@ public:
   virtual bool HandleComment(Preprocessor &PP, SourceRange Comment) = 0;
 };
 
+/// \brief Registry of pragma handlers added by plugins
+ty

[PATCH] D20732: Don't use static variables in LambdaCapture

2016-05-27 Thread John Brawn via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: faisalv, rsmith, jyknight.
john.brawn added a subscriber: cfe-commits.
john.brawn set the repository for this revision to rL LLVM.

When static variables are used in inline functions in header files anything 
that uses that function ends up with a reference to the variable. Because 
RecursiveASTVisitor uses the inline functions in LambdaCapture that use static 
variables any AST plugin that uses RecursiveASTVisitor, such as the 
PrintFunctionNames example, ends up with a reference to these variables. This 
is bad on Windows when building with MSVC with 
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON as variables used across a DLL boundary need 
to be explicitly dllimported in the DLL using them.

This patch avoids that by adjusting LambdaCapture to be similar to before 
r263921, with a capture of either 'this' or a VLA represented by a null Decl 
pointer in DeclAndBits with an extra flag added to the bits to distinguish 
between the two. This requires the use of an extra bit, and while Decl does 
happen to be sufficiently aligned to allow this it's done in a way that means 
PointerIntPair doesn't realise it and gives an assertion failure. Therefore I 
also adjust Decl slightly to use LLVM_ALIGNAS to allow this.

Repository:
  rL LLVM

http://reviews.llvm.org/D20732

Files:
  include/clang/AST/DeclBase.h
  include/clang/AST/LambdaCapture.h
  lib/AST/DeclBase.cpp
  lib/AST/ExprCXX.cpp

Index: lib/AST/ExprCXX.cpp
===
--- lib/AST/ExprCXX.cpp
+++ lib/AST/ExprCXX.cpp
@@ -818,13 +818,10 @@
   }
 }
 
-LambdaCapture::OpaqueCapturedEntity LambdaCapture::ThisSentinel;
-LambdaCapture::OpaqueCapturedEntity LambdaCapture::VLASentinel;
-
 LambdaCapture::LambdaCapture(SourceLocation Loc, bool Implicit,
  LambdaCaptureKind Kind, VarDecl *Var,
  SourceLocation EllipsisLoc)
-  : CapturedEntityAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc)
+  : DeclAndBits(Var, 0), Loc(Loc), EllipsisLoc(EllipsisLoc)
 {
   unsigned Bits = 0;
   if (Implicit)
@@ -836,7 +833,7 @@
 // Fall through
   case LCK_This:
 assert(!Var && "'this' capture cannot have a variable!");
-CapturedEntityAndBits.setPointer(&ThisSentinel);
+Bits |= Capture_This;
 break;
 
   case LCK_ByCopy:
@@ -847,19 +844,16 @@
 break;
   case LCK_VLAType:
 assert(!Var && "VLA type capture cannot have a variable!");
-CapturedEntityAndBits.setPointer(&VLASentinel);
 break;
   }
-  CapturedEntityAndBits.setInt(Bits);
+  DeclAndBits.setInt(Bits);
 }
 
 LambdaCaptureKind LambdaCapture::getCaptureKind() const {
-  void *Ptr = CapturedEntityAndBits.getPointer();
-  if (Ptr == &VLASentinel)
+  if (capturesVLAType())
 return LCK_VLAType;
-  const unsigned Bits = CapturedEntityAndBits.getInt();
-  bool CapByCopy = Bits & Capture_ByCopy;
-  if (Ptr == &ThisSentinel)
+  bool CapByCopy = DeclAndBits.getInt() & Capture_ByCopy;
+  if (capturesThis())
 return CapByCopy ? LCK_StarThis : LCK_This;
   return CapByCopy ? LCK_ByCopy : LCK_ByRef;
 }
Index: lib/AST/DeclBase.cpp
===
--- lib/AST/DeclBase.cpp
+++ lib/AST/DeclBase.cpp
@@ -46,7 +46,7 @@
 }
 
 #define DECL(DERIVED, BASE)\
-  static_assert(Decl::DeclObjAlignment >=  \
+  static_assert(llvm::AlignOf::Alignment >=  \
 llvm::AlignOf::Alignment,   \
 "Alignment sufficient after objects prepended to " #DERIVED);
 #define ABSTRACT_DECL(DECL)
@@ -56,7 +56,7 @@
  unsigned ID, std::size_t Extra) {
   // Allocate an extra 8 bytes worth of storage, which ensures that the
   // resulting pointer will still be 8-byte aligned.
-  static_assert(sizeof(unsigned) * 2 >= DeclObjAlignment,
+  static_assert(sizeof(unsigned) * 2 >= llvm::AlignOf::Alignment,
 "Decl won't be misaligned");
   void *Start = Context.Allocate(Size + Extra + 8);
   void *Result = (char*)Start + 8;
@@ -81,7 +81,8 @@
 // Ensure required alignment of the resulting object by adding extra
 // padding at the start if required.
 size_t ExtraAlign =
-llvm::OffsetToAlignment(sizeof(Module *), DeclObjAlignment);
+llvm::OffsetToAlignment(sizeof(Module *),
+llvm::AlignOf::Alignment);
 char *Buffer = reinterpret_cast(
 ::operator new(ExtraAlign + sizeof(Module *) + Size + Extra, Ctx));
 Buffer += ExtraAlign;
Index: include/clang/AST/LambdaCapture.h
===
--- include/clang/AST/LambdaCapture.h
+++ include/clang/AST/LambdaCapture.h
@@ -33,19 +33,21 @@
 /// given capture was by-copy.
 ///
 /// This includes the case of a non-reference init-capture.
-Capture_ByCopy = 0x

Re: [PATCH] D20732: Don't use static variables in LambdaCapture

2016-06-03 Thread John Brawn via cfe-commits
john.brawn added a comment.

Ping


Repository:
  rL LLVM

http://reviews.llvm.org/D20732



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


Re: [PATCH] D20732: Don't use static variables in LambdaCapture

2016-06-08 Thread John Brawn via cfe-commits
john.brawn added a comment.

In http://reviews.llvm.org/D20732#452055, @faisalv wrote:

> I'm assuming you've given some thought to any existing pathological code that 
> might break if the actual compile-time alignment of Decl itself is changed 
> (since currently it seems to be that the alignment requirements are 
> established at run-time and only through allocation via new (not that anyone 
> would be creating Decls on the stack)) - and whether there are any 
> consequences of relevance there...


I can't think of anything that could go wrong because of it. Reducing the 
alignment could cause problems, if there were things that check that the 
alignment is at least some value, but here I'm increasing it. Decl and all of 
its subclasses only have protected or private constructors and the only way to 
create them is through the various XYZDecl::Create methods which go through new 
so there should be no problem there either.


Repository:
  rL LLVM

http://reviews.llvm.org/D20732



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


Re: [PATCH] D20732: Don't use static variables in LambdaCapture

2016-06-14 Thread John Brawn via cfe-commits
john.brawn added a comment.

In http://reviews.llvm.org/D20732#456239, @jyknight wrote:

> This looks okay. The only downside: it will increase sizeof(Decl) on 32bit 
> platforms, since the layout is:
>  vtable ptr (4)
>  NextInContextAndBits ptr (4)
>  DeclCtx ptr (4)
>  Loc int (4)
>  bitfield int (4)
>
> Totaling 20 bytes, which will now be rounded up to 24 bytes. I don't know how 
> others feel, but it seems probably fine to me? On 64-bit platforms, it's 
> already 32 bytes, and that won't be affected.


I did an experiment compiling the top 5 largest llvm/clang source files with 
and without this patch and got the following numbers for "Maximum resident set 
size (kbytes)" reported by time -v

| **Source File** | **Before**  | **After**   | **Change**   |
| X86ISelLowering.cpp | 679824 +/- 28   | 679897 +/- 271  | 73 (0.01%)   |
| SemaDecl.cpp| 705379 +/- 440  | 705590 +/- 77   | 211 (0.03%)  |
| SemaExpr.cpp| 950729 +/- 6910 | 951654 +/- 5834 | 925 (0.10%)  |
| DAGCombiner.cpp | 443673 +/- 38   | 443721 +/- 16   | 48 (0.01%)   |
| SemaDeclCXX.cpp | 850441 +/- 4531 | 851891 +/- 5079 | 1450 (0.17%) |

I think a <0.2% increase in memory usage is fine.


Repository:
  rL LLVM

http://reviews.llvm.org/D20732



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


r272788 - Don't use static variables in LambdaCapture

2016-06-15 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Wed Jun 15 09:14:51 2016
New Revision: 272788

URL: http://llvm.org/viewvc/llvm-project?rev=272788&view=rev
Log:
Don't use static variables in LambdaCapture

When static variables are used in inline functions in header files anything that
uses that function ends up with a reference to the variable. Because
RecursiveASTVisitor uses the inline functions in LambdaCapture that use static
variables any AST plugin that uses RecursiveASTVisitor, such as the
PrintFunctionNames example, ends up with a reference to these variables. This is
bad on Windows when building with MSVC with LLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON
as variables used across a DLL boundary need to be explicitly dllimported in
the DLL using them.

This patch avoids that by adjusting LambdaCapture to be similar to before
r263921, with a capture of either 'this' or a VLA represented by a null Decl
pointer in DeclAndBits with an extra flag added to the bits to distinguish
between the two. This requires the use of an extra bit, and while Decl does
happen to be sufficiently aligned to allow this it's done in a way that means
PointerIntPair doesn't realise it and gives an assertion failure. Therefore I
also adjust Decl slightly to use LLVM_ALIGNAS to allow this.

Differential Revision: http://reviews.llvm.org/D20732

Modified:
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/AST/LambdaCapture.h
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/AST/ExprCXX.cpp

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=272788&r1=272787&r2=272788&view=diff
==
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Wed Jun 15 09:14:51 2016
@@ -73,13 +73,10 @@ namespace clang {
 ///
 /// Note: There are objects tacked on before the *beginning* of Decl
 /// (and its subclasses) in its Decl::operator new(). Proper alignment
-/// of all subclasses (not requiring more than DeclObjAlignment) is
+/// of all subclasses (not requiring more than the alignment of Decl) is
 /// asserted in DeclBase.cpp.
-class Decl {
+class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl {
 public:
-  /// \brief Alignment guaranteed when allocating Decl and any subtypes.
-  enum { DeclObjAlignment = llvm::AlignOf::Alignment };
-
   /// \brief Lists the kind of concrete classes of Decl.
   enum Kind {
 #define DECL(DERIVED, BASE) DERIVED,

Modified: cfe/trunk/include/clang/AST/LambdaCapture.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/LambdaCapture.h?rev=272788&r1=272787&r2=272788&view=diff
==
--- cfe/trunk/include/clang/AST/LambdaCapture.h (original)
+++ cfe/trunk/include/clang/AST/LambdaCapture.h Wed Jun 15 09:14:51 2016
@@ -33,19 +33,21 @@ class LambdaCapture {
 /// given capture was by-copy.
 ///
 /// This includes the case of a non-reference init-capture.
-Capture_ByCopy = 0x02
+Capture_ByCopy = 0x02,
+
+/// \brief Flag used by the Capture class to distinguish between a capture
+/// of '*this' and a capture of a VLA type.
+Capture_This = 0x04
   };
-  struct LLVM_ALIGNAS(4) OpaqueCapturedEntity {};
-  static OpaqueCapturedEntity ThisSentinel;
-  static OpaqueCapturedEntity VLASentinel;
-  
-  // Captured Entity could represent:
+
+  // Decl could represent:
   // - a VarDecl* that represents the variable that was captured or the 
   //   init-capture.
-  // - or, points to the ThisSentinel if this represents a capture of '*this'
-  //   by value or reference.
-  // - or, points to the VLASentinel if this represents a capture of a VLA 
type.
-  llvm::PointerIntPair CapturedEntityAndBits;
+  // - or, is a nullptr and Capture_This is set in Bits if this represents a
+  //   capture of '*this' by value or reference.
+  // - or, is a nullptr and Capture_This is not set in Bits if this represents
+  //   a capture of a VLA type.
+  llvm::PointerIntPair DeclAndBits;
 
   SourceLocation Loc;
   SourceLocation EllipsisLoc;
@@ -79,21 +81,20 @@ public:
   /// \brief Determine whether this capture handles the C++ \c this
   /// pointer.
   bool capturesThis() const {
-return CapturedEntityAndBits.getPointer() == &ThisSentinel;
+return DeclAndBits.getPointer() == nullptr &&
+  (DeclAndBits.getInt() & Capture_This);
   }
 
   /// \brief Determine whether this capture handles a variable.
   bool capturesVariable() const {
-void *Ptr = CapturedEntityAndBits.getPointer();
-if (Ptr != &ThisSentinel && Ptr != &VLASentinel)
-  return dyn_cast_or_null(static_cast(Ptr));
-return false;
+return dyn_cast_or_null(DeclAndBits.getPointer());
   }
 
   /// \brief Determine whether this captures a variable length array bound
   /// expression.
   bool capturesVLAType() const {
-return CapturedEntityAndBits.g

Re: [PATCH] D20732: Don't use static variables in LambdaCapture

2016-06-15 Thread John Brawn via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL272788: Don't use static variables in LambdaCapture 
(authored by john.brawn).

Changed prior to commit:
  http://reviews.llvm.org/D20732?vs=58787&id=60831#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20732

Files:
  cfe/trunk/include/clang/AST/DeclBase.h
  cfe/trunk/include/clang/AST/LambdaCapture.h
  cfe/trunk/lib/AST/DeclBase.cpp
  cfe/trunk/lib/AST/ExprCXX.cpp

Index: cfe/trunk/include/clang/AST/LambdaCapture.h
===
--- cfe/trunk/include/clang/AST/LambdaCapture.h
+++ cfe/trunk/include/clang/AST/LambdaCapture.h
@@ -33,19 +33,21 @@
 /// given capture was by-copy.
 ///
 /// This includes the case of a non-reference init-capture.
-Capture_ByCopy = 0x02
+Capture_ByCopy = 0x02,
+
+/// \brief Flag used by the Capture class to distinguish between a capture
+/// of '*this' and a capture of a VLA type.
+Capture_This = 0x04
   };
-  struct LLVM_ALIGNAS(4) OpaqueCapturedEntity {};
-  static OpaqueCapturedEntity ThisSentinel;
-  static OpaqueCapturedEntity VLASentinel;
-  
-  // Captured Entity could represent:
+
+  // Decl could represent:
   // - a VarDecl* that represents the variable that was captured or the 
   //   init-capture.
-  // - or, points to the ThisSentinel if this represents a capture of '*this'
-  //   by value or reference.
-  // - or, points to the VLASentinel if this represents a capture of a VLA type.
-  llvm::PointerIntPair CapturedEntityAndBits;
+  // - or, is a nullptr and Capture_This is set in Bits if this represents a
+  //   capture of '*this' by value or reference.
+  // - or, is a nullptr and Capture_This is not set in Bits if this represents
+  //   a capture of a VLA type.
+  llvm::PointerIntPair DeclAndBits;
 
   SourceLocation Loc;
   SourceLocation EllipsisLoc;
@@ -79,21 +81,20 @@
   /// \brief Determine whether this capture handles the C++ \c this
   /// pointer.
   bool capturesThis() const {
-return CapturedEntityAndBits.getPointer() == &ThisSentinel;
+return DeclAndBits.getPointer() == nullptr &&
+  (DeclAndBits.getInt() & Capture_This);
   }
 
   /// \brief Determine whether this capture handles a variable.
   bool capturesVariable() const {
-void *Ptr = CapturedEntityAndBits.getPointer();
-if (Ptr != &ThisSentinel && Ptr != &VLASentinel)
-  return dyn_cast_or_null(static_cast(Ptr));
-return false;
+return dyn_cast_or_null(DeclAndBits.getPointer());
   }
 
   /// \brief Determine whether this captures a variable length array bound
   /// expression.
   bool capturesVLAType() const {
-return CapturedEntityAndBits.getPointer() == &VLASentinel;
+return DeclAndBits.getPointer() == nullptr &&
+   !(DeclAndBits.getInt() & Capture_This);
   }
 
   /// \brief Retrieve the declaration of the local variable being
@@ -103,13 +104,13 @@
   /// (other than a capture of \c this).
   VarDecl *getCapturedVar() const {
 assert(capturesVariable() && "No variable available for capture");
-return static_cast(CapturedEntityAndBits.getPointer());
+return static_cast(DeclAndBits.getPointer());
   }
 
   /// \brief Determine whether this was an implicit capture (not
   /// written between the square brackets introducing the lambda).
   bool isImplicit() const {
-return CapturedEntityAndBits.getInt() & Capture_Implicit;
+return DeclAndBits.getInt() & Capture_Implicit;
   }
 
   /// \brief Determine whether this was an explicit capture (written
Index: cfe/trunk/include/clang/AST/DeclBase.h
===
--- cfe/trunk/include/clang/AST/DeclBase.h
+++ cfe/trunk/include/clang/AST/DeclBase.h
@@ -73,13 +73,10 @@
 ///
 /// Note: There are objects tacked on before the *beginning* of Decl
 /// (and its subclasses) in its Decl::operator new(). Proper alignment
-/// of all subclasses (not requiring more than DeclObjAlignment) is
+/// of all subclasses (not requiring more than the alignment of Decl) is
 /// asserted in DeclBase.cpp.
-class Decl {
+class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) Decl {
 public:
-  /// \brief Alignment guaranteed when allocating Decl and any subtypes.
-  enum { DeclObjAlignment = llvm::AlignOf::Alignment };
-
   /// \brief Lists the kind of concrete classes of Decl.
   enum Kind {
 #define DECL(DERIVED, BASE) DERIVED,
Index: cfe/trunk/lib/AST/ExprCXX.cpp
===
--- cfe/trunk/lib/AST/ExprCXX.cpp
+++ cfe/trunk/lib/AST/ExprCXX.cpp
@@ -808,13 +808,10 @@
   }
 }
 
-LambdaCapture::OpaqueCapturedEntity LambdaCapture::ThisSentinel;
-LambdaCapture::OpaqueCapturedEntity LambdaCapture::VLASentinel;
-
 LambdaCapture::LambdaCapture(SourceLocation Loc, bool Implicit,
  LambdaCaptureKind Kind, VarDecl *Var,
  SourceLocation EllipsisLoc)
-  : CapturedEntityAndBits(Var,

[PATCH] D21385: Adjust Registry interface to not require plugins to export a registry

2016-06-15 Thread John Brawn via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: ehsan, reames, chapuni.
john.brawn added subscribers: llvm-commits, cfe-commits.
john.brawn set the repository for this revision to rL LLVM.
Herald added a subscriber: klimek.

Currently the Registry class contains the vestiges of a previous attempt to 
allow plugins to be used on Windows without using BUILD_SHARED_LIBS, where a 
plugin would have its own copy of a registry and export it to be imported by 
the tool that's loading the plugin. This only works if the plugin is entirely 
self-contained with the only interface between the plugin and tool being the 
registry, and in particular this conflicts with how IR pass plugins work.

This patch changes things so that instead the add_node function of the registry 
is exported by the tool and then imported by the plugin, which solves this 
problem and also means that instead of every plugin having to export every 
registry they use instead LLVM only has to export the add_node functions. This 
allows plugins that use a registry to work on Windows if 
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS is used.


Repository:
  rL LLVM

http://reviews.llvm.org/D21385

Files:
  cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
  cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
  cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
  cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
  cfe/trunk/include/clang/Lex/Preprocessor.h
  cfe/trunk/lib/Frontend/FrontendAction.cpp
  cfe/trunk/lib/Lex/Preprocessor.cpp
  cfe/trunk/lib/Tooling/CompilationDatabase.cpp
  llvm/trunk/include/llvm/Support/Registry.h
  llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
  llvm/trunk/lib/CodeGen/GCStrategy.cpp

Index: llvm/trunk/lib/CodeGen/GCStrategy.cpp
===
--- llvm/trunk/lib/CodeGen/GCStrategy.cpp
+++ llvm/trunk/lib/CodeGen/GCStrategy.cpp
@@ -16,6 +16,8 @@
 
 using namespace llvm;
 
+LLVM_INSTANTIATE_REGISTRY(GCRegistry)
+
 GCStrategy::GCStrategy()
 : UseStatepoints(false), NeededSafePoints(0), CustomReadBarriers(false),
   CustomWriteBarriers(false), CustomRoots(false), InitRoots(true),
Index: llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
===
--- llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
+++ llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
@@ -14,6 +14,8 @@
 #include "llvm/CodeGen/GCMetadataPrinter.h"
 using namespace llvm;
 
+LLVM_INSTANTIATE_REGISTRY(GCMetadataPrinterRegistry)
+
 GCMetadataPrinter::GCMetadataPrinter() {}
 
 GCMetadataPrinter::~GCMetadataPrinter() {}
Index: llvm/trunk/include/llvm/Support/Registry.h
===
--- llvm/trunk/include/llvm/Support/Registry.h
+++ llvm/trunk/include/llvm/Support/Registry.h
@@ -69,13 +69,14 @@
   node(const entry &V) : Next(nullptr), Val(V) {}
 };
 
-static void add_node(node *N) {
-  if (Tail)
-Tail->Next = N;
-  else
-Head = N;
-  Tail = N;
-}
+/// Add a node to the Registry: this is the interface between the plugin and
+/// the executable.
+///
+/// This function is exported by the executable and called by the plugin to
+/// add a node to the executable's registry. Therefore it's not defined here
+/// to avoid it being instantiated in the plugin and is instead defined in
+/// the executable (see LLVM_INSTANTIATE_REGISTRY below).
+static void add_node(node *N);
 
 /// Iterators for registry entries.
 ///
@@ -120,61 +121,23 @@
 add_node(&Node);
   }
 };
-
-/// A dynamic import facility.  This is used on Windows to
-/// import the entries added in the plugin.
-static void import(sys::DynamicLibrary &DL, const char *RegistryName) {
-  typedef void *(*GetRegistry)();
-  std::string Name("LLVMGetRegistry_");
-  Name.append(RegistryName);
-  GetRegistry Getter =
-  (GetRegistry)(intptr_t)DL.getAddressOfSymbol(Name.c_str());
-  if (Getter) {
-// Call the getter function in order to get the full copy of the
-// registry defined in the plugin DLL, and copy them over to the
-// current Registry.
-typedef std::pair Info;
-Info *I = static_cast(Getter());
-iterator begin(I->first);
-iterator end(I->second);
-for (++end; begin != end; ++begin) {
-  // This Node object needs to remain alive for the
-  // duration of the program.
-  add_node(new node(*begin));
-}
-  }
-}
-
-/// Retrieve the data to be passed across DLL boundaries when
-/// importing registries from another DLL on Windows.
-static void *exportRegistry() {
-  static std::pair Info(Head, Tail);
-  return &Info;
-}
   };
-
-  
-  // Since these are defined in a header file, plugins must be sure to export
-  // these symbols.
-  template 
-  typename Registry::node *Registry::Head;
-
-  te

Re: [PATCH] D21611: Fix small structures calling convention issue for some big endian architectures

2016-06-23 Thread John Brawn via cfe-commits
john.brawn accepted this revision.
john.brawn added a comment.

Looks OK from the ARM side as well.


http://reviews.llvm.org/D21611



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


Re: [PATCH] D21385: Adjust Registry interface to not require plugins to export a registry

2016-06-23 Thread John Brawn via cfe-commits
john.brawn added a comment.

Ping.


Repository:
  rL LLVM

http://reviews.llvm.org/D21385



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


Re: [PATCH] D21385: Adjust Registry interface to not require plugins to export a registry

2016-06-30 Thread John Brawn via cfe-commits
john.brawn added a comment.

Ping


Repository:
  rL LLVM

http://reviews.llvm.org/D21385



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


Re: [PATCH] D21385: Adjust Registry interface to not require plugins to export a registry

2016-07-01 Thread John Brawn via cfe-commits
john.brawn added a comment.

In http://reviews.llvm.org/D21385#471807, @Ilod wrote:

> I gave up after this. I have Pyhton 3.5 64 bits, and was building clang 
> 32-bits on Windows with Visual Studio 2015 Update 2.


python 3 isn't supported when building llvm/clang, according to llvm's 
CMakeLists.txt.

> If that's all, I suppose it's better to have your limitation to plugin 
> support rather than a full support which will bug if you call a function that 
> accesses a static member.

> 

> (By the way, the previous attempt works fine, it was reverted because of a 
> mingw crash which can be fixed by the patch http://reviews.llvm.org/D18847)

> 

> However, couldn't we enable by default LLVM_EXPORT_SYMBOLS_FOR_PLUGINS on the 
> platforms/compilers which doesn't currently support the plugins? Having 
> plugins only work on custom builds of clang seems to be against the main use 
> of plugins. (If testing is the only problem, I would gladly test it on 
> Windows with mingw, and maybe Mac if needed)


After this patch goes in I plan to email llvm-dev/cfe-dev to see if people 
think that's a good idea.

> Also, could you add in the documentation (cfe/trunk/docs/ClangPlugins.rst) 
> what are the limitations/setup needed to make an out-of-tree plugin?


Will do.


Repository:
  rL LLVM

http://reviews.llvm.org/D21385



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


Re: [PATCH] D21385: Adjust Registry interface to not require plugins to export a registry

2016-07-01 Thread John Brawn via cfe-commits
john.brawn added a comment.

> http://clang.llvm.org/get_started.html doesn't specify a version of Python, 
> the LLVM webpage only say >= 2.7, and I ran the tests without any problem 
> with Python 3 (but maybe some tests were automatically skipped?). Also, 
> Python is also marked as only necessary to build the tests, which is no 
> longer true with your script.


Hmm, it looks like this webpage (and 
http://llvm.org/docs/GettingStarted.html#requirements) has been out of date 
since 2011 (commits r143742 and r143793), when python started being necessary 
always as it's used to run llvm-build. Python 3 not being supported appears to 
come from commit r184732 which just says "All of LLVM's Python scripts only 
support Python 2 for widely understood reasons", though I must confess I don't 
know what those reasons are. I'll look into making extract_symbols.py work with 
python 3, though I haven't touched python 3 before now so I don't know how much 
luck I'll have.


Repository:
  rL LLVM

http://reviews.llvm.org/D21385



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


Re: [PATCH] D21385: Adjust Registry interface to not require plugins to export a registry

2016-07-01 Thread John Brawn via cfe-commits
john.brawn added a comment.

Commit r274365 should make extract_symbols.py work with Python 3.


Repository:
  rL LLVM

http://reviews.llvm.org/D21385



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


Re: [PATCH] D21385: Adjust Registry interface to not require plugins to export a registry

2016-07-04 Thread John Brawn via cfe-commits
john.brawn added a comment.

In http://reviews.llvm.org/D21385#473163, @Ilod wrote:

> The PrintFunctionNames plugin works fine, but not the SampleAnalyzerPlugin? 
> The checker-plugins test fails.


Argh, I hadn't noticed that the plugin tests depend on the 'plugins' feature, 
and lit.cfg sets that based only based on BUILD_SHARED_LIBS, so I've 
accidentally been failing to run the tests. Thanks for noticing this.


Repository:
  rL LLVM

http://reviews.llvm.org/D21385



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


[PATCH] D21971: Explicitly export symbols from the sample analyzer plugin

2016-07-04 Thread John Brawn via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: Ilod, chapuni, ehsan, reames.
john.brawn added a subscriber: cfe-commits.
john.brawn set the repository for this revision to rL LLVM.

This is done so that it will work when built using MSVC if 
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON.

Repository:
  rL LLVM

http://reviews.llvm.org/D21971

Files:
  examples/analyzer-plugin/CMakeLists.txt
  examples/analyzer-plugin/SampleAnalyzerPlugin.exports

Index: examples/analyzer-plugin/SampleAnalyzerPlugin.exports
===
--- /dev/null
+++ examples/analyzer-plugin/SampleAnalyzerPlugin.exports
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
Index: examples/analyzer-plugin/CMakeLists.txt
===
--- examples/analyzer-plugin/CMakeLists.txt
+++ examples/analyzer-plugin/CMakeLists.txt
@@ -1,4 +1,5 @@
-add_llvm_loadable_module(SampleAnalyzerPlugin MainCallChecker.cpp)
+set(LLVM_EXPORTED_SYMBOL_FILE 
${CMAKE_CURRENT_SOURCE_DIR}/SampleAnalyzerPlugin.exports)
+add_llvm_loadable_module(SampleAnalyzerPlugin MainCallChecker.cpp PLUGIN_TOOL 
clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(SampleAnalyzerPlugin PRIVATE


Index: examples/analyzer-plugin/SampleAnalyzerPlugin.exports
===
--- /dev/null
+++ examples/analyzer-plugin/SampleAnalyzerPlugin.exports
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
Index: examples/analyzer-plugin/CMakeLists.txt
===
--- examples/analyzer-plugin/CMakeLists.txt
+++ examples/analyzer-plugin/CMakeLists.txt
@@ -1,4 +1,5 @@
-add_llvm_loadable_module(SampleAnalyzerPlugin MainCallChecker.cpp)
+set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/SampleAnalyzerPlugin.exports)
+add_llvm_loadable_module(SampleAnalyzerPlugin MainCallChecker.cpp PLUGIN_TOOL clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(SampleAnalyzerPlugin PRIVATE
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21385: Adjust Registry interface to not require plugins to export a registry

2016-07-04 Thread John Brawn via cfe-commits
john.brawn added a comment.

Created http://reviews.llvm.org/D21971 to make the sample analyzer plugin work.


Repository:
  rL LLVM

http://reviews.llvm.org/D21385



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


Re: [PATCH] D21385: Adjust Registry interface to not require plugins to export a registry

2016-07-04 Thread John Brawn via cfe-commits
john.brawn updated this revision to Diff 62684.
john.brawn added a comment.

Updated to not touch the sample analyzer plugin.


Repository:
  rL LLVM

http://reviews.llvm.org/D21385

Files:
  cfe/trunk/examples/AnnotateFunctions/CMakeLists.txt
  cfe/trunk/examples/PrintFunctionNames/CMakeLists.txt
  cfe/trunk/include/clang/Frontend/FrontendPluginRegistry.h
  cfe/trunk/include/clang/Lex/Preprocessor.h
  cfe/trunk/lib/Frontend/FrontendAction.cpp
  cfe/trunk/lib/Lex/Preprocessor.cpp
  cfe/trunk/lib/Tooling/CompilationDatabase.cpp
  llvm/trunk/include/llvm/Support/Registry.h
  llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
  llvm/trunk/lib/CodeGen/GCStrategy.cpp

Index: llvm/trunk/lib/CodeGen/GCStrategy.cpp
===
--- llvm/trunk/lib/CodeGen/GCStrategy.cpp
+++ llvm/trunk/lib/CodeGen/GCStrategy.cpp
@@ -16,6 +16,8 @@
 
 using namespace llvm;
 
+LLVM_INSTANTIATE_REGISTRY(GCRegistry)
+
 GCStrategy::GCStrategy()
 : UseStatepoints(false), NeededSafePoints(0), CustomReadBarriers(false),
   CustomWriteBarriers(false), CustomRoots(false), InitRoots(true),
Index: llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
===
--- llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
+++ llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
@@ -14,6 +14,8 @@
 #include "llvm/CodeGen/GCMetadataPrinter.h"
 using namespace llvm;
 
+LLVM_INSTANTIATE_REGISTRY(GCMetadataPrinterRegistry)
+
 GCMetadataPrinter::GCMetadataPrinter() {}
 
 GCMetadataPrinter::~GCMetadataPrinter() {}
Index: llvm/trunk/include/llvm/Support/Registry.h
===
--- llvm/trunk/include/llvm/Support/Registry.h
+++ llvm/trunk/include/llvm/Support/Registry.h
@@ -69,13 +69,14 @@
   node(const entry &V) : Next(nullptr), Val(V) {}
 };
 
-static void add_node(node *N) {
-  if (Tail)
-Tail->Next = N;
-  else
-Head = N;
-  Tail = N;
-}
+/// Add a node to the Registry: this is the interface between the plugin and
+/// the executable.
+///
+/// This function is exported by the executable and called by the plugin to
+/// add a node to the executable's registry. Therefore it's not defined here
+/// to avoid it being instantiated in the plugin and is instead defined in
+/// the executable (see LLVM_INSTANTIATE_REGISTRY below).
+static void add_node(node *N);
 
 /// Iterators for registry entries.
 ///
@@ -120,61 +121,23 @@
 add_node(&Node);
   }
 };
-
-/// A dynamic import facility.  This is used on Windows to
-/// import the entries added in the plugin.
-static void import(sys::DynamicLibrary &DL, const char *RegistryName) {
-  typedef void *(*GetRegistry)();
-  std::string Name("LLVMGetRegistry_");
-  Name.append(RegistryName);
-  GetRegistry Getter =
-  (GetRegistry)(intptr_t)DL.getAddressOfSymbol(Name.c_str());
-  if (Getter) {
-// Call the getter function in order to get the full copy of the
-// registry defined in the plugin DLL, and copy them over to the
-// current Registry.
-typedef std::pair Info;
-Info *I = static_cast(Getter());
-iterator begin(I->first);
-iterator end(I->second);
-for (++end; begin != end; ++begin) {
-  // This Node object needs to remain alive for the
-  // duration of the program.
-  add_node(new node(*begin));
-}
-  }
-}
-
-/// Retrieve the data to be passed across DLL boundaries when
-/// importing registries from another DLL on Windows.
-static void *exportRegistry() {
-  static std::pair Info(Head, Tail);
-  return &Info;
-}
   };
-
-  
-  // Since these are defined in a header file, plugins must be sure to export
-  // these symbols.
-  template 
-  typename Registry::node *Registry::Head;
-
-  template 
-  typename Registry::node *Registry::Tail;
 } // end namespace llvm
 
-#ifdef LLVM_ON_WIN32
-#define LLVM_EXPORT_REGISTRY(REGISTRY_CLASS)   \
-  extern "C" { \
-  __declspec(dllexport) void *__cdecl LLVMGetRegistry_##REGISTRY_CLASS() { \
-return REGISTRY_CLASS::exportRegistry();   \
-  }\
+/// Instantiate a registry class.
+///
+/// This instantiates add_node and the Head and Tail pointers.
+#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
+  namespace llvm { \
+  template<> void REGISTRY_CLASS::add_node(REGISTRY_CLASS::node *N) { \
+if (Tail) \
+ Tail->Next = N; \
+else \
+  Head = N; \
+Tail = N; \
+  } \
+  template<> typename REGISTRY_CLASS::node *REGISTRY_CLASS::Head = nullptr; \
+  template<> typename REGISTRY_CLASS::node *REGISTRY_CLASS::Tail = nullptr; \
   }
-#define LLVM_IMPORT

Re: [PATCH] D21971: Explicitly export symbols from the sample analyzer plugin

2016-07-08 Thread John Brawn via cfe-commits
john.brawn added a comment.

> Do you known if there is any good reason Analyzer plugins aren't using the 
> Registry system (thus forcing plugin writers to manually export the 
> functions)?


Your guess is as good as mine.


Repository:
  rL LLVM

http://reviews.llvm.org/D21971



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


r274871 - Explicitly export symbols from the sample analyzer plugin

2016-07-08 Thread John Brawn via cfe-commits
Author: john.brawn
Date: Fri Jul  8 11:20:57 2016
New Revision: 274871

URL: http://llvm.org/viewvc/llvm-project?rev=274871&view=rev
Log:
Explicitly export symbols from the sample analyzer plugin

This is done so that it will work when built using MSVC if
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON.

Differential Revision: http://reviews.llvm.org/D21971

Added:
cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports
Modified:
cfe/trunk/examples/analyzer-plugin/CMakeLists.txt

Modified: cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/analyzer-plugin/CMakeLists.txt?rev=274871&r1=274870&r2=274871&view=diff
==
--- cfe/trunk/examples/analyzer-plugin/CMakeLists.txt (original)
+++ cfe/trunk/examples/analyzer-plugin/CMakeLists.txt Fri Jul  8 11:20:57 2016
@@ -1,4 +1,5 @@
-add_llvm_loadable_module(SampleAnalyzerPlugin MainCallChecker.cpp)
+set(LLVM_EXPORTED_SYMBOL_FILE 
${CMAKE_CURRENT_SOURCE_DIR}/SampleAnalyzerPlugin.exports)
+add_llvm_loadable_module(SampleAnalyzerPlugin MainCallChecker.cpp PLUGIN_TOOL 
clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(SampleAnalyzerPlugin PRIVATE

Added: cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports?rev=274871&view=auto
==
--- cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports (added)
+++ cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports Fri Jul  8 
11:20:57 2016
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString


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


Re: [PATCH] D21971: Explicitly export symbols from the sample analyzer plugin

2016-07-08 Thread John Brawn via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL274871: Explicitly export symbols from the sample analyzer 
plugin (authored by john.brawn).

Changed prior to commit:
  http://reviews.llvm.org/D21971?vs=62674&id=63248#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D21971

Files:
  cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
  cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports

Index: cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
===
--- cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
+++ cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
@@ -1,4 +1,5 @@
-add_llvm_loadable_module(SampleAnalyzerPlugin MainCallChecker.cpp)
+set(LLVM_EXPORTED_SYMBOL_FILE 
${CMAKE_CURRENT_SOURCE_DIR}/SampleAnalyzerPlugin.exports)
+add_llvm_loadable_module(SampleAnalyzerPlugin MainCallChecker.cpp PLUGIN_TOOL 
clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(SampleAnalyzerPlugin PRIVATE
Index: cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports
===
--- cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports
+++ cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString


Index: cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
===
--- cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
+++ cfe/trunk/examples/analyzer-plugin/CMakeLists.txt
@@ -1,4 +1,5 @@
-add_llvm_loadable_module(SampleAnalyzerPlugin MainCallChecker.cpp)
+set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/SampleAnalyzerPlugin.exports)
+add_llvm_loadable_module(SampleAnalyzerPlugin MainCallChecker.cpp PLUGIN_TOOL clang)
 
 if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN))
   target_link_libraries(SampleAnalyzerPlugin PRIVATE
Index: cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports
===
--- cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports
+++ cfe/trunk/examples/analyzer-plugin/SampleAnalyzerPlugin.exports
@@ -0,0 +1,2 @@
+clang_registerCheckers
+clang_analyzerAPIVersionString
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D22221: Decide whether to enable plugin tests based on cmake variables

2016-07-11 Thread John Brawn via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: ehsan, reames, chapuni, Ilod.
john.brawn added a subscriber: cfe-commits.
john.brawn set the repository for this revision to rL LLVM.

Clang plugins work when either LLVM_ENABLE_PLUGINS or 
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS is ON, so enable the 'plugins' test feature 
when that is the case.


Repository:
  rL LLVM

http://reviews.llvm.org/D1

Files:
  test/lit.cfg
  test/lit.site.cfg.in

Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -7,6 +7,8 @@
 config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
 config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
 config.llvm_shlib_dir = "@SHLIBDIR@"
+config.llvm_enable_plugins = "@LLVM_ENABLE_PLUGINS@"
+config.llvm_export_symbols_for_plugins = "@LLVM_EXPORT_SYMBOLS_FOR_PLUGINS@"
 config.llvm_plugin_ext = "@LLVM_PLUGIN_EXT@"
 config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
 config.clang_obj_root = "@CLANG_BINARY_DIR@"
Index: test/lit.cfg
===
--- test/lit.cfg
+++ test/lit.cfg
@@ -195,12 +195,8 @@
 lit_config.note('using clang: %r' % config.clang)
 
 # Plugins (loadable modules)
-# TODO: This should be supplied by Makefile or autoconf.
-if sys.platform in ['win32', 'cygwin']:
-has_plugins = (config.enable_shared == 1)
-else:
-has_plugins = True
-
+has_plugins = (config.llvm_enable_plugins == "ON" or
+   config.llvm_export_symbols_for_plugins == "ON")
 if has_plugins and config.llvm_plugin_ext:
 config.available_features.add('plugins')
 


Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -7,6 +7,8 @@
 config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
 config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
 config.llvm_shlib_dir = "@SHLIBDIR@"
+config.llvm_enable_plugins = "@LLVM_ENABLE_PLUGINS@"
+config.llvm_export_symbols_for_plugins = "@LLVM_EXPORT_SYMBOLS_FOR_PLUGINS@"
 config.llvm_plugin_ext = "@LLVM_PLUGIN_EXT@"
 config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
 config.clang_obj_root = "@CLANG_BINARY_DIR@"
Index: test/lit.cfg
===
--- test/lit.cfg
+++ test/lit.cfg
@@ -195,12 +195,8 @@
 lit_config.note('using clang: %r' % config.clang)
 
 # Plugins (loadable modules)
-# TODO: This should be supplied by Makefile or autoconf.
-if sys.platform in ['win32', 'cygwin']:
-has_plugins = (config.enable_shared == 1)
-else:
-has_plugins = True
-
+has_plugins = (config.llvm_enable_plugins == "ON" or
+   config.llvm_export_symbols_for_plugins == "ON")
 if has_plugins and config.llvm_plugin_ext:
 config.available_features.add('plugins')
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21385: Adjust Registry interface to not require plugins to export a registry

2016-07-11 Thread John Brawn via cfe-commits
john.brawn added a comment.

> Plugins tests are still disabled by lit.cfg I think, as it only checks for 
> enable_shared, which is disabled. I suppose we could wait for both this and 
> the SampleAnalyzerPlugin to be patched before enabling plugins tests if we 
> have LLVM_EXPORT_SYMBOLS_FOR_PLUGINS, as every plugin test should work after 
> this.


http://reviews.llvm.org/D1 for enabling the tests.

Also: you said LGTM, but didn't mark the review as accepted. OK to commit?


Repository:
  rL LLVM

http://reviews.llvm.org/D21385



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


  1   2   >