Skip to content

Revert "[HLSL] Implement default constant buffer $Globals" #128112

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

Merged
merged 1 commit into from
Feb 21, 2025

Conversation

hekota
Copy link
Member

@hekota hekota commented Feb 21, 2025

Reverts #125807

Reverting this change because of failing tests.

@hekota hekota marked this pull request as ready for review February 21, 2025 02:38
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:codegen IR generation bugs: mangling, exceptions, etc. HLSL HLSL Language Support labels Feb 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 21, 2025

@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-hlsl

Author: Helena Kotas (hekota)

Changes

Reverts llvm/llvm-project#125807

Reverting this change because of failing tests.


Patch is 20.20 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/128112.diff

10 Files Affected:

  • (modified) clang/include/clang/AST/Decl.h (-30)
  • (modified) clang/include/clang/Sema/SemaHLSL.h (+1-6)
  • (modified) clang/lib/AST/Decl.cpp (-36)
  • (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+1-1)
  • (modified) clang/lib/CodeGen/CodeGenModule.cpp (-5)
  • (modified) clang/lib/Sema/Sema.cpp (+2-1)
  • (modified) clang/lib/Sema/SemaHLSL.cpp (+5-40)
  • (removed) clang/test/AST/HLSL/default_cbuffer.hlsl (-50)
  • (modified) clang/test/CodeGenHLSL/basic_types.hlsl (+32-32)
  • (removed) clang/test/CodeGenHLSL/default_cbuffer.hlsl (-39)
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 86e6d1417ae79..0f96bf0762ca4 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -5045,11 +5045,6 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
   // LayoutStruct - Layout struct for the buffer
   CXXRecordDecl *LayoutStruct;
 
-  // For default (implicit) constant buffer, a lisf of references of global
-  // decls that belong to the buffer. The decls are already parented by the
-  // translation unit context.
-  SmallVector<Decl *> DefaultBufferDecls;
-
   HLSLBufferDecl(DeclContext *DC, bool CBuffer, SourceLocation KwLoc,
                  IdentifierInfo *ID, SourceLocation IDLoc,
                  SourceLocation LBrace);
@@ -5059,8 +5054,6 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
                                 bool CBuffer, SourceLocation KwLoc,
                                 IdentifierInfo *ID, SourceLocation IDLoc,
                                 SourceLocation LBrace);
-  static HLSLBufferDecl *CreateDefaultCBuffer(ASTContext &C,
-                                              DeclContext *LexicalParent);
   static HLSLBufferDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
 
   SourceRange getSourceRange() const override LLVM_READONLY {
@@ -5075,7 +5068,6 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
   bool hasValidPackoffset() const { return HasValidPackoffset; }
   const CXXRecordDecl *getLayoutStruct() const { return LayoutStruct; }
   void addLayoutStruct(CXXRecordDecl *LS);
-  void addDefaultBufferDecl(Decl *D);
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
@@ -5087,28 +5079,6 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
     return static_cast<HLSLBufferDecl *>(const_cast<DeclContext *>(DC));
   }
 
-  // Iterator for the buffer decls. For constant buffers explicitly declared
-  // with `cbuffer` keyword this will the list of decls parented by this
-  // HLSLBufferDecl (equal to `decls()`).
-  // For implicit $Globals buffer this will be the list of default buffer
-  // declarations stored in DefaultBufferDecls plus the implicit layout
-  // struct (the only child of HLSLBufferDecl in this case).
-  //
-  // The iterator uses llvm::concat_iterator to concatenate the lists
-  // `decls()` and `DefaultBufferDecls`. For non-default buffers
-  // `DefaultBufferDecls` is always empty.
-  using buffer_decl_iterator =
-      llvm::concat_iterator<Decl *const, SmallVector<Decl *>::const_iterator,
-                            decl_iterator>;
-  using buffer_decl_range = llvm::iterator_range<buffer_decl_iterator>;
-
-  buffer_decl_range buffer_decls() const {
-    return buffer_decl_range(buffer_decls_begin(), buffer_decls_end());
-  }
-  buffer_decl_iterator buffer_decls_begin() const;
-  buffer_decl_iterator buffer_decls_end() const;
-  bool buffer_decls_empty();
-
   friend class ASTDeclReader;
   friend class ASTDeclWriter;
 };
diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h
index c4006fd13da17..4f4bbe95476ee 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -105,13 +105,13 @@ class SemaHLSL : public SemaBase {
                          HLSLParamModifierAttr::Spelling Spelling);
   void ActOnTopLevelFunction(FunctionDecl *FD);
   void ActOnVariableDeclarator(VarDecl *VD);
-  void ActOnEndOfTranslationUnit(TranslationUnitDecl *TU);
   void CheckEntryPoint(FunctionDecl *FD);
   void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param,
                                const HLSLAnnotationAttr *AnnotationAttr);
   void DiagnoseAttrStageMismatch(
       const Attr *A, llvm::Triple::EnvironmentType Stage,
       std::initializer_list<llvm::Triple::EnvironmentType> AllowedStages);
+  void DiagnoseAvailabilityViolations(TranslationUnitDecl *TU);
 
   QualType handleVectorBinOpConversion(ExprResult &LHS, ExprResult &RHS,
                                        QualType LHSType, QualType RHSType,
@@ -168,16 +168,11 @@ class SemaHLSL : public SemaBase {
   // List of all resource bindings
   ResourceBindings Bindings;
 
-  // default constant buffer $Globals
-  HLSLBufferDecl *DefaultCBuffer;
-
 private:
   void collectResourceBindingsOnVarDecl(VarDecl *D);
   void collectResourceBindingsOnUserRecordDecl(const VarDecl *VD,
                                                const RecordType *RT);
   void processExplicitBindingsOnDecl(VarDecl *D);
-
-  void diagnoseAvailabilityViolations(TranslationUnitDecl *TU);
 };
 
 } // namespace clang
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 9c0be5ce04542..5a3be1690f335 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -57,7 +57,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
@@ -5746,17 +5745,6 @@ HLSLBufferDecl *HLSLBufferDecl::Create(ASTContext &C,
   return Result;
 }
 
-HLSLBufferDecl *
-HLSLBufferDecl::CreateDefaultCBuffer(ASTContext &C,
-                                     DeclContext *LexicalParent) {
-  DeclContext *DC = LexicalParent;
-  IdentifierInfo *II = &C.Idents.get("$Globals", tok::TokenKind::identifier);
-  HLSLBufferDecl *Result = new (C, DC) HLSLBufferDecl(
-      DC, true, SourceLocation(), II, SourceLocation(), SourceLocation());
-  Result->setImplicit(true);
-  return Result;
-}
-
 HLSLBufferDecl *HLSLBufferDecl::CreateDeserialized(ASTContext &C,
                                                    GlobalDeclID ID) {
   return new (C, ID) HLSLBufferDecl(nullptr, false, SourceLocation(), nullptr,
@@ -5769,30 +5757,6 @@ void HLSLBufferDecl::addLayoutStruct(CXXRecordDecl *LS) {
   addDecl(LS);
 }
 
-void HLSLBufferDecl::addDefaultBufferDecl(Decl *D) {
-  assert(isImplicit() &&
-         "default decls can only be added to the implicit/default constant "
-         "buffer $Globals");
-  DefaultBufferDecls.push_back(D);
-}
-
-HLSLBufferDecl::buffer_decl_iterator
-HLSLBufferDecl::buffer_decls_begin() const {
-  return buffer_decl_iterator(llvm::iterator_range(DefaultBufferDecls.begin(),
-                                                   DefaultBufferDecls.end()),
-                              decl_range(decls_begin(), decls_end()));
-}
-
-HLSLBufferDecl::buffer_decl_iterator HLSLBufferDecl::buffer_decls_end() const {
-  return buffer_decl_iterator(
-      llvm::iterator_range(DefaultBufferDecls.end(), DefaultBufferDecls.end()),
-      decl_range(decls_end(), decls_end()));
-}
-
-bool HLSLBufferDecl::buffer_decls_empty() {
-  return DefaultBufferDecls.empty() && decls_empty();
-}
-
 //===----------------------------------------------------------------------===//
 // ImportDecl Implementation
 //===----------------------------------------------------------------------===//
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index ed6d2036cb984..547220fb1f1e1 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -116,7 +116,7 @@ void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
   BufGlobals.push_back(ValueAsMetadata::get(BufGV));
 
   const auto *ElemIt = LayoutStruct->element_begin();
-  for (Decl *D : BufDecl->buffer_decls()) {
+  for (Decl *D : BufDecl->decls()) {
     if (isa<CXXRecordDecl, EmptyDecl>(D))
       // Nothing to do for this declaration.
       continue;
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 1b7d0ac89690e..7924c32fcf633 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5513,11 +5513,6 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
   if (getLangOpts().OpenCL && ASTTy->isSamplerT())
     return;
 
-  // HLSL default buffer constants will be emitted during HLSLBufferDecl codegen
-  if (getLangOpts().HLSL &&
-      D->getType().getAddressSpace() == LangAS::hlsl_constant)
-    return;
-
   // If this is OpenMP device, check if it is legal to emit this global
   // normally.
   if (LangOpts.OpenMPIsTargetDevice && OpenMPRuntime &&
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index c699e92985156..145cda6c46b9b 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1417,7 +1417,8 @@ void Sema::ActOnEndOfTranslationUnit() {
   }
 
   if (LangOpts.HLSL)
-    HLSL().ActOnEndOfTranslationUnit(getASTContext().getTranslationUnitDecl());
+    HLSL().DiagnoseAvailabilityViolations(
+        getASTContext().getTranslationUnitDecl());
 
   // If there were errors, disable 'unused' warnings since they will mostly be
   // noise. Don't warn for a use from a module: either we should warn on all
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index b2984234d6171..d26d85d5861b1 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -9,7 +9,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Sema/SemaHLSL.h"
-#include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Attrs.inc"
@@ -148,7 +147,7 @@ bool ResourceBindings::hasBindingInfoForDecl(const VarDecl *VD) const {
   return DeclToBindingListIndex.contains(VD);
 }
 
-SemaHLSL::SemaHLSL(Sema &S) : SemaBase(S), DefaultCBuffer(nullptr) {}
+SemaHLSL::SemaHLSL(Sema &S) : SemaBase(S) {}
 
 Decl *SemaHLSL::ActOnStartBuffer(Scope *BufferScope, bool CBuffer,
                                  SourceLocation KwLoc, IdentifierInfo *Ident,
@@ -226,7 +225,7 @@ static void validatePackoffset(Sema &S, HLSLBufferDecl *BufDecl) {
   // or on none.
   bool HasPackOffset = false;
   bool HasNonPackOffset = false;
-  for (auto *Field : BufDecl->buffer_decls()) {
+  for (auto *Field : BufDecl->decls()) {
     VarDecl *Var = dyn_cast<VarDecl>(Field);
     if (!Var)
       continue;
@@ -493,7 +492,7 @@ void createHostLayoutStructForBuffer(Sema &S, HLSLBufferDecl *BufDecl) {
   LS->setImplicit(true);
   LS->startDefinition();
 
-  for (Decl *D : BufDecl->buffer_decls()) {
+  for (Decl *D : BufDecl->decls()) {
     VarDecl *VD = dyn_cast<VarDecl>(D);
     if (!VD || VD->getStorageClass() == SC_Static ||
         VD->getType().getAddressSpace() == LangAS::hlsl_groupshared)
@@ -1929,19 +1928,7 @@ void DiagnoseHLSLAvailability::CheckDeclAvailability(NamedDecl *D,
 
 } // namespace
 
-void SemaHLSL::ActOnEndOfTranslationUnit(TranslationUnitDecl *TU) {
-  // process default CBuffer - create buffer layout struct and invoke codegenCGH
-  if (DefaultCBuffer) {
-    SemaRef.getCurLexicalContext()->addDecl(DefaultCBuffer);
-    createHostLayoutStructForBuffer(SemaRef, DefaultCBuffer);
-
-    DeclGroupRef DG(DefaultCBuffer);
-    SemaRef.Consumer.HandleTopLevelDecl(DG);
-  }
-  diagnoseAvailabilityViolations(TU);
-}
-
-void SemaHLSL::diagnoseAvailabilityViolations(TranslationUnitDecl *TU) {
+void SemaHLSL::DiagnoseAvailabilityViolations(TranslationUnitDecl *TU) {
   // Skip running the diagnostics scan if the diagnostic mode is
   // strict (-fhlsl-strict-availability) and the target shader stage is known
   // because all relevant diagnostics were already emitted in the
@@ -3004,14 +2991,6 @@ QualType SemaHLSL::getInoutParameterType(QualType Ty) {
   return Ty;
 }
 
-static bool IsDefaultBufferConstantDecl(VarDecl *VD) {
-  QualType QT = VD->getType();
-  return VD->getDeclContext()->isTranslationUnit() &&
-         QT.getAddressSpace() == LangAS::Default &&
-         VD->getStorageClass() != SC_Static &&
-         !isInvalidConstantBufferLeafElementType(QT.getTypePtr());
-}
-
 void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
   if (VD->hasGlobalStorage()) {
     // make sure the declaration has a complete type
@@ -3023,21 +3002,7 @@ void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
       return;
     }
 
-    // Global variables outside a cbuffer block that are not a resource, static,
-    // groupshared, or an empty array or struct belong to the default constant
-    // buffer $Globals
-    if (IsDefaultBufferConstantDecl(VD)) {
-      if (DefaultCBuffer == nullptr)
-        DefaultCBuffer = HLSLBufferDecl::CreateDefaultCBuffer(
-            SemaRef.getASTContext(), SemaRef.getCurLexicalContext());
-      // update address space to hlsl_constant
-      QualType NewTy = getASTContext().getAddrSpaceQualType(
-          VD->getType(), LangAS::hlsl_constant);
-      VD->setType(NewTy);
-      DefaultCBuffer->addDefaultBufferDecl(VD);
-    }
-
-    // find all resources bindings on decl
+    // find all resources on decl
     if (VD->getType()->isHLSLIntangibleType())
       collectResourceBindingsOnVarDecl(VD);
 
diff --git a/clang/test/AST/HLSL/default_cbuffer.hlsl b/clang/test/AST/HLSL/default_cbuffer.hlsl
deleted file mode 100644
index 9e0fce7cc53cf..0000000000000
--- a/clang/test/AST/HLSL/default_cbuffer.hlsl
+++ /dev/null
@@ -1,50 +0,0 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -ast-dump -o - %s | FileCheck %s
-
-struct EmptyStruct {
-};
-
-struct S {
-  RWBuffer<float> buf;
-  EmptyStruct es;
-  float ea[0];
-  float b;
-};
-
-// CHECK: VarDecl {{.*}} used a 'hlsl_constant float'
-float a;
-
-// CHECK: VarDecl {{.*}} b 'RWBuffer<float>':'hlsl::RWBuffer<float>'
-RWBuffer<float> b; 
-
-// CHECK: VarDecl {{.*}} c 'EmptyStruct'
-EmptyStruct c;
-
-// CHECK: VarDecl {{.*}} d 'float[0]'
-float d[0];
-
-// CHECK: VarDecl {{.*}} e 'RWBuffer<float>[2]'
-RWBuffer<float> e[2];
-
-// CHECK: VarDecl {{.*}} f 'groupshared float'
-groupshared float f;
-
-// CHECK: VarDecl {{.*}} g 'hlsl_constant float'
-float g;
-
-// CHECK: VarDecl {{.*}} h 'hlsl_constant S'
-S h;
-
-// CHECK: HLSLBufferDecl {{.*}} implicit cbuffer $Globals
-// CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_$Globals definition
-// CHECK: PackedAttr
-// CHECK-NEXT: FieldDecl {{.*}} a 'float'
-// CHECK-NEXT: FieldDecl {{.*}} g 'float'
-// CHECK-NEXT: FieldDecl {{.*}} h '__cblayout_S'
-
-// CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_S definition
-// CHECK: PackedAttr {{.*}} Implicit
-// CHECK-NEXT: FieldDecl {{.*}} b 'float'
-
-export float foo() {
-  return a;
-}
diff --git a/clang/test/CodeGenHLSL/basic_types.hlsl b/clang/test/CodeGenHLSL/basic_types.hlsl
index 362042654ea8c..d987af45a649f 100644
--- a/clang/test/CodeGenHLSL/basic_types.hlsl
+++ b/clang/test/CodeGenHLSL/basic_types.hlsl
@@ -6,38 +6,38 @@
 // RUN:   -emit-llvm -disable-llvm-passes -o - -DNAMESPACED| FileCheck %s
 
 
-// CHECK: @uint16_t_Val = external addrspace(2) global i16, align 2
-// CHECK: @int16_t_Val = external addrspace(2) global i16, align 2
-// CHECK: @uint_Val = external addrspace(2) global i32, align 4
-// CHECK: @uint64_t_Val = external addrspace(2) global i64, align 8
-// CHECK: @int64_t_Val = external addrspace(2) global i64, align 8
-// CHECK: @int16_t2_Val = external addrspace(2) global <2 x i16>, align 4
-// CHECK: @int16_t3_Val = external addrspace(2) global <3 x i16>, align 8
-// CHECK: @int16_t4_Val = external addrspace(2) global <4 x i16>, align 8
-// CHECK: @uint16_t2_Val = external addrspace(2) global <2 x i16>, align 4
-// CHECK: @uint16_t3_Val = external addrspace(2) global <3 x i16>, align 8
-// CHECK: @uint16_t4_Val = external addrspace(2) global <4 x i16>, align 8
-// CHECK: @int2_Val = external addrspace(2) global <2 x i32>, align 8
-// CHECK: @int3_Val = external addrspace(2) global <3 x i32>, align 16
-// CHECK: @int4_Val = external addrspace(2) global <4 x i32>, align 16
-// CHECK: @uint2_Val = external addrspace(2) global <2 x i32>, align 8
-// CHECK: @uint3_Val = external addrspace(2) global <3 x i32>, align 16
-// CHECK: @uint4_Val = external addrspace(2) global <4 x i32>, align 16
-// CHECK: @int64_t2_Val = external addrspace(2) global <2 x i64>, align 16
-// CHECK: @int64_t3_Val = external addrspace(2) global <3 x i64>, align 32
-// CHECK: @int64_t4_Val = external addrspace(2) global <4 x i64>, align 32
-// CHECK: @uint64_t2_Val = external addrspace(2) global <2 x i64>, align 16
-// CHECK: @uint64_t3_Val = external addrspace(2) global <3 x i64>, align 32
-// CHECK: @uint64_t4_Val = external addrspace(2) global <4 x i64>, align 32
-// CHECK: @half2_Val = external addrspace(2) global <2 x half>, align 4
-// CHECK: @half3_Val = external addrspace(2) global <3 x half>, align 8
-// CHECK: @half4_Val = external addrspace(2) global <4 x half>, align 8
-// CHECK: @float2_Val = external addrspace(2) global <2 x float>, align 8
-// CHECK: @float3_Val = external addrspace(2) global <3 x float>, align 16
-// CHECK: @float4_Val = external addrspace(2) global <4 x float>, align 16
-// CHECK: @double2_Val = external addrspace(2) global <2 x double>, align 16
-// CHECK: @double3_Val = external addrspace(2) global <3 x double>, align 32
-// CHECK: @double4_Val = external addrspace(2) global <4 x double>, align 32
+// CHECK: @uint16_t_Val = global i16 0, align 2
+// CHECK: @int16_t_Val = global i16 0, align 2
+// CHECK: @uint_Val = global i32 0, align 4
+// CHECK: @uint64_t_Val = global i64 0, align 8
+// CHECK: @int64_t_Val = global i64 0, align 8
+// CHECK: @int16_t2_Val = global <2 x i16> zeroinitializer, align 4
+// CHECK: @int16_t3_Val = global <3 x i16> zeroinitializer, align 8
+// CHECK: @int16_t4_Val = global <4 x i16> zeroinitializer, align 8
+// CHECK: @uint16_t2_Val = global <2 x i16> zeroinitializer, align 4
+// CHECK: @uint16_t3_Val = global <3 x i16> zeroinitializer, align 8
+// CHECK: @uint16_t4_Val = global <4 x i16> zeroinitializer, align 8
+// CHECK: @int2_Val = global <2 x i32> zeroinitializer, align 8
+// CHECK: @int3_Val = global <3 x i32> zeroinitializer, align 16
+// CHECK: @int4_Val = global <4 x i32> zeroinitializer, align 16
+// CHECK: @uint2_Val = global <2 x i32> zeroinitializer, align 8
+// CHECK: @uint3_Val = global <3 x i32> zeroinitializer, align 16
+// CHECK: @uint4_Val = global <4 x i32> zeroinitializer, align 16
+// CHECK: @int64_t2_Val = global <2 x i64> zeroinitializer, align 16
+// CHECK: @int64_t3_Val = global <3 x i64> zeroinitializer, align 32
+// CHECK: @int64_t4_Val = global <4 x i64> zeroinitializer, align 32
+// CHECK: @uint64_t2_Val = global <2 x i64> zeroinitializer, align 16
+// CHECK: @uint64_t3_Val = global <3 x i64> zeroinitializer, align 32
+// CHECK: @uint64_t4_Val = global <4 x i64> zeroinitializer, align 32
+// CHECK: @half2_Val = global <2 x half> zeroinitializer, align 4
+// CHECK: @half3_Val = global <3 x half> zeroinitializer, align 8
+// CHECK: @half4_Val = global <4 x half> zeroinitializer, align 8
+// CHECK: @float2_Val = global <2 x float> zeroinitializer, align 8
+// CHECK: @float3_Val = global <3 x float> zeroinitializer, align 16
+// CHECK: @float4_Val = global <4 x float> zeroinitializer, align 16
+// CHECK: @double2_Val = global <2 x double> zeroinitializer, align 16
+// CHECK: @double3_Val = global <3 x double> zeroinitializer, align 32
+// CHECK: @double4_Val = global <4 x double> zeroinitializer, align 32
 
 #ifdef NAMESPACED
 #define TYPE_DECL(T)  hlsl::T T##_Val
diff --git a/clang/test/CodeGenHLSL/default_cbuffer.hlsl b/clang/test/CodeGenHLSL/default_cbuffer.hlsl
deleted file mode 100644
index c5176aa8466e4..0000000000000
--- a/clang/test/CodeGenHLSL/default_cbuffer.hlsl
+++ /dev/null
@@ -1,39 +0,0 @@
-// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-compute \
-// RUN:   -fnative-half-type -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
-
-// CHECK: %"__cblayout_$Globals" = type <{ float, float, target("dx.Layout", %__cblayout_S, 4, 0) }>
-// CHECK: %__cblayout_S = type <{ float }>
-
-// CHECK-DAG: @"$Globals.cb" = external constant target("dx.CBuffer", target("dx.Layout", %"__cblayout_$Globals", 20, 0, 4, 16))
-// CHECK-DAG: @a = external addrspace(2) global float
-// CHECK-DAG: @g = external addrspace(2) global float
-// CHECK-DAG: @h = external addrspace(2) global target("dx.Layout", %__cblayout_S, 4, 0), align 4
-
-struct EmptyStruct {
-};
-
-struct S {
-  RWBuffer<float> buf;
-  EmptyStruct es;
-  float ea[0];
-  float b;
-};
-
-float a;
-RWBuffer<float> b; 
-EmptyStruct c;
-float d[0];
-RWBuffer<float> e[2];
-groupshared float f;
-float g;
-S h;
-
-RWBuffer<float> Buf;
...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Feb 21, 2025

@llvm/pr-subscribers-clang

Author: Helena Kotas (hekota)

Changes

Reverts llvm/llvm-project#125807

Reverting this change because of failing tests.


Patch is 20.20 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/128112.diff

10 Files Affected:

  • (modified) clang/include/clang/AST/Decl.h (-30)
  • (modified) clang/include/clang/Sema/SemaHLSL.h (+1-6)
  • (modified) clang/lib/AST/Decl.cpp (-36)
  • (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+1-1)
  • (modified) clang/lib/CodeGen/CodeGenModule.cpp (-5)
  • (modified) clang/lib/Sema/Sema.cpp (+2-1)
  • (modified) clang/lib/Sema/SemaHLSL.cpp (+5-40)
  • (removed) clang/test/AST/HLSL/default_cbuffer.hlsl (-50)
  • (modified) clang/test/CodeGenHLSL/basic_types.hlsl (+32-32)
  • (removed) clang/test/CodeGenHLSL/default_cbuffer.hlsl (-39)
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 86e6d1417ae79..0f96bf0762ca4 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -5045,11 +5045,6 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
   // LayoutStruct - Layout struct for the buffer
   CXXRecordDecl *LayoutStruct;
 
-  // For default (implicit) constant buffer, a lisf of references of global
-  // decls that belong to the buffer. The decls are already parented by the
-  // translation unit context.
-  SmallVector<Decl *> DefaultBufferDecls;
-
   HLSLBufferDecl(DeclContext *DC, bool CBuffer, SourceLocation KwLoc,
                  IdentifierInfo *ID, SourceLocation IDLoc,
                  SourceLocation LBrace);
@@ -5059,8 +5054,6 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
                                 bool CBuffer, SourceLocation KwLoc,
                                 IdentifierInfo *ID, SourceLocation IDLoc,
                                 SourceLocation LBrace);
-  static HLSLBufferDecl *CreateDefaultCBuffer(ASTContext &C,
-                                              DeclContext *LexicalParent);
   static HLSLBufferDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
 
   SourceRange getSourceRange() const override LLVM_READONLY {
@@ -5075,7 +5068,6 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
   bool hasValidPackoffset() const { return HasValidPackoffset; }
   const CXXRecordDecl *getLayoutStruct() const { return LayoutStruct; }
   void addLayoutStruct(CXXRecordDecl *LS);
-  void addDefaultBufferDecl(Decl *D);
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
@@ -5087,28 +5079,6 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
     return static_cast<HLSLBufferDecl *>(const_cast<DeclContext *>(DC));
   }
 
-  // Iterator for the buffer decls. For constant buffers explicitly declared
-  // with `cbuffer` keyword this will the list of decls parented by this
-  // HLSLBufferDecl (equal to `decls()`).
-  // For implicit $Globals buffer this will be the list of default buffer
-  // declarations stored in DefaultBufferDecls plus the implicit layout
-  // struct (the only child of HLSLBufferDecl in this case).
-  //
-  // The iterator uses llvm::concat_iterator to concatenate the lists
-  // `decls()` and `DefaultBufferDecls`. For non-default buffers
-  // `DefaultBufferDecls` is always empty.
-  using buffer_decl_iterator =
-      llvm::concat_iterator<Decl *const, SmallVector<Decl *>::const_iterator,
-                            decl_iterator>;
-  using buffer_decl_range = llvm::iterator_range<buffer_decl_iterator>;
-
-  buffer_decl_range buffer_decls() const {
-    return buffer_decl_range(buffer_decls_begin(), buffer_decls_end());
-  }
-  buffer_decl_iterator buffer_decls_begin() const;
-  buffer_decl_iterator buffer_decls_end() const;
-  bool buffer_decls_empty();
-
   friend class ASTDeclReader;
   friend class ASTDeclWriter;
 };
diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h
index c4006fd13da17..4f4bbe95476ee 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -105,13 +105,13 @@ class SemaHLSL : public SemaBase {
                          HLSLParamModifierAttr::Spelling Spelling);
   void ActOnTopLevelFunction(FunctionDecl *FD);
   void ActOnVariableDeclarator(VarDecl *VD);
-  void ActOnEndOfTranslationUnit(TranslationUnitDecl *TU);
   void CheckEntryPoint(FunctionDecl *FD);
   void CheckSemanticAnnotation(FunctionDecl *EntryPoint, const Decl *Param,
                                const HLSLAnnotationAttr *AnnotationAttr);
   void DiagnoseAttrStageMismatch(
       const Attr *A, llvm::Triple::EnvironmentType Stage,
       std::initializer_list<llvm::Triple::EnvironmentType> AllowedStages);
+  void DiagnoseAvailabilityViolations(TranslationUnitDecl *TU);
 
   QualType handleVectorBinOpConversion(ExprResult &LHS, ExprResult &RHS,
                                        QualType LHSType, QualType RHSType,
@@ -168,16 +168,11 @@ class SemaHLSL : public SemaBase {
   // List of all resource bindings
   ResourceBindings Bindings;
 
-  // default constant buffer $Globals
-  HLSLBufferDecl *DefaultCBuffer;
-
 private:
   void collectResourceBindingsOnVarDecl(VarDecl *D);
   void collectResourceBindingsOnUserRecordDecl(const VarDecl *VD,
                                                const RecordType *RT);
   void processExplicitBindingsOnDecl(VarDecl *D);
-
-  void diagnoseAvailabilityViolations(TranslationUnitDecl *TU);
 };
 
 } // namespace clang
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 9c0be5ce04542..5a3be1690f335 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -57,7 +57,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
@@ -5746,17 +5745,6 @@ HLSLBufferDecl *HLSLBufferDecl::Create(ASTContext &C,
   return Result;
 }
 
-HLSLBufferDecl *
-HLSLBufferDecl::CreateDefaultCBuffer(ASTContext &C,
-                                     DeclContext *LexicalParent) {
-  DeclContext *DC = LexicalParent;
-  IdentifierInfo *II = &C.Idents.get("$Globals", tok::TokenKind::identifier);
-  HLSLBufferDecl *Result = new (C, DC) HLSLBufferDecl(
-      DC, true, SourceLocation(), II, SourceLocation(), SourceLocation());
-  Result->setImplicit(true);
-  return Result;
-}
-
 HLSLBufferDecl *HLSLBufferDecl::CreateDeserialized(ASTContext &C,
                                                    GlobalDeclID ID) {
   return new (C, ID) HLSLBufferDecl(nullptr, false, SourceLocation(), nullptr,
@@ -5769,30 +5757,6 @@ void HLSLBufferDecl::addLayoutStruct(CXXRecordDecl *LS) {
   addDecl(LS);
 }
 
-void HLSLBufferDecl::addDefaultBufferDecl(Decl *D) {
-  assert(isImplicit() &&
-         "default decls can only be added to the implicit/default constant "
-         "buffer $Globals");
-  DefaultBufferDecls.push_back(D);
-}
-
-HLSLBufferDecl::buffer_decl_iterator
-HLSLBufferDecl::buffer_decls_begin() const {
-  return buffer_decl_iterator(llvm::iterator_range(DefaultBufferDecls.begin(),
-                                                   DefaultBufferDecls.end()),
-                              decl_range(decls_begin(), decls_end()));
-}
-
-HLSLBufferDecl::buffer_decl_iterator HLSLBufferDecl::buffer_decls_end() const {
-  return buffer_decl_iterator(
-      llvm::iterator_range(DefaultBufferDecls.end(), DefaultBufferDecls.end()),
-      decl_range(decls_end(), decls_end()));
-}
-
-bool HLSLBufferDecl::buffer_decls_empty() {
-  return DefaultBufferDecls.empty() && decls_empty();
-}
-
 //===----------------------------------------------------------------------===//
 // ImportDecl Implementation
 //===----------------------------------------------------------------------===//
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index ed6d2036cb984..547220fb1f1e1 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -116,7 +116,7 @@ void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
   BufGlobals.push_back(ValueAsMetadata::get(BufGV));
 
   const auto *ElemIt = LayoutStruct->element_begin();
-  for (Decl *D : BufDecl->buffer_decls()) {
+  for (Decl *D : BufDecl->decls()) {
     if (isa<CXXRecordDecl, EmptyDecl>(D))
       // Nothing to do for this declaration.
       continue;
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 1b7d0ac89690e..7924c32fcf633 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5513,11 +5513,6 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
   if (getLangOpts().OpenCL && ASTTy->isSamplerT())
     return;
 
-  // HLSL default buffer constants will be emitted during HLSLBufferDecl codegen
-  if (getLangOpts().HLSL &&
-      D->getType().getAddressSpace() == LangAS::hlsl_constant)
-    return;
-
   // If this is OpenMP device, check if it is legal to emit this global
   // normally.
   if (LangOpts.OpenMPIsTargetDevice && OpenMPRuntime &&
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index c699e92985156..145cda6c46b9b 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1417,7 +1417,8 @@ void Sema::ActOnEndOfTranslationUnit() {
   }
 
   if (LangOpts.HLSL)
-    HLSL().ActOnEndOfTranslationUnit(getASTContext().getTranslationUnitDecl());
+    HLSL().DiagnoseAvailabilityViolations(
+        getASTContext().getTranslationUnitDecl());
 
   // If there were errors, disable 'unused' warnings since they will mostly be
   // noise. Don't warn for a use from a module: either we should warn on all
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index b2984234d6171..d26d85d5861b1 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -9,7 +9,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Sema/SemaHLSL.h"
-#include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Attrs.inc"
@@ -148,7 +147,7 @@ bool ResourceBindings::hasBindingInfoForDecl(const VarDecl *VD) const {
   return DeclToBindingListIndex.contains(VD);
 }
 
-SemaHLSL::SemaHLSL(Sema &S) : SemaBase(S), DefaultCBuffer(nullptr) {}
+SemaHLSL::SemaHLSL(Sema &S) : SemaBase(S) {}
 
 Decl *SemaHLSL::ActOnStartBuffer(Scope *BufferScope, bool CBuffer,
                                  SourceLocation KwLoc, IdentifierInfo *Ident,
@@ -226,7 +225,7 @@ static void validatePackoffset(Sema &S, HLSLBufferDecl *BufDecl) {
   // or on none.
   bool HasPackOffset = false;
   bool HasNonPackOffset = false;
-  for (auto *Field : BufDecl->buffer_decls()) {
+  for (auto *Field : BufDecl->decls()) {
     VarDecl *Var = dyn_cast<VarDecl>(Field);
     if (!Var)
       continue;
@@ -493,7 +492,7 @@ void createHostLayoutStructForBuffer(Sema &S, HLSLBufferDecl *BufDecl) {
   LS->setImplicit(true);
   LS->startDefinition();
 
-  for (Decl *D : BufDecl->buffer_decls()) {
+  for (Decl *D : BufDecl->decls()) {
     VarDecl *VD = dyn_cast<VarDecl>(D);
     if (!VD || VD->getStorageClass() == SC_Static ||
         VD->getType().getAddressSpace() == LangAS::hlsl_groupshared)
@@ -1929,19 +1928,7 @@ void DiagnoseHLSLAvailability::CheckDeclAvailability(NamedDecl *D,
 
 } // namespace
 
-void SemaHLSL::ActOnEndOfTranslationUnit(TranslationUnitDecl *TU) {
-  // process default CBuffer - create buffer layout struct and invoke codegenCGH
-  if (DefaultCBuffer) {
-    SemaRef.getCurLexicalContext()->addDecl(DefaultCBuffer);
-    createHostLayoutStructForBuffer(SemaRef, DefaultCBuffer);
-
-    DeclGroupRef DG(DefaultCBuffer);
-    SemaRef.Consumer.HandleTopLevelDecl(DG);
-  }
-  diagnoseAvailabilityViolations(TU);
-}
-
-void SemaHLSL::diagnoseAvailabilityViolations(TranslationUnitDecl *TU) {
+void SemaHLSL::DiagnoseAvailabilityViolations(TranslationUnitDecl *TU) {
   // Skip running the diagnostics scan if the diagnostic mode is
   // strict (-fhlsl-strict-availability) and the target shader stage is known
   // because all relevant diagnostics were already emitted in the
@@ -3004,14 +2991,6 @@ QualType SemaHLSL::getInoutParameterType(QualType Ty) {
   return Ty;
 }
 
-static bool IsDefaultBufferConstantDecl(VarDecl *VD) {
-  QualType QT = VD->getType();
-  return VD->getDeclContext()->isTranslationUnit() &&
-         QT.getAddressSpace() == LangAS::Default &&
-         VD->getStorageClass() != SC_Static &&
-         !isInvalidConstantBufferLeafElementType(QT.getTypePtr());
-}
-
 void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
   if (VD->hasGlobalStorage()) {
     // make sure the declaration has a complete type
@@ -3023,21 +3002,7 @@ void SemaHLSL::ActOnVariableDeclarator(VarDecl *VD) {
       return;
     }
 
-    // Global variables outside a cbuffer block that are not a resource, static,
-    // groupshared, or an empty array or struct belong to the default constant
-    // buffer $Globals
-    if (IsDefaultBufferConstantDecl(VD)) {
-      if (DefaultCBuffer == nullptr)
-        DefaultCBuffer = HLSLBufferDecl::CreateDefaultCBuffer(
-            SemaRef.getASTContext(), SemaRef.getCurLexicalContext());
-      // update address space to hlsl_constant
-      QualType NewTy = getASTContext().getAddrSpaceQualType(
-          VD->getType(), LangAS::hlsl_constant);
-      VD->setType(NewTy);
-      DefaultCBuffer->addDefaultBufferDecl(VD);
-    }
-
-    // find all resources bindings on decl
+    // find all resources on decl
     if (VD->getType()->isHLSLIntangibleType())
       collectResourceBindingsOnVarDecl(VD);
 
diff --git a/clang/test/AST/HLSL/default_cbuffer.hlsl b/clang/test/AST/HLSL/default_cbuffer.hlsl
deleted file mode 100644
index 9e0fce7cc53cf..0000000000000
--- a/clang/test/AST/HLSL/default_cbuffer.hlsl
+++ /dev/null
@@ -1,50 +0,0 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -ast-dump -o - %s | FileCheck %s
-
-struct EmptyStruct {
-};
-
-struct S {
-  RWBuffer<float> buf;
-  EmptyStruct es;
-  float ea[0];
-  float b;
-};
-
-// CHECK: VarDecl {{.*}} used a 'hlsl_constant float'
-float a;
-
-// CHECK: VarDecl {{.*}} b 'RWBuffer<float>':'hlsl::RWBuffer<float>'
-RWBuffer<float> b; 
-
-// CHECK: VarDecl {{.*}} c 'EmptyStruct'
-EmptyStruct c;
-
-// CHECK: VarDecl {{.*}} d 'float[0]'
-float d[0];
-
-// CHECK: VarDecl {{.*}} e 'RWBuffer<float>[2]'
-RWBuffer<float> e[2];
-
-// CHECK: VarDecl {{.*}} f 'groupshared float'
-groupshared float f;
-
-// CHECK: VarDecl {{.*}} g 'hlsl_constant float'
-float g;
-
-// CHECK: VarDecl {{.*}} h 'hlsl_constant S'
-S h;
-
-// CHECK: HLSLBufferDecl {{.*}} implicit cbuffer $Globals
-// CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_$Globals definition
-// CHECK: PackedAttr
-// CHECK-NEXT: FieldDecl {{.*}} a 'float'
-// CHECK-NEXT: FieldDecl {{.*}} g 'float'
-// CHECK-NEXT: FieldDecl {{.*}} h '__cblayout_S'
-
-// CHECK: CXXRecordDecl {{.*}} implicit struct __cblayout_S definition
-// CHECK: PackedAttr {{.*}} Implicit
-// CHECK-NEXT: FieldDecl {{.*}} b 'float'
-
-export float foo() {
-  return a;
-}
diff --git a/clang/test/CodeGenHLSL/basic_types.hlsl b/clang/test/CodeGenHLSL/basic_types.hlsl
index 362042654ea8c..d987af45a649f 100644
--- a/clang/test/CodeGenHLSL/basic_types.hlsl
+++ b/clang/test/CodeGenHLSL/basic_types.hlsl
@@ -6,38 +6,38 @@
 // RUN:   -emit-llvm -disable-llvm-passes -o - -DNAMESPACED| FileCheck %s
 
 
-// CHECK: @uint16_t_Val = external addrspace(2) global i16, align 2
-// CHECK: @int16_t_Val = external addrspace(2) global i16, align 2
-// CHECK: @uint_Val = external addrspace(2) global i32, align 4
-// CHECK: @uint64_t_Val = external addrspace(2) global i64, align 8
-// CHECK: @int64_t_Val = external addrspace(2) global i64, align 8
-// CHECK: @int16_t2_Val = external addrspace(2) global <2 x i16>, align 4
-// CHECK: @int16_t3_Val = external addrspace(2) global <3 x i16>, align 8
-// CHECK: @int16_t4_Val = external addrspace(2) global <4 x i16>, align 8
-// CHECK: @uint16_t2_Val = external addrspace(2) global <2 x i16>, align 4
-// CHECK: @uint16_t3_Val = external addrspace(2) global <3 x i16>, align 8
-// CHECK: @uint16_t4_Val = external addrspace(2) global <4 x i16>, align 8
-// CHECK: @int2_Val = external addrspace(2) global <2 x i32>, align 8
-// CHECK: @int3_Val = external addrspace(2) global <3 x i32>, align 16
-// CHECK: @int4_Val = external addrspace(2) global <4 x i32>, align 16
-// CHECK: @uint2_Val = external addrspace(2) global <2 x i32>, align 8
-// CHECK: @uint3_Val = external addrspace(2) global <3 x i32>, align 16
-// CHECK: @uint4_Val = external addrspace(2) global <4 x i32>, align 16
-// CHECK: @int64_t2_Val = external addrspace(2) global <2 x i64>, align 16
-// CHECK: @int64_t3_Val = external addrspace(2) global <3 x i64>, align 32
-// CHECK: @int64_t4_Val = external addrspace(2) global <4 x i64>, align 32
-// CHECK: @uint64_t2_Val = external addrspace(2) global <2 x i64>, align 16
-// CHECK: @uint64_t3_Val = external addrspace(2) global <3 x i64>, align 32
-// CHECK: @uint64_t4_Val = external addrspace(2) global <4 x i64>, align 32
-// CHECK: @half2_Val = external addrspace(2) global <2 x half>, align 4
-// CHECK: @half3_Val = external addrspace(2) global <3 x half>, align 8
-// CHECK: @half4_Val = external addrspace(2) global <4 x half>, align 8
-// CHECK: @float2_Val = external addrspace(2) global <2 x float>, align 8
-// CHECK: @float3_Val = external addrspace(2) global <3 x float>, align 16
-// CHECK: @float4_Val = external addrspace(2) global <4 x float>, align 16
-// CHECK: @double2_Val = external addrspace(2) global <2 x double>, align 16
-// CHECK: @double3_Val = external addrspace(2) global <3 x double>, align 32
-// CHECK: @double4_Val = external addrspace(2) global <4 x double>, align 32
+// CHECK: @uint16_t_Val = global i16 0, align 2
+// CHECK: @int16_t_Val = global i16 0, align 2
+// CHECK: @uint_Val = global i32 0, align 4
+// CHECK: @uint64_t_Val = global i64 0, align 8
+// CHECK: @int64_t_Val = global i64 0, align 8
+// CHECK: @int16_t2_Val = global <2 x i16> zeroinitializer, align 4
+// CHECK: @int16_t3_Val = global <3 x i16> zeroinitializer, align 8
+// CHECK: @int16_t4_Val = global <4 x i16> zeroinitializer, align 8
+// CHECK: @uint16_t2_Val = global <2 x i16> zeroinitializer, align 4
+// CHECK: @uint16_t3_Val = global <3 x i16> zeroinitializer, align 8
+// CHECK: @uint16_t4_Val = global <4 x i16> zeroinitializer, align 8
+// CHECK: @int2_Val = global <2 x i32> zeroinitializer, align 8
+// CHECK: @int3_Val = global <3 x i32> zeroinitializer, align 16
+// CHECK: @int4_Val = global <4 x i32> zeroinitializer, align 16
+// CHECK: @uint2_Val = global <2 x i32> zeroinitializer, align 8
+// CHECK: @uint3_Val = global <3 x i32> zeroinitializer, align 16
+// CHECK: @uint4_Val = global <4 x i32> zeroinitializer, align 16
+// CHECK: @int64_t2_Val = global <2 x i64> zeroinitializer, align 16
+// CHECK: @int64_t3_Val = global <3 x i64> zeroinitializer, align 32
+// CHECK: @int64_t4_Val = global <4 x i64> zeroinitializer, align 32
+// CHECK: @uint64_t2_Val = global <2 x i64> zeroinitializer, align 16
+// CHECK: @uint64_t3_Val = global <3 x i64> zeroinitializer, align 32
+// CHECK: @uint64_t4_Val = global <4 x i64> zeroinitializer, align 32
+// CHECK: @half2_Val = global <2 x half> zeroinitializer, align 4
+// CHECK: @half3_Val = global <3 x half> zeroinitializer, align 8
+// CHECK: @half4_Val = global <4 x half> zeroinitializer, align 8
+// CHECK: @float2_Val = global <2 x float> zeroinitializer, align 8
+// CHECK: @float3_Val = global <3 x float> zeroinitializer, align 16
+// CHECK: @float4_Val = global <4 x float> zeroinitializer, align 16
+// CHECK: @double2_Val = global <2 x double> zeroinitializer, align 16
+// CHECK: @double3_Val = global <3 x double> zeroinitializer, align 32
+// CHECK: @double4_Val = global <4 x double> zeroinitializer, align 32
 
 #ifdef NAMESPACED
 #define TYPE_DECL(T)  hlsl::T T##_Val
diff --git a/clang/test/CodeGenHLSL/default_cbuffer.hlsl b/clang/test/CodeGenHLSL/default_cbuffer.hlsl
deleted file mode 100644
index c5176aa8466e4..0000000000000
--- a/clang/test/CodeGenHLSL/default_cbuffer.hlsl
+++ /dev/null
@@ -1,39 +0,0 @@
-// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-compute \
-// RUN:   -fnative-half-type -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
-
-// CHECK: %"__cblayout_$Globals" = type <{ float, float, target("dx.Layout", %__cblayout_S, 4, 0) }>
-// CHECK: %__cblayout_S = type <{ float }>
-
-// CHECK-DAG: @"$Globals.cb" = external constant target("dx.CBuffer", target("dx.Layout", %"__cblayout_$Globals", 20, 0, 4, 16))
-// CHECK-DAG: @a = external addrspace(2) global float
-// CHECK-DAG: @g = external addrspace(2) global float
-// CHECK-DAG: @h = external addrspace(2) global target("dx.Layout", %__cblayout_S, 4, 0), align 4
-
-struct EmptyStruct {
-};
-
-struct S {
-  RWBuffer<float> buf;
-  EmptyStruct es;
-  float ea[0];
-  float b;
-};
-
-float a;
-RWBuffer<float> b; 
-EmptyStruct c;
-float d[0];
-RWBuffer<float> e[2];
-groupshared float f;
-float g;
-S h;
-
-RWBuffer<float> Buf;
...
[truncated]

@hekota hekota merged commit 6e5f26b into main Feb 21, 2025
13 of 19 checks passed
@hekota hekota deleted the revert-125807-default-cbuffer branch February 21, 2025 02:39
@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 21, 2025

LLVM Buildbot has detected a new failure on builder lldb-arm-ubuntu running on linaro-lldb-arm-ubuntu while building clang at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/11795

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: tools/lldb-dap/exception/TestDAP_exception.py (1151 of 2910)
PASS: lldb-api :: tools/lldb-dap/exception/cpp/TestDAP_exception_cpp.py (1152 of 2910)
UNSUPPORTED: lldb-api :: tools/lldb-dap/exception/objc/TestDAP_exception_objc.py (1153 of 2910)
PASS: lldb-api :: tools/lldb-dap/databreakpoint/TestDAP_setDataBreakpoints.py (1154 of 2910)
UNSUPPORTED: lldb-api :: tools/lldb-dap/extendedStackTrace/TestDAP_extendedStackTrace.py (1155 of 2910)
PASS: lldb-api :: tools/lldb-dap/instruction-breakpoint/TestDAP_instruction_breakpoint.py (1156 of 2910)
PASS: lldb-api :: tools/lldb-dap/disconnect/TestDAP_disconnect.py (1157 of 2910)
PASS: lldb-api :: tools/lldb-dap/locations/TestDAP_locations.py (1158 of 2910)
PASS: lldb-api :: tools/lldb-dap/memory/TestDAP_memory.py (1159 of 2910)
PASS: lldb-api :: tools/lldb-dap/optimized/TestDAP_optimized.py (1160 of 2910)
FAIL: lldb-api :: tools/lldb-dap/output/TestDAP_output.py (1161 of 2910)
******************** TEST 'lldb-api :: tools/lldb-dap/output/TestDAP_output.py' FAILED ********************
Script:
--
/usr/bin/python3.10 /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch armv8l --build-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex --lldb-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb --compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang --dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --lldb-obj-root /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb --lldb-libs-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib /home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/output -p TestDAP_output.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 6e5f26bba87be02ea4c1220898031c441c2562fc)
  clang revision 6e5f26bba87be02ea4c1220898031c441c2562fc
  llvm revision 6e5f26bba87be02ea4c1220898031c441c2562fc
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 'debugserver', 'objc']
========= DEBUG ADAPTER PROTOCOL LOGS =========
1740106519.131071329 --> 
Content-Length: 344

{
  "arguments": {
    "adapterID": "lldb-native",
    "clientID": "vscode",
    "columnsStartAt1": true,
    "linesStartAt1": true,
    "locale": "en-us",
    "pathFormat": "path",
    "sourceInitFile": false,
    "supportsRunInTerminalRequest": true,
    "supportsStartDebuggingRequest": true,
    "supportsVariablePaging": true,
    "supportsVariableType": true
  },
  "command": "initialize",
  "seq": 1,
  "type": "request"
}
1740106519.133443594 <-- 
Content-Length: 1631


@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 21, 2025

LLVM Buildbot has detected a new failure on builder lldb-remote-linux-win running on as-builder-10 while building clang at step 17 "test-check-lldb-api".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/197/builds/2288

Here is the relevant piece of the build log for the reference
Step 17 (test-check-lldb-api) failure: Test just built components: check-lldb-api completed (failure)
...
UNSUPPORTED: lldb-api :: functionalities/tail_call_frames/unambiguous_sequence/TestUnambiguousTailCalls.py (600 of 1232)
PASS: lldb-api :: functionalities/testid/TestTestId.py (601 of 1232)
PASS: lldb-api :: functionalities/tail_call_frames/sbapi_support/TestTailCallFrameSBAPI.py (602 of 1232)
PASS: lldb-api :: functionalities/target_var/no_vars/TestTargetVarNoVars.py (603 of 1232)
PASS: lldb-api :: functionalities/tail_call_frames/thread_step_out_or_return/TestSteppingOutWithArtificialFrames.py (604 of 1232)
PASS: lldb-api :: functionalities/thread/backtrace_limit/TestBacktraceLimit.py (605 of 1232)
PASS: lldb-api :: functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py (606 of 1232)
PASS: lldb-api :: functionalities/target_var/TestTargetVar.py (607 of 1232)
PASS: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentCrashWithBreak.py (608 of 1232)
UNRESOLVED: lldb-api :: functionalities/thread/concurrent_events/TestConcurrentCrashWithWatchpoint.py (609 of 1232)
******************** TEST 'lldb-api :: functionalities/thread/concurrent_events/TestConcurrentCrashWithWatchpoint.py' FAILED ********************
Script:
--
C:/Python312/python.exe C:/buildbot/as-builder-10/lldb-x-aarch64/llvm-project/lldb\test\API\dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=C:/buildbot/as-builder-10/lldb-x-aarch64/build/./lib --env LLVM_INCLUDE_DIR=C:/buildbot/as-builder-10/lldb-x-aarch64/build/include --env LLVM_TOOLS_DIR=C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin --arch aarch64 --build-dir C:/buildbot/as-builder-10/lldb-x-aarch64/build/lldb-test-build.noindex --lldb-module-cache-dir C:/buildbot/as-builder-10/lldb-x-aarch64/build/lldb-test-build.noindex/module-cache-lldb\lldb-api --clang-module-cache-dir C:/buildbot/as-builder-10/lldb-x-aarch64/build/lldb-test-build.noindex/module-cache-clang\lldb-api --executable C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin/lldb.exe --compiler C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin/clang.exe --dsymutil C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin/dsymutil.exe --make C:/ninja/make.exe --llvm-tools-dir C:/buildbot/as-builder-10/lldb-x-aarch64/build/./bin --lldb-obj-root C:/buildbot/as-builder-10/lldb-x-aarch64/build/tools/lldb --lldb-libs-dir C:/buildbot/as-builder-10/lldb-x-aarch64/build/./lib --platform-url connect://jetson-agx-0086.lab.llvm.org:1234 --platform-working-dir /home/ubuntu/lldb-tests --sysroot c:/buildbot/fs/jetson-agx-ubuntu --env ARCH_CFLAGS=-mcpu=cortex-a78 --platform-name remote-linux --skip-category=lldb-server C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\test\API\functionalities\thread\concurrent_events -p TestConcurrentCrashWithWatchpoint.py
--
Exit Code: 2147483651

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 6e5f26bba87be02ea4c1220898031c441c2562fc)
  clang revision 6e5f26bba87be02ea4c1220898031c441c2562fc
  llvm revision 6e5f26bba87be02ea4c1220898031c441c2562fc

--
Command Output (stderr):
--
A�s�s�e�r�t�i�o�n� �f�a�i�l�e�d�:� �m�_�g�d�b�_�c�l�i�e�n�t�_�u�p�-�>�I�s�C�o�n�n�e�c�t�e�d�(�)�,� �f�i�l�e� �C�:�\�b�u�i�l�d�b�o�t�\�a�s�-�b�u�i�l�d�e�r�-�1�0�\�l�l�d�b�-�x�-�a�a�r�c�h�6�4�\�l�l�v�m�-�p�r�o�j�e�c�t�\�l�l�d�b�\�s�o�u�r�c�e�\�P�l�u�g�i�n�s�\�P�l�a�t�f�o�r�m�\�g�d�b�-�s�e�r�v�e�r�\�P�l�a�t�f�o�r�m�R�e�m�o�t�e�G�D�B�S�e�r�v�e�r�.�c�p�p�,� �l�i�n�e� �2�1�0�
�Windows fatal exception: code 0x80000003

Current thread 0x0000336c (most recent call first):
  File "C:\buildbot\as-builder-10\lldb-x-aarch64\build\Lib\site-packages\lldb\__init__.py", line 3522 in HandleCommand
  File "C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\packages\Python\lldbsuite\test\lldbtest.py", line 971 in runCmd
  File "C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\packages\Python\lldbsuite\test\concurrent_base.py", line 158 in do_thread_actions
  File "C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\test\API\functionalities\thread\concurrent_events\TestConcurrentCrashWithWatchpoint.py", line 14 in test
  File "C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\packages\Python\lldbsuite\test\decorators.py", line 148 in wrapper
  File "C:\Python312\Lib\unittest\case.py", line 589 in _callTestMethod
  File "C:\Python312\Lib\unittest\case.py", line 634 in run
  File "C:\Python312\Lib\unittest\case.py", line 690 in __call__
  File "C:\Python312\Lib\unittest\suite.py", line 122 in run
  File "C:\Python312\Lib\unittest\suite.py", line 84 in __call__
  File "C:\Python312\Lib\unittest\suite.py", line 122 in run
  File "C:\Python312\Lib\unittest\suite.py", line 84 in __call__
  File "C:\Python312\Lib\unittest\runner.py", line 240 in run
  File "C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\packages\Python\lldbsuite\test\dotest.py", line 1106 in run_suite
  File "C:\buildbot\as-builder-10\lldb-x-aarch64\llvm-project\lldb\test\API\dotest.py", line 8 in <module>
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Exception Code: 0x80000003
 #0 0x00007ff96ce00775 PyInit__lldb (C:\buildbot\as-builder-10\lldb-x-aarch64\build\Lib\site-packages\lldb\_lldb.cp312-win_amd64.pyd+0x9e0775)
 #1 0x00007ff997e0bb04 (C:\Windows\System32\ucrtbase.dll+0x7bb04)

@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 21, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-libc-amdgpu-runtime running on omp-vega20-1 while building clang at step 7 "Add check check-offload".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/13381

Here is the relevant piece of the build log for the reference
Step 7 (Add check check-offload) failure: 1200 seconds without output running [b'ninja', b'-j 32', b'check-offload'], attempting to kill
...
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49779.cpp (1001 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/test_libc.cpp (1002 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug47654.cpp (1003 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/wtime.c (1004 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug50022.cpp (1005 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: offloading/bug49021.cpp (1006 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: offloading/std_complex_arithmetic.cpp (1007 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/complex_reduction.cpp (1008 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49021.cpp (1009 of 1011)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/std_complex_arithmetic.cpp (1010 of 1011)
command timed out: 1200 seconds without output running [b'ninja', b'-j 32', b'check-offload'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1235.716039

@damyanp damyanp moved this to Closed in HLSL Support Apr 25, 2025
@damyanp damyanp removed this from HLSL Support Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category HLSL HLSL Language Support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants