diff options
author | Hans Wennborg <hans@hanshq.net> | 2014-09-29 23:06:57 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2014-09-29 23:06:57 +0000 |
commit | c543a65783a4c493c4fa412952165098a7340903 (patch) | |
tree | 5f693ca44a604fabce69b84da328a9ff3cb9e8c5 /test/CodeGenCXX/vararg-non-pod-ms-compat.cpp | |
parent | 9b130df765b2ec64e8ab8483ead3a421eacc4984 (diff) |
Don't trap when passing non-POD arguments to variadic functions in MS-compatibility mode
Clang warns (treated as error by default, but still ignored in system headers)
when passing non-POD arguments to variadic functions, and generates a trap
instruction to crash the program if that code is ever run.
Unfortunately, MSVC happily generates code for such calls without a warning,
and there is code in system headers that use it.
This makes Clang not insert the trap instruction when in -fms-compatibility
mode, while still generating the warning/error message.
Differential Revision: http://reviews.llvm.org/D5492
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@218640 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenCXX/vararg-non-pod-ms-compat.cpp')
-rw-r--r-- | test/CodeGenCXX/vararg-non-pod-ms-compat.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/CodeGenCXX/vararg-non-pod-ms-compat.cpp b/test/CodeGenCXX/vararg-non-pod-ms-compat.cpp new file mode 100644 index 0000000000..da05c0b524 --- /dev/null +++ b/test/CodeGenCXX/vararg-non-pod-ms-compat.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -Wno-error=non-pod-varargs -triple i686-pc-win32 -fms-compatibility -emit-llvm -o - %s | FileCheck %s -check-prefix=X86 -check-prefix=CHECK +// RUN: %clang_cc1 -Wno-error=non-pod-varargs -triple x86_64-pc-win32 -fms-compatibility -emit-llvm -o - %s | FileCheck %s -check-prefix=X64 -check-prefix=CHECK + +struct X { + X(); + ~X(); + int data; +}; + +void vararg(...); + +void test(X x) { + // CHECK-LABEL: define void @"\01?test@@YAXUX@@@Z" + + // X86: %[[argmem:[^ ]*]] = alloca inalloca <{ %struct.X }> + // X86: call void (<{ %struct.X }>*, ...)* bitcast (void (...)* @"\01?vararg@@YAXZZ" to void (<{ %struct.X }>*, ...)*)(<{ %struct.X }>* inalloca %[[argmem]]) + + // X64: %[[valptr:[^ ]*]] = getelementptr %struct.X* %{{[^ ]*}}, i32 0, i32 0 + // X64: %[[val:[^ ]*]] = load i32* %[[valptr]] + // X64: call void (...)* @"\01?vararg@@YAXZZ"(i32 %[[val]]) + + // CHECK-NOT: llvm.trap + vararg(x); + // CHECK: ret void +} + |