zbrid created this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. zbrid requested review of this revision.
Revert or squash this before uploading for review. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D86033 Files: clang/lib/Sema/SemaStmtAsm.cpp clang/lib/Sema/SemaStmtAttr.cpp
Index: clang/lib/Sema/SemaStmtAttr.cpp =================================================================== --- clang/lib/Sema/SemaStmtAttr.cpp +++ clang/lib/Sema/SemaStmtAttr.cpp @@ -12,6 +12,7 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/EvaluatedExprVisitor.h" +#include "clang/AST/StmtVisitor.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Sema/DelayedDiagnostic.h" @@ -20,6 +21,7 @@ #include "clang/Sema/SemaInternal.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Triple.h" +#include <iostream> using namespace clang; using namespace sema; @@ -53,6 +55,26 @@ return ::new (S.Context) FallThroughAttr(S.Context, A); } +static void recur(SmallVectorImpl<DeclRefExpr> &V, const Stmt& S) { + for (auto Child: S.children()) { + if (isa<DeclRefExpr>(Child)) + std::cout << "is a declrefexpr" << std::endl; + else + std::cout << "is NOT a declrefexpr" << std::endl; + recur(V, *Child); + } +} +namespace { +class DeclRefExprVisitor : public StmtVisitor<DeclRefExprVisitor> { +public: + SmallVector<DeclRefExpr, 1> ExprNodesForAttrArgs; + ExprResult VisitDeclRefExpr(DeclRefExpr *E) { + std::cout << "Found a decl ref expr!" << std::endl; + ExprNodesForAttrArgs.emplace_back(&E); + } +}; +} // namespace + static Attr *handleHardenMisspeculationAttr(Sema &S, Stmt *St, const ParsedAttr &A, SourceRange Range) { @@ -81,6 +103,38 @@ return nullptr; } } + // We need to find the DeclRefExpr nodes that are for each variable passed + // into the attribute since we have to create a GCCAsmNode that references + // each variable later. + + DeclRefExprVisitor DREV; + DREV.Visit(St); + for (unsigned i = 0; i < A.getNumArgs(); i++) { + IdentifierLoc *CurrArg = A.getArg(i).get<IdentifierLoc*>(); + } +// CurrArg->dump(); + // Create GCC node... + // TODO: Figure out appropriate source location. +// SourceLocation AsmLoc = SourceLocation(); +// bool IsSimple = false; +// bool IsVolatile = true; +// unsigned NumOutputs = 1; +// unsigned NumInputs = 0; +// IdentifierInfo **Names = nullptr; // TODO: What should this be? +// StringLiteral *Constraint = nullptr; //StringLiteral("+r"); +// StringLiteral **Constraints = &Constraint; +// StringLiteral **Clobbers= nullptr; +// Expr **AsmExprs = &CurrArg; +// StringLiteral * AsmString = nullptr; //StringLiteral(""); +// unsigned NumClobbers = 0; +// unsigned NumLabels = 0; +// SourceLocation RParenLoc = SourceLocation(); //TODO +// +// ::new (S.Context) +// GCCAsmStmt(S.Context, AsmLoc, IsSimple, IsVolatile, NumOutputs, +// NumInputs, Names, Constraints, AsmExprs, AsmString, +// NumClobbers, Clobbers, NumLabels, RParenLoc); +// } return ::new (S.Context) HardenMisspeculationAttr(S.Context, A); } Index: clang/lib/Sema/SemaStmtAsm.cpp =================================================================== --- clang/lib/Sema/SemaStmtAsm.cpp +++ clang/lib/Sema/SemaStmtAsm.cpp @@ -24,6 +24,9 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/MC/MCParser/MCAsmParser.h" +#include <llvm-9/llvm/ADT/Twine.h> +#include <llvm/Support/FormatVariadic.h> +#include <iostream> using namespace clang; using namespace sema; @@ -245,11 +248,40 @@ Expr *asmString, MultiExprArg clobbers, unsigned NumLabels, SourceLocation RParenLoc) { +// llvm::formatv("My asm statement args: {0}, {1}, {2}, {3}, {4}, {5}, {6}, " +// "{7}, {8}, {9}, {10}, {11}, {12}", +// AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs, Names, +// constraints, Exprs, asmString, clobbers->get, NumLabels); + + std::cout << llvm::formatv("NumInputs: {0}\nNumOutputs: {1}\n", NumInputs, NumOutputs).str(); + std::cout << llvm::formatv("IsSimple: {0}\nIsVolatile: {1}\n", IsSimple, IsVolatile).str(); + asmString->dumpColor(); + dyn_cast<Stmt>(asmString)->dumpPretty(Context); + std::cout << llvm::formatv("AsmString: \"{0}\"\n", asmString).str(); + std::cout << llvm::formatv("NumLabels: {0}\n", NumLabels).str(); + std::cout << llvm::formatv("NumExprs: {0}\n", Exprs.size()).str(); + Exprs[0]->dumpColor(); unsigned NumClobbers = clobbers.size(); + std::cout << llvm::formatv("NumClobbers: {0}\n", NumClobbers).str(); + std::cout << llvm::formatv("NumConstraints: {0}\n", constraints.size()).str(); StringLiteral **Constraints = reinterpret_cast<StringLiteral**>(constraints.data()); + StringLiteral **CopyConstraints = Constraints; + int i = constraints.size(); + while (i > 0) { + std::cout << llvm::formatv("Constraint: {0}\n", (*CopyConstraints)->getBytes()).str(); + CopyConstraints++; + i--; + } StringLiteral *AsmString = cast<StringLiteral>(asmString); StringLiteral **Clobbers = reinterpret_cast<StringLiteral**>(clobbers.data()); +// StringLiteral **CopyClobbers = Clobbers; +// int j = clobbers.size(); +// while (j > 0) { +// std::cout << llvm::formatv("Clobber: {0}\n", *CopyClobbers).str(); +// CopyClobbers++; +// j--; +// } SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits