[PATCH] D141580: [clang] Don't consider a nullptr returned from ActOnTag() as a valid result in ParseClassSpecifier.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 12 09:40:20 PST 2023


aaron.ballman added a comment.

In D141580#4047737 <https://reviews.llvm.org/D141580#4047737>, @shafik wrote:

> I wonder if `ActionResult` needs a overload that takes `std::nullptr_t` the current interface seems easy to use wrong like we have seen here.
>
> @aaron.ballman wdyt?

I don't think that'll help in this case because the `ActionResult` is being constructed from a pointer (which happens to be null) and not a `nullptr` constant.



================
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,
----------------
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.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141580/new/

https://reviews.llvm.org/D141580



More information about the cfe-commits mailing list