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();


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();
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to