File tree 2 files changed +23
-1
lines changed
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -895,10 +895,12 @@ void DtoVarDeclaration(VarDeclaration *vd) {
895
895
896
896
Type *type = isSpecialRefVar (vd) ? pointerTo (vd->type ) : vd->type ;
897
897
898
+ // We also allocate a variable for zero-sized variables, because they are technically not `null` when loaded.
899
+ // The x86_64 ABI "loads" zero-sized function arguments, and without an allocation ASan will report an error (Github #4816).
898
900
llvm::Value *allocainst;
899
901
bool isRealAlloca = false ;
900
902
LLType *lltype = DtoType (type); // void for noreturn
901
- if (lltype->isVoidTy () || gDataLayout -> getTypeSizeInBits (lltype) == 0 ) {
903
+ if (lltype->isVoidTy ()) {
902
904
allocainst = getNullPtr ();
903
905
} else if (type != vd->type ) {
904
906
allocainst = DtoAlloca (type, vd->toChars ());
Original file line number Diff line number Diff line change
1
+ // Test extern(C) structs (zero sized structs) and zero-sized arrays. Github #4816
2
+
3
+ // REQUIRES: ASan
4
+
5
+ // RUN: %ldc -g -fsanitize=address %s -of=%t%exe
6
+ // RUN: %t%exe
7
+
8
+ auto foo (void [0 ] bar) { }
9
+
10
+ extern (C ) struct S {}
11
+ auto foo (S s) { }
12
+
13
+ void main ()
14
+ {
15
+ void [0 ] bar;
16
+ foo(bar);
17
+
18
+ S s;
19
+ foo(s);
20
+ }
You can’t perform that action at this time.
0 commit comments