r218640 - Don't trap when passing non-POD arguments to variadic functions in MS-compatibility mode
Hans Wennborg
hans at hanshq.net
Mon Sep 29 16:06:57 PDT 2014
Author: hans
Date: Mon Sep 29 18:06:57 2014
New Revision: 218640
URL: http://llvm.org/viewvc/llvm-project?rev=218640&view=rev
Log:
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
Added:
cfe/trunk/test/CodeGenCXX/vararg-non-pod-ms-compat.cpp
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/vararg-non-pod.cpp
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=218640&r1=218639&r2=218640&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Sep 29 18:06:57 2014
@@ -7737,6 +7737,7 @@ public:
VAK_Valid,
VAK_ValidInCXX11,
VAK_Undefined,
+ VAK_MSVCUndefined,
VAK_Invalid
};
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=218640&r1=218639&r2=218640&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Sep 29 18:06:57 2014
@@ -3569,6 +3569,7 @@ CheckPrintfHandler::checkFormatExpr(cons
break;
case Sema::VAK_Undefined:
+ case Sema::VAK_MSVCUndefined:
EmitFormatDiagnostic(
S.PDiag(diag::warn_non_pod_vararg_with_format_string)
<< S.getLangOpts().CPlusPlus11
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=218640&r1=218639&r2=218640&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 29 18:06:57 2014
@@ -800,6 +800,9 @@ Sema::VarArgKind Sema::isValidVarArgType
if (Ty->isObjCObjectType())
return VAK_Invalid;
+ if (getLangOpts().MSVCCompat)
+ return VAK_MSVCUndefined;
+
// FIXME: In C++11, these cases are conditionally-supported, meaning we're
// permitted to reject them. We should consider doing so.
return VAK_Undefined;
@@ -829,6 +832,7 @@ void Sema::checkVariadicArgument(const E
break;
case VAK_Undefined:
+ case VAK_MSVCUndefined:
DiagRuntimeBehavior(
E->getLocStart(), nullptr,
PDiag(diag::warn_cannot_pass_non_pod_arg_to_vararg)
Added: cfe/trunk/test/CodeGenCXX/vararg-non-pod-ms-compat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vararg-non-pod-ms-compat.cpp?rev=218640&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vararg-non-pod-ms-compat.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/vararg-non-pod-ms-compat.cpp Mon Sep 29 18:06:57 2014
@@ -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
+}
+
Modified: cfe/trunk/test/SemaCXX/vararg-non-pod.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/vararg-non-pod.cpp?rev=218640&r1=218639&r2=218640&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/vararg-non-pod.cpp (original)
+++ cfe/trunk/test/SemaCXX/vararg-non-pod.cpp Mon Sep 29 18:06:57 2014
@@ -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 {
More information about the cfe-commits
mailing list