Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/lib/CodeGen/CGDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
}
CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn, ModuleInits,
GuardAddr);
getTargetCodeGenInfo().setTargetAttributes(nullptr, Fn, *this);
}

// We allow for the case that a module object is added to a linked binary
Expand Down
9 changes: 5 additions & 4 deletions clang/lib/CodeGen/Targets/AArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {

void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &CGM) const override {
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
if (!FD)
auto *Fn = dyn_cast<llvm::Function>(GV);
if (!Fn)
return;

const auto *FD = dyn_cast_or_null<FunctionDecl>(D);
TargetInfo::BranchProtectionInfo BPI(CGM.getLangOpts());

if (const auto *TA = FD->getAttr<TargetAttr>()) {
if (FD && FD->hasAttr<TargetAttr>()) {
const auto *TA = FD->getAttr<TargetAttr>();
ParsedTargetAttr Attr =
CGM.getTarget().parseTargetAttr(TA->getFeaturesStr());
if (!Attr.BranchProtection.empty()) {
Expand All @@ -152,7 +154,6 @@ class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {
assert(Error.empty());
}
}
auto *Fn = cast<llvm::Function>(GV);
setBranchProtectionFnAttributes(BPI, *Fn);
}

Expand Down
13 changes: 7 additions & 6 deletions clang/lib/CodeGen/Targets/ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
CodeGen::CodeGenModule &CGM) const override {
if (GV->isDeclaration())
return;
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
if (!FD)
auto *Fn = dyn_cast<llvm::Function>(GV);
if (!Fn)
return;
auto *Fn = cast<llvm::Function>(GV);
const auto *FD = dyn_cast_or_null<FunctionDecl>(D);

if (const auto *TA = FD->getAttr<TargetAttr>()) {
if (FD && FD->hasAttr<TargetAttr>()) {
const auto *TA = FD->getAttr<TargetAttr>();
ParsedTargetAttr Attr =
CGM.getTarget().parseTargetAttr(TA->getFeaturesStr());
if (!Attr.BranchProtection.empty()) {
Expand Down Expand Up @@ -174,10 +175,10 @@ class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
setBranchProtectionFnAttributes(BPI, (*Fn));
}

const ARMInterruptAttr *Attr = FD->getAttr<ARMInterruptAttr>();
if (!Attr)
if (!FD || !FD->hasAttr<ARMInterruptAttr>())
return;

const ARMInterruptAttr *Attr = FD->getAttr<ARMInterruptAttr>();
const char *Kind;
switch (Attr->getInterrupt()) {
case ARMInterruptAttr::Generic: Kind = ""; break;
Expand Down
72 changes: 72 additions & 0 deletions clang/test/CodeGenCXX/cxx20-module-initializer-pacbti.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -emit-module-interface -target-feature +pacbti -mbranch-target-enforce -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-BTI %s

// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC %s

// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -emit-module-interface -target-feature +pacbti -msign-return-address=all -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-ALL %s

// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf -mbranch-target-enforce -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BTI %s

// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -emit-module-interface -target-feature +pacbti -msign-return-address=all -mbranch-target-enforce -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple thumbv8.1m.main-unknown-none-eabi -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BTI-ALL %s

// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -emit-module-interface -target-feature +pacbti -mbranch-target-enforce -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-BTI %s

// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC %s

// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf -msign-return-address-key=b_key -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BKEY %s

// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -emit-module-interface -target-feature +pacbti -msign-return-address=all -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-ALL %s

// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -emit-module-interface -target-feature +pacbti -msign-return-address=all -msign-return-address-key=b_key -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-ALL-BKEY %s

// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf -mbranch-target-enforce -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BTI %s

// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -emit-module-interface -target-feature +pacbti -msign-return-address=non-leaf -msign-return-address-key=b_key -mbranch-target-enforce -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BKEY-BTI %s

// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -emit-module-interface -target-feature +pacbti -msign-return-address=all -mbranch-target-enforce -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BTI-ALL %s

// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -emit-module-interface -target-feature +pacbti -msign-return-address=all -msign-return-address-key=b_key -mbranch-target-enforce -std=c++20 %s -o %t.pcm
// RUN: %clang_cc1 -triple aarch64-unknown-none-elf -std=c++20 %t.pcm -emit-llvm -o - | \
// RUN: FileCheck --check-prefixes=CHECK,CHECK-PAC-BKEY-BTI-ALL %s

// CHECK: define void @_ZGIW3foo() #0
// CHECK-BTI: attributes #0 = { nounwind "branch-target-enforcement" }
// CHECK-PAC: attributes #0 = { nounwind "sign-return-address"="non-leaf" "sign-return-address-key"="a_key" }
// CHECK-PAC-BKEY: attributes #0 = { nounwind "sign-return-address"="non-leaf" "sign-return-address-key"="b_key" }
// CHECK-PAC-ALL: attributes #0 = { nounwind "sign-return-address"="all" "sign-return-address-key"="a_key" }
// CHECK-PAC-ALL-BKEY: attributes #0 = { nounwind "sign-return-address"="all" "sign-return-address-key"="b_key" }
// CHECK-PAC-BTI: attributes #0 = { nounwind "branch-target-enforcement" "sign-return-address"="non-leaf" "sign-return-address-key"="a_key" }
// CHECK-PAC-BKEY-BTI: attributes #0 = { nounwind "branch-target-enforcement" "sign-return-address"="non-leaf" "sign-return-address-key"="b_key" }
// CHECK-PAC-BTI-ALL: attributes #0 = { nounwind "branch-target-enforcement" "sign-return-address"="all" "sign-return-address-key"="a_key" }
// CHECK-PAC-BKEY-BTI-ALL: attributes #0 = { nounwind "branch-target-enforcement" "sign-return-address"="all" "sign-return-address-key"="b_key" }

module;

export module foo;

export void func();