diff options
author | YexuanXiao <bizwen@nykz.org> | 2025-07-19 14:44:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-19 03:44:14 -0300 |
commit | 7c402b8b81d2b69b55eb5bac39830fbc631f8cde (patch) | |
tree | 1806db6768d0b062c370306ce45d3cdfe84d5477 /clang/lib/Serialization | |
parent | 9bf7d04c4386daf1ef0acf95782a59855c98474a (diff) | |
download | llvm-7c402b8b81d2b69b55eb5bac39830fbc631f8cde.zip llvm-7c402b8b81d2b69b55eb5bac39830fbc631f8cde.tar.gz llvm-7c402b8b81d2b69b55eb5bac39830fbc631f8cde.tar.bz2 |
Reland [Clang] Make the SizeType, SignedSizeType and PtrdiffType be named sugar types (#149613)
The checks for the 'z' and 't' format specifiers added in the original
PR #143653 had some issues and were overly strict, causing some build
failures and were consequently reverted at
https://github.com/llvm/llvm-project/commit/4c85bf2fe8042c855c9dd5be4b02191e9d071ffd.
In the latest commit
https://github.com/llvm/llvm-project/pull/149613/commits/27c58629ec76a703fde9c0b99b170573170b4a7a,
I relaxed the checks for the 'z' and 't' format specifiers, so warnings
are now only issued when they are used with mismatched types.
The original intent of these checks was to diagnose code that assumes
the underlying type of `size_t` is `unsigned` or `unsigned long`, for
example:
```c
printf("%zu", 1ul); // Not portable, but not an error when size_t is unsigned long
```
However, it produced a significant number of false positives. This was
partly because Clang does not treat the `typedef` `size_t` and
`__size_t` as having a common "sugar" type, and partly because a large
amount of existing code either assumes `unsigned` (or `unsigned long`)
is `size_t`, or they define the equivalent of size_t in their own way
(such as
sanitizer_internal_defs.h).https://github.com/llvm/llvm-project/blob/2e67dcfdcd023df2f06e0823eeea23990ce41534/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h#L203
Diffstat (limited to 'clang/lib/Serialization')
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 3596d224..10aedb6 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -7574,11 +7574,16 @@ void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) { void TypeLocReader::VisitBitIntTypeLoc(clang::BitIntTypeLoc TL) { TL.setNameLoc(readSourceLocation()); } + void TypeLocReader::VisitDependentBitIntTypeLoc( clang::DependentBitIntTypeLoc TL) { TL.setNameLoc(readSourceLocation()); } +void TypeLocReader::VisitPredefinedSugarTypeLoc(PredefinedSugarTypeLoc TL) { + // Nothing to do. +} + void ASTRecordReader::readTypeLoc(TypeLoc TL) { TypeLocReader TLR(*this); for (; !TL.isNull(); TL = TL.getNextTypeLoc()) diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index e868afe..a6957e5 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -692,7 +692,6 @@ void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) { addSourceLocation(TL.getKWLoc()); } - void TypeLocWriter::VisitBitIntTypeLoc(clang::BitIntTypeLoc TL) { addSourceLocation(TL.getNameLoc()); } @@ -701,6 +700,11 @@ void TypeLocWriter::VisitDependentBitIntTypeLoc( addSourceLocation(TL.getNameLoc()); } +void TypeLocWriter::VisitPredefinedSugarTypeLoc( + clang::PredefinedSugarTypeLoc TL) { + // Nothing to do. +} + void ASTWriter::WriteTypeAbbrevs() { using namespace llvm; |