This is an archive of the discontinued LLVM Phabricator instance.

[CLANG] Fix potential integer overflow value in getRVVTypeSize()
ClosedPublic

Authored by Manna on Jun 16 2023, 8:25 AM.

Details

Summary

In getRVVTypeSize(clang::​ASTContext &, clang::​BuiltinType const *) potential integer overflow occurs on expression VScale->first * MinElts with type unsigned int (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type uint64_t (64 bits, unsigned).

To avoid integer overflow, this patch changes the types of variables MinElts and EltSize to uint64_t instead of the cast.

Diff Detail

Event Timeline

Manna created this revision.Jun 16 2023, 8:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2023, 8:25 AM
Manna requested review of this revision.Jun 16 2023, 8:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2023, 8:25 AM
erichkeane added inline comments.Jun 21 2023, 5:29 AM
clang/lib/AST/ASTContext.cpp
9566–9567

I think I'd suggest just changing the types of these two variables instead of the cast.

Manna updated this revision to Diff 533589.Jun 22 2023, 7:02 AM
Manna edited the summary of this revision. (Show Details)

Thank you @erichkeane for review and comments. I have changed the types of variables MinElts and EltSize to uint64_t instead of the cast.

Manna marked an inline comment as done.Jun 22 2023, 7:02 AM
erichkeane accepted this revision.Jun 22 2023, 7:03 AM
This revision is now accepted and ready to land.Jun 22 2023, 7:03 AM