[PATCH] D18540: [Sema] Note when we've actually encountered a failure in ExprConstant, and take that into account when looking up objects.

George Burgess IV via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 28 21:27:42 PDT 2016


george.burgess.iv created this revision.
george.burgess.iv added a reviewer: rsmith.
george.burgess.iv added a subscriber: cfe-commits.

This patch aims to fix a bug encountered by compiling code with C++14.

Specifically, when evaluating `p` in `__builtin_object_size(p, n)`, we start speculatively evaluating. Currently, clang pretends that side-effects have always occurred when we start speculatively evaluating. This prevents us from reading any locals in C++14. So, the following code compiles fine in C++11 mode, but fails to compile with C++14:

```
void foo(char *p) __attribute__((enable_if(__builtin_object_size(p, 0) != -1, "")));

void runFoo() {
  char buf[5];
  foo(buf);
}
```

This patch makes ExprConstant note when we've actually failed (read: may have an unmodeled side-effect), and makes us act as conservatively before if a failure happened. If a failure hasn't happened, we can be more aggressive.

http://reviews.llvm.org/D18540

Files:
  include/clang/AST/Expr.h
  lib/AST/ExprConstant.cpp
  test/SemaCXX/builtin-object-size-cxx14.cpp
  test/SemaCXX/constant-expression-cxx1y.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18540.51872.patch
Type: text/x-patch
Size: 15705 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160329/5242a51d/attachment-0001.bin>


More information about the cfe-commits mailing list