[Flang] Fix usage of uninitialized resolution variable
authorPaul Scoropan <1paulscoropan@gmail.com>
Wed, 5 Apr 2023 14:31:16 +0000 (14:31 +0000)
committerPaul Scoropan <1paulscoropan@gmail.com>
Wed, 5 Apr 2023 15:00:56 +0000 (15:00 +0000)
Recent Flang PowerPC intrinsics patch used resolution variable without checking if it exists first, causing segmentation faults in some scenarios. This patch checks that the resolution variable exists first before usage.

Reviewed By: DanielCChen

Differential Revision: https://reviews.llvm.org/D147616

flang/lib/Semantics/expression.cpp

index 06226f2..cec936c 100644 (file)
@@ -2518,12 +2518,12 @@ auto ExpressionAnalyzer::GetCalleeAndArguments(const parser::Name &name,
         mightBeStructureConstructor)};
     resolution = pair.first;
     dueToAmbiguity = pair.second;
-    if (context_.GetPPCBuiltinsScope() &&
-        resolution->name().ToString().rfind("__ppc_", 0) == 0) {
-      semantics::CheckPPCIntrinsic(
-          *symbol, *resolution, arguments, GetFoldingContext());
-    }
     if (resolution) {
+      if (context_.GetPPCBuiltinsScope() &&
+          resolution->name().ToString().rfind("__ppc_", 0) == 0) {
+        semantics::CheckPPCIntrinsic(
+            *symbol, *resolution, arguments, GetFoldingContext());
+      }
       // re-resolve name to the specific procedure
       name.symbol = const_cast<Symbol *>(resolution);
     }