Skip to content

Commit 6d23613

Browse files
committed
- Change patch to use existing function.
- Modify setTargetAttributes function to work even without a function declaration.
1 parent bb64966 commit 6d23613

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

clang/lib/CodeGen/CGDeclCXX.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
793793
}
794794
CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn, ModuleInits,
795795
GuardAddr);
796+
getTargetCodeGenInfo().setTargetAttributes(nullptr, Fn, *this);
796797
}
797798

798799
// We allow for the case that a module object is added to a linked binary
@@ -818,12 +819,6 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
818819
Fn->addFnAttr("device-init");
819820
}
820821

821-
if (getTarget().isBranchProtectionSupportedArch(
822-
getTarget().getTargetOpts().CPU)) {
823-
TargetInfo::BranchProtectionInfo BPI(getLangOpts());
824-
getTargetCodeGenInfo().setBranchProtectionFnAttributes(BPI, (*Fn));
825-
}
826-
827822
// We are done with the inits.
828823
AllImports.clear();
829824
PrioritizedCXXGlobalInits.clear();

clang/lib/CodeGen/Targets/ARM.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,13 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
136136
CodeGen::CodeGenModule &CGM) const override {
137137
if (GV->isDeclaration())
138138
return;
139-
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
140-
if (!FD)
139+
auto *Fn = dyn_cast<llvm::Function>(GV);
140+
if (!Fn)
141141
return;
142-
auto *Fn = cast<llvm::Function>(GV);
142+
const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
143143

144-
if (const auto *TA = FD->getAttr<TargetAttr>()) {
144+
if (FD && FD->hasAttr<TargetAttr>()) {
145+
const auto *TA = FD->getAttr<TargetAttr>();
145146
ParsedTargetAttr Attr =
146147
CGM.getTarget().parseTargetAttr(TA->getFeaturesStr());
147148
if (!Attr.BranchProtection.empty()) {
@@ -174,10 +175,10 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
174175
setBranchProtectionFnAttributes(BPI, (*Fn));
175176
}
176177

177-
const ARMInterruptAttr *Attr = FD->getAttr<ARMInterruptAttr>();
178-
if (!Attr)
178+
if (!FD || !FD->hasAttr<ARMInterruptAttr>())
179179
return;
180180

181+
const ARMInterruptAttr *Attr = FD->getAttr<ARMInterruptAttr>();
181182
const char *Kind;
182183
switch (Attr->getInterrupt()) {
183184
case ARMInterruptAttr::Generic: Kind = ""; break;

0 commit comments

Comments
 (0)