[all-commits] [llvm/llvm-project] 8ef695: [Clang] Keep qualifiers outside of OverflowBehavio...
Justin Stitt via All-commits
all-commits at lists.llvm.org
Tue Sep 15 10:34:50 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 8ef69555af1ca20dd5c933bcf88d6185e6558b35
https://github.com/llvm/llvm-project/commit/8ef69555af1ca20dd5c933bcf88d6185e6558b35
Author: Justin Stitt <justinstitt at google.com>
Date: 2026-09-15 (Tue, 15 Sep 2026)
Changed paths:
M clang/docs/OverflowBehaviorTypes.md
M clang/include/clang/AST/TypeBase.h
M clang/lib/AST/ASTContext.cpp
M clang/lib/AST/Type.cpp
M clang/lib/AST/TypePrinter.cpp
M clang/test/Sema/attr-overflow-behavior.cpp
A clang/test/Sema/overflow-behavior-qualifiers.c
M clang/test/SemaCXX/sugar-common-types.cpp
Log Message:
-----------
[Clang] Keep qualifiers outside of OverflowBehaviorType nodes (#222190)
`__typeof_unqual__` wasn't stripping `const` off of an overflow behavior
type:
```c
__typeof_unqual__(const __ob_trap int) x; // '__ob_trap const int'
```
The canonical type was always right, so `x` really is writable -- we
just printed it as const, which is the opposite of the truth.
`getOverflowBehaviorType()` hoisted qualifiers out for the canonical
type but stored the underlying type verbatim in the sugar node, so
`const __ob_trap int` became `OBT{const int}` with nothing qualified at
the `QualType` level. `getUnqualifiedType()` checks the canonical type
to decide there's something to strip, then strips it by desugaring one
step at a time. `OverflowBehaviorType` isn't sugar, so that walk
dead-ends on it and the qualifiers never come off.
So the rule is: a type node you can't desugar through shouldn't have a
canonical type with local qualifiers on it. Split the qualifiers off at
construction and put them back outside the node, which is where the
canonical already puts them.
Local qualifiers alone aren't enough here. `__ob_trap cint`, where
`cint` is a `typedef const int`, has the const in its canonical type but
not in its local qualifier set, and it's broken the same way.
`getSplitUnqualifiedType()` gets both. We lose the `cint` spelling in
that case but I think that's fine... that typedef is what was hiding the
qualifier in the first place.
While here, let `canPrefixQualifiers()` prefix an OBT so we print `const
__ob_trap int` instead of `__ob_trap int const`. That list is for types
that wrap the declarator, and an OBT just puts a keyword in front of an
integer like `_BitInt` and `_Atomic` do. We were already printing the
same type two different ways in attr-overflow-behavior.cpp, which is a
pretty good hint it was in the wrong list.
Note the new test checks the *printed* types. Since the canonical type
was never wrong, anything that only looks at canonical types passes
either way and doesn't actually test this.
Also spell out in the docs that an OBT is a type specifier and not a
qualifier.
Assisted-by: claude
Signed-off-by: Justin Stitt <justinstitt at google.com>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list