aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorStefan Schulze Frielinghaus <stefansf@linux.ibm.com>2020-04-28 13:14:28 +0200
committerStefan Schulze Frielinghaus <stefansf@linux.ibm.com>2020-04-29 16:37:18 +0200
commit27594524d8a93cddb197ad8c9d4075c5870f1473 (patch)
treeaa6f9d166bf0d9c88a006852b9c173c6890af7c0 /gcc/fortran
parent392aa7d7adfbd84253121d2ef779bf3c627e8d0b (diff)
downloadgcc-27594524d8a93cddb197ad8c9d4075c5870f1473.zip
gcc-27594524d8a93cddb197ad8c9d4075c5870f1473.tar.gz
gcc-27594524d8a93cddb197ad8c9d4075c5870f1473.tar.bz2
fortran/io.c: Fix use of uninitialized variable num [PR94769]
While bootstrapping GCC on S/390 the following warning occurs: gcc/fortran/io.c: In function 'bool gfc_resolve_dt(gfc_code*, gfc_dt*, locus*)': gcc/fortran/io.c:3857:7: error: 'num' may be used uninitialized in this function [-Werror=maybe-uninitialized] 3857 | if (num == 0) | ^~ gcc/fortran/io.c:3843:11: note: 'num' was declared here 3843 | int num; Since gfc_resolve_dt is a non-static function we cannot assume anything about argument DT. Argument DT gets passed to function check_io_constraints which passes values depending on DT, namely dt->asynchronous->value.character.string to function compare_to_allowed_values as well as argument warn which is true as soon as DT->dterr is true. Thus both arguments depend on DT. If function compare_to_allowed_values is called with dt->asynchronous->value.character.string not being an allowed value, and ALLOWED_F2003 as well as ALLOWED_GNU being NULL (which is the case at the particular call side), and WARN equals true, then the function returns with a non-zero value and leaves num uninitialized which renders the warning true. Initialized num to -1 and added an assert statement. gcc/fortran/ChangeLog: 2020-04-29 Stefan Schulze Frielinghaus <stefansf@linux.ibm.com> PR fortran/94769 * io.c (check_io_constraints): Initialize local variable num to -1 and assert that it receives a meaningful value by function compare_to_allowed_values.
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/io.c4
2 files changed, 10 insertions, 1 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 1e6b593..f245cb4 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,10 @@
+2020-04-29 Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>
+
+ PR fortran/94769
+ * io.c (check_io_constraints): Initialize local variable num to
+ -1 and assert that it receives a meaningful value by function
+ compare_to_allowed_values.
+
2020-04-27 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/93956
diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c
index e066666..981cf9e 100644
--- a/gcc/fortran/io.c
+++ b/gcc/fortran/io.c
@@ -3840,7 +3840,7 @@ if (condition) \
if (dt->asynchronous)
{
- int num;
+ int num = -1;
static const char * asynchronous[] = { "YES", "NO", NULL };
/* Note: gfc_reduce_init_expr reports an error if not init-expr. */
@@ -3853,6 +3853,8 @@ if (condition) \
io_kind_name (k), warn, &dt->asynchronous->where, &num))
return false;
+ gcc_checking_assert (num != -1);
+
/* For "YES", mark related symbols as asynchronous. */
if (num == 0)
{