Skip to content

Commit

Permalink
[llvm][Transforms] Filter out instructions with "kcfi" annotation in …
Browse files Browse the repository at this point in the history
…LowerConstantExpr
  • Loading branch information
gmh5225 authored Sep 17, 2024
1 parent 4bd4649 commit 26db05a
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions llvm/lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2015,16 +2015,38 @@ bool llvm::LowerConstantExpr(Function &F) {

for (BasicBlock &BB : F) {
// Skip EHPad basic block.
if (BB.isEHPad()) continue;
if (BB.isEHPad())
continue;
for (Instruction &I : BB) {
// Skip EHPad instruction
if (I.isEHPad()) continue;
for (unsigned int Index = 0; Index < I.getNumOperands(); ++Index) {
if (ConstantExpr *CE =
dyn_cast<ConstantExpr>(I.getOperand(Index))) {
SavedList.push_back(&I);
// Skip EHPad instruction
if (I.isEHPad())
continue;

// Skip specific annotation instruction
if (I.hasMetadata("annotation")) {
MDNode *Annotations = I.getMetadata("annotation");
for (unsigned i = 0; i < Annotations->getNumOperands(); ++i) {
if (MDNode *Annotation =
dyn_cast<MDNode>(Annotations->getOperand(i))) {
if (MDString *AnnotationName =
dyn_cast<MDString>(Annotation->getOperand(0))) {
if (AnnotationName->getString() == "kcfi") {
// Skip kcfi
goto NextInstruction;
}
}
}
}
}

for (unsigned int Index = 0; Index < I.getNumOperands(); ++Index) {
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I.getOperand(Index))) {
SavedList.push_back(&I);
}
}

NextInstruction:
;
}
}

Expand Down

0 comments on commit 26db05a

Please sign in to comment.