Skip to content

Commit

Permalink
[InstrProfiling] Account for missing bitcast/GEP
Browse files Browse the repository at this point in the history
This code is supposed to clean up a constexpr bitcast/GEP, but
with opaque pointers this ends up dropping references to the
global.
  • Loading branch information
nikic committed Mar 23, 2022
1 parent 5c6752d commit ba36556
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions clang/test/CoverageMapping/ir.c
@@ -1,5 +1,6 @@
// Check the data structures emitted by coverage mapping
// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple x86_64-apple-macosx10.9 -main-file-name ir.c %s -o - -emit-llvm -fprofile-instrument=clang -fcoverage-mapping -mllvm -enable-name-compression=false | FileCheck %s -check-prefixes=COMMON,DARWIN
// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple x86_64-apple-macosx10.9 -main-file-name ir.c %s -o - -emit-llvm -fprofile-instrument=clang -fcoverage-mapping -mllvm -enable-name-compression=false -mllvm -opaque-pointers=0 | FileCheck %s -check-prefixes=COMMON,DARWIN
// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple x86_64-apple-macosx10.9 -main-file-name ir.c %s -o - -emit-llvm -fprofile-instrument=clang -fcoverage-mapping -mllvm -enable-name-compression=false -mllvm -opaque-pointers=1 | FileCheck %s -check-prefixes=COMMON,DARWIN
// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple x86_64--windows-msvc -main-file-name ir.c %s -o - -emit-llvm -fprofile-instrument=clang -fcoverage-mapping -mllvm -enable-name-compression=false | FileCheck %s -check-prefixes=COMMON,WINDOWS

static inline void unused(void) {}
Expand All @@ -24,7 +25,7 @@ int main(void) {
// WINDOWS: [[FuncRecord3:@__covrec_[0-9A-F]+]] = linkonce_odr hidden constant <{ i64, i32, i64, i64, [{{.*}} x i8] }> <{ {{.*}} }>, section ".lcovfun$M", comdat, align 8
// WINDOWS: @__llvm_coverage_mapping = private constant { { i32, i32, i32, i32 }, [{{.*}} x i8] } { {{.*}} }, section ".lcovmap$M", align 8

// COMMON: @llvm.used = appending global [{{.*}} x i8*]
// COMMON: @llvm.used = appending global [{{.*}}] [
// COMMON-SAME: [[FuncRecord1]]
// COMMON-SAME: [[FuncRecord2]]
// COMMON-SAME: [[FuncRecord3]]
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
Expand Up @@ -767,7 +767,8 @@ void InstrProfiling::lowerCoverageData(GlobalVariable *CoverageNamesVar) {

Name->setLinkage(GlobalValue::PrivateLinkage);
ReferencedNames.push_back(Name);
NC->dropAllReferences();
if (isa<ConstantExpr>(NC))
NC->dropAllReferences();
}
CoverageNamesVar->eraseFromParent();
}
Expand Down

0 comments on commit ba36556

Please sign in to comment.