Bug 51196 - FAIL: g++.dg/cpp0x/Wzero-as-null-pointer-constant-1.C
Summary: FAIL: g++.dg/cpp0x/Wzero-as-null-pointer-constant-1.C
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.7.0
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-17 16:55 UTC by Greta Yorsh
Modified: 2011-11-22 15:06 UTC (History)
1 user (show)

See Also:
Host:
Target: arm-none-eabi
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Sanity checked on x86_64-linux and lightly tested arm-none-eabi (319 bytes, patch)
2011-11-21 17:04 UTC, Paolo Carlini
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Greta Yorsh 2011-11-17 16:55:55 UTC
The warnings for variable pmf are not produced as expected in this test. The test was introduced by a patch for PR44277.

FAIL: g++.dg/cpp0x/Wzero-as-null-pointer-constant-1.C  (test for warnings, line 66)
FAIL: g++.dg/cpp0x/Wzero-as-null-pointer-constant-1.C  (test for warnings, line 78)
FAIL: g++.dg/cpp0x/Wzero-as-null-pointer-constant-1.C  (test for warnings, line 90)
FAIL: g++.dg/cpp0x/Wzero-as-null-pointer-constant-1.C  (test for warnings, line 102)
FAIL: g++.dg/warn/Wzero-as-null-pointer-constant-1.C -std=gnu++98  (test for warnings, line 53)
FAIL: g++.dg/warn/Wzero-as-null-pointer-constant-1.C -std=gnu++98  (test for warnings, line 65)
FAIL: g++.dg/warn/Wzero-as-null-pointer-constant-1.C -std=gnu++98  (test for warnings, line 77)
FAIL: g++.dg/warn/Wzero-as-null-pointer-constant-1.C -std=gnu++98  (test for warnings, line 89)
FAIL: g++.dg/warn/Wzero-as-null-pointer-constant-1.C -std=gnu++11  (test for warnings, line 53)
FAIL: g++.dg/warn/Wzero-as-null-pointer-constant-1.C -std=gnu++11  (test for warnings, line 65)
FAIL: g++.dg/warn/Wzero-as-null-pointer-constant-1.C -std=gnu++11  (test for warnings, line 77)
FAIL: g++.dg/warn/Wzero-as-null-pointer-constant-1.C -std=gnu++11  (test for warnings, line 89)


Target: arm-none-eabi

Configured with: --with-cpu=cortex-a9 --with-float=softfp --with-fpu=neon --enable-checking=release --disable-gdbtk --disable-werror --disable-tui --disable-rda --disable-sid --disable-utils --disable-lto --disable-lto --disable-werror --disable-shared --disable-nls --disable-threads --disable-tls --enable-checking=yes --enable-languages=c,c++,fortran --with-newlib
Thread model: single
gcc version 4.7.0 20111107 (experimental) (GCC)
Comment 1 Paolo Carlini 2011-11-17 17:33:43 UTC
That's a pity, but personally frankly I don't think I will be able to seriously debug for this target in the near future. Or maybe Jason has something to suggest. Otherwise I propose to xfail on arm, for 4.7.
Comment 2 Jason Merrill 2011-11-17 17:44:54 UTC
(In reply to comment #1)
> I don't think I will be able to seriously
> debug for this target in the near future.

It's easy to build a cross-compiler for compile-time tests like this.  Just

.../configure --target arm-none-eabi --enable-languages=c++ && make all-gcc

should get as far as building cc1plus, which is all you need to debug most PRs.
Comment 3 Paolo Carlini 2011-11-17 18:14:16 UTC
I'll see what I can do... At the moment really I have no idea why for this target only we have a different behavior.
Comment 4 Paolo Carlini 2011-11-21 15:53:55 UTC
Unexpectedly ;) I'm making progress debugging this: what happens is that, for arm, in cp_build_binary_op, case EQ_EXPR (this is for 'if (pmf == 0)') here:

	  if (TARGET_PTRMEMFUNC_VBIT_LOCATION
	      == ptrmemfunc_vbit_in_delta)
	    {
	      tree pfn0 = pfn_from_ptrmemfunc (op0);
	      tree delta0 = delta_from_ptrmemfunc (op0);
	      tree e1 = cp_build_binary_op (location,
					    EQ_EXPR,
	  			            pfn0,	
				      	    build_zero_cst (TREE_TYPE (pfn0)),
					    complain);
	      tree e2 = cp_build_binary_op (location,
					    BIT_AND_EXPR, 
					    delta0,
				            integer_one_node,
					    complain);
	      e2 = cp_build_binary_op (location,
				       EQ_EXPR, e2, integer_zero_node,
				       complain);
	      op0 = cp_build_binary_op (location,
					TRUTH_ANDIF_EXPR, e1, e2,
					complain);
	      op1 = cp_convert (TREE_TYPE (op0), integer_one_node); 
	    }
     	  else 
	    {
	      op0 = build_ptrmemfunc_access_expr (op0, pfn_identifier);
	      op1 = cp_convert (TREE_TYPE (op0), op1);
	    }

the condition is true, thus we don't call cp_convert with op1, which is integer_zero_node here, instead we pass integer_one_node to cp_convert and the warning down in cp_convert_to_pointer cannot possibly trigger (actually, for arm we don't even reach cp_convert_to_pointer)

Thus, an idea for fixing the problem would be just warn right here for arm and similar targets, because here we know that op1 is indeed integer_zero_node (and that TYPE_PTRMEMFUNC_P (type0) is true of course)

Jason, can you imagine something neater?
Comment 5 Paolo Carlini 2011-11-21 17:04:47 UTC
Created attachment 25873 [details]
Sanity checked on x86_64-linux and lightly tested arm-none-eabi

In practice, this works for me. Maybe Greta can test it more carefully.
Comment 6 Greta Yorsh 2011-11-22 10:56:41 UTC
Thanks for fixing it, Paolo. Tested as follows.

Successful cross-build of the patch version for arm-none-eabi target, configured as before. No regression on qemu for check-g++. The tests for g++.dg/cpp0x/Wzero-as-null-pointer-constant-1.C all pass. 

Can you see the patch committed to trunk, please? 

Thank you,
Greta
Comment 7 paolo@gcc.gnu.org 2011-11-22 15:04:33 UTC
Author: paolo
Date: Tue Nov 22 15:04:27 2011
New Revision: 181620

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=181620
Log:
2011-11-22  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51196
	* typeck.c (cp_build_binary_op, [case EQ_EXPR]): For targets having
	TARGET_PTRMEMFUNC_VBIT_LOCATION == ptrmemfunc_vbit_in_delta, do here
	the -Wzero-as-null-pointer-constant warning for pmf == 0.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
Comment 8 Paolo Carlini 2011-11-22 15:06:34 UTC
Thanks a lot Greta for testing, patch applied!