File tree Expand file tree Collapse file tree 4 files changed +11
-4
lines changed Expand file tree Collapse file tree 4 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -700,7 +700,7 @@ Global Variables
700700Global variables define regions of memory allocated at compilation time
701701instead of run-time.
702702
703- Global variable definitions must be initialized.
703+ Global variable definitions must be initialized with a sized value .
704704
705705Global variables in other translation units can also be declared, in which
706706case they don't have an initializer.
Original file line number Diff line number Diff line change @@ -835,6 +835,8 @@ void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
835835 " Global variable initializer type does not match global "
836836 " variable type!" ,
837837 &GV);
838+ Check (GV.getInitializer ()->getType ()->isSized (),
839+ " Global variable initializer must be sized" , &GV);
838840 // If the global has common linkage, it must have a zero initializer and
839841 // cannot be constant.
840842 if (GV.hasCommonLinkage ()) {
Original file line number Diff line number Diff line change 1+ ; RUN: not llvm-as < %s 2>&1 | FileCheck %s
2+
3+ @g = global target ("opaque" ) undef
4+
5+ ; CHECK: Global variable initializer must be sized
Original file line number Diff line number Diff line change 1313
1414; CHECK-NEXT: Globals cannot contain scalable types
1515; CHECK-NEXT: ptr @ScalableVecStructGlobal
16- @ScalableVecStructGlobal = global { i32 , <vscale x 4 x i32 > } zeroinitializer
16+ @ScalableVecStructGlobal = external global { i32 , <vscale x 4 x i32 > }
1717
1818; CHECK-NEXT: Globals cannot contain scalable types
1919; CHECK-NEXT: ptr @StructTestGlobal
2323; CHECK-NEXT: Globals cannot contain scalable types
2424; CHECK-NEXT: ptr @StructArrayTestGlobal
2525%struct.array.test = type { [2 x <vscale x 1 x double >] }
26- @StructArrayTestGlobal = global %struct.array.test zeroinitializer
26+ @StructArrayTestGlobal = external global %struct.array.test
2727
2828; CHECK-NEXT: Globals cannot contain scalable types
2929; CHECK-NEXT: ptr @StructTargetTestGlobal
3030%struct.target.test = type { target ("aarch64.svcount" ), target ("aarch64.svcount" ) }
31- @StructTargetTestGlobal = global %struct.target.test zeroinitializer
31+ @StructTargetTestGlobal = external global %struct.target.test
You can’t perform that action at this time.
0 commit comments