]> granicus.if.org Git - clang/commitdiff
When complaining about a non-POD second argument to va_arg, use a
authorDouglas Gregor <dgregor@apple.com>
Sat, 30 Jul 2011 06:45:27 +0000 (06:45 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 30 Jul 2011 06:45:27 +0000 (06:45 +0000)
special diagnostic for ARC ownership-qualified types. We wouldn't want
to expose Objective-C programmers to the term "POD", would we? Fixes
<rdar://problem/9772982>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136558 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/SemaObjC/arc-non-pod-memaccess.m

index 83f232e87658b321c9eebf346dcf6d355acad7a4..4f776c42c627228aa3284fe225b7dab790f77ec8 100644 (file)
@@ -4275,6 +4275,9 @@ def err_second_parameter_to_va_arg_abstract: Error<
 def warn_second_parameter_to_va_arg_not_pod : Warning<
   "second argument to 'va_arg' is of non-POD type %0">,
   InGroup<DiagGroup<"non-pod-varargs">>, DefaultError;
+def warn_second_parameter_to_va_arg_ownership_qualified : Warning<
+  "second argument to 'va_arg' is of ARC ownership-qualified type %0">,
+  InGroup<DiagGroup<"non-pod-varargs">>, DefaultError;
 def warn_second_parameter_to_va_arg_never_compatible : Warning<
   "second argument to 'va_arg' is of promotable type %0; this va_arg has "
   "undefined behavior because arguments will be promoted to %1">;
index bfaf5460361fa1ef15c86db9fb5e1f60913ff3fb..966fcbffcf2bf9a18d2d5496380ac187c01d7c0d 100644 (file)
@@ -8591,11 +8591,14 @@ ExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc,
           << TInfo->getTypeLoc().getSourceRange()))
       return ExprError();
 
-    if (!TInfo->getType().isPODType(Context))
+    if (!TInfo->getType().isPODType(Context)) {
       Diag(TInfo->getTypeLoc().getBeginLoc(),
-          diag::warn_second_parameter_to_va_arg_not_pod)
+           TInfo->getType()->isObjCLifetimeType()
+             ? diag::warn_second_parameter_to_va_arg_ownership_qualified
+             : diag::warn_second_parameter_to_va_arg_not_pod)
         << TInfo->getType()
         << TInfo->getTypeLoc().getSourceRange();
+    }
 
     // Check for va_arg where arguments of the given type will be promoted
     // (i.e. this va_arg is guaranteed to have undefined behavior).
index c9a77519694d38ec33a44862c05821ebb2cb5f8d..58f609c9b4c10d66c9101b66b02dd5ac017745c8 100644 (file)
@@ -53,3 +53,11 @@ void test(id __strong *sip, id __weak *wip, id __autoreleasing *aip,
                       // expected-note{{explicitly cast the pointer to silence this warning}}
   memmove(ptr, uip, 17);
 }
+
+void rdar9772982(int i, ...) {
+    __builtin_va_list ap;
+    
+    __builtin_va_start(ap, i);
+    __builtin_va_arg(ap, __strong id); // expected-error{{second argument to 'va_arg' is of ARC ownership-qualified type '__strong id'}}
+    __builtin_va_end(ap);
+}