r370083 - Change the X86 datalayout to add three address spaces for 32 bit signed,

2019-08-27 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Tue Aug 27 10:46:53 2019
New Revision: 370083

URL: http://llvm.org/viewvc/llvm-project?rev=370083&view=rev
Log:
Change the X86 datalayout to add three address spaces for 32 bit signed,
32 bit unsigned, and 64 bit pointers.

Modified:
cfe/trunk/lib/Basic/Targets/OSTargets.h
cfe/trunk/lib/Basic/Targets/X86.h
cfe/trunk/test/CodeGen/Inputs/thinlto-multi-module.ll
cfe/trunk/test/CodeGen/Inputs/thinlto_backend.ll
cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict1.ll
cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict2.ll
cfe/trunk/test/CodeGen/iamcu-abi.c
cfe/trunk/test/CodeGen/target-data.c
cfe/trunk/test/CodeGen/thinlto-diagnostic-handler-remarks-with-hotness.ll
cfe/trunk/test/CodeGen/thinlto-distributed-backend-skip.ll
cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll
cfe/trunk/test/CodeGen/thinlto-distributed-cfi.ll
cfe/trunk/test/CodeGen/thinlto-distributed.ll
cfe/trunk/test/CodeGen/thinlto-multi-module.ll
cfe/trunk/test/CodeGen/thinlto_backend.ll
cfe/trunk/test/CodeGen/thinlto_backend_local_name_conflict.ll

Modified: cfe/trunk/lib/Basic/Targets/OSTargets.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/OSTargets.h?rev=370083&r1=370082&r2=370083&view=diff
==
--- cfe/trunk/lib/Basic/Targets/OSTargets.h (original)
+++ cfe/trunk/lib/Basic/Targets/OSTargets.h Tue Aug 27 10:46:53 2019
@@ -775,9 +775,11 @@ public:
 if (Triple.getArch() == llvm::Triple::arm) {
   // Handled in ARM's setABI().
 } else if (Triple.getArch() == llvm::Triple::x86) {
-  this->resetDataLayout("e-m:e-p:32:32-i64:64-n8:16:32-S128");
+  this->resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-"
+"i64:64-n8:16:32-S128");
 } else if (Triple.getArch() == llvm::Triple::x86_64) {
-  this->resetDataLayout("e-m:e-p:32:32-i64:64-n8:16:32:64-S128");
+  this->resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-"
+"i64:64-n8:16:32:64-S128");
 } else if (Triple.getArch() == llvm::Triple::mipsel) {
   // Handled on mips' setDataLayout.
 } else {

Modified: cfe/trunk/lib/Basic/Targets/X86.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.h?rev=370083&r1=370082&r2=370083&view=diff
==
--- cfe/trunk/lib/Basic/Targets/X86.h (original)
+++ cfe/trunk/lib/Basic/Targets/X86.h Tue Aug 27 10:46:53 2019
@@ -340,7 +340,8 @@ public:
 LongDoubleWidth = 96;
 LongDoubleAlign = 32;
 SuitableAlign = 128;
-resetDataLayout("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128");
+resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-"
+"f80:32-n8:16:32-S128");
 SizeType = UnsignedInt;
 PtrDiffType = SignedInt;
 IntPtrType = SignedInt;
@@ -440,7 +441,8 @@ public:
   UseSignedCharForObjCBool = false;
 SizeType = UnsignedLong;
 IntPtrType = SignedLong;
-resetDataLayout("e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128");
+resetDataLayout("e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-"
+"f80:128-n8:16:32-S128");
 HasAlignMac68kSupport = true;
   }
 
@@ -465,9 +467,10 @@ public:
 DoubleAlign = LongLongAlign = 64;
 bool IsWinCOFF =
 getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
-resetDataLayout(IsWinCOFF
-? "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
-: "e-m:e-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32");
+resetDataLayout(IsWinCOFF ? "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:"
+"64-i64:64-f80:32-n8:16:32-a:0:32-S32"
+  : "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:"
+"64-i64:64-f80:32-n8:16:32-a:0:32-S32");
   }
 };
 
@@ -515,7 +518,8 @@ public:
   : X86_32TargetInfo(Triple, Opts) {
 this->WCharType = TargetInfo::UnsignedShort;
 DoubleAlign = LongLongAlign = 64;
-resetDataLayout("e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32");
+
resetDataLayout("e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:"
+"32-n8:16:32-a:0:32-S32");
   }
 
   void getTargetDefines(const LangOptions &Opts,
@@ -552,7 +556,8 @@ public:
   : X86_32TargetInfo(Triple, Opts) {
 LongDoubleWidth = 64;
 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
-resetDataLayout("e-m:e-p:32:32-i64:32-f64:32-f128:32-n8:16:32-a:0:32-S32");
+
resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:32-f64:"
+"32-f128:32-n8:16:32-a:0:32-S32");
 WIntType = UnsignedInt;
   }
 
@@ -611,10 +616,12 @@ public:
 RegParmMax = 6;
 
 // Pointers are 32-bit in x32.
-resetDataLayout(

r365357 - Replace temporary variable matches in test since r363952 causes an

2019-07-08 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Mon Jul  8 10:35:28 2019
New Revision: 365357

URL: http://llvm.org/viewvc/llvm-project?rev=365357&view=rev
Log:
Replace temporary variable matches in test since r363952 causes an
extra temporary variable to be created.

Modified:
cfe/trunk/test/CodeGenCXX/cxx2a-compare.cpp

Modified: cfe/trunk/test/CodeGenCXX/cxx2a-compare.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx2a-compare.cpp?rev=365357&r1=365356&r2=365357&view=diff
==
--- cfe/trunk/test/CodeGenCXX/cxx2a-compare.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx2a-compare.cpp Mon Jul  8 10:35:28 2019
@@ -18,9 +18,9 @@
 // CHECK-LABEL: @_Z11test_signedii
 auto test_signed(int x, int y) {
   // CHECK: %[[DEST:retval|agg.result]]
-  // CHECK: %cmp.lt = icmp slt i32 %0, %1
+  // CHECK: %cmp.lt = icmp slt i32 %{{.+}}, %{{.+}}
   // CHECK: %sel.lt = select i1 %cmp.lt, i8 [[LT]], i8 [[GT]]
-  // CHECK: %cmp.eq = icmp eq i32 %0, %1
+  // CHECK: %cmp.eq = icmp eq i32 %{{.+}}, %{{.+}}
   // CHECK: %sel.eq = select i1 %cmp.eq, i8 [[EQ]], i8 %sel.lt
   // CHECK: %__value_ = getelementptr inbounds %[[SO]], %[[SO]]* %[[DEST]]
   // CHECK: store i8 %sel.eq, i8* %__value_, align 1
@@ -31,9 +31,9 @@ auto test_signed(int x, int y) {
 // CHECK-LABEL: @_Z13test_unsignedjj
 auto test_unsigned(unsigned x, unsigned y) {
   // CHECK: %[[DEST:retval|agg.result]]
-  // CHECK: %cmp.lt = icmp ult i32 %0, %1
+  // CHECK: %cmp.lt = icmp ult i32 %{{.+}}, %{{.+}}
   // CHECK: %sel.lt = select i1 %cmp.lt, i8 [[LT]], i8 [[GT]]
-  // CHECK: %cmp.eq = icmp eq i32 %0, %1
+  // CHECK: %cmp.eq = icmp eq i32 %{{.+}}, %{{.+}}
   // CHECK: %sel.eq = select i1 %cmp.eq, i8 [[EQ]], i8 %sel.lt
   // CHECK: %__value_ = getelementptr inbounds %[[SO]], %[[SO]]* %[[DEST]]
   // CHECK: store i8 %sel.eq, i8* %__value_
@@ -44,11 +44,11 @@ auto test_unsigned(unsigned x, unsigned
 // CHECK-LABEL: @_Z10float_testdd
 auto float_test(double x, double y) {
   // CHECK: %[[DEST:retval|agg.result]]
-  // CHECK: %cmp.eq = fcmp oeq double %0, %1
+  // CHECK: %cmp.eq = fcmp oeq double %{{.+}}, %{{.+}}
   // CHECK: %sel.eq = select i1 %cmp.eq, i8 [[EQ]], i8 [[UNORD]]
-  // CHECK: %cmp.gt = fcmp ogt double %0, %1
+  // CHECK: %cmp.gt = fcmp ogt double %{{.+}}, %{{.+}}
   // CHECK: %sel.gt = select i1 %cmp.gt, i8 [[GT]], i8 %sel.eq
-  // CHECK: %cmp.lt = fcmp olt double %0, %1
+  // CHECK: %cmp.lt = fcmp olt double %{{.+}}, %{{.+}}
   // CHECK: %sel.lt = select i1 %cmp.lt, i8 [[LT]], i8 %sel.gt
   // CHECK: %__value_ = getelementptr inbounds %[[PO]], %[[PO]]* %[[DEST]]
   // CHECK: store i8 %sel.lt, i8* %__value_
@@ -59,9 +59,9 @@ auto float_test(double x, double y) {
 // CHECK-LABEL: @_Z8ptr_testPiS_
 auto ptr_test(int *x, int *y) {
   // CHECK: %[[DEST:retval|agg.result]]
-  // CHECK: %cmp.lt = icmp ult i32* %0, %1
+  // CHECK: %cmp.lt = icmp ult i32* %{{.+}}, %{{.+}}
   // CHECK: %sel.lt = select i1 %cmp.lt, i8 [[LT]], i8 [[GT]]
-  // CHECK: %cmp.eq = icmp eq i32* %0, %1
+  // CHECK: %cmp.eq = icmp eq i32* %{{.+}}, %{{.+}}
   // CHECK: %sel.eq = select i1 %cmp.eq, i8 [[EQ]], i8 %sel.lt
   // CHECK: %__value_ = getelementptr inbounds %[[SO]], %[[SO]]* %[[DEST]]
   // CHECK: store i8 %sel.eq, i8* %__value_, align 1
@@ -92,7 +92,7 @@ auto mem_ptr_test(MemPtrT x, MemPtrT y)
 // CHECK-LABEL: @_Z13mem_data_testM6MemPtriS0_
 auto mem_data_test(MemDataT x, MemDataT y) {
   // CHECK: %[[DEST:retval|agg.result]]
-  // CHECK: %[[CMP:.*]] = icmp eq i{{[0-9]+}} %0, %1
+  // CHECK: %[[CMP:.*]] = icmp eq i{{[0-9]+}} %{{.+}}, %{{.+}}
   // CHECK: %sel.eq = select i1 %[[CMP]], i8 [[EQ]], i8 [[NE]]
   // CHECK: %__value_ = getelementptr inbounds %[[SE]], %[[SE]]* %[[DEST]]
   // CHECK: store i8 %sel.eq, i8* %__value_, align 1
@@ -114,7 +114,7 @@ auto test_constant() {
 // CHECK-LABEL: @_Z16test_nullptr_objPiDn
 auto test_nullptr_obj(int* x, decltype(nullptr) y) {
   // CHECK: %[[DEST:retval|agg.result]]
-  // CHECK: %cmp.eq = icmp eq i32* %0, null
+  // CHECK: %cmp.eq = icmp eq i32* %{{.+}}, null
   // CHECK: %sel.eq = select i1 %cmp.eq, i8 [[EQ]], i8 [[NE]]
   // CHECK: %__value_ = getelementptr inbounds %[[SE]], %[[SE]]* %[[DEST]]
   // CHECK: store i8 %sel.eq, i8* %__value_, align 1


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


[clang] f71deb4 - [DebugInfo] Fix to ctor homing to ignore classes with trivial ctors.

2020-07-29 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-07-29T19:55:20-07:00
New Revision: f71deb43abea588901c083d3e6d6d25371b486ae

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

LOG: [DebugInfo] Fix to ctor homing to ignore classes with trivial ctors.

Previously ctor homing was omitting debug info for classes if they
have both trival and nontrivial constructors, but we should only omit debug
info if the class doesn't have any trivial constructors.

retained types list.

bug: https://bugs.llvm.org/show_bug.cgi?id=46537

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

Added: 


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

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 780e0c692c05..461f2eee965d 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2296,12 +2296,19 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
   // In constructor debug mode, only emit debug info for a class when its
   // constructor is emitted. Skip this optimization if the class or any of
   // its methods are marked dllimport.
+  //
+  // This applies to classes that don't have any trivial constructors and have
+  // at least one constructor.
   if (DebugKind == codegenoptions::DebugInfoConstructor &&
   !CXXDecl->isLambda() && !CXXDecl->hasConstexprNonCopyMoveConstructor() &&
-  !isClassOrMethodDLLImport(CXXDecl))
+  !isClassOrMethodDLLImport(CXXDecl)) {
+if (CXXDecl->ctors().empty())
+  return false;
 for (const auto *Ctor : CXXDecl->ctors())
-  if (Ctor->isUserProvided())
-return true;
+  if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
+return false;
+return true;
+  }
 
   TemplateSpecializationKind Spec = TSK_Undeclared;
   if (const auto *SD = dyn_cast(RD))

diff  --git a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp 
b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
index 25b4ebdb54a3..89dd2b16b75b 100644
--- a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
+++ b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -24,3 +24,10 @@ D::D() {}
 struct E {
   constexpr E(){};
 } TestE;
+
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"F"{{.*}}DIFlagTypePassByValue
+struct F {
+  F() = default;
+  F(int) {}
+  int i;
+} TestF;



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


[clang] ae6523c - [DebugInfo] Add -fuse-ctor-homing cc1 flag so we can turn on constructor homing only if limited debug info is already on.

2020-08-13 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-08-13T15:48:55-07:00
New Revision: ae6523cd62a44642390f4f9d9ba9ce17d5bbbc58

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

LOG: [DebugInfo] Add -fuse-ctor-homing cc1 flag so we can turn on constructor 
homing only if limited debug info is already on.

This adds a cc1 flag to enable constructor homing but doesn't turn on debug
info if it wasn't enabled already (which is what using
-debug-info-kind=constructor does). This will be used for testing, and won't
be needed anymore once ctor homing is used as default / merged into =limited.

Bug to enable ctor homing: https://bugs.llvm.org/show_bug.cgi?id=46537

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

Added: 
clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 99a2ec7ad2d4..9d36dc6cc393 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3691,6 +3691,8 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   AutoNormalizeEnum;
 def fno_math_builtin : Flag<["-"], "fno-math-builtin">,
   HelpText<"Disable implicit builtin knowledge of math functions">;
+def fuse_ctor_homing: Flag<["-"], "fuse-ctor-homing">,
+HelpText<"Use constructor homing if we are using limited debug info 
already">;
 }
 
 def disable_llvm_verifier : Flag<["-"], "disable-llvm-verifier">,

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 17c43ec55c79..86504ed9f92b 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -775,6 +775,12 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList 
&Args, InputKind IK,
 else
   Opts.setDebugInfo(static_cast(Val));
   }
+  // If -fuse-ctor-homing is set and limited debug info is already on, then use
+  // constructor homing.
+  if (Arg *A = Args.getLastArg(OPT_fuse_ctor_homing))
+if (Opts.getDebugInfo() == codegenoptions::LimitedDebugInfo)
+  Opts.setDebugInfo(codegenoptions::DebugInfoConstructor);
+
   if (Arg *A = Args.getLastArg(OPT_debugger_tuning_EQ)) {
 unsigned Val = llvm::StringSwitch(A->getValue())
.Case("gdb", unsigned(llvm::DebuggerKind::GDB))

diff  --git a/clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp 
b/clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp
new file mode 100644
index ..5443fa9ade23
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang -cc1 -debug-info-kind=constructor -emit-llvm %s -o - \
+// RUN:| FileCheck %s -check-prefix=CTOR_HOMING
+// RUN: %clang -cc1 -debug-info-kind=limited -fuse-ctor-homing -emit-llvm %s 
-o - \
+// RUN:| FileCheck %s -check-prefix=CTOR_HOMING
+// RUN: %clang -cc1 -debug-info-kind=standalone -fuse-ctor-homing -emit-llvm 
%s -o - \
+// RUN:| FileCheck %s -check-prefix=FULL_DEBUG
+// RUN: %clang -cc1 -debug-info-kind=line-tables-only -fuse-ctor-homing 
-emit-llvm %s -o - \
+// RUN:| FileCheck %s -check-prefix=NO_DEBUG
+// RUN: %clang -cc1 -fuse-ctor-homing -emit-llvm %s -o - \
+// RUN:| FileCheck %s -check-prefix=NO_DEBUG
+
+// This tests that the -fuse-ctor-homing is only used if limited debug info 
would have
+// been used otherwise.
+
+// CTOR_HOMING: !DICompositeType(tag: DW_TAG_structure_type, name: 
"A"{{.*}}flags: DIFlagFwdDecl
+// FULL_DEBUG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"A"{{.*}}DIFlagTypePassByValue
+// NO_DEBUG-NOT: !DICompositeType(tag: DW_TAG_structure_type, name: "A"
+struct A {
+  A();
+} TestA;



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


[clang] 227db86 - Switch to using -debug-info-kind=constructor as default (from =limited)

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

Author: Amy Huang
Date: 2020-07-09T15:26:46-07:00
New Revision: 227db86a1b7dd6f96f7df14890fcd071bc4fe1f5

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

LOG: Switch to using -debug-info-kind=constructor as default (from =limited)

Summary:
-debug-info-kind=constructor reduces the amount of class debug info that
is emitted; this patch switches to using this as the default.

Constructor homing emits the complete type info for a class only when the
constructor is emitted, so it is expected that there will be some classes that
are not defined in the debug info anymore because they are never constructed,
and we shouldn't need debug info for these classes.

I compared the PDB files for clang, and there are 273 class types that are 
defined with `=limited`
but not with `=constructor` (out of ~60,000 total class types).
We've looked at a number of the types that are no longer defined with 
=constructor. The vast
majority of cases are something like class A is used as a parameter in a member 
function of
some other class B, which is emitted. But the function that uses class A is 
never called, and class A
is never constructed, and therefore isn't emitted in the debug info.

Bug: https://bugs.llvm.org/show_bug.cgi?id=46537

Subscribers: aprantl, cfe-commits, lldb-commits

Tags: #clang, #lldb

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-options.c
clang/test/Driver/clang-g-opts.c
clang/test/Driver/cuda-dwarf-2.cu
clang/test/Driver/debug-options-as.c
clang/test/Driver/debug-options.c
clang/test/Driver/integrated-as.s
clang/test/Driver/myriad-toolchain.c
clang/test/Driver/openmp-offload-gpu.c
clang/test/Driver/split-debug.c
lldb/test/Shell/SymbolFile/PDB/Inputs/ClassLayoutTest.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index ed365c608387..9b424beec428 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -498,7 +498,7 @@ static codegenoptions::DebugInfoKind 
DebugLevelToInfoKind(const Arg &A) {
 return codegenoptions::DebugLineTablesOnly;
   if (A.getOption().matches(options::OPT_gline_directives_only))
 return codegenoptions::DebugDirectivesOnly;
-  return codegenoptions::LimitedDebugInfo;
+  return codegenoptions::DebugInfoConstructor;
 }
 
 static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
@@ -2380,7 +2380,7 @@ static void CollectArgsForIntegratedAssembler(Compilation 
&C,
   CmdArgs.push_back(Value.data());
 } else {
   RenderDebugEnablingArgs(Args, CmdArgs,
-  codegenoptions::LimitedDebugInfo,
+  codegenoptions::DebugInfoConstructor,
   DwarfVersion, llvm::DebuggerKind::Default);
 }
   } else if (Value.startswith("-mcpu") || Value.startswith("-mfpu") ||
@@ -3653,7 +3653,7 @@ static void RenderDebugOptions(const ToolChain &TC, const 
Driver &D,
   if (const Arg *A =
   Args.getLastArg(options::OPT_g_Group, options::OPT_gsplit_dwarf,
   options::OPT_gsplit_dwarf_EQ)) {
-DebugInfoKind = codegenoptions::LimitedDebugInfo;
+DebugInfoKind = codegenoptions::DebugInfoConstructor;
 
 // If the last option explicitly specified a debug-info level, use it.
 if (checkDebugInfoOption(A, Args, D, TC) &&
@@ -3758,7 +3758,7 @@ static void RenderDebugOptions(const ToolChain &TC, const 
Driver &D,
 if (checkDebugInfoOption(A, Args, D, TC)) {
   if (DebugInfoKind != codegenoptions::DebugLineTablesOnly &&
   DebugInfoKind != codegenoptions::DebugDirectivesOnly) {
-DebugInfoKind = codegenoptions::LimitedDebugInfo;
+DebugInfoKind = codegenoptions::DebugInfoConstructor;
 CmdArgs.push_back("-dwarf-ext-refs");
 CmdArgs.push_back("-fmodule-format=obj");
   }
@@ -3778,7 +3778,9 @@ static void RenderDebugOptions(const ToolChain &TC, const 
Driver &D,
   TC.GetDefaultStandaloneDebug());
   if (const Arg *A = Args.getLastArg(options::OPT_fstandalone_debug))
 (void)checkDebugInfoOption(A, Args, D, TC);
-  if (DebugInfoKind == codegenoptions::LimitedDebugInfo && NeedFullDebug)
+  if ((DebugInfoKind == codegenoptions::LimitedDebugInfo ||
+   DebugInfoKind == codegenoptions::DebugInfoConstructor) &&
+  NeedFullDebug)
 DebugInfoKind = codegenoptions::FullDebugInfo;
 
   if (Args.hasFlag(options::OPT_gembed_source, options::OPT_gno_embed_source,
@@ -6552,7 +6554,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID 
InputType,
   options::OPT_gline_tables_only)) 

[clang] 394db22 - Revert "Switch to using -debug-info-kind=constructor as default (from =limited)"

2020-07-28 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-07-28T11:23:59-07:00
New Revision: 394db2259575ef3cac8d3d37836b11eb2373c435

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

LOG: Revert "Switch to using -debug-info-kind=constructor as default (from 
=limited)"

This reverts commit 227db86a1b7dd6f96f7df14890fcd071bc4fe1f5.

Causing debug info errors in google3 LTO builds; also causes a
debuginfo-test failure.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-options.c
clang/test/Driver/clang-g-opts.c
clang/test/Driver/cuda-dwarf-2.cu
clang/test/Driver/debug-options-as.c
clang/test/Driver/debug-options.c
clang/test/Driver/integrated-as.s
clang/test/Driver/myriad-toolchain.c
clang/test/Driver/openmp-offload-gpu.c
clang/test/Driver/split-debug.c
lldb/test/Shell/SymbolFile/PDB/Inputs/ClassLayoutTest.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b0de225f8abf..68e4eb0eedda 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -498,7 +498,7 @@ static codegenoptions::DebugInfoKind 
DebugLevelToInfoKind(const Arg &A) {
 return codegenoptions::DebugLineTablesOnly;
   if (A.getOption().matches(options::OPT_gline_directives_only))
 return codegenoptions::DebugDirectivesOnly;
-  return codegenoptions::DebugInfoConstructor;
+  return codegenoptions::LimitedDebugInfo;
 }
 
 static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
@@ -2383,7 +2383,7 @@ static void CollectArgsForIntegratedAssembler(Compilation 
&C,
   CmdArgs.push_back(Value.data());
 } else {
   RenderDebugEnablingArgs(Args, CmdArgs,
-  codegenoptions::DebugInfoConstructor,
+  codegenoptions::LimitedDebugInfo,
   DwarfVersion, llvm::DebuggerKind::Default);
 }
   } else if (Value.startswith("-mcpu") || Value.startswith("-mfpu") ||
@@ -3656,7 +3656,7 @@ static void RenderDebugOptions(const ToolChain &TC, const 
Driver &D,
   if (const Arg *A =
   Args.getLastArg(options::OPT_g_Group, options::OPT_gsplit_dwarf,
   options::OPT_gsplit_dwarf_EQ)) {
-DebugInfoKind = codegenoptions::DebugInfoConstructor;
+DebugInfoKind = codegenoptions::LimitedDebugInfo;
 
 // If the last option explicitly specified a debug-info level, use it.
 if (checkDebugInfoOption(A, Args, D, TC) &&
@@ -3761,7 +3761,7 @@ static void RenderDebugOptions(const ToolChain &TC, const 
Driver &D,
 if (checkDebugInfoOption(A, Args, D, TC)) {
   if (DebugInfoKind != codegenoptions::DebugLineTablesOnly &&
   DebugInfoKind != codegenoptions::DebugDirectivesOnly) {
-DebugInfoKind = codegenoptions::DebugInfoConstructor;
+DebugInfoKind = codegenoptions::LimitedDebugInfo;
 CmdArgs.push_back("-dwarf-ext-refs");
 CmdArgs.push_back("-fmodule-format=obj");
   }
@@ -3781,9 +3781,7 @@ static void RenderDebugOptions(const ToolChain &TC, const 
Driver &D,
   TC.GetDefaultStandaloneDebug());
   if (const Arg *A = Args.getLastArg(options::OPT_fstandalone_debug))
 (void)checkDebugInfoOption(A, Args, D, TC);
-  if ((DebugInfoKind == codegenoptions::LimitedDebugInfo ||
-   DebugInfoKind == codegenoptions::DebugInfoConstructor) &&
-  NeedFullDebug)
+  if (DebugInfoKind == codegenoptions::LimitedDebugInfo && NeedFullDebug)
 DebugInfoKind = codegenoptions::FullDebugInfo;
 
   if (Args.hasFlag(options::OPT_gembed_source, options::OPT_gno_embed_source,
@@ -6569,7 +6567,7 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID 
InputType,
   options::OPT_gline_tables_only)) {
 *EmitCodeView = true;
 if (DebugInfoArg->getOption().matches(options::OPT__SLASH_Z7))
-  *DebugInfoKind = codegenoptions::DebugInfoConstructor;
+  *DebugInfoKind = codegenoptions::LimitedDebugInfo;
 else
   *DebugInfoKind = codegenoptions::DebugLineTablesOnly;
   } else {
@@ -6866,7 +6864,7 @@ void ClangAs::ConstructJob(Compilation &C, const 
JobAction &JA,
 // the guard for source type, however there is a test which asserts
 // that some assembler invocation receives no -debug-info-kind,
 // and it's not clear whether that test is just overly restrictive.
-DebugInfoKind = (WantDebug ? codegenoptions::DebugInfoConstructor
+DebugInfoKind = (WantDebug ? codegenoptions::LimitedDebugInfo
: codegenoptions::NoDebugInfo);
 // Add the -fdebug-compilation-dir flag if needed.
 addDebugCompDirArg(Args, CmdArgs, C.getDriver().getVFS());

diff  --git a/clang/test/Driver/cl-options.

r363335 - Use fully qualified name when printing S_CONSTANT records

2019-06-13 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Thu Jun 13 15:53:43 2019
New Revision: 363335

URL: http://llvm.org/viewvc/llvm-project?rev=363335&view=rev
Log:
Use fully qualified name when printing S_CONSTANT records

Summary:
Before it was using the fully qualified name only for static data members.
Now it does for all variable names to match MSVC.

Reviewers: rnk

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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

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

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=363335&r1=363334&r2=363335&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Jun 13 15:53:43 2019
@@ -4361,13 +4361,18 @@ void CGDebugInfo::EmitGlobalVariable(con
   StringRef Name = VD->getName();
   llvm::DIType *Ty = getOrCreateType(VD->getType(), Unit);
 
-  // Do not use global variables for enums, unless for CodeView.
+  // Do not use global variables for enums, unless in CodeView.
   if (const auto *ECD = dyn_cast(VD)) {
 const auto *ED = cast(ECD->getDeclContext());
 assert(isa(ED->getTypeForDecl()) && "Enum without EnumType?");
 (void)ED;
 
-if (!CGM.getCodeGenOpts().EmitCodeView)
+// If CodeView, emit enums as global variables, unless they are defined
+// inside a class. We do this because MSVC doesn't emit S_CONSTANTs for
+// enums in classes, and because it is difficult to attach this scope
+// information to the global variable.
+if (!CGM.getCodeGenOpts().EmitCodeView ||
+isa(ED->getDeclContext()))
   return;
   }
 


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


r363952 - Store a pointer to the return value in a static alloca and let the debugger use that

2019-06-20 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Thu Jun 20 10:15:21 2019
New Revision: 363952

URL: http://llvm.org/viewvc/llvm-project?rev=363952&view=rev
Log:
Store a pointer to the return value in a static alloca and let the debugger use 
that
as the variable address for NRVO variables.

Subscribers: hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added:
cfe/trunk/test/CodeGenCXX/debug-info-nrvo.cpp
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGen/arm64-microsoft-arguments.cpp
cfe/trunk/test/CodeGenCXX/conditional-gnu-ext.cpp
cfe/trunk/test/CodeGenCXX/lambda-expressions.cpp
cfe/trunk/test/CodeGenObjC/objc-non-trivial-struct-nrvo.m

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=363952&r1=363951&r2=363952&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Jun 20 10:15:21 2019
@@ -3835,7 +3835,8 @@ CGDebugInfo::EmitTypeForVarWithBlocksAtt
 llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
 llvm::Value *Storage,
 llvm::Optional ArgNo,
-CGBuilderTy &Builder) {
+CGBuilderTy &Builder,
+const bool UsePointerValue) {
   assert(DebugKind >= codegenoptions::LimitedDebugInfo);
   assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
   if (VD->hasAttr())
@@ -3940,6 +3941,16 @@ llvm::DILocalVariable *CGDebugInfo::Emit
 }
   }
 
+  // Clang stores the sret pointer provided by the caller in a static alloca.
+  // Use DW_OP_deref to tell the debugger to load the pointer and treat it as
+  // the address of the variable.
+  if (UsePointerValue) {
+assert(std::find(Expr.begin(), Expr.end(), llvm::dwarf::DW_OP_deref) ==
+   Expr.end() &&
+   "Debug info already contains DW_OP_deref.");
+Expr.push_back(llvm::dwarf::DW_OP_deref);
+  }
+
   // Create the descriptor for the variable.
   auto *D = ArgNo ? DBuilder.createParameterVariable(
 Scope, Name, *ArgNo, Unit, Line, Ty,
@@ -3958,9 +3969,10 @@ llvm::DILocalVariable *CGDebugInfo::Emit
 
 llvm::DILocalVariable *
 CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *VD, llvm::Value *Storage,
-   CGBuilderTy &Builder) {
+   CGBuilderTy &Builder,
+   const bool UsePointerValue) {
   assert(DebugKind >= codegenoptions::LimitedDebugInfo);
-  return EmitDeclare(VD, Storage, llvm::None, Builder);
+  return EmitDeclare(VD, Storage, llvm::None, Builder, UsePointerValue);
 }
 
 void CGDebugInfo::EmitLabel(const LabelDecl *D, CGBuilderTy &Builder) {

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=363952&r1=363951&r2=363952&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Thu Jun 20 10:15:21 2019
@@ -422,9 +422,10 @@ public:
   /// declaration.
   /// Returns a pointer to the DILocalVariable associated with the
   /// llvm.dbg.declare, or nullptr otherwise.
-  llvm::DILocalVariable *EmitDeclareOfAutoVariable(const VarDecl *Decl,
-   llvm::Value *AI,
-   CGBuilderTy &Builder);
+  llvm::DILocalVariable *
+  EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
+CGBuilderTy &Builder,
+const bool UsePointerValue = false);
 
   /// Emit call to \c llvm.dbg.label for an label.
   void EmitLabel(const LabelDecl *D, CGBuilderTy &Builder);
@@ -507,7 +508,8 @@ private:
   /// llvm.dbg.declare, or nullptr otherwise.
   llvm::DILocalVariable *EmitDeclare(const VarDecl *decl, llvm::Value *AI,
  llvm::Optional ArgNo,
- CGBuilderTy &Builder);
+ CGBuilderTy &Builder,
+ const bool UsePointerValue = false);
 
   struct BlockByRefType {
 /// The wrapper struct used inside the __block_literal struct.

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=363952&r1=363951&r2=363952&view=diff

[clang] 11a04a6 - [DebugInfo] Change to constructor homing debug info mode: skip literal types

2020-04-06 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-04-06T09:52:53-07:00
New Revision: 11a04a64aaa3dba6fddadbcf026d197fc02226e0

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

LOG: [DebugInfo] Change to constructor homing debug info mode: skip literal 
types

Summary:
In constructor type homing mode sometimes complete debug info for constexpr
types was missing, because there was not a constructor emitted. This change
makes constructor type homing ignore constexpr types.

Reviewers: rnk, dblaikie

Subscribers: aprantl, cfe-commits

Tags: #clang

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

Added: 


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

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 5f05323f61ef..8dc305bbfa8d 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2261,12 +2261,11 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
   // constructor is emitted. Skip this optimization if the class or any of
   // its methods are marked dllimport.
   if (DebugKind == codegenoptions::DebugInfoConstructor &&
-  !CXXDecl->isLambda() && !isClassOrMethodDLLImport(CXXDecl)) {
-for (const auto *Ctor : CXXDecl->ctors()) {
+  !CXXDecl->isLambda() && !CXXDecl->hasConstexprNonCopyMoveConstructor() &&
+  !isClassOrMethodDLLImport(CXXDecl))
+for (const auto *Ctor : CXXDecl->ctors())
   if (Ctor->isUserProvided())
 return true;
-}
-  }
 
   TemplateSpecializationKind Spec = TSK_Undeclared;
   if (const auto *SD = dyn_cast(RD))

diff  --git a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp 
b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
index 321f1736391f..25b4ebdb54a3 100644
--- a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
+++ b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -1,30 +1,26 @@
 // RUN: %clang -cc1 -debug-info-kind=constructor -emit-llvm %s -o - | 
FileCheck %s
 
-// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "A"
-// CHECK-NOT:  DIFlagFwdDecl
-// CHECK-SAME: ){{$}}
-struct A {};
-void TestA() { A a; }
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"A"{{.*}}DIFlagTypePassByValue
+struct A {
+} TestA;
 
-// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "B"
-// CHECK-SAME: flags: DIFlagFwdDecl
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"B"{{.*}}flags: DIFlagFwdDecl
 struct B {
   B();
-};
-void TestB() { B b; }
+} TestB;
 
-// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "C"
-// CHECK-NOT:  flags: DIFlagFwdDecl
-// CHECK-SAME: ){{$}}
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"C"{{.*}}DIFlagTypePassByValue
 struct C {
   C() {}
-};
-void TestC() { C c; }
+} TestC;
 
-// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "D"
-// CHECK-NOT:  flags: DIFlagFwdDecl
-// CHECK-SAME: ){{$}}
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"D"{{.*}}DIFlagTypePassByValue
 struct D {
   D();
 };
 D::D() {}
+
+// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"E"{{.*}}DIFlagTypePassByValue
+struct E {
+  constexpr E(){};
+} TestE;



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


[clang] bcf6608 - [DebugInfo] Fix for adding "returns cxx udt" option to functions in CodeView.

2020-04-07 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-04-07T09:10:27-07:00
New Revision: bcf66084eddd4d3dbe78fc4ed39a347d5d8d57d4

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

LOG: [DebugInfo] Fix for adding "returns cxx udt" option to functions in 
CodeView.

Summary:
This change adds DIFlagNonTrivial to forward declarations of
DICompositeType. It adds the flag to nontrivial types and types with
unknown triviality.

It fixes adding the "CxxReturnUdt" flag to functions inconsistently,
since it is added based on whether the return type is marked NonTrivial, and
that changes if the return type was a forward declaration.

continues the discussion at https://reviews.llvm.org/D75215

Bug: https://bugs.llvm.org/show_bug.cgi?id=44785

Reviewers: rnk, dblaikie, aprantl

Subscribers: cfe-commits

Tags: #clang

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

Added: 
clang/test/CodeGenCXX/debug-info-composite-triviality-fwd-decl.cpp

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 8dc305bbfa8d..74c079b0bd09 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -991,11 +991,21 @@ CGDebugInfo::getOrCreateRecordFwdDecl(const RecordType 
*Ty,
   uint64_t Size = 0;
   uint32_t Align = 0;
 
+  llvm::DINode::DIFlags Flags = llvm::DINode::FlagFwdDecl;
+
+  // Add flag to nontrivial forward declarations. To be consistent with MSVC,
+  // add the flag if a record has no definition because we don't know whether
+  // it will be trivial or not.
+  if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
+if (!CXXRD->hasDefinition() ||
+(CXXRD->hasDefinition() && !CXXRD->isTrivial()))
+  Flags |= llvm::DINode::FlagNonTrivial;
+
   // Create the type.
   SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
   llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
-  getTagForRecord(RD), RDName, Ctx, DefUnit, Line, 0, Size, Align,
-  llvm::DINode::FlagFwdDecl, Identifier);
+  getTagForRecord(RD), RDName, Ctx, DefUnit, Line, 0, Size, Align, Flags,
+  Identifier);
   if (CGM.getCodeGenOpts().DebugFwdTemplateParams)
 if (auto *TSpecial = dyn_cast(RD))
   DBuilder.replaceArrays(RetTy, llvm::DINodeArray(),

diff  --git 
a/clang/test/CodeGenCXX/debug-info-composite-triviality-fwd-decl.cpp 
b/clang/test/CodeGenCXX/debug-info-composite-triviality-fwd-decl.cpp
new file mode 100644
index ..4bf18279b3d5
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-composite-triviality-fwd-decl.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm -gcodeview -debug-info-kind=limited -x c %s -o - 
| FileCheck %s --check-prefix CHECK-C
+// RUN: %clang_cc1 -emit-llvm -gcodeview -debug-info-kind=limited -x c++ %s -o 
- | FileCheck %s --check-prefix CHECK-CXX
+//
+// Test for DIFlagNonTrivial on forward declared DICompositeTypes.
+
+struct Incomplete;
+struct Incomplete (*func_ptr)() = 0;
+// CHECK-C: !DICompositeType({{.*}}name: "Incomplete"
+// CHECK-C-NOT: DIFlagNonTrivial
+// CHECK-CXX: !DICompositeType({{.*}}name: "Incomplete"
+// CHECK-CXX-SAME: DIFlagNonTrivial



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


[clang] dace7ad - Slightly modify some tests as follow up to bcf66084, which breaks tests.

2020-04-07 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-04-07T09:25:16-07:00
New Revision: dace7ada3814d87171e3a8be154f315e1f9d6029

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

LOG: Slightly modify some tests as follow up to bcf66084, which breaks tests.

The change in bcf6604 added a debug info flag, which caused some tests
to fail; I removed some commas so that the test matching still works.

Added: 


Modified: 
clang/test/Modules/ExtDebugInfo.cpp
clang/test/Modules/ModuleDebugInfo.cpp

Removed: 




diff  --git a/clang/test/Modules/ExtDebugInfo.cpp 
b/clang/test/Modules/ExtDebugInfo.cpp
index a66c678227fe..6781810d592c 100644
--- a/clang/test/Modules/ExtDebugInfo.cpp
+++ b/clang/test/Modules/ExtDebugInfo.cpp
@@ -77,7 +77,7 @@ void foo() {
 
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum",
 // CHECK-SAME: scope: ![[NS:[0-9]+]],
-// CHECK-SAME: flags: DIFlagFwdDecl,
+// CHECK-SAME: flags: DIFlagFwdDecl
 // CHECK-SAME: identifier:  "_ZTSN8DebugCXX4EnumE")
 
 // CHECK: ![[NS]] = !DINamespace(name: "DebugCXX", scope: ![[MOD:[0-9]+]])
@@ -94,7 +94,7 @@ void foo() {
 // CHECK: !DICompositeType(tag: DW_TAG_class_type,
 // CHECK-SAME: name: "Template>",
 // CHECK-SAME: scope: ![[NS]],
-// CHECK-SAME: flags: DIFlagFwdDecl,
+// CHECK-SAME: flags: DIFlagFwdDecl
 // CHECK-SAME: identifier: 
"_ZTSN8DebugCXX8TemplateIiNS_6traitsIi")
 
 // This type isn't, however, even with standalone non-module debug info this
@@ -111,7 +111,7 @@ void foo() {
 
 // This type is anchored in the module by an explicit template instantiation.
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "traits",
-// CHECK-SAME: flags: DIFlagFwdDecl,
+// CHECK-SAME: flags: DIFlagFwdDecl
 // CHECK-SAME: identifier: "_ZTSN8DebugCXX6traitsIfEE")
 
 
@@ -127,11 +127,11 @@ void foo() {
 
 // CHECK: ![[STRUCT]] = !DICompositeType(tag: DW_TAG_structure_type, name: 
"Struct",
 // CHECK-SAME: scope: ![[NS]],
-// CHECK-SAME: flags: DIFlagFwdDecl,
+// CHECK-SAME: flags: DIFlagFwdDecl
 // CHECK-SAME: identifier: "_ZTSN8DebugCXX6StructE")
 
 // CHECK: !DICompositeType(tag: DW_TAG_union_type,
-// CHECK-SAME: flags: DIFlagFwdDecl,
+// CHECK-SAME: flags: DIFlagFwdDecl
 // CHECK-SAME: identifier: "_ZTS12TypedefUnion")
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
 // CHECK-SAME: flags: DIFlagFwdDecl,
@@ -214,8 +214,9 @@ void foo() {
 // CHECK-PCH:dwoId: 18446744073709551614
 
 // CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "A",
-// CHECK-SAME: DIFlagFwdDecl)
+// CHECK-SAME: DIFlagFwdDecl
 
 // There is a full definition of the type available in the module.
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Virtual",
-// CHECK-SAME: DIFlagFwdDecl, identifier: "_ZTS7Virtual")
+// CHECK-SAME: DIFlagFwdDecl
+// CHECK-SAME: identifier: "_ZTS7Virtual")

diff  --git a/clang/test/Modules/ModuleDebugInfo.cpp 
b/clang/test/Modules/ModuleDebugInfo.cpp
index c361053d03cd..26369c896058 100644
--- a/clang/test/Modules/ModuleDebugInfo.cpp
+++ b/clang/test/Modules/ModuleDebugInfo.cpp
@@ -133,7 +133,7 @@
 // CHECK-SAME:   baseType: ![[BASE:.*]])
 // CHECK: ![[BASE]] = !DICompositeType(tag: DW_TAG_class_type,
 // CHECK-SAME: name: "Template1",
-// CHECK-SAME: flags: DIFlagFwdDecl,
+// CHECK-SAME: flags: DIFlagFwdDecl
 // CHECK-SAME: identifier: "_ZTS9Template1IPvE")
 
 // Explicit instantiation.
@@ -154,7 +154,7 @@
 // CHECK-SAME:   baseType: ![[SPECIALIZEDBASE:.*]])
 // CHECK: ![[SPECIALIZEDBASE]] = !DICompositeType(tag: DW_TAG_class_type,
 // CHECK-SAME: name: "WithSpecializedBase",
-// CHECK-SAME: flags: DIFlagFwdDecl,
+// CHECK-SAME: flags: DIFlagFwdDecl
 
 // CHECK-MOD: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: 
![[DEBUGCXX]],
 // CHECK-MOD-SAME:  entity: ![[DUMMY:[0-9]+]],



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


[clang] 53539bb - [DebugInfo] Add another level to DebugInfoKind called Constructor

2020-01-13 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-01-13T15:59:03-08:00
New Revision: 53539bb032d162e0147c0e9650a5d1c7ca77dae0

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

LOG: [DebugInfo] Add another level to DebugInfoKind called Constructor

The option will limit debug info by only emitting complete class
type information when its constructor is emitted.
This patch changes comparisons with LimitedDebugInfo to use the new
level instead.

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

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Basic/DebugInfoOptions.h
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 900620a39292..21ac54e8ee12 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -357,6 +357,11 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   /// Check if CSIR profile use is on.
   bool hasProfileCSIRUse() const { return getProfileUse() == ProfileCSIRInstr; 
}
+
+  /// Check if type and variable info should be emitted.
+  bool hasReducedDebugInfo() const {
+return getDebugInfo() >= codegenoptions::DebugInfoConstructor;
+  }
 };
 
 }  // end namespace clang

diff  --git a/clang/include/clang/Basic/DebugInfoOptions.h 
b/clang/include/clang/Basic/DebugInfoOptions.h
index ac18a3a4796c..586168bd015f 100644
--- a/clang/include/clang/Basic/DebugInfoOptions.h
+++ b/clang/include/clang/Basic/DebugInfoOptions.h
@@ -34,6 +34,11 @@ enum DebugInfoKind {
   /// (-gline-tables-only).
   DebugLineTablesOnly,
 
+  /// Limit generated debug info for classes to reduce size. This emits class
+  /// type info only where the constructor is emitted, if it is a class that
+  /// has a constructor.
+  DebugInfoConstructor,
+
   /// Limit generated debug info to reduce size (-fno-standalone-debug). This
   /// emits forward decls for types that could be replaced with forward decls 
in
   /// the source code. For dynamic C++ classes type info is only emitted into

diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index b0295ce69bff..11f54d1f7fb2 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1483,8 +1483,7 @@ void CodeGenFunction::setBlockContextParameter(const 
ImplicitParamDecl *D,
   Address alloc = CreateMemTemp(D->getType(), D->getName() + ".addr");
   Builder.CreateStore(arg, alloc);
   if (CGDebugInfo *DI = getDebugInfo()) {
-if (CGM.getCodeGenOpts().getDebugInfo() >=
-codegenoptions::LimitedDebugInfo) {
+if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
   DI->setLocation(D->getLocation());
   DI->EmitDeclareOfBlockLiteralArgVariable(
   *BlockInfo, D->getName(), argNum,
@@ -1656,8 +1655,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
   const VarDecl *variable = CI.getVariable();
   DI->EmitLocation(Builder, variable->getLocation());
 
-  if (CGM.getCodeGenOpts().getDebugInfo() >=
-  codegenoptions::LimitedDebugInfo) {
+  if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
 const CGBlockInfo::Capture &capture = blockInfo.getCapture(variable);
 if (capture.isConstant()) {
   auto addr = LocalDeclMap.find(variable)->second;

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 675df309e3f0..3672490fafd5 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -591,6 +591,7 @@ void CGDebugInfo::CreateCompileUnit() {
   case codegenoptions::DebugDirectivesOnly:
 EmissionKind = llvm::DICompileUnit::DebugDirectivesOnly;
 break;
+  case codegenoptions::DebugInfoConstructor:
   case codegenoptions::LimitedDebugInfo:
   case codegenoptions::FullDebugInfo:
 EmissionKind = llvm::DICompileUnit::FullDebug;
@@ -2043,7 +2044,7 @@ void CGDebugInfo::CollectVTableInfo(const CXXRecordDecl 
*RD, llvm::DIFile *Unit,
 
 llvm::DIType *CGDebugInfo::getOrCreateRecordType(QualType RTy,
  SourceLocation Loc) {
-  assert(DebugKind >= codegenoptions::LimitedDebugInfo);
+  assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
   llvm::DIType *T = getOrCreateType(RTy, getOrCreateFile(Loc));
   return T;
 }
@@ -2055,7 +2056,7 @@ llvm::DIType 
*CGDebugInfo::getOrCreateInterfaceType(QualType D,
 
 llvm::DIType *CGDebugInfo::getOrCrea

[clang] 651128f - [DebugInfo] Add option to clang to limit debug info that is emitted for classes.

2020-01-14 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-01-14T12:40:21-08:00
New Revision: 651128f557229e79598e22102edb7fad3bf288c0

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

LOG: [DebugInfo] Add option to clang to limit debug info that is emitted for 
classes.

Summary:
This patch adds an option to limit debug info by only emitting complete class
type information when its constructor is emitted. This applies to classes
that have nontrivial user defined constructors.

I implemented the option by adding another level to `DebugInfoKind`, and
a flag `-flimit-debug-info-constructor`.

Total object file size on Windows, compiling with RelWithDebInfo:
  before: 4,257,448 kb
  after:  2,104,963 kb

And on Linux
  before: 9,225,140 kb
  after:  4,387,464 kb

According to the Windows clang.pdb files, here is a list of types that are no
longer complete with this option enabled: https://reviews.llvm.org/P8182

Reviewers: rnk, dblaikie

Subscribers: aprantl, cfe-commits

Tags: #clang

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

Added: 
clang/test/CodeGenCXX/debug-info-limited-ctor.cpp

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 3672490fafd5..cbd524eda9d0 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1648,6 +1648,12 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
   if (CGM.getLangOpts().Optimize)
 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
 
+  // In this debug mode, emit type info for a class when its constructor type
+  // info is emitted.
+  if (DebugKind == codegenoptions::DebugInfoConstructor)
+if (const CXXConstructorDecl *CD = dyn_cast(Method))
+  completeClass(CD->getParent());
+
   llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(Method, Unit);
   llvm::DISubprogram *SP = DBuilder.createMethod(
   RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine,
@@ -2211,6 +2217,17 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
   !isClassOrMethodDLLImport(CXXDecl))
 return true;
 
+  // In constructor debug mode, only emit debug info for a class when its
+  // constructor is emitted. Skip this optimization if the class or any of
+  // its methods are marked dllimport.
+  if (DebugKind == codegenoptions::DebugInfoConstructor &&
+  !CXXDecl->isLambda() && !isClassOrMethodDLLImport(CXXDecl)) {
+for (const auto *Ctor : CXXDecl->ctors()) {
+  if (Ctor->isUserProvided())
+return true;
+}
+  }
+
   TemplateSpecializationKind Spec = TSK_Undeclared;
   if (const auto *SD = dyn_cast(RD))
 Spec = SD->getSpecializationKind();

diff  --git a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp 
b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
new file mode 100644
index ..321f1736391f
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang -cc1 -debug-info-kind=constructor -emit-llvm %s -o - | 
FileCheck %s
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "A"
+// CHECK-NOT:  DIFlagFwdDecl
+// CHECK-SAME: ){{$}}
+struct A {};
+void TestA() { A a; }
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "B"
+// CHECK-SAME: flags: DIFlagFwdDecl
+struct B {
+  B();
+};
+void TestB() { B b; }
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "C"
+// CHECK-NOT:  flags: DIFlagFwdDecl
+// CHECK-SAME: ){{$}}
+struct C {
+  C() {}
+};
+void TestC() { C c; }
+
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "D"
+// CHECK-NOT:  flags: DIFlagFwdDecl
+// CHECK-SAME: ){{$}}
+struct D {
+  D();
+};
+D::D() {}



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


[clang] 3d210ed - Revert "Allow system header to provide their own implementation of some builtin"

2020-01-15 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-01-15T15:03:45-08:00
New Revision: 3d210ed3d1880c615776b07d1916edb400c245a6

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

LOG: Revert "Allow system header to provide their own implementation of some 
builtin"

This reverts commit 921f871ac438175ca8fcfcafdfcfac4d7ddf3905 because it
causes libc++ code to trigger __warn_memset_zero_len.

See https://reviews.llvm.org/D71082.

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/lib/AST/Decl.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 
clang/test/CodeGen/memcpy-nobuiltin.c
clang/test/CodeGen/memcpy-nobuiltin.inc



diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 43c6c7b85db4..620ab4b089db 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2309,9 +2309,6 @@ class FunctionDecl : public DeclaratorDecl,
   /// true through IsAligned.
   bool isReplaceableGlobalAllocationFunction(bool *IsAligned = nullptr) const;
 
-  /// Determine if this function provides an inline implementation of a 
builtin.
-  bool isInlineBuiltinDeclaration() const;
-
   /// Determine whether this is a destroying operator delete.
   bool isDestroyingOperatorDelete() const;
 

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 0d30f64b992e..be59d88b73f1 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3046,14 +3046,6 @@ bool 
FunctionDecl::isReplaceableGlobalAllocationFunction(bool *IsAligned) const
   return Params == FPT->getNumParams();
 }
 
-bool FunctionDecl::isInlineBuiltinDeclaration() const {
-  if (!getBuiltinID())
-return false;
-
-  const FunctionDecl *Definition;
-  return hasBody(Definition) && Definition->isInlineSpecified();
-}
-
 bool FunctionDecl::isDestroyingOperatorDelete() const {
   // C++ P0722:
   //   Within a class C, a single object deallocation function with signature

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 8e0604181fb1..b23d9df5f4ba 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4621,15 +4621,8 @@ RValue CodeGenFunction::EmitSimpleCallExpr(const 
CallExpr *E,
 }
 
 static CGCallee EmitDirectCallee(CodeGenFunction &CGF, const FunctionDecl *FD) 
{
-
   if (auto builtinID = FD->getBuiltinID()) {
-// Replaceable builtin provide their own implementation of a builtin. 
Unless
-// we are in the builtin implementation itself, don't call the actual
-// builtin. If we are in the builtin implementation, avoid trivial infinite
-// recursion.
-if (!FD->isInlineBuiltinDeclaration() ||
-CGF.CurFn->getName() == FD->getName())
-  return CGCallee::forBuiltin(builtinID, FD);
+return CGCallee::forBuiltin(builtinID, FD);
   }
 
   llvm::Constant *calleePtr = EmitFunctionDeclPointer(CGF.CGM, FD);

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 57beda26677c..038078bbe88d 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1840,11 +1840,6 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, 
llvm::Function *F,
   else if (const auto *SA = FD->getAttr())
  F->setSection(SA->getName());
 
-  if (FD->isInlineBuiltinDeclaration()) {
-F->addAttribute(llvm::AttributeList::FunctionIndex,
-llvm::Attribute::NoBuiltin);
-  }
-
   if (FD->isReplaceableGlobalAllocationFunction()) {
 // A replaceable global allocation function does not act like a builtin by
 // default, only if it is invoked by a new-expression or delete-expression.

diff  --git a/clang/test/CodeGen/memcpy-nobuiltin.c 
b/clang/test/CodeGen/memcpy-nobuiltin.c
deleted file mode 100644
index fb51d87413a1..
--- a/clang/test/CodeGen/memcpy-nobuiltin.c
+++ /dev/null
@@ -1,15 +0,0 @@
-// RUN: %clang_cc1 -verify -S -emit-llvm -o- %s -isystem %S -DWITH_DECL | 
FileCheck --check-prefix=CHECK-WITH-DECL %s
-// RUN: %clang_cc1 -verify -S -emit-llvm -o- %s -isystem %S -UWITH_DECL | 
FileCheck --check-prefix=CHECK-NO-DECL %s
-// RUN: %clang_cc1 -verify -S -emit-llvm -o- %s -isystem %S 
-DWITH_SELF_REFERENCE_DECL | FileCheck --check-prefix=CHECK-SELF-REF-DECL %s
-//
-// CHECK-WITH-DECL-NOT: @llvm.memcpy
-// CHECK-NO-DECL: @llvm.memcpy
-// CHECK-SELF-REF-DECL: @llvm.memcpy
-//
-#include 
-void test(void *dest, void const *from, size_t n) {
-  memcpy(dest, from, n);
-
-  static char buffer[1];
-  memcpy(buffer, from, 2); // expected-warning {{'memcpy' will always 
overflow; destination buffer has size 1, but size argument is 2}}
-}

diff  --git a/clang/test/CodeGen/memcpy-nobuiltin.inc 
b/clang/test/CodeGen/memcpy-nobuiltin.inc
deleted file mode 100644
index 25eab0a9ffd0..

[clang] 4456076 - Revert "Further implement CWG 2292"

2020-01-15 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-01-15T15:46:07-08:00
New Revision: 44560762c62d72a103bdceff49ffa70451efd5f8

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

LOG: Revert "Further implement CWG 2292"

This reverts commit ee0f1f1edc3ec0d4e698d50cc3180217448802b7 because it
causes an error on valid code.
See https://reviews.llvm.org/rGee0f1f1edc3ec0d4e698d50cc3180217448802b7.

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp

Removed: 
clang/test/SemaCXX/pseudo-destructor-name.cpp



diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 96e18105df78..a73e6906fceb 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -192,10 +192,8 @@ ParsedType Sema::getDestructorName(SourceLocation TildeLoc,
   AlreadySearched = true;
   LookupCtx = DC;
   isDependent = false;
-} else if (auto *RD = dyn_cast_or_null(DC)) {
-  if ((RD->hasDefinition() && RD->hasSimpleDestructor()) ||
-  !RD->hasDefinition())
-LookAtPrefix = false;
+} else if (DC && isa(DC)) {
+  LookAtPrefix = false;
   LookInScope = true;
 }
 

diff  --git a/clang/test/SemaCXX/pseudo-destructor-name.cpp 
b/clang/test/SemaCXX/pseudo-destructor-name.cpp
deleted file mode 100644
index cc7c22b8dc4d..
--- a/clang/test/SemaCXX/pseudo-destructor-name.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
-// expected-no-diagnostics
-
-struct AAA
-{
-struct BBB
-{
-~BBB() {}
-};
-
-typedef BBB BBB_alias;
-};
-
-typedef AAA::BBB BBB_alias2;
-
-int
-main()
-{
-AAA::BBB_alias *ptr1 = new AAA::BBB_alias();
-AAA::BBB_alias *ptr2 = new AAA::BBB_alias();
-
-ptr1->AAA::BBB_alias::~BBB_alias(); // Now OK
-ptr2->AAA::BBB_alias::~BBB();   // OK
-ptr1->~BBB_alias2();// OK
-return 0;
-}



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


[clang] a85f5ef - Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.

2019-12-18 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2019-12-18T10:41:12-08:00
New Revision: a85f5efd9597d0036f5c347b362cb873bdf51f16

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

LOG: Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.

Summary:
This adds parsing of the qualifiers __ptr32, __ptr64, __sptr, and __uptr and
lowers them to the corresponding address space pointer for 32-bit and 64-bit 
pointers.
(32/64-bit pointers added in https://reviews.llvm.org/D69639)

A large part of this patch is making these pointers ignore the address space
when doing things like overloading and casting.

https://bugs.llvm.org/show_bug.cgi?id=42359

Reviewers: rnk, rsmith

Subscribers: jholewinski, jvesely, nhaehnle, cfe-commits

Tags: #clang

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

Added: 
clang/test/CodeGen/ms-mixed-ptr-sizes.c
clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp

Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Type.h
clang/include/clang/Basic/AddressSpaces.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/Basic/Targets/AMDGPU.cpp
clang/lib/Basic/Targets/NVPTX.h
clang/lib/Basic/Targets/SPIR.h
clang/lib/Basic/Targets/TCE.h
clang/lib/Basic/Targets/X86.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaType.cpp
clang/test/Sema/MicrosoftExtensions.c
clang/test/SemaTemplate/address_space-dependent.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 4e1d4a44bd8c..92f81eb55ed7 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1155,6 +1155,10 @@ class ASTContext : public RefCountedBase {
   /// attribute.
   QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr) const;
 
+  /// Remove the existing address space on the type if it is a pointer size
+  /// address space and return the type with qualifiers intact.
+  QualType removePtrSizeAddrSpace(QualType T) const;
+
   /// Return the uniqued reference to the type for a \c restrict
   /// qualified type.
   ///
@@ -1209,6 +1213,15 @@ class ASTContext : public RefCountedBase {
const FunctionProtoType::ExceptionSpecInfo &ESI,
bool AsWritten = false);
 
+  /// Get a function type and produce the equivalent function type where
+  /// pointer size address spaces in the return type and parameter tyeps are
+  /// replaced with the default address space.
+  QualType getFunctionTypeWithoutPtrSizes(QualType T);
+
+  /// Determine whether two function types are the same, ignoring pointer sizes
+  /// in the return type and parameter types.
+  bool hasSameFunctionTypeIgnoringPtrSizes(QualType T, QualType U);
+
   /// Return the uniqued reference to the type for a complex
   /// number with the specified element type.
   QualType getComplexType(QualType T) const;

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 2968efa9b276..942564756c93 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -477,7 +477,10 @@ class Qualifiers {
 return A == B ||
// Otherwise in OpenCLC v2.0 s6.5.5: every address space except
// for __constant can be used as __generic.
-   (A == LangAS::opencl_generic && B != LangAS::opencl_constant);
+   (A == LangAS::opencl_generic && B != LangAS::opencl_constant) ||
+   // Consider pointer size address spaces to be equivalent to default.
+   ((isPtrSizeAddressSpace(A) || A == LangAS::Default) &&
+(isPtrSizeAddressSpace(B) || B == LangAS::Default));
   }
 
   /// Returns true if the address space in these qualifiers is equal to or

diff  --git a/clang/include/clang/Basic/AddressSpaces.h 
b/clang/include/clang/Basic/AddressSpaces.h
index 2cc67474c121..faf7f303aa2d 100644
--- a/clang/include/clang/Basic/AddressSpaces.h
+++ b/clang/include/clang/Basic/AddressSpaces.h
@@ -42,6 +42,11 @@ enum class LangAS : unsigned {
   cuda_constant,
   cuda_shared,
 
+  // Pointer size and extension address spaces.
+  ptr32_sptr,
+  ptr32_uptr,
+  ptr64,
+
   // This denotes the count of language-specific address spaces and also
   // the offset added to the target-specific address spaces, which are usually
   // specified by address space attributes __attribute__(address_space(n))).
@@ -68,6 +73,11 @@ inline LangAS getLangASFromTargetAS(unsigned TargetAS) {
  (unsigned)LangAS::FirstTargetAddressSpace);
 }
 
+inline bo

[clang] e3fa460 - Change triple in test case to not include triples the test shouldn't

2019-12-18 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2019-12-18T13:17:39-08:00
New Revision: e3fa4604076d01d2fe48d44d86fc2d6a48d4970c

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

LOG: Change triple in test case to not include triples the test shouldn't
pass.
This is fixes changes from a85f5efd9597d0036f5c347b362cb873bdf51f16.

Added: 


Modified: 
clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp 
b/clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
index a7dfe526743c..a56b4550cad7 100644
--- a/clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
+++ b/clang/test/CodeGenCXX/mangle-ptr-size-address-space.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fms-extensions -emit-llvm -triple %itanium_abi_triple -o - 
%s | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_cc1 -fms-extensions -emit-llvm -triple x86_64-linux-gnu -o - %s 
| FileCheck %s --check-prefixes=CHECK
 // RUN: %clang_cc1 -fms-extensions -emit-llvm -triple x86_64-windows-msvc -o - 
%s | FileCheck %s --check-prefixes=WIN
 
 // CHECK-LABEL: define {{.*}}void @_Z2f0PU10ptr32_sptri
@@ -13,6 +13,6 @@ void * __ptr32 __uptr f1(int * __ptr32 p) { return 0; }
 // WIN-LABEL: define {{.*}}void @"?f2@@YAXPEAH@Z"
 void f2(int * __ptr64 p) {}
 
-  // CHECK-LABEL: define {{.*}}i8* @_Z2f3Pi
+// CHECK-LABEL: define {{.*}}i8* @_Z2f3Pi
 // WIN-LABEL: define {{.*}}i8* @"?f3@@YAPEAXPEAH@Z"
 void * __ptr64 f3(int * __ptr64 p) { return 0; }



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


[clang] 6d03890 - [CodeView] Add option to disable inline line tables.

2019-10-30 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2019-10-30T16:52:39-07:00
New Revision: 6d03890384517919a3ba7fe4c35535425f278f89

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

LOG: [CodeView] Add option to disable inline line tables.

Summary:
This adds a clang option to disable inline line tables. When it is used,
the inliner uses the call site as the location of the inlined function instead 
of
marking it as an inline location with the function location.

See https://bugs.llvm.org/show_bug.cgi?id=42344

Reviewers: rnk

Subscribers: hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added: 
clang/test/CodeGen/debug-info-no-inline-line-tables.c
llvm/test/Transforms/Inline/no-inline-line-tables.ll

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
llvm/docs/LangRef.rst
llvm/include/llvm/IR/Attributes.td
llvm/lib/Transforms/Utils/InlineFunction.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index f8d94e352f28..ebdcb3c1f48b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -136,6 +136,8 @@ CODEGENOPT(FatalWarnings , 1, 0) ///< Set when 
-Wa,--fatal-warnings is
  ///< enabled.
 CODEGENOPT(NoWarn, 1, 0) ///< Set when -Wa,--no-warn is enabled.
 CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is 
enabled.
+CODEGENOPT(NoInlineLineTables, 1, 0) ///< Whether debug info should contain
+ ///< inline line tables.
 CODEGENOPT(NoImplicitFloat   , 1, 0) ///< Set when -mno-implicit-float is 
enabled.
 CODEGENOPT(NoInfsFPMath  , 1, 0) ///< Assume FP arguments, results not 
+-Inf.
 CODEGENOPT(NoSignedZeros , 1, 0) ///< Allow ignoring the signedness of FP 
zero

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2401a31ceb9a..1bdeed69602f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1984,6 +1984,9 @@ def gcodeview_ghash : Flag<["-"], "gcodeview-ghash">,
   HelpText<"Emit type record hashes in a .debug$H section">,
   Flags<[CC1Option, CoreOption]>;
 def gno_codeview_ghash : Flag<["-"], "gno-codeview-ghash">, 
Flags<[CoreOption]>;
+def ginline_line_tables : Flag<["-"], "ginline-line-tables">, 
Flags<[CoreOption]>;
+def gno_inline_line_tables : Flag<["-"], "gno-inline-line-tables">,
+  Flags<[CC1Option, CoreOption]>, HelpText<"Don't emit inline line tables">;
 
 // Equivalent to our default dwarf version. Forces usual dwarf emission when
 // CodeView is enabled.

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 3f9a52ab7638..1b1d391a63df 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -764,6 +764,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
   Fn->addFnAttr("no-jump-tables",
 llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables));
 
+  // Add no-inline-line-tables value.
+  if (CGM.getCodeGenOpts().NoInlineLineTables)
+Fn->addFnAttr("no-inline-line-tables");
+
   // Add profile-sample-accurate value.
   if (CGM.getCodeGenOpts().ProfileSampleAccurate)
 Fn->addFnAttr("profile-sample-accurate");

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index c60dc76ae1bf..f5abdf15fd44 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3296,6 +3296,12 @@ static void RenderDebugOptions(const ToolChain &TC, 
const Driver &D,
 }
   }
 
+  // Omit inline line tables if requested.
+  if (!Args.hasFlag(options::OPT_ginline_line_tables,
+options::OPT_gno_inline_line_tables, false)) {
+CmdArgs.push_back("-gno-inline-line-tables");
+  }
+
   // Adjust the debug info kind for the given toolchain.
   TC.adjustDebugInfoKind(DebugInfoKind, Args);
 

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index f197a67e7a38..29736d2dee18 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -806,6 +806,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList 
&Args, InputKind IK,
   Opts.RecordCommandLine = Args.getLastArgValue(OPT_record_command_line);
   Opts.MergeAllConstants = Args.hasArg(OPT_fmerge_all_constants);
   Opts.NoCommon = Args.hasArg(OPT_fno_common);
+  Opts.NoInlineLi

[clang] 004ed2b - Revert "[CodeView] Add option to disable inline line tables."

2019-10-30 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2019-10-30T17:31:12-07:00
New Revision: 004ed2b0d1b86d424643ffc88fce20ad8bab6804

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

LOG: Revert "[CodeView] Add option to disable inline line tables."
because it breaks compiler-rt tests.

This reverts commit 6d03890384517919a3ba7fe4c35535425f278f89.

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
llvm/docs/LangRef.rst
llvm/include/llvm/IR/Attributes.td
llvm/lib/Transforms/Utils/InlineFunction.cpp

Removed: 
clang/test/CodeGen/debug-info-no-inline-line-tables.c
llvm/test/Transforms/Inline/no-inline-line-tables.ll



diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index ebdcb3c1f48b..f8d94e352f28 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -136,8 +136,6 @@ CODEGENOPT(FatalWarnings , 1, 0) ///< Set when 
-Wa,--fatal-warnings is
  ///< enabled.
 CODEGENOPT(NoWarn, 1, 0) ///< Set when -Wa,--no-warn is enabled.
 CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is 
enabled.
-CODEGENOPT(NoInlineLineTables, 1, 0) ///< Whether debug info should contain
- ///< inline line tables.
 CODEGENOPT(NoImplicitFloat   , 1, 0) ///< Set when -mno-implicit-float is 
enabled.
 CODEGENOPT(NoInfsFPMath  , 1, 0) ///< Assume FP arguments, results not 
+-Inf.
 CODEGENOPT(NoSignedZeros , 1, 0) ///< Allow ignoring the signedness of FP 
zero

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1bdeed69602f..2401a31ceb9a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1984,9 +1984,6 @@ def gcodeview_ghash : Flag<["-"], "gcodeview-ghash">,
   HelpText<"Emit type record hashes in a .debug$H section">,
   Flags<[CC1Option, CoreOption]>;
 def gno_codeview_ghash : Flag<["-"], "gno-codeview-ghash">, 
Flags<[CoreOption]>;
-def ginline_line_tables : Flag<["-"], "ginline-line-tables">, 
Flags<[CoreOption]>;
-def gno_inline_line_tables : Flag<["-"], "gno-inline-line-tables">,
-  Flags<[CC1Option, CoreOption]>, HelpText<"Don't emit inline line tables">;
 
 // Equivalent to our default dwarf version. Forces usual dwarf emission when
 // CodeView is enabled.

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 1b1d391a63df..3f9a52ab7638 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -764,10 +764,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
   Fn->addFnAttr("no-jump-tables",
 llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables));
 
-  // Add no-inline-line-tables value.
-  if (CGM.getCodeGenOpts().NoInlineLineTables)
-Fn->addFnAttr("no-inline-line-tables");
-
   // Add profile-sample-accurate value.
   if (CGM.getCodeGenOpts().ProfileSampleAccurate)
 Fn->addFnAttr("profile-sample-accurate");

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index f5abdf15fd44..c60dc76ae1bf 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3296,12 +3296,6 @@ static void RenderDebugOptions(const ToolChain &TC, 
const Driver &D,
 }
   }
 
-  // Omit inline line tables if requested.
-  if (!Args.hasFlag(options::OPT_ginline_line_tables,
-options::OPT_gno_inline_line_tables, false)) {
-CmdArgs.push_back("-gno-inline-line-tables");
-  }
-
   // Adjust the debug info kind for the given toolchain.
   TC.adjustDebugInfoKind(DebugInfoKind, Args);
 

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 29736d2dee18..f197a67e7a38 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -806,7 +806,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList 
&Args, InputKind IK,
   Opts.RecordCommandLine = Args.getLastArgValue(OPT_record_command_line);
   Opts.MergeAllConstants = Args.hasArg(OPT_fmerge_all_constants);
   Opts.NoCommon = Args.hasArg(OPT_fno_common);
-  Opts.NoInlineLineTables = Args.hasArg(OPT_gno_inline_line_tables);
   Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
   Opts.OptimizeSize = getOptimizationLevelSize(Args);
   Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) ||

diff  --git a/clang/test/CodeGen/debug-info-no-inline-line-tables.c 
b/clang/tes

[clang] ab76cfd - Recommit "[CodeView] Add option to disable inline line tables."

2019-11-04 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2019-11-04T09:15:26-08:00
New Revision: ab76cfdd200d35177df2042a1c0c7e86868d01bc

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

LOG: Recommit "[CodeView] Add option to disable inline line tables."

This reverts commit 004ed2b0d1b86d424643ffc88fce20ad8bab6804.
Original commit hash 6d03890384517919a3ba7fe4c35535425f278f89

Summary:
This adds a clang option to disable inline line tables. When it is used,
the inliner uses the call site as the location of the inlined function instead 
of
marking it as an inline location with the function location.

https://reviews.llvm.org/D67723

Added: 
clang/test/CodeGen/debug-info-no-inline-line-tables.c
llvm/test/Transforms/Inline/no-inline-line-tables.ll

Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
llvm/docs/LangRef.rst
llvm/include/llvm/IR/Attributes.td
llvm/lib/Transforms/Utils/InlineFunction.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 0a47869af61b..99559b5abe7b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -138,6 +138,8 @@ CODEGENOPT(FatalWarnings , 1, 0) ///< Set when 
-Wa,--fatal-warnings is
  ///< enabled.
 CODEGENOPT(NoWarn, 1, 0) ///< Set when -Wa,--no-warn is enabled.
 CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is 
enabled.
+CODEGENOPT(NoInlineLineTables, 1, 0) ///< Whether debug info should contain
+ ///< inline line tables.
 CODEGENOPT(NoImplicitFloat   , 1, 0) ///< Set when -mno-implicit-float is 
enabled.
 CODEGENOPT(NoInfsFPMath  , 1, 0) ///< Assume FP arguments, results not 
+-Inf.
 CODEGENOPT(NoSignedZeros , 1, 0) ///< Allow ignoring the signedness of FP 
zero

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3093dc65fce4..47e8bbf3eb12 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1998,6 +1998,9 @@ def gcodeview_ghash : Flag<["-"], "gcodeview-ghash">,
   HelpText<"Emit type record hashes in a .debug$H section">,
   Flags<[CC1Option, CoreOption]>;
 def gno_codeview_ghash : Flag<["-"], "gno-codeview-ghash">, 
Flags<[CoreOption]>;
+def ginline_line_tables : Flag<["-"], "ginline-line-tables">, 
Flags<[CoreOption]>;
+def gno_inline_line_tables : Flag<["-"], "gno-inline-line-tables">,
+  Flags<[CC1Option, CoreOption]>, HelpText<"Don't emit inline line tables">;
 
 def gfull : Flag<["-"], "gfull">, Group;
 def gused : Flag<["-"], "gused">, Group;

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 3f9a52ab7638..1b1d391a63df 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -764,6 +764,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD,
   Fn->addFnAttr("no-jump-tables",
 llvm::toStringRef(CGM.getCodeGenOpts().NoUseJumpTables));
 
+  // Add no-inline-line-tables value.
+  if (CGM.getCodeGenOpts().NoInlineLineTables)
+Fn->addFnAttr("no-inline-line-tables");
+
   // Add profile-sample-accurate value.
   if (CGM.getCodeGenOpts().ProfileSampleAccurate)
 Fn->addFnAttr("profile-sample-accurate");

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 529c33a16748..369d8cc1aa96 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3312,6 +3312,12 @@ static void RenderDebugOptions(const ToolChain &TC, 
const Driver &D,
 }
   }
 
+  // Omit inline line tables if requested.
+  if (Args.hasFlag(options::OPT_gno_inline_line_tables,
+   options::OPT_ginline_line_tables, false)) {
+CmdArgs.push_back("-gno-inline-line-tables");
+  }
+
   // Adjust the debug info kind for the given toolchain.
   TC.adjustDebugInfoKind(DebugInfoKind, Args);
 

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 0775d1021c54..c935ce5ebab5 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -809,6 +809,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList 
&Args, InputKind IK,
   Opts.RecordCommandLine = Args.getLastArgValue(OPT_record_command_line);
   Opts.MergeAllConstants = Args.hasArg(OPT_fmerge_all_constants);
   Opts.NoCommon = Args.hasArg(OPT_fno_common);
+  Opts.NoInlineLineTables = Args.hasArg(OPT_gno_inline_line_ta

r357643 - add periods

2019-04-03 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Wed Apr  3 15:19:07 2019
New Revision: 357643

URL: http://llvm.org/viewvc/llvm-project?rev=357643&view=rev
Log:
add periods

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

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=357643&r1=357642&r2=357643&view=diff
==
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Wed Apr  3 15:19:07 2019
@@ -1688,7 +1688,7 @@ EmitAtomicUpdateValue(CodeGenFunction &C
 UpRVal = OldRVal;
 DesiredLVal = CGF.MakeAddrLValue(DesiredAddr, AtomicLVal.getType());
   } else {
-// Build new lvalue for temp address
+// Build new lvalue for temp address.
 Address Ptr = Atomics.materializeRValue(OldRVal);
 LValue UpdateLVal;
 if (AtomicLVal.isBitField()) {
@@ -1721,7 +1721,7 @@ EmitAtomicUpdateValue(CodeGenFunction &C
 }
 UpRVal = CGF.EmitLoadOfLValue(UpdateLVal, SourceLocation());
   }
-  // Store new value in the corresponding memory area
+  // Store new value in the corresponding memory area.
   RValue NewRVal = UpdateOp(UpRVal);
   if (NewRVal.isScalar()) {
 CGF.EmitStoreThroughLValue(NewRVal, DesiredLVal);
@@ -1786,7 +1786,7 @@ void AtomicInfo::EmitAtomicUpdateOp(
SourceLocation(), 
/*AsValue=*/false);
   EmitAtomicUpdateValue(CGF, *this, OldRVal, UpdateOp, NewAtomicAddr);
   auto *DesiredVal = CGF.Builder.CreateLoad(NewAtomicIntAddr);
-  // Try to write new value using cmpxchg operation
+  // Try to write new value using cmpxchg operation.
   auto Res = EmitAtomicCompareExchangeOp(PHI, DesiredVal, AO, Failure);
   PHI->addIncoming(Res.first, CGF.Builder.GetInsertBlock());
   CGF.Builder.CreateCondBr(Res.second, ExitBB, ContBB);
@@ -1797,7 +1797,7 @@ static void EmitAtomicUpdateValue(CodeGe
   RValue UpdateRVal, Address DesiredAddr) {
   LValue AtomicLVal = Atomics.getAtomicLValue();
   LValue DesiredLVal;
-  // Build new lvalue for temp address
+  // Build new lvalue for temp address.
   if (AtomicLVal.isBitField()) {
 DesiredLVal =
 LValue::MakeBitfield(DesiredAddr, AtomicLVal.getBitFieldInfo(),
@@ -1814,7 +1814,7 @@ static void EmitAtomicUpdateValue(CodeGe
 DesiredAddr, AtomicLVal.getExtVectorElts(), AtomicLVal.getType(),
 AtomicLVal.getBaseInfo(), AtomicLVal.getTBAAInfo());
   }
-  // Store new value in the corresponding memory area
+  // Store new value in the corresponding memory area.
   assert(UpdateRVal.isScalar());
   CGF.EmitStoreThroughLValue(UpdateRVal, DesiredLVal);
 }
@@ -1866,7 +1866,7 @@ void AtomicInfo::EmitAtomicUpdateOp(llvm
   }
   EmitAtomicUpdateValue(CGF, *this, UpdateRVal, NewAtomicAddr);
   auto *DesiredVal = CGF.Builder.CreateLoad(NewAtomicIntAddr);
-  // Try to write new value using cmpxchg operation
+  // Try to write new value using cmpxchg operation.
   auto Res = EmitAtomicCompareExchangeOp(PHI, DesiredVal, AO, Failure);
   PHI->addIncoming(Res.first, CGF.Builder.GetInsertBlock());
   CGF.Builder.CreateCondBr(Res.second, ExitBB, ContBB);


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


r357928 - [MS] Add metadata for __declspec(allocator)

2019-04-08 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Mon Apr  8 10:58:29 2019
New Revision: 357928

URL: http://llvm.org/viewvc/llvm-project?rev=357928&view=rev
Log:
[MS] Add metadata for __declspec(allocator)

Summary:
Emit !heapallocsite in the metadata for calls to functions marked with
__declspec(allocator). Eventually this will be emitted as S_HEAPALLOCSITE debug
info in codeview.

Reviewers: rnk

Subscribers: jfb, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/CodeGen/debug-info-codeview-heapallocsite.c
Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=357928&r1=357927&r2=357928&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Apr  8 10:58:29 2019
@@ -3800,6 +3800,8 @@ RValue CodeGenFunction::EmitCall(const C
 
   llvm::FunctionType *IRFuncTy = getTypes().GetFunctionType(CallInfo);
 
+  const Decl *TargetDecl = Callee.getAbstractInfo().getCalleeDecl().getDecl();
+
 #ifndef NDEBUG
   if (!(CallInfo.isVariadic() && CallInfo.getArgStruct())) {
 // For an inalloca varargs function, we don't expect CallInfo to match the
@@ -4288,11 +4290,7 @@ RValue CodeGenFunction::EmitCall(const C
   // Apply always_inline to all calls within flatten functions.
   // FIXME: should this really take priority over __try, below?
   if (CurCodeDecl && CurCodeDecl->hasAttr() &&
-  !(Callee.getAbstractInfo().getCalleeDecl().getDecl() &&
-Callee.getAbstractInfo()
-.getCalleeDecl()
-.getDecl()
-->hasAttr())) {
+  !(TargetDecl && TargetDecl->hasAttr())) {
 Attrs =
 Attrs.addAttribute(getLLVMContext(), 
llvm::AttributeList::FunctionIndex,
llvm::Attribute::AlwaysInline);
@@ -4376,11 +4374,16 @@ RValue CodeGenFunction::EmitCall(const C
 
   // Suppress tail calls if requested.
   if (llvm::CallInst *Call = dyn_cast(CI)) {
-const Decl *TargetDecl = 
Callee.getAbstractInfo().getCalleeDecl().getDecl();
 if (TargetDecl && TargetDecl->hasAttr())
   Call->setTailCallKind(llvm::CallInst::TCK_NoTail);
   }
 
+  // Add metadata for calls to MSAllocator functions
+  // FIXME: Get the type that the return value is cast to.
+  if (!DisableDebugInfo && TargetDecl &&
+  TargetDecl->hasAttr())
+getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy, Loc);
+
   // 4. Finish the call.
 
   // If the call doesn't return, finish the basic block and clear the
@@ -4537,7 +4540,6 @@ RValue CodeGenFunction::EmitCall(const C
   } ();
 
   // Emit the assume_aligned check on the return value.
-  const Decl *TargetDecl = Callee.getAbstractInfo().getCalleeDecl().getDecl();
   if (Ret.isScalar() && TargetDecl) {
 if (const auto *AA = TargetDecl->getAttr()) {
   llvm::Value *OffsetValue = nullptr;

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=357928&r1=357927&r2=357928&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Apr  8 10:58:29 2019
@@ -1959,6 +1959,20 @@ llvm::DIType *CGDebugInfo::getOrCreateSt
   return T;
 }
 
+void CGDebugInfo::addHeapAllocSiteMetadata(llvm::Instruction *CI,
+   QualType D,
+   SourceLocation Loc) {
+  llvm::MDNode *node;
+  if (D.getTypePtr()->isVoidPointerType()) {
+node = llvm::MDNode::get(CGM.getLLVMContext(), None);
+  } else {
+QualType PointeeTy = D.getTypePtr()->getPointeeType();
+node = getOrCreateType(PointeeTy, getOrCreateFile(Loc));
+  }
+
+  CI->setMetadata("heapallocsite", node);
+}
+
 void CGDebugInfo::completeType(const EnumDecl *ED) {
   if (DebugKind <= codegenoptions::DebugLineTablesOnly)
 return;

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=357928&r1=357927&r2=357928&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Mon Apr  8 10:58:29 2019
@@ -476,6 +476,10 @@ public:
   /// Emit standalone debug info for a type.
   llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
 
+  /// Add heapallocsite metadata for MSAllocator calls.
+  void addHeapAllocSiteMetadata(llvm::Instruction *CallSite, QualType Ty,
+SourceLocation Loc);
+
   void completeType(const EnumDecl *ED);
   void completeType(const RecordDecl *RD);
   void completeRequiredType(const RecordDecl *RD);

Added

r357952 - Revert "[MS] Add metadata for __declspec(allocator)"

2019-04-08 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Mon Apr  8 15:46:41 2019
New Revision: 357952

URL: http://llvm.org/viewvc/llvm-project?rev=357952&view=rev
Log:
Revert "[MS] Add metadata for __declspec(allocator)"

This reverts commit e7bd735bb03a7b8141e32f7d6cb98e8914d8799e.
Reverting because of buildbot failure.

Removed:
cfe/trunk/test/CodeGen/debug-info-codeview-heapallocsite.c
Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=357952&r1=357951&r2=357952&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Apr  8 15:46:41 2019
@@ -3800,8 +3800,6 @@ RValue CodeGenFunction::EmitCall(const C
 
   llvm::FunctionType *IRFuncTy = getTypes().GetFunctionType(CallInfo);
 
-  const Decl *TargetDecl = Callee.getAbstractInfo().getCalleeDecl().getDecl();
-
 #ifndef NDEBUG
   if (!(CallInfo.isVariadic() && CallInfo.getArgStruct())) {
 // For an inalloca varargs function, we don't expect CallInfo to match the
@@ -4290,7 +4288,11 @@ RValue CodeGenFunction::EmitCall(const C
   // Apply always_inline to all calls within flatten functions.
   // FIXME: should this really take priority over __try, below?
   if (CurCodeDecl && CurCodeDecl->hasAttr() &&
-  !(TargetDecl && TargetDecl->hasAttr())) {
+  !(Callee.getAbstractInfo().getCalleeDecl().getDecl() &&
+Callee.getAbstractInfo()
+.getCalleeDecl()
+.getDecl()
+->hasAttr())) {
 Attrs =
 Attrs.addAttribute(getLLVMContext(), 
llvm::AttributeList::FunctionIndex,
llvm::Attribute::AlwaysInline);
@@ -4374,16 +4376,11 @@ RValue CodeGenFunction::EmitCall(const C
 
   // Suppress tail calls if requested.
   if (llvm::CallInst *Call = dyn_cast(CI)) {
+const Decl *TargetDecl = 
Callee.getAbstractInfo().getCalleeDecl().getDecl();
 if (TargetDecl && TargetDecl->hasAttr())
   Call->setTailCallKind(llvm::CallInst::TCK_NoTail);
   }
 
-  // Add metadata for calls to MSAllocator functions
-  // FIXME: Get the type that the return value is cast to.
-  if (!DisableDebugInfo && TargetDecl &&
-  TargetDecl->hasAttr())
-getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy, Loc);
-
   // 4. Finish the call.
 
   // If the call doesn't return, finish the basic block and clear the
@@ -4540,6 +4537,7 @@ RValue CodeGenFunction::EmitCall(const C
   } ();
 
   // Emit the assume_aligned check on the return value.
+  const Decl *TargetDecl = Callee.getAbstractInfo().getCalleeDecl().getDecl();
   if (Ret.isScalar() && TargetDecl) {
 if (const auto *AA = TargetDecl->getAttr()) {
   llvm::Value *OffsetValue = nullptr;

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=357952&r1=357951&r2=357952&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Apr  8 15:46:41 2019
@@ -1959,20 +1959,6 @@ llvm::DIType *CGDebugInfo::getOrCreateSt
   return T;
 }
 
-void CGDebugInfo::addHeapAllocSiteMetadata(llvm::Instruction *CI,
-   QualType D,
-   SourceLocation Loc) {
-  llvm::MDNode *node;
-  if (D.getTypePtr()->isVoidPointerType()) {
-node = llvm::MDNode::get(CGM.getLLVMContext(), None);
-  } else {
-QualType PointeeTy = D.getTypePtr()->getPointeeType();
-node = getOrCreateType(PointeeTy, getOrCreateFile(Loc));
-  }
-
-  CI->setMetadata("heapallocsite", node);
-}
-
 void CGDebugInfo::completeType(const EnumDecl *ED) {
   if (DebugKind <= codegenoptions::DebugLineTablesOnly)
 return;

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=357952&r1=357951&r2=357952&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Mon Apr  8 15:46:41 2019
@@ -476,10 +476,6 @@ public:
   /// Emit standalone debug info for a type.
   llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
 
-  /// Add heapallocsite metadata for MSAllocator calls.
-  void addHeapAllocSiteMetadata(llvm::Instruction *CallSite, QualType Ty,
-SourceLocation Loc);
-
   void completeType(const EnumDecl *ED);
   void completeType(const RecordDecl *RD);
   void completeRequiredType(const RecordDecl *RD);

Removed: cfe/trunk/test/CodeGen/debug-info-codeview-heapallocsite.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-codeview-heapallocsite.c?rev=357951&view=aut

r358307 - Relanding r357928 with fixed debuginfo check.

2019-04-12 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Fri Apr 12 13:25:30 2019
New Revision: 358307

URL: http://llvm.org/viewvc/llvm-project?rev=358307&view=rev
Log:
Relanding r357928 with fixed debuginfo check.

[MS] Add metadata for __declspec(allocator)

Original summary:
Emit !heapallocsite in the metadata for calls to functions marked with
__declspec(allocator). Eventually this will be emitted as S_HEAPALLOCSITE debug
info in codeview.

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

Added:
cfe/trunk/test/CodeGen/debug-info-codeview-heapallocsite.c
Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=358307&r1=358306&r2=358307&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri Apr 12 13:25:30 2019
@@ -3791,6 +3791,8 @@ RValue CodeGenFunction::EmitCall(const C
 
   llvm::FunctionType *IRFuncTy = getTypes().GetFunctionType(CallInfo);
 
+  const Decl *TargetDecl = Callee.getAbstractInfo().getCalleeDecl().getDecl();
+
 #ifndef NDEBUG
   if (!(CallInfo.isVariadic() && CallInfo.getArgStruct())) {
 // For an inalloca varargs function, we don't expect CallInfo to match the
@@ -4279,11 +4281,7 @@ RValue CodeGenFunction::EmitCall(const C
   // Apply always_inline to all calls within flatten functions.
   // FIXME: should this really take priority over __try, below?
   if (CurCodeDecl && CurCodeDecl->hasAttr() &&
-  !(Callee.getAbstractInfo().getCalleeDecl().getDecl() &&
-Callee.getAbstractInfo()
-.getCalleeDecl()
-.getDecl()
-->hasAttr())) {
+  !(TargetDecl && TargetDecl->hasAttr())) {
 Attrs =
 Attrs.addAttribute(getLLVMContext(), 
llvm::AttributeList::FunctionIndex,
llvm::Attribute::AlwaysInline);
@@ -4367,11 +4365,16 @@ RValue CodeGenFunction::EmitCall(const C
 
   // Suppress tail calls if requested.
   if (llvm::CallInst *Call = dyn_cast(CI)) {
-const Decl *TargetDecl = 
Callee.getAbstractInfo().getCalleeDecl().getDecl();
 if (TargetDecl && TargetDecl->hasAttr())
   Call->setTailCallKind(llvm::CallInst::TCK_NoTail);
   }
 
+  // Add metadata for calls to MSAllocator functions
+  // FIXME: Get the type that the return value is cast to.
+  if (getDebugInfo() && TargetDecl &&
+  TargetDecl->hasAttr())
+getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy, Loc);
+
   // 4. Finish the call.
 
   // If the call doesn't return, finish the basic block and clear the
@@ -4528,7 +4531,6 @@ RValue CodeGenFunction::EmitCall(const C
   } ();
 
   // Emit the assume_aligned check on the return value.
-  const Decl *TargetDecl = Callee.getAbstractInfo().getCalleeDecl().getDecl();
   if (Ret.isScalar() && TargetDecl) {
 if (const auto *AA = TargetDecl->getAttr()) {
   llvm::Value *OffsetValue = nullptr;

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=358307&r1=358306&r2=358307&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Apr 12 13:25:30 2019
@@ -1959,6 +1959,20 @@ llvm::DIType *CGDebugInfo::getOrCreateSt
   return T;
 }
 
+void CGDebugInfo::addHeapAllocSiteMetadata(llvm::Instruction *CI,
+   QualType D,
+   SourceLocation Loc) {
+  llvm::MDNode *node;
+  if (D.getTypePtr()->isVoidPointerType()) {
+node = llvm::MDNode::get(CGM.getLLVMContext(), None);
+  } else {
+QualType PointeeTy = D.getTypePtr()->getPointeeType();
+node = getOrCreateType(PointeeTy, getOrCreateFile(Loc));
+  }
+
+  CI->setMetadata("heapallocsite", node);
+}
+
 void CGDebugInfo::completeType(const EnumDecl *ED) {
   if (DebugKind <= codegenoptions::DebugLineTablesOnly)
 return;

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=358307&r1=358306&r2=358307&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Fri Apr 12 13:25:30 2019
@@ -476,6 +476,10 @@ public:
   /// Emit standalone debug info for a type.
   llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
 
+  /// Add heapallocsite metadata for MSAllocator calls.
+  void addHeapAllocSiteMetadata(llvm::Instruction *CallSite, QualType Ty,
+SourceLocation Loc);
+
   void completeType(const EnumDecl *ED);
   void completeType(const RecordDecl *RD);
   void completeRequiredType(const RecordDecl *RD);

Added: cfe/tr

r358590 - Remove --show-includes flag in crash reduce script

2019-04-17 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Wed Apr 17 09:20:56 2019
New Revision: 358590

URL: http://llvm.org/viewvc/llvm-project?rev=358590&view=rev
Log:
Remove --show-includes flag in crash reduce script

Modified:
cfe/trunk/utils/creduce-clang-crash.py

Modified: cfe/trunk/utils/creduce-clang-crash.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/creduce-clang-crash.py?rev=358590&r1=358589&r2=358590&view=diff
==
--- cfe/trunk/utils/creduce-clang-crash.py (original)
+++ cfe/trunk/utils/creduce-clang-crash.py Wed Apr 17 09:20:56 2019
@@ -286,6 +286,10 @@ class Reduce(object):
 opts_startswith=["-gcodeview",
  "-debug-info-kind=",
  "-debugger-tuning="])
+
+new_args = self.try_remove_args(new_args,
+msg="Removed --show-includes",
+opts_startswith=["--show-includes"])
 # Not suppressing warnings (-w) sometimes prevents the crash from occurring
 # after preprocessing
 new_args = self.try_remove_args(new_args,


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


r358783 - [MS] Emit S_HEAPALLOCSITE debug info

2019-04-19 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Fri Apr 19 14:09:11 2019
New Revision: 358783

URL: http://llvm.org/viewvc/llvm-project?rev=358783&view=rev
Log:
[MS] Emit S_HEAPALLOCSITE debug info

Summary:
This emits labels around heapallocsite calls and S_HEAPALLOCSITE debug
info in codeview. Currently only changes FastISel, so emitting labels still
needs to be implemented in SelectionDAG.

Reviewers: hans, rnk

Subscribers: aprantl, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

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

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=358783&r1=358782&r2=358783&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Apr 19 14:09:11 2019
@@ -1969,7 +1969,6 @@ void CGDebugInfo::addHeapAllocSiteMetada
 QualType PointeeTy = D.getTypePtr()->getPointeeType();
 node = getOrCreateType(PointeeTy, getOrCreateFile(Loc));
   }
-
   CI->setMetadata("heapallocsite", node);
 }
 


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


r359034 - Revert "[MS] Emit S_HEAPALLOCSITE debug info" because of ToTWin64(db)

2019-04-23 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Tue Apr 23 14:12:58 2019
New Revision: 359034

URL: http://llvm.org/viewvc/llvm-project?rev=359034&view=rev
Log:
Revert "[MS] Emit S_HEAPALLOCSITE debug info" because of ToTWin64(db)
buildbot failure.

This reverts commit d07d6d617713bececf57f3547434dd52f0f13f9e and
c774f687b6880484a126ed3e3d737e74c926f0ae.

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

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=359034&r1=359033&r2=359034&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Apr 23 14:12:58 2019
@@ -1969,6 +1969,7 @@ void CGDebugInfo::addHeapAllocSiteMetada
 QualType PointeeTy = D.getTypePtr()->getPointeeType();
 node = getOrCreateType(PointeeTy, getOrCreateFile(Loc));
   }
+
   CI->setMetadata("heapallocsite", node);
 }
 


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


r359054 - Fixes in creduce-clang-crash.py for clang crash message parsing and reading the command from the repro script.

2019-04-23 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Tue Apr 23 17:28:23 2019
New Revision: 359054

URL: http://llvm.org/viewvc/llvm-project?rev=359054&view=rev
Log:
Fixes in creduce-clang-crash.py for clang crash message parsing and reading the 
command from the repro script.

Modified:
cfe/trunk/utils/creduce-clang-crash.py

Modified: cfe/trunk/utils/creduce-clang-crash.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/creduce-clang-crash.py?rev=359054&r1=359053&r2=359054&view=diff
==
--- cfe/trunk/utils/creduce-clang-crash.py (original)
+++ cfe/trunk/utils/creduce-clang-crash.py Tue Apr 23 17:28:23 2019
@@ -93,9 +93,14 @@ class Reduce(object):
   def read_clang_args(self, crash_script, filename):
 print("\nReading arguments from crash script...")
 with open(crash_script) as f:
-  # Assume clang call is on the last line of the script
-  line = f.readlines()[-1]
-  cmd = shlex.split(line)
+  # Assume clang call is the first non comment line.
+  cmd = []
+  for line in f:
+if not line.lstrip().startswith('#'):
+  cmd = shlex.split(line)
+  break
+if not cmd:
+  sys.exit("Could not find command in the crash script.");
 
 # Remove clang and filename from the command
 # Assume the last occurrence of the filename is the clang input file
@@ -122,7 +127,7 @@ class Reduce(object):
 # Look for specific error messages
 regexes = [r"Assertion `(.+)' failed", # Linux assert()
r"Assertion failed: (.+),", # FreeBSD/Mac assert()
-   r"fatal error: backend error: (.+)",
+   r"fatal error: error in backend: (.+)",
r"LLVM ERROR: (.+)",
r"UNREACHABLE executed (at .+)?!",
r"LLVM IR generation of ceclaration '(.+)'",


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


r361400 - Combine two if cases because the second one is never reached.

2019-05-22 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Wed May 22 08:48:59 2019
New Revision: 361400

URL: http://llvm.org/viewvc/llvm-project?rev=361400&view=rev
Log:
Combine two if cases because the second one is never reached.

Subscribers: cfe-commits

Tags: #clang

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

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

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=361400&r1=361399&r2=361400&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed May 22 08:48:59 2019
@@ -4352,16 +4352,14 @@ void CGDebugInfo::EmitGlobalVariable(con
   llvm::DIFile *Unit = getOrCreateFile(VD->getLocation());
   StringRef Name = VD->getName();
   llvm::DIType *Ty = getOrCreateType(VD->getType(), Unit);
+
+  // Do not use global variables for enums.
   if (const auto *ECD = dyn_cast(VD)) {
 const auto *ED = cast(ECD->getDeclContext());
 assert(isa(ED->getTypeForDecl()) && "Enum without EnumType?");
-Ty = getOrCreateType(QualType(ED->getTypeForDecl(), 0), Unit);
-  }
-  // Do not use global variables for enums.
-  //
-  // FIXME: why not?
-  if (Ty->getTag() == llvm::dwarf::DW_TAG_enumeration_type)
 return;
+  }
+
   // Do not emit separate definitions for function local const/statics.
   if (isa(VD->getDeclContext()))
 return;


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


r362038 - CodeView - add static data members to global variable debug info.

2019-05-29 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Wed May 29 14:45:34 2019
New Revision: 362038

URL: http://llvm.org/viewvc/llvm-project?rev=362038&view=rev
Log:
CodeView - add static data members to global variable debug info.

Summary:
Add static data members to IR debug info's list of global variables
so that they are emitted as S_CONSTANT records.

Related to https://bugs.llvm.org/show_bug.cgi?id=41615.

Reviewers: rnk

Subscribers: aprantl, cfe-commits, llvm-commits, thakis

Tags: #clang, #llvm

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

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/CodeGenCXX/debug-info-static-member.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=362038&r1=362037&r2=362038&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed May 29 14:45:34 2019
@@ -4361,9 +4361,13 @@ void CGDebugInfo::EmitGlobalVariable(con
 return;
   }
 
-  // Do not emit separate definitions for function local const/statics.
+  llvm::DIScope *DContext = nullptr;
+
+  // Do not emit separate definitions for function local consts.
   if (isa(VD->getDeclContext()))
 return;
+
+  // Emit definition for static members in CodeView.
   VD = cast(VD->getCanonicalDecl());
   auto *VarD = cast(VD);
   if (VarD->isStaticDataMember()) {
@@ -4375,10 +4379,16 @@ void CGDebugInfo::EmitGlobalVariable(con
 // through its scope.
 RetainedTypes.push_back(
 CGM.getContext().getRecordType(RD).getAsOpaquePtr());
-return;
-  }
 
-  llvm::DIScope *DContext = getDeclContextDescriptor(VD);
+if (!CGM.getCodeGenOpts().EmitCodeView)
+  return;
+
+// Use the global scope for static members.
+DContext = getContextDescriptor(
+cast(CGM.getContext().getTranslationUnitDecl()), TheCU);
+  } else {
+DContext = getDeclContextDescriptor(VD);
+  }
 
   auto &GV = DeclCache[VD];
   if (GV)

Modified: cfe/trunk/test/CodeGenCXX/debug-info-static-member.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-static-member.cpp?rev=362038&r1=362037&r2=362038&view=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-static-member.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-static-member.cpp Wed May 29 14:45:34 
2019
@@ -1,6 +1,7 @@
 // RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck %s
 // RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S 
-o - | FileCheck %s
 // RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S 
-o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -gcodeview 
-debug-info-kind=limited %s -emit-llvm -o - | FileCheck --check-prefix MSVC %s
 // PR14471
 
 // CHECK: @_ZN1C1aE = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]]
@@ -35,6 +36,7 @@ public:
 // CHECK: [[A]] = !DIGlobalVariableExpression(var: [[AV:.*]], expr: 
!DIExpression())
 // CHECK: [[AV]] = distinct !DIGlobalVariable(name: "a",
 // CHECK-SAME:declaration: ![[DECL_A:[0-9]+]])
+// MSVC: distinct !DIGlobalVariable(name: "a"
 //
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, 
identifier: "_ZTS1X")
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"anon_static_decl_struct"
@@ -48,6 +50,7 @@ int C::a = 4;
 // CHECK: [[B]] = !DIGlobalVariableExpression(var: [[BV:.*]], expr: 
!DIExpression())
 // CHECK: [[BV]] = distinct !DIGlobalVariable(name: "b",
 // CHECK-SAME:declaration: ![[DECL_B:[0-9]+]])
+// MSVC: distinct !DIGlobalVariable(name: "b"
 // CHECK: ![[DECL_B]] = !DIDerivedType(tag: DW_TAG_member, name: "b"
 // CHECK-NOT: size:
 // CHECK-NOT: align:
@@ -95,6 +98,7 @@ int C::a = 4;
 int C::b = 2;
 // CHECK: [[C]] = !DIGlobalVariableExpression(var: [[CV:.*]], expr: 
!DIExpression())
 // CHECK: [[CV]] = distinct !DIGlobalVariable(name: "c", {{.*}} declaration: 
![[DECL_C]])
+// MSVC: distinct !DIGlobalVariable(name: "c"
 int C::c = 1;
 
 int main()
@@ -114,11 +118,18 @@ struct anon_static_decl_struct {
 };
 }
 
-
 int ref() {
   return anon_static_decl_struct::anon_static_decl_var;
 }
 
+// In MSVC, static data members should be emitted as global variables when 
used.
+// MSVC: !DIGlobalVariableExpression(var: [[ANON_STATIC_DECL:![0-9]+]],
+// MSVC-SAME: !DIExpression(DW_OP_constu, 117, DW_OP_stack_value)
+// MSVC: [[ANON_STATIC_DECL]] = distinct !DIGlobalVariable(name: 
"anon_static_decl_var"
+// MSVC: !DIGlobalVariableExpression(var: [[STATIC_DECL_TEMPL:![0-9]+]]
+// MSVC-SAME: !DIExpression(DW_OP_constu, 7, DW_OP_stack_value)
+// MSVC: [[STATIC_DECL_TEMPL]] = distinct !DIGlobalVariable(name: 
"static_decl_templ_var"
+
 

r362166 - Add enums as global variables in the IR metadata.

2019-05-30 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Thu May 30 15:04:11 2019
New Revision: 362166

URL: http://llvm.org/viewvc/llvm-project?rev=362166&view=rev
Log:
Add enums as global variables in the IR metadata.

Summary:
Keeps track of the enums that were used by saving them as DIGlobalVariables,
since CodeView emits debug info for global constants.

Reviewers: rnk

Subscribers: aprantl, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/CodeGenCXX/debug-info-enum.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=362166&r1=362165&r2=362166&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu May 30 15:04:11 2019
@@ -4240,7 +4240,7 @@ void CGDebugInfo::EmitDeclareOfBlockLite
 
 llvm::DIDerivedType *
 CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D) {
-  if (!D->isStaticDataMember())
+  if (!D || !D->isStaticDataMember())
 return nullptr;
 
   auto MI = StaticDataMemberCache.find(D->getCanonicalDecl());
@@ -4353,12 +4353,14 @@ void CGDebugInfo::EmitGlobalVariable(con
   StringRef Name = VD->getName();
   llvm::DIType *Ty = getOrCreateType(VD->getType(), Unit);
 
-  // Do not use global variables for enums.
+  // Do not use global variables for enums, unless for CodeView.
   if (const auto *ECD = dyn_cast(VD)) {
 const auto *ED = cast(ECD->getDeclContext());
 assert(isa(ED->getTypeForDecl()) && "Enum without EnumType?");
 (void)ED;
-return;
+
+if (!CGM.getCodeGenOpts().EmitCodeView)
+  return;
   }
 
   llvm::DIScope *DContext = nullptr;
@@ -4369,8 +4371,8 @@ void CGDebugInfo::EmitGlobalVariable(con
 
   // Emit definition for static members in CodeView.
   VD = cast(VD->getCanonicalDecl());
-  auto *VarD = cast(VD);
-  if (VarD->isStaticDataMember()) {
+  auto *VarD = dyn_cast(VD);
+  if (VarD && VarD->isStaticDataMember()) {
 auto *RD = cast(VarD->getDeclContext());
 getDeclContextDescriptor(VarD);
 // Ensure that the type is retained even though it's otherwise 
unreferenced.

Modified: cfe/trunk/test/CodeGenCXX/debug-info-enum.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-enum.cpp?rev=362166&r1=362165&r2=362166&view=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-enum.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-enum.cpp Thu May 30 15:04:11 2019
@@ -1,9 +1,15 @@
 // RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -gcodeview 
-debug-info-kind=limited %s -o - | FileCheck --check-prefix MSVC %s
 
 // CHECK: !DICompileUnit(
 // CHECK-SAME:   enums: [[ENUMS:![0-9]*]]
 // CHECK: [[ENUMS]] = !{[[E1:![0-9]*]], [[E2:![0-9]*]], [[E3:![0-9]*]]}
 
+// In MSVC check that used enum values are emitted as globals.
+// MSVC: !DICompileUnit(
+// MSVC-SAME:   globals: [[GLOBALS:![0-9]*]]
+// MSVC: [[GLOBALS]] = !{[[G1:![0-9]*]], [[G2:![0-9]*]]}
+
 namespace test1 {
 // CHECK: [[E1]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "e"
 // CHECK-SAME:  scope: [[TEST1:![0-9]*]]
@@ -12,6 +18,10 @@ namespace test1 {
 // CHECK: [[TEST1]] = !DINamespace(name: "test1"
 // CHECK: [[TEST1_ENUMS]] = !{[[TEST1_E:![0-9]*]]}
 // CHECK: [[TEST1_E]] = !DIEnumerator(name: "E", value: 0, isUnsigned: true)
+
+// MSVC: [[G1]] = !DIGlobalVariableExpression(var: [[VAR1:![0-9]*]],
+// MSVC-SAME: expr: 
!DIExpression(DW_OP_constu, 0
+// MSVC: [[VAR1]] = distinct !DIGlobalVariable(name: "E"
 enum e { E };
 void foo() {
   int v = E;
@@ -25,6 +35,10 @@ namespace test2 {
 // CHECK-SAME:  elements: [[TEST1_ENUMS]]
 // CHECK-SAME:  identifier: "_ZTSN5test21eE"
 // CHECK: [[TEST2]] = !DINamespace(name: "test2"
+
+// MSVC: [[G2]] = !DIGlobalVariableExpression(var: [[VAR2:![0-9]*]],
+// MSVC-SAME: expr: 
!DIExpression(DW_OP_constu, 0
+// MSVC: [[VAR2]] = distinct !DIGlobalVariable(name: "E"
 enum e { E };
 bool func(int i) {
   return i == E;


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


r359216 - creduce-clang-crash: add -F flag to grep to avoid interpreting string as regex

2019-04-25 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Thu Apr 25 11:00:25 2019
New Revision: 359216

URL: http://llvm.org/viewvc/llvm-project?rev=359216&view=rev
Log:
creduce-clang-crash: add -F flag to grep to avoid interpreting string as regex

Modified:
cfe/trunk/utils/creduce-clang-crash.py

Modified: cfe/trunk/utils/creduce-clang-crash.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/creduce-clang-crash.py?rev=359216&r1=359215&r2=359216&view=diff
==
--- cfe/trunk/utils/creduce-clang-crash.py (original)
+++ cfe/trunk/utils/creduce-clang-crash.py Thu Apr 25 11:00:25 2019
@@ -187,7 +187,7 @@ class Reduce(object):
 (pipes.quote(not_cmd), crash_flag, quote_cmd(self.get_crash_cmd()))
 
 for msg in self.expected_output:
-  output += 'grep %s t.log || exit 1\n' % pipes.quote(msg)
+  output += 'grep -F %s t.log || exit 1\n' % pipes.quote(msg)
 
 write_to_script(output, self.testfile)
 self.check_interestingness()


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


r359823 - Change the metadata for heapallocsite calls when the type is cast.

2019-05-02 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Thu May  2 13:07:35 2019
New Revision: 359823

URL: http://llvm.org/viewvc/llvm-project?rev=359823&view=rev
Log:
Change the metadata for heapallocsite calls when the type is cast.

Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/test/CodeGen/debug-info-codeview-heapallocsite.c

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=359823&r1=359822&r2=359823&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu May  2 13:07:35 2019
@@ -4370,7 +4370,6 @@ RValue CodeGenFunction::EmitCall(const C
   }
 
   // Add metadata for calls to MSAllocator functions
-  // FIXME: Get the type that the return value is cast to.
   if (getDebugInfo() && TargetDecl &&
   TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy, Loc);

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=359823&r1=359822&r2=359823&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu May  2 13:07:35 2019
@@ -2063,6 +2063,12 @@ Value *ScalarExprEmitter::VisitCastExpr(
   }
 }
 
+// Update heapallocsite metadata when there is an explicit cast.
+if (llvm::CallInst *CI = dyn_cast(Src))
+  if (CI->getMetadata("heapallocsite") && isa(CE))
+  CGF.getDebugInfo()->
+  addHeapAllocSiteMetadata(CI, CE->getType(), CE->getExprLoc());
+
 return Builder.CreateBitCast(Src, DstTy);
   }
   case CK_AddressSpaceConversion: {

Modified: cfe/trunk/test/CodeGen/debug-info-codeview-heapallocsite.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-info-codeview-heapallocsite.c?rev=359823&r1=359822&r2=359823&view=diff
==
--- cfe/trunk/test/CodeGen/debug-info-codeview-heapallocsite.c (original)
+++ cfe/trunk/test/CodeGen/debug-info-codeview-heapallocsite.c Thu May  2 
13:07:35 2019
@@ -1,27 +1,23 @@
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -debug-info-kind=limited 
-gcodeview -fdeclspec -S -emit-llvm < %s | FileCheck %s
 
-struct Foo {
-  int x;
-};
+struct Foo;
+struct Bar;
 
 __declspec(allocator) void *alloc_void();
-__declspec(allocator) struct Foo *alloc_foo();
 
-void call_alloc_void() {
-  struct Foo *p = (struct Foo*)alloc_void();
+void call_alloc() {
+  struct Foo *p = alloc_void();
+  struct Foo *q = (struct Foo*)alloc_void();
+  struct Foo *r = (struct Foo*)(struct Bar*)alloc_void();
 }
 
-void call_alloc_foo() {
-  struct Foo *p = alloc_foo();
-}
-
-// CHECK-LABEL: define {{.*}}void @call_alloc_void
+// CHECK-LABEL: define {{.*}}void @call_alloc
 // CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
-
-// CHECK-LABEL: define {{.*}}void @call_alloc_foo
-// CHECK: call %struct.Foo* {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
+// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2:!.*]]
+// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
 
 // CHECK: [[DBG1]] = !{}
-// CHECK: [[DBG2]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
+// CHECK: [[DBG2]] = !DICompositeType(tag: DW_TAG_structure_type,
 // CHECK-SAME: name: "Foo"
-
+// CHECK: [[DBG3]] = !DICompositeType(tag: DW_TAG_structure_type,
+// CHECK-SAME: name: "Bar"


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


r371568 - Reland "Change the X86 datalayout to add three address spaces

2019-09-10 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Tue Sep 10 16:15:38 2019
New Revision: 371568

URL: http://llvm.org/viewvc/llvm-project?rev=371568&view=rev
Log:
Reland "Change the X86 datalayout to add three address spaces
 for 32 bit signed, 32 bit unsigned, and 64 bit pointers."
This reverts 57076d3199fc2b0af4a3736b7749dd5462cacda5.

Original review at https://reviews.llvm.org/D64931.
Review for added fix at https://reviews.llvm.org/D66843.

Modified:
cfe/trunk/lib/Basic/Targets/OSTargets.h
cfe/trunk/lib/Basic/Targets/X86.h
cfe/trunk/test/CodeGen/Inputs/thinlto-multi-module.ll
cfe/trunk/test/CodeGen/Inputs/thinlto_backend.ll
cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict1.ll
cfe/trunk/test/CodeGen/Inputs/thinlto_backend_local_name_conflict2.ll
cfe/trunk/test/CodeGen/iamcu-abi.c
cfe/trunk/test/CodeGen/target-data.c
cfe/trunk/test/CodeGen/thinlto-diagnostic-handler-remarks-with-hotness.ll
cfe/trunk/test/CodeGen/thinlto-distributed-backend-skip.ll
cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll
cfe/trunk/test/CodeGen/thinlto-distributed-cfi.ll
cfe/trunk/test/CodeGen/thinlto-distributed.ll
cfe/trunk/test/CodeGen/thinlto-multi-module.ll
cfe/trunk/test/CodeGen/thinlto_backend.ll
cfe/trunk/test/CodeGen/thinlto_backend_local_name_conflict.ll

Modified: cfe/trunk/lib/Basic/Targets/OSTargets.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/OSTargets.h?rev=371568&r1=371567&r2=371568&view=diff
==
--- cfe/trunk/lib/Basic/Targets/OSTargets.h (original)
+++ cfe/trunk/lib/Basic/Targets/OSTargets.h Tue Sep 10 16:15:38 2019
@@ -775,9 +775,11 @@ public:
 if (Triple.getArch() == llvm::Triple::arm) {
   // Handled in ARM's setABI().
 } else if (Triple.getArch() == llvm::Triple::x86) {
-  this->resetDataLayout("e-m:e-p:32:32-i64:64-n8:16:32-S128");
+  this->resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-"
+"i64:64-n8:16:32-S128");
 } else if (Triple.getArch() == llvm::Triple::x86_64) {
-  this->resetDataLayout("e-m:e-p:32:32-i64:64-n8:16:32:64-S128");
+  this->resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-"
+"i64:64-n8:16:32:64-S128");
 } else if (Triple.getArch() == llvm::Triple::mipsel) {
   // Handled on mips' setDataLayout.
 } else {

Modified: cfe/trunk/lib/Basic/Targets/X86.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.h?rev=371568&r1=371567&r2=371568&view=diff
==
--- cfe/trunk/lib/Basic/Targets/X86.h (original)
+++ cfe/trunk/lib/Basic/Targets/X86.h Tue Sep 10 16:15:38 2019
@@ -339,7 +339,8 @@ public:
 LongDoubleWidth = 96;
 LongDoubleAlign = 32;
 SuitableAlign = 128;
-resetDataLayout("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128");
+resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-"
+"f80:32-n8:16:32-S128");
 SizeType = UnsignedInt;
 PtrDiffType = SignedInt;
 IntPtrType = SignedInt;
@@ -439,7 +440,8 @@ public:
   UseSignedCharForObjCBool = false;
 SizeType = UnsignedLong;
 IntPtrType = SignedLong;
-resetDataLayout("e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128");
+resetDataLayout("e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-"
+"f80:128-n8:16:32-S128");
 HasAlignMac68kSupport = true;
   }
 
@@ -464,9 +466,10 @@ public:
 DoubleAlign = LongLongAlign = 64;
 bool IsWinCOFF =
 getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
-resetDataLayout(IsWinCOFF
-? "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
-: "e-m:e-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32");
+resetDataLayout(IsWinCOFF ? "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:"
+"64-i64:64-f80:32-n8:16:32-a:0:32-S32"
+  : "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:"
+"64-i64:64-f80:32-n8:16:32-a:0:32-S32");
   }
 };
 
@@ -514,7 +517,8 @@ public:
   : X86_32TargetInfo(Triple, Opts) {
 this->WCharType = TargetInfo::UnsignedShort;
 DoubleAlign = LongLongAlign = 64;
-resetDataLayout("e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32");
+
resetDataLayout("e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:"
+"32-n8:16:32-a:0:32-S32");
   }
 
   void getTargetDefines(const LangOptions &Opts,
@@ -551,7 +555,8 @@ public:
   : X86_32TargetInfo(Triple, Opts) {
 LongDoubleWidth = 64;
 LongDoubleFormat = &llvm::APFloat::IEEEdouble();
-resetDataLayout("e-m:e-p:32:32-i64:32-f64:32-f128:32-n8:16:32-a:0:32-S32");
+
resetDataLayout("e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:32-f64:"
+"32-f1

r373950 - Fix for expanding __pragmas in macro arguments

2019-10-07 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Mon Oct  7 12:41:53 2019
New Revision: 373950

URL: http://llvm.org/viewvc/llvm-project?rev=373950&view=rev
Log:
Fix for expanding __pragmas in macro arguments

Summary:
Avoid parsing __pragma into an annotation token when macro arguments are 
pre-expanded.
This is what clang currently does when parsing _Pragmas.

Fixes https://bugs.llvm.org/show_bug.cgi?id=41128, where clang crashed
when trying to get the length of an annotation token.

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/test/Preprocessor/pragma_microsoft.c

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=373950&r1=373949&r2=373950&view=diff
==
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Mon Oct  7 12:41:53 2019
@@ -121,6 +121,40 @@ void PragmaNamespace::HandlePragma(Prepr
 // Preprocessor Pragma Directive Handling.
 
//===--===//
 
+namespace {
+// TokenCollector provides the option to collect tokens that were "read"
+// and return them to the stream to be read later.
+// Currently used when reading _Pragma/__pragma directives.
+struct TokenCollector {
+  Preprocessor &Self;
+  bool Collect;
+  SmallVector Tokens;
+  Token &Tok;
+
+  void lex() {
+if (Collect)
+  Tokens.push_back(Tok);
+Self.Lex(Tok);
+  }
+
+  void revert() {
+assert(Collect && "did not collect tokens");
+assert(!Tokens.empty() && "collected unexpected number of tokens");
+
+// Push the ( "string" ) tokens into the token stream.
+auto Toks = std::make_unique(Tokens.size());
+std::copy(Tokens.begin() + 1, Tokens.end(), Toks.get());
+Toks[Tokens.size() - 1] = Tok;
+Self.EnterTokenStream(std::move(Toks), Tokens.size(),
+  /*DisableMacroExpansion*/ true,
+  /*IsReinject*/ true);
+
+// ... and return the pragma token unchanged.
+Tok = *Tokens.begin();
+  }
+};
+} // namespace
+
 /// HandlePragmaDirective - The "\#pragma" directive has been parsed.  Lex the
 /// rest of the pragma, passing it to the registered pragma handlers.
 void Preprocessor::HandlePragmaDirective(PragmaIntroducer Introducer) {
@@ -166,35 +200,6 @@ void Preprocessor::Handle_Pragma(Token &
   // In Case #2, we check the syntax now, but then put the tokens back into the
   // token stream for later consumption.
 
-  struct TokenCollector {
-Preprocessor &Self;
-bool Collect;
-SmallVector Tokens;
-Token &Tok;
-
-void lex() {
-  if (Collect)
-Tokens.push_back(Tok);
-  Self.Lex(Tok);
-}
-
-void revert() {
-  assert(Collect && "did not collect tokens");
-  assert(!Tokens.empty() && "collected unexpected number of tokens");
-
-  // Push the ( "string" ) tokens into the token stream.
-  auto Toks = std::make_unique(Tokens.size());
-  std::copy(Tokens.begin() + 1, Tokens.end(), Toks.get());
-  Toks[Tokens.size() - 1] = Tok;
-  Self.EnterTokenStream(std::move(Toks), Tokens.size(),
-/*DisableMacroExpansion*/ true,
-/*IsReinject*/ true);
-
-  // ... and return the _Pragma token unchanged.
-  Tok = *Tokens.begin();
-}
-  };
-
   TokenCollector Toks = {*this, InMacroArgPreExpansion, {}, Tok};
 
   // Remember the pragma token location.
@@ -328,11 +333,15 @@ void Preprocessor::Handle_Pragma(Token &
 /// HandleMicrosoft__pragma - Like Handle_Pragma except the pragma text
 /// is not enclosed within a string literal.
 void Preprocessor::HandleMicrosoft__pragma(Token &Tok) {
+  // During macro pre-expansion, check the syntax now but put the tokens back
+  // into the token stream for later consumption. Same as Handle_Pragma.
+  TokenCollector Toks = {*this, InMacroArgPreExpansion, {}, Tok};
+
   // Remember the pragma token location.
   SourceLocation PragmaLoc = Tok.getLocation();
 
   // Read the '('.
-  Lex(Tok);
+  Toks.lex();
   if (Tok.isNot(tok::l_paren)) {
 Diag(PragmaLoc, diag::err__Pragma_malformed);
 return;
@@ -341,14 +350,14 @@ void Preprocessor::HandleMicrosoft__prag
   // Get the tokens enclosed within the __pragma(), as well as the final ')'.
   SmallVector PragmaToks;
   int NumParens = 0;
-  Lex(Tok);
+  Toks.lex();
   while (Tok.isNot(tok::eof)) {
 PragmaToks.push_back(Tok);
 if (Tok.is(tok::l_paren))
   NumParens++;
 else if (Tok.is(tok::r_paren) && NumParens-- == 0)
   break;
-Lex(Tok);
+Toks.lex();
   }
 
   if (Tok.is(tok::eof)) {
@@ -356,6 +365,12 @@ void Preprocessor::HandleMicrosoft__prag
 return;
   }
 
+  // If we're expanding a macro argument, put the tokens back.
+  if (InMacroArgPreExpansion) {
+Toks.revert();
+return;
+  }
+
   PragmaToks.front().setFlag

[clang] 26e9c99 - [Docs] Add some documentation for constructor homing, a debug info optimization (-fuse-ctor-homing)

2021-02-03 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-02-03T15:25:49-08:00
New Revision: 26e9c99010b6870ee5c8ce998a84214e06f3f3a9

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

LOG: [Docs] Add some documentation for constructor homing, a debug info 
optimization (-fuse-ctor-homing)

Adding this, since there's currently no documentation about this.

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

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index b9024a3006f1..a2fc8c06dc6e 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2504,6 +2504,18 @@ below. If multiple flags are present, the last one is 
used.
**-fno-standalone-debug** option can be used to get to turn on the
vtable-based optimization described above.
 
+.. option:: -fuse-ctor-homing
+
+   This optimization is similar to the optimizations that are enabled as part
+   of -fno-standalone-debug. Here, Clang only emits type info for a
+   non-trivial, non-aggregate C++ class in the modules that contain a
+   definition of one of its constructors. This relies on the additional
+   assumption that all classes that are not trivially constructible have a
+   non-trivial constructor that is used somewhere.
+
+   This flag is not enabled by default, and needs to be used with -cc1 or
+   -Xclang.
+
 .. option:: -g
 
   Generate complete debug info.



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


[clang] 1b5c291 - [DebugInfo] Add an attribute to force type info to be emitted for

2021-02-12 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-02-12T10:16:49-08:00
New Revision: 1b5c2915a2318705727ada586290de15e2cad202

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

LOG: [DebugInfo] Add an attribute to force type info to be emitted for
class types.

The goal is to provide a way to bypass constructor homing when emitting
class definitions and force class definitions in the debug info.

Not sure about the wording of the attribute, or whether it should be
specific to classes with constructors

Added: 
clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp

Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index bc2d8ceeeb6c..5bddef1b4ef2 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1660,6 +1660,13 @@ def NoDebug : InheritableAttr {
   let Documentation = [NoDebugDocs];
 }
 
+def DebugTypeInfoAsNeeded : InheritableAttr {
+  let Spellings = [Clang<"debug_type_info_as_needed">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let Documentation = [Undocumented];
+  let SimpleHandler = 1;
+}
+
 def NoDuplicate : InheritableAttr {
   let Spellings = [Clang<"noduplicate">];
   let Subjects = SubjectList<[Function]>;

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 48b9bf049f48..ef17983b446a 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2344,6 +2344,10 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
   if (!CXXDecl)
 return false;
 
+  // Don't omit definition if marked with attribute.
+  if (RD->hasAttr())
+return false;
+
   // Only emit complete debug info for a dynamic class when its vtable is
   // emitted.  However, Microsoft debuggers don't resolve type information
   // across DLL boundaries, so skip this optimization if the class or any of 
its

diff  --git a/clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp 
b/clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp
new file mode 100644
index ..a2f0eae314c8
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -DSETATTR=0 -emit-llvm -std=c++14 
-debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=DEBUG
+// RUN: %clang_cc1 -DSETATTR=1 -emit-llvm -std=c++14 
-debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=WITHATTR
+
+#if SETATTR
+#define DEBUGASNEEDED __attribute__((debug_type_info_as_needed))
+#else
+#define DEBUGASNEEDED
+#endif
+
+// Struct that isn't constructed, so its full type info should be omitted with
+// -debug-info-kind=constructor.
+struct DEBUGASNEEDED some_struct {
+  some_struct() {}
+};
+
+void func1(some_struct s) {}
+// void func2() { func1(); }
+// DEBUG:  !DICompositeType({{.*}}name: "some_struct"
+// DEBUG-SAME:  flags: {{.*}}DIFlagFwdDecl
+// WITHATTR: !DICompositeType({{.*}}name: "some_struct"
+// WITHATTR-NOT: DIFlagFwdDecl
+



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


[clang] 3fe465f - Revert "[DebugInfo] Add an attribute to force type info to be emitted for"

2021-02-12 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-02-12T10:18:17-08:00
New Revision: 3fe465fb2cd64cd7bd910c761920e3378fe8d1b0

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

LOG: Revert "[DebugInfo] Add an attribute to force type info to be emitted for"

Didn't mean to commit this.

This reverts commit 1b5c2915a2318705727ada586290de15e2cad202.

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 
clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp



diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 5bddef1b4ef2..bc2d8ceeeb6c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1660,13 +1660,6 @@ def NoDebug : InheritableAttr {
   let Documentation = [NoDebugDocs];
 }
 
-def DebugTypeInfoAsNeeded : InheritableAttr {
-  let Spellings = [Clang<"debug_type_info_as_needed">];
-  let Subjects = SubjectList<[CXXRecord]>;
-  let Documentation = [Undocumented];
-  let SimpleHandler = 1;
-}
-
 def NoDuplicate : InheritableAttr {
   let Spellings = [Clang<"noduplicate">];
   let Subjects = SubjectList<[Function]>;

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index ef17983b446a..48b9bf049f48 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2344,10 +2344,6 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
   if (!CXXDecl)
 return false;
 
-  // Don't omit definition if marked with attribute.
-  if (RD->hasAttr())
-return false;
-
   // Only emit complete debug info for a dynamic class when its vtable is
   // emitted.  However, Microsoft debuggers don't resolve type information
   // across DLL boundaries, so skip this optimization if the class or any of 
its

diff  --git a/clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp 
b/clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp
deleted file mode 100644
index a2f0eae314c8..
--- a/clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-// RUN: %clang_cc1 -DSETATTR=0 -emit-llvm -std=c++14 
-debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=DEBUG
-// RUN: %clang_cc1 -DSETATTR=1 -emit-llvm -std=c++14 
-debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=WITHATTR
-
-#if SETATTR
-#define DEBUGASNEEDED __attribute__((debug_type_info_as_needed))
-#else
-#define DEBUGASNEEDED
-#endif
-
-// Struct that isn't constructed, so its full type info should be omitted with
-// -debug-info-kind=constructor.
-struct DEBUGASNEEDED some_struct {
-  some_struct() {}
-};
-
-void func1(some_struct s) {}
-// void func2() { func1(); }
-// DEBUG:  !DICompositeType({{.*}}name: "some_struct"
-// DEBUG-SAME:  flags: {{.*}}DIFlagFwdDecl
-// WITHATTR: !DICompositeType({{.*}}name: "some_struct"
-// WITHATTR-NOT: DIFlagFwdDecl
-



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


[clang] 589ce5f - [DebugInfo] Move constructor homing case in shouldOmitDefinition.

2020-08-24 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-08-24T20:17:59-07:00
New Revision: 589ce5f7050dd83fd3f7dbc182ea0fb051ece994

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

LOG: [DebugInfo] Move constructor homing case in shouldOmitDefinition.

For some reason the ctor homing case was before the template
specialization case, and could have returned false too early.
I moved the code out into a separate function to avoid this.

Also added a run line to the template specialization test. I guess
all the -debug-info-kind=limited tests should still pass with =constructor,
but it's probably unnecessary to test for all of those.

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index e3442ecd4bd5..c2929d027a1b 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2260,6 +2260,25 @@ static bool 
hasExplicitMemberDefinition(CXXRecordDecl::method_iterator I,
   return false;
 }
 
+static bool canUseCtorHoming(const CXXRecordDecl *RD) {
+  // Constructor homing can be used for classes that have at least one
+  // constructor and have no trivial or constexpr constructors.
+  // Skip this optimization if the class or any of its methods are marked
+  // dllimport.
+  if (RD->isLambda() || RD->hasConstexprNonCopyMoveConstructor() ||
+  isClassOrMethodDLLImport(RD))
+return false;
+
+  if (RD->ctors().empty())
+return false;
+
+  for (const auto *Ctor : RD->ctors())
+if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
+  return false;
+
+  return true;
+}
+
 static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
  bool DebugTypeExtRefs, const RecordDecl *RD,
  const LangOptions &LangOpts) {
@@ -2294,23 +2313,6 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
   !isClassOrMethodDLLImport(CXXDecl))
 return true;
 
-  // In constructor debug mode, only emit debug info for a class when its
-  // constructor is emitted. Skip this optimization if the class or any of
-  // its methods are marked dllimport.
-  //
-  // This applies to classes that don't have any trivial constructors and have
-  // at least one constructor.
-  if (DebugKind == codegenoptions::DebugInfoConstructor &&
-  !CXXDecl->isLambda() && !CXXDecl->hasConstexprNonCopyMoveConstructor() &&
-  !isClassOrMethodDLLImport(CXXDecl)) {
-if (CXXDecl->ctors().empty())
-  return false;
-for (const auto *Ctor : CXXDecl->ctors())
-  if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
-return false;
-return true;
-  }
-
   TemplateSpecializationKind Spec = TSK_Undeclared;
   if (const auto *SD = dyn_cast(RD))
 Spec = SD->getSpecializationKind();
@@ -2320,6 +2322,12 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
   CXXDecl->method_end()))
 return true;
 
+  // In constructor homing mode, only emit complete debug info for a class
+  // when its constructor is emitted.
+  if ((DebugKind != codegenoptions::DebugInfoConstructor) &&
+  canUseCtorHoming(CXXDecl))
+return true;
+
   return false;
 }
 

diff  --git 
a/clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp 
b/clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
index 4e41c4092bf4..ff0457e94404 100644
--- a/clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
+++ b/clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
@@ -1,4 +1,7 @@
-// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple 
-debug-info-kind=limited %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple 
-debug-info-kind=limited %s -o - | FileCheck %
+
+// Make sure this still works with constructor homing.
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple 
-debug-info-kind=constructor %s -o - | FileCheck %s
 
 // Run again with -gline-tables-only or -gline-directives-only and verify we 
don't crash.  We won't output
 // type info at all.



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


[clang] b1009ee - Reland "[DebugInfo] Move constructor homing case in shouldOmitDefinition."

2020-08-25 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-08-25T12:36:11-07:00
New Revision: b1009ee84fc0242bcebd07889306bf39d9b7170f

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

LOG: Reland "[DebugInfo] Move constructor homing case in shouldOmitDefinition."

For some reason the ctor homing case was before the template
specialization case, and could have returned false too early.
I moved the code out into a separate function to avoid this.

This reverts commit 05777ab941063192b9ccb1775358a83a2700ccc1.

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index e3442ecd4bd5..36bab9c22d43 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2260,6 +2260,25 @@ static bool 
hasExplicitMemberDefinition(CXXRecordDecl::method_iterator I,
   return false;
 }
 
+static bool canUseCtorHoming(const CXXRecordDecl *RD) {
+  // Constructor homing can be used for classes that have at least one
+  // constructor and have no trivial or constexpr constructors.
+  // Skip this optimization if the class or any of its methods are marked
+  // dllimport.
+  if (RD->isLambda() || RD->hasConstexprNonCopyMoveConstructor() ||
+  isClassOrMethodDLLImport(RD))
+return false;
+
+  if (RD->ctors().empty())
+return false;
+
+  for (const auto *Ctor : RD->ctors())
+if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
+  return false;
+
+  return true;
+}
+
 static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
  bool DebugTypeExtRefs, const RecordDecl *RD,
  const LangOptions &LangOpts) {
@@ -2294,23 +2313,6 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
   !isClassOrMethodDLLImport(CXXDecl))
 return true;
 
-  // In constructor debug mode, only emit debug info for a class when its
-  // constructor is emitted. Skip this optimization if the class or any of
-  // its methods are marked dllimport.
-  //
-  // This applies to classes that don't have any trivial constructors and have
-  // at least one constructor.
-  if (DebugKind == codegenoptions::DebugInfoConstructor &&
-  !CXXDecl->isLambda() && !CXXDecl->hasConstexprNonCopyMoveConstructor() &&
-  !isClassOrMethodDLLImport(CXXDecl)) {
-if (CXXDecl->ctors().empty())
-  return false;
-for (const auto *Ctor : CXXDecl->ctors())
-  if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
-return false;
-return true;
-  }
-
   TemplateSpecializationKind Spec = TSK_Undeclared;
   if (const auto *SD = dyn_cast(RD))
 Spec = SD->getSpecializationKind();
@@ -2320,6 +2322,12 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
   CXXDecl->method_end()))
 return true;
 
+  // In constructor homing mode, only emit complete debug info for a class
+  // when its constructor is emitted.
+  if ((DebugKind == codegenoptions::DebugInfoConstructor) &&
+  canUseCtorHoming(CXXDecl))
+return true;
+
   return false;
 }
 

diff  --git 
a/clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp 
b/clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
index 4e41c4092bf4..b756674f54c4 100644
--- a/clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
+++ b/clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple 
-debug-info-kind=limited %s -o - | FileCheck %s
 
+// Make sure this still works with constructor homing.
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple 
-debug-info-kind=constructor %s -o - | FileCheck %s
+
 // Run again with -gline-tables-only or -gline-directives-only and verify we 
don't crash.  We won't output
 // type info at all.
 // RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple 
-debug-info-kind=line-tables-only %s -o - | FileCheck %s -check-prefix 
LINES-ONLY



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


[clang] aaf1a96 - [DebugInfo] Add size to class declarations in debug info.

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

Author: Amy Huang
Date: 2020-09-03T15:42:27-07:00
New Revision: aaf1a96408b1587b5fb80a3a7c424348cb09e577

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

LOG: [DebugInfo] Add size to class declarations in debug info.

This adds the size to forward declared class DITypes, if the size is known.

Fixes an issue where we determine whether to emit fragments based on the
type size, so fragments would sometimes be incorrectly emitted if there
was no size.

Bug: https://bugs.llvm.org/show_bug.cgi?id=47338

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-class.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 8a85a24910e4..1fdb6814c7bd 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1031,6 +1031,10 @@ CGDebugInfo::getOrCreateRecordFwdDecl(const RecordType 
*Ty,
   uint64_t Size = 0;
   uint32_t Align = 0;
 
+  const RecordDecl *D = RD->getDefinition();
+  if (D && D->isCompleteDefinition())
+Size = CGM.getContext().getTypeSize(Ty);
+
   llvm::DINode::DIFlags Flags = llvm::DINode::FlagFwdDecl;
 
   // Add flag to nontrivial forward declarations. To be consistent with MSVC,

diff  --git a/clang/test/CodeGenCXX/debug-info-class.cpp 
b/clang/test/CodeGenCXX/debug-info-class.cpp
index 94d5a0f1f082..e000532b8c3b 100644
--- a/clang/test/CodeGenCXX/debug-info-class.cpp
+++ b/clang/test/CodeGenCXX/debug-info-class.cpp
@@ -136,7 +136,7 @@ int main(int argc, char **argv) {
 // CHECK: [[C_DTOR]] = !DISubprogram(name: "~C"
 
 // CHECK: [[D:![0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: 
"D"
-// CHECK-NOT:  size:
+// CHECK-SAME: size:
 // CHECK-SAME: DIFlagFwdDecl
 // CHECK-NOT:  identifier:
 // CHECK-SAME: ){{$}}



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


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

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

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

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

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

This reverts commit 4cff1b40dacf6a5489b09657d94ea4757b8cd3b0.

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

Added: 


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

Removed: 




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

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

[clang] c8df781 - [DebugInfo] Fix bug in constructor homing with classes with trivial

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

Author: Amy Huang
Date: 2020-09-24T14:43:48-07:00
New Revision: c8df781e54a43593eafd993a5a5cd647866955f8

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

LOG: [DebugInfo] Fix bug in constructor homing with classes with trivial
constructors.

This changes the code to avoid using constructor homing for aggregate
classes and classes with trivial default constructors, instead of trying
to loop through the constructors.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 1fdb6814c7bd..27c584ff0795 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2281,22 +2281,20 @@ static bool 
hasExplicitMemberDefinition(CXXRecordDecl::method_iterator I,
 }
 
 static bool canUseCtorHoming(const CXXRecordDecl *RD) {
-  // Constructor homing can be used for classes that have at least one
-  // constructor and have no trivial or constexpr constructors.
+  // Constructor homing can be used for classes that cannnot be constructed
+  // without emitting code for one of their constructors. This is classes that
+  // don't have trivial or constexpr constructors, or can be created from
+  // aggregate initialization. Also skip lambda objects because they don't call
+  // constructors.
+
   // Skip this optimization if the class or any of its methods are marked
   // dllimport.
-  if (RD->isLambda() || RD->hasConstexprNonCopyMoveConstructor() ||
-  isClassOrMethodDLLImport(RD))
-return false;
-
-  if (RD->ctors().empty())
+  if (isClassOrMethodDLLImport(RD))
 return false;
 
-  for (const auto *Ctor : RD->ctors())
-if (Ctor->isTrivial() && !Ctor->isCopyOrMoveConstructor())
-  return false;
-
-  return true;
+  return !RD->isLambda() && !RD->isAggregate() &&
+ !RD->hasTrivialDefaultConstructor() &&
+ !RD->hasConstexprNonCopyMoveConstructor();
 }
 
 static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,

diff  --git a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp 
b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
index 89dd2b16b75b..cf2e89e35522 100644
--- a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
+++ b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -20,14 +20,56 @@ struct D {
 };
 D::D() {}
 
+// Test for constexpr constructor.
 // CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"E"{{.*}}DIFlagTypePassByValue
 struct E {
   constexpr E(){};
 } TestE;
 
+// Test for trivial constructor.
 // CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"F"{{.*}}DIFlagTypePassByValue
 struct F {
   F() = default;
   F(int) {}
   int i;
 } TestF;
+
+// Test for trivial constructor.
+// CHECK-DAG: ![[G:.*]] ={{.*}}!DICompositeType({{.*}}name: 
"G"{{.*}}DIFlagTypePassByValue
+// CHECK-DAG: !DICompositeType({{.*}}scope: ![[G]], {{.*}}DIFlagTypePassByValue
+struct G {
+  G() : g_(0) {}
+  struct {
+int g_;
+  };
+} TestG;
+
+// Test for an aggregate class with an implicit non-trivial default constructor
+// that is not instantiated.
+// CHECK-DAG: !DICompositeType({{.*}}name: "H",{{.*}}DIFlagTypePassByValue
+struct H {
+  B b;
+};
+void f(H h) {}
+
+// Test for an aggregate class with an implicit non-trivial default constructor
+// that is instantiated.
+// CHECK-DAG: !DICompositeType({{.*}}name: "J",{{.*}}DIFlagTypePassByValue
+struct J {
+  B b;
+};
+void f(decltype(J()) j) {}
+
+// Test for a class with trivial default constructor that is not instantiated.
+// CHECK-DAG: !DICompositeType({{.*}}name: "K",{{.*}}DIFlagTypePassByValue
+class K {
+  int i;
+};
+void f(K k) {}
+
+// Test that we don't use constructor homing on lambdas.
+// CHECK-DAG: ![[L:.*]] ={{.*}}!DISubprogram({{.*}}name: "L"
+// CHECK-DAG: !DICompositeType({{.*}}scope: ![[L]], {{.*}}DIFlagTypePassByValue
+void L() {
+  auto func = [&]() {};
+}



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


[clang] 5c4fc58 - [DebugInfo] Add types from constructor homing to the retained types list.

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

Author: Amy Huang
Date: 2020-09-29T17:00:45-07:00
New Revision: 5c4fc581d5fe8427f03ec90b0d745453398aa3ad

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

LOG: [DebugInfo] Add types from constructor homing to the retained types list.

Add class types to the retained types list to make sure they
don't get dropped if the constructor is optimized out later.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 27c584ff0795..88aace8b85dd 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1726,7 +1726,7 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
   // info is emitted.
   if (DebugKind == codegenoptions::DebugInfoConstructor)
 if (const CXXConstructorDecl *CD = dyn_cast(Method))
-  completeClass(CD->getParent());
+  completeUnusedClass(*CD->getParent());
 
   llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(Method, Unit);
   llvm::DISubprogram *SP = DBuilder.createMethod(

diff  --git a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp 
b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
index cf2e89e35522..cf7adad6b449 100644
--- a/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
+++ b/clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
@@ -9,7 +9,7 @@ struct B {
   B();
 } TestB;
 
-// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: 
"C"{{.*}}DIFlagTypePassByValue
+// CHECK-DAG: ![[C:[0-9]+]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type, name: "C"{{.*}}DIFlagTypePassByValue
 struct C {
   C() {}
 } TestC;
@@ -73,3 +73,7 @@ void f(K k) {}
 void L() {
   auto func = [&]() {};
 }
+
+// Check that types are being added to retained types list.
+// CHECK-DAG: !DICompileUnit{{.*}}retainedTypes: ![[RETAINED:[0-9]+]]
+// CHECK-DAG: ![[RETAINED]] = {{.*}}![[C]]



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


[clang] 5159732 - [CodeView] Emit static data members as S_CONSTANTs.

2020-10-26 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-10-26T15:30:35-07:00
New Revision: 515973222ed29abe49f241e89edb6854f44162d4

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

LOG: [CodeView] Emit static data members as S_CONSTANTs.

We used to only emit static const data members in CodeView as
S_CONSTANTS when they were used; this patch makes it so they are always emitted.

I changed CodeViewDebug.cpp to find the static const members from the
class debug info instead of creating DIGlobalVariables in the IR
whenever a static const data member is used.

Bug: https://bugs.llvm.org/show_bug.cgi?id=47580

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-static-member.cpp
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
llvm/test/DebugInfo/COFF/global-constants.ll
llvm/test/DebugInfo/COFF/types-array-unsized.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 8280fe718f26..96689c1b38ec 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4729,13 +4729,10 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl 
*VD, const APValue &Init) {
 }
   }
 
-  llvm::DIScope *DContext = nullptr;
-
   // Do not emit separate definitions for function local consts.
   if (isa(VD->getDeclContext()))
 return;
 
-  // Emit definition for static members in CodeView.
   VD = cast(VD->getCanonicalDecl());
   auto *VarD = dyn_cast(VD);
   if (VarD && VarD->isStaticDataMember()) {
@@ -4748,15 +4745,9 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl 
*VD, const APValue &Init) {
 RetainedTypes.push_back(
 CGM.getContext().getRecordType(RD).getAsOpaquePtr());
 
-if (!CGM.getCodeGenOpts().EmitCodeView)
-  return;
-
-// Use the global scope for static members.
-DContext = getContextDescriptor(
-cast(CGM.getContext().getTranslationUnitDecl()), TheCU);
-  } else {
-DContext = getDeclContextDescriptor(VD);
+return;
   }
+  llvm::DIScope *DContext = getDeclContextDescriptor(VD);
 
   auto &GV = DeclCache[VD];
   if (GV)

diff  --git a/clang/test/CodeGenCXX/debug-info-static-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-member.cpp
index 8ad86843f4e9..260a3afdd652 100644
--- a/clang/test/CodeGenCXX/debug-info-static-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-member.cpp
@@ -1,12 +1,12 @@
-// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S 
-o - | FileCheck %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S 
-o - | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-windows-msvc -gcodeview 
-debug-info-kind=limited %s -emit-llvm -o - | FileCheck --check-prefix MSVC %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
+// RUN: %clangxx -target x86_64-windows-msvc -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK %s
 // PR14471
 
-// CHECK: @_ZN1C1aE = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]]
-// CHECK: @_ZN1C1bE = dso_local global i32 2, align 4, !dbg [[B:![0-9]+]]
-// CHECK: @_ZN1C1cE = dso_local global i32 1, align 4, !dbg [[C:![0-9]+]]
+// CHECK: @{{.*}}a{{.*}} = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]]
+// CHECK: @{{.*}}b{{.*}} = dso_local global i32 2, align 4, !dbg [[B:![0-9]+]]
+// CHECK: @{{.*}}c{{.*}} = dso_local global i32 1, align 4, !dbg [[C:![0-9]+]]
 
 enum X {
   Y
@@ -36,9 +36,8 @@ class C
 // CHECK: [[A]] = !DIGlobalVariableExpression(var: [[AV:.*]], expr: 
!DIExpression())
 // CHECK: [[AV]] = distinct !DIGlobalVariable(name: "a",
 // CHECK-SAME:declaration: ![[DECL_A:[0-9]+]])
-// MSVC: distinct !DIGlobalVariable(name: "a"
 //
-// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, 
identifier: "_ZTS1X")
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}})
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"anon_static_decl_struct"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"static_decl_templ"
@@ -50,14 +49,13 @@ int C::a = 4;
 // CHECK: [[B]] = !DIGlobalVariableExp

[clang] 5046153 - Revert "[CodeView] Emit static data members as S_CONSTANTs."

2020-10-27 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-10-27T11:29:58-07:00
New Revision: 504615353f31136dd6bf7a971b6c236fd70582be

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

LOG: Revert "[CodeView] Emit static data members as S_CONSTANTs."

Seems like there's an assert in here that we shouldn't be running into.

This reverts commit 515973222ed29abe49f241e89edb6854f44162d4.

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-static-member.cpp
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
llvm/test/DebugInfo/COFF/global-constants.ll
llvm/test/DebugInfo/COFF/types-array-unsized.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 96689c1b38ec..8280fe718f26 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4729,10 +4729,13 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl 
*VD, const APValue &Init) {
 }
   }
 
+  llvm::DIScope *DContext = nullptr;
+
   // Do not emit separate definitions for function local consts.
   if (isa(VD->getDeclContext()))
 return;
 
+  // Emit definition for static members in CodeView.
   VD = cast(VD->getCanonicalDecl());
   auto *VarD = dyn_cast(VD);
   if (VarD && VarD->isStaticDataMember()) {
@@ -4745,9 +4748,15 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl 
*VD, const APValue &Init) {
 RetainedTypes.push_back(
 CGM.getContext().getRecordType(RD).getAsOpaquePtr());
 
-return;
+if (!CGM.getCodeGenOpts().EmitCodeView)
+  return;
+
+// Use the global scope for static members.
+DContext = getContextDescriptor(
+cast(CGM.getContext().getTranslationUnitDecl()), TheCU);
+  } else {
+DContext = getDeclContextDescriptor(VD);
   }
-  llvm::DIScope *DContext = getDeclContextDescriptor(VD);
 
   auto &GV = DeclCache[VD];
   if (GV)

diff  --git a/clang/test/CodeGenCXX/debug-info-static-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-member.cpp
index 260a3afdd652..8ad86843f4e9 100644
--- a/clang/test/CodeGenCXX/debug-info-static-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-member.cpp
@@ -1,12 +1,12 @@
-// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-windows-msvc -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S 
-o - | FileCheck %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S 
-o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -gcodeview 
-debug-info-kind=limited %s -emit-llvm -o - | FileCheck --check-prefix MSVC %s
 // PR14471
 
-// CHECK: @{{.*}}a{{.*}} = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]]
-// CHECK: @{{.*}}b{{.*}} = dso_local global i32 2, align 4, !dbg [[B:![0-9]+]]
-// CHECK: @{{.*}}c{{.*}} = dso_local global i32 1, align 4, !dbg [[C:![0-9]+]]
+// CHECK: @_ZN1C1aE = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]]
+// CHECK: @_ZN1C1bE = dso_local global i32 2, align 4, !dbg [[B:![0-9]+]]
+// CHECK: @_ZN1C1cE = dso_local global i32 1, align 4, !dbg [[C:![0-9]+]]
 
 enum X {
   Y
@@ -36,8 +36,9 @@ class C
 // CHECK: [[A]] = !DIGlobalVariableExpression(var: [[AV:.*]], expr: 
!DIExpression())
 // CHECK: [[AV]] = distinct !DIGlobalVariable(name: "a",
 // CHECK-SAME:declaration: ![[DECL_A:[0-9]+]])
+// MSVC: distinct !DIGlobalVariable(name: "a"
 //
-// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}})
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, 
identifier: "_ZTS1X")
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"anon_static_decl_struct"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"static_decl_templ"
@@ -49,13 +50,14 @@ int C::a = 4;
 // CHECK: [[B]] = !DIGlobalVariableExpression(var: [[BV:.*]], expr: 
!DIExpression())
 // CHECK: [[BV]] = distinct !DIGlobalVariable(name: "b",
 // CHECK-SAME:declaration: ![[DECL_B:[0-9]+]])
+// MSVC: distinct !DIGlobalVariable(name: "b"
 // CHECK: ![[DECL_B]] = !DIDerivedType(tag: DW_TAG_m

[clang] 7669f3c - Recommit "[CodeView] Emit static data members as S_CONSTANTs."

2020-10-28 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-10-28T16:35:59-07:00
New Revision: 7669f3c0f69db78cdd3deef066abc99f60fc580d

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

LOG: Recommit "[CodeView] Emit static data members as S_CONSTANTs."

We used to only emit static const data members in CodeView as
S_CONSTANTS when they were used; this patch makes it so they are always emitted.

This changes CodeViewDebug.cpp to find the static const members from the
class debug info instead of creating DIGlobalVariables in the IR
whenever a static const data member is used.

Bug: https://bugs.llvm.org/show_bug.cgi?id=47580

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

This reverts commit 504615353f31136dd6bf7a971b6c236fd70582be.

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-static-member.cpp
llvm/include/llvm/CodeGen/DebugHandlerBase.h
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
llvm/test/DebugInfo/COFF/global-constants.ll
llvm/test/DebugInfo/COFF/types-array-unsized.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 1b1fbccaaa04..6f77aed526bc 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4736,13 +4736,10 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl 
*VD, const APValue &Init) {
 }
   }
 
-  llvm::DIScope *DContext = nullptr;
-
   // Do not emit separate definitions for function local consts.
   if (isa(VD->getDeclContext()))
 return;
 
-  // Emit definition for static members in CodeView.
   VD = cast(VD->getCanonicalDecl());
   auto *VarD = dyn_cast(VD);
   if (VarD && VarD->isStaticDataMember()) {
@@ -4755,15 +4752,9 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl 
*VD, const APValue &Init) {
 RetainedTypes.push_back(
 CGM.getContext().getRecordType(RD).getAsOpaquePtr());
 
-if (!CGM.getCodeGenOpts().EmitCodeView)
-  return;
-
-// Use the global scope for static members.
-DContext = getContextDescriptor(
-cast(CGM.getContext().getTranslationUnitDecl()), TheCU);
-  } else {
-DContext = getDeclContextDescriptor(VD);
+return;
   }
+  llvm::DIScope *DContext = getDeclContextDescriptor(VD);
 
   auto &GV = DeclCache[VD];
   if (GV)

diff  --git a/clang/test/CodeGenCXX/debug-info-static-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-member.cpp
index 8ad86843f4e9..260a3afdd652 100644
--- a/clang/test/CodeGenCXX/debug-info-static-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-member.cpp
@@ -1,12 +1,12 @@
-// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S 
-o - | FileCheck %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S 
-o - | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-windows-msvc -gcodeview 
-debug-info-kind=limited %s -emit-llvm -o - | FileCheck --check-prefix MSVC %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
+// RUN: %clangxx -target x86_64-windows-msvc -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK %s
 // PR14471
 
-// CHECK: @_ZN1C1aE = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]]
-// CHECK: @_ZN1C1bE = dso_local global i32 2, align 4, !dbg [[B:![0-9]+]]
-// CHECK: @_ZN1C1cE = dso_local global i32 1, align 4, !dbg [[C:![0-9]+]]
+// CHECK: @{{.*}}a{{.*}} = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]]
+// CHECK: @{{.*}}b{{.*}} = dso_local global i32 2, align 4, !dbg [[B:![0-9]+]]
+// CHECK: @{{.*}}c{{.*}} = dso_local global i32 1, align 4, !dbg [[C:![0-9]+]]
 
 enum X {
   Y
@@ -36,9 +36,8 @@ class C
 // CHECK: [[A]] = !DIGlobalVariableExpression(var: [[AV:.*]], expr: 
!DIExpression())
 // CHECK: [[AV]] = distinct !DIGlobalVariable(name: "a",
 // CHECK-SAME:declaration: ![[DECL_A:[0-9]+]])
-// MSVC: distinct !DIGlobalVariable(name: "a"
 //
-// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, 
identifier: "_ZTS1X")
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}})
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"anon_static_decl_struct"
 // CH

[clang] 6227069 - [DebugInfo][CodeView] Change in line tables only mode to emit type information

2021-01-15 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-01-15T09:28:27-08:00
New Revision: 6227069bdce6b0c3c22f0a0c8f1aef705985125a

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

LOG: [DebugInfo][CodeView] Change in line tables only mode to emit type 
information
for function scopes, rather than using the qualified name.

In line-tables-only mode, we used to emit qualified names as the display name 
for functions when using CodeView.
This patch changes to emitting the parent scopes instead, with forward 
declarations for class types.
The total object file size ends up being slightly smaller than if we use the 
full qualified names.

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

Added: 
clang/test/CodeGenCXX/debug-info-codeview-scopes.cpp

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 881ee24546c2..00606d3ae507 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -254,24 +254,12 @@ StringRef CGDebugInfo::getFunctionName(const FunctionDecl 
*FD) {
   FunctionTemplateSpecializationInfo *Info =
   FD->getTemplateSpecializationInfo();
 
-  // Emit the unqualified name in normal operation. LLVM and the debugger can
-  // compute the fully qualified name from the scope chain. If we're only
-  // emitting line table info, there won't be any scope chains, so emit the
-  // fully qualified name here so that stack traces are more accurate.
-  // FIXME: Do this when emitting DWARF as well as when emitting CodeView after
-  // evaluating the size impact.
-  bool UseQualifiedName = DebugKind == codegenoptions::DebugLineTablesOnly &&
-  CGM.getCodeGenOpts().EmitCodeView;
-
-  if (!Info && FII && !UseQualifiedName)
+  if (!Info && FII)
 return FII->getName();
 
   SmallString<128> NS;
   llvm::raw_svector_ostream OS(NS);
-  if (!UseQualifiedName)
-FD->printName(OS);
-  else
-FD->printQualifiedName(OS, getPrintingPolicy());
+  FD->printName(OS);
 
   // Add any template specialization args.
   if (Info) {
@@ -1058,7 +1046,10 @@ CGDebugInfo::getOrCreateRecordFwdDecl(const RecordType 
*Ty,
   Flags |= llvm::DINode::FlagNonTrivial;
 
   // Create the type.
-  SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
+  SmallString<256> Identifier;
+  // Don't include a linkage name in line tables only.
+  if (CGM.getCodeGenOpts().hasReducedDebugInfo())
+Identifier = getTypeIdentifier(Ty, CGM, TheCU);
   llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
   getTagForRecord(RD), RDName, Ctx, DefUnit, Line, 0, Size, Align, Flags,
   Identifier);
@@ -2326,6 +2317,9 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
 if (ES->hasExternalDefinitions(RD) == ExternalASTSource::EK_Always)
   return true;
 
+  if (DebugKind == codegenoptions::DebugLineTablesOnly)
+return true;
+
   if (DebugKind > codegenoptions::LimitedDebugInfo)
 return false;
 
@@ -3473,7 +3467,11 @@ void CGDebugInfo::collectFunctionDeclProps(GlobalDecl 
GD, llvm::DIFile *Unit,
   DebugKind <= 
codegenoptions::DebugLineTablesOnly))
 LinkageName = StringRef();
 
-  if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
+  // Emit the function scope in line tables only mode (if CodeView) to
+  // 
diff erentiate between function names.
+  if (CGM.getCodeGenOpts().hasReducedDebugInfo() ||
+  (DebugKind == codegenoptions::DebugLineTablesOnly &&
+   CGM.getCodeGenOpts().EmitCodeView)) {
 if (const NamespaceDecl *NSDecl =
 dyn_cast_or_null(FD->getDeclContext()))
   FDContext = getOrCreateNamespace(NSDecl);
@@ -3482,6 +3480,8 @@ void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, 
llvm::DIFile *Unit,
   llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
   FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
 }
+  }
+  if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
 // Check if it is a noreturn-marked function
 if (FD->isNoReturn())
   Flags |= llvm::DINode::FlagNoReturn;

diff  --git a/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp 
b/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
index 15f625d8832d..935fded5e67c 100644
--- a/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
+++ b/clang/test/CodeGenCXX/debug-info-codeview-display-name.cpp
@@ -20,11 +20,9 @@ void freefunc() { }
 
 namespace N {
   int b() { return 0; }
-// UNQUAL-DAG: "b"
-// QUAL-DAG: "N::b"
+// CHECK-DAG: "b"
   namespace { void func() { } }
-// UNQUAL-DAG: "func"
-// QUAL-DAG: "N::`anonymous namespace'::func"
+// CHECK-DAG: "func"
 }
 
 v

[clang] a1be47b - [CodeView][DebugInfo] Add test case to show that linkage names are not

2021-01-15 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-01-15T12:05:33-08:00
New Revision: a1be47b4771467998d7549dcd1b9f9cebdaa9af9

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

LOG: [CodeView][DebugInfo] Add test case to show that linkage names are not
being added to class types in -gline-tables-only.
Also changed the name of the test file for clarity.
(follow up to D94639)

Added: 
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Modified: 


Removed: 
clang/test/CodeGenCXX/debug-info-codeview-scopes.cpp



diff  --git a/clang/test/CodeGenCXX/debug-info-codeview-scopes.cpp 
b/clang/test/CodeGenCXX/debug-info-codeview-scopes.cpp
deleted file mode 100644
index f096e334a158..
--- a/clang/test/CodeGenCXX/debug-info-codeview-scopes.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu 
-debug-info-kind=line-tables-only -S -emit-llvm -std=c++11 -o - %s | FileCheck 
--check-prefix LINUX %s
-// RUN: %clang_cc1 -triple x86_64-windows-msvc 
-debug-info-kind=line-tables-only -gcodeview -S -emit-llvm -std=c++11 -o - %s | 
FileCheck --check-prefix MSVC %s
-
-// Check that we emit type information for function scopes in line tables for
-// CodeView.
-
-namespace A {
-void f() {}
-
-struct S {
-  static void m() {}
-};
-}
-
-int main() {
-  A::f();
-  A::S::m();
-  return 0;
-  // MSVC:   !{{[0-9]+}} = distinct !DISubprogram(name: "f"
-  // MSVC-SAME: scope: [[SCOPE1:![0-9]+]]
-  // MSVC-SAME: )
-  // MSVC:   [[SCOPE1]] = !DINamespace(name: "A", {{.*}})
-  // MSVC:   !{{[0-9]+}} = distinct !DISubprogram(name: "m"
-  // MSVC-SAME: scope: [[SCOPE2:![0-9]+]]
-  // MSVC-SAME: )
-  // MSVC:   [[SCOPE2]] = !DICompositeType(tag: DW_TAG_structure_type,
-  // MSVC-SAME: name: "S",
-  // MSVC-SAME: scope: [[SCOPE1]]
-  // MSVC-SAME: )
-
-  // LINUX-NOT: !DINamespace
-  // LINUX-NOT: !DICompositeType
-  return 0;
-}

diff  --git a/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp 
b/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
new file mode 100644
index ..25f801737f74
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 %s -gcodeview -debug-info-kind=line-tables-only -S \
+// RUN:   -emit-llvm -o - | FileCheck %s
+// Checks that clang with "-gline-tables-only" with CodeView emits some debug
+// info for variables and types when they appear in function scopes.
+
+namespace NS {
+struct C {
+public:
+  void m() {}
+};
+void f() {}
+}
+
+NS::C c;
+
+void test() {
+  // CHECK: ![[EMPTY:[0-9]+]] = !{}
+  // CHECK: !DISubprogram(name: "f", scope: ![[NS:[0-9]+]],
+  // CHECK-SAME:  type: ![[F:[0-9]+]]
+  // CHECK: ![[NS]] = !DINamespace(name: "NS", scope: null)
+  // CHECK: ![[F]] = !DISubroutineType(types: ![[EMPTY]])
+  NS::f();
+
+  // CHECK: !DISubprogram(name: "m", scope: ![[C:[0-9]+]],
+  // CHECK-SAME:  type: ![[F]]
+  // CHECK: ![[C]] = !DICompositeType(tag: DW_TAG_structure_type, name: "C",
+  // CHECK-SAME:  flags: DIFlagFwdDecl
+  // CHECK-NOT: identifier
+  c.m();
+}



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


[clang] a3d7cee - [CodeView] Emit function types in -gline-tables-only.

2021-01-20 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-01-20T12:47:35-08:00
New Revision: a3d7cee7f9bdfbe3e88e4de39a76c3d3e2690fdb

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

LOG: [CodeView] Emit function types in -gline-tables-only.

This change adds function types to further differentiate between
FUNC_IDs in -gline-tables-only.

Size increase of object files in clang are
Before: 917990 kb
After:  999312 kb

Bug: https://bugs.llvm.org/show_bug.cgi?id=48432

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 00606d3ae507..02dfb14ae615 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2317,6 +2317,9 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
 if (ES->hasExternalDefinitions(RD) == ExternalASTSource::EK_Always)
   return true;
 
+  // Only emit forward declarations in line tables only to keep debug info size
+  // small. This only applies to CodeView, since we don't emit types in DWARF
+  // line tables only.
   if (DebugKind == codegenoptions::DebugLineTablesOnly)
 return true;
 
@@ -3726,7 +3729,10 @@ llvm::DISubprogram 
*CGDebugInfo::getObjCMethodDeclaration(
 llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(const Decl *D,
  QualType FnType,
  llvm::DIFile *F) {
-  if (!D || DebugKind <= codegenoptions::DebugLineTablesOnly)
+  // In CodeView, we emit the function types in line tables only because the
+  // only way to distinguish between functions is by display name and type.
+  if (!D || (DebugKind <= codegenoptions::DebugLineTablesOnly &&
+ !CGM.getCodeGenOpts().EmitCodeView))
 // Create fake but valid subroutine type. Otherwise -verify would fail, and
 // subprogram DIE will miss DW_AT_decl_file and DW_AT_decl_line fields.
 return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray(None));

diff  --git a/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp 
b/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
index 25f801737f74..27ac682c10f5 100644
--- a/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
+++ b/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
@@ -5,7 +5,6 @@
 
 namespace NS {
 struct C {
-public:
   void m() {}
 };
 void f() {}
@@ -14,17 +13,18 @@ void f() {}
 NS::C c;
 
 void test() {
-  // CHECK: ![[EMPTY:[0-9]+]] = !{}
   // CHECK: !DISubprogram(name: "f", scope: ![[NS:[0-9]+]],
   // CHECK-SAME:  type: ![[F:[0-9]+]]
   // CHECK: ![[NS]] = !DINamespace(name: "NS", scope: null)
-  // CHECK: ![[F]] = !DISubroutineType(types: ![[EMPTY]])
+  // CHECK: ![[F]] = !DISubroutineType(types: ![[FTYPE:[0-9]+]])
+  // CHECK: ![[FTYPE]] = !{null}
   NS::f();
 
-  // CHECK: !DISubprogram(name: "m", scope: ![[C:[0-9]+]],
-  // CHECK-SAME:  type: ![[F]]
+  // CHECK: ![[M:[0-9]+]] = distinct !DISubprogram(name: "m", scope: 
![[C:[0-9]+]],
+  // CHECK-SAME:   type: ![[MTYPE:[0-9]+]]
   // CHECK: ![[C]] = !DICompositeType(tag: DW_TAG_structure_type, name: "C",
   // CHECK-SAME:  flags: DIFlagFwdDecl
   // CHECK-NOT: identifier
+  // CHECK: ![[MTYPE]] = !DISubroutineType(types: !{{.*}})
   c.m();
 }



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


[clang] d73564c - [DebugInfo][CodeView] Use as the display name for lambdas.

2021-01-28 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-01-28T16:30:38-08:00
New Revision: d73564c510036b2d4f5858effdcd23fe54fc1063

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

LOG: [DebugInfo][CodeView] Use  as the display name for lambdas.

Currently (for codeview) lambdas have a string like `` in
their mangled name, and don't have any display name. This change uses the
`` as the display name, which helps distinguish between lambdas
in -gline-tables-only, since there are no linkage names there.
It also changes how we display lambda names; previously we used
``; now it will show ``.

I added a function to the mangling context code to create this string;
for Itanium it just returns an empty string.

Bug: https://bugs.llvm.org/show_bug.cgi?id=48432

Reviewed By: rnk

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

Added: 


Modified: 
clang/include/clang/AST/Mangle.h
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Mangle.h 
b/clang/include/clang/AST/Mangle.h
index 0e8d6dd53d8a6..f8f44853567fd 100644
--- a/clang/include/clang/AST/Mangle.h
+++ b/clang/include/clang/AST/Mangle.h
@@ -89,6 +89,17 @@ class MangleContext {
 return Result.first->second;
   }
 
+  uint64_t getAnonymousStructIdForDebugInfo(const NamedDecl *D) {
+llvm::DenseMap::iterator Result =
+AnonStructIds.find(D);
+// The decl should already be inserted, but return 0 in case it is not.
+if (Result == AnonStructIds.end())
+  return 0;
+return Result->second;
+  }
+
+  virtual StringRef getLambdaString(const CXXRecordDecl *Lambda) = 0;
+
   /// @name Mangler Entry Points
   /// @{
 

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 4420f6a2c1c38..265c2172801c4 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -203,6 +203,36 @@ class ItaniumMangleContextImpl : public 
ItaniumMangleContext {
 disc = discriminator-2;
 return true;
   }
+
+  StringRef getLambdaString(const CXXRecordDecl *Lambda) override {
+// This function matches the one in MicrosoftMangle, which returns
+// the string that is used in lambda mangled names.
+assert(Lambda->isLambda() && "RD must be a lambda!");
+llvm::SmallString<10> Name("getLambdaContextDecl();
+unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber();
+unsigned LambdaId;
+const ParmVarDecl *Parm = dyn_cast_or_null(LambdaContextDecl);
+const FunctionDecl *Func =
+Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
+
+if (Func) {
+  unsigned DefaultArgNo =
+  Func->getNumParams() - Parm->getFunctionScopeIndex();
+  Name += llvm::utostr(DefaultArgNo);
+  Name += "_";
+}
+
+if (LambdaManglingNumber)
+  LambdaId = LambdaManglingNumber;
+else
+  LambdaId = getAnonymousStructIdForDebugInfo(Lambda);
+
+Name += llvm::utostr(LambdaId);
+Name += '>';
+return StringRef(Name);
+  }
+
   /// @}
 };
 

diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index 9eac3586c8715..aaaba62a0fd4e 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -228,6 +228,34 @@ class MicrosoftMangleContextImpl : public 
MicrosoftMangleContext {
 return true;
   }
 
+  StringRef getLambdaString(const CXXRecordDecl *Lambda) override {
+assert(Lambda->isLambda() && "RD must be a lambda!");
+llvm::SmallString<10> Name("getLambdaContextDecl();
+unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber();
+unsigned LambdaId;
+const ParmVarDecl *Parm = dyn_cast_or_null(LambdaContextDecl);
+const FunctionDecl *Func =
+Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
+
+if (Func) {
+  unsigned DefaultArgNo =
+  Func->getNumParams() - Parm->getFunctionScopeIndex();
+  Name += llvm::utostr(DefaultArgNo);
+  Name += "_";
+}
+
+if (LambdaManglingNumber)
+  LambdaId = LambdaManglingNumber;
+else
+  LambdaId = getLambdaIdForDebugInfo(Lambda);
+
+Name += llvm::utostr(LambdaId);
+Name += ">";
+return StringRef(Name);
+  }
+
   unsigned getLambdaId(const CXXRecordDecl *RD) {
 assert(RD->isLambda() && "RD must be a lambda!");
 assert(!RD->isExternallyVisible() && "RD must not be visible!");
@@ -238,6 +266,19 @@ class MicrosoftMangleContextImpl : public 
MicrosoftMangleContext {
 return Result.first->second;
   }
 
+  unsigned getLambdaIdForDebugInfo(const CXXRecordDecl *RD) {
+assert(RD->isLambda() && "RD must be a lamb

[clang] 9b21d4b - Revert "[DebugInfo][CodeView] Use as the display name for lambdas."

2021-01-28 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-01-28T16:41:26-08:00
New Revision: 9b21d4b9434d2d4796b0d60d64f6ded9bac95441

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

LOG: Revert "[DebugInfo][CodeView] Use  as the display name for 
lambdas."
for test failures.

This reverts commit d73564c510036b2d4f5858effdcd23fe54fc1063.

Added: 


Modified: 
clang/include/clang/AST/Mangle.h
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Mangle.h 
b/clang/include/clang/AST/Mangle.h
index f8f44853567f..0e8d6dd53d8a 100644
--- a/clang/include/clang/AST/Mangle.h
+++ b/clang/include/clang/AST/Mangle.h
@@ -89,17 +89,6 @@ class MangleContext {
 return Result.first->second;
   }
 
-  uint64_t getAnonymousStructIdForDebugInfo(const NamedDecl *D) {
-llvm::DenseMap::iterator Result =
-AnonStructIds.find(D);
-// The decl should already be inserted, but return 0 in case it is not.
-if (Result == AnonStructIds.end())
-  return 0;
-return Result->second;
-  }
-
-  virtual StringRef getLambdaString(const CXXRecordDecl *Lambda) = 0;
-
   /// @name Mangler Entry Points
   /// @{
 

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 265c2172801c..4420f6a2c1c3 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -203,36 +203,6 @@ class ItaniumMangleContextImpl : public 
ItaniumMangleContext {
 disc = discriminator-2;
 return true;
   }
-
-  StringRef getLambdaString(const CXXRecordDecl *Lambda) override {
-// This function matches the one in MicrosoftMangle, which returns
-// the string that is used in lambda mangled names.
-assert(Lambda->isLambda() && "RD must be a lambda!");
-llvm::SmallString<10> Name("getLambdaContextDecl();
-unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber();
-unsigned LambdaId;
-const ParmVarDecl *Parm = dyn_cast_or_null(LambdaContextDecl);
-const FunctionDecl *Func =
-Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
-
-if (Func) {
-  unsigned DefaultArgNo =
-  Func->getNumParams() - Parm->getFunctionScopeIndex();
-  Name += llvm::utostr(DefaultArgNo);
-  Name += "_";
-}
-
-if (LambdaManglingNumber)
-  LambdaId = LambdaManglingNumber;
-else
-  LambdaId = getAnonymousStructIdForDebugInfo(Lambda);
-
-Name += llvm::utostr(LambdaId);
-Name += '>';
-return StringRef(Name);
-  }
-
   /// @}
 };
 

diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index aaaba62a0fd4..9eac3586c871 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -228,34 +228,6 @@ class MicrosoftMangleContextImpl : public 
MicrosoftMangleContext {
 return true;
   }
 
-  StringRef getLambdaString(const CXXRecordDecl *Lambda) override {
-assert(Lambda->isLambda() && "RD must be a lambda!");
-llvm::SmallString<10> Name("getLambdaContextDecl();
-unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber();
-unsigned LambdaId;
-const ParmVarDecl *Parm = dyn_cast_or_null(LambdaContextDecl);
-const FunctionDecl *Func =
-Parm ? dyn_cast(Parm->getDeclContext()) : nullptr;
-
-if (Func) {
-  unsigned DefaultArgNo =
-  Func->getNumParams() - Parm->getFunctionScopeIndex();
-  Name += llvm::utostr(DefaultArgNo);
-  Name += "_";
-}
-
-if (LambdaManglingNumber)
-  LambdaId = LambdaManglingNumber;
-else
-  LambdaId = getLambdaIdForDebugInfo(Lambda);
-
-Name += llvm::utostr(LambdaId);
-Name += ">";
-return StringRef(Name);
-  }
-
   unsigned getLambdaId(const CXXRecordDecl *RD) {
 assert(RD->isLambda() && "RD must be a lambda!");
 assert(!RD->isExternallyVisible() && "RD must not be visible!");
@@ -266,19 +238,6 @@ class MicrosoftMangleContextImpl : public 
MicrosoftMangleContext {
 return Result.first->second;
   }
 
-  unsigned getLambdaIdForDebugInfo(const CXXRecordDecl *RD) {
-assert(RD->isLambda() && "RD must be a lambda!");
-assert(!RD->isExternallyVisible() && "RD must not be visible!");
-assert(RD->getLambdaManglingNumber() == 0 &&
-   "RD must not have a mangling number!");
-llvm::DenseMap::iterator Result =
-LambdaIds.find(RD);
-// The lambda should exist, but return 0 in case it doesn't.
-if (Result == LambdaIds.end())
-  return 0;
-return Result->second;
-  }
-
   /// Return a character sequence that is (somewhat) unique to the TU suitable
   /// for mangling ano

[clang] 7ef79bb - Fix typo in "[DebugInfo][CodeView] Use as the display name for lambdas."

2021-01-28 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-01-28T19:03:41-08:00
New Revision: 7ef79bb8e240aafab265107b8b7d63d3e32ddb93

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

LOG: Fix typo in "[DebugInfo][CodeView] Use  as the display name for 
lambdas."
(Commited in d5f5deee9ee996f078fb40ee20795539409523e4)

Added: 


Modified: 
clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp 
b/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
index ad781c8ed952..6b9c9a243dec 100644
--- a/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
+++ b/clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 %s -triple x86_64-windows-msvc -gcodeview
-// RUN: -debug-info-kind=line-tables-only -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-windows-msvc -gcodeview \
+// RUN:   -debug-info-kind=line-tables-only -emit-llvm -o - | FileCheck %s
 // Checks that clang with "-gline-tables-only" with CodeView emits some debug
 // info for variables and types when they appear in function scopes.
 



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


[clang] 0c80b54 - Some updates/fixes to the creduce script.

2020-11-12 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2020-11-12T13:40:26-08:00
New Revision: 0c80b542d38b4819809c600e71a6997a9b4e4294

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

LOG: Some updates/fixes to the creduce script.

This was motivated by changes to llvm's `not --crash` disabling symbolization
but I ended up removing `not` from the script entirely because it
returns differently depending on  whether clang "crashes" or exits for some
other reason. The script had to choose between calling `not` and `not --crash`
and sometimes it was wrong.

The script also now disables symbolization when we don't read the stack
trace because symbolizing is kind of slow.

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

Added: 


Modified: 
clang/utils/creduce-clang-crash.py

Removed: 




diff  --git a/clang/utils/creduce-clang-crash.py 
b/clang/utils/creduce-clang-crash.py
index b69d6efc2481..cdc639c6f854 100755
--- a/clang/utils/creduce-clang-crash.py
+++ b/clang/utils/creduce-clang-crash.py
@@ -23,7 +23,6 @@
 verbose = False
 creduce_cmd = None
 clang_cmd = None
-not_cmd = None
 
 def verbose_print(*args, **kwargs):
   if verbose:
@@ -77,7 +76,7 @@ def __init__(self, crash_script, file_to_reduce):
 self.clang = clang_cmd
 self.clang_args = []
 self.expected_output = []
-self.is_crash = True
+self.needs_stack_trace = False
 self.creduce_flags = ["--tidy"]
 
 self.read_clang_args(crash_script, file_to_reduce)
@@ -128,23 +127,20 @@ def read_expected_output(self):
 crash_output = re.sub(ansi_escape, '', crash_output.decode('utf-8'))
 
 # Look for specific error messages
-regexes = [r"Assertion `(.+)' failed", # Linux assert()
-   r"Assertion failed: (.+),", # FreeBSD/Mac assert()
-   r"fatal error: error in backend: (.+)",
-   r"LLVM ERROR: (.+)",
-   r"UNREACHABLE executed (at .+)?!",
-   r"LLVM IR generation of declaration '(.+)'",
-   r"Generating code for declaration '(.+)'",
-   r"\*\*\* Bad machine code: (.+) \*\*\*"]
+regexes = [r"Assertion .+ failed", # Linux assert()
+   r"Assertion failed: .+,", # FreeBSD/Mac assert()
+   r"fatal error: error in backend: .+",
+   r"LLVM ERROR: .+",
+   r"UNREACHABLE executed at .+?!",
+   r"LLVM IR generation of declaration '.+'",
+   r"Generating code for declaration '.+'",
+   r"\*\*\* Bad machine code: .+ \*\*\*"]
 for msg_re in regexes:
   match = re.search(msg_re, crash_output)
   if match:
-msg = match.group(1)
+msg = match.group(0)
 result = [msg]
 print("Found message:", msg)
-
-if "fatal error:" in msg_re:
-  self.is_crash = False
 break
 
 # If no message was found, use the top five stack trace functions,
@@ -152,12 +148,15 @@ def read_expected_output(self):
 # Five is a somewhat arbitrary number; the goal is to get a small number
 # of identifying functions with some leeway for common functions
 if not result:
+  self.needs_stack_trace = True
   stacktrace_re = r'[0-9]+\s+0[xX][0-9a-fA-F]+\s*([^(]+)\('
-  filters = ["PrintStackTraceSignalHandler",
- "llvm::sys::RunSignalHandlers",
- "SignalHandler", "__restore_rt", "gsignal", "abort"]
+  filters = ["PrintStackTrace", "RunSignalHandlers", "CleanupOnSignal",
+ "HandleCrash", "SignalHandler", "__restore_rt", "gsignal", 
"abort"]
+  def skip_function(func_name):
+return any(name in func_name for name in filters)
+
   matches = re.findall(stacktrace_re, crash_output)
-  result = [x for x in matches if x and x.strip() not in filters][:5]
+  result = [x for x in matches if x and not skip_function(x)][:5]
   for msg in result:
 print("Found stack trace function:", msg)
 
@@ -184,10 +183,17 @@ def check_expected_output(self, args=None, filename=None):
   def write_interestingness_test(self):
 print("\nCreating the interestingness test...")
 
-crash_flag = "--crash" if self.is_crash else ""
+# Disable symbolization if it's not required to avoid slow symbolization.
+disable_symbolization = ''
+if not self.needs_stack_trace:
+  disable_symbolization = 'export LLVM_DISABLE_SYMBOLIZATION=1'
 
-output = "#!/bin/bash\n%s %s %s >& t.log || exit 1\n" % \
-(pipes.quote(not_cmd), crash_flag, quote_cmd(self.get_crash_cmd()))
+output = """#!/bin/bash
+%s
+if %s >& t.log ; then
+  exit 1
+fi
+""" % (disable_symbolization, quote_cmd(self.get_crash_cmd()))
 
 for msg in self.expected_output:
   output += 'grep -F %s t.log || exit 1\n' % pipes.quote(msg)
@@ -372,7 +378,6 @@ def main():
   g

[clang] 7daa182 - Fix tmp files being left on Windows builds.

2021-06-01 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-06-01T17:09:08-07:00
New Revision: 7daa18215905c831e130c7542f17619e9d936dfc

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

LOG: Fix tmp files being left on Windows builds.

Clang writes object files by first writing to a .tmp file and then
renaming to the final .obj name. On Windows, if a compile is killed
partway through the .tmp files don't get deleted.

Currently it seems like RemoveFileOnSignal takes care of deleting the
tmp files on Linux, but on Windows we need to call
setDeleteDisposition on tmp files so that they are deleted when
closed.

This patch switches to using TempFile to create the .tmp files we write
when creating object files, since it uses setDeleteDisposition on Windows.
This change applies to both Linux and Windows for consistency.

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

Added: 


Modified: 
clang/include/clang/Frontend/CompilerInstance.h
clang/lib/Frontend/CompilerInstance.cpp
llvm/lib/Support/Path.cpp
llvm/lib/Support/Windows/Path.inc

Removed: 




diff  --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 5e879d672d801..9d6dd8fa1006f 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -22,6 +22,7 @@
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/BuryPointer.h"
+#include "llvm/Support/FileSystem.h"
 #include 
 #include 
 #include 
@@ -165,11 +166,10 @@ class CompilerInstance : public ModuleLoader {
   /// failed.
   struct OutputFile {
 std::string Filename;
-std::string TempFilename;
+Optional File;
 
-OutputFile(std::string filename, std::string tempFilename)
-: Filename(std::move(filename)), TempFilename(std::move(tempFilename)) 
{
-}
+OutputFile(std::string filename, Optional file)
+: Filename(std::move(filename)), File(std::move(file)) {}
   };
 
   /// The list of active output files.

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 5df40c742d469..b1b983d620653 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -703,31 +703,37 @@ void CompilerInstance::createSema(TranslationUnitKind 
TUKind,
 // Output Files
 
 void CompilerInstance::clearOutputFiles(bool EraseFiles) {
+  // Ignore errors that occur when trying to discard the temp file.
   for (OutputFile &OF : OutputFiles) {
 if (EraseFiles) {
-  if (!OF.TempFilename.empty()) {
-llvm::sys::fs::remove(OF.TempFilename);
-continue;
-  }
+  if (OF.File)
+consumeError(OF.File->discard());
   if (!OF.Filename.empty())
 llvm::sys::fs::remove(OF.Filename);
   continue;
 }
 
-if (OF.TempFilename.empty())
+if (!OF.File)
   continue;
 
+if (OF.File->TmpName.empty()) {
+  consumeError(OF.File->discard());
+  continue;
+}
+
 // If '-working-directory' was passed, the output filename should be
 // relative to that.
 SmallString<128> NewOutFile(OF.Filename);
 FileMgr->FixupRelativePath(NewOutFile);
-std::error_code EC = llvm::sys::fs::rename(OF.TempFilename, NewOutFile);
-if (!EC)
+
+llvm::Error E = OF.File->keep(NewOutFile);
+if (!E)
   continue;
+
 getDiagnostics().Report(diag::err_unable_to_rename_temp)
-<< OF.TempFilename << OF.Filename << EC.message();
+<< OF.File->TmpName << OF.Filename << std::move(E);
 
-llvm::sys::fs::remove(OF.TempFilename);
+llvm::sys::fs::remove(OF.File->TmpName);
   }
   OutputFiles.clear();
   if (DeleteBuiltModules) {
@@ -809,7 +815,7 @@ CompilerInstance::createOutputFileImpl(StringRef 
OutputPath, bool Binary,
 }
   }
 
-  std::string TempFile;
+  Optional Temp;
   if (UseTemporary) {
 // Create a temporary file.
 // Insert - before the extension (if any), and because some tools
@@ -821,25 +827,36 @@ CompilerInstance::createOutputFileImpl(StringRef 
OutputPath, bool Binary,
 TempPath += "-";
 TempPath += OutputExtension;
 TempPath += ".tmp";
-int fd;
-std::error_code EC = llvm::sys::fs::createUniqueFile(
-TempPath, fd, TempPath,
-Binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_Text);
-
-if (CreateMissingDirectories &&
-EC == llvm::errc::no_such_file_or_directory) {
-  StringRef Parent = llvm::sys::path::parent_path(OutputPath);
-  EC = llvm::sys::fs::create_directories(Parent);
-  if (!EC) {
-EC = llvm::sys::fs::createUniqueFile(TempPath, fd, TempPath,
- Binary ? llvm::sys::fs::OF_None
-

[clang] 20797b1 - Revert "Fix tmp files being left on Windows builds." for now;

2021-06-01 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-06-01T19:51:47-07:00
New Revision: 20797b129f844d4b12ffb2b12cf33baa2d42985c

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

LOG: Revert "Fix tmp files being left on Windows builds." for now;
causing some asan test failures.

This reverts commit 7daa18215905c831e130c7542f17619e9d936dfc.

Added: 


Modified: 
clang/include/clang/Frontend/CompilerInstance.h
clang/lib/Frontend/CompilerInstance.cpp
llvm/lib/Support/Path.cpp
llvm/lib/Support/Windows/Path.inc

Removed: 




diff  --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 9d6dd8fa1006f..5e879d672d801 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -22,7 +22,6 @@
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/BuryPointer.h"
-#include "llvm/Support/FileSystem.h"
 #include 
 #include 
 #include 
@@ -166,10 +165,11 @@ class CompilerInstance : public ModuleLoader {
   /// failed.
   struct OutputFile {
 std::string Filename;
-Optional File;
+std::string TempFilename;
 
-OutputFile(std::string filename, Optional file)
-: Filename(std::move(filename)), File(std::move(file)) {}
+OutputFile(std::string filename, std::string tempFilename)
+: Filename(std::move(filename)), TempFilename(std::move(tempFilename)) 
{
+}
   };
 
   /// The list of active output files.

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index b1b983d620653..5df40c742d469 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -703,37 +703,31 @@ void CompilerInstance::createSema(TranslationUnitKind 
TUKind,
 // Output Files
 
 void CompilerInstance::clearOutputFiles(bool EraseFiles) {
-  // Ignore errors that occur when trying to discard the temp file.
   for (OutputFile &OF : OutputFiles) {
 if (EraseFiles) {
-  if (OF.File)
-consumeError(OF.File->discard());
+  if (!OF.TempFilename.empty()) {
+llvm::sys::fs::remove(OF.TempFilename);
+continue;
+  }
   if (!OF.Filename.empty())
 llvm::sys::fs::remove(OF.Filename);
   continue;
 }
 
-if (!OF.File)
+if (OF.TempFilename.empty())
   continue;
 
-if (OF.File->TmpName.empty()) {
-  consumeError(OF.File->discard());
-  continue;
-}
-
 // If '-working-directory' was passed, the output filename should be
 // relative to that.
 SmallString<128> NewOutFile(OF.Filename);
 FileMgr->FixupRelativePath(NewOutFile);
-
-llvm::Error E = OF.File->keep(NewOutFile);
-if (!E)
+std::error_code EC = llvm::sys::fs::rename(OF.TempFilename, NewOutFile);
+if (!EC)
   continue;
-
 getDiagnostics().Report(diag::err_unable_to_rename_temp)
-<< OF.File->TmpName << OF.Filename << std::move(E);
+<< OF.TempFilename << OF.Filename << EC.message();
 
-llvm::sys::fs::remove(OF.File->TmpName);
+llvm::sys::fs::remove(OF.TempFilename);
   }
   OutputFiles.clear();
   if (DeleteBuiltModules) {
@@ -815,7 +809,7 @@ CompilerInstance::createOutputFileImpl(StringRef 
OutputPath, bool Binary,
 }
   }
 
-  Optional Temp;
+  std::string TempFile;
   if (UseTemporary) {
 // Create a temporary file.
 // Insert - before the extension (if any), and because some tools
@@ -827,36 +821,25 @@ CompilerInstance::createOutputFileImpl(StringRef 
OutputPath, bool Binary,
 TempPath += "-";
 TempPath += OutputExtension;
 TempPath += ".tmp";
-Expected ExpectedFile =
-llvm::sys::fs::TempFile::create(TempPath);
-
-llvm::Error E = handleErrors(
-ExpectedFile.takeError(), [&](const llvm::ECError &E) -> llvm::Error {
-  std::error_code EC = E.convertToErrorCode();
-  if (CreateMissingDirectories &&
-  EC == llvm::errc::no_such_file_or_directory) {
-StringRef Parent = llvm::sys::path::parent_path(OutputPath);
-EC = llvm::sys::fs::create_directories(Parent);
-if (!EC) {
-  ExpectedFile = llvm::sys::fs::TempFile::create(TempPath);
-  if (!ExpectedFile)
-return llvm::errorCodeToError(
-llvm::errc::no_such_file_or_directory);
-}
-  }
-  return llvm::errorCodeToError(EC);
-});
-
-if (E) {
-  consumeError(std::move(E));
-} else {
-  Temp = std::move(ExpectedFile.get());
-  TempPath = Temp->TmpName;
+int fd;
+std::error_code EC = llvm::sys::fs::createUniqueFile(
+TempPath, fd, TempPath,
+Binary ? llvm::sys::fs::OF_None : llvm

[clang] 9d070b2 - Recommit "Fix tmp files being left on Windows builds." with a fix for

2021-06-02 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-06-02T16:50:37-07:00
New Revision: 9d070b2f4889887f9ce497592ef01df7b9601a1c

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

LOG: Recommit "Fix tmp files being left on Windows builds." with a fix for
incorrect std::string use. (Also remove redundant call to
RemoveFileOnSignal.)

Clang writes object files by first writing to a .tmp file and then
renaming to the final .obj name. On Windows, if a compile is killed
partway through the .tmp files don't get deleted.

Currently it seems like RemoveFileOnSignal takes care of deleting the
tmp files on Linux, but on Windows we need to call
setDeleteDisposition on tmp files so that they are deleted when
closed.

This patch switches to using TempFile to create the .tmp files we write
when creating object files, since it uses setDeleteDisposition on Windows.
This change applies to both Linux and Windows for consistency.

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

This reverts commit 20797b129f844d4b12ffb2b12cf33baa2d42985c.

Added: 


Modified: 
clang/include/clang/Frontend/CompilerInstance.h
clang/lib/Frontend/CompilerInstance.cpp
llvm/lib/Support/Path.cpp
llvm/lib/Support/Windows/Path.inc

Removed: 




diff  --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 5e879d672d801..9d6dd8fa1006f 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -22,6 +22,7 @@
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/BuryPointer.h"
+#include "llvm/Support/FileSystem.h"
 #include 
 #include 
 #include 
@@ -165,11 +166,10 @@ class CompilerInstance : public ModuleLoader {
   /// failed.
   struct OutputFile {
 std::string Filename;
-std::string TempFilename;
+Optional File;
 
-OutputFile(std::string filename, std::string tempFilename)
-: Filename(std::move(filename)), TempFilename(std::move(tempFilename)) 
{
-}
+OutputFile(std::string filename, Optional file)
+: Filename(std::move(filename)), File(std::move(file)) {}
   };
 
   /// The list of active output files.

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 5df40c742d469..32e7fdf64fa93 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -703,31 +703,37 @@ void CompilerInstance::createSema(TranslationUnitKind 
TUKind,
 // Output Files
 
 void CompilerInstance::clearOutputFiles(bool EraseFiles) {
+  // Ignore errors that occur when trying to discard the temp file.
   for (OutputFile &OF : OutputFiles) {
 if (EraseFiles) {
-  if (!OF.TempFilename.empty()) {
-llvm::sys::fs::remove(OF.TempFilename);
-continue;
-  }
+  if (OF.File)
+consumeError(OF.File->discard());
   if (!OF.Filename.empty())
 llvm::sys::fs::remove(OF.Filename);
   continue;
 }
 
-if (OF.TempFilename.empty())
+if (!OF.File)
   continue;
 
+if (OF.File->TmpName.empty()) {
+  consumeError(OF.File->discard());
+  continue;
+}
+
 // If '-working-directory' was passed, the output filename should be
 // relative to that.
 SmallString<128> NewOutFile(OF.Filename);
 FileMgr->FixupRelativePath(NewOutFile);
-std::error_code EC = llvm::sys::fs::rename(OF.TempFilename, NewOutFile);
-if (!EC)
+
+llvm::Error E = OF.File->keep(NewOutFile);
+if (!E)
   continue;
+
 getDiagnostics().Report(diag::err_unable_to_rename_temp)
-<< OF.TempFilename << OF.Filename << EC.message();
+<< OF.File->TmpName << OF.Filename << std::move(E);
 
-llvm::sys::fs::remove(OF.TempFilename);
+llvm::sys::fs::remove(OF.File->TmpName);
   }
   OutputFiles.clear();
   if (DeleteBuiltModules) {
@@ -809,7 +815,7 @@ CompilerInstance::createOutputFileImpl(StringRef 
OutputPath, bool Binary,
 }
   }
 
-  std::string TempFile;
+  Optional Temp;
   if (UseTemporary) {
 // Create a temporary file.
 // Insert - before the extension (if any), and because some tools
@@ -821,25 +827,34 @@ CompilerInstance::createOutputFileImpl(StringRef 
OutputPath, bool Binary,
 TempPath += "-";
 TempPath += OutputExtension;
 TempPath += ".tmp";
-int fd;
-std::error_code EC = llvm::sys::fs::createUniqueFile(
-TempPath, fd, TempPath,
-Binary ? llvm::sys::fs::OF_None : llvm::sys::fs::OF_Text);
-
-if (CreateMissingDirectories &&
-EC == llvm::errc::no_such_file_or_directory) {
-  StringRef Parent = llvm::sys::path::parent_path(OutputPath);
-  EC = llvm::sys::fs::create_directories(Parent);
-  if (!EC) {
-

[clang] 3e2ad26 - [DebugInfo] Add -fno-ctor-homing for as counterpart to -fuse-ctor-homing

2021-07-22 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-07-22T14:52:36-07:00
New Revision: 3e2ad26b08a23e786e64e8e47547d25a1b5a7f28

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

LOG: [DebugInfo] Add -fno-ctor-homing for as counterpart to -fuse-ctor-homing

Add an opt out flag for constructor homing.

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

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index f7f76ed3f3e20..20be01a5f40ac 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2563,7 +2563,8 @@ below. If multiple flags are present, the last one is 
used.
non-trivial, non-aggregate C++ class in the modules that contain a
definition of one of its constructors. This relies on the additional
assumption that all classes that are not trivially constructible have a
-   non-trivial constructor that is used somewhere.
+   non-trivial constructor that is used somewhere. The negation,
+   -fno-use-ctor-homing, ensures that constructor homing is not used.
 
This flag is not enabled by default, and needs to be used with -cc1 or
-Xclang.

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 79955f4fa4f08..1815cd4621e87 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4836,6 +4836,8 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
 def fno_math_builtin : Flag<["-"], "fno-math-builtin">,
   HelpText<"Disable implicit builtin knowledge of math functions">,
   MarshallingInfoFlag>;
+def fno_use_ctor_homing: Flag<["-"], "fno-use-ctor-homing">,
+HelpText<"Don't use constructor homing for debug info">;
 def fuse_ctor_homing: Flag<["-"], "fuse-ctor-homing">,
 HelpText<"Use constructor homing if we are using limited debug info 
already">;
 }

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2c696b5394538..a8f25fa7c11c4 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1369,9 +1369,6 @@ void CompilerInvocation::GenerateCodeGenArgs(
   if (DebugInfoVal)
 GenerateArg(Args, OPT_debug_info_kind_EQ, *DebugInfoVal, SA);
 
-  if (Opts.DebugInfo == codegenoptions::DebugInfoConstructor)
-GenerateArg(Args, OPT_fuse_ctor_homing, SA);
-
   for (const auto &Prefix : Opts.DebugPrefixMap)
 GenerateArg(Args, OPT_fdebug_prefix_map_EQ,
 Prefix.first + "=" + Prefix.second, SA);
@@ -1627,10 +1624,16 @@ bool 
CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
   }
 
   // If -fuse-ctor-homing is set and limited debug info is already on, then use
-  // constructor homing.
-  if (Args.getLastArg(OPT_fuse_ctor_homing))
-if (Opts.getDebugInfo() == codegenoptions::LimitedDebugInfo)
+  // constructor homing, and vice versa for -fno-use-ctor-homing.
+  if (const Arg *A =
+  Args.getLastArg(OPT_fuse_ctor_homing, OPT_fno_use_ctor_homing)) {
+if (A->getOption().matches(OPT_fuse_ctor_homing) &&
+Opts.getDebugInfo() == codegenoptions::LimitedDebugInfo)
   Opts.setDebugInfo(codegenoptions::DebugInfoConstructor);
+if (A->getOption().matches(OPT_fno_use_ctor_homing) &&
+Opts.getDebugInfo() == codegenoptions::DebugInfoConstructor)
+  Opts.setDebugInfo(codegenoptions::LimitedDebugInfo);
+  }
 
   for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ)) {
 auto Split = StringRef(Arg).split('=');

diff  --git a/clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp 
b/clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp
index 5443fa9ade237..e0832f48c5e21 100644
--- a/clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp
+++ b/clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp
@@ -8,6 +8,9 @@
 // RUN:| FileCheck %s -check-prefix=NO_DEBUG
 // RUN: %clang -cc1 -fuse-ctor-homing -emit-llvm %s -o - \
 // RUN:| FileCheck %s -check-prefix=NO_DEBUG
+//
+// RUN: %clang -cc1 -debug-info-kind=constructor -fno-use-ctor-homing \
+// RUN:-emit-llvm %s -o - | FileCheck %s -check-prefix=FULL_DEBUG
 
 // This tests that the -fuse-ctor-homing is only used if limited debug info 
would have
 // been used otherwise.



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


[clang] 1a3bf29 - [DebugInfo] Switch to using constructor homing (-debug-info-kind=constructor) by default when debug info is enabled

2021-07-26 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-07-26T17:24:42-07:00
New Revision: 1a3bf2953a9209fdc4dbb6e99678e02a7fec019d

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

LOG: [DebugInfo] Switch to using constructor homing 
(-debug-info-kind=constructor) by default when debug info is enabled

Constructor homing reduces the amount of class type info that is emitted
by emitting conmplete type info for a class only when a constructor for
that class is emitted.

This will mainly reduce the amount of duplicate debug info in object
files. In Chrome enabling ctor homing decreased total build directory sizes
by about 30%.

It's also expected that some class types (such as unused classes)
will no longer be emitted in the debug info. This is fine, since we wouldn't
expect to need these types when debugging.

In some cases (e.g. libc++, https://reviews.llvm.org/D98750), classes
are used without calling the constructor. Since this is technically
undefined behavior, enabling constructor homing should be fine.
However Clang now has an attribute
`__attribute__((standalone_debug))` that can be used on classes to
ignore ctor homing.

Bug: https://bugs.llvm.org/show_bug.cgi?id=46537

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

Added: 


Modified: 
clang/include/clang/Basic/DebugInfoOptions.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGenCXX/debug-info-template-deduction-guide.cpp
clang/test/Driver/cl-options.c
clang/test/Driver/clang-g-opts.c
clang/test/Driver/cuda-dwarf-2.cu
clang/test/Driver/debug-options-as.c
clang/test/Driver/debug-options.c
clang/test/Driver/integrated-as.s
clang/test/Driver/myriad-toolchain.c
clang/test/Driver/openmp-offload-gpu.c
clang/test/Driver/split-debug.c
lldb/test/Shell/SymbolFile/PDB/Inputs/ClassLayoutTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DebugInfoOptions.h 
b/clang/include/clang/Basic/DebugInfoOptions.h
index 7f5669c1760fd..c1259d7797db2 100644
--- a/clang/include/clang/Basic/DebugInfoOptions.h
+++ b/clang/include/clang/Basic/DebugInfoOptions.h
@@ -37,6 +37,7 @@ enum DebugInfoKind {
   /// Limit generated debug info for classes to reduce size. This emits class
   /// type info only where the constructor is emitted, if it is a class that
   /// has a constructor.
+  /// FIXME: Consider combining this with LimitedDebugInfo.
   DebugInfoConstructor,
 
   /// Limit generated debug info to reduce size (-fno-standalone-debug). This

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index fabacd9d49c02..fa45be0f8169f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -504,7 +504,7 @@ static codegenoptions::DebugInfoKind 
DebugLevelToInfoKind(const Arg &A) {
 return codegenoptions::DebugLineTablesOnly;
   if (A.getOption().matches(options::OPT_gline_directives_only))
 return codegenoptions::DebugDirectivesOnly;
-  return codegenoptions::LimitedDebugInfo;
+  return codegenoptions::DebugInfoConstructor;
 }
 
 static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
@@ -2545,7 +2545,7 @@ static void CollectArgsForIntegratedAssembler(Compilation 
&C,
   CmdArgs.push_back(Value.data());
 } else {
   RenderDebugEnablingArgs(Args, CmdArgs,
-  codegenoptions::LimitedDebugInfo,
+  codegenoptions::DebugInfoConstructor,
   DwarfVersion, llvm::DebuggerKind::Default);
 }
   } else if (Value.startswith("-mcpu") || Value.startswith("-mfpu") ||
@@ -3914,7 +3914,7 @@ static void renderDebugOptions(const ToolChain &TC, const 
Driver &D,
 }
   }
   if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
-DebugInfoKind = codegenoptions::LimitedDebugInfo;
+DebugInfoKind = codegenoptions::DebugInfoConstructor;
 
 // If the last option explicitly specified a debug-info level, use it.
 if (checkDebugInfoOption(A, Args, D, TC) &&
@@ -4036,7 +4036,7 @@ static void renderDebugOptions(const ToolChain &TC, const 
Driver &D,
 if (checkDebugInfoOption(A, Args, D, TC)) {
   if (DebugInfoKind != codegenoptions::DebugLineTablesOnly &&
   DebugInfoKind != codegenoptions::DebugDirectivesOnly) {
-DebugInfoKind = codegenoptions::LimitedDebugInfo;
+DebugInfoKind = codegenoptions::DebugInfoConstructor;
 CmdArgs.push_back("-dwarf-ext-refs");
 CmdArgs.push_back("-fmodule-format=obj");
   }
@@ -4057,7 +4057,8 @@ static void renderDebugOptions(const ToolChain &TC, const 
Driver &D,
   if (const Arg *A = Args.getLastArg(options::OPT_fstandalone_debug))
 (void)checkDebugInfoOption(A, Args, D, TC);
 
-  if (Debug

[clang] cf11d95 - Fix to Windows temp file change.

2021-06-09 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-06-09T16:15:16-07:00
New Revision: cf11d9585afd5c43031a9fb622c8c31b4bef

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

LOG: Fix to Windows temp file change.

Original change passed wrong parameters to the raw_fd_ostream ctor.
Fixes a bug in https://reviews.llvm.org/D102736.

Added: 


Modified: 
clang/lib/Frontend/CompilerInstance.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index a70fe95800e1..78c7d84bbef4 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -853,9 +853,7 @@ CompilerInstance::createOutputFileImpl(StringRef 
OutputPath, bool Binary,
   consumeError(std::move(E));
 } else {
   Temp = std::move(ExpectedFile.get());
-  OS.reset(new llvm::raw_fd_ostream(Temp->FD, /*shouldClose=*/false,
-Binary ? llvm::sys::fs::OF_None
-   : llvm::sys::fs::OF_Text));
+  OS.reset(new llvm::raw_fd_ostream(Temp->FD, /*shouldClose=*/false));
   OSFile = Temp->TmpName;
 }
 // If we failed to create the temporary, fallback to writing to the file



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


[clang] d7cd208 - [DebugInfo] Add an attribute to force type info to be emitted for types that are required to be complete.

2021-03-12 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-03-12T12:30:01-08:00
New Revision: d7cd208f08afca450484be97604a55704a628e88

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

LOG: [DebugInfo] Add an attribute to force type info to be emitted for types 
that are required to be complete.

This was motivated by the fact that constructor type homing (debug info
optimization that we want to turn on by default) drops some libc++ types,
so an attribute would allow us to override constructor homing and emit
them anyway. I'm currently looking into the particular libc++ issue, but
even if we do fix that, this issue might come up elsewhere and it might be
nice to have this.

As I've implemented it now, the attribute isn't specific to the
constructor homing optimization and overrides all of the debug info
optimizations.

Open to discussion about naming, specifics on what the attribute should do, etc.

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

Added: 
clang/test/CodeGenCXX/standalone-debug-attribute.cpp
clang/test/Sema/attr-standalonedebug.cpp

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 9625e7f8f3221..664eb566a7032 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1673,6 +1673,14 @@ def NoDebug : InheritableAttr {
   let Documentation = [NoDebugDocs];
 }
 
+def StandaloneDebug : InheritableAttr {
+  let Spellings = [Clang<"standalone_debug", /*allowInC =*/0>];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let Documentation = [StandaloneDebugDocs];
+  let SimpleHandler = 1;
+  let LangOpts = [CPlusPlus];
+}
+
 def NoDuplicate : InheritableAttr {
   let Spellings = [Clang<"noduplicate">];
   let Subjects = SubjectList<[Function]>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index deda68b64f909..77d3bd1fdcd6e 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1102,6 +1102,16 @@ data member, or for a typedef or using declaration.
   }];
 }
 
+def StandaloneDebugDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+The ``standalone_debug`` attribute causes debug info to be emitted for a record
+type regardless of the debug info optimizations that are enabled with
+-fno-standalone-debug. This attribute only has an effect when debug info
+optimizations are enabled (e.g. with -fno-standalone-debug), and is C++-only.
+  }];
+}
+
 def NoDuplicateDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0aa8737b9f07d..468c2b78b488d 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2385,7 +2385,8 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
   if (DebugKind == codegenoptions::DebugLineTablesOnly)
 return true;
 
-  if (DebugKind > codegenoptions::LimitedDebugInfo)
+  if (DebugKind > codegenoptions::LimitedDebugInfo ||
+  RD->hasAttr())
 return false;
 
   if (!LangOpts.CPlusPlus)

diff  --git a/clang/test/CodeGenCXX/standalone-debug-attribute.cpp 
b/clang/test/CodeGenCXX/standalone-debug-attribute.cpp
new file mode 100644
index 0..a814e6f425ed6
--- /dev/null
+++ b/clang/test/CodeGenCXX/standalone-debug-attribute.cpp
@@ -0,0 +1,54 @@
+// RUN: %clang_cc1 -DSETATTR=0 -triple x86_64-unknown-linux-gnu -emit-llvm 
-debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=DEBUG
+// RUN: %clang_cc1 -DSETATTR=1 -triple x86_64-unknown-linux-gnu -emit-llvm 
-debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=WITHATTR
+// Use -debug-info-kind=constructor because it includes all the optimizations.
+
+#if SETATTR
+#define STANDALONEDEBUGATTR __attribute__((standalone_debug))
+#else
+#define STANDALONEDEBUGATTR
+#endif
+
+struct STANDALONEDEBUGATTR StructWithConstructor {
+  StructWithConstructor() {}
+};
+void f(StructWithConstructor s) {}
+// DEBUG:  !DICompositeType({{.*}}name: "StructWithConstructor"
+// DEBUG-SAME:  flags: {{.*}}DIFlagFwdDecl
+// WITHATTR: !DICompositeType({{.*}}name: "StructWithConstructor"
+// WITHATTR-NOT: DIFlagFwdDecl
+
+union STANDALONEDEBUGATTR UnionWithConstructor {
+  UnionWithConstructor() {}
+};
+void f(UnionWithConstructor u) {}
+// DEBUG:  !DICompositeType({{.*}}name: "UnionWithConstructor"
+// DEBUG-SAME:  flags: {{.*}}DIFlagFwdDecl
+// WITHATTR: !DICompositeType({{.*}}name: "UnionWithConstructor"
+// WITHATTR-NOT: DIFl

[clang] f5352dd - Emit inline implementation of __builtin__wmemchr on MSVCRT platforms.

2021-03-15 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-03-15T15:30:55-07:00
New Revision: f5352dd9dab1ee8a2ae19a3fca3111c8b5de8ce2

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

LOG: Emit inline implementation of __builtin__wmemchr on MSVCRT platforms.

The MSVC runtime library doesn't have a definition for wmemchr,
so provide an inline implementation.

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

Added: 
clang/test/CodeGen/wmemchr.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9827311e07d8..e5778c0c78f7 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3380,6 +3380,52 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Builder.CreateMemSet(Dest, ByteVal, SizeVal, false);
 return RValue::get(Dest.getPointer());
   }
+  case Builtin::BI__builtin_wmemchr: {
+// The MSVC runtime library does not provide a definition of wmemchr, so we
+// need an inline implementation.
+if (!getTarget().getTriple().isOSMSVCRT())
+  break;
+
+llvm::Type *WCharTy = ConvertType(getContext().WCharTy);
+Value *Str = EmitScalarExpr(E->getArg(0));
+Value *Chr = EmitScalarExpr(E->getArg(1));
+Value *Size = EmitScalarExpr(E->getArg(2));
+
+BasicBlock *Entry = Builder.GetInsertBlock();
+BasicBlock *CmpEq = createBasicBlock("wmemchr.eq");
+BasicBlock *Next = createBasicBlock("wmemchr.next");
+BasicBlock *Exit = createBasicBlock("wmemchr.exit");
+Value *SizeEq0 = Builder.CreateICmpEQ(Size, ConstantInt::get(SizeTy, 0));
+Builder.CreateCondBr(SizeEq0, Exit, CmpEq);
+
+EmitBlock(CmpEq);
+PHINode *StrPhi = Builder.CreatePHI(Str->getType(), 2);
+StrPhi->addIncoming(Str, Entry);
+PHINode *SizePhi = Builder.CreatePHI(SizeTy, 2);
+SizePhi->addIncoming(Size, Entry);
+CharUnits WCharAlign =
+getContext().getTypeAlignInChars(getContext().WCharTy);
+Value *StrCh = Builder.CreateAlignedLoad(WCharTy, StrPhi, WCharAlign);
+Value *FoundChr = Builder.CreateConstInBoundsGEP1_32(WCharTy, StrPhi, 0);
+Value *StrEqChr = Builder.CreateICmpEQ(StrCh, Chr);
+Builder.CreateCondBr(StrEqChr, Exit, Next);
+
+EmitBlock(Next);
+Value *NextStr = Builder.CreateConstInBoundsGEP1_32(WCharTy, StrPhi, 1);
+Value *NextSize = Builder.CreateSub(SizePhi, ConstantInt::get(SizeTy, 1));
+Value *NextSizeEq0 =
+Builder.CreateICmpEQ(NextSize, ConstantInt::get(SizeTy, 0));
+Builder.CreateCondBr(NextSizeEq0, Exit, CmpEq);
+StrPhi->addIncoming(NextStr, Next);
+SizePhi->addIncoming(NextSize, Next);
+
+EmitBlock(Exit);
+PHINode *Ret = Builder.CreatePHI(Str->getType(), 3);
+Ret->addIncoming(llvm::Constant::getNullValue(Str->getType()), Entry);
+Ret->addIncoming(llvm::Constant::getNullValue(Str->getType()), Next);
+Ret->addIncoming(FoundChr, CmpEq);
+return RValue::get(Ret);
+  }
   case Builtin::BI__builtin_wmemcmp: {
 // The MSVC runtime library does not provide a definition of wmemcmp, so we
 // need an inline implementation.

diff  --git a/clang/test/CodeGen/wmemchr.c b/clang/test/CodeGen/wmemchr.c
new file mode 100644
index ..3ff3fba34043
--- /dev/null
+++ b/clang/test/CodeGen/wmemchr.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 %s -triple x86_64-pc-win32 -emit-llvm -o - | FileCheck %s
+
+typedef __SIZE_TYPE__ size_t;
+typedef __WCHAR_TYPE__ wchar_t;
+
+const wchar_t *wmemchr_test(const wchar_t *s, const wchar_t c, size_t n) {
+  // CHECK-LABEL: define dso_local i16* @wmemchr_test
+  // CHECK: [[S:%.*]] = load
+  // CHECK: [[C:%.*]] = load
+  // CHECK: [[N:%.*]] = load
+  // CHECK: [[N0:%.*]] = icmp eq i64 [[N]], 0
+  // CHECK: br i1 [[N0]], label %[[EXIT:.*]], label %[[EQ:.*]]
+
+  // CHECK: [[EQ]]:
+  // CHECK: [[SP:%.*]] = phi i16* [ [[S]], %[[ENTRY:.*]] ], [ [[SN:.*]], 
%[[NEXT:.*]] ]
+  // CHECK: [[NP:%.*]] = phi i64 [ [[N]], %[[ENTRY]] ], [ [[NN:.*]], %[[NEXT]] 
]
+  // CHECK: [[SL:%.*]] = load i16, i16* [[SP]], align 2
+  // CHECK: [[RES:%.*]] = getelementptr inbounds i16, i16* [[SP]], i32 0
+  // CHECK: [[CMPEQ:%.*]] = icmp eq i16 [[SL]], [[C]]
+  // CHECK: br i1 [[CMPEQ]], label %[[EXIT]], label %[[LT:.*]]
+
+  // CHECK: [[NEXT]]:
+  // CHECK: [[SN]] = getelementptr inbounds i16, i16* [[SP]], i32 1
+  // CHECK: [[NN]] = sub i64 [[NP]], 1
+  // CHECK: [[NN0:%.*]] = icmp eq i64 [[NN]], 0
+  // CHECK: br i1 [[NN0]], label %[[EXIT]], label %[[EQ]]
+  //
+  // CHECK: [[EXIT]]:
+  // CHECK: [[RV:%.*]] = phi i16* [ null, %[[ENTRY]] ], [ null, %[[NEXT]] ], [ 
[[RES]], %[[EQ]] ] 
+  // CHECK: ret i16* [[RV]]
+  return __builtin_wmemchr(s, c, n);
+}



___
cfe-commits m

[clang] Fix to msvc::no_unique_address causing assert when used with __declspec(empty_bases) (PR #74776)

2023-12-07 Thread Amy Huang via cfe-commits

https://github.com/amykhuang created 
https://github.com/llvm/llvm-project/pull/74776

no_unique_address makes it possible for a class to be empty and have non-zero 
virtual size, so just remove this assert.

Bug: https://github.com/llvm/llvm-project/issues/74442

>From c3dedfd535f037fb54a8e04640f9332e655a9a7d Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Thu, 7 Dec 2023 14:08:24 -0800
Subject: [PATCH] Fix to msvc::no_unique_address not interacting well with
 __declspec(empty_bases)

---
 clang/lib/AST/RecordLayoutBuilder.cpp |  4 +-
 .../Layout/ms-x86-declspec-empty_bases.cpp| 60 +++
 2 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index f1f2275da44dc..73b248ffe5899 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2936,8 +2936,8 @@ void MicrosoftRecordLayoutBuilder::layoutNonVirtualBase(
   }
 
   if (!FoundBase) {
-if (MDCUsesEBO && BaseDecl->isEmpty()) {
-  assert(BaseLayout.getNonVirtualSize() == CharUnits::Zero());
+if (MDCUsesEBO && BaseDecl->isEmpty() &&
+(BaseLayout.getNonVirtualSize() == CharUnits::Zero())) {
   BaseOffset = CharUnits::Zero();
 } else {
   // Otherwise, lay the base out at the end of the MDC.
diff --git a/clang/test/Layout/ms-x86-declspec-empty_bases.cpp 
b/clang/test/Layout/ms-x86-declspec-empty_bases.cpp
index cc13a980cb5db..4738ce5720f75 100644
--- a/clang/test/Layout/ms-x86-declspec-empty_bases.cpp
+++ b/clang/test/Layout/ms-x86-declspec-empty_bases.cpp
@@ -264,3 +264,63 @@ int _ = sizeof(G);
 // CHECK-NEXT:| [sizeof=12, align=4,
 // CHECK-NEXT:|  nvsize=12, nvalign=4]
 }
+
+namespace test5 {
+
+struct A {
+  int a;
+};
+struct B {
+  int b;
+};
+struct C {};
+struct __declspec(align(16)) D {};
+struct E {
+  [[msvc::no_unique_address]] C c;
+};
+struct __declspec(empty_bases) X : A, D, B, C, E {
+};
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test5::A
+// CHECK-NEXT:  0 |   int a
+// CHECK-NEXT:| [sizeof=4, align=4,
+// CHECK-NEXT:|  nvsize=4, nvalign=4]
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test5::D (empty)
+// CHECK-NEXT:| [sizeof=16, align=16,
+// CHECK-NEXT:|  nvsize=0, nvalign=16]
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test5::B
+// CHECK-NEXT:  0 |   int b
+// CHECK-NEXT:| [sizeof=4, align=4,
+// CHECK-NEXT:|  nvsize=4, nvalign=4]
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test5::C (empty)
+// CHECK-NEXT:| [sizeof=1, align=1,
+// CHECK-NEXT:|  nvsize=0, nvalign=1]
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test5::E (empty)
+// CHECK-NEXT:  0 |   struct test5::C c (empty)
+// CHECK-NEXT:| [sizeof=1, align=1,
+// CHECK-NEXT:|  nvsize=1, nvalign=1]
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT:  0 | struct test5::X
+// CHECK-NEXT:  0 |   struct test5::A (base)
+// CHECK-NEXT:  0 | int a
+// CHECK-NEXT:  0 |   struct test5::D (base) (empty)
+// CHECK-NEXT:  0 |   struct test5::C (base) (empty)
+// CHECK-NEXT:  4 |   struct test5::B (base)
+// CHECK-NEXT:  4 | int b
+// CHECK-NEXT:  8 |   struct test5::E (base) (empty)
+// CHECK-NEXT:  8 | struct test5::C c (empty)
+// CHECK-NEXT:| [sizeof=16, align=16,
+// CHECK-NEXT:|  nvsize=16, nvalign=16]
+
+int _ = sizeof(X);
+}

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


[clang] Fix to msvc::no_unique_address causing assert when used with __declspec(empty_bases) (PR #74776)

2023-12-11 Thread Amy Huang via cfe-commits

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


[clang] Fix to attribute plugins reaching an unreachable (PR #70877)

2023-11-15 Thread Amy Huang via cfe-commits

amykhuang wrote:

ping for review?

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


[clang] Fix to attribute plugins reaching an unreachable (PR #70877)

2023-11-15 Thread Amy Huang via cfe-commits

https://github.com/amykhuang updated 
https://github.com/llvm/llvm-project/pull/70877

>From 8216d6bc5329d4fcb723db14e2c503cb718cb36d Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Tue, 31 Oct 2023 16:45:17 -0700
Subject: [PATCH 1/2] Fix attribute plugins

---
 clang/lib/Sema/ParsedAttr.cpp | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index f59b01efe7ed8f4..ad95a61d7587264 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -193,11 +193,20 @@ bool ParsedAttr::isTypeAttr() const { return 
getInfo().IsType; }
 bool ParsedAttr::isStmtAttr() const { return getInfo().IsStmt; }
 
 bool ParsedAttr::existsInTarget(const TargetInfo &Target) const {
-  return getInfo().existsInTarget(Target) &&
- getInfo().spellingExistsInTarget(Target,
-  getAttributeSpellingListIndex());
+  Kind K = getParsedKind();
+
+  // If the attribute has a target-specific spelling, check that it exists.
+  // Only call this if the attr is not ignored/unknown. For most targets, this
+  // function just returns true.
+  bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute &&
+ K != NoSemaHandlerAttribute;
+  bool TargetSpecificSpellingExists = !HasSpelling ||
+getInfo().spellingExistsInTarget(Target, getAttributeSpellingListIndex());
+
+  return getInfo().existsInTarget(Target) && TargetSpecificSpellingExists;
 }
 
+
 bool ParsedAttr::isKnownToGCC() const { return getInfo().IsKnownToGCC; }
 
 bool ParsedAttr::isSupportedByPragmaAttribute() const {

>From 2ed7200e8853fb5c2b51f57129d20b359bb54173 Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Tue, 7 Nov 2023 14:51:06 -0800
Subject: [PATCH 2/2] clang-format

---
 clang/lib/Sema/ParsedAttr.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index ad95a61d7587264..06c213267c7ef5d 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -200,13 +200,13 @@ bool ParsedAttr::existsInTarget(const TargetInfo &Target) 
const {
   // function just returns true.
   bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute &&
  K != NoSemaHandlerAttribute;
-  bool TargetSpecificSpellingExists = !HasSpelling ||
-getInfo().spellingExistsInTarget(Target, getAttributeSpellingListIndex());
+  bool TargetSpecificSpellingExists =
+  !HasSpelling ||
+  getInfo().spellingExistsInTarget(Target, 
getAttributeSpellingListIndex());
 
   return getInfo().existsInTarget(Target) && TargetSpecificSpellingExists;
 }
 
-
 bool ParsedAttr::isKnownToGCC() const { return getInfo().IsKnownToGCC; }
 
 bool ParsedAttr::isSupportedByPragmaAttribute() const {

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


[clang] Fix to attribute plugins reaching an unreachable (PR #70877)

2023-11-16 Thread Amy Huang via cfe-commits

amykhuang wrote:

Whoops, sorry about that, I guess I am failing to update my fork properly... 

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


[clang] Fix to attribute plugins reaching an unreachable (PR #70877)

2023-11-16 Thread Amy Huang via cfe-commits

https://github.com/amykhuang updated 
https://github.com/llvm/llvm-project/pull/70877

>From e24ee9cbc51d0f372c30512ce5722b2bc32e20d0 Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Tue, 31 Oct 2023 16:45:17 -0700
Subject: [PATCH 1/2] Fix attribute plugins

---
 clang/lib/Sema/ParsedAttr.cpp | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index f59b01efe7ed8f4..ad95a61d7587264 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -193,11 +193,20 @@ bool ParsedAttr::isTypeAttr() const { return 
getInfo().IsType; }
 bool ParsedAttr::isStmtAttr() const { return getInfo().IsStmt; }
 
 bool ParsedAttr::existsInTarget(const TargetInfo &Target) const {
-  return getInfo().existsInTarget(Target) &&
- getInfo().spellingExistsInTarget(Target,
-  getAttributeSpellingListIndex());
+  Kind K = getParsedKind();
+
+  // If the attribute has a target-specific spelling, check that it exists.
+  // Only call this if the attr is not ignored/unknown. For most targets, this
+  // function just returns true.
+  bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute &&
+ K != NoSemaHandlerAttribute;
+  bool TargetSpecificSpellingExists = !HasSpelling ||
+getInfo().spellingExistsInTarget(Target, getAttributeSpellingListIndex());
+
+  return getInfo().existsInTarget(Target) && TargetSpecificSpellingExists;
 }
 
+
 bool ParsedAttr::isKnownToGCC() const { return getInfo().IsKnownToGCC; }
 
 bool ParsedAttr::isSupportedByPragmaAttribute() const {

>From c75681d0817bed88773635eb6b91eb483db29a50 Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Tue, 7 Nov 2023 14:51:06 -0800
Subject: [PATCH 2/2] clang-format

---
 clang/lib/Sema/ParsedAttr.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index ad95a61d7587264..06c213267c7ef5d 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -200,13 +200,13 @@ bool ParsedAttr::existsInTarget(const TargetInfo &Target) 
const {
   // function just returns true.
   bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute &&
  K != NoSemaHandlerAttribute;
-  bool TargetSpecificSpellingExists = !HasSpelling ||
-getInfo().spellingExistsInTarget(Target, getAttributeSpellingListIndex());
+  bool TargetSpecificSpellingExists =
+  !HasSpelling ||
+  getInfo().spellingExistsInTarget(Target, 
getAttributeSpellingListIndex());
 
   return getInfo().existsInTarget(Target) && TargetSpecificSpellingExists;
 }
 
-
 bool ParsedAttr::isKnownToGCC() const { return getInfo().IsKnownToGCC; }
 
 bool ParsedAttr::isSupportedByPragmaAttribute() const {

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


[clang] Fix to attribute plugins reaching an unreachable (PR #70877)

2023-11-20 Thread Amy Huang via cfe-commits

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


[clang] Fix to attribute plugins reaching an unreachable (PR #70877)

2023-11-07 Thread Amy Huang via cfe-commits

amykhuang wrote:

Huh, apparently my no-unique-address patch did break existing plugin tests 
(e.g. clang/test/Frontend/plugin-attribute.cpp), and this patch doesn't fix it

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


[clang] Fix to attribute plugins reaching an unreachable (PR #70877)

2023-11-07 Thread Amy Huang via cfe-commits

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


[clang] Fix to attribute plugins reaching an unreachable (PR #70877)

2023-11-07 Thread Amy Huang via cfe-commits

https://github.com/amykhuang updated 
https://github.com/llvm/llvm-project/pull/70877

>From 18369263a3160963b943cd8574edaa212b6d0996 Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Tue, 31 Oct 2023 16:45:17 -0700
Subject: [PATCH] Fix attribute plugins

---
 clang/lib/Sema/ParsedAttr.cpp | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index f59b01efe7ed8f4..ad95a61d7587264 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -193,11 +193,20 @@ bool ParsedAttr::isTypeAttr() const { return 
getInfo().IsType; }
 bool ParsedAttr::isStmtAttr() const { return getInfo().IsStmt; }
 
 bool ParsedAttr::existsInTarget(const TargetInfo &Target) const {
-  return getInfo().existsInTarget(Target) &&
- getInfo().spellingExistsInTarget(Target,
-  getAttributeSpellingListIndex());
+  Kind K = getParsedKind();
+
+  // If the attribute has a target-specific spelling, check that it exists.
+  // Only call this if the attr is not ignored/unknown. For most targets, this
+  // function just returns true.
+  bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute &&
+ K != NoSemaHandlerAttribute;
+  bool TargetSpecificSpellingExists = !HasSpelling ||
+getInfo().spellingExistsInTarget(Target, getAttributeSpellingListIndex());
+
+  return getInfo().existsInTarget(Target) && TargetSpecificSpellingExists;
 }
 
+
 bool ParsedAttr::isKnownToGCC() const { return getInfo().IsKnownToGCC; }
 
 bool ParsedAttr::isSupportedByPragmaAttribute() const {

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


[clang] Fix to attribute plugins reaching an unreachable (PR #70877)

2023-11-07 Thread Amy Huang via cfe-commits

amykhuang wrote:

Updated the PR description and the patch. The existing 
`clang/test/Frontend/plugin-attribute.cpp` seems sufficient for test coverage. 
(I guess it wasn't being tested on bots though, otherwise we would have seen 
it?)

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


[clang] Fix to attribute plugins reaching an unreachable (PR #70877)

2023-11-07 Thread Amy Huang via cfe-commits

https://github.com/amykhuang updated 
https://github.com/llvm/llvm-project/pull/70877

>From 18369263a3160963b943cd8574edaa212b6d0996 Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Tue, 31 Oct 2023 16:45:17 -0700
Subject: [PATCH 1/2] Fix attribute plugins

---
 clang/lib/Sema/ParsedAttr.cpp | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index f59b01efe7ed8f4..ad95a61d7587264 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -193,11 +193,20 @@ bool ParsedAttr::isTypeAttr() const { return 
getInfo().IsType; }
 bool ParsedAttr::isStmtAttr() const { return getInfo().IsStmt; }
 
 bool ParsedAttr::existsInTarget(const TargetInfo &Target) const {
-  return getInfo().existsInTarget(Target) &&
- getInfo().spellingExistsInTarget(Target,
-  getAttributeSpellingListIndex());
+  Kind K = getParsedKind();
+
+  // If the attribute has a target-specific spelling, check that it exists.
+  // Only call this if the attr is not ignored/unknown. For most targets, this
+  // function just returns true.
+  bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute &&
+ K != NoSemaHandlerAttribute;
+  bool TargetSpecificSpellingExists = !HasSpelling ||
+getInfo().spellingExistsInTarget(Target, getAttributeSpellingListIndex());
+
+  return getInfo().existsInTarget(Target) && TargetSpecificSpellingExists;
 }
 
+
 bool ParsedAttr::isKnownToGCC() const { return getInfo().IsKnownToGCC; }
 
 bool ParsedAttr::isSupportedByPragmaAttribute() const {

>From f068257dac770959b130bc8b33eb4689e5dd47db Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Tue, 7 Nov 2023 14:51:06 -0800
Subject: [PATCH 2/2] clang-format

---
 clang/lib/Sema/ParsedAttr.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index ad95a61d7587264..06c213267c7ef5d 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -200,13 +200,13 @@ bool ParsedAttr::existsInTarget(const TargetInfo &Target) 
const {
   // function just returns true.
   bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute &&
  K != NoSemaHandlerAttribute;
-  bool TargetSpecificSpellingExists = !HasSpelling ||
-getInfo().spellingExistsInTarget(Target, getAttributeSpellingListIndex());
+  bool TargetSpecificSpellingExists =
+  !HasSpelling ||
+  getInfo().spellingExistsInTarget(Target, 
getAttributeSpellingListIndex());
 
   return getInfo().existsInTarget(Target) && TargetSpecificSpellingExists;
 }
 
-
 bool ParsedAttr::isKnownToGCC() const { return getInfo().IsKnownToGCC; }
 
 bool ParsedAttr::isSupportedByPragmaAttribute() const {

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


[clang] Fix to attribute plugins reaching an unreachable (PR #70877)

2023-10-31 Thread Amy Huang via cfe-commits

https://github.com/amykhuang created 
https://github.com/llvm/llvm-project/pull/70877

[0faee97](https://github.com/llvm/llvm-project/commit/0faee97a924adec76d5c7cd680c289ced51e6b5a)
 made the attribute plugin code hit an unreachable.

Bug: [70702](https://github.com/llvm/llvm-project/issues/70702)

>From bb896fbc4b7303bc0ef524bbff91e95610cb11ce Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Tue, 31 Oct 2023 16:45:17 -0700
Subject: [PATCH] Fix attribute plugins

---
 clang/lib/Sema/ParsedAttr.cpp | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp
index f59b01efe7ed8f4..2d6d17e74f6e38d 100644
--- a/clang/lib/Sema/ParsedAttr.cpp
+++ b/clang/lib/Sema/ParsedAttr.cpp
@@ -193,9 +193,13 @@ bool ParsedAttr::isTypeAttr() const { return 
getInfo().IsType; }
 bool ParsedAttr::isStmtAttr() const { return getInfo().IsStmt; }
 
 bool ParsedAttr::existsInTarget(const TargetInfo &Target) const {
+  Kind K = getParsedKind();
+  bool HasSpelling = K != IgnoredAttribute && K != UnknownAttribute &&
+ K != NoSemaHandlerAttribute;
   return getInfo().existsInTarget(Target) &&
- getInfo().spellingExistsInTarget(Target,
-  getAttributeSpellingListIndex());
+ (HasSpelling &&
+  getInfo().spellingExistsInTarget(Target,
+  getAttributeSpellingListIndex()));
 }
 
 bool ParsedAttr::isKnownToGCC() const { return getInfo().IsKnownToGCC; }

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


[clang] [MSVC, ARM64] Add __prefetch intrinsic (PR #67174)

2023-10-13 Thread Amy Huang via cfe-commits

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread Amy Huang via cfe-commits

amykhuang wrote:

Hi, this is causing failures for Chrome, building with c++20:

```
$ cat t.cc
template  class StrongAlias {
  friend constexpr bool operator==(const StrongAlias &, const StrongAlias &) = 
default;
  Type value;
};

class Token {};
bool operator==(const Token&, const Token&);

StrongAlias a;

$ clang -std=c++20 t.cc
t.cc:2:3: error: defaulted definition of equality comparison operator cannot be 
declared constexpr because it invokes a non-constexpr comparison function 
2 |   friend constexpr bool operator==(const StrongAlias &, const 
StrongAlias &) = default;
  |   ^
t.cc:9:20: note: in instantiation of template class 'StrongAlias' 
requested here
9 | StrongAlias a;
  |^
t.cc:3:8: note: non-constexpr comparison function would be used to compare 
member 'value'
3 |   Type value;
  |^
t.cc:7:6: note: non-constexpr comparison function declared here
7 | bool operator==(const Token&, const Token&);
  |  ^
1 error generated.
```

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


[clang] Revert "[Clang][C++23] Implement P2448R2 ..." (PR #85136)

2024-03-13 Thread Amy Huang via cfe-commits

https://github.com/amykhuang created 
https://github.com/llvm/llvm-project/pull/85136

Revert "[Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions 
(#77753)"

This reverts commit 99500e8c08a4d941acb8a7eb00523296fb2acf7a because it causes 
a behavior change for std=c++20. See
https://github.com/llvm/llvm-project/pull/77753.

>From 2f67dfb012038678dd0b873394a55bd5c937f843 Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Wed, 13 Mar 2024 21:40:12 +
Subject: [PATCH] Revert "[Clang][C++23] Implement P2448R2: Relaxing some
 constexpr restrictions (#77753)"

This reverts commit 99500e8c08a4d941acb8a7eb00523296fb2acf7a because it
causes a behavior change for std=c++20. See
https://github.com/llvm/llvm-project/pull/77753.
---
 clang/docs/ReleaseNotes.rst   |   2 -
 .../clang/Basic/DiagnosticSemaKinds.td|  26 ++-
 clang/lib/AST/DeclCXX.cpp |  13 +-
 clang/lib/Sema/SemaDeclCXX.cpp|  93 +-
 clang/test/AST/Interp/cxx23.cpp   |  59 +--
 .../class.compare.default/p3.cpp  |  40 +++--
 .../class.compare.default/p4.cpp  |  20 +--
 .../dcl.dcl/dcl.spec/dcl.constexpr/dtor.cpp   |   8 +-
 .../dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp  |  10 +-
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp |  18 +-
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp |   8 +-
 .../dcl.fct.def/dcl.fct.def.default/p2.cpp|   6 +-
 clang/test/CXX/drs/dr13xx.cpp |  22 +--
 clang/test/CXX/drs/dr14xx.cpp |   6 +-
 clang/test/CXX/drs/dr15xx.cpp |  21 +--
 clang/test/CXX/drs/dr16xx.cpp |  20 +--
 clang/test/CXX/drs/dr6xx.cpp  |  24 +--
 clang/test/CXX/expr/expr.const/p5-26.cpp  |   4 +-
 clang/test/CXX/special/class.copy/p13-0x.cpp  |   2 +-
 .../SemaCXX/constant-expression-cxx11.cpp |  38 ++---
 .../SemaCXX/constant-expression-cxx14.cpp |  33 ++--
 .../SemaCXX/constant-expression-cxx2b.cpp |  24 +--
 .../test/SemaCXX/cxx23-invalid-constexpr.cpp  | 159 --
 clang/test/SemaCXX/cxx2a-consteval.cpp|   2 +-
 .../SemaCXX/deduced-return-type-cxx14.cpp |   8 +-
 .../addrspace-constructors.clcpp  |   2 +-
 clang/www/cxx_status.html |   9 +-
 27 files changed, 269 insertions(+), 408 deletions(-)
 delete mode 100644 clang/test/SemaCXX/cxx23-invalid-constexpr.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5fe3fd066df235..e018d38355945f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -102,8 +102,6 @@ C++23 Feature Support
   materialize temporary object which is a prvalue in discarded-value 
expression.
 - Implemented `P1774R8: Portable assumptions `_.
 
-- Implemented `P2448R2: Relaxing some constexpr restrictions 
`_.
-
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d7ab1635cf12bc..605fbc52701df0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9617,10 +9617,13 @@ def err_defaulted_copy_assign_not_ref : Error<
   "the parameter for an explicitly-defaulted copy assignment operator must be 
an "
   "lvalue reference type">;
 def err_incorrect_defaulted_constexpr : Error<
-  "defaulted definition of %sub{select_special_member_kind}0 cannot be marked 
%select{constexpr|consteval}1 "
-  "before C++23">;
+  "defaulted definition of %sub{select_special_member_kind}0 "
+  "is not constexpr">;
 def err_incorrect_defaulted_constexpr_with_vb: Error<
   "%sub{select_special_member_kind}0 cannot be 'constexpr' in a class with 
virtual base class">;
+def err_incorrect_defaulted_consteval : Error<
+  "defaulted declaration of %sub{select_special_member_kind}0 "
+  "cannot be consteval because implicit definition is not constexpr">;
 def warn_defaulted_method_deleted : Warning<
   "explicitly defaulted %sub{select_special_member_kind}0 is implicitly "
   "deleted">, InGroup;
@@ -9731,12 +9734,21 @@ def 
note_defaulted_comparison_cannot_deduce_undeduced_auto : Note<
   "%select{|member|base class}0 %1 declared here">;
 def note_defaulted_comparison_cannot_deduce_callee : Note<
   "selected 'operator<=>' for %select{|member|base class}0 %1 declared here">;
-def err_defaulted_comparison_constexpr_mismatch : Error<
+def ext_defaulted_comparison_constexpr_mismatch : Extension<
   "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
-  "three-way comparison operator}0 cannot be "
-  "declared %select{constexpr|consteval}2 because "
-  "%select{it|for which the corresponding implicit 'operator==' }0 "
-  "invokes a non-constexpr comparison function ">;
+  "three-way comparison operator}0 that is "
+  "declared %select{constexpr|consteval}2 but"
+  "%select{|for which the correspo

[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread Amy Huang via cfe-commits

amykhuang wrote:

I'm assuming this behavior is unintended? Sorry for the late revert

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


[clang] Revert "[Clang][C++23] Implement P2448R2 ..." (PR #85136)

2024-03-13 Thread Amy Huang via cfe-commits

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


[clang] Unrevert "[Clang][C++23] Implement P2448R2: Relaxing some constexpr re… (PR #85140)

2024-03-13 Thread Amy Huang via cfe-commits

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread Amy Huang via cfe-commits

amykhuang wrote:

Nevermind, unreverted since there appear to be newer tests that use this patch. 

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


[clang] Unrevert "[Clang][C++23] Implement P2448R2: Relaxing some constexpr re… (PR #85140)

2024-03-13 Thread Amy Huang via cfe-commits

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


[clang] Reapply "[Clang][C++23] Implement P2448R2 ..." (#85136) (PR #85145)

2024-03-13 Thread Amy Huang via cfe-commits

https://github.com/amykhuang created 
https://github.com/llvm/llvm-project/pull/85145

This reverts commit 003e292f9895a9cf4e30688269efa668d1fcbb09 because there were 
dependent changes in the codebase that now fail. 

>From d8f21288633aefd1528133ccdf46c5dc790e4f1f Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Wed, 13 Mar 2024 22:55:31 +
Subject: [PATCH] Reapply "[Clang][C++23] Implement P2448R2 ..." (#85136)

This reverts commit 003e292f9895a9cf4e30688269efa668d1fcbb09.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|  26 +--
 clang/lib/AST/DeclCXX.cpp |  13 +-
 clang/lib/Sema/SemaDeclCXX.cpp|  93 +-
 clang/test/AST/Interp/cxx23.cpp   |  59 ++-
 .../class.compare.default/p3.cpp  |  40 ++---
 .../class.compare.default/p4.cpp  |  20 +--
 .../dcl.dcl/dcl.spec/dcl.constexpr/dtor.cpp   |   8 +-
 .../dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp  |  10 +-
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp |  18 +-
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp |   8 +-
 .../dcl.fct.def/dcl.fct.def.default/p2.cpp|   6 +-
 clang/test/CXX/drs/dr13xx.cpp |  22 +--
 clang/test/CXX/drs/dr14xx.cpp |   6 +-
 clang/test/CXX/drs/dr15xx.cpp |  21 ++-
 clang/test/CXX/drs/dr16xx.cpp |  20 +--
 clang/test/CXX/drs/dr6xx.cpp  |  24 +--
 clang/test/CXX/expr/expr.const/p5-26.cpp  |   4 +-
 clang/test/CXX/special/class.copy/p13-0x.cpp  |   2 +-
 .../SemaCXX/constant-expression-cxx11.cpp |  38 +++--
 .../SemaCXX/constant-expression-cxx14.cpp |  33 ++--
 .../SemaCXX/constant-expression-cxx2b.cpp |  24 +--
 .../test/SemaCXX/cxx23-invalid-constexpr.cpp  | 159 ++
 clang/test/SemaCXX/cxx2a-consteval.cpp|   2 +-
 .../SemaCXX/deduced-return-type-cxx14.cpp |   8 +-
 .../addrspace-constructors.clcpp  |   2 +-
 clang/www/cxx_status.html |   9 +-
 27 files changed, 408 insertions(+), 269 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx23-invalid-constexpr.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e018d38355945f..5fe3fd066df235 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -102,6 +102,8 @@ C++23 Feature Support
   materialize temporary object which is a prvalue in discarded-value 
expression.
 - Implemented `P1774R8: Portable assumptions `_.
 
+- Implemented `P2448R2: Relaxing some constexpr restrictions 
`_.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 605fbc52701df0..d7ab1635cf12bc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9617,13 +9617,10 @@ def err_defaulted_copy_assign_not_ref : Error<
   "the parameter for an explicitly-defaulted copy assignment operator must be 
an "
   "lvalue reference type">;
 def err_incorrect_defaulted_constexpr : Error<
-  "defaulted definition of %sub{select_special_member_kind}0 "
-  "is not constexpr">;
+  "defaulted definition of %sub{select_special_member_kind}0 cannot be marked 
%select{constexpr|consteval}1 "
+  "before C++23">;
 def err_incorrect_defaulted_constexpr_with_vb: Error<
   "%sub{select_special_member_kind}0 cannot be 'constexpr' in a class with 
virtual base class">;
-def err_incorrect_defaulted_consteval : Error<
-  "defaulted declaration of %sub{select_special_member_kind}0 "
-  "cannot be consteval because implicit definition is not constexpr">;
 def warn_defaulted_method_deleted : Warning<
   "explicitly defaulted %sub{select_special_member_kind}0 is implicitly "
   "deleted">, InGroup;
@@ -9734,21 +9731,12 @@ def 
note_defaulted_comparison_cannot_deduce_undeduced_auto : Note<
   "%select{|member|base class}0 %1 declared here">;
 def note_defaulted_comparison_cannot_deduce_callee : Note<
   "selected 'operator<=>' for %select{|member|base class}0 %1 declared here">;
-def ext_defaulted_comparison_constexpr_mismatch : Extension<
+def err_defaulted_comparison_constexpr_mismatch : Error<
   "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
-  "three-way comparison operator}0 that is "
-  "declared %select{constexpr|consteval}2 but"
-  "%select{|for which the corresponding implicit 'operator==' }0 "
-  "invokes a non-constexpr comparison function is a C++23 extension">,
-  InGroup>;
-def warn_cxx23_compat_defaulted_comparison_constexpr_mismatch : Warning<
-  "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
-  "three-way comparison operator}0 that is "
-  "declared %select{constexpr|consteval}2 but"
-  "%select{|for which the corresponding implicit 'operator==' }0 "
-  "invokes a non-constexpr comparison function is inc

[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread Amy Huang via cfe-commits

amykhuang wrote:

Whoops, not very familiar with git pull requests, I guess. actually reapplying 
the commit now

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


[clang] Reapply "[Clang][C++23] Implement P2448R2 ..." (#85136) (PR #85145)

2024-03-13 Thread Amy Huang via cfe-commits

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


[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread Amy Huang via cfe-commits

amykhuang wrote:

I looked at this a bit and the change that increases the constexpr restrictions 
is that `ext_defaulted_comparison_constexpr_mismatch` (which was added in 
https://reviews.llvm.org/D146090) became 
`err_incorrect_defaulted_comparison_constexpr`?

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


[clang] [Clang][Driver] Expose `-fno-eliminate-unused-debug-types` to clang-cl (PR #95259)

2024-06-12 Thread Amy Huang via cfe-commits

https://github.com/amykhuang approved this pull request.

Looks reasonable to me. 

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


[clang] [Clang][Driver] Expose `-fno-eliminate-unused-debug-types` to clang-cl (PR #95259)

2024-06-17 Thread Amy Huang via cfe-commits

amykhuang wrote:

Yes, feel free to take over that part, thanks!

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


[clang] [llvm] Add __hlt intrinsic for Windows ARM. (PR #96578)

2024-07-08 Thread Amy Huang via cfe-commits

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


[clang] Allow passing creduce options through creduce-clang-crash.py (PR #92141)

2024-05-14 Thread Amy Huang via cfe-commits

https://github.com/amykhuang approved this pull request.

lgtm!

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


[clang] [MSVC, ARM64] Fix signature for __prefetch (PR #93235)

2024-05-23 Thread Amy Huang via cfe-commits

https://github.com/amykhuang approved this pull request.

Thanks for the fix

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


[clang] Enable unguarded availability diagnostic on instantiated template functions (PR #91699)

2024-06-06 Thread Amy Huang via cfe-commits

amykhuang wrote:

here's a reduced example of what we ran into in Chrome. I guess the attribute 
is being applied to a function that's passed to `f()`, and the warning points 
to the call in the definition of `f`. 

```
#define a(b) __attribute__((__availability__(android, introduced = b)))
#define c(b) (a(b), apply_to = function)

template  void f(callback cb) {
  cb();
}

#pragma clang attribute push c(29)
void test() {
  f([](){});
}
#pragma clang attribute pop
```

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


[clang] Enable unguarded availability diagnostic on instantiated template functions (PR #91699)

2024-06-06 Thread Amy Huang via cfe-commits

amykhuang wrote:

nevermind, that example is working as intended

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


[clang] [llvm] Add __hlt intrinsic for Windows ARM. (PR #96578)

2024-06-24 Thread Amy Huang via cfe-commits

https://github.com/amykhuang created 
https://github.com/llvm/llvm-project/pull/96578

None

>From 1b436900146e1a91efac95416077485571722517 Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Mon, 24 Jun 2024 16:55:08 -0700
Subject: [PATCH] Add __hlt intrinsic for Windows ARM.

---
 clang/include/clang/Basic/BuiltinsAArch64.def   |  1 +
 clang/lib/CodeGen/CGBuiltin.cpp |  5 +
 clang/lib/Headers/intrin.h  |  3 +++
 clang/test/CodeGen/arm64-microsoft-intrinsics.c |  7 +++
 llvm/include/llvm/IR/IntrinsicsAArch64.td   |  3 +++
 llvm/lib/Target/AArch64/AArch64InstrInfo.td |  3 ++-
 llvm/test/CodeGen/AArch64/arm64-hlt.ll  | 10 ++
 7 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/AArch64/arm64-hlt.ll

diff --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index 5f53c98167dfb..668c4296208de 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -291,6 +291,7 @@ TARGET_HEADER_BUILTIN(_CountOneBits, "UiUNi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES,
 TARGET_HEADER_BUILTIN(_CountOneBits64, "UiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(__prefetch, "vvC*", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__hlt, "iUi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
 
 #undef BUILTIN
 #undef LANGBUILTIN
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 08a89bd123d03..c646614333499 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -11475,6 +11475,11 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 return Builder.CreateCall(F, {Address, RW, Locality, Data});
   }
 
+  if (BuiltinID == AArch64::BI__hlt) {
+Function *F = CGM.getIntrinsic(Intrinsic::aarch64_hlt);
+return Builder.CreateCall(F, {EmitScalarExpr(E->getArg(0))});
+  }
+
   // Handle MSVC intrinsics before argument evaluation to prevent double
   // evaluation.
   if (std::optional MsvcIntId =
diff --git a/clang/lib/Headers/intrin.h b/clang/lib/Headers/intrin.h
index 1227f45d5432b..a8a3463a78494 100644
--- a/clang/lib/Headers/intrin.h
+++ b/clang/lib/Headers/intrin.h
@@ -397,7 +397,10 @@ unsigned int _CountLeadingSigns64(__int64);
 unsigned int _CountOneBits(unsigned long);
 unsigned int _CountOneBits64(unsigned __int64);
 
+int __hlt(unsigned int);
+
 void __cdecl __prefetch(const void *);
+
 #endif
 
 
/**\
diff --git a/clang/test/CodeGen/arm64-microsoft-intrinsics.c 
b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
index a354ed948ca5f..5d17cc1ca6162 100644
--- a/clang/test/CodeGen/arm64-microsoft-intrinsics.c
+++ b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
@@ -127,6 +127,13 @@ void check__break() {
 // CHECK-MSVC: call void @llvm.aarch64.break(i32 0)
 // CHECK-LINUX: error: call to undeclared function '__break'
 
+void check__hlt() {
+  __hlt(0);
+}
+
+// CHECK-MSVC: call void @llvm.aarch64.hlt(i32 0)
+// CHECK-LINUX: error: call to undeclared function '__hlt'
+
 unsigned __int64 check__getReg(void) {
   unsigned volatile __int64 reg;
   reg = __getReg(18);
diff --git a/llvm/include/llvm/IR/IntrinsicsAArch64.td 
b/llvm/include/llvm/IR/IntrinsicsAArch64.td
index 9a71aaa9f4434..d7c3189280de7 100644
--- a/llvm/include/llvm/IR/IntrinsicsAArch64.td
+++ b/llvm/include/llvm/IR/IntrinsicsAArch64.td
@@ -57,6 +57,7 @@ def int_aarch64_frint64x
 : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ], [ LLVMMatchType<0> ],
 [ IntrNoMem ]>;
 
+
 
//===--===//
 // HINT
 
@@ -65,6 +66,8 @@ def int_aarch64_hint : DefaultAttrsIntrinsic<[], 
[llvm_i32_ty]>;
 def int_aarch64_break : Intrinsic<[], [llvm_i32_ty],
 [IntrNoMem, IntrHasSideEffects, IntrNoReturn, IntrCold, 
ImmArg>]>;
 
+def int_aarch64_hlt : Intrinsic<[], [llvm_i32_ty],
+[IntrNoMem, IntrHasSideEffects, IntrNoReturn, IntrCold, 
ImmArg>]>;
 
 def int_aarch64_prefetch : Intrinsic<[],
 [llvm_ptr_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.td 
b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
index 91e5bc3caa102..f4434525afecc 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.td
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
@@ -3076,7 +3076,8 @@ def BRK   : ExceptionGeneration<0b001, 0b00, "brk",
 def DCPS1 : ExceptionGeneration<0b101, 0b01, "dcps1">;
 def DCPS2 : ExceptionGeneration<0b101, 0b10, "dcps2">;
 def DCPS3 : ExceptionGeneration<0b101, 0b11, "dcps3">, Requires<[HasEL3]>;
-def HLT   : ExceptionGeneration<0b010, 0b00, "hlt">;
+def HLT   : ExceptionGeneration<0b010, 0b00, "hlt",
+[(int_aarch64_hlt timm32_0_65535:$imm)]>;
 def HVC   : ExceptionGeneration<0b000, 0b10, "hvc">;
 def SMC   : ExceptionG

[clang] [llvm] Add __hlt intrinsic for Windows ARM. (PR #96578)

2024-06-24 Thread Amy Huang via cfe-commits

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


[clang] [llvm] Add __hlt intrinsic for Windows ARM. (PR #96578)

2024-06-26 Thread Amy Huang via cfe-commits

https://github.com/amykhuang updated 
https://github.com/llvm/llvm-project/pull/96578

>From 1b436900146e1a91efac95416077485571722517 Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Mon, 24 Jun 2024 16:55:08 -0700
Subject: [PATCH 1/2] Add __hlt intrinsic for Windows ARM.

---
 clang/include/clang/Basic/BuiltinsAArch64.def   |  1 +
 clang/lib/CodeGen/CGBuiltin.cpp |  5 +
 clang/lib/Headers/intrin.h  |  3 +++
 clang/test/CodeGen/arm64-microsoft-intrinsics.c |  7 +++
 llvm/include/llvm/IR/IntrinsicsAArch64.td   |  3 +++
 llvm/lib/Target/AArch64/AArch64InstrInfo.td |  3 ++-
 llvm/test/CodeGen/AArch64/arm64-hlt.ll  | 10 ++
 7 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/AArch64/arm64-hlt.ll

diff --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index 5f53c98167dfb..668c4296208de 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -291,6 +291,7 @@ TARGET_HEADER_BUILTIN(_CountOneBits, "UiUNi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES,
 TARGET_HEADER_BUILTIN(_CountOneBits64, "UiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(__prefetch, "vvC*", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__hlt, "iUi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
 
 #undef BUILTIN
 #undef LANGBUILTIN
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 08a89bd123d03..c646614333499 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -11475,6 +11475,11 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 return Builder.CreateCall(F, {Address, RW, Locality, Data});
   }
 
+  if (BuiltinID == AArch64::BI__hlt) {
+Function *F = CGM.getIntrinsic(Intrinsic::aarch64_hlt);
+return Builder.CreateCall(F, {EmitScalarExpr(E->getArg(0))});
+  }
+
   // Handle MSVC intrinsics before argument evaluation to prevent double
   // evaluation.
   if (std::optional MsvcIntId =
diff --git a/clang/lib/Headers/intrin.h b/clang/lib/Headers/intrin.h
index 1227f45d5432b..a8a3463a78494 100644
--- a/clang/lib/Headers/intrin.h
+++ b/clang/lib/Headers/intrin.h
@@ -397,7 +397,10 @@ unsigned int _CountLeadingSigns64(__int64);
 unsigned int _CountOneBits(unsigned long);
 unsigned int _CountOneBits64(unsigned __int64);
 
+int __hlt(unsigned int);
+
 void __cdecl __prefetch(const void *);
+
 #endif
 
 
/**\
diff --git a/clang/test/CodeGen/arm64-microsoft-intrinsics.c 
b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
index a354ed948ca5f..5d17cc1ca6162 100644
--- a/clang/test/CodeGen/arm64-microsoft-intrinsics.c
+++ b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
@@ -127,6 +127,13 @@ void check__break() {
 // CHECK-MSVC: call void @llvm.aarch64.break(i32 0)
 // CHECK-LINUX: error: call to undeclared function '__break'
 
+void check__hlt() {
+  __hlt(0);
+}
+
+// CHECK-MSVC: call void @llvm.aarch64.hlt(i32 0)
+// CHECK-LINUX: error: call to undeclared function '__hlt'
+
 unsigned __int64 check__getReg(void) {
   unsigned volatile __int64 reg;
   reg = __getReg(18);
diff --git a/llvm/include/llvm/IR/IntrinsicsAArch64.td 
b/llvm/include/llvm/IR/IntrinsicsAArch64.td
index 9a71aaa9f4434..d7c3189280de7 100644
--- a/llvm/include/llvm/IR/IntrinsicsAArch64.td
+++ b/llvm/include/llvm/IR/IntrinsicsAArch64.td
@@ -57,6 +57,7 @@ def int_aarch64_frint64x
 : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ], [ LLVMMatchType<0> ],
 [ IntrNoMem ]>;
 
+
 
//===--===//
 // HINT
 
@@ -65,6 +66,8 @@ def int_aarch64_hint : DefaultAttrsIntrinsic<[], 
[llvm_i32_ty]>;
 def int_aarch64_break : Intrinsic<[], [llvm_i32_ty],
 [IntrNoMem, IntrHasSideEffects, IntrNoReturn, IntrCold, 
ImmArg>]>;
 
+def int_aarch64_hlt : Intrinsic<[], [llvm_i32_ty],
+[IntrNoMem, IntrHasSideEffects, IntrNoReturn, IntrCold, 
ImmArg>]>;
 
 def int_aarch64_prefetch : Intrinsic<[],
 [llvm_ptr_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.td 
b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
index 91e5bc3caa102..f4434525afecc 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.td
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
@@ -3076,7 +3076,8 @@ def BRK   : ExceptionGeneration<0b001, 0b00, "brk",
 def DCPS1 : ExceptionGeneration<0b101, 0b01, "dcps1">;
 def DCPS2 : ExceptionGeneration<0b101, 0b10, "dcps2">;
 def DCPS3 : ExceptionGeneration<0b101, 0b11, "dcps3">, Requires<[HasEL3]>;
-def HLT   : ExceptionGeneration<0b010, 0b00, "hlt">;
+def HLT   : ExceptionGeneration<0b010, 0b00, "hlt",
+[(int_aarch64_hlt timm32_0_65535:$imm)]>;
 def HVC   : ExceptionGeneration<0b000, 0b10, "hvc">;
 def SMC   : ExceptionGen

[clang] [llvm] Add __hlt intrinsic for Windows ARM. (PR #96578)

2024-06-26 Thread Amy Huang via cfe-commits

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


[clang] [llvm] Add __hlt intrinsic for Windows ARM. (PR #96578)

2024-06-26 Thread Amy Huang via cfe-commits

https://github.com/amykhuang updated 
https://github.com/llvm/llvm-project/pull/96578

>From 1b436900146e1a91efac95416077485571722517 Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Mon, 24 Jun 2024 16:55:08 -0700
Subject: [PATCH 1/3] Add __hlt intrinsic for Windows ARM.

---
 clang/include/clang/Basic/BuiltinsAArch64.def   |  1 +
 clang/lib/CodeGen/CGBuiltin.cpp |  5 +
 clang/lib/Headers/intrin.h  |  3 +++
 clang/test/CodeGen/arm64-microsoft-intrinsics.c |  7 +++
 llvm/include/llvm/IR/IntrinsicsAArch64.td   |  3 +++
 llvm/lib/Target/AArch64/AArch64InstrInfo.td |  3 ++-
 llvm/test/CodeGen/AArch64/arm64-hlt.ll  | 10 ++
 7 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/AArch64/arm64-hlt.ll

diff --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index 5f53c98167dfb..668c4296208de 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -291,6 +291,7 @@ TARGET_HEADER_BUILTIN(_CountOneBits, "UiUNi", "nh", 
INTRIN_H, ALL_MS_LANGUAGES,
 TARGET_HEADER_BUILTIN(_CountOneBits64, "UiULLi", "nh", INTRIN_H, 
ALL_MS_LANGUAGES, "")
 
 TARGET_HEADER_BUILTIN(__prefetch, "vvC*", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__hlt, "iUi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
 
 #undef BUILTIN
 #undef LANGBUILTIN
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 08a89bd123d03..c646614333499 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -11475,6 +11475,11 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 return Builder.CreateCall(F, {Address, RW, Locality, Data});
   }
 
+  if (BuiltinID == AArch64::BI__hlt) {
+Function *F = CGM.getIntrinsic(Intrinsic::aarch64_hlt);
+return Builder.CreateCall(F, {EmitScalarExpr(E->getArg(0))});
+  }
+
   // Handle MSVC intrinsics before argument evaluation to prevent double
   // evaluation.
   if (std::optional MsvcIntId =
diff --git a/clang/lib/Headers/intrin.h b/clang/lib/Headers/intrin.h
index 1227f45d5432b..a8a3463a78494 100644
--- a/clang/lib/Headers/intrin.h
+++ b/clang/lib/Headers/intrin.h
@@ -397,7 +397,10 @@ unsigned int _CountLeadingSigns64(__int64);
 unsigned int _CountOneBits(unsigned long);
 unsigned int _CountOneBits64(unsigned __int64);
 
+int __hlt(unsigned int);
+
 void __cdecl __prefetch(const void *);
+
 #endif
 
 
/**\
diff --git a/clang/test/CodeGen/arm64-microsoft-intrinsics.c 
b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
index a354ed948ca5f..5d17cc1ca6162 100644
--- a/clang/test/CodeGen/arm64-microsoft-intrinsics.c
+++ b/clang/test/CodeGen/arm64-microsoft-intrinsics.c
@@ -127,6 +127,13 @@ void check__break() {
 // CHECK-MSVC: call void @llvm.aarch64.break(i32 0)
 // CHECK-LINUX: error: call to undeclared function '__break'
 
+void check__hlt() {
+  __hlt(0);
+}
+
+// CHECK-MSVC: call void @llvm.aarch64.hlt(i32 0)
+// CHECK-LINUX: error: call to undeclared function '__hlt'
+
 unsigned __int64 check__getReg(void) {
   unsigned volatile __int64 reg;
   reg = __getReg(18);
diff --git a/llvm/include/llvm/IR/IntrinsicsAArch64.td 
b/llvm/include/llvm/IR/IntrinsicsAArch64.td
index 9a71aaa9f4434..d7c3189280de7 100644
--- a/llvm/include/llvm/IR/IntrinsicsAArch64.td
+++ b/llvm/include/llvm/IR/IntrinsicsAArch64.td
@@ -57,6 +57,7 @@ def int_aarch64_frint64x
 : DefaultAttrsIntrinsic<[ llvm_anyfloat_ty ], [ LLVMMatchType<0> ],
 [ IntrNoMem ]>;
 
+
 
//===--===//
 // HINT
 
@@ -65,6 +66,8 @@ def int_aarch64_hint : DefaultAttrsIntrinsic<[], 
[llvm_i32_ty]>;
 def int_aarch64_break : Intrinsic<[], [llvm_i32_ty],
 [IntrNoMem, IntrHasSideEffects, IntrNoReturn, IntrCold, 
ImmArg>]>;
 
+def int_aarch64_hlt : Intrinsic<[], [llvm_i32_ty],
+[IntrNoMem, IntrHasSideEffects, IntrNoReturn, IntrCold, 
ImmArg>]>;
 
 def int_aarch64_prefetch : Intrinsic<[],
 [llvm_ptr_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.td 
b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
index 91e5bc3caa102..f4434525afecc 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.td
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
@@ -3076,7 +3076,8 @@ def BRK   : ExceptionGeneration<0b001, 0b00, "brk",
 def DCPS1 : ExceptionGeneration<0b101, 0b01, "dcps1">;
 def DCPS2 : ExceptionGeneration<0b101, 0b10, "dcps2">;
 def DCPS3 : ExceptionGeneration<0b101, 0b11, "dcps3">, Requires<[HasEL3]>;
-def HLT   : ExceptionGeneration<0b010, 0b00, "hlt">;
+def HLT   : ExceptionGeneration<0b010, 0b00, "hlt",
+[(int_aarch64_hlt timm32_0_65535:$imm)]>;
 def HVC   : ExceptionGeneration<0b000, 0b10, "hvc">;
 def SMC   : ExceptionGen

[clang] fda44be - Add Clang driver flags equivalent to cl's /MD, /MT, /MDd, /MTd.

2022-09-15 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2022-09-15T17:45:41Z
New Revision: fda44bedd64dbcde1b54432d99ad2f0fca0ad204

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

LOG: Add Clang driver flags equivalent to cl's /MD, /MT, /MDd, /MTd.

This will allow selecting the MS C runtime library without having to use
cc1 flags.

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/cl-runtime-flags.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8383aeb2f1c68..2e0f4c9452d65 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2211,6 +2211,14 @@ def fms_compatibility_version
   HelpText<"Dot-separated value representing the Microsoft compiler "
"version number to report in _MSC_VER (0 = don't define it "
"(default))">;
+def fms_runtime_lib_EQ : Joined<["-"], "fms-runtime-lib=">, Group,
+  Flags<[NoXarchOption, CoreOption]>, Values<"static,static_dbg,dll,dll_dbg">,
+  HelpText<"Select Windows run-time library">,
+  DocBrief<[{
+Specify Visual Studio C runtime library. "static" and "static_dbg" correspond
+to the cl flags /MT and /MTd which use the multithread, static version. "dll"
+and "dll_dbg" correspond to the cl flags /MD and /MDd which use the 
multithread,
+dll version.}]>;
 defm delayed_template_parsing : BoolFOption<"delayed-template-parsing",
   LangOpts<"DelayedTemplateParsing">, DefaultFalse,
   PosFlag,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 689dedbe49df8..9737a0ef33f80 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4437,6 +4437,71 @@ static void renderDebugOptions(const ToolChain &TC, 
const Driver &D,
   RenderDebugInfoCompressionArgs(Args, CmdArgs, D, TC);
 }
 
+static void ProcessVSRuntimeLibrary(const ArgList &Args,
+ArgStringList &CmdArgs) {
+  unsigned RTOptionID = options::OPT__SLASH_MT;
+
+  if (Args.hasArg(options::OPT__SLASH_LDd))
+// The /LDd option implies /MTd. The dependent lib part can be overridden,
+// but defining _DEBUG is sticky.
+RTOptionID = options::OPT__SLASH_MTd;
+
+  if (Arg *A = Args.getLastArg(options::OPT__SLASH_M_Group))
+RTOptionID = A->getOption().getID();
+
+  if (Arg *A = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
+RTOptionID = llvm::StringSwitch(A->getValue())
+ .Case("static", options::OPT__SLASH_MT)
+ .Case("static_dbg", options::OPT__SLASH_MTd)
+ .Case("dll", options::OPT__SLASH_MD)
+ .Case("dll_dbg", options::OPT__SLASH_MDd)
+ .Default(options::OPT__SLASH_MT);
+  }
+
+  StringRef FlagForCRT;
+  switch (RTOptionID) {
+  case options::OPT__SLASH_MD:
+if (Args.hasArg(options::OPT__SLASH_LDd))
+  CmdArgs.push_back("-D_DEBUG");
+CmdArgs.push_back("-D_MT");
+CmdArgs.push_back("-D_DLL");
+FlagForCRT = "--dependent-lib=msvcrt";
+break;
+  case options::OPT__SLASH_MDd:
+CmdArgs.push_back("-D_DEBUG");
+CmdArgs.push_back("-D_MT");
+CmdArgs.push_back("-D_DLL");
+FlagForCRT = "--dependent-lib=msvcrtd";
+break;
+  case options::OPT__SLASH_MT:
+if (Args.hasArg(options::OPT__SLASH_LDd))
+  CmdArgs.push_back("-D_DEBUG");
+CmdArgs.push_back("-D_MT");
+CmdArgs.push_back("-flto-visibility-public-std");
+FlagForCRT = "--dependent-lib=libcmt";
+break;
+  case options::OPT__SLASH_MTd:
+CmdArgs.push_back("-D_DEBUG");
+CmdArgs.push_back("-D_MT");
+CmdArgs.push_back("-flto-visibility-public-std");
+FlagForCRT = "--dependent-lib=libcmtd";
+break;
+  default:
+llvm_unreachable("Unexpected option ID.");
+  }
+
+  if (Args.hasArg(options::OPT__SLASH_Zl)) {
+CmdArgs.push_back("-D_VC_NODEFAULTLIB");
+  } else {
+CmdArgs.push_back(FlagForCRT.data());
+
+// This provides POSIX compatibility (maps 'open' to '_open'), which most
+// users want.  The /Za flag to cl.exe turns this off, but it's not
+// implemented in clang.
+CmdArgs.push_back("--dependent-lib=oldnames");
+  }
+}
+
 void Clang::ConstructJob(Compilation &C, const JobAction &JA,
  const InputInfo &Output, const InputInfoList &Inputs,
  const ArgList &Args, const char *LinkingOutput) const 
{
@@ -6478,6 +6543,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (IsMSVCCompat)
 CmdArgs.push_back("-fms-compatibility");
 
+  if (Triple.isWindowsMSVCEnvironment() && !D.IsCLMode())
+ProcessVSRuntimeL

  1   2   >