[SanitizerCoverage] Clang crashes if user declares `__sancov_lowest_stack` variable
commit11ecb01af0732e06e21ad73b1e2cb50378545940
authorJulian Lettner <jlettner@apple.com>
Mon, 4 Feb 2019 22:06:30 +0000 (4 22:06 +0000)
committerJulian Lettner <jlettner@apple.com>
Mon, 4 Feb 2019 22:06:30 +0000 (4 22:06 +0000)
tree5b6be73edc0ab261f0d897dcbe0402bcf85c6e9d
parenta43daae17e062c7f4e0c765d3b3393f0bcd925a2
[SanitizerCoverage] Clang crashes if user declares `__sancov_lowest_stack` variable

Summary:
If the user declares or defines `__sancov_lowest_stack` with an
unexpected type, then `getOrInsertGlobal` inserts a bitcast and the
following cast fails:
```
Constant *SanCovLowestStackConstant =
       M.getOrInsertGlobal(SanCovLowestStackName, IntptrTy);
SanCovLowestStack = cast<GlobalVariable>(SanCovLowestStackConstant);
```

This variable is a SanitizerCoverage implementation detail and the user
should generally never have a need to access it, so we emit an error
now.

rdar://problem/44143130

Reviewers: morehouse

Differential Revision: https://reviews.llvm.org/D57633

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353100 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Instrumentation/SanitizerCoverage.cpp
test/Instrumentation/SanitizerCoverage/stack-depth-variable-declared-by-user.ll [new file with mode: 0644]