Bug 93557 - __builtin_convertvector doesn't mark input as used
Summary: __builtin_convertvector doesn't mark input as used
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: 9.3
Assignee: Jakub Jelinek
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2020-02-03 19:07 UTC by Evan Nemerson
Modified: 2020-02-14 11:21 UTC (History)
2 users (show)

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


Attachments
test case (pass -Wextra to enable the warnings) (141 bytes, text/plain)
2020-02-03 19:07 UTC, Evan Nemerson
Details
gcc10-pr93557.patch (755 bytes, patch)
2020-02-04 13:50 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Evan Nemerson 2020-02-03 19:07:59 UTC
Created attachment 47771 [details]
test case (pass -Wextra to enable the warnings)

I'm getting some false positives with -Wunused-but-set-parameter and -Wunused-but-variable which I've narrowed down to __builtin_convertvector.  There is a quick test case attached, or ot godbolt at https://godbolt.org/z/RSFLGB

It works as expected with gcc, but with g++ I get:

    cv.cc: In function ‘vecf conv(veci)’:
    cv.cc:4:16: warning: parameter ‘a’ set but not used [-Wunused-but-set-parameter]
        4 | vecf conv(veci a) {
          |           ~~~~~^
    cv.cc: In function ‘vecf conv2(veci)’:
    cv.cc:11:8: warning: variable ‘tmp’ set but not used [-Wunused-but-set-variable]
       11 |   veci tmp = a;
          |        ^~~

In case anyone else finds this, as a (hopefully temporary) workaround I'm planning to modify my macro wrapper to use a statement expr to create a temporary variable which I mark as used using the ((void) foo) trick:

#define SIMDE__CONVERT_VECTOR(to, from) ((to) = (__extension__({ \
     __typeof__(from) from_ = (from); \
     ((void) from_); \
     __builtin_convertvector(from_, __typeof__(to)); \
   })))
Comment 1 Jakub Jelinek 2020-02-03 20:09:45 UTC
I'll take this.
Comment 2 Jakub Jelinek 2020-02-04 13:50:45 UTC
Created attachment 47776 [details]
gcc10-pr93557.patch

Untested fix.
Comment 3 GCC Commits 2020-02-05 22:36:26 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:5a8ad97b6e4823d4ded00a3ce8d80e4bf93368d4

commit r10-6460-g5a8ad97b6e4823d4ded00a3ce8d80e4bf93368d4
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Feb 5 23:35:08 2020 +0100

    c++: Mark __builtin_convertvector operand as read [PR93557]
    
    In C++ we weren't calling mark_exp_read on the __builtin_convertvector first
    argument.  I guess it could misbehave even with lambda implicit captures.
    
    Fixed by calling decay_conversion on the argument, we use the argument as
    rvalue so we want the standard lvalue to rvalue conversions, but as the
    argument must be a vector type, e.g. integral promotions aren't really
    needed.
    
    2020-02-05  Jakub Jelinek  <jakub@redhat.com>
    
    	PR c++/93557
    	* semantics.c (cp_build_vec_convert): Call decay_conversion on arg
    	prior to passing it to c_build_vec_convert.
    
    	* c-c++-common/Wunused-var-17.c: New test.
Comment 4 GCC Commits 2020-02-13 22:32:39 UTC
The releases/gcc-9 branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:520b364da0b20dcb492229757190cc3f30322052

commit r9-8219-g520b364da0b20dcb492229757190cc3f30322052
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Feb 5 23:35:08 2020 +0100

    c++: Mark __builtin_convertvector operand as read [PR93557]
    
    In C++ we weren't calling mark_exp_read on the __builtin_convertvector first
    argument.  I guess it could misbehave even with lambda implicit captures.
    
    Fixed by calling decay_conversion on the argument, we use the argument as
    rvalue so we want the standard lvalue to rvalue conversions, but as the
    argument must be a vector type, e.g. integral promotions aren't really
    needed.
    
    2020-02-05  Jakub Jelinek  <jakub@redhat.com>
    
    	PR c++/93557
    	* semantics.c (cp_build_vec_convert): Call decay_conversion on arg
    	prior to passing it to c_build_vec_convert.
    
    	* c-c++-common/Wunused-var-17.c: New test.
Comment 5 Jakub Jelinek 2020-02-14 11:21:15 UTC
Fixed.