[PATCH] D13263: Addition of __attribute__((pass_object_size)) to Clang

George Burgess IV via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 29 11:46:40 PDT 2015


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

This was a fun patch :)

This patch adds the parameter attribute `pass_object_size` to Clang. The design doc for this attribute is available here: https://docs.google.com/document/d/14TwNLxFL_jhiYn7_kppNUDiaTopRAIY5bc-B8NcnKMM/edit?usp=sharing

General notes:

- Never mangled things before, so I'm open to any suggestions on how to make the mangling for pass_object_size better :)
- There's a tiny diagnostics bugfix in here -- I'm happy to make that its own patch. (See: `tryGetFunctionProtoType` in SemaOverload.cpp)
- A lot of the additions to Sema (anything that's a boolean named like `TakingCandidateAddress`) are to improve diagnostics on templated functions with pass_object_size on their parameters. I'm happy to simplify the diff a bit if we think that the improved diag ("functions with pass_object_size params cannot have their address taken" vs "assigning to 'int (*)(void *)' from incompatible type 'int (void *const pass_object_size)'") isn't worth the extra cruft.

@rsmith: Other than the name change, the design has changed (since the last time we talked) such that having `pass_object_size(N)` on some parameter P makes the function act like there's an enable_if that disables the function if we can't determine the object size of P at the callsite. More concretely:

- One can no longer take the address of a function with `pass_object_size`
- If an overload candidate parameter with `pass_object_size` on it cannot have its object size determined, then the candidate is not viable.
  - If there's no overloading going on at all (e.g. in C), it's still an error to call a function with `pass_object_size` on one or more of its params if the object size of that param can't be determined.

http://reviews.llvm.org/D13263

Files:
  include/clang/AST/Expr.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Initialization.h
  include/clang/Sema/Overload.h
  include/clang/Sema/Sema.h
  include/clang/Sema/TemplateDeduction.h
  lib/AST/ASTContext.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/pass-object-size.c
  test/Sema/pass-object-size.c
  test/SemaCXX/pass-object-size.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13263.36014.patch
Type: text/x-patch
Size: 87497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150929/7348382f/attachment-0001.bin>


More information about the cfe-commits mailing list