https://github.com/spall updated 
https://github.com/llvm/llvm-project/pull/243555

>From 9bfc16d728a376dd7d1a25eacddb313a19dc015d Mon Sep 17 00:00:00 2001
From: Sarah Spall <[email protected]>
Date: Tue, 17 Nov 2026 10:13:13 -0800
Subject: [PATCH 1/2] disallow multiple inheritance in hlsl

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td   |  1 +
 clang/lib/Sema/SemaDeclCXX.cpp                     |  6 ++++++
 .../SemaHLSL/Language/NoMultipleInheritance.hlsl   | 14 ++++++++++++++
 3 files changed, 21 insertions(+)
 create mode 100644 clang/test/SemaHLSL/Language/NoMultipleInheritance.hlsl

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dff45a081f2e8c..8d12265192642d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -13850,6 +13850,7 @@ def 
err_hlsl_builtin_resource_coordinate_dimension_mismatch : Error<
   "builtin %0 resource coordinate dimension mismatch: expected %1, found %2">;
 
 // HLSL Diagnostics
+def err_hlsl_mult_inheritance : Error<"HLSL does not support multiple 
inheritance">;
 def err_hlsl_cstor_dstor : Error<"HLSL does not support constructors or 
destructors">;
 def err_hlsl_langstd_unimplemented : Error<"support for HLSL language version 
%0 is incomplete">;
 def err_hlsl_attr_unsupported_in_stage : Error<"attribute %0 is unsupported in 
'%1' shaders, requires %select{|one of the following: }2%3">;
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 62cbcc03ea42fe..cb9e80eac8669e 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -3003,6 +3003,12 @@ bool Sema::AttachBaseSpecifiers(CXXRecordDecl *Class,
   // Copy non-redundant base specifiers into permanent storage.
   unsigned NumGoodBases = 0;
   bool Invalid = false;
+
+  if (getLangOpts().HLSL && Bases.size() > 1) {
+    Diag(Bases[1]->getBeginLoc(), diag::err_hlsl_mult_inheritance);
+    Invalid = true;
+  }
+
   for (unsigned idx = 0; idx < Bases.size(); ++idx) {
     QualType NewBaseType
       = Context.getCanonicalType(Bases[idx]->getType());
diff --git a/clang/test/SemaHLSL/Language/NoMultipleInheritance.hlsl 
b/clang/test/SemaHLSL/Language/NoMultipleInheritance.hlsl
new file mode 100644
index 00000000000000..ec7d09ba232c23
--- /dev/null
+++ b/clang/test/SemaHLSL/Language/NoMultipleInheritance.hlsl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -verify %s
+
+struct FirstBase {
+  int X;
+};
+
+struct SecondBase {
+  int Y;
+};
+
+struct SingleInheritance : FirstBase {};
+struct ChainedInheritance : SingleInheritance {};
+
+struct MultipleInheritance : FirstBase, SecondBase {}; // expected-error{{HLSL 
does not support multiple inheritance}}

>From 20aeff3e6de4083c25a9ba4a2510900a55a0330c Mon Sep 17 00:00:00 2001
From: Sarah Spall <[email protected]>
Date: Tue, 17 Nov 2026 14:26:53 -0800
Subject: [PATCH 2/2] address pr feedback

---
 clang/lib/Sema/SemaDeclCXX.cpp                          | 2 ++
 clang/test/SemaHLSL/Language/NoMultipleInheritance.hlsl | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index cb9e80eac8669e..efe8d3fd7f3d43 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -3006,6 +3006,8 @@ bool Sema::AttachBaseSpecifiers(CXXRecordDecl *Class,
 
   if (getLangOpts().HLSL && Bases.size() > 1) {
     Diag(Bases[1]->getBeginLoc(), diag::err_hlsl_mult_inheritance);
+    // To prevent producing error messages about the additional base classes
+    Bases = Bases.take_front();
     Invalid = true;
   }
 
diff --git a/clang/test/SemaHLSL/Language/NoMultipleInheritance.hlsl 
b/clang/test/SemaHLSL/Language/NoMultipleInheritance.hlsl
index ec7d09ba232c23..678f7478ac60a2 100644
--- a/clang/test/SemaHLSL/Language/NoMultipleInheritance.hlsl
+++ b/clang/test/SemaHLSL/Language/NoMultipleInheritance.hlsl
@@ -12,3 +12,5 @@ struct SingleInheritance : FirstBase {};
 struct ChainedInheritance : SingleInheritance {};
 
 struct MultipleInheritance : FirstBase, SecondBase {}; // expected-error{{HLSL 
does not support multiple inheritance}}
+
+struct MultiError : FirstBase, FirstBase {}; // expected-error{{HLSL does not 
support multiple inheritance}}

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

Reply via email to