[cfe-commits] r132979 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/Sema/varargs.c test/SemaCXX/vararg-non-pod.cpp test/SemaTemplate/instantiate-expr-3.cpp
David Majnemer
david.majnemer at gmail.com
Mon Jun 13 22:17:32 PDT 2011
Author: majnemer
Date: Tue Jun 14 00:17:32 2011
New Revision: 132979
URL: http://llvm.org/viewvc/llvm-project?rev=132979&view=rev
Log:
Properly diagnose using abstract and incomplete types in va_arg
- Move a test from test/SemaTemplate/instantiate-expr-3.cpp, it did not belong there
- Incomplete and abstract types are considered hard errors
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/varargs.c
cfe/trunk/test/SemaCXX/vararg-non-pod.cpp
cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=132979&r1=132978&r2=132979&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jun 14 00:17:32 2011
@@ -3927,12 +3927,17 @@
"switch condition has incomplete class type %0">;
def warn_empty_if_body : Warning<
"if statement has empty body">, InGroup<EmptyBody>;
+
def err_va_start_used_in_non_variadic_function : Error<
"'va_start' used in function with fixed args">;
def warn_second_parameter_of_va_start_not_last_named_argument : Warning<
"second parameter of 'va_start' not last named argument">;
def err_first_argument_to_va_arg_not_of_type_va_list : Error<
"first argument to 'va_arg' is of type %0 and not 'va_list'">;
+def err_second_parameter_to_va_arg_incomplete: Error<
+ "second argument to 'va_arg' is of incomplete type %0">;
+def err_second_parameter_to_va_arg_abstract: Error<
+ "second argument to 'va_arg' is of abstract type %0">;
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;
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=132979&r1=132978&r2=132979&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jun 14 00:17:32 2011
@@ -9818,12 +9818,24 @@
<< OrigExpr->getType() << E->getSourceRange());
}
- // FIXME: Check that type is complete/non-abstract
+ if (!TInfo->getType()->isDependentType()) {
+ if (RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), TInfo->getType(),
+ PDiag(diag::err_second_parameter_to_va_arg_incomplete)
+ << TInfo->getTypeLoc().getSourceRange()))
+ return ExprError();
+
+ if (RequireNonAbstractType(TInfo->getTypeLoc().getBeginLoc(),
+ TInfo->getType(),
+ PDiag(diag::err_second_parameter_to_va_arg_abstract)
+ << TInfo->getTypeLoc().getSourceRange()))
+ return ExprError();
- if (!TInfo->getType()->isDependentType() && !TInfo->getType()->isPODType())
- return ExprError(Diag(TInfo->getTypeLoc().getBeginLoc(),
- diag::warn_second_parameter_to_va_arg_not_pod)
- << TInfo->getType() << TInfo->getTypeLoc().getSourceRange());
+ if (!TInfo->getType()->isPODType())
+ Diag(TInfo->getTypeLoc().getBeginLoc(),
+ diag::warn_second_parameter_to_va_arg_not_pod)
+ << TInfo->getType()
+ << TInfo->getTypeLoc().getSourceRange();
+ }
QualType T = TInfo->getType().getNonLValueExprType(Context);
return Owned(new (Context) VAArgExpr(BuiltinLoc, E, TInfo, RPLoc, T));
Modified: cfe/trunk/test/Sema/varargs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/varargs.c?rev=132979&r1=132978&r2=132979&view=diff
==============================================================================
--- cfe/trunk/test/Sema/varargs.c (original)
+++ cfe/trunk/test/Sema/varargs.c Tue Jun 14 00:17:32 2011
@@ -61,3 +61,9 @@
__builtin_va_end(ap);
}
+void f8(int a, ...) {
+ __builtin_va_list ap;
+ __builtin_va_start(ap, a);
+ (void)__builtin_va_arg(ap, void); // expected-error {{second argument to 'va_arg' is of incomplete type 'void'}}
+ __builtin_va_end(ap);
+}
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=132979&r1=132978&r2=132979&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/vararg-non-pod.cpp (original)
+++ cfe/trunk/test/SemaCXX/vararg-non-pod.cpp Tue Jun 14 00:17:32 2011
@@ -101,3 +101,21 @@
__builtin_va_start(list, somearg);
}
+void t7(int n, ...) {
+ __builtin_va_list list;
+ __builtin_va_start(list, n);
+ (void)__builtin_va_arg(list, C); // expected-warning{{second argument to 'va_arg' is of non-POD type 'C'}}
+ __builtin_va_end(list);
+}
+
+struct Abstract {
+ virtual void doit() = 0; // expected-note{{unimplemented pure virtual method}}
+};
+
+void t8(int n, ...) {
+ __builtin_va_list list;
+ __builtin_va_start(list, n);
+ (void)__builtin_va_arg(list, Abstract); // expected-error{{second argument to 'va_arg' is of abstract type 'Abstract'}}
+ __builtin_va_end(list);
+}
+
Modified: cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp?rev=132979&r1=132978&r2=132979&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-3.cpp Tue Jun 14 00:17:32 2011
@@ -117,12 +117,3 @@
template struct VaArg1<__builtin_va_list, int>;
template struct VaArg1<int, int>; // expected-note{{instantiation}}
-
-struct VaArg2 {
- virtual void f(int n, ...) {
- __builtin_va_list va;
- __builtin_va_start(va, n);
- (void)__builtin_va_arg(va, VaArg2); // expected-error {{second argument to 'va_arg' is of non-POD type 'VaArg2'}}
- __builtin_va_end(va);
- }
-};
More information about the cfe-commits
mailing list