* C++ PATCH for c++/49813 (c99 builtins in c++0x mode)
@ 2011-07-22 17:01 Jason Merrill
2011-08-01 18:13 ` C++ PATCH for c++/49813 (__builtin_isinf in constant expression) Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2011-07-22 17:01 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 134 bytes --]
C++0x references the C99 standard, so in C++0x mode we should have the
C99 builtins.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 49813.patch --]
[-- Type: text/x-patch, Size: 3484 bytes --]
commit fc181abfe4b268602287b2cd036035ab40685b9b
Author: Jason Merrill <jason@redhat.com>
Date: Fri Jul 22 10:43:00 2011 -0400
PR c++/49813
* c-opts.c (set_std_cxx0x): Set flag_isoc94 and flag_isoc99.
* c-pretty-print.c (pp_c_cv_qualifiers): Check c_dialect_cxx as well
as flag_isoc99 for 'restrict'.
(pp_c_specifier_qualifier_list): Likewise for _Complex.
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 5cf58ac..3227f7b 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -1488,6 +1488,9 @@ set_std_cxx0x (int iso)
flag_no_gnu_keywords = iso;
flag_no_nonansi_builtin = iso;
flag_iso = iso;
+ /* C++0x includes the C99 standard library. */
+ flag_isoc94 = 1;
+ flag_isoc99 = 1;
cxx_dialect = cxx0x;
}
diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c
index 977f79e..53d39d6 100644
--- a/gcc/c-family/c-pretty-print.c
+++ b/gcc/c-family/c-pretty-print.c
@@ -205,7 +205,8 @@ pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type)
{
if (previous)
pp_c_whitespace (pp);
- pp_c_ws_string (pp, flag_isoc99 ? "restrict" : "__restrict__");
+ pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
+ ? "restrict" : "__restrict__"));
}
}
@@ -476,7 +477,8 @@ pp_c_specifier_qualifier_list (c_pretty_printer *pp, tree t)
case VECTOR_TYPE:
case COMPLEX_TYPE:
if (code == COMPLEX_TYPE)
- pp_c_ws_string (pp, flag_isoc99 ? "_Complex" : "__complex__");
+ pp_c_ws_string (pp, (flag_isoc99 && !c_dialect_cxx ()
+ ? "_Complex" : "__complex__"));
else if (code == VECTOR_TYPE)
{
pp_c_ws_string (pp, "__vector");
diff --git a/gcc/testsuite/g++.dg/opt/builtins2.C b/gcc/testsuite/g++.dg/opt/builtins2.C
new file mode 100644
index 0000000..00a28db
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/builtins2.C
@@ -0,0 +1,11 @@
+// PR c++/49813
+// We should handle asinh as a built-in in C++0x mode, even when strict.
+// { dg-options "-std=c++0x" }
+// { dg-final { scan-assembler-not "asinh" } }
+
+#include <math.h>
+
+int main()
+{
+ double das = asinh(1.0);
+}
diff --git a/gcc/testsuite/g++.dg/other/error27.C b/gcc/testsuite/g++.dg/other/error27.C
index de97428..ef1e590 100644
--- a/gcc/testsuite/g++.dg/other/error27.C
+++ b/gcc/testsuite/g++.dg/other/error27.C
@@ -4,10 +4,10 @@
void foo (double x, double y)
{
- __builtin_isgreater(x, y)(); // { dg-error "__builtin_\[^\n\]*cannot be used as a function" }
- __builtin_isless(x, y)(); // { dg-error "__builtin_\[^\n\]*cannot be used as a function" }
- __builtin_isgreaterequal(x, y)(); // { dg-error "__builtin_\[^\n\]*cannot be used as a function" }
- __builtin_islessequal(x, y)(); // { dg-error "__builtin_\[^\n\]*cannot be used as a function" }
- __builtin_isunordered(x, y)(); // { dg-error "__builtin_\[^\n\]*cannot be used as a function" }
- __builtin_islessgreater(x, y)(); // { dg-error "__builtin_\[^\n\]*cannot be used as a function" }
+ __builtin_isgreater(x, y)(); // { dg-error "cannot be used as a function" }
+ __builtin_isless(x, y)(); // { dg-error "cannot be used as a function" }
+ __builtin_isgreaterequal(x, y)(); // { dg-error "cannot be used as a function" }
+ __builtin_islessequal(x, y)(); // { dg-error "cannot be used as a function" }
+ __builtin_isunordered(x, y)(); // { dg-error "cannot be used as a function" }
+ __builtin_islessgreater(x, y)(); // { dg-error "cannot be used as a function" }
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: C++ PATCH for c++/49813 (__builtin_isinf in constant expression)
2011-07-22 17:01 C++ PATCH for c++/49813 (c99 builtins in c++0x mode) Jason Merrill
@ 2011-08-01 18:13 ` Jason Merrill
2011-08-01 19:28 ` Paolo Carlini
2011-08-03 11:24 ` Gabriel Dos Reis
0 siblings, 2 replies; 4+ messages in thread
From: Jason Merrill @ 2011-08-01 18:13 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 388 bytes --]
Another issue raised in 49813 is that
morally_constexpr_builtin_function_p was rejecting __builtin_isinf
because it has a variadic signature. I'm changing
potential_constant_expression_1 to just allow any built-in function in a
constexpr function; if it doesn't expand to a constant, we'll deal with
that when we actually expand it.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 49813-2.patch --]
[-- Type: text/x-patch, Size: 2668 bytes --]
commit e2a2b30a8008b9f2d21e19bb2fd73776dbf89576
Author: Jason Merrill <jason@redhat.com>
Date: Mon Aug 1 11:49:09 2011 -0400
PR c++/49813
* semantics.c (potential_constant_expression_1): Allow any builtin.
(morally_constexpr_builtin_function_p): Remove.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index c44c0ef..47b714f 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -7523,32 +7523,6 @@ check_automatic_or_tls (tree ref)
}
#endif
-/* Return true if the DECL designates a builtin function that is
- morally constexpr, in the sense that its parameter types and
- return type are literal types and the compiler is allowed to
- fold its invocations. */
-
-static bool
-morally_constexpr_builtin_function_p (tree decl)
-{
- tree funtype = TREE_TYPE (decl);
- tree t;
-
- if (!is_builtin_fn (decl))
- return false;
- if (!literal_type_p (TREE_TYPE (funtype)))
- return false;
- for (t = TYPE_ARG_TYPES (funtype); t != NULL ; t = TREE_CHAIN (t))
- {
- if (t == void_list_node)
- return true;
- if (!literal_type_p (TREE_VALUE (t)))
- return false;
- }
- /* We assume no varargs builtins are suitable. */
- return t != NULL;
-}
-
/* Return true if T denotes a potentially constant expression. Issue
diagnostic as appropriate under control of FLAGS. If WANT_RVAL is true,
an lvalue-rvalue conversion is implied.
@@ -7656,7 +7630,9 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
if (builtin_valid_in_constant_expr_p (fun))
return true;
if (!DECL_DECLARED_CONSTEXPR_P (fun)
- && !morally_constexpr_builtin_function_p (fun))
+ /* Allow any built-in function; if the expansion
+ isn't constant, we'll deal with that then. */
+ && !is_builtin_fn (fun))
{
if (flags & tf_error)
{
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-builtin1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-builtin1.C
new file mode 100644
index 0000000..b3f5576
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-builtin1.C
@@ -0,0 +1,25 @@
+// PR c++/49813
+// { dg-options -std=c++0x }
+
+inline constexpr bool
+isinf(long double __x)
+{ return __builtin_isinf(__x); }
+
+inline constexpr bool
+isinf(double __x)
+{ return __builtin_isinf(__x); }
+
+inline constexpr bool
+isnan(long double __x)
+{ return __builtin_isnan(__x); }
+
+int main()
+{
+ constexpr long double num1 = __builtin_isinf(1.l); // Ok.
+
+ constexpr long double num2 = isinf(1.l); // Error.
+
+ constexpr double num3 = isinf(1.); // Ok.
+
+ constexpr long double num4 = isnan(1.l); // Ok.
+}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: C++ PATCH for c++/49813 (__builtin_isinf in constant expression)
2011-08-01 18:13 ` C++ PATCH for c++/49813 (__builtin_isinf in constant expression) Jason Merrill
@ 2011-08-01 19:28 ` Paolo Carlini
2011-08-03 11:24 ` Gabriel Dos Reis
1 sibling, 0 replies; 4+ messages in thread
From: Paolo Carlini @ 2011-08-01 19:28 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 106 bytes --]
Thanks a lot, Jason.
I applied the below, tested x86_64-linux multilib.
Paolo.
//////////////////////
[-- Attachment #2: CL_49813_lib_2 --]
[-- Type: text/plain, Size: 123 bytes --]
2011-08-01 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/49813
* include/c_global/cmath (isinf): Remove workaround.
[-- Attachment #3: patch_49813_lib_2 --]
[-- Type: text/plain, Size: 784 bytes --]
Index: include/c_global/cmath
===================================================================
--- include/c_global/cmath (revision 177068)
+++ include/c_global/cmath (working copy)
@@ -547,18 +547,17 @@
isfinite(_Tp __x)
{ return true; }
- // Workaround the isinf issue discussed in PR 49813.
constexpr bool
isinf(float __x)
- { return fpclassify(__x) == FP_INFINITE; }
+ { return __builtin_isinf(__x); }
constexpr bool
isinf(double __x)
- { return fpclassify(__x) == FP_INFINITE; }
+ { return __builtin_isinf(__x); }
constexpr bool
isinf(long double __x)
- { return fpclassify(__x) == FP_INFINITE; }
+ { return __builtin_isinf(__x); }
template<typename _Tp>
constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: C++ PATCH for c++/49813 (__builtin_isinf in constant expression)
2011-08-01 18:13 ` C++ PATCH for c++/49813 (__builtin_isinf in constant expression) Jason Merrill
2011-08-01 19:28 ` Paolo Carlini
@ 2011-08-03 11:24 ` Gabriel Dos Reis
1 sibling, 0 replies; 4+ messages in thread
From: Gabriel Dos Reis @ 2011-08-03 11:24 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches List
On Mon, Aug 1, 2011 at 1:12 PM, Jason Merrill <jason@redhat.com> wrote:
> Another issue raised in 49813 is that morally_constexpr_builtin_function_p
> was rejecting __builtin_isinf because it has a variadic signature. I'm
> changing potential_constant_expression_1 to just allow any built-in function
> in a constexpr function; if it doesn't expand to a constant, we'll deal with
> that when we actually expand it.
OK; at the time, I did not form a firm policy about variadic builtins.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-08-03 11:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-22 17:01 C++ PATCH for c++/49813 (c99 builtins in c++0x mode) Jason Merrill
2011-08-01 18:13 ` C++ PATCH for c++/49813 (__builtin_isinf in constant expression) Jason Merrill
2011-08-01 19:28 ` Paolo Carlini
2011-08-03 11:24 ` Gabriel Dos Reis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).