diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-09 02:04:48 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-09 02:04:48 +0000 |
commit | e052d46f4db91f9ba572859ffc984e85cbf5d5ff (patch) | |
tree | 9baebdec96646ad35d1242ca1f844311acab7d39 /lib/Analysis/FormatString.cpp | |
parent | 6a1db484f32eb791840dd55a8d45c86ff5bd0834 (diff) |
Replace the implementation of __builtin_constant_p (which was based on the GCC
documentation) with one based on what GCC's __builtin_constant_p is actually
intended to do (discovered by asking a friendly GCC developer).
In particular, an expression which folds to a pointer is now only considered to
be a "constant" by this builtin if it refers to the first character in a string
literal.
This fixes a rather subtle wrong-code issue when building with glibc. Given:
const char cs[4] = "abcd";
int f(const char *p) { return strncmp(p, cs, 4); }
... the macro magic for strncmp produces a (potentially crashing) call to
strlen(cs), because it expands to an expression starting with:
__builtin_constant_p(cs) && strlen(cs) < 4 ? /* ... */
Under the secret true meaning of __builtin_constant_p, this is guaranteed to be
safe!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146236 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/FormatString.cpp')
0 files changed, 0 insertions, 0 deletions