Skip to content

Commit 3fce145

Browse files
authored
Revert "Add option to generate additional debug info for expression dereferencing pointer to pointers. #94100" (#95174)
The option is causing the binary output to be different when compiled under `-O0`, because it introduce dbg.declare on pseudovariables. Going to change this implementation to use dbg.value instead.
1 parent 438a7d4 commit 3fce145

File tree

4 files changed

+1
-218
lines changed

4 files changed

+1
-218
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5746,78 +5746,6 @@ void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
57465746
Var->addDebugInfo(GVE);
57475747
}
57485748

5749-
void CGDebugInfo::EmitPseudoVariable(CGBuilderTy &Builder,
5750-
llvm::Instruction *Value, QualType Ty) {
5751-
// Only when -g2 or above is specified, debug info for variables will be
5752-
// generated.
5753-
if (CGM.getCodeGenOpts().getDebugInfo() <=
5754-
llvm::codegenoptions::DebugLineTablesOnly)
5755-
return;
5756-
5757-
llvm::DebugLoc SaveDebugLoc = Builder.getCurrentDebugLocation();
5758-
if (!SaveDebugLoc.get())
5759-
return;
5760-
5761-
llvm::DIFile *Unit = SaveDebugLoc->getFile();
5762-
llvm::DIType *Type = getOrCreateType(Ty, Unit);
5763-
5764-
// Check if Value is already a declared variable and has debug info, in this
5765-
// case we have nothing to do. Clang emits declared variable as alloca, and
5766-
// it is loaded upon use, so we identify such pattern here.
5767-
if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(Value)) {
5768-
llvm::Value *Var = Load->getPointerOperand();
5769-
// There can be implicit type cast applied on a variable if it is an opaque
5770-
// ptr, in this case its debug info may not match the actual type of object
5771-
// being used as in the next instruction, so we will need to emit a pseudo
5772-
// variable for type-casted value.
5773-
auto DeclareTypeMatches = [&](auto *DbgDeclare) {
5774-
return DbgDeclare->getVariable()->getType() == Type;
5775-
};
5776-
if (any_of(llvm::findDbgDeclares(Var), DeclareTypeMatches) ||
5777-
any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
5778-
return;
5779-
}
5780-
5781-
// Find the correct location to insert a sequence of instructions to
5782-
// materialize Value on the stack.
5783-
auto SaveInsertionPoint = Builder.saveIP();
5784-
if (llvm::InvokeInst *Invoke = dyn_cast<llvm::InvokeInst>(Value))
5785-
Builder.SetInsertPoint(Invoke->getNormalDest()->begin());
5786-
else if (llvm::Instruction *Next = Value->getIterator()->getNextNode())
5787-
Builder.SetInsertPoint(Next);
5788-
else
5789-
Builder.SetInsertPoint(Value->getParent());
5790-
llvm::DebugLoc DL = Value->getDebugLoc();
5791-
if (DL.get())
5792-
Builder.SetCurrentDebugLocation(DL);
5793-
else if (!Builder.getCurrentDebugLocation().get())
5794-
Builder.SetCurrentDebugLocation(SaveDebugLoc);
5795-
5796-
llvm::AllocaInst *PseudoVar = Builder.CreateAlloca(Value->getType());
5797-
Address PseudoVarAddr(PseudoVar, Value->getType(),
5798-
CharUnits::fromQuantity(PseudoVar->getAlign()));
5799-
llvm::LoadInst *Load = Builder.CreateLoad(PseudoVarAddr);
5800-
Value->replaceAllUsesWith(Load);
5801-
Builder.SetInsertPoint(Load);
5802-
Builder.CreateStore(Value, PseudoVarAddr);
5803-
5804-
// Emit debug info for materialized Value.
5805-
unsigned Line = Builder.getCurrentDebugLocation().getLine();
5806-
unsigned Column = Builder.getCurrentDebugLocation().getCol();
5807-
llvm::DILocalVariable *D = DBuilder.createAutoVariable(
5808-
LexicalBlockStack.back(), "", nullptr, 0, Type, false,
5809-
llvm::DINode::FlagArtificial);
5810-
llvm::DILocation *DIL =
5811-
llvm::DILocation::get(CGM.getLLVMContext(), Line, Column,
5812-
LexicalBlockStack.back(), CurInlinedAt);
5813-
SmallVector<uint64_t> Expr;
5814-
DBuilder.insertDeclare(PseudoVar, D, DBuilder.createExpression(Expr), DIL,
5815-
Load);
5816-
5817-
Builder.restoreIP(SaveInsertionPoint);
5818-
Builder.SetCurrentDebugLocation(SaveDebugLoc);
5819-
}
5820-
58215749
void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV,
58225750
const GlobalDecl GD) {
58235751

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,12 +530,6 @@ class CGDebugInfo {
530530
/// Emit information about an external variable.
531531
void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
532532

533-
/// Emit a pseudo variable and debug info for an intermediate value if it does
534-
/// not correspond to a variable in the source code, so that a profiler can
535-
/// track more accurate usage of certain instructions of interest.
536-
void EmitPseudoVariable(CGBuilderTy &Builder, llvm::Instruction *Value,
537-
QualType Ty);
538-
539533
/// Emit information about global variable alias.
540534
void EmitGlobalAlias(const llvm::GlobalValue *GV, const GlobalDecl Decl);
541535

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,26 +1937,7 @@ Value *ScalarExprEmitter::VisitMemberExpr(MemberExpr *E) {
19371937
}
19381938
}
19391939

1940-
llvm::Value *Result = EmitLoadOfLValue(E);
1941-
1942-
// If -fdebug-info-for-profiling is specified, emit a pseudo variable and its
1943-
// debug info for the pointer, even if there is no variable associated with
1944-
// the pointer's expression.
1945-
if (CGF.CGM.getCodeGenOpts().DebugInfoForProfiling && CGF.getDebugInfo()) {
1946-
if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(Result)) {
1947-
if (llvm::GetElementPtrInst *GEP =
1948-
dyn_cast<llvm::GetElementPtrInst>(Load->getPointerOperand())) {
1949-
if (llvm::Instruction *Pointer =
1950-
dyn_cast<llvm::Instruction>(GEP->getPointerOperand())) {
1951-
QualType Ty = E->getBase()->getType();
1952-
if (!E->isArrow())
1953-
Ty = CGF.getContext().getPointerType(Ty);
1954-
CGF.getDebugInfo()->EmitPseudoVariable(Builder, Pointer, Ty);
1955-
}
1956-
}
1957-
}
1958-
}
1959-
return Result;
1940+
return EmitLoadOfLValue(E);
19601941
}
19611942

19621943
Value *ScalarExprEmitter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {

clang/test/CodeGenCXX/debug-info-ptr-to-ptr.cpp

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)