[flang-commits] [flang] 73b83be - [flang] Add warning and documentation for extension (#179708)
via flang-commits
flang-commits at lists.llvm.org
Fri Feb 6 09:32:21 PST 2026
Author: Peter Klausler
Date: 2026-02-06T09:32:16-08:00
New Revision: 73b83be1c9b3fd3c844a789d26e2a08d8f7caf62
URL: https://github.com/llvm/llvm-project/commit/73b83be1c9b3fd3c844a789d26e2a08d8f7caf62
DIFF: https://github.com/llvm/llvm-project/commit/73b83be1c9b3fd3c844a789d26e2a08d8f7caf62.diff
LOG: [flang] Add warning and documentation for extension (#179708)
When a pointer component has no default initialization in the derived
type definition and does not appear explicitly as a component in a
structure constructor, we assume that it is meant to be NULL() as an
extension. But there's no warning or documentation for this extension;
add them.
Fixes https://github.com/llvm/llvm-project/issues/179580.
Added:
flang/test/Semantics/bug179580.f90
Modified:
flang/docs/Extensions.md
flang/include/flang/Support/Fortran-features.h
flang/lib/Semantics/expression.cpp
Removed:
################################################################################
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 493bb10af6f85..79e6213f7f3c9 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -481,6 +481,8 @@ end
* A data object can be initialized multiple times by `DATA` statements
and default component initialization, but only when all initializations
are to the same value. Distinct initializations remain errors.
+* A pointer component that has no default initialization or explicit value
+ in a structure constructor is defaulted to `NULL()`.
### Extensions supported when enabled by options
diff --git a/flang/include/flang/Support/Fortran-features.h b/flang/include/flang/Support/Fortran-features.h
index c705e031eff9d..fa300da48ffe1 100644
--- a/flang/include/flang/Support/Fortran-features.h
+++ b/flang/include/flang/Support/Fortran-features.h
@@ -56,7 +56,8 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
IgnoreIrrelevantAttributes, Unsigned, ContiguousOkForSeqAssociation,
ForwardRefExplicitTypeDummy, InaccessibleDeferredOverride,
CudaWarpMatchFunction, DoConcurrentOffload, TransferBOZ, Coarray,
- PointerPassObject, MultipleIdenticalDATA)
+ PointerPassObject, MultipleIdenticalDATA,
+ DefaultStructConstructorNullPointer)
// Portability and suspicious usage warnings
ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 7c3db734bb612..b0235469c9de6 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -2431,6 +2431,14 @@ MaybeExpr ExpressionAnalyzer::CheckStructureConstructor(
result.Add(symbol, Expr<SomeType>{ProcedureDesignator{**proc->init()}});
} else if (IsAllocatableOrPointer(symbol)) {
result.Add(symbol, Expr<SomeType>{NullPointer{}});
+ if (IsPointer(symbol)) {
+ AttachDeclaration(
+ Warn(common::LanguageFeature::DefaultStructConstructorNullPointer,
+ typeName,
+ "Structure constructor lacks a value for pointer component '%s', NULL() assumed"_warn_en_US,
+ symbol.name()),
+ symbol);
+ }
} else {
AttachDeclaration(
Say(typeName,
diff --git a/flang/test/Semantics/bug179580.f90 b/flang/test/Semantics/bug179580.f90
new file mode 100644
index 0000000000000..88ca0c551d2b5
--- /dev/null
+++ b/flang/test/Semantics/bug179580.f90
@@ -0,0 +1,9 @@
+!RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror
+type t
+ real v
+ integer, pointer :: p
+end type
+type(t), allocatable :: a
+!WARNING: Structure constructor lacks a value for pointer component 'p', NULL() assumed [-Wdefault-struct-constructor-null-pointer]
+allocate(a, source=t(v=3.3))
+end
More information about the flang-commits
mailing list