[clang] [Clang] Prevent potential null pointer dereferences (PR #117176)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 21 09:19:37 PST 2024


================
@@ -627,7 +627,7 @@ class Analyzer {
           IsNoexcept = isNoexcept(FD);
         } else if (auto *BD = dyn_cast<BlockDecl>(D)) {
           if (auto *TSI = BD->getSignatureAsWritten()) {
-            auto *FPT = TSI->getType()->getAs<FunctionProtoType>();
+            auto *FPT = TSI->getType()->castAs<FunctionProtoType>();
----------------
AaronBallman wrote:

This code path is hit from:
```
  if (Context.hasAnyFunctionEffects())
    performFunctionEffectAnalysis(Context.getTranslationUnitDecl());
```
and the only thing that sets `AnyFunctionEffects` is through a call to `ASTContext::getFunctionTypeInternal()`, which is only called for functions with prototypes. So I believe this change is correct as-is, but is a bit fragile.

CC @Sirraide @cjappl @dougsonos for extra eyes; are K&R C functions supposed to support function effects? If so, I suspect that doesn't work today.

https://github.com/llvm/llvm-project/pull/117176


More information about the cfe-commits mailing list