aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Verifier.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2025-05-02 09:52:39 +0200
committerGitHub <noreply@github.com>2025-05-02 09:52:39 +0200
commita8ec6e8788832cff77ec855a2331438c937fb5da (patch)
treebb4854bea81653b51520b7b3f982f3b303a8353a /llvm/lib/IR/Verifier.cpp
parent140c2b6d081b781b19f50bf1c4fbf4b17bfacdc1 (diff)
downloadllvm-a8ec6e8788832cff77ec855a2331438c937fb5da.zip
llvm-a8ec6e8788832cff77ec855a2331438c937fb5da.tar.gz
llvm-a8ec6e8788832cff77ec855a2331438c937fb5da.tar.bz2
[IR] Require that global value initializers are sized (#137358)
While external globals can be unsized, I don't think an unsized initializer makes sense. It seems like the backend currently ends up treating this as a zero-size global. If people want that behavior, they should declare it as such.
Diffstat (limited to 'llvm/lib/IR/Verifier.cpp')
-rw-r--r--llvm/lib/IR/Verifier.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 7d1918e..a798808 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -835,6 +835,8 @@ void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
"Global variable initializer type does not match global "
"variable type!",
&GV);
+ Check(GV.getInitializer()->getType()->isSized(),
+ "Global variable initializer must be sized", &GV);
// If the global has common linkage, it must have a zero initializer and
// cannot be constant.
if (GV.hasCommonLinkage()) {