Skip to content

Commit 7d4a45d

Browse files
committed
Revert "Add option to generate additional debug info for expression dereferencing pointer to pointers. (#81545)"
This reverts commit aeccfee, and dependents: Revert "[NFC] Fix PPC buildbot failure https://lab.llvm.org/buildbot/#/builders/230/builds/29066" This reverts commit 2b1d1c5. Revert "Fix test - remove unnecessary/incorrect `-S`, in favor of `-emit-llvm`" This reverts commit ea1ecb5. The test is failing on MacOs and Windows
1 parent 8890209 commit 7d4a45d

File tree

4 files changed

+1
-230
lines changed

4 files changed

+1
-230
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5737,90 +5737,6 @@ void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
57375737
Var->addDebugInfo(GVE);
57385738
}
57395739

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

clang/lib/CodeGen/CGDebugInfo.h

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

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

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)