aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorRoger Sayle <roger@eyesopen.com>2003-04-14 20:23:27 +0000
committerRoger Sayle <sayle@gcc.gnu.org>2003-04-14 20:23:27 +0000
commit712b7a052fc05a2373ed40c1fd13b3cfb0e7df62 (patch)
treeaffbca36245c345c26aa8393d0f487eadfbc22c9 /gcc/builtins.c
parent15d4fd986330e2e993d0aef0f58d0c5bf7ab0e28 (diff)
downloadgcc-712b7a052fc05a2373ed40c1fd13b3cfb0e7df62.zip
gcc-712b7a052fc05a2373ed40c1fd13b3cfb0e7df62.tar.gz
gcc-712b7a052fc05a2373ed40c1fd13b3cfb0e7df62.tar.bz2
builtins.c (expand_builtin_strlen): Evaluate the lengths of string literals at compile-time.
* builtins.c (expand_builtin_strlen): Evaluate the lengths of string literals at compile-time. From-SVN: r65585
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 1519593..89f9531 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -1935,14 +1935,18 @@ expand_builtin_strlen (exp, target)
else
{
rtx pat;
- tree src = TREE_VALUE (arglist);
-
- int align
- = get_pointer_alignment (src, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
-
+ tree len, src = TREE_VALUE (arglist);
rtx result, src_reg, char_rtx, before_strlen;
enum machine_mode insn_mode = value_mode, char_mode;
enum insn_code icode = CODE_FOR_nothing;
+ int align;
+
+ /* If the length can be computed at compile-time, return it. */
+ len = c_strlen (src);
+ if (len)
+ return expand_expr (len, target, value_mode, EXPAND_NORMAL);
+
+ align = get_pointer_alignment (src, BIGGEST_ALIGNMENT) / BITS_PER_UNIT;
/* If SRC is not a pointer type, don't do this operation inline. */
if (align == 0)