Deep Majumder via llvm-dev
2021-Jan-19 08:46 UTC
[llvm-dev] Query about Clang Static Analyzer behaviour
Hi everyone, The following is a code from a test in the Clang Static Analyzer (clang/test/Analysis/pointer-to-member.cpp): Why are the last two statements expected to produce a warning? struct B { int f; }; struct L1 : public B { }; struct R1 : public B { }; struct M : public L1, R1 { }; struct L2 : public M { }; struct R2 : public M { }; struct D2 : public L2, R2 { }; void diamond() { M m; static_cast<L1 *>(&m)->f = 7; static_cast<R1 *>(&m)->f = 16; int L1::* pl1 = &B::f; int M::* pm_via_l1 = pl1; int R1::* pr1 = &B::f; int M::* pm_via_r1 = pr1; clang_analyzer_eval(m.*(pm_via_l1) == 7); // expected-warning {{TRUE}} clang_analyzer_eval(m.*(pm_via_r1) == 16); // expected-warning {{TRUE}} } Warm Regards, Deep -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210119/20e36cb2/attachment.html>
David Blaikie via llvm-dev
2021-Jan-19 17:38 UTC
[llvm-dev] Query about Clang Static Analyzer behaviour
It's a testing tool for the analyzer: https://clang.llvm.org/docs/analyzer/developer-docs/DebugChecks.html#exprinspection-checks On Tue, Jan 19, 2021 at 12:46 AM Deep Majumder via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > Hi everyone, > The following is a code from a test in the Clang Static Analyzer (clang/test/Analysis/pointer-to-member.cpp): Why are the last two statements expected to produce a warning? > struct B { > int f; > }; > struct L1 : public B { }; > struct R1 : public B { }; > struct M : public L1, R1 { }; > struct L2 : public M { }; > struct R2 : public M { }; > struct D2 : public L2, R2 { }; > > void diamond() { > M m; > > static_cast<L1 *>(&m)->f = 7; > static_cast<R1 *>(&m)->f = 16; > > int L1::* pl1 = &B::f; > int M::* pm_via_l1 = pl1; > > int R1::* pr1 = &B::f; > int M::* pm_via_r1 = pr1; > > clang_analyzer_eval(m.*(pm_via_l1) == 7); // expected-warning {{TRUE}} > clang_analyzer_eval(m.*(pm_via_r1) == 16); // expected-warning {{TRUE}} > } > Warm Regards, > Deep > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev