summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2003-02-16 22:10:10 +0000
committerhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2003-02-16 22:10:10 +0000
commit6d0025f4332e78bb49dfbd312160720fa295b00d (patch)
treec0995f241340b5f698925d91af5ffa83db5f4b1e
parent832570c5e63f133db192f6c1acd7f6103cd285ea (diff)
downloadgcc-6d0025f4332e78bb49dfbd312160720fa295b00d.tar.gz
* c-typeck.c (build_c_cast): Fold constant variables into
initial values. * gcc.dg/c90-const-expr-3.c (DZERO): New static variable (foo): Add few extra tests * gcc.dg/c99-const-expr-3.c: Likewise. * gcc.c-torture/execute/20030216-1.c: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@62987 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-typeck.c5
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/20030216-1.c10
-rw-r--r--gcc/testsuite/gcc.dg/c90-const-expr-3.c6
-rw-r--r--gcc/testsuite/gcc.dg/c99-const-expr-3.c6
6 files changed, 38 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3b610126435..6fc6b3996f8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+Sun Feb 16 23:07:52 CET 2003 Jan Hubicka <jh@suse.cz>
+
+ * c-typeck.c (build_c_cast): Fold constant variables into
+ initial values.
+
2003-02-16 Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>
* doc/install.texi (Specific): Fix link for m68k-att-sysv.
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index bbd94a044fa..f3b6bb96fbc 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -3765,8 +3765,11 @@ build_c_cast (type, expr)
get_alias_set (TREE_TYPE (type))))
warning ("dereferencing type-punned pointer will break strict-aliasing rules");
}
-
+
ovalue = value;
+ /* Replace a nonvolatile const static variable with its value. */
+ if (optimize && TREE_CODE (value) == VAR_DECL)
+ value = decl_constant_value (value);
value = convert (type, value);
/* Ignore any integer overflow caused by the cast. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 39436e8d9ee..0356de92d98 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+Sun Feb 16 23:08:19 CET 2003 Jan HUbicka <jh@suse.cz>
+
+ * gcc.dg/c90-const-expr-3.c (DZERO): New static variable
+ (foo): Add few extra tests
+ * gcc.dg/c99-const-expr-3.c: Likewise.
+ * gcc.c-torture/execute/20030216-1.c: New.
+
2003-02-16 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/9459
diff --git a/gcc/testsuite/gcc.c-torture/execute/20030216-1.c b/gcc/testsuite/gcc.c-torture/execute/20030216-1.c
new file mode 100644
index 00000000000..2153bfdd71f
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/20030216-1.c
@@ -0,0 +1,10 @@
+void link_error (void);
+const double one=1.0;
+main ()
+{
+#ifdef __OPTIMIZE__
+ if ((int) one != 1)
+ link_error ();
+#endif
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/c90-const-expr-3.c b/gcc/testsuite/gcc.dg/c90-const-expr-3.c
index 987284360d8..4a0eb105ef5 100644
--- a/gcc/testsuite/gcc.dg/c90-const-expr-3.c
+++ b/gcc/testsuite/gcc.dg/c90-const-expr-3.c
@@ -6,6 +6,7 @@
to give the correct behavior to conforming programs. */
static const int ZERO = 0;
+static const double DZERO = 0;
int *a;
int b;
@@ -36,4 +37,9 @@ foo (void)
ASSERT_NOT_NPC ((char) ZERO);
ASSERT_NPC ((int) 0);
ASSERT_NOT_NPC ((int) ZERO);
+ ASSERT_NPC ((int) 0.0);
+ ASSERT_NOT_NPC ((int) DZERO);
+ ASSERT_NOT_NPC ((int) +0.0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+ ASSERT_NOT_NPC ((int) (0.0+0.0)); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+ ASSERT_NOT_NPC ((int) (double)0.0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
}
diff --git a/gcc/testsuite/gcc.dg/c99-const-expr-3.c b/gcc/testsuite/gcc.dg/c99-const-expr-3.c
index 7490f62a4ab..096825eb8f5 100644
--- a/gcc/testsuite/gcc.dg/c99-const-expr-3.c
+++ b/gcc/testsuite/gcc.dg/c99-const-expr-3.c
@@ -6,6 +6,7 @@
to give the correct behavior to conforming programs. */
static const int ZERO = 0;
+static const double DZERO = 0;
int *a;
int b;
@@ -36,4 +37,9 @@ foo (void)
ASSERT_NOT_NPC ((char) ZERO);
ASSERT_NPC ((int) 0);
ASSERT_NOT_NPC ((int) ZERO);
+ ASSERT_NPC ((int) 0.0);
+ ASSERT_NOT_NPC ((int) DZERO);
+ ASSERT_NOT_NPC ((int) +0.0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+ ASSERT_NOT_NPC ((int) (0.0+0.0)); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+ ASSERT_NOT_NPC ((int) (double)0.0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
}