Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flang/include/flang/Support/Fortran-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
ZeroDoStep, UnusedForallIndex, OpenMPUsage, DataLength, IgnoredDirective,
HomonymousSpecific, HomonymousResult, IgnoredIntrinsicFunctionType,
PreviousScalarUse, RedeclaredInaccessibleComponent, ImplicitShared,
IndexVarRedefinition, IncompatibleImplicitInterfaces, CdefinedInit,
IndexVarRedefinition, IncompatibleImplicitInterfaces,
VectorSubscriptFinalization, UndefinedFunctionResult, UselessIomsg,
MismatchingDummyProcedure, SubscriptedEmptyArray, UnsignedLiteralTruncation,
CompatibleDeclarationsFromDistinctModules, ConstantIsContiguous,
Expand Down
8 changes: 4 additions & 4 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9194,11 +9194,11 @@ bool DeclarationVisitor::CheckNonPointerInitialization(
"'%s' has already been initialized"_err_en_US);
} else if (IsAllocatable(ultimate)) {
Say(name, "Allocatable object '%s' cannot be initialized"_err_en_US);
} else if (details->isCDefined()) {
// CDEFINED variables cannot have initializer, because their storage
// may come outside of Fortran.
Say(name, "CDEFINED variable cannot be initialized"_err_en_US);
} else {
if (details->isCDefined()) {
context().Warn(common::UsageWarning::CdefinedInit, name.source,
"CDEFINED variable should not have an initializer"_warn_en_US);
}
return true;
}
} else {
Expand Down
7 changes: 4 additions & 3 deletions flang/test/Lower/cdefined.f90
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
! RUN: bbc -emit-hlfir -o - %s | FileCheck %s
! Ensure that CDEFINED variable has external (default) linkage and that
! it doesn't have an initializer
! it doesn't have either zero or constant initializer.
module m
use iso_c_binding
integer(c_int), bind(C, name='c_global', CDEFINED) :: c = 42
integer(c_int), bind(C, name='c_global', CDEFINED) :: c
! CHECK: fir.global @c_global : i32
! CHECK-NOT: fir.zero_bits
! CHECK-NOT: fir.zero_bits
! CHECK-NOT: arith.constant
end
4 changes: 2 additions & 2 deletions flang/test/Semantics/cdefined.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror
! RUN: %python %S/test_errors.py %s %flang_fc1
module m
use iso_c_binding
!WARNING: CDEFINED variable should not have an initializer [-Wcdefined-init]
!ERROR: CDEFINED variable cannot be initialized
integer(c_int), bind(C, name='c_global', CDEFINED) :: c = 42
end