================
@@ -2572,24 +2572,49 @@ CodeGenFunction::EmitAsmInput(const
TargetInfo::ConstraintInfo &Info,
static llvm::MDNode *getAsmSrcLocInfo(const StringLiteral *Str,
CodeGenFunction &CGF) {
SmallVector<llvm::Metadata *, 8> Locs;
+
+ // We need these to find the correct location for the first line.
+ StringRef StrVal = Str->getString();
+ const SourceManager &SM = CGF.CGM.getContext().getSourceManager();
+ const LangOptions &LangOpts = CGF.CGM.getLangOpts();
+ unsigned StartToken = 0;
+ unsigned ByteOffset = 0;
+
// Add the location of the first line to the MDNode.
+
+ // Find the offset of the first character that isn't horizontal whitespace.
+ size_t FirstLocOffset = StrVal.find_first_not_of(" \t\v\f");
+
+ // If the string is empty or all-whitespace, default to offset 0.
+ if (FirstLocOffset == StringRef::npos)
+ FirstLocOffset = 0;
+
+ SourceLocation FirstLineLoc = Str->getLocationOfByte(
+ FirstLocOffset, SM, LangOpts, CGF.getTarget(), &StartToken, &ByteOffset);
+
Locs.push_back(llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
- CGF.Int64Ty, Str->getBeginLoc().getRawEncoding())));
- StringRef StrVal = Str->getString();
- if (!StrVal.empty()) {
- const SourceManager &SM = CGF.CGM.getContext().getSourceManager();
- const LangOptions &LangOpts = CGF.CGM.getLangOpts();
- unsigned StartToken = 0;
- unsigned ByteOffset = 0;
+ CGF.Int64Ty, FirstLineLoc.getRawEncoding())));
+ if (!StrVal.empty()) {
// Add the location of the start of each subsequent line of the asm to the
// MDNode.
for (unsigned i = 0, e = StrVal.size() - 1; i != e; ++i) {
if (StrVal[i] != '\n') continue;
+
+ // The next line starts at byte offset i + 1.
+ // Find the first non-horizontal-whitespace at or after this offset.
+ size_t NextLineOffset = StrVal.find_first_not_of(" \t\v\f", i + 1);
----------------
efriedma-quic wrote:
Can you rearrange the loop so you don't have to duplicate the code for the
first line?
https://github.com/llvm/llvm-project/pull/167316
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits