diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -31,6 +31,7 @@ #include "llvm/IR/InlineAsm.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/MDBuilder.h" +#include "llvm/IR/Mangler.h" #include "llvm/Support/SaveAndRestore.h" using namespace clang; @@ -2544,6 +2545,19 @@ Constraints += InputConstraint; } + // Replace global value to its name. + if (isa(&S)) { + for (int I = 0, E = Args.size(); I != E; ++I) { + if (auto *GV = dyn_cast(Args[I])) { + llvm::Mangler M; + SmallString<256> MangleName; + M.getNameWithPrefix(MangleName, GV, /*CannotUsePrivateLabel=*/true); + AsmString.replace(AsmString.find("$" + std::to_string(I)), 2, + MangleName.c_str()); + } + } + } + // Append the "input" part of inout constraints. for (unsigned i = 0, e = InOutArgs.size(); i != e; i++) { ArgTypes.push_back(InOutArgTypes[i]);