@@ -1376,7 +1376,7 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty,
1376
1376
return Src;
1377
1377
1378
1378
const auto *AliasDecl = cast<TypeAliasTemplateDecl>(TD)->getTemplatedDecl ();
1379
- if (AliasDecl->hasAttr <NoDebugAttr>())
1379
+ if (AliasDecl->hasAttr <NoDebugAttr>() || noSystemDebugInfo (AliasDecl, CGM) )
1380
1380
return Src;
1381
1381
1382
1382
SmallString<128 > NS;
@@ -1435,7 +1435,8 @@ llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
1435
1435
llvm::DIType *Underlying =
1436
1436
getOrCreateType (Ty->getDecl ()->getUnderlyingType (), Unit);
1437
1437
1438
- if (Ty->getDecl ()->hasAttr <NoDebugAttr>())
1438
+ if (Ty->getDecl ()->hasAttr <NoDebugAttr>() ||
1439
+ noSystemDebugInfo (Ty->getDecl (), CGM))
1439
1440
return Underlying;
1440
1441
1441
1442
// We don't set size information, but do specify where the typedef was
@@ -1818,7 +1819,7 @@ void CGDebugInfo::CollectRecordFields(
1818
1819
// the corresponding declarations in the source program.
1819
1820
for (const auto *I : record->decls ())
1820
1821
if (const auto *V = dyn_cast<VarDecl>(I)) {
1821
- if (V->hasAttr <NoDebugAttr>())
1822
+ if (V->hasAttr <NoDebugAttr>() || noSystemDebugInfo (V, CGM) )
1822
1823
continue ;
1823
1824
1824
1825
// Skip variable template specializations when emitting CodeView. MSVC
@@ -2081,7 +2082,8 @@ void CGDebugInfo::CollectCXXMemberFunctions(
2081
2082
// derived classes. GDB doesn't seem to notice/leverage these when I tried
2082
2083
// it, so I'm not rushing to fix this. (GCC seems to produce them, if
2083
2084
// referenced)
2084
- if (!Method || Method->isImplicit () || Method->hasAttr <NoDebugAttr>())
2085
+ if (!Method || Method->isImplicit () || Method->hasAttr <NoDebugAttr>() ||
2086
+ noSystemDebugInfo (Method, CGM))
2085
2087
continue ;
2086
2088
2087
2089
if (Method->getType ()->castAs <FunctionProtoType>()->getContainedAutoType ())
@@ -4451,6 +4453,7 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
4451
4453
// Do not emit a declaration subprogram for a function with nodebug
4452
4454
// attribute, or if call site info isn't required.
4453
4455
if (CalleeDecl->hasAttr <NoDebugAttr>() ||
4456
+ noSystemDebugInfo (CalleeDecl, CGM) ||
4454
4457
getCallSiteRelatedAttrs () == llvm::DINode::FlagZero)
4455
4458
return ;
4456
4459
@@ -4642,7 +4645,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
4642
4645
const bool UsePointerValue) {
4643
4646
assert (CGM.getCodeGenOpts ().hasReducedDebugInfo ());
4644
4647
assert (!LexicalBlockStack.empty () && " Region stack mismatch, stack empty!" );
4645
- if (VD->hasAttr <NoDebugAttr>())
4648
+ if (VD->hasAttr <NoDebugAttr>() || noSystemDebugInfo (VD, CGM) )
4646
4649
return nullptr ;
4647
4650
4648
4651
bool Unwritten =
@@ -4856,7 +4859,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
4856
4859
const bool UsePointerValue) {
4857
4860
assert (CGM.getCodeGenOpts ().hasReducedDebugInfo ());
4858
4861
assert (!LexicalBlockStack.empty () && " Region stack mismatch, stack empty!" );
4859
- if (BD->hasAttr <NoDebugAttr>())
4862
+ if (BD->hasAttr <NoDebugAttr>() || noSystemDebugInfo (BD, CGM) )
4860
4863
return nullptr ;
4861
4864
4862
4865
// Skip the tuple like case, we don't handle that here
@@ -4962,7 +4965,7 @@ void CGDebugInfo::EmitLabel(const LabelDecl *D, CGBuilderTy &Builder) {
4962
4965
assert (CGM.getCodeGenOpts ().hasReducedDebugInfo ());
4963
4966
assert (!LexicalBlockStack.empty () && " Region stack mismatch, stack empty!" );
4964
4967
4965
- if (D->hasAttr <NoDebugAttr>())
4968
+ if (D->hasAttr <NoDebugAttr>() || noSystemDebugInfo (D, CGM) )
4966
4969
return ;
4967
4970
4968
4971
auto *Scope = cast<llvm::DIScope>(LexicalBlockStack.back ());
@@ -5001,7 +5004,7 @@ void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
5001
5004
5002
5005
if (Builder.GetInsertBlock () == nullptr )
5003
5006
return ;
5004
- if (VD->hasAttr <NoDebugAttr>())
5007
+ if (VD->hasAttr <NoDebugAttr>() || noSystemDebugInfo (VD, CGM) )
5005
5008
return ;
5006
5009
5007
5010
bool isByRef = VD->hasAttr <BlocksAttr>();
@@ -5521,7 +5524,7 @@ std::string CGDebugInfo::GetName(const Decl *D, bool Qualified) const {
5521
5524
void CGDebugInfo::EmitGlobalVariable (llvm::GlobalVariable *Var,
5522
5525
const VarDecl *D) {
5523
5526
assert (CGM.getCodeGenOpts ().hasReducedDebugInfo ());
5524
- if (D->hasAttr <NoDebugAttr>())
5527
+ if (D->hasAttr <NoDebugAttr>() || noSystemDebugInfo (D, CGM) )
5525
5528
return ;
5526
5529
5527
5530
llvm::TimeTraceScope TimeScope (" DebugGlobalVariable" , [&]() {
@@ -5586,7 +5589,7 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
5586
5589
5587
5590
void CGDebugInfo::EmitGlobalVariable (const ValueDecl *VD, const APValue &Init) {
5588
5591
assert (CGM.getCodeGenOpts ().hasReducedDebugInfo ());
5589
- if (VD->hasAttr <NoDebugAttr>())
5592
+ if (VD->hasAttr <NoDebugAttr>() || noSystemDebugInfo (VD, CGM) )
5590
5593
return ;
5591
5594
llvm::TimeTraceScope TimeScope (" DebugConstGlobalVariable" , [&]() {
5592
5595
return GetName (VD, true );
@@ -5663,7 +5666,7 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
5663
5666
void CGDebugInfo::EmitExternalVariable (llvm::GlobalVariable *Var,
5664
5667
const VarDecl *D) {
5665
5668
assert (CGM.getCodeGenOpts ().hasReducedDebugInfo ());
5666
- if (D->hasAttr <NoDebugAttr>())
5669
+ if (D->hasAttr <NoDebugAttr>() || noSystemDebugInfo (D, CGM) )
5667
5670
return ;
5668
5671
5669
5672
auto Align = getDeclAlignIfRequired (D, CGM.getContext ());
@@ -5688,7 +5691,7 @@ void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV,
5688
5691
return ;
5689
5692
5690
5693
const auto *D = cast<ValueDecl>(GD.getDecl ());
5691
- if (D->hasAttr <NoDebugAttr>())
5694
+ if (D->hasAttr <NoDebugAttr>() || noSystemDebugInfo (D, CGM) )
5692
5695
return ;
5693
5696
5694
5697
auto AliaseeDecl = CGM.getMangledNameDecl (GV->getName ());
@@ -5745,6 +5748,8 @@ llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
5745
5748
void CGDebugInfo::EmitUsingDirective (const UsingDirectiveDecl &UD) {
5746
5749
if (!CGM.getCodeGenOpts ().hasReducedDebugInfo ())
5747
5750
return ;
5751
+ if (noSystemDebugInfo (&UD, CGM))
5752
+ return ;
5748
5753
const NamespaceDecl *NSDecl = UD.getNominatedNamespace ();
5749
5754
if (!NSDecl->isAnonymousNamespace () ||
5750
5755
CGM.getCodeGenOpts ().DebugExplicitImport ) {
@@ -5770,6 +5775,8 @@ void CGDebugInfo::EmitUsingShadowDecl(const UsingShadowDecl &USD) {
5770
5775
void CGDebugInfo::EmitUsingDecl (const UsingDecl &UD) {
5771
5776
if (!CGM.getCodeGenOpts ().hasReducedDebugInfo ())
5772
5777
return ;
5778
+ if (noSystemDebugInfo (&UD, CGM))
5779
+ return ;
5773
5780
assert (UD.shadow_size () &&
5774
5781
" We shouldn't be codegening an invalid UsingDecl containing no decls" );
5775
5782
@@ -5795,6 +5802,8 @@ void CGDebugInfo::EmitUsingDecl(const UsingDecl &UD) {
5795
5802
void CGDebugInfo::EmitUsingEnumDecl (const UsingEnumDecl &UD) {
5796
5803
if (!CGM.getCodeGenOpts ().hasReducedDebugInfo ())
5797
5804
return ;
5805
+ if (noSystemDebugInfo (&UD, CGM))
5806
+ return ;
5798
5807
assert (UD.shadow_size () &&
5799
5808
" We shouldn't be codegening an invalid UsingEnumDecl"
5800
5809
" containing no decls" );
@@ -5820,6 +5829,8 @@ llvm::DIImportedEntity *
5820
5829
CGDebugInfo::EmitNamespaceAlias (const NamespaceAliasDecl &NA) {
5821
5830
if (!CGM.getCodeGenOpts ().hasReducedDebugInfo ())
5822
5831
return nullptr ;
5832
+ if (noSystemDebugInfo (&NA, CGM))
5833
+ return nullptr ;
5823
5834
auto &VH = NamespaceAliasCache[&NA];
5824
5835
if (VH)
5825
5836
return cast<llvm::DIImportedEntity>(VH);
@@ -6011,3 +6022,14 @@ CGDebugInfo::createConstantValueExpression(const clang::ValueDecl *VD,
6011
6022
6012
6023
return nullptr ;
6013
6024
}
6025
+
6026
+ bool clang::CodeGen::noSystemDebugInfo (const Decl *D,
6027
+ const CodeGenModule &CGM) {
6028
+ // Declaration is in system file
6029
+ if (CGM.getContext ().getSourceManager ().isInSystemHeader (D->getLocation ())) {
6030
+ // -fno-system-debug was used. Do not generate debug info.
6031
+ if (CGM.getCodeGenOpts ().NoSystemDebug )
6032
+ return true ;
6033
+ }
6034
+ return false ;
6035
+ }
0 commit comments