[PATCH] D132421: [NFC] [HLSL] Add HLSLExternalSemaSource as ExternalSemaSource instead of ASTContext::ExternalSource.

Xiang Li via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 23 10:25:05 PDT 2022


python3kgae updated this revision to Diff 454888.
python3kgae added a comment.

When there's no external source set, add HLSLSema as ExternalSource so ASTWriter can access HLSLSema.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132421/new/

https://reviews.llvm.org/D132421

Files:
  clang/lib/Frontend/FrontendAction.cpp
  clang/test/SemaHLSL/pch.hlsl


Index: clang/test/SemaHLSL/pch.hlsl
===================================================================
--- /dev/null
+++ clang/test/SemaHLSL/pch.hlsl
@@ -0,0 +1,21 @@
+// Test PCH and HLSLExternalSemaSource can work together.
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl \
+// RUN:  -finclude-default-header -emit-pch -o %t %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl \
+// RUN:  -finclude-default-header -include-pch %t -ast-dump-all  /dev/null \
+// RUN: | FileCheck  %s
+
+// CHECK:FunctionDecl 0x{{[0-9a-f]+}} <{{.*}}:19:1, line:21:1> line:19:8 imported foo 'float2 (float2, float2)'
+// CHECK-NEXT:ParmVarDecl 0x[[A:[0-9a-f]+]] <col:12, col:19> col:19 imported used a 'float2':'float __attribute__((ext_vector_type(2)))'
+// CHECK-NEXT:ParmVarDecl 0x[[B:[0-9a-f]+]] <col:22, col:29> col:29 imported used b 'float2':'float __attribute__((ext_vector_type(2)))'
+// CHECK-NEXT:CompoundStmt 0x{{[0-9a-f]+}} <col:32, line:21:1>
+// CHECK-NEXT:ReturnStmt 0x{{[0-9a-f]+}} <line:20:3, col:12>
+// CHECK-NEXT:BinaryOperator 0x{{[0-9a-f]+}} <col:10, col:12> 'float2':'float __attribute__((ext_vector_type(2)))' '+'
+// CHECK-NEXT:ImplicitCastExpr 0x{{[0-9a-f]+}} <col:10> 'float2':'float __attribute__((ext_vector_type(2)))' <LValueToRValue>
+// CHECK-NEXT:DeclRefExpr 0x{{[0-9a-f]+}} <col:10> 'float2':'float __attribute__((ext_vector_type(2)))' lvalue ParmVar 0x[[A]] 'a' 'float2':'float __attribute__((ext_vector_type(2)))'
+// CHECK-NEXT:ImplicitCastExpr 0x{{[0-9a-f]+}} <col:12> 'float2':'float __attribute__((ext_vector_type(2)))' <LValueToRValue>
+// CHECK-NEXT:DeclRefExpr 0x{{[0-9a-f]+}} <col:12> 'float2':'float __attribute__((ext_vector_type(2)))' lvalue ParmVar 0x[[B]] 'b' 'float2':'float __attribute__((ext_vector_type(2)))'
+
+float2 foo(float2 a, float2 b) {
+  return a+b;
+}
\ No newline at end of file
Index: clang/lib/Frontend/FrontendAction.cpp
===================================================================
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -1018,9 +1018,14 @@
 
   // Setup HLSL External Sema Source
   if (CI.getLangOpts().HLSL && CI.hasASTContext()) {
-    IntrusiveRefCntPtr<ExternalASTSource> HLSLSema(
+    IntrusiveRefCntPtr<ExternalSemaSource> HLSLSema(
         new HLSLExternalSemaSource());
-    CI.getASTContext().setExternalSource(HLSLSema);
+    // When there's no external source set, add HLSLSema as ExternalSource so
+    // ASTWriter can access HLSLSema.
+    if (CI.getASTContext().getExternalSource())
+      CI.setExternalSemaSource(HLSLSema);
+    else
+      CI.getASTContext().setExternalSource(HLSLSema);
   }
 
   FailureCleanup.release();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132421.454888.patch
Type: text/x-patch
Size: 2690 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220823/ff4360b0/attachment-0001.bin>


More information about the cfe-commits mailing list