[clang] Reland #90786 ([BoundsSafety] Allow 'counted_by' attribute on pointers in structs in C) (PR #93121)

Dan Liew via cfe-commits cfe-commits at lists.llvm.org
Thu May 23 13:32:20 PDT 2024


================
@@ -4944,6 +4944,26 @@ void Parser::ParseStructDeclaration(
   }
 }
 
+// TODO: All callers of this function should be moved to
+// `Parser::ParseLexedAttributeList`.
+void Parser::ParseLexedCAttributeList(LateParsedAttrList &LAs, bool EnterScope,
+                                      ParsedAttributes *OutAttrs) {
+  assert(LAs.parseSoon() &&
+         "Attribute list should be marked for immediate parsing.");
+#ifndef NDEBUG
+  auto LangStd = getLangOpts().LangStd;
+  if (LangStd != LangStandard::lang_unspecified) {
+    auto Lang = LangStandard::getLangStandardForKind(LangStd).getLanguage();
+    assert(Lang == Language::C || Lang == Language::OpenCL);
----------------
delcypher wrote:

So parsing a `.m` file without specifying a language seems to result in

```
(lldb) p LangOpts.LangStd
(clang::LangStandard::Kind) lang_gnu11
(lldb) p LangOpts.ObjC
(unsigned int) 1
(lldb) p LangOpts.C99
(unsigned int) 1
(lldb) p LangOpts.C11
(unsigned int) 1
(lldb) p LangOpts.C17
(unsigned int) 0
(lldb) p LangOpts.C23
(unsigned int) 0
(lldb) p LangOpts.CPlusPlus
(unsigned int) 0
(lldb) p clang::LangStandard::getLangStandardForKind(LangOpts.LangStd).getLanguage()
(clang::Language) C
```

So my assert doesn't do the right thing for Objective-C. For Objective-C my assert thinks its C 🤦‍♂️. So it seems like my assert would want to be `assert(!getLangOpts().CPlusPlus && !getLangOpts().ObjC)`. However, I think I'll remove this assert for now because I intend (provided I can make it to work with our internal code) to remove this code entirely in favor of re-using the late parsing code that's used for C++.

https://github.com/llvm/llvm-project/pull/93121


More information about the cfe-commits mailing list