[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)
Nathan Sidwell via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 15 11:18:23 PST 2023
================
@@ -498,3 +498,137 @@ CodeGenTBAA::mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo,
// access type regardless of their base types.
return TBAAAccessInfo::getMayAliasInfo();
}
+
+// Determine the aliasing kind bit-converting from type Src to type Dst.
+CodeGenTBAA::AliasingKind CodeGenTBAA::getAliasingKind(QualType &Dst,
+ QualType &Src) {
+ assert(!Src->isVoidType() && !Dst->isVoidType());
+ if (TypeHasMayAlias(Src) || TypeHasMayAlias(Dst))
+ return AK_Ok;
+
+ Src = QualType{Src->getBaseElementTypeUnsafe(), 0};
+ Dst = QualType{Dst->getBaseElementTypeUnsafe(), 0};
+
+ auto *SrcDecl = Src->getAsRecordDecl();
+ auto *DstDecl = Dst->getAsRecordDecl();
+
+ const llvm::MDNode *AnyTBAA = getChar();
+ const llvm::MDNode *SrcTBAA = nullptr;
+ const llvm::MDNode *DstTBAA = nullptr;
+
+ if (!SrcDecl) {
+ SrcTBAA = getTypeInfo(Src);
+ if (!SrcTBAA || SrcTBAA == AnyTBAA)
----------------
urnathan wrote:
Pedantically 'signed char' is not blessed with that property by the std. But many compilers (llvm included) bestow it upon signed char. Indeed this particular patch doesn't make a judgement on that, it just gets the aliasing info for 'signed char' and it happens to get the same ubiquitous char tbaa.
https://github.com/llvm/llvm-project/pull/74155
More information about the cfe-commits
mailing list