[llvm] [llvm][ARM][AArch64] Add conflicting module flag check to the verifier. (PR #83635)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 1 15:47:42 PST 2024
https://github.com/DanielKristofKiss created https://github.com/llvm/llvm-project/pull/83635
Some flags shall not be set at the same time.
>From 2537cb8ece73b9c8bd2924550c0baf48d72621d8 Mon Sep 17 00:00:00 2001
From: Daniel Kiss <daniel.kiss at arm.com>
Date: Sat, 2 Mar 2024 00:40:36 +0100
Subject: [PATCH] Add conflicting module flag check to the verifier.
Some flags shall not be set at the same time.
---
llvm/lib/IR/Verifier.cpp | 16 ++++++++++++++++
llvm/test/Verifier/module-flags-1.ll | 6 +++++-
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 1b02d11ff4e7b3..56b71f826c06eb 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -1744,6 +1744,22 @@ void Verifier::visitModuleFlags() {
continue;
}
}
+
+ // Validate only one of the flags set with none zero value.
+ auto isModuleAttributeSet = [&](const StringRef &ModAttr) -> bool {
+ const auto *Attr =
+ mdconst::extract_or_null<ConstantInt>(M.getModuleFlag(ModAttr));
+ return Attr && Attr->getZExtValue();
+ };
+ const std::pair<StringRef, StringRef> ConflictingFlags[] = {
+ {"sign-return-address", "sign-return-address-all"}};
+
+ for (auto FlagPair : ConflictingFlags) {
+ if (isModuleAttributeSet(FlagPair.first) &&
+ isModuleAttributeSet(FlagPair.second))
+ CheckFailed("invalid pair of flags set as " + FlagPair.first + " and " +
+ FlagPair.second);
+ }
}
void
diff --git a/llvm/test/Verifier/module-flags-1.ll b/llvm/test/Verifier/module-flags-1.ll
index 3dfc2a31462ef5..ba6f81fc4172de 100644
--- a/llvm/test/Verifier/module-flags-1.ll
+++ b/llvm/test/Verifier/module-flags-1.ll
@@ -62,6 +62,10 @@
!14 = !{i32 1, !"flag-1", i32 55}
!15 = !{i32 3, !"bar", !{!"flag-1", i32 55}}
+!22 = !{i32 8, !"sign-return-address", i32 1}
+!23 = !{i32 8, !"sign-return-address-all", i32 1}
+; CHECK-NOT: invalid set of flags set as sign-return-address and sign-return-address-all
+
!llvm.module.flags = !{
!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11, !12, !13, !14, !15,
- !16, !17, !18, !19, !20, !21 }
+ !16, !17, !18, !19, !20, !21, !22, !23 }
More information about the llvm-commits
mailing list