Skip to content

Commit

Permalink
Merge commit '8959c3cf987f94f8514d30fc82923c662088cad3' into attach_a…
Browse files Browse the repository at this point in the history
…nnotation_to_get
  • Loading branch information
wangdi4 committed Jan 22, 2024
2 parents 88fe720 + 8959c3c commit 3ebd695
Show file tree
Hide file tree
Showing 121 changed files with 1,766 additions and 695 deletions.
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DebugOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ ENUM_DEBUGOPT(DebugInfo, llvm::codegenoptions::DebugInfoKind, 4,
/// Whether to generate macro debug info.
DEBUGOPT(MacroDebugInfo, 1, 0)

/// Whether to not generate debug info for system headers.
DEBUGOPT(NoSystemDebug, 1, 0)

/// Tune the debug info for this debugger.
ENUM_DEBUGOPT(DebuggerTuning, llvm::DebuggerKind, 3,
llvm::DebuggerKind::Default)
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -3769,6 +3769,10 @@ def fdebug_macro : Flag<["-"], "fdebug-macro">, Group<f_Group>,
def fno_debug_macro : Flag<["-"], "fno-debug-macro">, Group<f_Group>,
Visibility<[ClangOption, CLOption, DXCOption]>,
HelpText<"Do not emit macro debug information">;
def fno_system_debug : Flag<["-"], "fno-system-debug">, Group<f_Group>,
Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
HelpText<"Do not emit debug information for declarations in system headers">,
MarshallingInfoFlag<CodeGenOpts<"NoSystemDebug">>;
def fstrict_aliasing : Flag<["-"], "fstrict-aliasing">, Group<f_Group>,
Visibility<[ClangOption, CLOption, DXCOption]>,
HelpText<"Enable optimizations based on strict aliasing rules">;
Expand Down
46 changes: 34 additions & 12 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty,
return Src;

const auto *AliasDecl = cast<TypeAliasTemplateDecl>(TD)->getTemplatedDecl();
if (AliasDecl->hasAttr<NoDebugAttr>())
if (AliasDecl->hasAttr<NoDebugAttr>() || noSystemDebugInfo(AliasDecl, CGM))
return Src;

SmallString<128> NS;
Expand Down Expand Up @@ -1435,7 +1435,8 @@ llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
llvm::DIType *Underlying =
getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit);

if (Ty->getDecl()->hasAttr<NoDebugAttr>())
if (Ty->getDecl()->hasAttr<NoDebugAttr>() ||
noSystemDebugInfo(Ty->getDecl(), CGM))
return Underlying;

// We don't set size information, but do specify where the typedef was
Expand Down Expand Up @@ -1818,7 +1819,7 @@ void CGDebugInfo::CollectRecordFields(
// the corresponding declarations in the source program.
for (const auto *I : record->decls())
if (const auto *V = dyn_cast<VarDecl>(I)) {
if (V->hasAttr<NoDebugAttr>())
if (V->hasAttr<NoDebugAttr>() || noSystemDebugInfo(V, CGM))
continue;

// Skip variable template specializations when emitting CodeView. MSVC
Expand Down Expand Up @@ -2081,7 +2082,8 @@ void CGDebugInfo::CollectCXXMemberFunctions(
// derived classes. GDB doesn't seem to notice/leverage these when I tried
// it, so I'm not rushing to fix this. (GCC seems to produce them, if
// referenced)
if (!Method || Method->isImplicit() || Method->hasAttr<NoDebugAttr>())
if (!Method || Method->isImplicit() || Method->hasAttr<NoDebugAttr>() ||
noSystemDebugInfo(Method, CGM))
continue;

if (Method->getType()->castAs<FunctionProtoType>()->getContainedAutoType())
Expand Down Expand Up @@ -4451,6 +4453,7 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
// Do not emit a declaration subprogram for a function with nodebug
// attribute, or if call site info isn't required.
if (CalleeDecl->hasAttr<NoDebugAttr>() ||
noSystemDebugInfo(CalleeDecl, CGM) ||
getCallSiteRelatedAttrs() == llvm::DINode::FlagZero)
return;

Expand Down Expand Up @@ -4642,7 +4645,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
const bool UsePointerValue) {
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
if (VD->hasAttr<NoDebugAttr>())
if (VD->hasAttr<NoDebugAttr>() || noSystemDebugInfo(VD, CGM))
return nullptr;

bool Unwritten =
Expand Down Expand Up @@ -4856,7 +4859,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
const bool UsePointerValue) {
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
if (BD->hasAttr<NoDebugAttr>())
if (BD->hasAttr<NoDebugAttr>() || noSystemDebugInfo(BD, CGM))
return nullptr;

// Skip the tuple like case, we don't handle that here
Expand Down Expand Up @@ -4962,7 +4965,7 @@ void CGDebugInfo::EmitLabel(const LabelDecl *D, CGBuilderTy &Builder) {
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");

if (D->hasAttr<NoDebugAttr>())
if (D->hasAttr<NoDebugAttr>() || noSystemDebugInfo(D, CGM))
return;

auto *Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
Expand Down Expand Up @@ -5001,7 +5004,7 @@ void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(

if (Builder.GetInsertBlock() == nullptr)
return;
if (VD->hasAttr<NoDebugAttr>())
if (VD->hasAttr<NoDebugAttr>() || noSystemDebugInfo(VD, CGM))
return;

bool isByRef = VD->hasAttr<BlocksAttr>();
Expand Down Expand Up @@ -5521,7 +5524,7 @@ std::string CGDebugInfo::GetName(const Decl *D, bool Qualified) const {
void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
const VarDecl *D) {
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
if (D->hasAttr<NoDebugAttr>())
if (D->hasAttr<NoDebugAttr>() || noSystemDebugInfo(D, CGM))
return;

llvm::TimeTraceScope TimeScope("DebugGlobalVariable", [&]() {
Expand Down Expand Up @@ -5586,7 +5589,7 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,

void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
if (VD->hasAttr<NoDebugAttr>())
if (VD->hasAttr<NoDebugAttr>() || noSystemDebugInfo(VD, CGM))
return;
llvm::TimeTraceScope TimeScope("DebugConstGlobalVariable", [&]() {
return GetName(VD, true);
Expand Down Expand Up @@ -5663,7 +5666,7 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
const VarDecl *D) {
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
if (D->hasAttr<NoDebugAttr>())
if (D->hasAttr<NoDebugAttr>() || noSystemDebugInfo(D, CGM))
return;

auto Align = getDeclAlignIfRequired(D, CGM.getContext());
Expand All @@ -5688,7 +5691,7 @@ void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV,
return;

const auto *D = cast<ValueDecl>(GD.getDecl());
if (D->hasAttr<NoDebugAttr>())
if (D->hasAttr<NoDebugAttr>() || noSystemDebugInfo(D, CGM))
return;

auto AliaseeDecl = CGM.getMangledNameDecl(GV->getName());
Expand Down Expand Up @@ -5745,6 +5748,8 @@ llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) {
if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
return;
if (noSystemDebugInfo(&UD, CGM))
return;
const NamespaceDecl *NSDecl = UD.getNominatedNamespace();
if (!NSDecl->isAnonymousNamespace() ||
CGM.getCodeGenOpts().DebugExplicitImport) {
Expand All @@ -5770,6 +5775,8 @@ void CGDebugInfo::EmitUsingShadowDecl(const UsingShadowDecl &USD) {
void CGDebugInfo::EmitUsingDecl(const UsingDecl &UD) {
if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
return;
if (noSystemDebugInfo(&UD, CGM))
return;
assert(UD.shadow_size() &&
"We shouldn't be codegening an invalid UsingDecl containing no decls");

Expand All @@ -5795,6 +5802,8 @@ void CGDebugInfo::EmitUsingDecl(const UsingDecl &UD) {
void CGDebugInfo::EmitUsingEnumDecl(const UsingEnumDecl &UD) {
if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
return;
if (noSystemDebugInfo(&UD, CGM))
return;
assert(UD.shadow_size() &&
"We shouldn't be codegening an invalid UsingEnumDecl"
" containing no decls");
Expand All @@ -5820,6 +5829,8 @@ llvm::DIImportedEntity *
CGDebugInfo::EmitNamespaceAlias(const NamespaceAliasDecl &NA) {
if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
return nullptr;
if (noSystemDebugInfo(&NA, CGM))
return nullptr;
auto &VH = NamespaceAliasCache[&NA];
if (VH)
return cast<llvm::DIImportedEntity>(VH);
Expand Down Expand Up @@ -6011,3 +6022,14 @@ CGDebugInfo::createConstantValueExpression(const clang::ValueDecl *VD,

return nullptr;
}

bool clang::CodeGen::noSystemDebugInfo(const Decl *D,
const CodeGenModule &CGM) {
// Declaration is in system file
if (CGM.getContext().getSourceManager().isInSystemHeader(D->getLocation())) {
// -fno-system-debug was used. Do not generate debug info.
if (CGM.getCodeGenOpts().NoSystemDebug)
return true;
}
return false;
}
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CGDebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,8 @@ class ApplyInlineDebugLocation {
~ApplyInlineDebugLocation();
};

bool noSystemDebugInfo(const Decl *D, const CodeGenModule &CGM);

} // namespace CodeGen
} // namespace clang

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ void CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
llvm::GlobalVariable *Addr,
bool PerformInit) {
// Check if we need to emit debug info for variable initializer.
if (D->hasAttr<NoDebugAttr>())
if (D->hasAttr<NoDebugAttr>() || noSystemDebugInfo(D, CGM))
DebugInfo = nullptr; // disable debug info indefinitely for this function

CurEHLocation = D->getBeginLoc();
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CGObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,9 @@ void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD,
const ObjCContainerDecl *CD) {
SourceLocation StartLoc = OMD->getBeginLoc();
FunctionArgList args;

// Check if we should generate debug info for this method.
if (OMD->hasAttr<NoDebugAttr>())
if (OMD->hasAttr<NoDebugAttr>() || noSystemDebugInfo(OMD, CGM))
DebugInfo = nullptr; // disable debug info indefinitely for this function

llvm::Function *Fn = CGM.getObjCRuntime().GenerateMethod(OMD, CD);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
}

// Check if we should generate debug info for this function.
if (FD->hasAttr<NoDebugAttr>()) {
if (FD->hasAttr<NoDebugAttr>() || noSystemDebugInfo(FD, CGM)) {
// Clear non-distinct debug info that was possibly attached to the function
// due to an earlier declaration without the nodebug attribute
Fn->setSubprogram(nullptr);
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4575,6 +4575,10 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T,
D, TC))
CmdArgs.push_back("-debug-info-macro");

// -fno-system-debug turns off debug info generation for system headers
if (Args.hasArg(options::OPT_fno_system_debug))
CmdArgs.push_back("-fno-system-debug");

// -ggnu-pubnames turns on gnu style pubnames in the backend.
const auto *PubnamesArg =
Args.getLastArg(options::OPT_ggnu_pubnames, options::OPT_gno_gnu_pubnames,
Expand Down Expand Up @@ -10306,7 +10310,7 @@ void SYCLPostLink::ConstructJob(Compilation &C, const JobAction &JA,
if (!(T.isAMDGCN()))
addArgs(CmdArgs, TCArgs, {"-emit-param-info"});
// Enable PI program metadata
if (T.isNVPTX())
if (T.isNVPTX() || T.isAMDGCN())
addArgs(CmdArgs, TCArgs, {"-emit-program-metadata"});
if (SYCLPostLink->getTrueType() == types::TY_LLVM_BC) {
// single file output requested - this means only perform necessary IR
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/HIPAMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ void HIPAMDToolChain::addClangTargetOptions(
// supported for the foreseeable future.
if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
options::OPT_fvisibility_ms_compat)) {
CC1Args.append({"-fvisibility=hidden"});
if (DeviceOffloadingKind != Action::OFK_SYCL)
CC1Args.append({"-fvisibility=hidden"});
CC1Args.push_back("-fapply-global-visibility-to-externs");
}

Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Sema/SPIRVBuiltins.td
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,9 @@ foreach Ty = [Void, ConstType<Void>, VolatileType<Void>, VolatileType<ConstType<
def : SPVBuiltin<"GenericCastToPtrExplicit_ToGlobal", [PointerType<Ty, GlobalAS>, PointerType<Ty, DefaultAS>, Int], Attr.Const>;
def : SPVBuiltin<"GenericCastToPtrExplicit_ToLocal", [PointerType<Ty, LocalAS>, PointerType<Ty, DefaultAS>, Int], Attr.Const>;
def : SPVBuiltin<"GenericCastToPtrExplicit_ToPrivate", [PointerType<Ty, PrivateAS>, PointerType<Ty, DefaultAS>, Int], Attr.Const>;
def : SPVBuiltin<"GenericCastToPtr_ToGlobal", [PointerType<Ty, GlobalAS>, PointerType<Ty, DefaultAS>, Int], Attr.Const>;
def : SPVBuiltin<"GenericCastToPtr_ToLocal", [PointerType<Ty, LocalAS>, PointerType<Ty, DefaultAS>, Int], Attr.Const>;
def : SPVBuiltin<"GenericCastToPtr_ToPrivate", [PointerType<Ty, PrivateAS>, PointerType<Ty, DefaultAS>, Int], Attr.Const>;
}

foreach Type = TLFloat.List in {
Expand Down
33 changes: 33 additions & 0 deletions clang/test/CodeGenCXX/debug-sin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
////////////////////////////////////////////////////////////////////////////////////////

// With default options, ensure that declarations obtained by a using declaration have
// debug info generated. sin() is declared through cmath with: using ::sin;
//
// Also ensure that no debug info for sin() is generated if -fno-system-debug is used.

// Debug info for math library functions is not generated on Windows
// UNSUPPORTED: system-windows

// RUN: %clang -emit-llvm -S -g %s -o %t.default.ll
// RUN: %clang -fno-system-debug -emit-llvm -S -g %s -o %t.no_system_debug.ll

// Check for debug info for "sin" with default option
// RUN: FileCheck --check-prefix=CHECK-DEFAULT %s < %t.default.ll

// No debug information for "sin" should be generated with -fno-system-debug
// RUN: FileCheck --check-prefix=CHECK-NO-SYSTEM-DEBUG %s < %t.no_system_debug.ll

// CHECK-DEFAULT: DISubprogram(name: "sin",
// CHECK-NO-SYSTEM-DEBUG-NOT: DISubprogram(name: "sin",

////////////////////////////////////////////////////////////////////////////////////////


#include <math.h>

int main() {
float f;

f=sin(1.32);
return 0;
}
Loading

0 comments on commit 3ebd695

Please sign in to comment.