[PATCH] D48734: [Sema] Consider all format_arg attributes.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 29 05:41:04 PDT 2018


aaron.ballman added inline comments.


================
Comment at: lib/Sema/SemaChecking.cpp:5523
+      StringLiteralCheckType CommonResult;
+      for (const FormatArgAttr *FA : ND->specific_attrs<FormatArgAttr>()) {
         const Expr *Arg = CE->getArg(FA->getFormatIdx().getASTIndex());
----------------
You can use `const auto *FA` here instead; the type is spelled out in the initializer.


================
Comment at: lib/Sema/SemaChecking.cpp:5536
+
+      if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
         unsigned BuiltinID = FD->getBuiltinID();
----------------
`const auto *`


================
Comment at: test/Sema/attr-format_arg.c:17
+
+  printf(h("", ""), 123); // expected-warning 2{{format string is empty}}
 }
----------------
Can you add tests for the other permutations as well? It would also be useful to put the string literals on their own line so that the expected-warning designation matches the specific argument that's being diagnosed. e.g.,
```
h(
  "%d",
  ""
)
h(
  "", 
  "%d"
)
h(
  "%d",
  "%d"
)
```



Repository:
  rC Clang

https://reviews.llvm.org/D48734





More information about the cfe-commits mailing list