Bug 93543 - [10 regression] bootstrap with clang fails in analyzer: reinterpret_cast from 'nullptr_t' to 'function *' is not allowed
Summary: [10 regression] bootstrap with clang fails in analyzer: reinterpret_cast from...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: analyzer (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: 10.0
Assignee: David Malcolm
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2020-02-02 22:41 UTC by Gerald Pfeifer
Modified: 2020-02-05 06:04 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-02-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gerald Pfeifer 2020-02-02 22:41:51 UTC
This was originally filed in the FreeBSD bug tracker against lang/gcc10-devel,
cf. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=243681

A user reported

  /usr/ports/lang/gcc10-devel/work/gcc-10-20200126/gcc/analyzer/engine.cc:2971:13: error: 
      reinterpret_cast from 'nullptr_t' to 'function *' is not allowed
  v.m_fun = reinterpret_cast<function *> (NULL);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
  /usr/ports/lang/gcc10-devel/work/gcc-10-20200126/gcc/analyzer/engine.cc:2983:21: error: 
      reinterpret_cast from 'nullptr_t' to 'function *' is not allowed
  return v.m_fun == reinterpret_cast<function *> (NULL);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

in analyzer/engine.cc.

David Malcolm kindly provided a patch that I applied on the FreeBSD side.

This report is to track and ensure this gets fixed in upstream GCC with 
the GCC 10.1 release.
Comment 1 David Malcolm 2020-02-03 20:11:37 UTC
Here's a simpler patch; does it fix the build with clang?

gcc/analyzer/ChangeLog:
        PR analyzer/93543
        * engine.cc (pod_hash_traits<function_call_string>::mark_empty):
        Eliminate reinterpret_cast.
        (pod_hash_traits<function_call_string>::is_empty): Likewise.
---
 gcc/analyzer/engine.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index 90f7067dec1..81b8a76c5eb 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -2962,7 +2962,7 @@ template <>
 inline void
 pod_hash_traits<function_call_string>::mark_empty (value_type &v)
 {
-  v.m_fun = reinterpret_cast<function *> (NULL);
+  v.m_fun = NULL;
 }
 template <>
 inline bool
@@ -2974,7 +2974,7 @@ template <>
 inline bool
 pod_hash_traits<function_call_string>::is_empty (value_type v)
 {
-  return v.m_fun == reinterpret_cast<function *> (NULL);
+  return v.m_fun == NULL;
 }
 
 namespace ana {
-- 
2.21.0
Comment 2 Sebastian Huber 2020-02-04 14:06:38 UTC
LLVM 8.0.1 is also affected by this. In

https://en.cppreference.com/w/cpp/language/reinterpret_cast

I found this note:

"9) The null pointer value of any pointer type can be converted to any other pointer type, resulting in the null pointer value of that type. Note that the null pointer constant nullptr or any other value of type std::nullptr_t cannot be converted to a pointer with reinterpret_cast: implicit conversion or static_cast should be used for this purpose."

Consider the following test program:

struct function;

function *g(void)
{
  return static_cast<function *>(nullptr);
}

function *f(void)
{
  return reinterpret_cast<function *>(nullptr);
}

$ clang -c test.cc
test.cc:10:10: error: reinterpret_cast from 'nullptr_t' to 'function *' is not allowed
  return reinterpret_cast<function *>(nullptr);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Comment 3 David Malcolm 2020-02-04 14:08:42 UTC
Thanks.  Does the patch in comment #1 fix it for you?
Comment 4 Sebastian Huber 2020-02-04 15:24:59 UTC
(In reply to David Malcolm from comment #3)
> Thanks.  Does the patch in comment #1 fix it for you?

I tested the patch on FreeBSD 12.1 with LLVM 8.0.1 and it fixes the issue.
Comment 5 CVS Commits 2020-02-04 15:39:45 UTC
The master branch has been updated by David Malcolm <dmalcolm@gcc.gnu.org>:

https://gcc.gnu.org/g:1dae549dccfec1edb0cb4e65feadc4722bb3bcc8

commit r10-6434-g1dae549dccfec1edb0cb4e65feadc4722bb3bcc8
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Tue Jan 28 16:31:01 2020 -0500

    analyzer: fix build error with clang (PR 93543)
    
    https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=243681 reports a build
    failure with clang 9.0.1:
    
    gcc/analyzer/engine.cc:2971:13: error:
          reinterpret_cast from 'nullptr_t' to 'function *' is not allowed
      v.m_fun = reinterpret_cast<function *> (NULL);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    engine.cc:2983:21: error:
          reinterpret_cast from 'nullptr_t' to 'function *' is not allowed
      return v.m_fun == reinterpret_cast<function *> (NULL);
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    The casts appears to be unnecessary; eliminate them.
    
    gcc/analyzer/ChangeLog:
    	PR analyzer/93543
    	* engine.cc (pod_hash_traits<function_call_string>::mark_empty):
    	Eliminate reinterpret_cast.
    	(pod_hash_traits<function_call_string>::is_empty): Likewise.
Comment 6 David Malcolm 2020-02-04 15:41:06 UTC
(In reply to Sebastian Huber from comment #4)
> (In reply to David Malcolm from comment #3)
> > Thanks.  Does the patch in comment #1 fix it for you?
> 
> I tested the patch on FreeBSD 12.1 with LLVM 8.0.1 and it fixes the issue.

Thanks!  Should now be fixed in master as per comment #5.
Comment 7 Gerald Pfeifer 2020-02-05 00:57:29 UTC
Thank you - and I just received confirmation that also the new patch
addresses the original issue coming from a FreeBSD user with clang 9.0.1.