[llvm] c4de78e - [SanitizerCoverage] Fix global type check with opaque pointers

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 29 11:32:24 PDT 2021


Author: Nikita Popov
Date: 2021-06-29T20:32:14+02:00
New Revision: c4de78e91c9341b5b1abf927da15e0956a484b79

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

LOG: [SanitizerCoverage] Fix global type check with opaque pointers

The code was previously relying on the fact that an incorrectly
typed global would result in the insertion of a BitCast constant
expression. With opaque pointers, this is no longer the case, so
we should check the type explicitly.

Added: 
    

Modified: 
    llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
    llvm/test/Instrumentation/SanitizerCoverage/stack-depth-variable-declared-by-user.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index 52670dad777e0..d8720c37305b6 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -469,7 +469,7 @@ bool ModuleSanitizerCoverage::instrumentModule(
   Constant *SanCovLowestStackConstant =
       M.getOrInsertGlobal(SanCovLowestStackName, IntptrTy);
   SanCovLowestStack = dyn_cast<GlobalVariable>(SanCovLowestStackConstant);
-  if (!SanCovLowestStack) {
+  if (!SanCovLowestStack || SanCovLowestStack->getValueType() != IntptrTy) {
     C->emitError(StringRef("'") + SanCovLowestStackName +
                  "' should not be declared by the user");
     return true;

diff  --git a/llvm/test/Instrumentation/SanitizerCoverage/stack-depth-variable-declared-by-user.ll b/llvm/test/Instrumentation/SanitizerCoverage/stack-depth-variable-declared-by-user.ll
index f44c3e0c458f5..e3d225fd1db68 100644
--- a/llvm/test/Instrumentation/SanitizerCoverage/stack-depth-variable-declared-by-user.ll
+++ b/llvm/test/Instrumentation/SanitizerCoverage/stack-depth-variable-declared-by-user.ll
@@ -4,6 +4,8 @@
 ; RUN:         -sanitizer-coverage-stack-depth -S 2>&1 -enable-new-pm=0 | FileCheck %s
 ; RUN: not opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 \
 ; RUN:         -sanitizer-coverage-stack-depth -S 2>&1 | FileCheck %s
+; RUN: not opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 \
+; RUN:         -sanitizer-coverage-stack-depth -force-opaque-pointers -S 2>&1 | FileCheck %s
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"


        


More information about the llvm-commits mailing list