Skip to content

Fix auto type-specifier conflict crash - #209308

Merged
cor3ntin merged 1 commit into
llvm:mainfrom
osamakader:fix-auto-typespec-owned
Jul 14, 2026
Merged

Fix auto type-specifier conflict crash#209308
cor3ntin merged 1 commit into
llvm:mainfrom
osamakader:fix-auto-typespec-owned

Conversation

@osamakader

Copy link
Copy Markdown
Contributor

Clear owned type state when an invalid C++ auto/type-specifier conflict is converted to an error so invalid declarations cannot trip DeclSpec invariants.

Fixes #209000

Clear owned type state when an invalid C++ auto/type-specifier conflict is converted to an error so invalid declarations cannot trip DeclSpec invariants.

Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 13, 2026
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-clang

Author: Osama Abdelkader (osamakader)

Changes

Clear owned type state when an invalid C++ auto/type-specifier conflict is converted to an error so invalid declarations cannot trip DeclSpec invariants.

Fixes #209000


Full diff: https://github.com/llvm/llvm-project/pull/209308.diff

2 Files Affected:

  • (modified) clang/lib/Sema/DeclSpec.cpp (+1)
  • (modified) clang/test/SemaCXX/auto-cxx0x.cpp (+3)
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 3c882bc3a1003..4d20657d5e517 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -1349,6 +1349,7 @@ void DeclSpec::CheckTypeSpec(Sema &S, const PrintingPolicy &Policy) {
       }
       // Mark as error to prevent further processing
       TypeSpecType = TST_error;
+      TypeSpecOwned = false;
     } else if (!S.getLangOpts().CPlusPlus) {
       // For C, C23, etc., convert 'auto' to storage class specifier
       // (This is already handled above for C23, but keep for other C dialects)
diff --git a/clang/test/SemaCXX/auto-cxx0x.cpp b/clang/test/SemaCXX/auto-cxx0x.cpp
index a51b4798cbcb3..fa953f35723ef 100644
--- a/clang/test/SemaCXX/auto-cxx0x.cpp
+++ b/clang/test/SemaCXX/auto-cxx0x.cpp
@@ -11,6 +11,9 @@ void f() {
   auto int arr[10]; // expected-error {{'auto' cannot be combined with a type specifier}}
 }
 
+struct PR209000 {
+} auto; // expected-error {{'auto' cannot be combined with a type specifier}}
+
 typedef auto PR25449(); // expected-error {{'auto' not allowed in typedef}}
 
 thread_local auto x; // expected-error {{requires an initializer}}

@osamakader

Copy link
Copy Markdown
Contributor Author

Thanks @cor3ntin for the review. Can you please merge it when it's suitable, since I don't have a permission to do so.

@cor3ntin
cor3ntin merged commit 226acaf into llvm:main Jul 14, 2026
14 checks passed
pedroMVicente pushed a commit to pedroMVicente/llvm-project that referenced this pull request Jul 15, 2026
Clear owned type state when an invalid C++ auto/type-specifier conflict
is converted to an error so invalid declarations cannot trip DeclSpec
invariants.

Fixes llvm#209000
to268 added a commit to to268/llvm-project that referenced this pull request Aug 10, 2026
to268 added a commit to to268/llvm-project that referenced this pull request Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[clang] Assertion `!TypeSpecOwned || isDeclRep((TST)TypeSpecType)' failed.

2 participants