[clang] clang: __builtin_VARIABLE_NAME (PR #86756)
Jon Roelofs via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 27 14:21:56 PDT 2024
================
@@ -2305,6 +2308,36 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
};
switch (getIdentKind()) {
+ case SourceLocIdentKind::VariableName: {
+ // __builtin_VARIABLE_NAME() is a Clang-specific extension that expands to
+ // the name of the variable being defined in a CXXDefaultArgExpr.
+
+ // FIXME: The AST doesn't have upward edges, so we can't easily traverse up
+ // from the CXXDefaultArgExpr to find it. Unfortunately, this means we need
+ // to do a linear scan of (up to) the entire FunctionDecl.
+ struct FindVarDecl : public RecursiveASTVisitor<FindVarDecl> {
+ const Expr *ToFind;
+ const VarDecl *Found = nullptr;
+ bool TraverseVarDecl(VarDecl *D) {
+ if (const auto *CE = dyn_cast_or_null<CXXConstructExpr>(D->getInit())) {
----------------
jroelofs wrote:
Need to strip casts, conversions, parens, etc.
https://github.com/llvm/llvm-project/pull/86756
More information about the cfe-commits
mailing list