[llvm] [XCore] Fix crash lowering unsized/zero-length-array thread_local globals (PR #220543)
Bill Wendling via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 2 14:47:51 PDT 2026
================
@@ -121,21 +122,24 @@ static bool rewriteNonInstructionUses(GlobalVariable *GV, Pass *P) {
return true;
}
-static bool isZeroLengthArray(Type *Ty) {
- ArrayType *AT = dyn_cast<ArrayType>(Ty);
- return AT && (AT->getNumElements() == 0);
-}
-
bool XCoreLowerThreadLocal::lowerGlobal(GlobalVariable *GV) {
Module *M = GV->getParent();
if (!GV->isThreadLocal())
return false;
- // Skip globals that we can't lower and leave it for the backend to error.
- if (!rewriteNonInstructionUses(GV, this) ||
- !GV->getType()->isSized() || isZeroLengthArray(GV->getType()))
+ if (!rewriteNonInstructionUses(GV, this))
return false;
+ // The lowered representation needs an ArrayType of the value type, which
+ // requires a known per-element stride: reject anything that can't provide
+ // one now, with a clear diagnostic, rather than emitting a malformed GEP
+ // that only fails much later (and much less clearly) in instruction
+ // selection.
+ if (!GV->getValueType()->isSized() ||
+ GV->getGlobalSize(M->getDataLayout()) == 0)
+ reportFatalUsageError("Size of thread local object '" + GV->getName() +
----------------
isanbard wrote:
Okay, I'm just having trouble with how it's represented in C or C++...(Well, C++ is weird enough that it's probably very simple to do...)
https://github.com/llvm/llvm-project/pull/220543
More information about the llvm-commits
mailing list