summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Sema/Sema.h1
-rw-r--r--clang/lib/Sema/SemaChecking.cpp1
-rw-r--r--clang/lib/Sema/SemaExpr.cpp4
-rw-r--r--clang/test/CodeGenCXX/vararg-non-pod-ms-compat.cpp26
-rw-r--r--clang/test/SemaCXX/vararg-non-pod.cpp3
5 files changed, 35 insertions, 0 deletions
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a9cda19d19..be781c300d1 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7737,6 +7737,7 @@ public:
VAK_Valid,
VAK_ValidInCXX11,
VAK_Undefined,
+ VAK_MSVCUndefined,
VAK_Invalid
};
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2cf25feae2e..b4f90d3b4f6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3569,6 +3569,7 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
break;
case Sema::VAK_Undefined:
+ case Sema::VAK_MSVCUndefined:
EmitFormatDiagnostic(
S.PDiag(diag::warn_non_pod_vararg_with_format_string)
<< S.getLangOpts().CPlusPlus11
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5edabc03b69..0c7cb2e6df1 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -800,6 +800,9 @@ Sema::VarArgKind Sema::isValidVarArgType(const QualType &Ty) {
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 Expr *E, VariadicCallType CT) {
break;
case VAK_Undefined:
+ case VAK_MSVCUndefined:
DiagRuntimeBehavior(
E->getLocStart(), nullptr,
PDiag(diag::warn_cannot_pass_non_pod_arg_to_vararg)
diff --git a/clang/test/CodeGenCXX/vararg-non-pod-ms-compat.cpp b/clang/test/CodeGenCXX/vararg-non-pod-ms-compat.cpp
new file mode 100644
index 00000000000..da05c0b5248
--- /dev/null
+++ b/clang/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
+}
+
diff --git a/clang/test/SemaCXX/vararg-non-pod.cpp b/clang/test/SemaCXX/vararg-non-pod.cpp
index 56dafc41f13..66da9964b42 100644
--- a/clang/test/SemaCXX/vararg-non-pod.cpp
+++ b/clang/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 {
OpenPOWER on IntegriCloud