diff --git a/compiler/AST/type.cpp b/compiler/AST/type.cpp index 38293afec46a..2465ce689a18 100644 --- a/compiler/AST/type.cpp +++ b/compiler/AST/type.cpp @@ -1502,6 +1502,13 @@ int get_width(Type *t) { return 0; } +int get_component_width(Type *t) { + if (is_complex_type(t)) { + return get_width(t) / 2; + } + return get_width(t); +} + // numbers between -2**width .. 2**width // will fit exactly in a floating-point representation. int get_mantissa_width(Type *t) { diff --git a/compiler/include/driver.h b/compiler/include/driver.h index 7c27cbee9ecb..5b7067120e8d 100644 --- a/compiler/include/driver.h +++ b/compiler/include/driver.h @@ -239,8 +239,16 @@ extern bool ignore_errors; extern bool ignore_user_errors; extern bool ignore_errors_for_pass; extern int squelch_header_errors; -extern bool fWarnConstLoops; + extern bool fWarnIntUint; +extern bool fWarnSmallIntegralFloat; +extern bool fWarnIntegralFloat; +extern bool fWarnFloatFloat; +extern bool fWarnIntegralIntegral; +extern bool fWarnImplicitNumericConversions; +extern bool fWarnParamImplicitNumericConversions; + +extern bool fWarnConstLoops; extern bool fWarnUnstable; extern bool fWarnUnstableStandard; extern bool fWarnUnstableInternal; diff --git a/compiler/include/resolution.h b/compiler/include/resolution.h index 75aba07089fc..ef802d21932d 100644 --- a/compiler/include/resolution.h +++ b/compiler/include/resolution.h @@ -303,8 +303,9 @@ void resolveNormalCallCompilerWarningStuff(CallExpr* call, FnSymbol* resolvedFn) void checkMoveIntoClass(CallExpr* call, Type* lhs, Type* rhs); -void warnForIntUintConversion(BaseAST* context, Type* formalType, - Type* actualType, Symbol* actual); +// warn for some int -> uint and small int -> real +void warnForSomeNumericConversions(BaseAST* context, Type* formalType, + Type* actualType, Symbol* actual); void lvalueCheck(CallExpr* call); diff --git a/compiler/include/type.h b/compiler/include/type.h index 5a24c310b4ae..88ef4982495d 100644 --- a/compiler/include/type.h +++ b/compiler/include/type.h @@ -589,7 +589,12 @@ bool is_imag_type(Type*); bool is_complex_type(Type*); bool is_enum_type(Type*); bool isLegalParamType(Type*); +// returns the width in bytes of a numeric type int get_width(Type*); +// returns the component width in bytes of a numeric type +// like get_width but for complex types, returns get_width/2 +// since that is the width of the real or imaginary component. +int get_component_width(Type*); int get_mantissa_width(Type*); int get_exponent_width(Type*); bool isClass(Type* t); // includes ref, ddata, classes; not unmanaged diff --git a/compiler/main/driver.cpp b/compiler/main/driver.cpp index 9883d1811a09..131be064ef67 100644 --- a/compiler/main/driver.cpp +++ b/compiler/main/driver.cpp @@ -219,9 +219,18 @@ FILE* printPassesFile = NULL; // flag for llvmWideOpt bool fLLVMWideOpt = false; +// warnings for various implicit numeric conversions +bool fWarnIntUint = false; +bool fWarnSmallIntegralFloat = false; +bool fWarnIntegralFloat = false; +bool fWarnFloatFloat = false; +bool fWarnIntegralIntegral = false; +bool fWarnImplicitNumericConversions = false; +bool fWarnParamImplicitNumericConversions = false; + +// other warnings bool fWarnArrayOfRange = true; bool fWarnConstLoops = true; -bool fWarnIntUint = false; bool fWarnUnstable = false; bool fWarnUnstableStandard = false; bool fWarnUnstableInternal = false; @@ -663,6 +672,17 @@ static void addUsingAttributeToolname(const ArgumentDescription* desc, usingAttributeToolNames.push_back(name); } +/* called for --warn-implicit-numeric-conversions to enable the warnings */ +static void setNumericWarnings(const ArgumentDescription* desc, + const char* arg) { + bool shouldWarn = fWarnImplicitNumericConversions; + fWarnIntUint = shouldWarn; + fWarnSmallIntegralFloat = shouldWarn; + fWarnIntegralFloat = shouldWarn; + fWarnFloatFloat = shouldWarn; + fWarnIntegralIntegral = shouldWarn; +} + // In order to handle accumulating ccflags arguments, the argument // processing calls this function. This function appends the flags // to the ccflags variable, so that multiple --ccflags arguments @@ -1231,12 +1251,19 @@ static ArgumentDescription arg_desc[] = { {"print-search-dirs", ' ', NULL, "[Don't] print module search path", "N", &printSearchDirs, "CHPL_PRINT_SEARCH_DIRS", NULL}, {"", ' ', NULL, "Warning and Language Control Options", NULL, NULL, NULL, NULL}, - {"permit-unhandled-module-errors", ' ', NULL, "Permit unhandled errors in explicit modules; such errors halt at runtime", "N", &fPermitUnhandledModuleErrors, "CHPL_PERMIT_UNHANDLED_MODULE_ERRORS", NULL}, + {"permit-unhandled-module-errors", ' ', NULL, "Permit unhandled thrown errors; such errors halt at runtime", "N", &fPermitUnhandledModuleErrors, "CHPL_PERMIT_UNHANDLED_MODULE_ERRORS", NULL}, {"warn-unstable", ' ', NULL, "Enable [disable] warnings for uses of language features that are in flux", "N", &fWarnUnstable, "CHPL_WARN_UNSTABLE", NULL}, {"warnings", ' ', NULL, "Enable [disable] output of warnings", "n", &ignore_warnings, "CHPL_WARNINGS", NULL}, {"warn-unknown-attribute-toolname", ' ', NULL, "Enable [disable] warnings when an unknown tool name is found in an attribute", "N", &fWarnUnknownAttributeToolname, "CHPL_WARN_UNKNOWN_ATTRIBUTE_TOOLNAME", NULL}, {"using-attribute-toolname", ' ', "", "Specify additional tool names for attributes that are expected in the source", "S", NULL, "CHPL_ATTRIBUTE_TOOLNAMES", addUsingAttributeToolname}, -{"warn-potential-races", ' ', NULL, "Enable [disable] output of warnings for potential race conditions", "N", &fWarnPotentialRaces, "CHPL_WARN_POTENTIAL_RACES", NULL}, + {"warn-potential-races", ' ', NULL, "Enable [disable] output of warnings for potential race conditions", "N", &fWarnPotentialRaces, "CHPL_WARN_POTENTIAL_RACES", NULL}, + {"warn-int-to-uint", ' ', NULL, "Enable [disable] warnings for implicitly converting a potentially negative int value of any width to a uint", "N", &fWarnIntUint, "CHPL_WARN_INT_TO_UINT", NULL}, + {"warn-small-integral-to-float", ' ', NULL, "Enable [disable] warnings for implicitly converting a small int/uint to a small real/complex", "N", &fWarnSmallIntegralFloat, "CHPL_WARN_SMALL_INTEGRAL_TO_FLOAT", NULL}, + {"warn-integral-to-float", ' ', NULL, "Enable [disable] warnings for implicitly converting an int/uint to a real/complex of any width", "N", &fWarnIntegralFloat, "CHPL_WARN_INTEGRAL_TO_FLOAT", NULL}, + {"warn-float-to-float", ' ', NULL, "Enable [disable] warnings for implicitly converting a real/imag/complex to a real/imag/complex with different precision", "N", &fWarnFloatFloat, "CHPL_WARN_REAL_REAL", NULL}, + {"warn-integral-to-integral", ' ', NULL, "Enable [disable] warnings for implicitly converting an int/uint to an int/uint with different size", "N", &fWarnIntegralIntegral, "CHPL_WARN_INTEGRAL_TO_INTEGRAL", NULL}, + {"warn-implicit-numeric-conversions", ' ', NULL, "Enable [disable] warnings for implicitly converting a value of numeric type to a different numeric type", "N", &fWarnImplicitNumericConversions, "CHPL_WARN_IMPLICIT_NUMERIC_CONVERSIONS", setNumericWarnings}, + {"warn-param-implicit-numeric-conversions", ' ', NULL, "Enable [disable] int-to-uint, real-to-real, and integral-to-integral implicit conversion warnings to apply to 'param' values", "N", &fWarnParamImplicitNumericConversions, "CHPL_WARN_PARAM_IMPLICIT_NUMERIC_CONVERSIONS", NULL}, {"", ' ', NULL, "Parallelism Control Options", NULL, NULL, NULL, NULL}, {"local", ' ', NULL, "Target one [many] locale[s]", "N", &fLocal, "CHPL_LOCAL", setLocal}, @@ -1487,7 +1514,6 @@ static ArgumentDescription arg_desc[] = { {"warn-array-of-range", ' ', NULL, "Enable [disable] warnings about arrays of range literals", "N", &fWarnArrayOfRange, "CHPL_WARN_ARRAY_OF_RANGE", NULL}, {"warn-const-loops", ' ', NULL, "Enable [disable] warnings for some 'while' loops with constant conditions", "N", &fWarnConstLoops, "CHPL_WARN_CONST_LOOPS", NULL}, {"warn-domain-literal", ' ', NULL, "Enable [disable] old domain literal syntax warnings", "n", &fNoWarnDomainLiteral, "CHPL_WARN_DOMAIN_LITERAL", setWarnDomainLiteral}, - {"warn-int-uint", ' ', NULL, "Enable [disable] warnings for potentially negative 'int' values implicitly converted to 'uint'", "N", &fWarnIntUint, "CHPL_WARN_INT_UINT", NULL}, {"warn-tuple-iteration", ' ', NULL, "Enable [disable] warnings for tuple iteration", "n", &fNoWarnTupleIteration, "CHPL_WARN_TUPLE_ITERATION", setWarnTupleIteration}, {"warn-special", ' ', NULL, "Enable [disable] special warnings", "n", &fNoWarnSpecial, "CHPL_WARN_SPECIAL", setWarnSpecial}, {"warn-unstable-internal", ' ', NULL, "Enable [disable] unstable warnings in internal modules", "N", &fWarnUnstableInternal, NULL, NULL}, diff --git a/compiler/resolution/functionResolution.cpp b/compiler/resolution/functionResolution.cpp index c09e959f99dd..866982857c40 100644 --- a/compiler/resolution/functionResolution.cpp +++ b/compiler/resolution/functionResolution.cpp @@ -8174,39 +8174,134 @@ void checkMoveIntoClass(CallExpr* call, Type* lhs, Type* rhs) { } -void warnForIntUintConversion(BaseAST* context, - Type* formalType, - Type* actualType, - Symbol* actual) { - if (fWarnIntUint || shouldWarnUnstableFor(context)) { - Type* formalVt = formalType->getValType(); - Type* actualVt = actualType->getValType(); - if (is_uint_type(formalVt) && is_int_type(actualVt)) { - if (get_width(formalVt) <= get_width(actualVt)) { - bool isParam = false; - bool isNegParam = false; - - if (VarSymbol* var = toVarSymbol(actual)) { - if (Immediate* imm = var->immediate) { - isParam = true; - isNegParam = is_negative(imm); - } +void warnForSomeNumericConversions(BaseAST* context, + Type* formalType, + Type* actualType, + Symbol* actual) { + + Type* formalVt = formalType->getValType(); + Type* actualVt = actualType->getValType(); + bool formalFloatingPoint = is_real_type(formalVt) || + is_imag_type(formalVt) || + is_complex_type(formalVt); + bool actualFloatingPoint = is_real_type(actualVt) || + is_imag_type(actualVt) || + is_complex_type(actualVt); + bool formalIntUint = is_int_type(formalVt) || is_uint_type(formalVt); + bool actualIntUint = is_int_type(actualVt) || is_uint_type(actualVt); + + // nothing to do if the formal is not numeric + if (!formalFloatingPoint && !formalIntUint) return; + // nothing to do if the actual is not numeric + if (!actualFloatingPoint && !actualIntUint) return; + + int formalWidth = get_component_width(formalVt); + int actualWidth = get_component_width(actualVt); + + bool actualIsParam = false; + if (VarSymbol* var = toVarSymbol(actual)) { + if (var->immediate != nullptr) { + actualIsParam = true; + } + } + + bool userModule = false; + if (ModuleSymbol* mod = context->getModule()) { + userModule = mod->modTag == MOD_USER; + } + + // consider warning for int -> uint implicit conversion + if (formalIntUint && actualIntUint && + is_int_type(actualVt) && is_uint_type(formalVt)) { + // note: used to check formalWidth <= actualWidth + // but that doesn't make sense to me; if the concern is + // it could a be negative int, the widths don't matter + + if (fWarnIntUint || shouldWarnUnstableFor(context)) { + bool isParam = actualIsParam; + bool isNegParam = false; + + if (VarSymbol* var = toVarSymbol(actual)) { + if (Immediate* imm = var->immediate) { + isNegParam = is_negative(imm); } + } - // If it's a param, warn only if it is negative. - // Otherwise, warn. - if (isNegParam || !isParam) { - if (fWarnIntUint) { - USR_WARN(context, "potentially surprising int->uint implicit conversion"); - } else { - USR_WARN(context, "int->uint implicit conversion is unstable"); - } - USR_PRINT(context, "add a cast :%s to avoid this warning", - toString(formalVt)); + // If it's a param, warn only if it is negative. + // Otherwise, warn. + if (isNegParam || !isParam || + (fWarnParamImplicitNumericConversions && userModule)) { + if (fWarnIntUint) { + USR_WARN(context, "potentially surprising implicit conversion " + "from '%s' to '%s'", + toString(actualVt), toString(formalVt)); + } else { + USR_WARN(context, "int->uint implicit conversion is unstable"); } + USR_PRINT(context, "add a cast :%s to avoid this warning", + toString(formalVt)); + return; + } + } + } + + // consider warning for small int -> small real implicit conversion + if (actualIntUint && formalFloatingPoint && + actualWidth < 64 && formalWidth != 64) { + if (fWarnSmallIntegralFloat || shouldWarnUnstableFor(context)) { + if (fWarnSmallIntegralFloat) { + USR_WARN(context, "potentially surprising implicit conversion " + "from '%s' to '%s'", + toString(actualVt), toString(formalVt)); + USR_PRINT(context, "add a cast :%s to avoid this warning", + toString(formalVt)); + return; + } else if (actualWidth < 32) { + // unstable warning focuses on 8 and 16 bit int/uint + USR_WARN(context, "implicit conversion from 8- and 16- bit integral " + "types to 'real(32)' is unstable"); + USR_PRINT(context, "add a cast :%s to avoid this warning", + toString(formalVt)); + return; } } } + + // consider warning for any int -> real implicit conversion + if (fWarnIntegralFloat && userModule && + actualIntUint && formalFloatingPoint) { + if (!actualIsParam || fWarnParamImplicitNumericConversions) { + USR_WARN(context, "implicit conversion from '%s' to '%s'", + toString(actualVt), toString(formalVt)); + USR_PRINT(context, "add a cast :%s to avoid this warning", + toString(formalVt)); + return; + } + } + + // consider warning for real(t) -> real(u) implicit conversion + if (fWarnFloatFloat && actualFloatingPoint && formalFloatingPoint && + actualWidth != formalWidth && userModule) { + if (!actualIsParam || fWarnParamImplicitNumericConversions) { + USR_WARN(context, "implicit conversion from '%s' to '%s'", + toString(actualVt), toString(formalVt)); + USR_PRINT(context, "add a cast :%s to avoid this warning", + toString(formalVt)); + return; + } + } + + // consider warning for int/uint -> int/uint implicit conversion + if (fWarnIntegralIntegral && actualIntUint && formalIntUint && + actualWidth != formalWidth && userModule) { + if (!actualIsParam || fWarnParamImplicitNumericConversions) { + USR_WARN(context, "implicit conversion from '%s' to '%s'", + toString(actualVt), toString(formalVt)); + USR_PRINT(context, "add a cast :%s to avoid this warning", + toString(formalVt)); + return; + } + } } diff --git a/compiler/resolution/postFold.cpp b/compiler/resolution/postFold.cpp index 571e67069afa..0d9e0cdadaf5 100644 --- a/compiler/resolution/postFold.cpp +++ b/compiler/resolution/postFold.cpp @@ -173,6 +173,17 @@ static Expr* postFoldNormal(CallExpr* call) { VarSymbol* ret = toVarSymbol(fn->getReturnSymbol()); if (ret != NULL && ret->immediate != NULL) { + + // warn for certain numeric implicit conversions before we forget + // everything about the call + for_formals_actuals(formal, actual, call) { + if (SymExpr* actualSe = toSymExpr(actual)) { + warnForSomeNumericConversions(call, + formal->typeInfo(), actual->typeInfo(), + actualSe->symbol()); + } + } + retval = new SymExpr(ret); call->replace(retval); diff --git a/compiler/resolution/resolveFunction.cpp b/compiler/resolution/resolveFunction.cpp index e0e654068416..abdcf5d9b1a0 100644 --- a/compiler/resolution/resolveFunction.cpp +++ b/compiler/resolution/resolveFunction.cpp @@ -2763,7 +2763,7 @@ static void insertInitConversion(Symbol* to, Symbol* toType, Symbol* from, INT_ASSERT(toValType == toType->type); // generate a warning in some cases for int->uint implicit conversion - warnForIntUintConversion(insertBefore, toValType, fromValType, from); + warnForSomeNumericConversions(insertBefore, toValType, fromValType, from); } // seemingly redundant toType->type->symbol is for lowered runtime type vars diff --git a/compiler/resolution/wrappers.cpp b/compiler/resolution/wrappers.cpp index 06585e8812ee..c5c485e4bc2c 100644 --- a/compiler/resolution/wrappers.cpp +++ b/compiler/resolution/wrappers.cpp @@ -1550,8 +1550,9 @@ static void addArgCoercion(FnSymbol* fn, SET_LINENO(actual); // generate a warning in some cases for int->uint implicit conversion - warnForIntUintConversion(call, formal->type, actual->symbol()->type, - actual->symbol()); + // generate a warning in some cases for small int -> real implicit conversion + warnForSomeNumericConversions(call, formal->type, actual->symbol()->type, + actual->symbol()); Symbol* prevActual = actual->symbol(); TypeSymbol* ats = prevActual->type->symbol; diff --git a/man/chpl.rst b/man/chpl.rst index 0023e2b174cb..fdde05172547 100644 --- a/man/chpl.rst +++ b/man/chpl.rst @@ -143,6 +143,51 @@ OPTIONS operation may be race condition and will warn with this flag. Defaults to not printing race condition warnings. +**\--[no-]warn-int-to-uint** + + Enable [disable] compilation warnings for when implicitly converting + from a value of ``int`` type of any width to a ``uint`` value. + +**\--[no-]warn-small-integral-to-float** + + Enable [disable] compilation warnings for when implicitly converting + from a value of small integral type to a small floating-point value. + More specifically, it will warn when implicitly converting something + of type ``int(t)`` or ``uint(t)`` where ``t<64``, to something of + type ``real(u)`` or ``complex(2*u)`` where ``u<64``. + +**\--[no-]warn-integral-to-float** + + Enable [disable] compilation warnings for when implicitly converting + from a value of ``int`` or ``uint`` type of any width to a ``real`` + or ``complex`` type of any width. + +**\--[no-]warn-float-to-float** + + Enable [disable] compilation warnings for when implicitly converting + from a floating-point type of one precision to another. That includes + implicitly converting from ``real(32)`` to ``real(64)`` as well as + similar cases with ``imag`` and ``complex`` types. + +**\--[no-]warn-integral-to-integral** + + Enable [disable] compilation warnings for when implicitly converting + from a value of integral type to another integral type of different width. + (An integral type is an ``int`` or ``uint`` type). + +**\--[no-]warn-implicit-numeric-conversions** + + Enable [disable] the above compilation warnings for implicitly + converting between numeric types. + +**\--[no-]warn-param-implicit-numeric-conversions** + + When used in conjunction with ``warn-int-uint``, + ``--warn-real-real``, or ``--warn-integral-integral``, this flag + enables [or disables] these compilation warnings about implicitly + converting between numeric types to also apply when the converted + value is a ``param``. + *Parallelism Control Options* **\--[no-]local** diff --git a/test/compflags/bradc/help/userhelp.good b/test/compflags/bradc/help/userhelp.good index f53e2b24709b..02e7233984a3 100644 --- a/test/compflags/bradc/help/userhelp.good +++ b/test/compflags/bradc/help/userhelp.good @@ -10,8 +10,8 @@ Module Processing Options: Warning and Language Control Options: --[no-]permit-unhandled-module-errors - Permit unhandled errors in explicit - modules; such errors halt at runtime + Permit unhandled thrown errors; such + errors halt at runtime --[no-]warn-unstable Enable [disable] warnings for uses of language features that are in flux --[no-]warnings Enable [disable] output of warnings @@ -25,6 +25,33 @@ Warning and Language Control Options: source --[no-]warn-potential-races Enable [disable] output of warnings for potential race conditions + --[no-]warn-int-to-uint Enable [disable] warnings for implicitly + converting a potentially negative int + value of any width to a uint + --[no-]warn-small-integral-to-float + Enable [disable] warnings for implicitly + converting a small int/uint to a small + real/complex + --[no-]warn-integral-to-float Enable [disable] warnings for implicitly + converting an int/uint to a real/complex + of any width + --[no-]warn-float-to-float Enable [disable] warnings for implicitly + converting a real/imag/complex to a + real/imag/complex with different + precision + --[no-]warn-integral-to-integral + Enable [disable] warnings for implicitly + converting an int/uint to an int/uint + with different size + --[no-]warn-implicit-numeric-conversions + Enable [disable] warnings for implicitly + converting a value of numeric type to a + different numeric type + --[no-]warn-param-implicit-numeric-conversions + Enable [disable] int-to-uint, + real-to-real, and integral-to-integral + implicit conversion warnings to apply to + 'param' values Parallelism Control Options: --[no-]local Target one [many] locale[s] diff --git a/test/compflags/ferguson/warn-int-uint.chpl b/test/compflags/ferguson/implicit-conversion-warnings/warn-int-uint.chpl similarity index 100% rename from test/compflags/ferguson/warn-int-uint.chpl rename to test/compflags/ferguson/implicit-conversion-warnings/warn-int-uint.chpl diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-int-uint.compopts b/test/compflags/ferguson/implicit-conversion-warnings/warn-int-uint.compopts new file mode 100644 index 000000000000..0f617a4cef36 --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-int-uint.compopts @@ -0,0 +1,2 @@ +--warn-int-to-uint +--warn-implicit-numeric-conversions diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-int-uint.good b/test/compflags/ferguson/implicit-conversion-warnings/warn-int-uint.good new file mode 100644 index 000000000000..5d1eba27dea2 --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-int-uint.good @@ -0,0 +1,24 @@ +warn-int-uint.chpl:13: In function 'ret_v': +warn-int-uint.chpl:15: warning: potentially surprising implicit conversion from 'int(64)' to 'uint(64)' +warn-int-uint.chpl:15: note: add a cast :uint(64) to avoid this warning +warn-int-uint.chpl:17: In function 'ret_negone': +warn-int-uint.chpl:19: warning: potentially surprising implicit conversion from 'int(64)' to 'uint(64)' +warn-int-uint.chpl:19: note: add a cast :uint(64) to avoid this warning +warn-int-uint.chpl:39: warning: potentially surprising implicit conversion from 'int(64)' to 'uint(64)' +warn-int-uint.chpl:39: note: add a cast :uint(64) to avoid this warning +warn-int-uint.chpl:41: warning: potentially surprising implicit conversion from 'int(64)' to 'uint(64)' +warn-int-uint.chpl:41: note: add a cast :uint(64) to avoid this warning +warn-int-uint.chpl:46: warning: potentially surprising implicit conversion from 'int(64)' to 'uint(64)' +warn-int-uint.chpl:46: note: add a cast :uint(64) to avoid this warning +warn-int-uint.chpl:48: warning: potentially surprising implicit conversion from 'int(64)' to 'uint(64)' +warn-int-uint.chpl:48: note: add a cast :uint(64) to avoid this warning +warn-int-uint.chpl:53: warning: potentially surprising implicit conversion from 'int(64)' to 'uint(64)' +warn-int-uint.chpl:53: note: add a cast :uint(64) to avoid this warning +warn-int-uint.chpl:55: warning: potentially surprising implicit conversion from 'int(64)' to 'uint(64)' +warn-int-uint.chpl:55: note: add a cast :uint(64) to avoid this warning +warn-int-uint.chpl:40: warning: potentially surprising implicit conversion from 'int(64)' to 'uint(64)' +warn-int-uint.chpl:40: note: add a cast :uint(64) to avoid this warning +warn-int-uint.chpl:47: warning: potentially surprising implicit conversion from 'int(64)' to 'uint(64)' +warn-int-uint.chpl:47: note: add a cast :uint(64) to avoid this warning +warn-int-uint.chpl:54: warning: potentially surprising implicit conversion from 'int(64)' to 'uint(64)' +warn-int-uint.chpl:54: note: add a cast :uint(64) to avoid this warning diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-integral.chpl b/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-integral.chpl new file mode 100644 index 000000000000..da0e12818711 --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-integral.chpl @@ -0,0 +1,7 @@ +proc test1fn(arg: int) { } + +proc test1() { + var myInt32: int(32) = 2; + test1fn(myInt32); +} +test1(); diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-integral.compopts b/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-integral.compopts new file mode 100644 index 000000000000..bb86fea44761 --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-integral.compopts @@ -0,0 +1,2 @@ +--warn-integral-to-integral +--warn-implicit-numeric-conversions diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-integral.good b/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-integral.good new file mode 100644 index 000000000000..3c30261188a2 --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-integral.good @@ -0,0 +1,3 @@ +warn-integral-integral.chpl:3: In function 'test1': +warn-integral-integral.chpl:5: warning: implicit conversion from 'int(32)' to 'int(64)' +warn-integral-integral.chpl:5: note: add a cast :int(64) to avoid this warning diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-real.chpl b/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-real.chpl new file mode 100644 index 000000000000..71e1898be5ba --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-real.chpl @@ -0,0 +1,15 @@ +proc test1fn(arg: real(32)) { } + +proc test1() { + var myInt: int = 22; + test1fn(myInt); +} +test1(); + +proc test2fn(arg: real(64)) { } + +proc test2() { + var myUint16: uint(16) = 22; + test2fn(myUint16); +} +test2(); diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-real.compopts b/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-real.compopts new file mode 100644 index 000000000000..42d85d038ae9 --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-real.compopts @@ -0,0 +1,2 @@ +--warn-integral-to-float +--warn-implicit-numeric-conversions diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-real.good b/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-real.good new file mode 100644 index 000000000000..88afcb398c27 --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-integral-real.good @@ -0,0 +1,6 @@ +warn-integral-real.chpl:3: In function 'test1': +warn-integral-real.chpl:5: warning: implicit conversion from 'int(64)' to 'real(32)' +warn-integral-real.chpl:5: note: add a cast :real(32) to avoid this warning +warn-integral-real.chpl:11: In function 'test2': +warn-integral-real.chpl:13: warning: implicit conversion from 'uint(16)' to 'real(64)' +warn-integral-real.chpl:13: note: add a cast :real(64) to avoid this warning diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-param.chpl b/test/compflags/ferguson/implicit-conversion-warnings/warn-param.chpl new file mode 100644 index 000000000000..ca1d449dd406 --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-param.chpl @@ -0,0 +1,26 @@ +proc acceptsUint(arg: uint) { } +proc checkPositiveIntUint() { + param p = 11; + acceptsUint(p); +} +checkPositiveIntUint(); + +proc acceptsReal(arg: real) { } +proc checkRealReal() { + param p = 2.25:real(32); + acceptsReal(p); +} +checkRealReal(); + +proc acceptsInt(arg: int) { } +proc checkIntInt() { + param p = 33: int(16); + acceptsInt(p); +} +checkIntInt(); + +proc checkUintUint() { + param p = 44: uint(16); + acceptsUint(p); +} +checkUintUint(); diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-param.compopts b/test/compflags/ferguson/implicit-conversion-warnings/warn-param.compopts new file mode 100644 index 000000000000..c288a370269a --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-param.compopts @@ -0,0 +1,2 @@ +--warn-implicit-numeric-conversions # warn-param.empty.good +--warn-implicit-numeric-conversions --warn-param-implicit-numeric-conversions diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-param.empty.good b/test/compflags/ferguson/implicit-conversion-warnings/warn-param.empty.good new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-param.good b/test/compflags/ferguson/implicit-conversion-warnings/warn-param.good new file mode 100644 index 000000000000..e8e6a39b8657 --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-param.good @@ -0,0 +1,12 @@ +warn-param.chpl:2: In function 'checkPositiveIntUint': +warn-param.chpl:4: warning: potentially surprising implicit conversion from 'int(64)' to 'uint(64)' +warn-param.chpl:4: note: add a cast :uint(64) to avoid this warning +warn-param.chpl:9: In function 'checkRealReal': +warn-param.chpl:11: warning: implicit conversion from 'real(32)' to 'real(64)' +warn-param.chpl:11: note: add a cast :real(64) to avoid this warning +warn-param.chpl:16: In function 'checkIntInt': +warn-param.chpl:18: warning: implicit conversion from 'int(16)' to 'int(64)' +warn-param.chpl:18: note: add a cast :int(64) to avoid this warning +warn-param.chpl:22: In function 'checkUintUint': +warn-param.chpl:24: warning: implicit conversion from 'uint(16)' to 'uint(64)' +warn-param.chpl:24: note: add a cast :uint(64) to avoid this warning diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-real-real.chpl b/test/compflags/ferguson/implicit-conversion-warnings/warn-real-real.chpl new file mode 100644 index 000000000000..ce07d56075c7 --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-real-real.chpl @@ -0,0 +1,7 @@ +proc test1fn(arg: real) { } + +proc test1() { + var myReal32: real(32) = 2.0; + test1fn(myReal32); +} +test1(); diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-real-real.compopts b/test/compflags/ferguson/implicit-conversion-warnings/warn-real-real.compopts new file mode 100644 index 000000000000..5d72cc065e27 --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-real-real.compopts @@ -0,0 +1,2 @@ +--warn-float-to-float +--warn-implicit-numeric-conversions diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-real-real.good b/test/compflags/ferguson/implicit-conversion-warnings/warn-real-real.good new file mode 100644 index 000000000000..ac7c6605f365 --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-real-real.good @@ -0,0 +1,3 @@ +warn-real-real.chpl:3: In function 'test1': +warn-real-real.chpl:5: warning: implicit conversion from 'real(32)' to 'real(64)' +warn-real-real.chpl:5: note: add a cast :real(64) to avoid this warning diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-small-integral-real.chpl b/test/compflags/ferguson/implicit-conversion-warnings/warn-small-integral-real.chpl new file mode 100644 index 000000000000..644b746fc184 --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-small-integral-real.chpl @@ -0,0 +1,59 @@ +use Math; +// test warnings from --warn-small-integral-to-float / --warn-unstable +proc test1fn() { + var red: uint(8) = 1; + var green: uint(8) = 2; + var blue: uint(8) = 3; + return 0.2126*red + 0.7152*green + 0.0722*blue; +} + +proc test1() { + var x = test1fn(); + writeln("test1fn() = ", x, " : ", x.type:string); +} +test1(); + +proc test2() { + var myInt16: int(16) = 1; + var result = sin(myInt16); + writeln("sin(myInt16) = ", result, " : ", result.type:string); +} +test2(); + +proc test3() { + var x: int(16) = 1; + var y = 2.0; + var z = sqrt(x) + sin(y); + writeln("z = ", z, " : ", z.type:string); +} +test3(); + +proc test4() { + param two: uint(16) = 2; + var x = sqrt(two); + writeln("sqrt(2:uint(16)) = ", x, " : ", x.type:string); +} +test4(); + +proc test5fn(arg: real(32)) { } + +proc test5() { + test5fn(1:int(16)); +} +test5(); + +proc test6fn(arg: real(32)) param { return 1.0:real(32); } + +proc test6() { + var x = test6fn(1:int(16)); + writeln("test6 ", x, " : ", x.type:string); +} +test6(); + +proc test7fn(arg: real(32)) { } + +proc test7() { + var myInt32: int(32); + test7fn(myInt32); +} +test7(); diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-small-integral-real.compopts b/test/compflags/ferguson/implicit-conversion-warnings/warn-small-integral-real.compopts new file mode 100644 index 000000000000..6b51a6d6ee3b --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-small-integral-real.compopts @@ -0,0 +1 @@ +--warn-small-integral-to-float diff --git a/test/compflags/ferguson/implicit-conversion-warnings/warn-small-integral-real.good b/test/compflags/ferguson/implicit-conversion-warnings/warn-small-integral-real.good new file mode 100644 index 000000000000..95cc71c1508f --- /dev/null +++ b/test/compflags/ferguson/implicit-conversion-warnings/warn-small-integral-real.good @@ -0,0 +1,30 @@ +warn-small-integral-real.chpl:3: In function 'test1fn': +warn-small-integral-real.chpl:7: warning: potentially surprising implicit conversion from 'uint(8)' to 'real(32)' +warn-small-integral-real.chpl:7: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:7: warning: potentially surprising implicit conversion from 'uint(8)' to 'real(32)' +warn-small-integral-real.chpl:7: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:7: warning: potentially surprising implicit conversion from 'uint(8)' to 'real(32)' +warn-small-integral-real.chpl:7: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:16: In function 'test2': +warn-small-integral-real.chpl:18: warning: potentially surprising implicit conversion from 'int(16)' to 'real(32)' +warn-small-integral-real.chpl:18: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:23: In function 'test3': +warn-small-integral-real.chpl:26: warning: potentially surprising implicit conversion from 'int(16)' to 'real(32)' +warn-small-integral-real.chpl:26: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:31: In function 'test4': +warn-small-integral-real.chpl:33: warning: potentially surprising implicit conversion from 'uint(16)' to 'real(32)' +warn-small-integral-real.chpl:33: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:40: In function 'test5': +warn-small-integral-real.chpl:41: warning: potentially surprising implicit conversion from 'int(16)' to 'real(32)' +warn-small-integral-real.chpl:41: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:47: In function 'test6': +warn-small-integral-real.chpl:48: warning: potentially surprising implicit conversion from 'int(16)' to 'real(32)' +warn-small-integral-real.chpl:48: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:55: In function 'test7': +warn-small-integral-real.chpl:57: warning: potentially surprising implicit conversion from 'int(32)' to 'real(32)' +warn-small-integral-real.chpl:57: note: add a cast :real(32) to avoid this warning +test1fn() = 1.8596 : real(32) +sin(myInt16) = 0.841471 : real(32) +z = 1.9093 : real(64) +sqrt(2:uint(16)) = 1.41421 : real(32) +test6 1.0 : real(32) diff --git a/test/compflags/ferguson/warn-int-uint.compopts b/test/compflags/ferguson/warn-int-uint.compopts deleted file mode 100644 index eb1e1f8ce66b..000000000000 --- a/test/compflags/ferguson/warn-int-uint.compopts +++ /dev/null @@ -1 +0,0 @@ ---warn-int-uint diff --git a/test/compflags/ferguson/warn-int-uint.good b/test/compflags/ferguson/warn-int-uint.good deleted file mode 100644 index 0f84e49c9d09..000000000000 --- a/test/compflags/ferguson/warn-int-uint.good +++ /dev/null @@ -1,24 +0,0 @@ -warn-int-uint.chpl:13: In function 'ret_v': -warn-int-uint.chpl:15: warning: potentially surprising int->uint implicit conversion -warn-int-uint.chpl:15: note: add a cast :uint(64) to avoid this warning -warn-int-uint.chpl:17: In function 'ret_negone': -warn-int-uint.chpl:19: warning: potentially surprising int->uint implicit conversion -warn-int-uint.chpl:19: note: add a cast :uint(64) to avoid this warning -warn-int-uint.chpl:39: warning: potentially surprising int->uint implicit conversion -warn-int-uint.chpl:39: note: add a cast :uint(64) to avoid this warning -warn-int-uint.chpl:41: warning: potentially surprising int->uint implicit conversion -warn-int-uint.chpl:41: note: add a cast :uint(64) to avoid this warning -warn-int-uint.chpl:46: warning: potentially surprising int->uint implicit conversion -warn-int-uint.chpl:46: note: add a cast :uint(64) to avoid this warning -warn-int-uint.chpl:48: warning: potentially surprising int->uint implicit conversion -warn-int-uint.chpl:48: note: add a cast :uint(64) to avoid this warning -warn-int-uint.chpl:53: warning: potentially surprising int->uint implicit conversion -warn-int-uint.chpl:53: note: add a cast :uint(64) to avoid this warning -warn-int-uint.chpl:55: warning: potentially surprising int->uint implicit conversion -warn-int-uint.chpl:55: note: add a cast :uint(64) to avoid this warning -warn-int-uint.chpl:40: warning: potentially surprising int->uint implicit conversion -warn-int-uint.chpl:40: note: add a cast :uint(64) to avoid this warning -warn-int-uint.chpl:47: warning: potentially surprising int->uint implicit conversion -warn-int-uint.chpl:47: note: add a cast :uint(64) to avoid this warning -warn-int-uint.chpl:54: warning: potentially surprising int->uint implicit conversion -warn-int-uint.chpl:54: note: add a cast :uint(64) to avoid this warning diff --git a/test/functions/ferguson/coercions.compopts b/test/functions/ferguson/coercions.compopts index 34ed5685466b..91b1162f5061 100644 --- a/test/functions/ferguson/coercions.compopts +++ b/test/functions/ferguson/coercions.compopts @@ -1 +1 @@ ---no-overload-sets-checks +--no-overload-sets-checks --no-warn-implicit-numeric-conversions diff --git a/test/studies/ml/lib/MNIST.chpl b/test/studies/ml/lib/MNIST.chpl index f6cd064edb11..603adeb0838b 100644 --- a/test/studies/ml/lib/MNIST.chpl +++ b/test/studies/ml/lib/MNIST.chpl @@ -27,6 +27,7 @@ proc loadImages(num: int, fileName: string = "week2/emnist/data/train-images-idx raw[i,j] = fr.read(uint(8)); } } + // note: this is a 32-bit divide today var image: [imageDomain] real = raw / 255.0; return image; } diff --git a/test/studies/parboil/histo/histoSerial.chpl b/test/studies/parboil/histo/histoSerial.chpl index 19ecbda936ac..b4ae005d4e7b 100644 --- a/test/studies/parboil/histo/histoSerial.chpl +++ b/test/studies/parboil/histo/histoSerial.chpl @@ -102,7 +102,7 @@ proc dumpHisto(histo: [] uint(8), height: uint(32), width: uint(32), outFilename if value == 0 then (pixMap[pos].R, pixMap[pos].G, pixMap[pos].B) = (0:uint(8),0:uint(8),0:uint(8)); else - pixMap[pos] = HSVtoRGB(0.0, 1.0, cbrt(1+63.0*value/max(uint(8)))/4); + pixMap[pos] = HSVtoRGB(0.0, 1.0, cbrt(1+63.0*value:real/max(uint(8)))/4); } } createBMP(pixMap, height, width, outFilename); diff --git a/test/types/coerce/COMPOPTS b/test/types/coerce/COMPOPTS new file mode 100644 index 000000000000..7a57e0c86fbb --- /dev/null +++ b/test/types/coerce/COMPOPTS @@ -0,0 +1 @@ +--no-warn-implicit-numeric-conversions diff --git a/test/unstable/warn-int-uint.chpl b/test/unstable/warn-int-uint.chpl index cbd5e0ef07ce..ae1f1bdc94af 120000 --- a/test/unstable/warn-int-uint.chpl +++ b/test/unstable/warn-int-uint.chpl @@ -1 +1 @@ -../compflags/ferguson/warn-int-uint.chpl \ No newline at end of file +../compflags/ferguson/implicit-conversion-warnings/warn-int-uint.chpl \ No newline at end of file diff --git a/test/unstable/warn-small-integral-real.chpl b/test/unstable/warn-small-integral-real.chpl new file mode 120000 index 000000000000..8e93e5bcef9f --- /dev/null +++ b/test/unstable/warn-small-integral-real.chpl @@ -0,0 +1 @@ +../compflags/ferguson/implicit-conversion-warnings/warn-small-integral-real.chpl \ No newline at end of file diff --git a/test/unstable/warn-small-integral-real.good b/test/unstable/warn-small-integral-real.good new file mode 100644 index 000000000000..601be6d1f934 --- /dev/null +++ b/test/unstable/warn-small-integral-real.good @@ -0,0 +1,27 @@ +warn-small-integral-real.chpl:3: In function 'test1fn': +warn-small-integral-real.chpl:7: warning: implicit conversion from 8- and 16- bit integral types to 'real(32)' is unstable +warn-small-integral-real.chpl:7: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:7: warning: implicit conversion from 8- and 16- bit integral types to 'real(32)' is unstable +warn-small-integral-real.chpl:7: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:7: warning: implicit conversion from 8- and 16- bit integral types to 'real(32)' is unstable +warn-small-integral-real.chpl:7: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:16: In function 'test2': +warn-small-integral-real.chpl:18: warning: implicit conversion from 8- and 16- bit integral types to 'real(32)' is unstable +warn-small-integral-real.chpl:18: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:23: In function 'test3': +warn-small-integral-real.chpl:26: warning: implicit conversion from 8- and 16- bit integral types to 'real(32)' is unstable +warn-small-integral-real.chpl:26: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:31: In function 'test4': +warn-small-integral-real.chpl:33: warning: implicit conversion from 8- and 16- bit integral types to 'real(32)' is unstable +warn-small-integral-real.chpl:33: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:40: In function 'test5': +warn-small-integral-real.chpl:41: warning: implicit conversion from 8- and 16- bit integral types to 'real(32)' is unstable +warn-small-integral-real.chpl:41: note: add a cast :real(32) to avoid this warning +warn-small-integral-real.chpl:47: In function 'test6': +warn-small-integral-real.chpl:48: warning: implicit conversion from 8- and 16- bit integral types to 'real(32)' is unstable +warn-small-integral-real.chpl:48: note: add a cast :real(32) to avoid this warning +test1fn() = 1.8596 : real(32) +sin(myInt16) = 0.841471 : real(32) +z = 1.9093 : real(64) +sqrt(2:uint(16)) = 1.41421 : real(32) +test6 1.0 : real(32) diff --git a/util/chpl-completion.bash b/util/chpl-completion.bash index 945cb1854b43..4c781f2898a3 100644 --- a/util/chpl-completion.bash +++ b/util/chpl-completion.bash @@ -290,8 +290,14 @@ _chpl () --no-warn-array-of-range \ --no-warn-const-loops \ --no-warn-domain-literal \ ---no-warn-int-uint \ +--no-warn-float-to-float \ +--no-warn-implicit-numeric-conversions \ +--no-warn-int-to-uint \ +--no-warn-integral-to-float \ +--no-warn-integral-to-integral \ +--no-warn-param-implicit-numeric-conversions \ --no-warn-potential-races \ +--no-warn-small-integral-to-float \ --no-warn-special \ --no-warn-tuple-iteration \ --no-warn-unknown-attribute-toolname \ @@ -390,8 +396,14 @@ _chpl () --warn-array-of-range \ --warn-const-loops \ --warn-domain-literal \ ---warn-int-uint \ +--warn-float-to-float \ +--warn-implicit-numeric-conversions \ +--warn-int-to-uint \ +--warn-integral-to-float \ +--warn-integral-to-integral \ +--warn-param-implicit-numeric-conversions \ --warn-potential-races \ +--warn-small-integral-to-float \ --warn-special \ --warn-tuple-iteration \ --warn-unknown-attribute-toolname \ @@ -536,7 +548,14 @@ _chpl () --no-task-tracking \ --no-tuple-copy-opt \ --no-vectorize \ +--no-warn-float-to-float \ +--no-warn-implicit-numeric-conversions \ +--no-warn-int-to-uint \ +--no-warn-integral-to-float \ +--no-warn-integral-to-integral \ +--no-warn-param-implicit-numeric-conversions \ --no-warn-potential-races \ +--no-warn-small-integral-to-float \ --no-warn-unknown-attribute-toolname \ --no-warn-unstable \ --no-warnings \ @@ -583,7 +602,14 @@ _chpl () --using-attribute-toolname \ --vectorize \ --version \ +--warn-float-to-float \ +--warn-implicit-numeric-conversions \ +--warn-int-to-uint \ +--warn-integral-to-float \ +--warn-integral-to-integral \ +--warn-param-implicit-numeric-conversions \ --warn-potential-races \ +--warn-small-integral-to-float \ --warn-unknown-attribute-toolname \ --warn-unstable \ --warnings \