https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260
>From 01f77d9f42a712324479e3280c57f12800655271 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne <pe...@pcc.me.uk> Date: Wed, 27 Aug 2025 14:51:58 -0700 Subject: [PATCH] Add verifier check Created using spr 1.3.6-beta.1 --- llvm/docs/LangRef.rst | 2 +- llvm/lib/IR/Verifier.cpp | 16 ++++++++++++++++ llvm/test/Verifier/elf-section-properties.ll | 12 ++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Verifier/elf-section-properties.ll diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index 0664f3bf48f37..de1b5180e1956 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -8381,7 +8381,7 @@ Example: @global = global i32 1, !elf_section_properties !{i32 1879002126, i32 8} -This defines as global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry +This defines a global with type ``SHT_LLVM_CFI_JUMP_TABLE`` and entry size 8. diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 4eb4b58d022e8..537b6dfcbdbee 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -763,6 +763,22 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) { DL.getIntPtrType(GO->getType()), RangeLikeMetadataKind::AbsoluteSymbol); } + + if (auto *Props = GO->getMetadata(LLVMContext::MD_elf_section_properties)) { + Check(Props->getNumOperands() == 2, + "elf_section_properties metadata must have two operands", GO, Props); + if (Props->getNumOperands() == 2) { + auto *Type = dyn_cast<ConstantAsMetadata>(Props->getOperand(0)); + Check(Type, "type field must be ConstantAsMetadata", GO, Props); + auto *TypeInt = dyn_cast<ConstantInt>(Type->getValue()); + Check(TypeInt, "type field must be ConstantInt", GO, Props); + + auto *Entsize = dyn_cast<ConstantAsMetadata>(Props->getOperand(1)); + Check(Entsize, "entsize field must be ConstantAsMetadata", GO, Props); + auto *EntsizeInt = dyn_cast<ConstantInt>(Entsize->getValue()); + Check(EntsizeInt, "entsize field must be ConstantInt", GO, Props); + } + } } Check(!GV.hasAppendingLinkage() || isa<GlobalVariable>(GV), diff --git a/llvm/test/Verifier/elf-section-properties.ll b/llvm/test/Verifier/elf-section-properties.ll new file mode 100644 index 0000000000000..3ec4a8f5d7d66 --- /dev/null +++ b/llvm/test/Verifier/elf-section-properties.ll @@ -0,0 +1,12 @@ +; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s + +; CHECK: elf_section_properties metadata must have two operands +@g1 = global i32 0, !elf_section_properties !{i32 0} +; CHECK: type field must be ConstantAsMetadata +@g2 = global i32 0, !elf_section_properties !{!{}, i32 0} +; CHECK: entsize field must be ConstantAsMetadata +@g3 = global i32 0, !elf_section_properties !{i32 0, !{}} +; CHECK: type field must be ConstantInt +@g4 = global i32 0, !elf_section_properties !{float 0.0, i32 0} +; CHECK: entsize field must be ConstantInt +@g5 = global i32 0, !elf_section_properties !{i32 0, float 0.0} _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits