llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Arnab Sarkar (28arnab)

<details>
<summary>Changes</summary>

At translation unit termination (Sema::ActOnEndOfTranslationUnit), tentative 
array definitions that were completed by later extern declarations (e.g., 
`extern int b[3];`) were still checking the type of the initial declaration 
rather than querying the most recent redeclaration. This caused completed 
tentative arrays to incorrectly fall back to a size of 1 and emit an erroneous 
warning.

This fix checks `VD-&gt;getMostRecentDecl()` during tentative definition 
processing and updates the variable's type if a later redeclaration has 
completed the array type.

Fixes: #<!-- -->242842  
Assisted-By: AI

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


1 Files Affected:

- (modified) clang/lib/Sema/Sema.cpp (+6) 


``````````diff
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index ebc8b85cf8a62..ece3421cf104a 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1515,6 +1515,12 @@ void Sema::ActOnEndOfTranslationUnit() {
     if (!VD || VD->isInvalidDecl() || !Seen.insert(VD).second)
       continue;
 
+    // If a later redeclaration (e.g. extern int b[3]) completed the type,
+    // update the tentative definition to use that completed type.
+    VarDecl *MostRecent = VD->getMostRecentDecl();
+    if (MostRecent != VD && !MostRecent->getType()->isIncompleteArrayType())
+      VD->setType(MostRecent->getType());
+
     if (const IncompleteArrayType *ArrayT
         = Context.getAsIncompleteArrayType(VD->getType())) {
       // Set the length of the array to 1 (C99 6.9.2p5).

``````````

</details>


https://github.com/llvm/llvm-project/pull/243855
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to