Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UndefinedBehavior alignment in hipo::structure #49

Open
c-dilks opened this issue Feb 20, 2024 · 2 comments · May be fixed by #64
Open

UndefinedBehavior alignment in hipo::structure #49

c-dilks opened this issue Feb 20, 2024 · 2 comments · May be fixed by #64

Comments

@c-dilks
Copy link
Contributor

c-dilks commented Feb 20, 2024

Running Clang's UndefinedBehaviorSanitizer in iguana, which depends on this repo, reveals the following alignment issue in hipo::bank::getFloatAt:

/__w/iguana/iguana/hipo/lib/pkgconfig/../../include/hipo4/bank.h:116:16: runtime error: load of misaligned address 0x55e52f404da6 for type 'float', which requires 4 byte alignment
0x55e52f404da6: note: pointer points here
 00 00 00 00 00 00  80 bf 00 00 80 bf 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00
             ^ 
    #0 0x7fb0b4ad3ee4 in hipo::structure::getFloatAt(int) const /__w/iguana/iguana/hipo/lib/pkgconfig/../../include/hipo4/bank.h:116:16
    #1 0x7fb0b4ad1d73 in hipo::bank::getFloat(char const*, int) const /__w/iguana/iguana/hipo/lib/pkgconfig/../../include/hipo4/bank.h:449:16
    #2 0x7fb0b4ae3d26 in iguana::clas12::MomentumCorrection::Run(std::vector<hipo::bank, std::allocator<hipo::bank>>&) const /__w/iguana/iguana/build-iguana/../src/iguana/algorithms/clas12/MomentumCorrection.cc:20:29
    #3 0x7fb0b4a9f6f3 in iguana::AlgorithmSequence::Run(std::vector<hipo::bank, std::allocator<hipo::bank>>&) const /__w/iguana/iguana/build-iguana/../src/iguana/algorithms/AlgorithmSequence.cc:11:46
    #4 0x55e52d1cab07 in main /__w/iguana/iguana/build-iguana/../src/iguana/tests/iguana-test.cc:103:11
    #5 0x7fb0b42dcccf  (/usr/lib/libc.so.6+0x25ccf) (BuildId: c0caa0b7709d3369ee575fcd7d7d0b0fc48733af)
    #6 0x7fb0b42dcd89 in __libc_start_main (/usr/lib/libc.so.6+0x25d89) (BuildId: c0caa0b7709d3369ee575fcd7d7d0b0fc48733af)
    #7 0x55e52d193dd4 in _start (/__w/iguana/iguana/build-iguana/src/iguana/tests/iguana-test+0x7add4) (BuildId: 1a4186039a18b5d38dec21484f462abf569d1f4c)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /__w/iguana/iguana/hipo/lib/pkgconfig/../../include/hipo4/bank.h:116:16 in 

For now I've suppressed it in iguana's sanitizer, but documenting the issue here.

See https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html

@c-dilks c-dilks changed the title UndefinedBehavior alignment in hipo::bank UndefinedBehavior alignment in hipo::structure Feb 20, 2024
@c-dilks
Copy link
Contributor Author

c-dilks commented Mar 11, 2024

Similarly for short:

runime error: load of misaligned address 0x56546c8e1829 for type 'int16_t' (aka 'short'), which requires 2 byte alignment
0x56546c8e1829: note: pointer points here
 1c 46 4a  f7 56 04 a0 0f f2 03 da  07 da 07 a2 08 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00
              ^ 
    #0 0x7f25bcb9d2b4 in hipo::structure::getShortAt(int) const /__w/iguana/iguana/hipo/lib/pkgconfig/../../include/hipo4/bank.h:110:16
    #1 0x7f25bcc015a4 in hipo::bank::getShort(char const*, int) const /__w/iguana/iguana/hipo/lib/pkgconfig/../../include/hipo4/bank.h:427:33

@c-dilks
Copy link
Contributor Author

c-dilks commented Mar 12, 2024

And putDoubleAt (whereas the above 2 are getters).

__w/iguana/iguana/hipo/lib/pkgconfig/../../include/hipo4/bank.h:144:9: runtime error: store to misaligned address 0x564b9aa659aa for type 'double', which requires 8 byte alignment
0x564b9aa659aa: note: pointer points here
 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
              ^ 
    #0 0x7effc981a003 in hipo::structure::putDoubleAt(int, double) /__w/iguana/iguana/hipo/lib/pkgconfig/../../include/hipo4/bank.h:144:73
    #1 0x7effc98144f7 in hipo::bank::putDouble(int, int, double) /__w/iguana/iguana/hipo/lib/pkgconfig/../../include/hipo4/bank.h:499:7

Perhaps I should write something to check all of them...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant