From: Steve Naroff Date: Wed, 1 Aug 2007 17:20:42 +0000 (+0000) Subject: Two typeof() related changes... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d1a3b8ca1e5fcc4567b5a6f51d82be2e460de1c;p=clang Two typeof() related changes... - Changed the name of ASTContext::getTypeOfType(Expr*)->getTypeOfExpr(). - Remove FIXME for TypeOfExpr::getAsStringInternal(). This will work fine for printing the AST. It isn't ideal for error diagnostics (since it's more natural to display the expressions type). One "random" (or at least delayed:-) change... - Changed all "ext_typecheck_*" diagnostics from EXTENSION->WARNING. Reason: Since -pedantic is now off (by default), these diagnostics were never being emitted (which is bad). With this change, clang will emit the warning all the time. The only downside (wrt GCC compatibility) is -pedantic-errors will not turn this diagnostics into errors (a "feature" of making tagging them with EXTENSION). When/if this becomes an issue, we can revisit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40676 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp index 6f7165101e..12de403e3c 100644 --- a/AST/ASTContext.cpp +++ b/AST/ASTContext.cpp @@ -584,7 +584,7 @@ QualType ASTContext::getTypedefType(TypedefDecl *Decl) { return QualType(Decl->TypeForDecl, 0); } -QualType ASTContext::getTypeOfType(Expr *tofExpr) { +QualType ASTContext::getTypeOfExpr(Expr *tofExpr) { QualType Canonical = tofExpr->getType().getCanonicalType(); // Note: TypeOfExpr's aren't uniqued. return QualType(new TypeOfExpr(tofExpr, Canonical), 0); diff --git a/AST/Type.cpp b/AST/Type.cpp index 15f0968b81..63a681a52c 100644 --- a/AST/Type.cpp +++ b/AST/Type.cpp @@ -18,6 +18,8 @@ #include "clang/Basic/TargetInfo.h" #include "llvm/Support/Streams.h" #include "llvm/ADT/StringExtras.h" +#include + using namespace clang; Type::~Type() {} @@ -652,9 +654,9 @@ void OCUVectorType::getAsStringInternal(std::string &S) const { } void TypeOfExpr::getAsStringInternal(std::string &InnerString) const { - // FIXME: output expression, getUnderlyingExpr()->print(). - // At the moment, Stmt::print(std::ostream) doesn't work for us here. - InnerString = "typeof() " + InnerString; + std::ostringstream s; + getUnderlyingExpr()->print(s); + InnerString = "typeof(" + s.str() + ") " + InnerString; } void TypeOfType::getAsStringInternal(std::string &S) const { diff --git a/Sema/SemaType.cpp b/Sema/SemaType.cpp index a1dd1f7cda..a1e9e1ccc2 100644 --- a/Sema/SemaType.cpp +++ b/Sema/SemaType.cpp @@ -105,7 +105,7 @@ static QualType ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) { Expr *E = static_cast(DS.getTypeRep()); assert(E && "Didn't get an expression for typeof?"); // TypeQuals handled by caller. - return Ctx.getTypeOfType(E); + return Ctx.getTypeOfExpr(E); } } } diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 5d4c11b9cd..240f54689d 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -101,7 +101,7 @@ public: QualType getTypedefType(TypedefDecl *Decl); /// getTypeOfType - GCC extension. - QualType getTypeOfType(Expr *e); + QualType getTypeOfExpr(Expr *e); QualType getTypeOfType(QualType t); /// getTagDeclType - Return the unique reference to the type for the diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index f700fa24bf..acf8296414 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -604,21 +604,21 @@ DIAG(err_typecheck_indirection_requires_pointer, ERROR, "indirection requires pointer operand ('%0' invalid)") DIAG(err_typecheck_deref_incomplete_type, ERROR, "dereferencing pointer to incomplete type '%0'") -DIAG(ext_typecheck_deref_ptr_to_void, EXTENSION, +DIAG(ext_typecheck_deref_ptr_to_void, WARNING, "dereferencing '%0' pointer") DIAG(err_typecheck_invalid_operands, ERROR, "invalid operands to binary expression ('%0' and '%1')") -DIAG(ext_typecheck_comparison_of_pointer_integer, EXTENSION, +DIAG(ext_typecheck_comparison_of_pointer_integer, WARNING, "comparison between pointer and integer") DIAG(err_typecheck_assign_const, ERROR, "read-only variable is not assignable") DIAG(err_typecheck_assign_incompatible, ERROR, "incompatible types assigning '%1' to '%0'") -DIAG(ext_typecheck_assign_pointer_int, EXTENSION, +DIAG(ext_typecheck_assign_pointer_int, WARNING, "incompatible types assigning '%1' to '%0'") -DIAG(ext_typecheck_assign_incompatible_pointer, EXTENSION, +DIAG(ext_typecheck_assign_incompatible_pointer, WARNING, "incompatible pointer types assigning '%1' to '%0'") -DIAG(ext_typecheck_assign_discards_qualifiers, EXTENSION, +DIAG(ext_typecheck_assign_discards_qualifiers, WARNING, "assigning '%1' to '%0' discards qualifiers") DIAG(err_typecheck_array_not_modifiable_lvalue, ERROR, "array type '%0' is not assignable") @@ -638,11 +638,11 @@ DIAG(err_typecheck_call_too_many_args, ERROR, "too many arguments to function") DIAG(err_typecheck_passing_incompatible, ERROR, "incompatible types passing '%0' to function expecting '%1'") -DIAG(ext_typecheck_passing_incompatible_pointer, EXTENSION, +DIAG(ext_typecheck_passing_incompatible_pointer, WARNING, "incompatible pointer types passing '%0' to function expecting '%1'") -DIAG(ext_typecheck_passing_pointer_int, EXTENSION, +DIAG(ext_typecheck_passing_pointer_int, WARNING, "incompatible types passing '%1' to function expecting '%0'") -DIAG(ext_typecheck_passing_discards_qualifiers, EXTENSION, +DIAG(ext_typecheck_passing_discards_qualifiers, WARNING, "passing '%0' to '%1' discards qualifiers") DIAG(err_typecheck_cond_expect_scalar, ERROR, "used type '%0' where arithmetic or pointer type is required") @@ -650,7 +650,7 @@ DIAG(err_typecheck_expect_scalar_operand, ERROR, "operand of type '%0' where arithmetic or pointer type is required") DIAG(err_typecheck_cond_incompatible_operands, ERROR, "incompatible operand types ('%0' and '%1')") -DIAG(ext_typecheck_cond_incompatible_pointers, EXTENSION, +DIAG(ext_typecheck_cond_incompatible_pointers, WARNING, "pointer type mismatch ('%0' and '%1')") DIAG(warn_unused_expr, WARNING, @@ -667,11 +667,11 @@ DIAG(err_case_not_in_switch, ERROR, "'case' statement not in switch statement") DIAG(err_typecheck_return_incompatible, ERROR, "incompatible type returning '%1', expected '%0'") -DIAG(ext_typecheck_return_pointer_int, EXTENSION, +DIAG(ext_typecheck_return_pointer_int, WARNING, "incompatible type returning '%1', expected '%0'") -DIAG(ext_typecheck_return_incompatible_pointer, EXTENSION, +DIAG(ext_typecheck_return_incompatible_pointer, WARNING, "incompatible pointer type returning '%1', expected '%0'") -DIAG(ext_typecheck_return_discards_qualifiers, EXTENSION, +DIAG(ext_typecheck_return_discards_qualifiers, WARNING, "returning '%1' from function expecting '%0' discards qualifiers") DIAG(err_typecheck_statement_requires_scalar, ERROR, "statement requires expression of scalar type ('%0' invalid)") diff --git a/test/Parser/typeof.c b/test/Parser/typeof.c index 8556687123..14025e5809 100644 --- a/test/Parser/typeof.c +++ b/test/Parser/typeof.c @@ -1,23 +1,23 @@ -// RUN: clang -parse-ast-check %s -pedantic +// RUN: clang -parse-ast-check %s typedef int TInt; static void test() { int *pi; - int typeof (int) aIntInt; // expected-error{{cannot combine with previous 'int' declaration specifier}} expected-warning{{extension used}} - short typeof (int) aShortInt; // expected-error{{'short typeof' is invalid}} expected-warning{{extension used}} + int typeof (int) aIntInt; // expected-error{{cannot combine with previous 'int' declaration specifier}} + short typeof (int) aShortInt; // expected-error{{'short typeof' is invalid}} int int ttt; // expected-error{{cannot combine with previous 'int' declaration specifier}} - typeof(TInt) anInt; // expected-warning{{extension used}} + typeof(TInt) anInt; short TInt eee; // expected-error{{parse error}} void ary[7] fff; // expected-error{{array has incomplete element type 'void'}} expected-error{{parse error}} - typeof(void ary[7]) anIntError; // expected-warning{{extension used}} expected-error{{expected ')'}} expected-error{{to match this '('}} - typeof(const int) aci; // expected-warning{{extension used}} - const typeof (*pi) aConstInt; // expected-warning{{extension used}} + typeof(void ary[7]) anIntError; // expected-error{{expected ')'}} expected-error{{to match this '('}} + typeof(const int) aci; + const typeof (*pi) aConstInt; int xx; int *i; i = aci; // expected-warning{{incompatible types assigning 'typeof(int const)' to 'int *'}} i = anInt; // expected-warning{{incompatible types assigning 'typeof(TInt)' to 'int *'}} - i = aConstInt; // expected-warning{{incompatible types assigning 'typeof() const' to 'int *'}} + i = aConstInt; // expected-warning{{incompatible types assigning 'typeof(*pi) const' to 'int *'}} i = xx; // expected-warning{{incompatible types assigning 'int' to 'int *'}} }