Skip to content

Commit 9f187bf

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. Also fix a ArgumentPromotion test due to adding DW_CC_nocall to debuginfo.
1 parent cda542d commit 9f187bf

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

llvm/lib/Transforms/IPO/ArgumentPromotion.cpp

Lines changed: 9 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,14 @@ doPromotion(Function *F, FunctionAnalysisManager &FAM,
432433
PromoteMemToReg(Allocas, DT, &AC);
433434
}
434435

436+
// DW_CC_nocall to DISubroutineType to inform debugger that it may not be safe
437+
// to call this function.
438+
DISubprogram *SP = NF->getSubprogram();
439+
if (SP) {
440+
auto Temp = SP->getType()->cloneWithCC(llvm::dwarf::DW_CC_nocall);
441+
SP->replaceType(MDNode::replaceWithPermanent(std::move(Temp)));
442+
}
443+
435444
return NF;
436445
}
437446

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)