Comments (10)
I note that gcc has been known to produce inaccurate warnings of this type historically.
from xbyak.
Thank you for the report.
I found a strange behavior.
Make a.cpp
in xbyak/test
.
#include <xbyak/xbyak.h>
using namespace Xbyak::util;
void f()
{
ptr[eax] == ptr[eax];
}
int main()
{
#ifdef A
ptr[eax] == ptr[eax];
#endif
}
g++-11.2 -O2 -I../ a.cpp -Warray-bounds
shows the warnings. But,
g++-11.2 -O2 -I../ a.cpp -Warray-bounds -DA
does not show it.
I'm not sure what that message const Xbyak::Address[0] is partly outside array bounds of Xbyak::Address [1]
means.
from xbyak.
Uhm, strange... I don't fully understand the warning either, as it seems to me that Xbyak::Address::operator== is simply confronting values. Maybe the issue lies in Xbyak::Address
itself.
If you're 100% sure that GCC is wrong you could tell it to ignore that warning with something like:
bool operator==(const Address& rhs) const
{
#ifdef __GNUG__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Warray-bounds"
#endif
return getBit() == rhs.getBit() && e_ == rhs.e_ && label_ == rhs.label_ && mode_ == rhs.mode_ && broadcast_ == rhs.broadcast_;
#ifdef __GNUG__
# pragma GCC diagnostic pop
#endif
}
But I'd try to fully understand the issue before suppressing it.
from xbyak.
I'm getting the same warning here (array subscript 1 is outside array bounds of 'Xbyak::Reg [1]'
):
Lines 564 to 567 in 7aef3ff
also here (array subscript 3 is outside array bounds of 'Xbyak::Reg [1]'
:
Line 569 in 7aef3ff
and here (array subscript 1 is outside array bounds of 'Xbyak::Reg [1]'
):
Lines 889 to 892 in 7aef3ff
from xbyak.
I am suspicious gcc because Valgrind and address-sanitizer do not show warnings.
But I'll try to make a minimal example to verify it.
from xbyak.
If you're 100% sure that GCC is wrong you could tell it to ignore that warning with something like:
bool operator==(const Address& rhs) const { #ifdef __GNUG__ # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Warray-bounds" #endif
Yes, I sometimes use the pragma .
from xbyak.
I've minimized the code which shows the warnings.
I think that this is a misjudgment of GCC-11 about downcast.
https://wandbox.org/permlink/64SLolCCNsyOkoSS
g++-11.2 -O2 -I../ a.cpp -Warray-bounds
shows the warnings and does not show it if -DA
is added.
#include <stdio.h>
struct Base {
bool isX_;
Base(bool isX = false) : isX_(isX) { }
bool isX() const { return isX_; }
bool operator==(const Base& rhs) const;
};
struct X : public Base {
X(const Base& b) : Base(true), b_(b) { }
bool operator==(const X& rhs) const { return b_ == rhs.b_; }
Base b_;
};
inline bool Base::operator==(const Base& rhs) const
{
return isX() && rhs.isX() && static_cast<const X&>(*this) == static_cast<const X&>(rhs);
}
Base base;
#ifndef A
void f()
{
X(base) == X(base);
}
#endif
int main()
{
#ifdef A
X(base) == X(base);
#endif
}
g++-11.2 -O2 -I../ a.cpp -Warray-bounds
a.cpp: In function 'void f()':
a.cpp:6:29: warning: array subscript 2 is outside array bounds of 'X [1]' [-Warray-bounds]
6 | bool isX() const { return isX_; }
| ^~~~
a.cpp:26:9: note: while referencing '<anonymous>'
26 | X(base) == X(base);
| ^
a.cpp:6:29: warning: array subscript 2 is outside array bounds of 'X [1]' [-Warray-bounds]
6 | bool isX() const { return isX_; }
| ^~~~
a.cpp:26:20: note: while referencing '<anonymous>'
26 | X(base) == X(base);
| ^
a.cpp:6:29: warning: array subscript 3 is outside array bounds of 'X [1]' [-Warray-bounds]
6 | bool isX() const { return isX_; }
| ^~~~
a.cpp:26:9: note: while referencing '<anonymous>'
26 | X(base) == X(base);
| ^
a.cpp:6:29: warning: array subscript 3 is outside array bounds of 'X [1]' [-Warray-bounds]
6 | bool isX() const { return isX_; }
| ^~~~
a.cpp:26:20: note: while referencing '<anonymous>'
26 | X(base) == X(base);
| ^
a.cpp:6:29: warning: array subscript 4 is outside array bounds of 'X [1]' [-Warray-bounds]
6 | bool isX() const { return isX_; }
| ^~~~
a.cpp:26:9: note: while referencing '<anonymous>'
26 | X(base) == X(base);
| ^
a.cpp:6:29: warning: array subscript 4 is outside array bounds of 'X [1]' [-Warray-bounds]
6 | bool isX() const { return isX_; }
| ^~~~
a.cpp:26:20: note: while referencing '<anonymous>'
26 | X(base) == X(base);
| ^
a.cpp:6:29: warning: array subscript 5 is outside array bounds of 'X [1]' [-Warray-bounds]
6 | bool isX() const { return isX_; }
| ^~~~
a.cpp:26:9: note: while referencing '<anonymous>'
26 | X(base) == X(base);
| ^
a.cpp:6:29: warning: array subscript 5 is outside array bounds of 'X [1]' [-Warray-bounds]
6 | bool isX() const { return isX_; }
| ^~~~
a.cpp:26:20: note: while referencing '<anonymous>'
26 | X(base) == X(base);
| ^
a.cpp:12:51: warning: array subscript 2 is outside array bounds of 'X [1]' [-Warray-bounds]
12 | bool operator==(const X& rhs) const { return b_ == rhs.b_; }
| ~~~^~~~~~~~~
a.cpp:26:9: note: while referencing '<anonymous>'
26 | X(base) == X(base);
| ^
a.cpp:12:58: warning: array subscript 2 is outside array bounds of 'X [1]' [-Warray-bounds]
12 | bool operator==(const X& rhs) const { return b_ == rhs.b_; }
| ~~~~^~
a.cpp:26:20: note: while referencing '<anonymous>'
26 | X(base) == X(base);
from xbyak.
Ok, this is definitely a bug in GCC 10+ (doesn't happen in GCC 9), so I'll close this. Thanks for your investigation :)
from xbyak.
cf. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104603
from xbyak.
Thank you! I wanted to report it to the GCC devs too but I forgot about it :/
Looks like this helped discovering a bug in the compiler :D
from xbyak.
Related Issues (20)
- Broken test suite on x86 (IA-32) HOT 2
- WAITPKG HOT 2
- Build failure with XBYAK_NO_EXCEPTION HOT 2
- Cpu::has() check is inconsistent HOT 3
- The version number went backwards: 6.052 -> 6.06 HOT 10
- Compilation issue with template trick on MSVC HOT 3
- Standalone CPUID flags are coupled with `AVX512F` HOT 1
- movzx eax, ah HOT 3
- "invalid token at start of a preprocessor expression" HOT 5
- Question on error stickyness HOT 3
- Error raised when using vpmovsdb with memory mask HOT 4
- x32 support HOT 11
- Please use ${CXX} instead of hardcoding g++ because in different systems C++ compiler has different executable names HOT 2
- RISC-V ISA support HOT 2
- aligned allocation requests should be rounded up to page size HOT 2
- AMD MONITORX instructions support HOT 2
- Support for Intel APX and AVX10 HOT 4
- Support for xbegin, xend, xabort functions HOT 1
- APX support in progress HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xbyak.