aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaCast.cpp
diff options
context:
space:
mode:
authorRaul Tambre <raul@tambre.ee>2024-06-03 20:56:59 +0300
committerGitHub <noreply@github.com>2024-06-03 20:56:59 +0300
commit2bc098b8aba089fe8328b3b8a8b6b6816cd5a908 (patch)
tree5ca84fba7f4324a4af35768a57017a27357eb297 /clang/lib/Sema/SemaCast.cpp
parenta088c61d5c409ec0b8994340866d5864ba913516 (diff)
downloadllvm-2bc098b8aba089fe8328b3b8a8b6b6816cd5a908.zip
llvm-2bc098b8aba089fe8328b3b8a8b6b6816cd5a908.tar.gz
llvm-2bc098b8aba089fe8328b3b8a8b6b6816cd5a908.tar.bz2
[clang][Sema] Don't issue -Wcast-function-type-mismatch for enums with a matching underlying type (#87793)
Enums are passed as their underlying integral type so they're ABI compatible if the size matches. Useful with C APIs that pass user-controlled values to callbacks that can be made type safe by using enumerations (e.g. GStreamer). Discovered internally in some code after 999d4f840777bf8de26d45947192aa0728edc0fb.
Diffstat (limited to 'clang/lib/Sema/SemaCast.cpp')
-rw-r--r--clang/lib/Sema/SemaCast.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 7db6b1d..f03dcf0 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -1093,9 +1093,10 @@ static bool argTypeIsABIEquivalent(QualType SrcType, QualType DestType,
return true;
// Allow integral type mismatch if their size are equal.
- if (SrcType->isIntegralType(Context) && DestType->isIntegralType(Context))
- if (Context.getTypeInfoInChars(SrcType).Width ==
- Context.getTypeInfoInChars(DestType).Width)
+ if ((SrcType->isIntegralType(Context) || SrcType->isEnumeralType()) &&
+ (DestType->isIntegralType(Context) || DestType->isEnumeralType()))
+ if (Context.getTypeSizeInChars(SrcType) ==
+ Context.getTypeSizeInChars(DestType))
return true;
return Context.hasSameUnqualifiedType(SrcType, DestType);