Skip to content

Commit db3a47c

Browse files
authored
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.
1 parent 08fae46 commit db3a47c

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5760,7 +5760,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
57605760
// Add metadata if calling an __attribute__((error(""))) or warning fn.
57615761
if (TargetDecl && TargetDecl->hasAttr<ErrorAttr>()) {
57625762
llvm::ConstantInt *Line =
5763-
llvm::ConstantInt::get(Int32Ty, Loc.getRawEncoding());
5763+
llvm::ConstantInt::get(Int64Ty, Loc.getRawEncoding());
57645764
llvm::ConstantAsMetadata *MD = llvm::ConstantAsMetadata::get(Line);
57655765
llvm::MDTuple *MDT = llvm::MDNode::get(getLLVMContext(), {MD});
57665766
CI->setMetadata("srcloc", MDT);

clang/test/CodeGen/attr-error.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ void bar(void) {
88
// CHECK: call void @foo(), !srcloc [[SRCLOC:![0-9]+]]
99
// CHECK: declare{{.*}} void @foo() [[ATTR:#[0-9]+]]
1010
// CHECK: attributes [[ATTR]] = {{{.*}}"dontcall-error"="oh no"
11-
// CHECK: [[SRCLOC]] = !{i32 {{[0-9]+}}}
11+
// CHECK: [[SRCLOC]] = !{i64 {{[0-9]+}}}

clang/test/CodeGen/attr-warning.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ void bar(void) {
88
// CHECK: call void @foo(), !srcloc [[SRCLOC:![0-9]+]]
99
// CHECK: declare{{.*}} void @foo() [[ATTR:#[0-9]+]]
1010
// CHECK: attributes [[ATTR]] = {{{.*}}"dontcall-warn"="oh no"
11-
// CHECK: [[SRCLOC]] = !{i32 {{[0-9]+}}}
11+
// CHECK: [[SRCLOC]] = !{i64 {{[0-9]+}}}

llvm/docs/LangRef.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5658,7 +5658,7 @@ it. For example:
56585658

56595659
call void asm sideeffect "something bad", ""(), !srcloc !42
56605660
...
5661-
!42 = !{ i32 1234567 }
5661+
!42 = !{ i64 1234567 }
56625662

56635663
It is up to the front-end to make sense of the magic numbers it places
56645664
in the IR. If the MDNode contains multiple constants, the code generator

llvm/include/llvm/IR/DiagnosticInfo.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,19 +1076,19 @@ class DiagnosticInfoSrcMgr : public DiagnosticInfo {
10761076

10771077
// For inlineasm !srcloc translation.
10781078
bool InlineAsmDiag;
1079-
unsigned LocCookie;
1079+
uint64_t LocCookie;
10801080

10811081
public:
10821082
DiagnosticInfoSrcMgr(const SMDiagnostic &Diagnostic, StringRef ModName,
1083-
bool InlineAsmDiag = true, unsigned LocCookie = 0)
1083+
bool InlineAsmDiag = true, uint64_t LocCookie = 0)
10841084
: DiagnosticInfo(DK_SrcMgr, getDiagnosticSeverity(Diagnostic.getKind())),
10851085
Diagnostic(Diagnostic), ModName(ModName), InlineAsmDiag(InlineAsmDiag),
10861086
LocCookie(LocCookie) {}
10871087

10881088
StringRef getModuleName() const { return ModName; }
10891089
bool isInlineAsmDiag() const { return InlineAsmDiag; }
10901090
const SMDiagnostic &getSMDiag() const { return Diagnostic; }
1091-
unsigned getLocCookie() const { return LocCookie; }
1091+
uint64_t getLocCookie() const { return LocCookie; }
10921092
void print(DiagnosticPrinter &DP) const override;
10931093

10941094
static bool classof(const DiagnosticInfo *DI) {
@@ -1101,16 +1101,16 @@ void diagnoseDontCall(const CallInst &CI);
11011101
class DiagnosticInfoDontCall : public DiagnosticInfo {
11021102
StringRef CalleeName;
11031103
StringRef Note;
1104-
unsigned LocCookie;
1104+
uint64_t LocCookie;
11051105

11061106
public:
11071107
DiagnosticInfoDontCall(StringRef CalleeName, StringRef Note,
1108-
DiagnosticSeverity DS, unsigned LocCookie)
1108+
DiagnosticSeverity DS, uint64_t LocCookie)
11091109
: DiagnosticInfo(DK_DontCall, DS), CalleeName(CalleeName), Note(Note),
11101110
LocCookie(LocCookie) {}
11111111
StringRef getFunctionName() const { return CalleeName; }
11121112
StringRef getNote() const { return Note; }
1113-
unsigned getLocCookie() const { return LocCookie; }
1113+
uint64_t getLocCookie() const { return LocCookie; }
11141114
void print(DiagnosticPrinter &DP) const override;
11151115
static bool classof(const DiagnosticInfo *DI) {
11161116
return DI->getKind() == DK_DontCall;

llvm/lib/CodeGen/MachineModuleInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ INITIALIZE_PASS(MachineModuleInfoWrapperPass, "machinemoduleinfo",
185185
"Machine Module Information", false, false)
186186
char MachineModuleInfoWrapperPass::ID = 0;
187187

188-
static unsigned getLocCookie(const SMDiagnostic &SMD, const SourceMgr &SrcMgr,
188+
static uint64_t getLocCookie(const SMDiagnostic &SMD, const SourceMgr &SrcMgr,
189189
std::vector<const MDNode *> &LocInfos) {
190190
// Look up a LocInfo for the buffer this diagnostic is coming from.
191191
unsigned BufNum = SrcMgr.FindBufferContainingLoc(SMD.getLoc());
@@ -195,7 +195,7 @@ static unsigned getLocCookie(const SMDiagnostic &SMD, const SourceMgr &SrcMgr,
195195

196196
// If the inline asm had metadata associated with it, pull out a location
197197
// cookie corresponding to which line the error occurred on.
198-
unsigned LocCookie = 0;
198+
uint64_t LocCookie = 0;
199199
if (LocInfo) {
200200
unsigned ErrorLine = SMD.getLineNo() - 1;
201201
if (ErrorLine >= LocInfo->getNumOperands())
@@ -218,7 +218,7 @@ bool MachineModuleInfoWrapperPass::doInitialization(Module &M) {
218218
[&Ctx, &M](const SMDiagnostic &SMD, bool IsInlineAsm,
219219
const SourceMgr &SrcMgr,
220220
std::vector<const MDNode *> &LocInfos) {
221-
unsigned LocCookie = 0;
221+
uint64_t LocCookie = 0;
222222
if (IsInlineAsm)
223223
LocCookie = getLocCookie(SMD, SrcMgr, LocInfos);
224224
Ctx.diagnose(

llvm/lib/IR/DiagnosticInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ void llvm::diagnoseDontCall(const CallInst &CI) {
432432
auto Sev = i == 0 ? DS_Error : DS_Warning;
433433

434434
if (F->hasFnAttribute(AttrName)) {
435-
unsigned LocCookie = 0;
435+
uint64_t LocCookie = 0;
436436
auto A = F->getFnAttribute(AttrName);
437437
if (MDNode *MD = CI.getMetadata("srcloc"))
438438
LocCookie =

0 commit comments

Comments
 (0)