Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -76,7 +76,7 @@ ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
IndexVarRedefinition, IncompatibleImplicitInterfaces, CdefinedInit,
VectorSubscriptFinalization, UndefinedFunctionResult, UselessIomsg,
MismatchingDummyProcedure, SubscriptedEmptyArray, UnsignedLiteralTruncation,
CompatibleDeclarationsFromDistinctModules,
CompatibleDeclarationsFromDistinctModules, ConstantIsContiguous,
NullActualForDefaultIntentAllocatable, UseAssociationIntoSameNameSubprogram,
HostAssociatedIntentOutInSpecExpr, NonVolatilePointerToVolatile,
RealConstantWidening, VolatileOrAsynchronousTemporary)
Expand Down
8 changes: 8 additions & 0 deletions flang/lib/Evaluate/fold-logical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,12 +799,20 @@ Expr<Type<TypeCategory::Logical, KIND>> FoldIntrinsicFunction(
}
} else if (name == "is_contiguous") {
if (args.at(0)) {
auto warnContiguous = [&]() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always use braced initialization in everything before lowering or in the runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if (auto source{args[0]->sourceLocation()}) {
context.Warn(common::UsageWarning::ConstantIsContiguous, *source,
"constant values constructed at compile time are likely to be contiguous"_warn_en_US);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text of this message isn't really actionable; what should the programmer do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message updated.

}
};
if (auto *expr{args[0]->UnwrapExpr()}) {
if (auto contiguous{IsContiguous(*expr, context)}) {
warnContiguous();
return Expr<T>{*contiguous};
}
} else if (auto *assumedType{args[0]->GetAssumedTypeDummy()}) {
if (auto contiguous{IsContiguous(*assumedType, context)}) {
warnContiguous();
return Expr<T>{*contiguous};
}
}
Expand Down
6 changes: 6 additions & 0 deletions flang/test/Semantics/contiguous-warn.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror
integer, parameter :: num = 3
integer, parameter :: arr(num)=[(i, i=1,num)]
!WARNING: constant values constructed at compile time are likely to be contiguous [-Wconstant-is-contiguous]
logical, parameter :: result=is_contiguous(arr(num:1:-1))
end