File tree Expand file tree Collapse file tree 4 files changed +25
-6
lines changed Expand file tree Collapse file tree 4 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -69,13 +69,14 @@ class IsConstantExprHelper
69
69
bool operator ()(const Component &component) const {
70
70
return (*this )(component.base ());
71
71
}
72
- // Forbid integer division by zero in constants .
72
+ // Prevent integer division by known zeroes in constant expressions .
73
73
template <int KIND>
74
74
bool operator ()(
75
75
const Divide<Type<TypeCategory::Integer, KIND>> &division) const {
76
76
using T = Type<TypeCategory::Integer, KIND>;
77
- if (const auto divisor{GetScalarConstantValue<T>(division.right ())}) {
78
- return !divisor->IsZero () && (*this )(division.left ());
77
+ if ((*this )(division.left ()) && (*this )(division.right ())) {
78
+ const auto divisor{GetScalarConstantValue<T>(division.right ())};
79
+ return !divisor || !divisor->IsZero ();
79
80
} else {
80
81
return false ;
81
82
}
Original file line number Diff line number Diff line change @@ -567,11 +567,18 @@ const DeclTypeSpec &InstantiateHelper::InstantiateIntrinsicType(
567
567
kind = *value;
568
568
} else {
569
569
foldingContext ().messages ().Say (symbolName,
570
- " KIND parameter value (%jd) of intrinsic type %s "
571
- " did not resolve to a supported value" _err_en_US,
570
+ " KIND parameter value (%jd) of intrinsic type %s did not resolve to a supported value" _err_en_US,
572
571
*value,
573
572
parser::ToUpperCaseLetters (EnumToString (intrinsic.category ())));
574
573
}
574
+ } else {
575
+ std::string exprString;
576
+ llvm::raw_string_ostream sstream (exprString);
577
+ copy.AsFortran (sstream);
578
+ foldingContext ().messages ().Say (symbolName,
579
+ " KIND parameter expression (%s) of intrinsic type %s did not resolve to a constant value" _err_en_US,
580
+ exprString,
581
+ parser::ToUpperCaseLetters (EnumToString (intrinsic.category ())));
575
582
}
576
583
switch (spec.category ()) {
577
584
case DeclTypeSpec::Numeric:
Original file line number Diff line number Diff line change
1
+ ! RUN: not %flang_fc1 %s 2>&1 | FileCheck %s
2
+ ! CHECK: error: KIND parameter expression (int(1_4/0_4,kind=8)) of intrinsic type CHARACTER did not resolve to a constant value
3
+ ! CHECK: in the context: instantiation of parameterized derived type 'ty(j=1_4,k=0_4)'
4
+ ! CHECK: warning: INTEGER(4) division by zero
5
+ program main
6
+ type ty (j,k)
7
+ integer , kind :: j, k
8
+ character (kind= j/ k) a
9
+ end type
10
+ type (ty(1 ,0 )) x
11
+ end
Original file line number Diff line number Diff line change 1
1
! RUN: %python %S/test_errors.py %s %flang_fc1
2
2
! Test instantiation of components that are procedure pointers.
3
- !
4
3
program test
5
4
type dtype (kindParam)
6
5
integer , kind :: kindParam = 4
6
+ ! ERROR: KIND parameter expression (kindparam) of intrinsic type REAL did not resolve to a constant value
7
7
! ERROR: KIND parameter value (66) of intrinsic type REAL did not resolve to a supported value
8
8
! ERROR: KIND parameter value (55) of intrinsic type REAL did not resolve to a supported value
9
9
procedure (real (kindParam)), pointer , nopass :: field = > null ()
You can’t perform that action at this time.
0 commit comments