From c4de78e91c9341b5b1abf927da15e0956a484b79 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 29 Jun 2021 20:29:10 +0200 Subject: [PATCH] [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. --- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp | 2 +- .../SanitizerCoverage/stack-depth-variable-declared-by-user.ll | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp index 52670dad777e..d8720c37305b 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(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 f44c3e0c458f..e3d225fd1db6 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"