llvm-project/clang/lib/AST
George Burgess IV f8f6324983 [Sema] Fix PR30346: relax __builtin_object_size checks.
This patch makes us act more conservatively when trying to determine
the objectsize for an array at the end of an object. This is in
response to code like the following:

```
struct sockaddr {
  /* snip */
  char sa_data[14];
};

void foo(const char *s) {
  size_t slen = strlen(s) + 1;
  size_t added_len = slen <= 14 ? 0 : slen - 14;
  struct sockaddr *sa = malloc(sizeof(struct sockaddr) + added_len);
  strcpy(sa->sa_data, s);
  // ...
}
```

`__builtin_object_size(sa->sa_data, 1)` would return 14, when there
could be more than 14 bytes at `sa->sa_data`.

Code like this is apparently not uncommon. FreeBSD's manual even
explicitly mentions this pattern:
https://www.freebsd.org/doc/en/books/developers-handbook/sockets-essential-functions.html
(section 7.5.1.1.2).

In light of this, we now just give up on any array at the end of an
object if we can't find the object's initial allocation.

I lack numbers for how much more conservative we actually become as a
result of this change, so I chose the fix that would make us as
compatible with GCC as possible. If we want to be more aggressive, I'm
happy to consider some kind of whitelist or something instead.

llvm-svn: 281277
2016-09-12 23:50:35 +00:00
..
APValue.cpp [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
ASTConsumer.cpp Move LocInfoType from Sema to AST. 2016-02-01 17:42:01 +00:00
ASTContext.cpp Remove a pointless LLVM_CONSTEXPR. NFC. 2016-08-25 01:54:37 +00:00
ASTDiagnostic.cpp Fix typos from r277797 and unused variable from r277889. 2016-08-06 01:44:06 +00:00
ASTDumper.cpp P0217R3: Perform semantic checks and initialization for the bindings in a 2016-08-11 22:25:46 +00:00
ASTImporter.cpp Reapply r276069 with workaround for MSVC 2013 2016-07-30 22:33:34 +00:00
ASTTypeTraits.cpp [ASTMatcher] Add templateName matcher. 2016-07-29 15:45:11 +00:00
AttrImpl.cpp [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
CMakeLists.txt Move functions declared in Stmt{ObjC,CXX}.h and OpenMPClause.h into 2015-10-02 13:41:04 +00:00
CXXABI.h [MS ABI] Correctly mangle classes without names for linkage purposes 2015-08-31 18:48:39 +00:00
CXXInheritance.cpp [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
Comment.cpp [Sema][Comments] Add support for TypeAliasTemplate 2016-08-25 17:09:33 +00:00
CommentBriefParser.cpp [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
CommentCommandTraits.cpp Fix for PR21254 - Assertion in comment parser 2014-10-15 16:18:20 +00:00
CommentLexer.cpp Fix some Clang-tidy readability-redundant-control-flow warnings; other minor fixes. 2016-02-10 19:11:58 +00:00
CommentParser.cpp [C++11] Use 'nullptr'. AST edition. 2014-05-12 05:36:57 +00:00
CommentSema.cpp AST: improve layout of SimpleTypoCorrector 2016-08-28 21:33:30 +00:00
Decl.cpp C++ Modules TS: Add parsing and some semantic analysis support for 2016-09-08 23:14:54 +00:00
DeclBase.cpp Modules: revert r280728. 2016-09-09 19:03:07 +00:00
DeclCXX.cpp Lazily load the ContextDecl for a lambda's DefinitionData, to fix a 2016-08-25 00:34:00 +00:00
DeclFriend.cpp [TrailingObjects] Convert Decl* classes. 2015-12-29 22:13:13 +00:00
DeclGroup.cpp [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
DeclObjC.cpp Fix ObjCMethodDecl::findPropertyDecl for class properties. 2016-03-11 21:14:40 +00:00
DeclOpenMP.cpp [OPENMP 4.0] Initial support for 'omp declare reduction' construct. 2016-03-03 05:21:39 +00:00
DeclPrinter.cpp Teach -ast-print to print constexpr variables. 2016-07-08 21:09:08 +00:00
DeclTemplate.cpp Reapply r276069 with workaround for MSVC 2013 2016-07-30 22:33:34 +00:00
DeclarationName.cpp [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
Expr.cpp P0217R3: Perform semantic checks and initialization for the bindings in a 2016-08-11 22:25:46 +00:00
ExprCXX.cpp Re-commit "[Temporary] Add an ExprWithCleanups for each C++ MaterializeTemporaryExpr." 2016-06-21 20:29:17 +00:00
ExprClassification.cpp P0217R3: Perform semantic checks and initialization for the bindings in a 2016-08-11 22:25:46 +00:00
ExprConstant.cpp [Sema] Fix PR30346: relax __builtin_object_size checks. 2016-09-12 23:50:35 +00:00
ExprObjC.cpp [TrailingObjects] Fix bug in "Convert classes in ExprObjC.h" 2015-12-31 06:01:19 +00:00
ExternalASTSource.cpp Roll-back r250822. 2015-10-20 13:23:58 +00:00
InheritViz.cpp InheritViz: Hide implementation details 2015-03-09 15:03:20 +00:00
ItaniumCXXABI.cpp [MS ABI] Correctly mangle classes without names for linkage purposes 2015-08-31 18:48:39 +00:00
ItaniumMangle.cpp P0217R3: code generation support for decomposition declarations. 2016-08-15 01:33:41 +00:00
Mangle.cpp Make TargetInfo store an actual DataLayout instead of a string. 2016-03-04 19:00:41 +00:00
MicrosoftCXXABI.cpp Update for LLVM function name change. 2016-01-14 21:00:27 +00:00
MicrosoftMangle.cpp P0217R3: code generation support for decomposition declarations. 2016-08-15 01:33:41 +00:00
NSAPI.cpp Enable support for __float128 in Clang and enable it on pertinent platforms 2016-05-09 08:52:33 +00:00
NestedNameSpecifier.cpp [AST] Use ArrayRef in more interfaces 2016-07-07 04:43:07 +00:00
OpenMPClause.cpp [OpenMP] Code generation for the is_device_ptr clause 2016-07-28 14:25:09 +00:00
ParentMap.cpp [arcmt/objcmt] Fix ParentMap crash with invalid code. 2016-07-14 20:21:16 +00:00
RawCommentList.cpp Allow any comment to be a trailing comment when -fparse-all-comments is on. 2015-07-15 19:13:39 +00:00
RecordLayout.cpp [RecordLayout] Use an ASTVector instead of using a separate pointer and counter 2016-05-24 18:10:50 +00:00
RecordLayoutBuilder.cpp [RecordLayout] Use an ASTVector instead of using a separate pointer and counter 2016-05-24 18:10:50 +00:00
SelectorLocationsKind.cpp
Stmt.cpp [ObjC] Warn on unguarded use of partial declaration 2016-08-16 17:44:11 +00:00
StmtCXX.cpp Revert accidential "[MSVC] Late parsing of in-class defined member functions in template" 2016-06-15 11:24:54 +00:00
StmtIterator.cpp [ptr-traits] Stop using two bogus types as stand-ins for flags 2015-12-30 02:51:00 +00:00
StmtObjC.cpp Move functions declared in Stmt{ObjC,CXX}.h and OpenMPClause.h into 2015-10-02 13:41:04 +00:00
StmtOpenMP.cpp Revert "[OpenMP] Sema and parsing for 'teams distribute simd’ pragma" 2016-08-18 09:25:07 +00:00
StmtPrinter.cpp Revert "[OpenMP] Sema and parsing for 'teams distribute simd’ pragma" 2016-08-18 09:25:07 +00:00
StmtProfile.cpp [AST] Remove unused function, to silence a GCC7 warning. 2016-08-22 21:33:12 +00:00
StmtViz.cpp
TemplateBase.cpp Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith r259192 post commit comment. 2016-01-29 19:38:18 +00:00
TemplateName.cpp Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith r259192 post commit comment. 2016-01-29 19:38:18 +00:00
Type.cpp Revert r279351 and r279357 due to bot failures 2016-08-20 03:00:54 +00:00
TypeLoc.cpp [NFC] Header cleanup 2016-07-18 19:02:11 +00:00
TypePrinter.cpp [AST] Use ArrayRef in more interfaces 2016-07-07 04:43:07 +00:00
VTTBuilder.cpp Update for LLVM API change to make Small(Ptr)Set::insert return pair<iterator, bool> as per the C++ standard's associative container concept. 2014-11-19 07:49:47 +00:00
VTableBuilder.cpp [MS] Improve VPtrInfo field names and doc comments 2016-07-20 14:40:25 +00:00