Skip to content

Commit 26db05a

Browse files
authored
[llvm][Transforms] Filter out instructions with "kcfi" annotation in LowerConstantExpr
1 parent 4bd4649 commit 26db05a

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,16 +2015,38 @@ bool llvm::LowerConstantExpr(Function &F) {
20152015

20162016
for (BasicBlock &BB : F) {
20172017
// Skip EHPad basic block.
2018-
if (BB.isEHPad()) continue;
2018+
if (BB.isEHPad())
2019+
continue;
20192020
for (Instruction &I : BB) {
2020-
// Skip EHPad instruction
2021-
if (I.isEHPad()) continue;
2022-
for (unsigned int Index = 0; Index < I.getNumOperands(); ++Index) {
2023-
if (ConstantExpr *CE =
2024-
dyn_cast<ConstantExpr>(I.getOperand(Index))) {
2025-
SavedList.push_back(&I);
2021+
// Skip EHPad instruction
2022+
if (I.isEHPad())
2023+
continue;
2024+
2025+
// Skip specific annotation instruction
2026+
if (I.hasMetadata("annotation")) {
2027+
MDNode *Annotations = I.getMetadata("annotation");
2028+
for (unsigned i = 0; i < Annotations->getNumOperands(); ++i) {
2029+
if (MDNode *Annotation =
2030+
dyn_cast<MDNode>(Annotations->getOperand(i))) {
2031+
if (MDString *AnnotationName =
2032+
dyn_cast<MDString>(Annotation->getOperand(0))) {
2033+
if (AnnotationName->getString() == "kcfi") {
2034+
// Skip kcfi
2035+
goto NextInstruction;
2036+
}
20262037
}
2038+
}
2039+
}
2040+
}
2041+
2042+
for (unsigned int Index = 0; Index < I.getNumOperands(); ++Index) {
2043+
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I.getOperand(Index))) {
2044+
SavedList.push_back(&I);
20272045
}
2046+
}
2047+
2048+
NextInstruction:
2049+
;
20282050
}
20292051
}
20302052

0 commit comments

Comments
 (0)