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
6969 bool operator ()(const Component &component) const {
7070 return (*this )(component.base ());
7171 }
72- // Forbid integer division by zero in constants .
72+ // Prevent integer division by known zeroes in constant expressions .
7373 template <int KIND>
7474 bool operator ()(
7575 const Divide<Type<TypeCategory::Integer, KIND>> &division) const {
7676 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 ();
7980 } else {
8081 return false ;
8182 }
Original file line number Diff line number Diff line change @@ -567,11 +567,18 @@ const DeclTypeSpec &InstantiateHelper::InstantiateIntrinsicType(
567567 kind = *value;
568568 } else {
569569 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,
572571 *value,
573572 parser::ToUpperCaseLetters (EnumToString (intrinsic.category ())));
574573 }
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 ())));
575582 }
576583 switch (spec.category ()) {
577584 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 11! RUN: %python %S/test_errors.py %s %flang_fc1
22! Test instantiation of components that are procedure pointers.
3- !
43program test
54 type dtype (kindParam)
65 integer , kind :: kindParam = 4
6+ ! ERROR: KIND parameter expression (kindparam) of intrinsic type REAL did not resolve to a constant value
77 ! ERROR: KIND parameter value (66) of intrinsic type REAL did not resolve to a supported value
88 ! ERROR: KIND parameter value (55) of intrinsic type REAL did not resolve to a supported value
99 procedure (real (kindParam)), pointer , nopass :: field = > null ()
You can’t perform that action at this time.
0 commit comments