Skip to content

Commit d2ad9df

Browse files
committedJan 3, 2017
[Win64] Don't widen integer literal zero arguments to unprototyped function calls
The special case to widen the integer literal zero when passed to variadic function calls should only apply to variadic functions, not unprototyped functions. This is consistent with what MSVC does. In this test case, MSVC uses a 4-byte store to pass the 5th argument to 'kr' and an 8-byte store to pass the zero to 'v': void v(int, ...); void kr(); void f(void) { v(1, 2, 3, 4, 0); kr(1, 2, 3, 4, 0); } Aaron Ballman discovered this issue in https://reviews.llvm.org/D28166 llvm-svn: 290906
1 parent 6aff744 commit d2ad9df

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed
 

‎clang/lib/CodeGen/CodeGenFunction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3571,7 +3571,7 @@ class CodeGenFunction : public CodeGenTypeCache {
35713571

35723572
// If we still have any arguments, emit them using the type of the argument.
35733573
for (auto *A : llvm::make_range(Arg, ArgRange.end()))
3574-
ArgTypes.push_back(getVarArgType(A));
3574+
ArgTypes.push_back(CallArgTypeInfo ? getVarArgType(A) : A->getType());
35753575

35763576
EmitCallArgs(Args, ArgTypes, ArgRange, CalleeDecl, ParamsToSkip, Order);
35773577
}

‎clang/test/CodeGen/variadic-null-win64.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33

44
// Make it possible to pass NULL through variadic functions on platforms where
55
// NULL has an integer type that is more narrow than a pointer. On such
6-
// platforms we widen null pointer constants to a pointer-sized integer.
6+
// platforms we widen null pointer constants passed to variadic functions to a
7+
// pointer-sized integer. We don't apply this special case to K&R-style
8+
// unprototyped functions, because MSVC doesn't either.
79

810
#define NULL 0
911

1012
void v(const char *f, ...);
13+
void kr();
1114
void f(const char *f) {
1215
v(f, 1, 2, 3, NULL);
16+
kr(f, 1, 2, 3, 0);
1317
}
1418
// WINDOWS: define void @f(i8* %f)
1519
// WINDOWS: call void (i8*, ...) @v(i8* {{.*}}, i32 1, i32 2, i32 3, i64 0)
20+
// WINDOWS: call void bitcast (void (...)* @kr to void (i8*, i32, i32, i32, i32)*)(i8* {{.*}}, i32 1, i32 2, i32 3, i32 0)
1621
// LINUX: define void @f(i8* %f)
1722
// LINUX: call void (i8*, ...) @v(i8* {{.*}}, i32 1, i32 2, i32 3, i32 0)
23+
// LINUX: call void (i8*, i32, i32, i32, i32, ...) bitcast (void (...)* @kr to void (i8*, i32, i32, i32, i32, ...)*)(i8* %1, i32 1, i32 2, i32 3, i32 0)

0 commit comments

Comments
 (0)
Please sign in to comment.