Skip to content

Commit c169d11

Browse files
author
Yonghong Song
committed
[ArgPromotion] Add DW_CC_nocall to DISubprogram
ArgumentPromotion pass may change function signatures. If this happens and debuginfo is enabled, let us add DW_CC_nocall to debuginfo so it is clear that the function signature has changed. DeadArgumentElimination ([1]) has similar implementation. Also fix an ArgumentPromotion test due to adding DW_CC_nocall to debuginfo. [1] 340b0ca
1 parent bfcd67c commit c169d11

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

llvm/lib/Transforms/IPO/ArgumentPromotion.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "llvm/IR/BasicBlock.h"
5151
#include "llvm/IR/CFG.h"
5252
#include "llvm/IR/Constants.h"
53+
#include "llvm/IR/DIBuilder.h"
5354
#include "llvm/IR/DataLayout.h"
5455
#include "llvm/IR/DerivedTypes.h"
5556
#include "llvm/IR/Dominators.h"
@@ -432,6 +433,16 @@ doPromotion(Function *F, FunctionAnalysisManager &FAM,
432433
PromoteMemToReg(Allocas, DT, &AC);
433434
}
434435

436+
// If argument(s) are dead (hence removed) or promoted, probably the function
437+
// does not follow standard calling convention anymore. Add DW_CC_nocall to
438+
// DISubroutineType to inform debugger that it may not be safe to call this
439+
// function.
440+
DISubprogram *SP = NF->getSubprogram();
441+
if (SP) {
442+
auto Temp = SP->getType()->cloneWithCC(llvm::dwarf::DW_CC_nocall);
443+
SP->replaceType(MDNode::replaceWithPermanent(std::move(Temp)));
444+
}
445+
435446
return NF;
436447
}
437448

llvm/test/Transforms/ArgumentPromotion/dbg.ll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ define void @caller(ptr %Y, ptr %P) {
5353

5454
!0 = !{i32 2, !"Debug Info Version", i32 3}
5555
!1 = !DILocation(line: 8, scope: !2)
56-
!2 = distinct !DISubprogram(name: "test", file: !5, line: 3, isLocal: true, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !3, scopeLine: 3, scope: null)
56+
!2 = distinct !DISubprogram(name: "test", file: !5, line: 3, type: !7, isLocal: true, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, unit: !3, scopeLine: 3, scope: null)
5757
!3 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 ", isOptimized: false, emissionKind: LineTablesOnly, file: !5)
5858
!5 = !DIFile(filename: "test.c", directory: "")
5959
!6 = !DILocation(line: 9, scope: !2)
60+
!7 = !DISubroutineType(types: !8)
61+
!8 = !{null, !9}
62+
!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10)
63+
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)

0 commit comments

Comments
 (0)