[clang] 1029747 - [Sema] Fix null pointer dereference handleAlwaysInlineAttr.

Voss, Matthew via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 16 20:23:12 PDT 2023


LG. Thanks!

> -----Original Message-----
> From: Craig Topper <craig.topper at sifive.com>
> Sent: Thursday, March 16, 2023 8:01 PM
> To: Voss, Matthew <Matthew.Voss at sony.com>
> Cc: Craig Topper <llvmlistbot at llvm.org>; cfe-commits at lists.llvm.org
> Subject: Re: [clang] 1029747 - [Sema] Fix null pointer dereference
> handleAlwaysInlineAttr.
> 
> Thanks for the heads up. Looks like we have a different default C++ standard
> enabled than what the tests got in my local testing. I’ll revert and make a fix.
> 
> > On Mar 16, 2023, at 7:53 PM, Voss, Matthew <Matthew.Voss at sony.com>
> wrote:
> >
> > Hi Craig,
> >
> > There are some failures on the PS5 buildbot after this change. Could you take a
> look?
> >
> > INVALID URI REMOVED
> >
> 16/builds/18474__;Iw!!JmoZiZGBv3RvKRSx!8a7C6K5aa0CE1QTOIygEPamFI5WL
> KVq
> > Q-REw0n6KCF54tqKP7df8KtY_duKszo3lif-L572623pQ5nsE68Mw6YhD$
> >
> > Thanks,
> > Matt
> >
> >> -----Original Message-----
> >> From: cfe-commits <cfe-commits-bounces at lists.llvm.org> On Behalf Of
> >> Craig Topper via cfe-commits
> >> Sent: Thursday, March 16, 2023 5:52 PM
> >> To: cfe-commits at lists.llvm.org
> >> Subject: [clang] 1029747 - [Sema] Fix null pointer dereference
> >> handleAlwaysInlineAttr.
> >>
> >>
> >> Author: Craig Topper
> >> Date: 2023-03-16T17:49:34-07:00
> >> New Revision: 10297470e953f4f3968c54c851c8af82b07af00b
> >>
> >> URL: INVALID URI REMOVED
> >>
> project/commit/10297470e953f4f3968c54c851c8af82b07af00b__;!!JmoZiZGBv
> >> 3RvKRSx!5T2bYoGu6_sqxRYd-ZFC--KklLgMVa3mP6dp-
> >> DaM426lCB_1eQvZAEGwE8Pe2BFekx30eRBU7KU4wdK2-3ln_WfRflk$
> >> DIFF: INVALID URI REMOVED
> >>
> project/commit/10297470e953f4f3968c54c851c8af82b07af00b.diff__;!!JmoZ
> >> iZ
> >> GBv3RvKRSx!5T2bYoGu6_sqxRYd-ZFC--KklLgMVa3mP6dp-
> >> DaM426lCB_1eQvZAEGwE8Pe2BFekx30eRBU7KU4wdK2-3lnHdJlBwk$
> >>
> >> LOG: [Sema] Fix null pointer dereference handleAlwaysInlineAttr.
> >>
> >> It's possible for `getCalleeDecl()` to return a null pointer.
> >>
> >> This was encountered by a user of our downstream compiler.
> >>
> >> The case involved a DependentScopeDeclRefExpr.
> >>
> >> Since this seems to only be for a warning diagnostic, I skipped the
> >> diagnostic check if it returned null. But mabye there's a different way to fix
> this.
> >>
> >> Reviewed By: erichkeane
> >>
> >> Differential Revision:
> >> https://reviews.llvm.org/D146089
> >> iZGBv3RvKRSx!8a7C6K5aa0CE1QTOIygEPamFI5WLKVqQ-
> REw0n6KCF54tqKP7df8KtY_
> >> duKszo3lif-L572623pQ5nsE6xcR7geM$
> >> 3RvKRSx!5T2bYoGu6_sqxRYd-ZFC--KklLgMVa3mP6dp-
> >> DaM426lCB_1eQvZAEGwE8Pe2BFekx30eRBU7KU4wdK2-3lnaIroE7Q$
> >>
> >> Added:
> >>
> >>
> >> Modified:
> >>    clang/lib/Sema/SemaStmtAttr.cpp
> >>    clang/test/Sema/attr-alwaysinline.cpp
> >>    clang/test/Sema/attr-noinline.cpp
> >>
> >> Removed:
> >>
> >>
> >>
> >>
> #################################################################
> >> ###############
> >> diff  --git a/clang/lib/Sema/SemaStmtAttr.cpp
> >> b/clang/lib/Sema/SemaStmtAttr.cpp index 6d443837a4c5..eeef85373ccb
> >> 100644
> >> --- a/clang/lib/Sema/SemaStmtAttr.cpp
> >> +++ b/clang/lib/Sema/SemaStmtAttr.cpp
> >> @@ -233,7 +233,8 @@ static Attr *handleNoInlineAttr(Sema &S, Stmt
> >> *St, const ParsedAttr &A,
> >>
> >>   for (const auto *CallExpr : CEF.getCallExprs()) {
> >>     const Decl *Decl = CallExpr->getCalleeDecl();
> >> -    if (Decl->hasAttr<AlwaysInlineAttr>() || Decl->hasAttr<FlattenAttr>())
> >> +    if (Decl &&
> >> +        (Decl->hasAttr<AlwaysInlineAttr>() ||
> >> + Decl->hasAttr<FlattenAttr>()))
> >>       S.Diag(St->getBeginLoc(),
> diag::warn_function_stmt_attribute_precedence)
> >>           << A << (Decl->hasAttr<AlwaysInlineAttr>() ? 0 : 1);
> >>   }
> >> @@ -259,7 +260,7 @@ static Attr *handleAlwaysInlineAttr(Sema &S, Stmt
> >> *St, const ParsedAttr &A,
> >>
> >>   for (const auto *CallExpr : CEF.getCallExprs()) {
> >>     const Decl *Decl = CallExpr->getCalleeDecl();
> >> -    if (Decl->hasAttr<NoInlineAttr>() || Decl->hasAttr<FlattenAttr>())
> >> +    if (Decl && (Decl->hasAttr<NoInlineAttr>() ||
> >> + Decl->hasAttr<FlattenAttr>()))
> >>       S.Diag(St->getBeginLoc(),
> diag::warn_function_stmt_attribute_precedence)
> >>           << A << (Decl->hasAttr<NoInlineAttr>() ? 2 : 1);
> >>   }
> >>
> >> diff  --git a/clang/test/Sema/attr-alwaysinline.cpp
> >> b/clang/test/Sema/attr- alwaysinline.cpp index
> >> 6b8e8f215a4b..213d70407f48 100644
> >> --- a/clang/test/Sema/attr-alwaysinline.cpp
> >> +++ b/clang/test/Sema/attr-alwaysinline.cpp
> >> @@ -25,3 +25,22 @@ void foo() {
> >> }
> >>
> >> [[clang::always_inline]] static int i = bar(); // expected-warning
> {{'always_inline'
> >> attribute only applies to functions and statements}}
> >> +
> >> +// This used to crash the compiler.
> >> +template<int D>
> >> +int foo(int x) {
> >> +    if constexpr (D > 1)
> >> +        [[clang::always_inline]] return foo<D-1>(x + 1);
> >> +    else
> >> +        return x;
> >> +}
> >> +
> >> +// FIXME: This should warn that always_inline statement attribute
> >> +has higher // precedence than the noinline function attribute.
> >> +template<int D> [[gnu::noinline]]
> >> +int bar(int x) {
> >> +    if constexpr (D > 1)
> >> +        [[clang::always_inline]] return bar<D-1>(x + 1);
> >> +    else
> >> +        return x;
> >> +}
> >>
> >> diff  --git a/clang/test/Sema/attr-noinline.cpp
> >> b/clang/test/Sema/attr- noinline.cpp index d35782f11adb..a62ca1debcc5
> >> 100644
> >> --- a/clang/test/Sema/attr-noinline.cpp
> >> +++ b/clang/test/Sema/attr-noinline.cpp
> >> @@ -25,3 +25,22 @@ void foo() {
> >> }
> >>
> >> [[clang::noinline]] static int i = bar(); // expected-warning
> >> {{'noinline' attribute only applies to functions and statements}}
> >> +
> >> +// This used to crash the compiler.
> >> +template<int D>
> >> +int foo(int x) {
> >> +    if constexpr (D > 1)
> >> +        [[clang::noinline]] return foo<D-1>(x + 1);
> >> +    else
> >> +        return x;
> >> +}
> >> +
> >> +// FIXME: This should warn that noinline statement attribute has
> >> +higher // precedence than the always_inline function attribute.
> >> +template<int D> [[clang::always_inline]] int bar(int x) {
> >> +    if constexpr (D > 1)
> >> +        [[clang::noinline]] return bar<D-1>(x + 1);
> >> +    else
> >> +        return x;
> >> +}
> >>
> >>
> >>
> >> _______________________________________________
> >> cfe-commits mailing list
> >> cfe-commits at lists.llvm.org
> >> INVALID URI REMOVED
> >> commits__;!!JmoZiZGBv3RvKRSx!5T2bYoGu6_sqxRYd-ZFC--
> KklLgMVa3mP6dp-
> >> DaM426lCB_1eQvZAEGwE8Pe2BFekx30eRBU7KU4wdK2-3lnIjBE824$



More information about the cfe-commits mailing list