llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Oliver Hunt (ojhunt)

<details>
<summary>Changes</summary>

CheckAsmLabel fails to check for an incomplete type before attempting to get 
the type layout. Short circuit on an incomplete type as Sema will already 
reject a global with an incomplete type.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaDecl.cpp (+4) 
- (added) clang/test/Sema/global-explicit-register-undefined-type.c (+9) 


``````````diff
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 07c6157ab8f31..4850cb5a6cb9f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7756,6 +7756,10 @@ void Sema::CheckAsmLabel(Scope *S, Expr *E, StorageClass 
SC,
   StringLiteral *SE = cast<StringLiteral>(E);
   StringRef Label = SE->getString();
   QualType R = TInfo->getType();
+  if (RequireCompleteType(NewVD->getBeginLoc(), R, 
diag::err_typecheck_decl_incomplete_type)) {
+    NewVD->setInvalidDecl();
+    return;
+  }
   if (S->getFnParent() != nullptr) {
     switch (SC) {
     case SC_None:
diff --git a/clang/test/Sema/global-explicit-register-undefined-type.c 
b/clang/test/Sema/global-explicit-register-undefined-type.c
new file mode 100644
index 0000000000000..690dc0a9efddb
--- /dev/null
+++ b/clang/test/Sema/global-explicit-register-undefined-type.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -triple arm64-apple-macosx -fsyntax-only -verify
+
+register struct Undefined1 bar asm("x1"); // #inline-type-def
+// expected-error@#inline-type-def {{variable has incomplete type 'struct 
Undefined1'}}
+// expected-note@#inline-type-def {{forward declaration of 'struct 
Undefined1'}}
+struct Undefined2; // #outline-type-def
+register struct Undefined2 bar asm("x1"); // #outline-type-label
+// expected-error@#outline-type-label {{variable has incomplete type 'struct 
Undefined2'}}
+// expected-note@#outline-type-def {{forward declaration of 'struct 
Undefined2'}}

``````````

</details>


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

Reply via email to