File tree 4 files changed +17
-5
lines changed
4 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -236,9 +236,12 @@ class CodegenVisitor : public Visitor {
236
236
decl->toPrettyChars ());
237
237
LOG_SCOPE;
238
238
239
- if (decl->ir ->isDefined ()) {
239
+ if (decl->ir ->isDefined ())
240
+ return ;
241
+
242
+ // skip external declarations (IR-declared lazily)
243
+ if (decl->storage_class & STCextern)
240
244
return ;
241
- }
242
245
243
246
if (decl->type ->ty == TY::Terror) {
244
247
decl->error (" had semantic errors when compiling" );
Original file line number Diff line number Diff line change @@ -11,3 +11,5 @@ version (D_SoftFloat) {} else static assert(0);
11
11
int definedGlobal = 123 ;
12
12
// CHECK: @_D3avr14declaredGlobali = external global i32
13
13
extern int declaredGlobal;
14
+
15
+ int dummyRef () { return declaredGlobal; } // make sure `declaredGlobal` is IR-declared
Original file line number Diff line number Diff line change @@ -15,8 +15,6 @@ version (CRuntime_WASI) {} else static assert(0);
15
15
16
16
// CHECK: @_D4wasi13definedGlobali = global i32 123
17
17
int definedGlobal = 123 ;
18
- // CHECK: @_D4wasi14declaredGlobali = external global i32
19
- extern int declaredGlobal;
20
18
21
19
22
20
// make sure the ModuleInfo ref is emitted into the __minfo section:
Original file line number Diff line number Diff line change
1
+ // It should compile fine when not referencing the colliding external global:
2
+ // RUN: %ldc -c %s -d-version=DontReference
3
+
4
+ // But fail if referenced:
1
5
// RUN: not %ldc -c %s 2>&1 | FileCheck %s
2
6
3
7
extern (C ) extern int myGlobal;
4
8
5
- // CHECK: global_var_collision.d(9): Error: Global variable type does not match previous declaration with same mangled name: `myGlobal`
9
+ version (DontReference) {} else
10
+ {
11
+ int dummyRef () { return myGlobal; }
12
+ }
13
+
14
+ // CHECK: global_var_collision.d([[@LINE+4]]): Error: Global variable type does not match previous declaration with same mangled name: `myGlobal`
6
15
// CHECK-NEXT: Previous IR type: i32, mutable, thread-local
7
16
// CHECK-NEXT: New IR type: i64, const, non-thread-local
8
17
pragma (mangle, myGlobal.mangleof)
You can’t perform that action at this time.
0 commit comments