[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2024-02-13 Thread Eli Friedman via cfe-commits
efriedma-quic wrote: > IIUC you're suggesting movint the TBAA data origination from CodeGen into > (probably) Sema and/or TargetInfo and then deriving the LLVM info in CodeGen > from that. I.e. keep once source of truth, but move where it is? Right; move the core computation to AST, and then t

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2024-02-13 Thread Nathan Sidwell via cfe-commits
urnathan wrote: > On the LLVM side, there's very little interesting logic; it's basically just > walking the tree of metadata nodes generated by clang. See > https://llvm.org/docs/LangRef.html#tbaa-node-semantics . The hard part of the > refactoring would just be adding an abstraction for the

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-15 Thread Eli Friedman via cfe-commits
efriedma-quic wrote: > > Making Sema pull the TBAA info out of clang/lib/CodeGen is a layering > > violation (and probably breaks if we aren't actually generating code). If > > we need some notion of "aliasing" in Sema, we should pull the relevant code > > into clang/lib/AST. > > That's unfor

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-15 Thread Nathan Sidwell via cfe-commits
urnathan wrote: > > > FWIW the GCC doc is > > > https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstrict-aliasing_003dn > > > It says for Level 3 "If optimization is enabled, it also runs in the > > > back end, where it deals with multiple statement cases using > > > flow-sensiti

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-15 Thread Nathan Sidwell via cfe-commits
@@ -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::A

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-15 Thread Nathan Sidwell via cfe-commits
@@ -37,6 +38,27 @@ class ASTConsumer { friend class SemaConsumer; +public: + /// Allow type-based aliasing information to be interrogated by the AST + /// producer (for diagnostics). + class TypeAliasing { urnathan wrote: Oh, we also endup deriving from

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits
@@ -0,0 +1,192 @@ +// RUN: %clang_cc1 %s -O0 -Wstrict-aliasing -S -o %t -verify=quiet +// RUN: %clang_cc1 %s -O2 -Wstrict-aliasing=0 -S -o %t -verify=quiet +// RUN: %clang_cc1 %s -O2 -Wno-strict-aliasing -S -o %t -verify=quiet +// RUN: %clang_cc1 %s -O2 -Wstrict-aliasing=1 -S -o %

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits
https://github.com/urnathan updated https://github.com/llvm/llvm-project/pull/74155 >From 89c05618bb75fd073343046f3b54bde5f2254719 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 15 Nov 2023 15:27:16 -0500 Subject: [PATCH 1/6] [clang] Strict aliasing warning ala GCC [PR50066] This imp

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits
@@ -128,6 +128,10 @@ class DiagnosticOptions : public RefCountedBase{ /// whether -Wsystem-headers is enabled on a per-module basis. std::vector SystemHeaderWarningsModules; + /// Level of scrutiny reinterpret_casts get for type-unsafe aliasing + /// checks. Requires an

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Vlad Serebrennikov via cfe-commits
@@ -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::A

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Vlad Serebrennikov via cfe-commits
@@ -37,6 +38,27 @@ class ASTConsumer { friend class SemaConsumer; +public: + /// Allow type-based aliasing information to be interrogated by the AST + /// producer (for diagnostics). + class TypeAliasing { Endilll wrote: Sorry I didn't make myself clear

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Vlad Serebrennikov via cfe-commits
@@ -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::A

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: > > FWIW the GCC doc is > > https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstrict-aliasing_003dn > > It says for Level 3 "If optimization is enabled, it also runs in the back > > end, where it deals with multiple statement cases using flow-sensitive > > poi

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits
https://github.com/urnathan edited https://github.com/llvm/llvm-project/pull/74155 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits
urnathan wrote: > Thank you for your efforts! I scratched the surface a bit; not qualified to > do an in-depth review. Can you also add a release note? Thanks for your comments. A release note is added. https://github.com/llvm/llvm-project/pull/74155 __

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits
urnathan wrote: > FWIW the GCC doc is > https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstrict-aliasing_003dn > It says for Level 3 "If optimization is enabled, it also runs in the back > end, where it deals with multiple statement cases using flow-sensitive > points-to informa

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits
urnathan wrote: > Making Sema pull the TBAA info out of clang/lib/CodeGen is a layering > violation (and probably breaks if we aren't actually generating code). If we > need some notion of "aliasing" in Sema, we should pull the relevant code into > clang/lib/AST. That's unfortunate. The code

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits
@@ -2026,6 +2027,137 @@ static TryCastResult TryConstCast(Sema &Self, ExprResult &SrcExpr, return TC_Success; } +// We're dereferencing E, either by turning into an RValue, or by dereferencing +// it. Check whether it's a deref of a reinterpret cast that has aliasing +// is

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits
@@ -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::A

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits
@@ -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::A

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-06 Thread Nathan Sidwell via cfe-commits
https://github.com/urnathan updated https://github.com/llvm/llvm-project/pull/74155 >From 89c05618bb75fd073343046f3b54bde5f2254719 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 15 Nov 2023 15:27:16 -0500 Subject: [PATCH 1/5] [clang] Strict aliasing warning ala GCC [PR50066] This imp

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-05 Thread Fangrui Song via cfe-commits
MaskRay wrote: Add @shafik who authors https://gist.github.com/shafik/848ae25ee209f698763cffee272a58f8 ("Although clang allows these flags it apparently does not actually implement the warnings") > [*] I implemented what turned into GCC's level=1 way back when. Cool! FWIW the GCC doc is ht

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-05 Thread Fangrui Song via cfe-commits
@@ -0,0 +1,192 @@ +// RUN: %clang_cc1 %s -O0 -Wstrict-aliasing -S -o %t -verify=quiet +// RUN: %clang_cc1 %s -O2 -Wstrict-aliasing=0 -S -o %t -verify=quiet +// RUN: %clang_cc1 %s -O2 -Wno-strict-aliasing -S -o %t -verify=quiet +// RUN: %clang_cc1 %s -O2 -Wstrict-aliasing=1 -S -o %

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-05 Thread Eli Friedman via cfe-commits
efriedma-quic wrote: Making Sema pull the TBAA info out of clang/lib/CodeGen is a layering violation (and probably breaks if we aren't actually generating code). If we need some notion of "aliasing" in Sema, we should pull the relevant code into clang/lib/AST. I don't have any experience wit

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-03 Thread Vlad Serebrennikov via cfe-commits
@@ -128,6 +128,10 @@ class DiagnosticOptions : public RefCountedBase{ /// whether -Wsystem-headers is enabled on a per-module basis. std::vector SystemHeaderWarningsModules; + /// Level of scrutiny reinterpret_casts get for type-unsafe aliasing + /// checks. Requires an

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-03 Thread Vlad Serebrennikov via cfe-commits
@@ -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::A

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-03 Thread Vlad Serebrennikov via cfe-commits
@@ -37,6 +38,27 @@ class ASTConsumer { friend class SemaConsumer; +public: + /// Allow type-based aliasing information to be interrogated by the AST + /// producer (for diagnostics). + class TypeAliasing { Endilll wrote: It seems to me that we'd be bett

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-03 Thread Vlad Serebrennikov via cfe-commits
@@ -2026,6 +2027,137 @@ static TryCastResult TryConstCast(Sema &Self, ExprResult &SrcExpr, return TC_Success; } +// We're dereferencing E, either by turning into an RValue, or by dereferencing +// it. Check whether it's a deref of a reinterpret cast that has aliasing +// is

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-03 Thread Vlad Serebrennikov via cfe-commits
@@ -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::A

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-03 Thread Vlad Serebrennikov via cfe-commits
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/74155 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-03 Thread Vlad Serebrennikov via cfe-commits
https://github.com/Endilll commented: Thank you for your efforts! I scratched the surface a bit; not qualified to do an in-depth review. Can you also add a release note? https://github.com/llvm/llvm-project/pull/74155 ___ cfe-commits mailing list cfe-c

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-02 Thread Nathan Sidwell via cfe-commits
https://github.com/urnathan edited https://github.com/llvm/llvm-project/pull/74155 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-02 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Nathan Sidwell (urnathan) Changes This implements -Wstrict-aliasing(=[123])? along the same lines as GCC. It's not 100% the same for reasons expanded on below. The default is level 3, and I have verified

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-02 Thread Nathan Sidwell via cfe-commits
https://github.com/urnathan ready_for_review https://github.com/llvm/llvm-project/pull/74155 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang] Strict aliasing warning ala GCC [PR50066] (PR #74155)

2023-12-01 Thread Nathan Sidwell via cfe-commits
https://github.com/urnathan created https://github.com/llvm/llvm-project/pull/74155 This implements -Wstrict-aliasing(=[123])? along the same lines as GCC. It's not 100% the same for reasons expanded on below. The default is level 3, and I have verified that bootstrapping does not trigger any