Skip to content
Commit 10c7c909 authored by Richard Smith's avatar Richard Smith
Browse files

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!

llvm-svn: 146236
parent 7033127b
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment