Skip to content

release/20.x: [clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (#142749) #142909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: release/20.x
Choose a base branch
from

Conversation

llvmbot
Copy link
Member

@llvmbot llvmbot commented Jun 5, 2025

Backport 7ca7bcb

Requested by: @anutosh491

…l language models (llvm#142749)

As can be seen through the docs
(https://github.com/llvm/llvm-project/blob/7e1fa09ce2a228c949ce4490c98f2c73ed8ada00/clang/docs/LanguageExtensions.rst#c-keywords-supported-in-all-language-modes),
Clang supports certain C keywords in all language modes — this patch
ensures clang-repl handles them consistently.

Here's an example testing all the above keywords. We have everything in
place except `_Imaginary` (_Complex works but _Imaginary doesn't which
was weird) and `_Noreturn`

(cherry picked from commit 7ca7bcb)
@llvmbot
Copy link
Member Author

llvmbot commented Jun 5, 2025

@vgvassilev What do you think about merging this PR to the release branch?

@llvmbot llvmbot requested a review from vgvassilev June 5, 2025 06:42
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jun 5, 2025
@llvmbot
Copy link
Member Author

llvmbot commented Jun 5, 2025

@llvm/pr-subscribers-clang

Author: None (llvmbot)

Changes

Backport 7ca7bcb

Requested by: @anutosh491


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

2 Files Affected:

  • (modified) clang/lib/Parse/ParseTentative.cpp (+2)
  • (modified) clang/test/Interpreter/disambiguate-decl-stmt.cpp (+13)
diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp
index ff27ef70944a4..27cdf2f90f51f 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -1504,6 +1504,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
   case tok::kw_inline:
   case tok::kw_virtual:
   case tok::kw_explicit:
+  case tok::kw__Noreturn:
 
     // Modules
   case tok::kw___module_private__:
@@ -1558,6 +1559,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
     // GNU
   case tok::kw_restrict:
   case tok::kw__Complex:
+  case tok::kw__Imaginary:
   case tok::kw___attribute:
   case tok::kw___auto_type:
     return TPResult::True;
diff --git a/clang/test/Interpreter/disambiguate-decl-stmt.cpp b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
index 1f4d5e267288b..f2a59c510f9a2 100644
--- a/clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -102,3 +102,16 @@ __attribute((noreturn)) Attrs2::Attrs2() = default;
 
 // Extra semicolon
 namespace N {};
+
+// Test C keywords supported in all language modes.
+// https://clang.llvm.org/docs/LanguageExtensions.html#c-keywords-supported-in-all-language-modes
+
+_Alignas(16) int aligned_var;
+int align = _Alignof(double);
+_Atomic int atomic_var = 0;
+_Complex double complex_val = 1.0 + 2.0i;
+_Float16 f = 1.5;
+_Thread_local int counter = 0;
+_Static_assert(sizeof(int) == 4, "int must be 4 bytes");
+_Imaginary float i = 2.0f; // expected-error {{imaginary types are not supported}}
+_Noreturn void noreturn_func() { while (true) {} }
\ No newline at end of file

@anutosh491
Copy link
Member

anutosh491 commented Jun 5, 2025

See #142933 (comment) (converting to draft)

@anutosh491 anutosh491 marked this pull request as draft June 5, 2025 09:11
@tstellar tstellar moved this from Needs Triage to Needs Fix in LLVM Release Status Jun 11, 2025
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
Status: Needs Fix
Development

Successfully merging this pull request may close these issues.

2 participants