From: Ted Kremenek Date: Tue, 17 Jun 2008 03:11:08 +0000 (+0000) Subject: Fix more strict-aliasing warnings. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1060aff23f72135f8b50034a1e80f16725ebc56c;p=clang Fix more strict-aliasing warnings. Fix indentation of class declarations in ExprCXX.h git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52380 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 98bfbe945b..9a351aec68 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -18,156 +18,156 @@ namespace clang { - //===--------------------------------------------------------------------===// - // C++ Expressions. - //===--------------------------------------------------------------------===// - - /// CXXCastExpr - [C++ 5.2.7, 5.2.9, 5.2.10, 5.2.11] C++ Cast Operators. - /// - class CXXCastExpr : public Expr { - public: - enum Opcode { - DynamicCast, - StaticCast, - ReinterpretCast, - ConstCast - }; - private: - QualType Ty; - Opcode Opc; - Expr *Op; - SourceLocation Loc; // the location of the casting op - public: - CXXCastExpr(Opcode op, QualType ty, Expr *expr, SourceLocation l) - : Expr(CXXCastExprClass, ty), Ty(ty), Opc(op), Op(expr), Loc(l) {} - - QualType getDestType() const { return Ty; } - Expr *getSubExpr() const { return Op; } - - Opcode getOpcode() const { return Opc; } - - /// getOpcodeStr - Turn an Opcode enum value into the string it represents, - /// e.g. "reinterpret_cast". - static const char *getOpcodeStr(Opcode Op) { - // FIXME: move out of line. - switch (Op) { - default: assert(0 && "Not a C++ cast expression"); - case CXXCastExpr::ConstCast: return "const_cast"; - case CXXCastExpr::DynamicCast: return "dynamic_cast"; - case CXXCastExpr::ReinterpretCast: return "reinterpret_cast"; - case CXXCastExpr::StaticCast: return "static_cast"; - } - } - - virtual SourceRange getSourceRange() const { - return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd()); - } - static bool classof(const Stmt *T) { - return T->getStmtClass() == CXXCastExprClass; - } - static bool classof(const CXXCastExpr *) { return true; } - - // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); +//===--------------------------------------------------------------------===// +// C++ Expressions. +//===--------------------------------------------------------------------===// + +/// CXXCastExpr - [C++ 5.2.7, 5.2.9, 5.2.10, 5.2.11] C++ Cast Operators. +/// +class CXXCastExpr : public Expr { +public: + enum Opcode { + DynamicCast, + StaticCast, + ReinterpretCast, + ConstCast }; +private: + QualType Ty; + Opcode Opc; + Stmt *Op; + SourceLocation Loc; // the location of the casting op +public: + CXXCastExpr(Opcode op, QualType ty, Expr *expr, SourceLocation l) + : Expr(CXXCastExprClass, ty), Ty(ty), Opc(op), Op(expr), Loc(l) {} + + QualType getDestType() const { return Ty; } + Expr *getSubExpr() const { return cast(Op); } + + Opcode getOpcode() const { return Opc; } + + /// getOpcodeStr - Turn an Opcode enum value into the string it represents, + /// e.g. "reinterpret_cast". + static const char *getOpcodeStr(Opcode Op) { + // FIXME: move out of line. + switch (Op) { + default: assert(0 && "Not a C++ cast expression"); + case CXXCastExpr::ConstCast: return "const_cast"; + case CXXCastExpr::DynamicCast: return "dynamic_cast"; + case CXXCastExpr::ReinterpretCast: return "reinterpret_cast"; + case CXXCastExpr::StaticCast: return "static_cast"; + } + } + + virtual SourceRange getSourceRange() const { + return SourceRange(Loc, getSubExpr()->getSourceRange().getEnd()); + } + static bool classof(const Stmt *T) { + return T->getStmtClass() == CXXCastExprClass; + } + static bool classof(const CXXCastExpr *) { return true; } + + // Iterators + virtual child_iterator child_begin(); + virtual child_iterator child_end(); +}; + +/// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. +/// +class CXXBoolLiteralExpr : public Expr { + bool Value; + SourceLocation Loc; +public: + CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : + Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {} + + bool getValue() const { return Value; } - /// CXXBoolLiteralExpr - [C++ 2.13.5] C++ Boolean Literal. - /// - class CXXBoolLiteralExpr : public Expr { - bool Value; - SourceLocation Loc; - public: - CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : - Expr(CXXBoolLiteralExprClass, Ty), Value(val), Loc(l) {} + virtual SourceRange getSourceRange() const { return SourceRange(Loc); } - bool getValue() const { return Value; } - - virtual SourceRange getSourceRange() const { return SourceRange(Loc); } + static bool classof(const Stmt *T) { + return T->getStmtClass() == CXXBoolLiteralExprClass; + } + static bool classof(const CXXBoolLiteralExpr *) { return true; } - static bool classof(const Stmt *T) { - return T->getStmtClass() == CXXBoolLiteralExprClass; - } - static bool classof(const CXXBoolLiteralExpr *) { return true; } - - // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); - }; - - /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles - /// 'throw' and 'throw' assignment-expression. When - /// assignment-expression isn't present, Op will be null. - /// - class CXXThrowExpr : public Expr { - Expr *Op; - SourceLocation ThrowLoc; - public: - // Ty is the void type which is used as the result type of the - // exepression. The l is the location of the throw keyword. expr - // can by null, if the optional expression to throw isn't present. - CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) : - Expr(CXXThrowExprClass, Ty), Op(expr), ThrowLoc(l) {} - const Expr *getSubExpr() const { return Op; } - Expr *getSubExpr() { return Op; } - - virtual SourceRange getSourceRange() const { - if (getSubExpr() == 0) - return SourceRange(ThrowLoc, ThrowLoc); - return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); - } - - static bool classof(const Stmt *T) { - return T->getStmtClass() == CXXThrowExprClass; - } - static bool classof(const CXXThrowExpr *) { return true; } - - // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); - }; - - /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a - /// function call argument that was created from the corresponding - /// parameter's default argument, when the call did not explicitly - /// supply arguments for all of the parameters. - class CXXDefaultArgExpr : public Expr { - ParmVarDecl *Param; - public: - // Param is the parameter whose default argument is used by this - // expression. - explicit CXXDefaultArgExpr(ParmVarDecl *param) - : Expr(CXXDefaultArgExprClass, param->getDefaultArg()->getType()), - Param(param) { } - - // Retrieve the parameter that the argument was created from. - const ParmVarDecl *getParam() const { return Param; } - ParmVarDecl *getParam() { return Param; } - - // Retrieve the actual argument to the function call. - const Expr *getExpr() const { return Param->getDefaultArg(); } - Expr *getExpr() { return Param->getDefaultArg(); } - - virtual SourceRange getSourceRange() const { - // Default argument expressions have no representation in the - // source, so they have an empty source range. - return SourceRange(); - } - - static bool classof(const Stmt *T) { - return T->getStmtClass() == CXXDefaultArgExprClass; - } - static bool classof(const CXXDefaultArgExpr *) { return true; } - - // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); - - // Serialization - virtual void EmitImpl(llvm::Serializer& S) const; - static CXXDefaultArgExpr* CreateImpl(llvm::Deserializer& D, - ASTContext& C); - }; + // Iterators + virtual child_iterator child_begin(); + virtual child_iterator child_end(); +}; + +/// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles +/// 'throw' and 'throw' assignment-expression. When +/// assignment-expression isn't present, Op will be null. +/// +class CXXThrowExpr : public Expr { + Stmt *Op; + SourceLocation ThrowLoc; +public: + // Ty is the void type which is used as the result type of the + // exepression. The l is the location of the throw keyword. expr + // can by null, if the optional expression to throw isn't present. + CXXThrowExpr(Expr *expr, QualType Ty, SourceLocation l) : + Expr(CXXThrowExprClass, Ty), Op(expr), ThrowLoc(l) {} + const Expr *getSubExpr() const { return cast_or_null(Op); } + Expr *getSubExpr() { return cast_or_null(Op); } + + virtual SourceRange getSourceRange() const { + if (getSubExpr() == 0) + return SourceRange(ThrowLoc, ThrowLoc); + return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); + } + + static bool classof(const Stmt *T) { + return T->getStmtClass() == CXXThrowExprClass; + } + static bool classof(const CXXThrowExpr *) { return true; } + + // Iterators + virtual child_iterator child_begin(); + virtual child_iterator child_end(); +}; + +/// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a +/// function call argument that was created from the corresponding +/// parameter's default argument, when the call did not explicitly +/// supply arguments for all of the parameters. +class CXXDefaultArgExpr : public Expr { + ParmVarDecl *Param; +public: + // Param is the parameter whose default argument is used by this + // expression. + explicit CXXDefaultArgExpr(ParmVarDecl *param) + : Expr(CXXDefaultArgExprClass, param->getDefaultArg()->getType()), + Param(param) { } + + // Retrieve the parameter that the argument was created from. + const ParmVarDecl *getParam() const { return Param; } + ParmVarDecl *getParam() { return Param; } + + // Retrieve the actual argument to the function call. + const Expr *getExpr() const { return Param->getDefaultArg(); } + Expr *getExpr() { return Param->getDefaultArg(); } + + virtual SourceRange getSourceRange() const { + // Default argument expressions have no representation in the + // source, so they have an empty source range. + return SourceRange(); + } + + static bool classof(const Stmt *T) { + return T->getStmtClass() == CXXDefaultArgExprClass; + } + static bool classof(const CXXDefaultArgExpr *) { return true; } + + // Iterators + virtual child_iterator child_begin(); + virtual child_iterator child_end(); + + // Serialization + virtual void EmitImpl(llvm::Serializer& S) const; + static CXXDefaultArgExpr* CreateImpl(llvm::Deserializer& D, + ASTContext& C); +}; } // end namespace clang #endif diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index 2f7419b046..6db454479f 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -626,14 +626,15 @@ public: /// IndirectGotoStmt - This represents an indirect goto. /// class IndirectGotoStmt : public Stmt { - Expr *Target; + Stmt *Target; // FIXME: Add location information (e.g. SourceLocation objects). // When doing so, update the serialization routines. public: - IndirectGotoStmt(Expr *target) : Stmt(IndirectGotoStmtClass), Target(target){} + IndirectGotoStmt(Expr *target) : Stmt(IndirectGotoStmtClass), + Target((Stmt*)target){} - Expr *getTarget() { return Target; } - const Expr *getTarget() const { return Target; } + Expr *getTarget(); + const Expr *getTarget() const; virtual SourceRange getSourceRange() const { return SourceRange(); } @@ -707,14 +708,14 @@ public: /// depend on the return type of the function and the presence of an argument. /// class ReturnStmt : public Stmt { - Expr *RetExpr; + Stmt *RetExpr; SourceLocation RetLoc; public: ReturnStmt(SourceLocation RL, Expr *E = 0) : Stmt(ReturnStmtClass), - RetExpr(E), RetLoc(RL) {} + RetExpr((Stmt*) E), RetLoc(RL) {} - const Expr *getRetValue() const { return RetExpr; } - Expr *getRetValue() { return RetExpr; } + const Expr *getRetValue() const; + Expr *getRetValue(); virtual SourceRange getSourceRange() const; diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 323fdd67a1..6069438137 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -20,12 +20,8 @@ using namespace clang; // CXXCastExpr -Stmt::child_iterator CXXCastExpr::child_begin() { - return reinterpret_cast(&Op); -} -Stmt::child_iterator CXXCastExpr::child_end() { - return reinterpret_cast(&Op)+1; -} +Stmt::child_iterator CXXCastExpr::child_begin() { return &Op; } +Stmt::child_iterator CXXCastExpr::child_end() { return &Op+1; } // CXXBoolLiteralExpr Stmt::child_iterator CXXBoolLiteralExpr::child_begin() { @@ -36,14 +32,10 @@ Stmt::child_iterator CXXBoolLiteralExpr::child_end() { } // CXXThrowExpr -Stmt::child_iterator CXXThrowExpr::child_begin() { - return reinterpret_cast(&Op); -} +Stmt::child_iterator CXXThrowExpr::child_begin() { return &Op; } Stmt::child_iterator CXXThrowExpr::child_end() { // If Op is 0, we are processing throw; which has no children. - if (Op == 0) - return reinterpret_cast(&Op)+0; - return reinterpret_cast(&Op)+1; + return Op ? &Op+1 : &Op; } // CXXDefaultArgExpr diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 31433a44b6..d3f3ff0e11 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -246,11 +246,11 @@ Stmt::child_iterator GotoStmt::child_begin() { return child_iterator(); } Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); } // IndirectGotoStmt -Stmt::child_iterator IndirectGotoStmt::child_begin() { - return reinterpret_cast(&Target); -} +Expr* IndirectGotoStmt::getTarget() { return cast(Target); } +const Expr* IndirectGotoStmt::getTarget() const { return cast(Target); } -Stmt::child_iterator IndirectGotoStmt::child_end() { return ++child_begin(); } +Stmt::child_iterator IndirectGotoStmt::child_begin() { return &Target; } +Stmt::child_iterator IndirectGotoStmt::child_end() { return &Target+1; } // ContinueStmt Stmt::child_iterator ContinueStmt::child_begin() { return child_iterator(); } @@ -261,14 +261,18 @@ Stmt::child_iterator BreakStmt::child_begin() { return child_iterator(); } Stmt::child_iterator BreakStmt::child_end() { return child_iterator(); } // ReturnStmt -Stmt::child_iterator ReturnStmt::child_begin() { - if (RetExpr) return reinterpret_cast(&RetExpr); - else return child_iterator(); +const Expr* ReturnStmt::getRetValue() const { + return cast_or_null(RetExpr); +} +Expr* ReturnStmt::getRetValue() { + return cast_or_null(RetExpr); } -Stmt::child_iterator ReturnStmt::child_end() { - if (RetExpr) return reinterpret_cast(&RetExpr)+1; - else return child_iterator(); +Stmt::child_iterator ReturnStmt::child_begin() { + return &RetExpr; +} +Stmt::child_iterator ReturnStmt::child_end() { + return RetExpr ? &RetExpr+1 : &RetExpr; } // AsmStmt