[flang-commits] [flang] 85779e5 - [flang] Silence "used but undefined" warning for LOC(x) (#174807)

via flang-commits flang-commits at lists.llvm.org
Thu Jan 8 08:58:29 PST 2026


Author: Peter Klausler
Date: 2026-01-08T08:58:25-08:00
New Revision: 85779e547b00b377aa9675bcd80b1c20d0522d18

URL: https://github.com/llvm/llvm-project/commit/85779e547b00b377aa9675bcd80b1c20d0522d18
DIFF: https://github.com/llvm/llvm-project/commit/85779e547b00b377aa9675bcd80b1c20d0522d18.diff

LOG: [flang] Silence "used but undefined" warning for LOC(x) (#174807)

When a variable appears as the argument of the extension intrinsic
function LOC(x), assume that it's defined for the purposes of the
warning about variables that are used but never defined, since the
result of the LOC() can be used to define a based Cray pointer.

Added: 
    flang/test/Semantics/bug2021.f90

Modified: 
    flang/lib/Semantics/check-call.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 58b8c248147e4..c7150acab33f2 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -783,7 +783,8 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
         }
       }
     } else if (dummy.intent != common::Intent::In ||
-        (dummyIsPointer && !actualIsPointer)) {
+        (dummyIsPointer && !actualIsPointer) ||
+        (intrinsic && intrinsic->name == "loc")) {
       if (auto named{evaluate::ExtractNamedEntity(actual)}) {
         context.NoteDefinedSymbol(named->GetFirstSymbol());
       }

diff  --git a/flang/test/Semantics/bug2021.f90 b/flang/test/Semantics/bug2021.f90
new file mode 100644
index 0000000000000..f5214bce946a9
--- /dev/null
+++ b/flang/test/Semantics/bug2021.f90
@@ -0,0 +1,8 @@
+!RUN: %flang -fc1 -fsyntax-only -pedantic %s 2>&1 | FileCheck %s
+!CHECK-NOT: warning: Value of uninitialized local variable 'b' is used but never defined [-Wused-undefined-variable]
+real :: a, b
+pointer(p,a)
+p = loc(b)
+a = 2.0
+print *, b
+end


        


More information about the flang-commits mailing list