Skip to content

Commit c4de78e

Browse files
committed
[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.
1 parent 69937a8 commit c4de78e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ bool ModuleSanitizerCoverage::instrumentModule(
469469
Constant *SanCovLowestStackConstant =
470470
M.getOrInsertGlobal(SanCovLowestStackName, IntptrTy);
471471
SanCovLowestStack = dyn_cast<GlobalVariable>(SanCovLowestStackConstant);
472-
if (!SanCovLowestStack) {
472+
if (!SanCovLowestStack || SanCovLowestStack->getValueType() != IntptrTy) {
473473
C->emitError(StringRef("'") + SanCovLowestStackName +
474474
"' should not be declared by the user");
475475
return true;

llvm/test/Instrumentation/SanitizerCoverage/stack-depth-variable-declared-by-user.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
; RUN: -sanitizer-coverage-stack-depth -S 2>&1 -enable-new-pm=0 | FileCheck %s
55
; RUN: not opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 \
66
; RUN: -sanitizer-coverage-stack-depth -S 2>&1 | FileCheck %s
7+
; RUN: not opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 \
8+
; RUN: -sanitizer-coverage-stack-depth -force-opaque-pointers -S 2>&1 | FileCheck %s
79

810
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
911
target triple = "x86_64-unknown-linux-gnu"

0 commit comments

Comments
 (0)