[PATCH] PR15677 - Crash in template diffing.

Nikola Smiljanić popizdeh at gmail.com
Thu Jun 19 19:22:11 PDT 2014


Hi rtrieu,

In addition to having and integral type the expression needs to be evaluatable.

I'm not too happy with how GetInt function looks but, one idea would be to return a bool and take APInt as an output parameter, in that case the function would something like this:

  bool GetInt(const TSTiterator &Iter, Expr *ArgExpr, llvm::APInt &Int) {
    // Default, value-depenedent expressions require fetching
    // from the desugared TemplateArgument
    if (Iter.isEnd() && ArgExpr->isValueDependent()) {
      switch (Iter.getDesugar().getKind()) {
      case TemplateArgument::Integral:
        Int = Iter.getDesugar().getAsIntegral();
      case TemplateArgument::Expression:
        ArgExpr = Iter.getDesugar().getAsExpr();
        Int = ArgExpr->EvaluateKnownConstInt(Context);
      default:
        llvm_unreachable("Unexpected template argument kind");
      }
      return true;
    } else if (ArgExpr->isEvaluatable(Context)) {
      Int = ArgExpr->EvaluateKnownConstInt(Context);
      return true;
    }

    return false;
  }

http://reviews.llvm.org/D4226

Files:
  lib/AST/ASTDiagnostic.cpp
  test/Misc/diag-template-diffing.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4226.10676.patch
Type: text/x-patch
Size: 3774 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140620/191e9a76/attachment.bin>


More information about the cfe-commits mailing list