Skip to content

Instantly share code, notes, and snippets.

@markoshorro
Created December 9, 2019 05:24
Show Gist options
  • Save markoshorro/16d7df8e868c6ea0813639a4a3a516dd to your computer and use it in GitHub Desktop.
Save markoshorro/16d7df8e868c6ea0813639a4a3a516dd to your computer and use it in GitHub Desktop.
Clang: get int value from clang::Expr
/// ASTContext needed, you can get it from CompilerInstance
int64_t getIntFromExpr(const Expr *E, const ASTContext *C) {
clang::Expr::EvalResult R;
if (E->EvaluateAsInt(R, *C)) {
return R.Val.getInt().getExtValue();
}
/// Could be that returning -1 is not safe, you should modify this
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment