[clang] ba36556 - [InstrProfiling] Account for missing bitcast/GEP

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 23 07:39:57 PDT 2022


Author: Nikita Popov
Date: 2022-03-23T15:39:39+01:00
New Revision: ba365561455e467664df8c656f111b26fd1f81de

URL: https://github.com/llvm/llvm-project/commit/ba365561455e467664df8c656f111b26fd1f81de
DIFF: https://github.com/llvm/llvm-project/commit/ba365561455e467664df8c656f111b26fd1f81de.diff

LOG: [InstrProfiling] Account for missing bitcast/GEP

This code is supposed to clean up a constexpr bitcast/GEP, but
with opaque pointers this ends up dropping references to the
global.

Added: 
    

Modified: 
    clang/test/CoverageMapping/ir.c
    llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/CoverageMapping/ir.c b/clang/test/CoverageMapping/ir.c
index 7dd23943f701a..bd1eeb450d4c9 100644
--- a/clang/test/CoverageMapping/ir.c
+++ b/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) {}
@@ -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]]

diff  --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index dc5f2c01351d2..379c41ce66936 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -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();
 }


        


More information about the cfe-commits mailing list