[PATCH] D37035: Implement __builtin_LINE() et. al. to support source location capture.

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 2 18:44:54 PDT 2018


EricWF updated this revision to Diff 153840.
EricWF added a comment.

When evaluating a `SourceLocExpr` returning a string literal, we have to produce the string within the context the `SourceLocExpr` appears and then propagate it within the resulting `LValue`. We cannot lazily produce the value when a character of the string is actually accessed.

This change adds the field `const char *LValueBase::LValueString` to allow storing and propagating the result of evaluating a `SourceLocExpr`, as well as providing the required information  to compute the "true" `ConstantArrayType` for an `LValueBase` which refers to a `SourceLocExpr`.

@rsmith How does this approach look to you?

This prevents the need to produce new `StringLiteral` expressions. However I'm not sure this is the best approach, since it increases the complexity when accessing an `LValueBase` in `ExprConstant.cpp`, in particular producing the type of the `LValueBase` (which has to be invented on the fly).

An alternative solution would be to create a `StringLiteral`, cache it in `ASTContext` for reuse, and return the new expression. Would this require serializing the `ASTContext` cache? Would this be a better solution?


https://reviews.llvm.org/D37035

Files:
  docs/LanguageExtensions.rst
  include/clang/AST/APValue.h
  include/clang/AST/ASTContext.h
  include/clang/AST/CurrentSourceLocExprScope.h
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/Stmt.h
  include/clang/Basic/StmtNodes.td
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/APValue.cpp
  lib/AST/ASTContext.cpp
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprConstant.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/CodeGenCXX/builtin-source-location.cpp
  test/CodeGenCXX/builtin_FUNCTION.cpp
  test/CodeGenCXX/builtin_LINE.cpp
  test/CodeGenCXX/debug-info-line.cpp
  test/Parser/builtin_source_location.c
  test/Sema/source_location.c
  test/SemaCXX/Inputs/source-location-file.h
  test/SemaCXX/source_location.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37035.153840.patch
Type: text/x-patch
Size: 124734 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180703/18d8f784/attachment-0001.bin>


More information about the cfe-commits mailing list