[PATCH] D64883: Add new warning -Walloca for use of builtin alloca function
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 25 13:38:42 PDT 2019
aaron.ballman marked an inline comment as done.
aaron.ballman added inline comments.
================
Comment at: clang/lib/Sema/SemaChecking.cpp:1172
return ExprError();
+ LLVM_FALLTHROUGH;
+ case Builtin::BI__builtin_alloca:
----------------
ziyig wrote:
> aaron.ballman wrote:
> > Do we want to warn on all uses of alloca(), or just the ones that get past the call to `SemaBuiltinAllocaWithAlign()`?
> I don't have strong opinion about this. Which one do you think is better?
I think the code is fine as-is. `SemaBuiltinAllocaWithAlign()` returns true when there's an error with the call, and so users will not get the warning only if the call is erroneous, which seems fine given that the code didn't compile. It turns out this matches GCC's behavior as well.
================
Comment at: clang/lib/Sema/SemaChecking.cpp:1175
+ Diag(TheCall->getBeginLoc(), diag::warn_alloca)
+ << TheCall->getDirectCallee()->getNameInfo().getAsString();
break;
----------------
You should pass in `TheCall->getDirectCallee()` and not try to get the name directly; the diagnostics engine will do the right thing automatically.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D64883/new/
https://reviews.llvm.org/D64883
More information about the cfe-commits
mailing list