Hi rnk, rsmith,
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 patch makes Clang not insert the trap instruction when in
-fms-compatibility mode, while still generating the warning/error message.
http://reviews.llvm.org/D5492
Files:
lib/Sema/SemaExpr.cpp
test/CodeGenCXX/vararg-non-pod-ms-compat.cpp
test/SemaCXX/vararg-non-pod.cpp
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -875,7 +875,8 @@
// Diagnostics regarding non-POD argument types are
// emitted along with format string checking in Sema::CheckFunctionCall().
- if (isValidVarArgType(E->getType()) == VAK_Undefined) {
+ if (isValidVarArgType(E->getType()) == VAK_Undefined &&
+ !LangOpts.MSVCCompat) {
// Turn this into a trap.
CXXScopeSpec SS;
SourceLocation TemplateKWLoc;
Index: test/CodeGenCXX/vararg-non-pod-ms-compat.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/vararg-non-pod-ms-compat.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -Wno-error=non-pod-varargs -triple i686-pc-win32 -fms-compatibility -emit-llvm -o - %s | FileCheck %s
+
+struct X {
+ X();
+ ~X();
+ int data;
+};
+
+void vararg(...);
+
+// CHECK-LABEL: define void @"\01?test@@YAXUX@@@Z"
+void test(X x) {
+ // CHECK: %[[argmem:[^ ]*]] = alloca inalloca <{ %struct.X }>
+ // CHECK: call void (<{ %struct.X }>*, ...)* bitcast (void (...)* @"\01?vararg@@YAXZZ" to void (<{ %struct.X }>*, ...)*)(<{ %struct.X }>* inalloca %[[argmem]])
+ // CHECK-NOT: llvm.trap
+ vararg(x);
+ // CHECK: ret void
+}
+
Index: test/SemaCXX/vararg-non-pod.cpp
===================================================================
--- test/SemaCXX/vararg-non-pod.cpp
+++ test/SemaCXX/vararg-non-pod.cpp
@@ -1,5 +1,8 @@
// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wno-error=non-pod-varargs
+// Check that the warning is still there under -fms-compatibility.
+// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wno-error=non-pod-varargs -fms-compatibility
+
extern char version[];
class C {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits