[clang] [Clang] Introduce OverflowBehaviorType for fine-grained overflow control (PR #148914)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 26 10:55:20 PDT 2025
mizvekov wrote:
> Great see commit [`af63956`](https://github.com/llvm/llvm-project/pull/148914/commits/af6395691ad98c3763d89e4794f353e77f0e3d9b). I just stole the pattern from the array canonicalization code. Added tests too.
Great, there are other places that need to be updated to handle this correctly as well.
In ASTContext.cpp, see `getCommonArrayElementType`, and how it's used.
Your `OverflowBehaviourType` is going to need the same kind of handling.
That is a generic function which expects the type node to have a `getElementType` to be the accessor to the underlying type. Unfortunately in yours it's called `getUnderlyingType`.
My suggestion is to split the meat of that function into a non-templated one which just takes the underlying qualtypes directly. Then rewrite getCommonArrayElementType to use that, and make your OverflowBehaviourType use that as well.
Then, in ASTContext::getCommonSugaredType
change this line:
```C++
bool KeepCommonQualifiers = Unqualified || isa<ArrayType>(SX.Ty);
```
To:
```C++
bool KeepCommonQualifiers = Unqualified || isa<ArrayType, OverflowBehaviourType>(SX.Ty);
```
Then in `clang/test/SemaCXX/sugar-common-types.cpp`, look for the tests grouped in namespace 'arrays', you will want to create the same tests cases for your OverflowBehaviourType.
https://github.com/llvm/llvm-project/pull/148914
More information about the cfe-commits
mailing list