Skip to content

Commit c71848f

Browse files
authored
gen: fix control-flow protection attribute marking (#4828)
* gen/modules.cpp: use setModuleFlag API to replace ... ... the module attribute to avoid LLVM assertions if specified module attribute already exists * changelog for gen/module.cpp cf-protection fix
1 parent 9de21fd commit c71848f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#### Platform support
99

1010
#### Bug fixes
11+
- Building multi-file D applications with control-flow protection will no longer cause LDC to throw an internal compiler error. (#4828)
1112

1213
# LDC 1.40.0 (2024-12-15)
1314

gen/modules.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,18 @@ void registerModuleInfo(Module *m) {
391391

392392
void addModuleFlags(llvm::Module &m) {
393393
const auto ModuleMinFlag = llvm::Module::Min;
394+
const auto ConstantOne =
395+
llvm::ConstantInt::get(LLType::getInt32Ty(m.getContext()), 1);
396+
const auto ConstantOneMetadata = llvm::ConstantAsMetadata::get(ConstantOne);
394397

395398
if (opts::fCFProtection == opts::CFProtectionType::Return ||
396399
opts::fCFProtection == opts::CFProtectionType::Full) {
397-
m.addModuleFlag(ModuleMinFlag, "cf-protection-return", 1);
400+
m.setModuleFlag(ModuleMinFlag, "cf-protection-return", ConstantOneMetadata);
398401
}
399402

400403
if (opts::fCFProtection == opts::CFProtectionType::Branch ||
401404
opts::fCFProtection == opts::CFProtectionType::Full) {
402-
m.addModuleFlag(ModuleMinFlag, "cf-protection-branch", 1);
405+
m.setModuleFlag(ModuleMinFlag, "cf-protection-branch", ConstantOneMetadata);
403406
}
404407
}
405408

0 commit comments

Comments
 (0)