r193685 - Recover instead of crashing on MS assembly when no target is loaded

mcrosier at codeaurora.org mcrosier at codeaurora.org
Wed Oct 30 07:39:16 PDT 2013


Nice.  Thanks, Alp.

> Author: alp
> Date: Wed Oct 30 09:29:28 2013
> New Revision: 193685
>
> URL: http://llvm.org/viewvc/llvm-project?rev=193685&view=rev
> Log:
> Recover instead of crashing on MS assembly when no target is loaded
>
> It's possible to embed the frontend in applications that haven't
> initialized
> backend targets so we need to handle this condition gracefully.
>
> Added:
>     cfe/trunk/test/Index/ms-asm-no-target.cpp
> Modified:
>     cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
>     cfe/trunk/lib/Parse/ParseStmt.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=193685&r1=193684&r2=193685&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Wed Oct 30
> 09:29:28 2013
> @@ -23,6 +23,8 @@ def err_asm_empty : Error<"__asm used wi
>  def err_inline_ms_asm_parsing : Error<"%0">;
>  def err_msasm_unsupported_arch : Error<
>    "Unsupported architecture '%0' for MS-style inline assembly">;
> +def err_msasm_unable_to_create_target : Error<
> +  "MS-style inline assembly is not available: %0">;
>  }
>
>  let CategoryName = "Parse Issue" in {
>
> Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=193685&r1=193684&r2=193685&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseStmt.cpp Wed Oct 30 09:29:28 2013
> @@ -2104,9 +2104,15 @@ StmtResult Parser::ParseMicrosoftAsmStat
>    if (UnsupportedArch)
>      Diag(AsmLoc, diag::err_msasm_unsupported_arch) <<
> TheTriple.getArchName();
>
> +  std::string Error;
> +  const std::string &TT = TheTriple.getTriple();
> +  const llvm::Target *TheTarget = llvm::TargetRegistry::lookupTarget(TT,
> Error);
> +  if (!TheTarget)
> +    Diag(AsmLoc, diag::err_msasm_unable_to_create_target) << Error;
> +
>    // If we don't support assembly, or the assembly is empty, we don't
>    // need to instantiate the AsmParser, etc.
> -  if (UnsupportedArch || AsmToks.empty()) {
> +  if (UnsupportedArch || !TheTarget || AsmToks.empty()) {
>      return Actions.ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks,
> StringRef(),
>                                    /*NumOutputs*/ 0, /*NumInputs*/ 0,
>                                    ConstraintRefs, ClobberRefs, Exprs,
> EndLoc);
> @@ -2118,11 +2124,6 @@ StmtResult Parser::ParseMicrosoftAsmStat
>    if (buildMSAsmString(PP, AsmLoc, AsmToks, TokOffsets, AsmString))
>      return StmtError();
>
> -  // Find the target and create the target specific parser.
> -  std::string Error;
> -  const std::string &TT = TheTriple.getTriple();
> -  const llvm::Target *TheTarget = llvm::TargetRegistry::lookupTarget(TT,
> Error);
> -
>    OwningPtr<llvm::MCRegisterInfo> MRI(TheTarget->createMCRegInfo(TT));
>    OwningPtr<llvm::MCAsmInfo> MAI(TheTarget->createMCAsmInfo(*MRI, TT));
>    // Get the instruction descriptor.
>
> Added: cfe/trunk/test/Index/ms-asm-no-target.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/ms-asm-no-target.cpp?rev=193685&view=auto
> ==============================================================================
> --- cfe/trunk/test/Index/ms-asm-no-target.cpp (added)
> +++ cfe/trunk/test/Index/ms-asm-no-target.cpp Wed Oct 30 09:29:28 2013
> @@ -0,0 +1,9 @@
> +// RUN: c-index-test -test-load-source all -triple x86_64-apple-darwin10
> -fasm-blocks -Wno-microsoft %s 2>&1 | FileCheck %s
> +
> +// Test that we diagnose when the application hasn't initialized LLVM
> targets
> +// supporting the MS-style inline asm parser.
> +
> +void Break() {
> +  __asm { int 3 }
> +}
> +// CHECK: error: MS-style inline assembly is not available
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>





More information about the cfe-commits mailing list