[llvm-branch-commits] [clang] 082b2fc - strict-dwarf in backend

2021-04-26 Thread Chen Zheng via llvm-branch-commits

Author: Chen Zheng
Date: 2021-04-22T21:28:07-04:00
New Revision: 082b2fc0e5a78bd45840c1faa392354ff856de11

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

LOG: strict-dwarf in backend

Added: 
llvm/test/DebugInfo/PowerPC/strict-dwarf.ll

Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/CodeGen/CommandFlags.h
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/CommandFlags.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7edca6fb30730..a499877bb2a98 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -598,6 +598,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   Entry.IgnoreSysRoot ? Entry.Path : HSOpts.Sysroot + Entry.Path);
   Options.MCOptions.Argv0 = CodeGenOpts.Argv0;
   Options.MCOptions.CommandLineArgs = CodeGenOpts.CommandLineArgs;
+  Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
 
   return true;
 }

diff  --git a/llvm/include/llvm/CodeGen/CommandFlags.h 
b/llvm/include/llvm/CodeGen/CommandFlags.h
index e18ee36445363..072df9dce1ee2 100644
--- a/llvm/include/llvm/CodeGen/CommandFlags.h
+++ b/llvm/include/llvm/CodeGen/CommandFlags.h
@@ -140,6 +140,8 @@ bool getForceDwarfFrameSection();
 
 bool getXRayOmitFunctionIndex();
 
+bool getDebugStrictDwarf();
+
 /// Create this object with static storage to register codegen-related command
 /// line options.
 struct RegisterCodeGenFlags {

diff  --git a/llvm/include/llvm/Target/TargetOptions.h 
b/llvm/include/llvm/Target/TargetOptions.h
index 651dbe163a811..fd82afed14b38 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -141,6 +141,7 @@ namespace llvm {
   SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
   PseudoProbeForProfiling(false), 
ValueTrackingVariableLocations(false),
   ForceDwarfFrameSection(false), XRayOmitFunctionIndex(false),
+  DebugStrictDwarf(false),
   FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {}
 
 /// DisableFramePointerElim - This returns true if frame pointer 
elimination
@@ -331,6 +332,10 @@ namespace llvm {
 /// Emit XRay Function Index section
 unsigned XRayOmitFunctionIndex : 1;
 
+/// When set to true, don't use DWARF extensions in later DWARF versions.
+/// By default, it is set to false.
+unsigned DebugStrictDwarf : 1;
+
 /// Stack protector guard offset to use.
 unsigned StackProtectorGuardOffset = -1U;
 

diff  --git a/llvm/lib/CodeGen/CommandFlags.cpp 
b/llvm/lib/CodeGen/CommandFlags.cpp
index de560559b6fe0..a0c748fdf2de7 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -97,6 +97,7 @@ CGOPT(bool, PseudoProbeForProfiling)
 CGOPT(bool, ValueTrackingVariableLocations)
 CGOPT(bool, ForceDwarfFrameSection)
 CGOPT(bool, XRayOmitFunctionIndex)
+CGOPT(bool, DebugStrictDwarf)
 
 codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
 #define CGBINDOPT(NAME)
\
@@ -471,6 +472,10 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
   cl::init(false));
   CGBINDOPT(XRayOmitFunctionIndex);
 
+  static cl::opt DebugStrictDwarf(
+  "strict-dwarf", cl::desc("use strict dwarf"), cl::init(false));
+  CGBINDOPT(DebugStrictDwarf);
+
 #undef CGBINDOPT
 
   mc::RegisterMCTargetOptionsFlags();
@@ -567,6 +572,7 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple 
&TheTriple) {
   Options.ValueTrackingVariableLocations = getValueTrackingVariableLocations();
   Options.ForceDwarfFrameSection = getForceDwarfFrameSection();
   Options.XRayOmitFunctionIndex = getXRayOmitFunctionIndex();
+  Options.DebugStrictDwarf = getDebugStrictDwarf();
 
   Options.MCOptions = mc::InitMCTargetOptionsFromFlags();
 

diff  --git a/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll 
b/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll
new file mode 100644
index 0..b64fd426e8eab
--- /dev/null
+++ b/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll
@@ -0,0 +1,60 @@
+; RUN: llc -filetype=obj -mtriple=powerpc64le-unknown-linux-gnu < %s | \
+; RUN:   llvm-dwarfdump -debug-info - | FileCheck %s
+; RUN: llc -filetype=obj -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:   -strict-dwarf=true < %s | llvm-dwarfdump -debug-info - | \
+; RUN:   FileCheck %s
+
+; FIXME: when -strict-dwarf=true is specified, we should check "STRICT" to tell
+; that with DWARF 4, we should not generate DWARF 5 attribute DW_AT_noreturn 
and
+; DW_AT_alignment.
+
+; CHECK: DW_AT_alignment
+; CHECK: DW_AT_noreturn
+; STRICT-NOT: DW_AT_noreturn
+; STRICT-NOT: DW_AT_alignment
+
+@_ZL3var = internal global i32 0, align 16, !dbg !0
+
+; Function Attrs: noinline

[llvm-branch-commits] [llvm] 681d9ec - [Debug-Info] change return type to void for attribute adding functions.

2021-04-26 Thread Chen Zheng via llvm-branch-commits

Author: Chen Zheng
Date: 2021-04-22T21:30:22-04:00
New Revision: 681d9ecd727bf5835098a4e5d5a49f823670a6b5

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

LOG: [Debug-Info] change return type to void for attribute adding functions.

Added: 


Modified: 
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h

Removed: 




diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp 
b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 7a28bcb08ba42..40d290ebe47fa 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -286,11 +286,9 @@ void DwarfUnit::addString(DIE &Die, dwarf::Attribute 
Attribute,
DIEString(StringPoolEntry));
 }
 
-DIEValueList::value_iterator DwarfUnit::addLabel(DIEValueList &Die,
- dwarf::Attribute Attribute,
- dwarf::Form Form,
- const MCSymbol *Label) {
-  return Die.addValue(DIEValueAllocator, Attribute, Form, DIELabel(Label));
+void DwarfUnit::addLabel(DIEValueList &Die, dwarf::Attribute Attribute,
+ dwarf::Form Form, const MCSymbol *Label) {
+  Die.addValue(DIEValueAllocator, Attribute, Form, DIELabel(Label));
 }
 
 void DwarfUnit::addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label) 
{
@@ -1746,20 +1744,18 @@ void DwarfTypeUnit::emitHeader(bool UseOffsets) {
   Asm->emitDwarfLengthOrOffset(Ty ? Ty->getOffset() : 0);
 }
 
-DIE::value_iterator
-DwarfUnit::addSectionDelta(DIE &Die, dwarf::Attribute Attribute,
-   const MCSymbol *Hi, const MCSymbol *Lo) {
-  return Die.addValue(DIEValueAllocator, Attribute,
-  DD->getDwarfSectionOffsetForm(),
-  new (DIEValueAllocator) DIEDelta(Hi, Lo));
+void DwarfUnit::addSectionDelta(DIE &Die, dwarf::Attribute Attribute,
+const MCSymbol *Hi, const MCSymbol *Lo) {
+  Die.addValue(DIEValueAllocator, Attribute, DD->getDwarfSectionOffsetForm(),
+   new (DIEValueAllocator) DIEDelta(Hi, Lo));
 }
 
-DIE::value_iterator
-DwarfUnit::addSectionLabel(DIE &Die, dwarf::Attribute Attribute,
-   const MCSymbol *Label, const MCSymbol *Sec) {
+void DwarfUnit::addSectionLabel(DIE &Die, dwarf::Attribute Attribute,
+const MCSymbol *Label, const MCSymbol *Sec) {
   if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
-return addLabel(Die, Attribute, DD->getDwarfSectionOffsetForm(), Label);
-  return addSectionDelta(Die, Attribute, Label, Sec);
+addLabel(Die, Attribute, DD->getDwarfSectionOffsetForm(), Label);
+  else
+addSectionDelta(Die, Attribute, Label, Sec);
 }
 
 bool DwarfTypeUnit::isDwoUnit() const {

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h 
b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
index a1d6008251796..10fd725cb8ae7 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -147,10 +147,8 @@ class DwarfUnit : public DIEUnit {
   void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str);
 
   /// Add a Dwarf label attribute data and value.
-  DIEValueList::value_iterator addLabel(DIEValueList &Die,
-dwarf::Attribute Attribute,
-dwarf::Form Form,
-const MCSymbol *Label);
+  void addLabel(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form 
Form,
+const MCSymbol *Label);
 
   void addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label);
 
@@ -272,13 +270,12 @@ class DwarfUnit : public DIEUnit {
   void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy);
 
   /// addSectionDelta - Add a label delta attribute data and value.
-  DIE::value_iterator addSectionDelta(DIE &Die, dwarf::Attribute Attribute,
-  const MCSymbol *Hi, const MCSymbol *Lo);
+  void addSectionDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol 
*Hi,
+   const MCSymbol *Lo);
 
   /// Add a Dwarf section label attribute data and value.
-  DIE::value_iterator addSectionLabel(DIE &Die, dwarf::Attribute Attribute,
-  const MCSymbol *Label,
-  const MCSymbol *Sec);
+  void addSectionLabel(DIE &Die, dwarf::Attribute Attribute,
+   const MCSymbol *Label, const MCSymbol *Sec);
 
   /// Get context owner's DIE.
   DIE *createTypeDIE(const DICompositeType *Ty);



___
llvm-branch-commits mailing list
llvm-branch-commit

[llvm-branch-commits] [llvm] b12067b - [Debug-Info] add a wrapper addAttribute for addValue()

2021-04-26 Thread Chen Zheng via llvm-branch-commits

Author: Chen Zheng
Date: 2021-04-22T22:55:30-04:00
New Revision: b12067bad7c30c33caf2dd168c126be3303be634

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

LOG: [Debug-Info] add a wrapper addAttribute for addValue()

Added: 


Modified: 
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h

Removed: 




diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp 
b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index ac7a316398441..faa14dca1c3f1 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -83,7 +83,7 @@ void DwarfCompileUnit::addLabelAddress(DIE &Die, 
dwarf::Attribute Attribute,
 
   if (!Base || Base == Label) {
 unsigned idx = DD->getAddressPool().getIndex(Label);
-Die.addValue(DIEValueAllocator, Attribute,
+addAttribute(Die, Attribute,
  DD->getDwarfVersion() >= 5 ? dwarf::DW_FORM_addrx
 : dwarf::DW_FORM_GNU_addr_index,
  DIEInteger(idx));
@@ -100,7 +100,7 @@ void DwarfCompileUnit::addLabelAddress(DIE &Die, 
dwarf::Attribute Attribute,
 addPoolOpAddress(*Loc, Label);
 addBlock(Die, Attribute, dwarf::DW_FORM_exprloc, Loc);
   } else
-Die.addValue(DIEValueAllocator, Attribute, 
dwarf::DW_FORM_LLVM_addrx_offset,
+addAttribute(Die, Attribute, dwarf::DW_FORM_LLVM_addrx_offset,
  new (DIEValueAllocator) DIEAddrOffset(
  DD->getAddressPool().getIndex(Base), Label, Base));
 }
@@ -112,11 +112,9 @@ void DwarfCompileUnit::addLocalLabelAddress(DIE &Die,
 DD->addArangeLabel(SymbolCU(this, Label));
 
   if (Label)
-Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr,
- DIELabel(Label));
+addAttribute(Die, Attribute, dwarf::DW_FORM_addr, DIELabel(Label));
   else
-Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr,
- DIEInteger(0));
+addAttribute(Die, Attribute, dwarf::DW_FORM_addr, DIEInteger(0));
 }
 
 unsigned DwarfCompileUnit::getOrCreateSourceID(const DIFile *File) {
@@ -1472,7 +1470,7 @@ void DwarfCompileUnit::addLocationList(DIE &Die, 
dwarf::Attribute Attribute,
   dwarf::Form Form = (DD->getDwarfVersion() >= 5)
  ? dwarf::DW_FORM_loclistx
  : DD->getDwarfSectionOffsetForm();
-  Die.addValue(DIEValueAllocator, Attribute, Form, DIELocList(Index));
+  addAttribute(Die, Attribute, Form, DIELocList(Index));
 }
 
 void DwarfCompileUnit::applyVariableAttributes(const DbgVariable &Var,
@@ -1504,7 +1502,7 @@ void DwarfCompileUnit::applyLabelAttributes(const 
DbgLabel &Label,
 /// Add a Dwarf expression attribute data and value.
 void DwarfCompileUnit::addExpr(DIELoc &Die, dwarf::Form Form,
const MCExpr *Expr) {
-  Die.addValue(DIEValueAllocator, (dwarf::Attribute)0, Form, DIEExpr(Expr));
+  addAttribute(Die, (dwarf::Attribute)0, Form, DIEExpr(Expr));
 }
 
 void DwarfCompileUnit::applySubprogramAttributesToDefinition(
@@ -1538,7 +1536,7 @@ void DwarfCompileUnit::addAddrTableBase() {
 }
 
 void DwarfCompileUnit::addBaseTypeRef(DIEValueList &Die, int64_t Idx) {
-  Die.addValue(DIEValueAllocator, (dwarf::Attribute)0, dwarf::DW_FORM_udata,
+  addAttribute(Die, (dwarf::Attribute)0, dwarf::DW_FORM_udata,
new (DIEValueAllocator) DIEBaseTypeRef(this, Idx));
 }
 

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp 
b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 40d290ebe47fa..2b171ae3b6e84 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -219,11 +219,9 @@ void DwarfUnit::insertDIE(DIE *D) {
 
 void DwarfUnit::addFlag(DIE &Die, dwarf::Attribute Attribute) {
   if (DD->getDwarfVersion() >= 4)
-Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_flag_present,
- DIEInteger(1));
+addAttribute(Die, Attribute, dwarf::DW_FORM_flag_present, DIEInteger(1));
   else
-Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_flag,
- DIEInteger(1));
+addAttribute(Die, Attribute, dwarf::DW_FORM_flag, DIEInteger(1));
 }
 
 void DwarfUnit::addUInt(DIEValueList &Die, dwarf::Attribute Attribute,
@@ -232,7 +230,7 @@ void DwarfUnit::addUInt(DIEValueList &Die, dwarf::Attribute 
Attribute,
 Form = DIEInteger::BestForm(false, Integer);
   assert(Form != dwarf::DW_FORM_implicit_const &&
  "DW_FORM_implicit_const is used only for signed integers");
-  Die.addValue(DIEValueAllocator, Attribute, *Form, DIEInteger(Integer));
+  addAttribute(Die, Attribute, *Form, DIEInteger(Integer));
 }
 
 void DwarfUnit::addUInt(DIEValueList 

[llvm-branch-commits] [llvm] e91eb89 - [Debug-Info] guard attribute generating under strict dwarf.

2021-04-26 Thread Chen Zheng via llvm-branch-commits

Author: Chen Zheng
Date: 2021-04-24T21:34:42-04:00
New Revision: e91eb89cc97d077c8bbae2c28749304d005511cd

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

LOG: [Debug-Info] guard attribute generating under strict dwarf.

Conflicts:
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h

Added: 


Modified: 
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
llvm/test/DebugInfo/PowerPC/strict-dwarf.ll

Removed: 




diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h 
b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
index aca831a535a19..3a961ab47f6df 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/CodeGen/DIE.h"
+#include "llvm/Target/TargetMachine.h"
 #include 
 
 namespace llvm {
@@ -79,6 +80,12 @@ class DwarfUnit : public DIEUnit {
   template 
   void addAttribute(DIEValueList &Die, dwarf::Attribute Attribute,
 dwarf::Form Form, T &&Value) {
+// For strict DWARF mode, only generate attributes available to current
+// DWARF version.
+if (Attribute != 0 && Asm->TM.Options.DebugStrictDwarf &&
+DD->getDwarfVersion() < dwarf::AttributeVersion(Attribute))
+  return;
+
 Die.addValue(DIEValueAllocator,
  DIEValue(Attribute, Form, std::forward(Value)));
   }

diff  --git a/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll 
b/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll
index b64fd426e8eab..27fbfdbcedf42 100644
--- a/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll
+++ b/llvm/test/DebugInfo/PowerPC/strict-dwarf.ll
@@ -2,16 +2,25 @@
 ; RUN:   llvm-dwarfdump -debug-info - | FileCheck %s
 ; RUN: llc -filetype=obj -mtriple=powerpc64le-unknown-linux-gnu \
 ; RUN:   -strict-dwarf=true < %s | llvm-dwarfdump -debug-info - | \
-; RUN:   FileCheck %s
+; RUN:   FileCheck %s -check-prefix=STRICT
 
-; FIXME: when -strict-dwarf=true is specified, we should check "STRICT" to tell
-; that with DWARF 4, we should not generate DWARF 5 attribute DW_AT_noreturn 
and
-; DW_AT_alignment.
+; We also check that with/without -strict-dwarf=true, the location attribute
+; is not changed. The location attribute adding will call DwarfUnit::addUInt()
+; which contains a attribute 0, we want to make sure the strict-dwarf handling
+; is also right for attribute 0.
+; For this case, the location attribute adding is for global variable @_ZL3var
+; and the call chain to addUInt() is:
+; 1: DwarfCompileUnit::addLocationAttribute()
+; 2: DwarfUnit::addOpAddress()
+; 3: DwarfUnit::addUInt()
+; 4: addUInt(Block, (dwarf::Attribute)0, Form, Integer);
 
 ; CHECK: DW_AT_alignment
+; CHECK: DW_AT_location  (DW_OP_addr 0x0)
 ; CHECK: DW_AT_noreturn
 ; STRICT-NOT: DW_AT_noreturn
 ; STRICT-NOT: DW_AT_alignment
+; STRICT: DW_AT_location  (DW_OP_addr 0x0)
 
 @_ZL3var = internal global i32 0, align 16, !dbg !0
 



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


[llvm-branch-commits] [clang] 72cc3f7 - DW_TAG_Rvalue_reference

2021-04-26 Thread Chen Zheng via llvm-branch-commits

Author: Chen Zheng
Date: 2021-04-24T21:41:22-04:00
New Revision: 72cc3f7159b695f1928b82a4f29935db6eb62b42

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

LOG: DW_TAG_Rvalue_reference

Added: 


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

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 290cdbf8c4e34..1aa48034da69f 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2989,8 +2989,14 @@ llvm::DIType *CGDebugInfo::CreateType(const 
LValueReferenceType *Ty,
 
 llvm::DIType *CGDebugInfo::CreateType(const RValueReferenceType *Ty,
   llvm::DIFile *Unit) {
-  return CreatePointerLikeType(llvm::dwarf::DW_TAG_rvalue_reference_type, Ty,
-   Ty->getPointeeType(), Unit);
+  llvm::dwarf::Tag Tag = llvm::dwarf::DW_TAG_rvalue_reference_type;
+  // DW_TAG_rvalue_reference_type was introduced in DWARF 4, in strict DWARF
+  // mode, only generate it when DWARF version is no smaller than 4.
+  if (CGM.getCodeGenOpts().DebugStrictDwarf &&
+  CGM.getCodeGenOpts().DwarfVersion < 4)
+Tag = llvm::dwarf::DW_TAG_reference_type;
+
+  return CreatePointerLikeType(Tag, Ty, Ty->getPointeeType(), Unit);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const MemberPointerType *Ty,

diff  --git a/clang/test/CodeGenCXX/debug-info-rvalue-ref.cpp 
b/clang/test/CodeGenCXX/debug-info-rvalue-ref.cpp
index de0f65ad9a029..45b19705fae2f 100644
--- a/clang/test/CodeGenCXX/debug-info-rvalue-ref.cpp
+++ b/clang/test/CodeGenCXX/debug-info-rvalue-ref.cpp
@@ -1,4 +1,8 @@
 // RUN: %clang_cc1 -std=c++11 -emit-llvm -debug-info-kind=limited -triple 
x86_64-apple-darwin %s -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -gstrict-dwarf -dwarf-version=4 -emit-llvm 
-debug-info-kind=limited \
+// RUN:   -triple x86_64-apple-darwin %s -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -gstrict-dwarf -dwarf-version=3 -emit-llvm 
-debug-info-kind=limited \
+// RUN:   -triple x86_64-apple-darwin %s -o - | FileCheck %s 
--check-prefix=NORVALUE
 
 extern "C" {
 extern int printf(const char * format, ...);
@@ -10,3 +14,4 @@ void foo (int &&i)
 
 // CHECK: !DIDerivedType(tag: DW_TAG_rvalue_reference_type, baseType: 
![[INT:[0-9]+]], size: 64)
 // CHECK: ![[INT]] = !DIBasicType(name: "int"
+// NORVALUE: !DIDerivedType(tag: DW_TAG_reference_type, baseType: 
![[INT:[0-9]+]], size: 64)



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


[llvm-branch-commits] [llvm] b92a912 - DW_OP_stack_value

2021-04-26 Thread Chen Zheng via llvm-branch-commits

Author: Chen Zheng
Date: 2021-04-25T02:59:49-04:00
New Revision: b92a9126259f0e9adeb589d54358d095477e9a35

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

LOG: DW_OP_stack_value

Added: 
llvm/test/DebugInfo/PowerPC/strict-dwarf-op-stack-value.ll

Modified: 
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Removed: 




diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp 
b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 2b171ae3b6e84..99722e7921284 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1020,6 +1020,11 @@ void DwarfUnit::constructTemplateValueParameterDIE(
 if (ConstantInt *CI = mdconst::dyn_extract(Val))
   addConstantValue(ParamDIE, CI, VP->getType());
 else if (GlobalValue *GV = mdconst::dyn_extract(Val)) {
+  // We need DW_OP_stack_value to represent the value of the global value.
+  // DW_OP_stack_value was introduced in DWARF 4, in strict dwarf mode, we
+  // should not use this expression if DWARF version is smaller than 4.
+  if (Asm->TM.Options.DebugStrictDwarf && DD->getDwarfVersion() < 4)
+return;
   // We cannot describe the location of dllimport'd entities: the
   // computation of their address requires loads from the IAT.
   if (!GV->hasDLLImportStorageClass()) {

diff  --git a/llvm/test/DebugInfo/PowerPC/strict-dwarf-op-stack-value.ll 
b/llvm/test/DebugInfo/PowerPC/strict-dwarf-op-stack-value.ll
new file mode 100644
index 0..e60efde6cf458
--- /dev/null
+++ b/llvm/test/DebugInfo/PowerPC/strict-dwarf-op-stack-value.ll
@@ -0,0 +1,100 @@
+; RUN: llc -filetype=obj -mtriple=powerpc64le-unknown-linux-gnu < %s | \
+; RUN:   llvm-dwarfdump -debug-info - | FileCheck %s
+; RUN: llc -filetype=obj -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN:   -strict-dwarf=true < %s | llvm-dwarfdump -debug-info - | \
+; RUN:   FileCheck %s -check-prefix=STRICT
+
+; check that DWARF 4 location expression DW_OP_stack_value is not emitted in
+; DWARF 3 at strict dwarf mode.
+
+; CHECK: DW_AT_location (DW_OP_addr 0x0, DW_OP_stack_value)
+; STRICT-NOT: DW_OP_stack_value
+
+; $ cat 1.cpp
+; extern bool cmp();
+;
+; typedef bool comparator_function();
+; template
+; void quicksort(Iterator begin, Iterator end)
+; {
+; }
+; void foo(void)
+; {
+;   double a[100];
+;   quicksort(a, a + 100);
+; }
+
+
+$_Z9quicksortIPdXadL_Z3cmpvEEEvT_S1_ = comdat any
+
+; Function Attrs: noinline optnone uwtable mustprogress
+define dso_local void @_Z3foov() #0 !dbg !8 {
+entry:
+  %a = alloca [100 x double], align 8
+  call void @llvm.dbg.declare(metadata [100 x double]* %a, metadata !11, 
metadata !DIExpression()), !dbg !16
+  %arraydecay = getelementptr inbounds [100 x double], [100 x double]* %a, i64 
0, i64 0, !dbg !17
+  %arraydecay1 = getelementptr inbounds [100 x double], [100 x double]* %a, 
i64 0, i64 0, !dbg !18
+  %add.ptr = getelementptr inbounds double, double* %arraydecay1, i64 100, 
!dbg !19
+  call void @_Z9quicksortIPdXadL_Z3cmpvEEEvT_S1_(double* %arraydecay, double* 
%add.ptr), !dbg !20
+  ret void, !dbg !21
+}
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+; Function Attrs: noinline nounwind optnone uwtable mustprogress
+define linkonce_odr dso_local void 
@_Z9quicksortIPdXadL_Z3cmpvEEEvT_S1_(double* %begin, double* %end) #2 comdat 
!dbg !22 {
+entry:
+  %begin.addr = alloca double*, align 8
+  %end.addr = alloca double*, align 8
+  store double* %begin, double** %begin.addr, align 8
+  call void @llvm.dbg.declare(metadata double** %begin.addr, metadata !33, 
metadata !DIExpression()), !dbg !34
+  store double* %end, double** %end.addr, align 8
+  call void @llvm.dbg.declare(metadata double** %end.addr, metadata !35, 
metadata !DIExpression()), !dbg !36
+  ret void, !dbg !37
+}
+
+declare zeroext i1 @_Z3cmpv() #3
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5, !6}
+!llvm.ident = !{!7}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, 
producer: "clang version 13.0.0", isOptimized: false, runtimeVersion: 0, 
emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: 
None)
+!1 = !DIFile(filename: "1.cpp", directory: "./")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 3}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{i32 7, !"uwtable", i32 1}
+!7 = !{!"clang version 13.0.0"}
+!8 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, 
file: !1, line: 9, type: !9, scopeLine: 10, flags: DIFlagPrototyped, spFlags: 
DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!9 = !DISubroutineType(types: !10)
+!10 = !{null}
+!11 = !DILocalVariable(name: "a", scope: !8, file:

[llvm-branch-commits] [llvm] 93a3592 - file name - directory info

2021-04-26 Thread Chen Zheng via llvm-branch-commits

Author: Chen Zheng
Date: 2021-04-26T01:31:23-04:00
New Revision: 93a3592728ac1b55a7dd2a1d6abeeb8f9a54e2b6

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

LOG: file name - directory info

Added: 
llvm/test/CodeGen/PowerPC/aix-filename-absolute-path.ll
llvm/test/CodeGen/PowerPC/aix-filename-relative-path.ll

Modified: 
llvm/include/llvm/MC/MCAsmInfo.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/MC/MCAsmInfoXCOFF.cpp

Removed: 




diff  --git a/llvm/include/llvm/MC/MCAsmInfo.h 
b/llvm/include/llvm/MC/MCAsmInfo.h
index 250d219d100e4..b674af072ed55 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -341,6 +341,10 @@ class MCAsmInfo {
   /// argument and how it is interpreted.  Defaults to NoAlignment.
   LCOMM::LCOMMType LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
 
+  /// True if the target only has basename for .file directive. False if the
+  /// target also needs the directory along with the basename. Default to true.
+  bool HasBasenameOnlyForFileDirective = true;
+
   // True if the target allows .align directives on functions. This is true for
   // most targets, so defaults to true.
   bool HasFunctionAlignment = true;
@@ -666,6 +670,9 @@ class MCAsmInfo {
 return LCOMMDirectiveAlignmentType;
   }
 
+  bool hasBasenameOnlyForFileDirective() const {
+return HasBasenameOnlyForFileDirective;
+  }
   bool hasFunctionAlignment() const { return HasFunctionAlignment; }
   bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; 
}
   bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }

diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index eb7c7e2797d4e..869d83abd47dc 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -297,8 +297,11 @@ bool AsmPrinter::doInitialization(Module &M) {
   // don't, this at least helps the user find where a global came from.
   if (MAI->hasSingleParameterDotFile()) {
 // .file "foo.c"
-OutStreamer->emitFileDirective(
-llvm::sys::path::filename(M.getSourceFileName()));
+if (MAI->hasBasenameOnlyForFileDirective())
+  OutStreamer->emitFileDirective(
+  llvm::sys::path::filename(M.getSourceFileName()));
+else
+  OutStreamer->emitFileDirective(M.getSourceFileName());
   }
 
   GCModuleInfo *MI = getAnalysisIfAvailable();

diff  --git a/llvm/lib/MC/MCAsmInfoXCOFF.cpp b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
index a23a71b865b43..f90fc5a8f4983 100644
--- a/llvm/lib/MC/MCAsmInfoXCOFF.cpp
+++ b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
@@ -19,6 +19,7 @@ void MCAsmInfoXCOFF::anchor() {}
 MCAsmInfoXCOFF::MCAsmInfoXCOFF() {
   IsLittleEndian = false;
   HasVisibilityOnlyWithLinkage = true;
+  HasBasenameOnlyForFileDirective = false;
   PrivateGlobalPrefix = "L..";
   PrivateLabelPrefix = "L..";
   SupportsQuotedNames = false;

diff  --git a/llvm/test/CodeGen/PowerPC/aix-filename-absolute-path.ll 
b/llvm/test/CodeGen/PowerPC/aix-filename-absolute-path.ll
new file mode 100644
index 0..d5b6886ebcefe
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/aix-filename-absolute-path.ll
@@ -0,0 +1,8 @@
+; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff < %s \
+; RUN:   | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff < %s \
+; RUN:   | FileCheck %s
+
+; CHECK: .file "/absolute/path/to/file"
+
+source_filename = "/absolute/path/to/file"

diff  --git a/llvm/test/CodeGen/PowerPC/aix-filename-relative-path.ll 
b/llvm/test/CodeGen/PowerPC/aix-filename-relative-path.ll
new file mode 100644
index 0..6df85c84d2678
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/aix-filename-relative-path.ll
@@ -0,0 +1,8 @@
+; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff < %s \
+; RUN:   | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff < %s \
+; RUN:   | FileCheck %s
+
+; CHECK: .file "../relative/path/to/file"
+
+source_filename = "../relative/path/to/file"



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


[llvm-branch-commits] [llvm] d8dc1f2 - file name - special characters.

2021-04-26 Thread Chen Zheng via llvm-branch-commits

Author: Chen Zheng
Date: 2021-04-26T05:13:10-04:00
New Revision: d8dc1f20c9a86adfe31ae8df2a763e89ee5068bb

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

LOG: file name - special characters.

Added: 
llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.ll
llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.ll

Modified: 
llvm/include/llvm/MC/MCAsmInfo.h
llvm/lib/MC/MCAsmInfoXCOFF.cpp
llvm/lib/MC/MCAsmStreamer.cpp

Removed: 




diff  --git a/llvm/include/llvm/MC/MCAsmInfo.h 
b/llvm/include/llvm/MC/MCAsmInfo.h
index b674af072ed55..e48d1edd05068 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -345,6 +345,10 @@ class MCAsmInfo {
   /// target also needs the directory along with the basename. Default to true.
   bool HasBasenameOnlyForFileDirective = true;
 
+  /// Tue if the target represents string constant as mostly raw characters in
+  /// paired double quotation. Default to false.
+  bool HasPairedDoubleQuoteStringConstants = false;
+
   // True if the target allows .align directives on functions. This is true for
   // most targets, so defaults to true.
   bool HasFunctionAlignment = true;
@@ -673,6 +677,9 @@ class MCAsmInfo {
   bool hasBasenameOnlyForFileDirective() const {
 return HasBasenameOnlyForFileDirective;
   }
+  bool hasPairedDoubleQuoteStringConstants() const {
+return HasPairedDoubleQuoteStringConstants;
+  }
   bool hasFunctionAlignment() const { return HasFunctionAlignment; }
   bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; 
}
   bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }

diff  --git a/llvm/lib/MC/MCAsmInfoXCOFF.cpp b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
index f90fc5a8f4983..670ab30821638 100644
--- a/llvm/lib/MC/MCAsmInfoXCOFF.cpp
+++ b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
@@ -20,6 +20,11 @@ MCAsmInfoXCOFF::MCAsmInfoXCOFF() {
   IsLittleEndian = false;
   HasVisibilityOnlyWithLinkage = true;
   HasBasenameOnlyForFileDirective = false;
+
+  // For XCOFF, string constant consists of any number of characters enclosed 
in
+  // "" (double quotation marks)
+  HasPairedDoubleQuoteStringConstants = true;
+
   PrivateGlobalPrefix = "L..";
   PrivateLabelPrefix = "L..";
   SupportsQuotedNames = false;

diff  --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 0012c10bf83b4..432c7bb3971bd 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -60,6 +60,12 @@ class MCAsmStreamer final : public MCStreamer {
   unsigned UseDwarfDirectory : 1;
 
   void EmitRegisterName(int64_t Register);
+  void PrintQuotedString(StringRef Data, raw_ostream &OS);
+  void printDwarfFileDirective(unsigned FileNo, StringRef Directory,
+   StringRef Filename,
+   Optional Checksum,
+   Optional Source,
+   bool UseDwarfDirectory, raw_svector_ostream 
&OS);
   void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
   void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
 
@@ -1040,33 +1046,53 @@ static void PrintByteList(StringRef Data, raw_ostream 
&OS,
   llvm_unreachable("Invalid AsmCharLiteralSyntax value!");
 }
 
-static void PrintQuotedString(StringRef Data, raw_ostream &OS) {
+void MCAsmStreamer::PrintQuotedString(StringRef Data, raw_ostream &OS) {
   OS << '"';
 
-  for (unsigned i = 0, e = Data.size(); i != e; ++i) {
-unsigned char C = Data[i];
-if (C == '"' || C == '\\') {
-  OS << '\\' << (char)C;
-  continue;
+  if (MAI->hasPairedDoubleQuoteStringConstants()) {
+for (unsigned i = 0, e = Data.size(); i != e; ++i) {
+  unsigned char C = Data[i];
+  if (C == '"')
+OS << "\"\"";
+  else
+OS << (char)C;
 }
+  } else {
+for (unsigned i = 0, e = Data.size(); i != e; ++i) {
+  unsigned char C = Data[i];
+  if (C == '"' || C == '\\') {
+OS << '\\' << (char)C;
+continue;
+  }
 
-if (isPrint((unsigned char)C)) {
-  OS << (char)C;
-  continue;
-}
+  if (isPrint((unsigned char)C)) {
+OS << (char)C;
+continue;
+  }
 
-switch (C) {
-  case '\b': OS << "\\b"; break;
-  case '\f': OS << "\\f"; break;
-  case '\n': OS << "\\n"; break;
-  case '\r': OS << "\\r"; break;
-  case '\t': OS << "\\t"; break;
+  switch (C) {
+  case '\b':
+OS << "\\b";
+break;
+  case '\f':
+OS << "\\f";
+break;
+  case '\n':
+OS << "\\n";
+break;
+  case '\r':
+OS << "\\r";
+break;
+  case '\t':
+OS << "\\t";
+break;
   default:
 OS << '