GithubHelp home page GithubHelp logo

array-bounds error about xbyak HOT 10 CLOSED

Tachi107 avatar Tachi107 commented on June 15, 2024
array-bounds error

from xbyak.

Comments (10)

merryhime avatar merryhime commented on June 15, 2024 1

I note that gcc has been known to produce inaccurate warnings of this type historically.

from xbyak.

herumi avatar herumi commented on June 15, 2024

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.

Tachi107 avatar Tachi107 commented on June 15, 2024

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.

Tachi107 avatar Tachi107 commented on June 15, 2024

I'm getting the same warning here (array subscript 1 is outside array bounds of 'Xbyak::Reg [1]'):

xbyak/xbyak/xbyak.h

Lines 564 to 567 in 7aef3ff

XBYAK_CONSTEXPR bool is(int kind, uint32_t bit = 0) const
{
return (kind == 0 || (kind_ & kind)) && (bit == 0 || (bit_ & bit)); // cf. you can set (8|16)
}

also here (array subscript 3 is outside array bounds of 'Xbyak::Reg [1]':

XBYAK_CONSTEXPR uint32_t getBit() const { return bit_; }

and here (array subscript 1 is outside array bounds of 'Xbyak::Reg [1]'):

xbyak/xbyak/xbyak.h

Lines 889 to 892 in 7aef3ff

bool operator==(const RegExp& rhs) const
{
return base_ == rhs.base_ && index_ == rhs.index_ && disp_ == rhs.disp_ && scale_ == rhs.scale_;
}

from xbyak.

herumi avatar herumi commented on June 15, 2024

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.

herumi avatar herumi commented on June 15, 2024

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.

herumi avatar herumi commented on June 15, 2024

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.

Tachi107 avatar Tachi107 commented on June 15, 2024

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.

herumi avatar herumi commented on June 15, 2024

cf. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104603

from xbyak.

Tachi107 avatar Tachi107 commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.