summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/varargs.c
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2016-09-15 14:01:10 +0000
committerAaron Ballman <aaron@aaronballman.com>2016-09-15 14:01:10 +0000
commitfc3f8f5e8633c950a4792b6a44d9c61ceda06f73 (patch)
tree3b6df7530d3fd2ea60bae858856ebb969994c6d2 /clang/test/Sema/varargs.c
parent3adbbc3891bc212314bb87e1c556ce5f5585a874 (diff)
downloadbcm5719-llvm-fc3f8f5e8633c950a4792b6a44d9c61ceda06f73.tar.gz
bcm5719-llvm-fc3f8f5e8633c950a4792b6a44d9c61ceda06f73.zip
Silence false positive diagnostics regarding passing an object of enumeration type to va_start(). The underlying type for an enumeration in C is either char, signed int, or unsigned int. In the case the underlying type is chosen to be char (such as when passing -fshort-enums or using __attribute__((packed)) on the enum declaration), the enumeration can result in undefined behavior. However, when the underlying type is signed int or unsigned int (or long long as an extension), there is no undefined behavior because the types are compatible. This patch silences diagnostics for the latter while retaining the diagnostics for the former.
This patch addresses PR29140. llvm-svn: 281609
Diffstat (limited to 'clang/test/Sema/varargs.c')
-rw-r--r--clang/test/Sema/varargs.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/clang/test/Sema/varargs.c b/clang/test/Sema/varargs.c
index 457d84c212f..27d49ea1f2e 100644
--- a/clang/test/Sema/varargs.c
+++ b/clang/test/Sema/varargs.c
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple i386-pc-unknown
// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-apple-darwin9
+// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -DMS -verify %s
void f1(int a)
{
@@ -94,3 +95,20 @@ void f12(register int i, ...) { // expected-note {{parameter of type 'int' is d
__builtin_va_start(ap, i); // expected-warning {{passing a parameter declared with the 'register' keyword to 'va_start' has undefined behavior}}
__builtin_va_end(ap);
}
+
+enum __attribute__((packed)) E1 {
+ one1
+};
+
+void f13(enum E1 e, ...) {
+ __builtin_va_list va;
+ __builtin_va_start(va, e);
+#ifndef MS
+ // In Microsoft compatibility mode, all enum types are int, but in
+ // non-ms-compatibility mode, this enumeration type will undergo default
+ // argument promotions.
+ // expected-note@-7 {{parameter of type 'enum E1' is declared here}}
+ // expected-warning@-6 {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
+#endif
+ __builtin_va_end(va);
+}
OpenPOWER on IntegriCloud