From: Chris Lattner Date: Mon, 18 Aug 2008 19:55:17 +0000 (+0000) Subject: Several cleanups and tweaks to diagnostics in Sema::ActOnAsmStmt, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1708b963a014b48103e78131f960a13ee1aa6d0c;p=clang Several cleanups and tweaks to diagnostics in Sema::ActOnAsmStmt, no other functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54941 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index a10ceaa19e..30efa85981 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -1001,15 +1001,15 @@ DIAG(err_pascal_string_too_long, ERROR, "Pascal string is too long") DIAG(err_asm_wide_character, ERROR, "wide string is invalid in 'asm'") -DIAG(err_invalid_lvalue_in_asm_output, ERROR, +DIAG(err_asm_invalid_lvalue_in_output, ERROR, "invalid lvalue in asm output") -DIAG(err_invalid_output_constraint_in_asm, ERROR, - "invalid output constraint in asm") -DIAG(err_invalid_input_constraint_in_asm, ERROR, - "invalid input constraint in asm") -DIAG(err_invalid_type_in_asm_input, ERROR, - "invalid type '%0' in asm input") -DIAG(err_unknown_register_name_in_asm, ERROR, +DIAG(err_asm_invalid_output_constraint, ERROR, + "invalid output constraint '%0' in asm") +DIAG(err_asm_invalid_input_constraint, ERROR, + "invalid input constraint '%0' in asm") +DIAG(err_asm_invalid_type_in_input, ERROR, + "invalid type '%0' in asm input for constraint '%1'") +DIAG(err_asm_unknown_register_name, ERROR, "unknown register name '%0' in asm") DIAG(err_invalid_conversion_between_vectors, ERROR, "invalid conversion between vector type '%0' and '%1' of different size") diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 6bc6f3fb0c..619eb772c3 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -675,22 +675,26 @@ Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, unsigned NumOutputs, unsigned NumInputs, std::string *Names, - ExprTy **Constraints, - ExprTy **Exprs, + ExprTy **constraints, + ExprTy **exprs, ExprTy *asmString, unsigned NumClobbers, - ExprTy **Clobbers, + ExprTy **clobbers, SourceLocation RParenLoc) { - // The parser verifies that there is a string literal here. + StringLiteral **Constraints = reinterpret_cast(constraints); + Expr **Exprs = reinterpret_cast(exprs); StringLiteral *AsmString = cast((Expr *)asmString); + StringLiteral **Clobbers = reinterpret_cast(clobbers); + + // The parser verifies that there is a string literal here. if (AsmString->isWide()) // FIXME: We currently leak memory here. return Diag(AsmString->getLocStart(), diag::err_asm_wide_character, AsmString->getSourceRange()); - for (unsigned i = 0; i < NumOutputs; i++) { - StringLiteral *Literal = cast((Expr *)Constraints[i]); + for (unsigned i = 0; i != NumOutputs; i++) { + StringLiteral *Literal = Constraints[i]; if (Literal->isWide()) // FIXME: We currently leak memory here. return Diag(Literal->getLocStart(), diag::err_asm_wide_character, @@ -703,23 +707,21 @@ Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(),info)) // FIXME: We currently leak memory here. return Diag(Literal->getLocStart(), - diag::err_invalid_output_constraint_in_asm); + diag::err_asm_invalid_output_constraint, OutputConstraint); // Check that the output exprs are valid lvalues. - Expr *OutputExpr = (Expr *)Exprs[i]; + ParenExpr *OutputExpr = cast(Exprs[i]); Expr::isLvalueResult Result = OutputExpr->isLvalue(Context); if (Result != Expr::LV_Valid) { - ParenExpr *PE = cast(OutputExpr); - // FIXME: We currently leak memory here. - return Diag(PE->getSubExpr()->getLocStart(), - diag::err_invalid_lvalue_in_asm_output, - PE->getSubExpr()->getSourceRange()); + return Diag(OutputExpr->getSubExpr()->getLocStart(), + diag::err_asm_invalid_lvalue_in_output, + OutputExpr->getSubExpr()->getSourceRange()); } } for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) { - StringLiteral *Literal = cast((Expr *)Constraints[i]); + StringLiteral *Literal = Constraints[i]; if (Literal->isWide()) // FIXME: We currently leak memory here. return Diag(Literal->getLocStart(), diag::err_asm_wide_character, @@ -730,29 +732,27 @@ Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, TargetInfo::ConstraintInfo info; if (!Context.Target.validateInputConstraint(InputConstraint.c_str(), - NumOutputs, - info)) { + NumOutputs, info)) { // FIXME: We currently leak memory here. return Diag(Literal->getLocStart(), - diag::err_invalid_input_constraint_in_asm); + diag::err_asm_invalid_input_constraint, InputConstraint); } // Check that the input exprs aren't of type void. - Expr *InputExpr = (Expr *)Exprs[i]; + ParenExpr *InputExpr = cast(Exprs[i]); if (InputExpr->getType()->isVoidType()) { - ParenExpr *PE = cast(InputExpr); // FIXME: We currently leak memory here. - return Diag(PE->getSubExpr()->getLocStart(), - diag::err_invalid_type_in_asm_input, - PE->getType().getAsString(), - PE->getSubExpr()->getSourceRange()); + return Diag(InputExpr->getSubExpr()->getLocStart(), + diag::err_asm_invalid_type_in_input, + InputExpr->getType().getAsString(), InputConstraint, + InputExpr->getSubExpr()->getSourceRange()); } } // Check that the clobbers are valid. - for (unsigned i = 0; i < NumClobbers; i++) { - StringLiteral *Literal = cast((Expr *)Clobbers[i]); + for (unsigned i = 0; i != NumClobbers; i++) { + StringLiteral *Literal = Clobbers[i]; if (Literal->isWide()) // FIXME: We currently leak memory here. return Diag(Literal->getLocStart(), diag::err_asm_wide_character, @@ -765,20 +765,12 @@ Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, if (!Context.Target.isValidGCCRegisterName(Clobber.c_str())) // FIXME: We currently leak memory here. return Diag(Literal->getLocStart(), - diag::err_unknown_register_name_in_asm, Clobber.c_str()); + diag::err_asm_unknown_register_name, Clobber.c_str()); } - return new AsmStmt(AsmLoc, - IsSimple, - IsVolatile, - NumOutputs, - NumInputs, - Names, - reinterpret_cast(Constraints), - reinterpret_cast(Exprs), - AsmString, NumClobbers, - reinterpret_cast(Clobbers), - RParenLoc); + return new AsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs, + Names, Constraints, Exprs, AsmString, NumClobbers, + Clobbers, RParenLoc); } Action::StmtResult