hokein added inline comments.
================ Comment at: clang/lib/Parse/ParseDeclCXX.cpp:2069-2078 + if (auto *TagDecl = Actions.ActOnTag( + getCurScope(), TagType, TUK, StartLoc, SS, Name, NameLoc, attrs, AS, + DS.getModulePrivateSpecLoc(), TParams, Owned, IsDependent, + SourceLocation(), false, clang::TypeResult(), + DSC == DeclSpecContext::DSC_type_specifier, + DSC == DeclSpecContext::DSC_template_param || + DSC == DeclSpecContext::DSC_template_type_arg, ---------------- aaron.ballman wrote: > I think this is the wrong approach to fixing the issue. None of the other > assignments to `TagOrTempResult` test for nullptr first, such as: > https://github.com/llvm/llvm-project/blob/main/clang/lib/Parse/ParseDeclCXX.cpp#L2037 > and > https://github.com/llvm/llvm-project/blob/main/clang/lib/Parse/ParseDeclCXX.cpp#L2029. > > An `ActionResult` can be both valid/invalid *and* usable/unusable (and a > `DeclResult` is a kind of `ActionResult`). When it's assigned *any pointer > value* (including nullptr), it's a valid `ActionResult` but it's not a usable > `ActionResult` > (https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Sema/Ownership.h#L166). > > I think the correct fix is to find the places assuming a valid `ActionResult` > means a nonnull pointer from `get()`, such as > https://github.com/llvm/llvm-project/blob/main/clang/lib/Parse/ParseDeclCXX.cpp#L2121 > and switch them over to looking for a usable `ActionResult` instead. Thanks for the comment! > None of the other assignments to TagOrTempResult test for nullptr first I think the problem here is: - most of the `ActOn*` methods return a `DeclResult` (and inside these method implementations, they return an Invalid `DeclResult` if the Decl is nullptr), so `TagOrTempResult = Actions.ActOn*` is a fine pattern. - Only two exceptions `ActOnTagDecl` and `ActOnTemplatedFriendTag`, they return a `Decl*`, so the `TagOrTempResult = Action.ActOn*` is a very suspicious pattern. (IMO, they're not intentional, likely bugs). > such as: > https://github.com/llvm/llvm-project/blob/main/clang/lib/Parse/ParseDeclCXX.cpp#L2037 > and > https://github.com/llvm/llvm-project/blob/main/clang/lib/Parse/ParseDeclCXX.cpp#L2029. The first one is the other exception; the second one is not (ActOnExplicitInstantiation returns a `DeclResult`). > I think the correct fix is to find the places assuming a valid ActionResult > means a nonnull pointer from get(), such as > https://github.com/llvm/llvm-project/blob/main/clang/lib/Parse/ParseDeclCXX.cpp#L2121 > and switch them over to looking for a usable ActionResult instead. This is one of the solutions. But instead of justifying every places of DeclResult, I think we should fix the two exception places (by adding the nullptr check in https://github.com/llvm/llvm-project/blob/main/clang/lib/Parse/ParseDeclCXX.cpp#L2037 and https://github.com/llvm/llvm-project/blob/main/clang/lib/Parse/ParseDeclCXX.cpp#L2069), what do you think? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D141580/new/ https://reviews.llvm.org/D141580 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits