Skip to content

Commit 3425f22

Browse files
authored
[flang] Disable some warnings with ineluctable false positives (llvm#167714)
There are a few well-meaning warnings for some cases of the FPTR= argument to C_F_POINTER() that can be false positives, since the restrictions in the standard are dependent on the source of the CPTR= argument. Further, there is no way to alter a program to avoid these warnings, so one cannot compile a correct and conforming program with -pedantic -Werror. Disable these warnings. Fixes llvm#167470.
1 parent 9c3955a commit 3425f22

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

flang/lib/Evaluate/intrinsics.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,28 +3139,6 @@ IntrinsicProcTable::Implementation::HandleC_F_Pointer(
31393139
if (type->HasDeferredTypeParameter()) {
31403140
context.messages().Say(at,
31413141
"FPTR= argument to C_F_POINTER() may not have a deferred type parameter"_err_en_US);
3142-
} else if (type->category() == TypeCategory::Derived) {
3143-
if (type->IsUnlimitedPolymorphic()) {
3144-
context.Warn(common::UsageWarning::Interoperability, at,
3145-
"FPTR= argument to C_F_POINTER() should not be unlimited polymorphic"_warn_en_US);
3146-
} else if (!type->GetDerivedTypeSpec().typeSymbol().attrs().test(
3147-
semantics::Attr::BIND_C)) {
3148-
context.Warn(common::UsageWarning::Portability, at,
3149-
"FPTR= argument to C_F_POINTER() should not have a derived type that is not BIND(C)"_port_en_US);
3150-
}
3151-
} else if (!IsInteroperableIntrinsicType(
3152-
*type, &context.languageFeatures())
3153-
.value_or(true)) {
3154-
if (type->category() == TypeCategory::Character &&
3155-
type->kind() == 1) {
3156-
context.Warn(common::UsageWarning::CharacterInteroperability, at,
3157-
"FPTR= argument to C_F_POINTER() should not have the non-interoperable character length %s"_warn_en_US,
3158-
type->AsFortran());
3159-
} else {
3160-
context.Warn(common::UsageWarning::Interoperability, at,
3161-
"FPTR= argument to C_F_POINTER() should not have the non-interoperable intrinsic type or kind %s"_warn_en_US,
3162-
type->AsFortran());
3163-
}
31643142
}
31653143
if (ExtractCoarrayRef(*expr)) {
31663144
context.messages().Say(at,

flang/test/Semantics/c_f_pointer.f90

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ program test
4646
call c_f_pointer(scalarC, multiDimIntF, shape=[1_8])
4747
!ERROR: SHAPE= argument to C_F_POINTER() must be a rank-one array.
4848
call c_f_pointer(scalarC, multiDimIntF, shape=rankTwoArray)
49-
!WARNING: FPTR= argument to C_F_POINTER() should not be unlimited polymorphic [-Winteroperability]
49+
50+
!These warnings have been disabled because the C_F_POINTER's restrictions
51+
!are dependent on the source of the CPTR= argument. Each warning here
52+
!might be a false positive for a valid program.
53+
!!WARNING: FPTR= argument to C_F_POINTER() should not be unlimited polymorphic [-Winteroperability]
5054
call c_f_pointer(scalarC, unlimited)
51-
!PORTABILITY: FPTR= argument to C_F_POINTER() should not have a derived type that is not BIND(C) [-Wportability]
55+
!!PORTABILITY: FPTR= argument to C_F_POINTER() should not have a derived type that is not BIND(C) [-Wportability]
5256
call c_f_pointer(scalarC, notBindC)
53-
!WARNING: FPTR= argument to C_F_POINTER() should not have the non-interoperable character length CHARACTER(KIND=1,LEN=2_8) [-Wcharacter-interoperability]
57+
!!WARNING: FPTR= argument to C_F_POINTER() should not have the non-interoperable character length CHARACTER(KIND=1,LEN=2_8) [-Wcharacter-interoperability]
5458
call c_f_pointer(scalarC, c2ptr)
55-
!WARNING: FPTR= argument to C_F_POINTER() should not have the non-interoperable intrinsic type or kind CHARACTER(KIND=4,LEN=1_8) [-Winteroperability]
59+
!!WARNING: FPTR= argument to C_F_POINTER() should not have the non-interoperable intrinsic type or kind CHARACTER(KIND=4,LEN=1_8) [-Winteroperability]
5660
call c_f_pointer(scalarC, unicodePtr)
5761

5862
!ERROR: SHAPE= argument to C_F_POINTER() may not appear when FPTR= is scalar

0 commit comments

Comments
 (0)