[cfe-commits] r54074 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/AST/Type.cpp lib/Sema/SemaStmt.cpp test/Sema/enum.c
Chris Lattner
sabre at nondot.org
Fri Jul 25 16:18:17 PDT 2008
Author: lattner
Date: Fri Jul 25 18:18:17 2008
New Revision: 54074
URL: http://llvm.org/viewvc/llvm-project?rev=54074&view=rev
Log:
Fix rdar://6095136, various crashes with incomplete enum types.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/Sema/enum.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=54074&r1=54073&r2=54074&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Jul 25 18:18:17 2008
@@ -961,6 +961,7 @@
"expression is not assignable")
DIAG(err_typecheck_incomplete_type_not_modifiable_lvalue, ERROR,
"incomplete type '%0' is not assignable")
+
DIAG(err_typecheck_duplicate_vector_components_not_mlvalue, ERROR,
"vector is not assignable (contains duplicate components)")
DIAG(err_typecheck_call_not_function, ERROR,
Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=54074&r1=54073&r2=54074&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Fri Jul 25 18:18:17 2008
@@ -476,7 +476,8 @@
return BT->getKind() >= BuiltinType::Bool &&
BT->getKind() <= BuiltinType::LongLong;
if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
- if (TT->getDecl()->isEnum())
+ // Incomplete enum types are not treated as integer types.
+ if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
return true;
if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
return VT->getElementType()->isIntegerType();
@@ -490,8 +491,8 @@
return BT->getKind() >= BuiltinType::Bool &&
BT->getKind() <= BuiltinType::LongLong;
if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
- if (TT->getDecl()->isEnum())
- return true;
+ if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
+ return true; // Complete enum types are integral.
if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
return ASQT->getBaseType()->isIntegralType();
return false;
@@ -593,7 +594,7 @@
return BT->getKind() >= BuiltinType::Bool &&
BT->getKind() <= BuiltinType::LongDouble;
if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
- return TT->getDecl()->isEnum();
+ return TT->getDecl()->isEnum() && TT->getDecl()->isDefinition();
if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
return VT->getElementType()->isRealType();
if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
@@ -617,7 +618,9 @@
if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
return BT->getKind() != BuiltinType::Void;
if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) {
- if (TT->getDecl()->isEnum())
+ // Enums are scalar types, but only if they are defined. Incomplete enums
+ // are not treated as scalar types.
+ if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
return true;
return false;
}
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=54074&r1=54073&r2=54074&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Fri Jul 25 18:18:17 2008
@@ -25,6 +25,12 @@
Sema::StmtResult Sema::ActOnExprStmt(ExprTy *expr) {
Expr *E = static_cast<Expr*>(expr);
assert(E && "ActOnExprStmt(): missing expression");
+
+ // C99 6.8.3p2: The expression in an expression statement is evaluated as a
+ // void expression for its side effects. Conversion to void allows any
+ // operand, even incomplete types.
+
+ // Same thing in for stmt first clause (when expr) and third clause.
return E;
}
@@ -536,7 +542,7 @@
if (!SecondType->isScalarType()) // C99 6.8.5p2
return Diag(ForLoc, diag::err_typecheck_statement_requires_scalar,
- SecondType.getAsString(), Second->getSourceRange());
+ SecondType.getAsString(), Second->getSourceRange());
}
return new ForStmt(First, Second, Third, Body, ForLoc);
}
Modified: cfe/trunk/test/Sema/enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enum.c?rev=54074&r1=54073&r2=54074&view=diff
==============================================================================
--- cfe/trunk/test/Sema/enum.c (original)
+++ cfe/trunk/test/Sema/enum.c Fri Jul 25 18:18:17 2008
@@ -33,3 +33,18 @@
union u0; // expected-error {{previous use is here}}
enum u0 { U0A }; // expected-error {{error: use of 'u0' with tag type that does not match previous declaration}}
+
+// rdar://6095136
+extern enum some_undefined_enum ve2; // expected-warning {{ISO C forbids forward references to 'enum' types}}
+
+void test4() {
+ for (; ve2;) // expected-error {{statement requires expression of scalar type}}
+ ;
+ (_Bool)ve2; // expected-error {{statement requires expression of scalar type}}
+
+ for (; ;ve2)
+ ;
+ (void)ve2;
+ ve2;
+}
+
More information about the cfe-commits
mailing list