[clang] db3a47c - Fix silent truncation of inline ASM `srcloc` cookie when going through a `DiagnosticInfoSrcMgr` (#84559)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 14 07:06:02 PDT 2024
Author: beetrees
Date: 2024-06-14T15:05:57+01:00
New Revision: db3a47c810639388c80ed173dda3623dac00ce0a
URL: https://github.com/llvm/llvm-project/commit/db3a47c810639388c80ed173dda3623dac00ce0a
DIFF: https://github.com/llvm/llvm-project/commit/db3a47c810639388c80ed173dda3623dac00ce0a.diff
LOG: Fix silent truncation of inline ASM `srcloc` cookie when going through a `DiagnosticInfoSrcMgr` (#84559)
The size of the inline ASM `srcloc` cookie was changed from 32 bits to
64 bits in [D105491](https://reviews.llvm.org/D105491). However, that
commit only updated the size of the cookie in `DiagnosticInfoInlineAsm`,
meaning that inline ASM diagnostics that are instead represented with a
`DiagnosticInfoSrcMgr` have their cookies truncated to 32 bits. This PR
replaces the remaining uses of `unsigned` to represent the cookie with
`uint64_t`, allowing the cookie to make it all the way to the diagnostic
handler without being truncated.
Added:
Modified:
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGen/attr-error.c
clang/test/CodeGen/attr-warning.c
llvm/docs/LangRef.rst
llvm/include/llvm/IR/DiagnosticInfo.h
llvm/lib/CodeGen/MachineModuleInfo.cpp
llvm/lib/IR/DiagnosticInfo.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 65d82285b907b..c11ebe9a3e9c0 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5760,7 +5760,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
// Add metadata if calling an __attribute__((error(""))) or warning fn.
if (TargetDecl && TargetDecl->hasAttr<ErrorAttr>()) {
llvm::ConstantInt *Line =
- llvm::ConstantInt::get(Int32Ty, Loc.getRawEncoding());
+ llvm::ConstantInt::get(Int64Ty, Loc.getRawEncoding());
llvm::ConstantAsMetadata *MD = llvm::ConstantAsMetadata::get(Line);
llvm::MDTuple *MDT = llvm::MDNode::get(getLLVMContext(), {MD});
CI->setMetadata("srcloc", MDT);
diff --git a/clang/test/CodeGen/attr-error.c b/clang/test/CodeGen/attr-error.c
index a1b63ab9fa9e5..ce0e00c3c465b 100644
--- a/clang/test/CodeGen/attr-error.c
+++ b/clang/test/CodeGen/attr-error.c
@@ -8,4 +8,4 @@ void bar(void) {
// CHECK: call void @foo(), !srcloc [[SRCLOC:![0-9]+]]
// CHECK: declare{{.*}} void @foo() [[ATTR:#[0-9]+]]
// CHECK: attributes [[ATTR]] = {{{.*}}"dontcall-error"="oh no"
-// CHECK: [[SRCLOC]] = !{i32 {{[0-9]+}}}
+// CHECK: [[SRCLOC]] = !{i64 {{[0-9]+}}}
diff --git a/clang/test/CodeGen/attr-warning.c b/clang/test/CodeGen/attr-warning.c
index 5c89066aff75a..034ab7869f769 100644
--- a/clang/test/CodeGen/attr-warning.c
+++ b/clang/test/CodeGen/attr-warning.c
@@ -8,4 +8,4 @@ void bar(void) {
// CHECK: call void @foo(), !srcloc [[SRCLOC:![0-9]+]]
// CHECK: declare{{.*}} void @foo() [[ATTR:#[0-9]+]]
// CHECK: attributes [[ATTR]] = {{{.*}}"dontcall-warn"="oh no"
-// CHECK: [[SRCLOC]] = !{i32 {{[0-9]+}}}
+// CHECK: [[SRCLOC]] = !{i64 {{[0-9]+}}}
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 10d53bea149ef..6935ccdfc9196 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -5658,7 +5658,7 @@ it. For example:
call void asm sideeffect "something bad", ""(), !srcloc !42
...
- !42 = !{ i32 1234567 }
+ !42 = !{ i64 1234567 }
It is up to the front-end to make sense of the magic numbers it places
in the IR. If the MDNode contains multiple constants, the code generator
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h
index 628445fe9fb2c..b35923efdad5d 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -1076,11 +1076,11 @@ class DiagnosticInfoSrcMgr : public DiagnosticInfo {
// For inlineasm !srcloc translation.
bool InlineAsmDiag;
- unsigned LocCookie;
+ uint64_t LocCookie;
public:
DiagnosticInfoSrcMgr(const SMDiagnostic &Diagnostic, StringRef ModName,
- bool InlineAsmDiag = true, unsigned LocCookie = 0)
+ bool InlineAsmDiag = true, uint64_t LocCookie = 0)
: DiagnosticInfo(DK_SrcMgr, getDiagnosticSeverity(Diagnostic.getKind())),
Diagnostic(Diagnostic), ModName(ModName), InlineAsmDiag(InlineAsmDiag),
LocCookie(LocCookie) {}
@@ -1088,7 +1088,7 @@ class DiagnosticInfoSrcMgr : public DiagnosticInfo {
StringRef getModuleName() const { return ModName; }
bool isInlineAsmDiag() const { return InlineAsmDiag; }
const SMDiagnostic &getSMDiag() const { return Diagnostic; }
- unsigned getLocCookie() const { return LocCookie; }
+ uint64_t getLocCookie() const { return LocCookie; }
void print(DiagnosticPrinter &DP) const override;
static bool classof(const DiagnosticInfo *DI) {
@@ -1101,16 +1101,16 @@ void diagnoseDontCall(const CallInst &CI);
class DiagnosticInfoDontCall : public DiagnosticInfo {
StringRef CalleeName;
StringRef Note;
- unsigned LocCookie;
+ uint64_t LocCookie;
public:
DiagnosticInfoDontCall(StringRef CalleeName, StringRef Note,
- DiagnosticSeverity DS, unsigned LocCookie)
+ DiagnosticSeverity DS, uint64_t LocCookie)
: DiagnosticInfo(DK_DontCall, DS), CalleeName(CalleeName), Note(Note),
LocCookie(LocCookie) {}
StringRef getFunctionName() const { return CalleeName; }
StringRef getNote() const { return Note; }
- unsigned getLocCookie() const { return LocCookie; }
+ uint64_t getLocCookie() const { return LocCookie; }
void print(DiagnosticPrinter &DP) const override;
static bool classof(const DiagnosticInfo *DI) {
return DI->getKind() == DK_DontCall;
diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp
index 1dba591d02b6c..b950f4fdbcf79 100644
--- a/llvm/lib/CodeGen/MachineModuleInfo.cpp
+++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp
@@ -185,7 +185,7 @@ INITIALIZE_PASS(MachineModuleInfoWrapperPass, "machinemoduleinfo",
"Machine Module Information", false, false)
char MachineModuleInfoWrapperPass::ID = 0;
-static unsigned getLocCookie(const SMDiagnostic &SMD, const SourceMgr &SrcMgr,
+static uint64_t getLocCookie(const SMDiagnostic &SMD, const SourceMgr &SrcMgr,
std::vector<const MDNode *> &LocInfos) {
// Look up a LocInfo for the buffer this diagnostic is coming from.
unsigned BufNum = SrcMgr.FindBufferContainingLoc(SMD.getLoc());
@@ -195,7 +195,7 @@ static unsigned getLocCookie(const SMDiagnostic &SMD, const SourceMgr &SrcMgr,
// If the inline asm had metadata associated with it, pull out a location
// cookie corresponding to which line the error occurred on.
- unsigned LocCookie = 0;
+ uint64_t LocCookie = 0;
if (LocInfo) {
unsigned ErrorLine = SMD.getLineNo() - 1;
if (ErrorLine >= LocInfo->getNumOperands())
@@ -218,7 +218,7 @@ bool MachineModuleInfoWrapperPass::doInitialization(Module &M) {
[&Ctx, &M](const SMDiagnostic &SMD, bool IsInlineAsm,
const SourceMgr &SrcMgr,
std::vector<const MDNode *> &LocInfos) {
- unsigned LocCookie = 0;
+ uint64_t LocCookie = 0;
if (IsInlineAsm)
LocCookie = getLocCookie(SMD, SrcMgr, LocInfos);
Ctx.diagnose(
diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp
index 31971b179fb4b..108bf68900595 100644
--- a/llvm/lib/IR/DiagnosticInfo.cpp
+++ b/llvm/lib/IR/DiagnosticInfo.cpp
@@ -432,7 +432,7 @@ void llvm::diagnoseDontCall(const CallInst &CI) {
auto Sev = i == 0 ? DS_Error : DS_Warning;
if (F->hasFnAttribute(AttrName)) {
- unsigned LocCookie = 0;
+ uint64_t LocCookie = 0;
auto A = F->getFnAttribute(AttrName);
if (MDNode *MD = CI.getMetadata("srcloc"))
LocCookie =
More information about the cfe-commits
mailing list