[PATCH] AST: Mangle reference temporaries reliably
Richard Smith
richard at metafoo.co.uk
Tue Apr 29 17:58:20 PDT 2014
Please also propose this mangling scheme on cxx-abi-dev.
================
Comment at: lib/AST/ExprCXX.cpp:1458-1459
@@ +1457,4 @@
+ if (!State.is<ExtraState *>()) {
+ auto ES = static_cast<ExtraState *>(ExtendedBy->getASTContext().Allocate(
+ sizeof(ExtraState), llvm::alignOf<ExtraState>()));
+ ES->Temporary = State.get<Stmt *>();
----------------
auto ES = new (ExtendedBy->getASTContext()) ExtraState;
================
Comment at: lib/AST/ExprCXX.cpp:1464-1465
@@ +1463,4 @@
+
+ State.get<ExtraState *>()->ExtendingDecl = ExtendedBy;
+ State.get<ExtraState *>()->ManglingNumber = ManglingNumber;
+}
----------------
Maybe stash the `ExtraState*` in a variable to avoid repeateding `get`ing it here?
================
Comment at: lib/Sema/SemaInit.cpp:5769
@@ -5763,2 +5768,3 @@
getDeclForTemporaryLifetimeExtension(Entity)) {
- if (performReferenceExtension(CurInit.get(), ExtendingDecl))
+ unsigned ManglingNumber = 1;
+ if (performReferenceExtension(CurInit.get(), ExtendingDecl,
----------------
It's not sufficient to start the numbering from 1 each time: we need to number within the topmost `InitializedEntity`, not just within the subentity for which we're currently building an initializer. Example:
struct S { const int &a, const int &b; };
S s = { 1, 2 };
================
Comment at: lib/Serialization/ASTWriterStmt.cpp:1569-1573
@@ -1568,6 +1568,7 @@
void ASTStmtWriter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
VisitExpr(E);
- Writer.AddStmt(E->Temporary);
- Writer.AddDeclRef(E->ExtendingDecl, Record);
+ Record.push_back(E->getManglingNumber());
+ Writer.AddStmt(E->getTemporary());
+ Writer.AddDeclRef(E->getExtendingDecl(), Record);
Code = serialization::EXPR_MATERIALIZE_TEMPORARY;
}
----------------
We usually serialize fields in the order they appear in the class (so mangling number would go last). Not a big deal, though.
http://reviews.llvm.org/D3554
More information about the cfe-commits
mailing list