[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-x86_64-debian-fast` running on `gribozavr4` while building `clang` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/56/builds/12264 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'Clang :: AST/HLSL/AppendStructuredBuffer-AST.hlsl' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl | /b/1/clang-x86_64-debian-fast/llvm.obj/bin/FileCheck -check-prefix=EMPTY /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl + /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -cc1 -internal-isystem /b/1/clang-x86_64-debian-fast/llvm.obj/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl + /b/1/clang-x86_64-debian-fast/llvm.obj/bin/FileCheck -check-prefix=EMPTY /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl:15:16: error: EMPTY-NEXT: expected string not found in input // EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> class depth 0 index 0 element_type ^ :39:96: note: scanning from here | |-ClassTemplateDecl 0xd061cd0 <> implicit AppendStructuredBuffer ^ :40:7: note: possible intended match here | | |-TemplateTypeParmDecl 0xd061c30 <> typename depth 0 index 0 element_type ^ Input file: Check file: /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl -dump-input=help explains the following input dump. Input was: << . . . 34: | | `-FinalAttr 0xd05f508 <> Implicit final 35: | |-ClassTemplateDecl 0xd05f9f0 <> implicit RWStructuredBuffer 36: | | |-TemplateTypeParmDecl 0xd05f950 <> typename depth 0 index 0 element_type 37: | | `-CXXRecordDecl 0xd05f850 <> implicit class RWStructuredBuffer 38: | | `-FinalAttr 0xd05f8f8 <> Implicit final 39: | |-ClassTemplateDecl 0xd061cd0 <> implicit AppendStructuredBuffer next:15'0 X error: no match found 40: | | |-TemplateTypeParmDecl 0xd061c30 <> typename depth 0 index 0 element_type next:15'0 ~~~ next:15'1 ? possible intended match 41: | | `-CXXRecordDecl 0xd061b30 <> implicit class AppendStructuredBuffer next:15'0 ~~ 42: | | `-FinalAttr 0xd061bd8 <> Implicit final next:15'0 ~~ 43: | |-ClassTemplateDecl 0xd0620c0 <> implicit ConsumeStructuredBuffer next:15'0 ~ 44: | | |-TemplateTypeParmDecl 0xd062020 <> typename depth 0 index 0 element_type next:15'0 ~~~ 45: | | `-CXXRecordDecl 0xd061f20 <> implicit class ConsumeStructuredBuffer next:15'0 ~~~ . . ... ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-x86_64-debian-dylib` running on `gribozavr4` while building `clang` at step 6 "test-build-unified-tree-check-clang". Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/12759 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-clang) failure: test (failure) TEST 'Clang :: AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl | /b/1/llvm-x86_64-debian-dylib/build/bin/FileCheck -check-prefix=EMPTY /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl + /b/1/llvm-x86_64-debian-dylib/build/bin/clang -cc1 -internal-isystem /b/1/llvm-x86_64-debian-dylib/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl + /b/1/llvm-x86_64-debian-dylib/build/bin/FileCheck -check-prefix=EMPTY /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl:15:16: error: EMPTY-NEXT: expected string not found in input // EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> class depth 0 index 0 element_type ^ :47:107: note: scanning from here | `-ClassTemplateDecl 0x11f98c0 <> implicit RasterizerOrderedStructuredBuffer ^ :48:5: note: possible intended match here | |-TemplateTypeParmDecl 0x11f9820 <> typename depth 0 index 0 element_type ^ Input file: Check file: /b/1/llvm-x86_64-debian-dylib/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl -dump-input=help explains the following input dump. Input was: << . . . 42: | | `-FinalAttr 0x11f8fe8 <> Implicit final 43: | |-ClassTemplateDecl 0x11f94d0 <> implicit ConsumeStructuredBuffer 44: | | |-TemplateTypeParmDecl 0x11f9430 <> typename depth 0 index 0 element_type 45: | | `-CXXRecordDecl 0x11f9330 <> implicit class ConsumeStructuredBuffer 46: | | `-FinalAttr 0x11f93d8 <> Implicit final 47: | `-ClassTemplateDecl 0x11f98c0 <> implicit RasterizerOrderedStructuredBuffer next:15'0 X error: no match found 48: | |-TemplateTypeParmDecl 0x11f9820 <> typename depth 0 index 0 element_type next:15'0 ~ next:15'1 ? possible intended match 49: | `-CXXRecordDecl 0x11f9720 <> implicit class RasterizerOrderedStructuredBuffer next:15'0 ~~~ 50: | `-FinalAttr 0x11f97c8 <> Implicit final next:15'0 51: |-ConceptDecl 0x11cdda0 <> __is_typed_resource_element_compatible next:15'0 ~~~ 52: | |-TemplateTypeParmDecl 0x11cdc88 <> referenced typename depth 0 index 0 element_type next:15'0 53: | `-BinaryOperator 0x11cdd80 <> 'bool' lvalue '<=' next:15'0 ~ . . ... ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `premerge-monolithic-linux` running on `premerge-linux-1` while building `clang` at step 7 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/14719 Here is the relevant piece of the build log for the reference ``` Step 7 (test-build-unified-tree-check-all) failure: test (failure) TEST 'Clang :: AST/HLSL/ConsumeStructuredBuffer-AST.hlsl' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /build/buildbot/premerge-monolithic-linux/build/bin/clang -cc1 -internal-isystem /build/buildbot/premerge-monolithic-linux/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl | /build/buildbot/premerge-monolithic-linux/build/bin/FileCheck -check-prefix=EMPTY /build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl + /build/buildbot/premerge-monolithic-linux/build/bin/clang -cc1 -internal-isystem /build/buildbot/premerge-monolithic-linux/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl + /build/buildbot/premerge-monolithic-linux/build/bin/FileCheck -check-prefix=EMPTY /build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl /build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl:15:16: error: EMPTY-NEXT: expected string not found in input // EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> class depth 0 index 0 element_type ^ :43:102: note: scanning from here | |-ClassTemplateDecl 0x56455fbd9540 <> implicit ConsumeStructuredBuffer ^ :44:7: note: possible intended match here | | |-TemplateTypeParmDecl 0x56455fbd94a0 <> typename depth 0 index 0 element_type ^ Input file: Check file: /build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl -dump-input=help explains the following input dump. Input was: << . . . 38: | | `-FinalAttr 0x56455fbd6d78 <> Implicit final 39: | |-ClassTemplateDecl 0x56455fbd9150 <> implicit AppendStructuredBuffer 40: | | |-TemplateTypeParmDecl 0x56455fbd90b0 <> typename depth 0 index 0 element_type 41: | | `-CXXRecordDecl 0x56455fbd8fb0 <> implicit class AppendStructuredBuffer 42: | | `-FinalAttr 0x56455fbd9058 <> Implicit final 43: | |-ClassTemplateDecl 0x56455fbd9540 <> implicit ConsumeStructuredBuffer next:15'0 X error: no match found 44: | | |-TemplateTypeParmDecl 0x56455fbd94a0 <> typename depth 0 index 0 element_type next:15'0 next:15'1 ? possible intended match 45: | | `-CXXRecordDecl 0x56455fbd93a0 <> implicit class ConsumeStructuredBuffer next:15'0 46: | | `-FinalAttr 0x56455fbd9448 <> Implicit final next:15'0 ~~~ 47: | `-ClassTemplateDecl 0x56455fbd9930 <> implicit RasterizerOrderedStructuredBuffer next:15'0 48: | |-TemplateTypeParmDecl 0x56455fbd9890 <> typename depth 0 index 0 element_type next:15'0 ~~ 49: | `-CXXRecordDecl 0x56455fbd9790 <> implicit class RasterizerOrderedStructuredBuffer next:15'0 . . ... ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-clang-aarch64-darwin` running on `doug-worker-4` while building `clang` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/9516 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'Clang :: AST/HLSL/AppendStructuredBuffer-AST.hlsl' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=EMPTY /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl + /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefix=EMPTY /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl + /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 -internal-isystem /Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl [1m/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl:15:16: [0m[0;1;31merror: [0m[1mEMPTY-NEXT: expected string not found in input [0m// EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> class depth 0 index 0 element_type [0;1;32m ^ [0m[1m:39:98: [0m[0;1;30mnote: [0m[1mscanning from here [0m| |-ClassTemplateDecl 0x133853fa0 <> implicit AppendStructuredBuffer [0;1;32m ^ [0m[1m:40:7: [0m[0;1;30mnote: [0m[1mpossible intended match here [0m| | |-TemplateTypeParmDecl 0x133853f00 <> typename depth 0 index 0 element_type [0;1;32m ^ [0m Input file: Check file: /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl -dump-input=help explains the following input dump. Input was: << [1m[0m[0;1;30m 1: [0m[1m[0;1;46mTranslationUnitDecl 0x13382c608 <> [0m [0;1;30m 2: [0m[1m[0;1;46m|-NamespaceDecl 0x13382cf28 <> implicit hlsl [0m [0;1;30m 3: [0m[1m[0;1;46m| |-TypeAliasTemplateDecl 0x13382d280 <> implicit vector [0m [0;1;30m 4: [0m[1m[0;1;46m| | |-TemplateTypeParmDecl 0x13382cfb0 <> class depth 0 index 0 element [0m [0;1;30m 5: [0m[1m[0;1;46m| | | `-TemplateArgument type 'float' [0m [0;1;30m 6: [0m[1m[0;1;46m| | | `-BuiltinType 0x13382c810 'float' [0m [0;1;30m 7: [0m[1m[0;1;46m| | |-NonTypeTemplateParmDecl 0x13382d0b0 <> 'int' depth 0 index 1 element_count [0m [0;1;30m 8: [0m[1m[0;1;46m| | | `-TemplateArgument expr '4' [0m [0;1;30m 9: [0m[1m[0;1;46m| | | `-IntegerLiteral 0x13382d108 <> 'int' 4 [0m [0;1;30m 10: [0m[1m[0;1;46m| | `-TypeAliasDecl 0x13382d220 <> implicit vector 'vector' [0m [0;1;30m 11: [0m[1m[0;1;46m| | `-DependentSizedExtVectorType 0x13382d1d0 'vector' dependent [0m [0;1;30m 12: [0m[1m[0;1;46m| | |-TemplateTypeParmType 0x13382d030 'element' dependent depth 0 index 0 [0m [0;1;30m 13: [0m[1m[0;1;46m| | | `-TemplateTypeParm 0x13382cfb0 'element' [0m [0;1;30m 14: [0m[1m[0;1;46m| | `-DeclRefExpr 0x13382d170 <> 'int' lvalue NonTypeTemplateParm 0x13382d0b0 'element_count' 'int' [0m [0;1;30m 15: [0m[1m[0;1;46m| |-ClassTemplateDecl 0x1338521a8 <> implicit RWBuffer [0m [0;1;30m 16: [0m[1m[0;1;46m| | |-TemplateTypeParmDecl 0x13382d538 <> typename depth 0 index 0 element_type [0m [0;1;30m 17: [0m[1m[0;1;46m| | |-ConceptSpecializationExpr 0x133852148 <> 'bool' Concept 0x13382d3f0 '__is_typed_resource_element_compatible' [0m [0;1;30m 18: [0m[1m[0;1;46m| | | |-ImplicitConceptSpecializationDecl 0x133852080 <> [0m [0;1;30m 19: [0m[1m[0;1;46m| | | | `-TemplateArgument type 'type-parameter-0-0' [0m [0;1;30m 20: [0m[1m[0;1;46m| | | | `-TemplateTypeParmType 0x133852050 'type-parameter-0-0' dependent depth 0 index 0 [0m [0;1;30m 21: [0m[1m[0;1;46m| | | | `-TemplateTypeParm 0x133852000 '' [0m [0;1;30m 22: [0m[1m[0;1;46m| | | `-TemplateArgument type 'element_t
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `fuchsia-x86_64-linux` running on `fuchsia-debian-64-us-central1-a-1` while building `clang` at step 4 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/11/builds/8210 Here is the relevant piece of the build log for the reference ``` Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/fuchsia-linux.py ...' (failure) ... [1345/1347] Linking CXX executable tools/clang/unittests/Tooling/ToolingTests [1346/1347] Running the Clang regression tests llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using clang: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-zmj85sc8/bin/clang llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/subst.py:126: note: Did not find clang-repl in /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-zmj85sc8/bin:/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-zmj85sc8/bin llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld.lld: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-zmj85sc8/bin/ld.lld llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using lld-link: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-zmj85sc8/bin/lld-link llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld64.lld: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-zmj85sc8/bin/ld64.lld llvm-lit: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using wasm-ld: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-zmj85sc8/bin/wasm-ld -- Testing: 21511 tests, 60 workers -- Testing: FAIL: Clang :: AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl (152 of 21511) TEST 'Clang :: AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-zmj85sc8/bin/clang -cc1 -internal-isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-zmj85sc8/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl | /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-zmj85sc8/bin/FileCheck -check-prefix=EMPTY /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl + /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-zmj85sc8/bin/FileCheck -check-prefix=EMPTY /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl + /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-zmj85sc8/bin/clang -cc1 -internal-isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-zmj85sc8/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl:15:16: error: EMPTY-NEXT: expected string not found in input // EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> class depth 0 index 0 element_type ^ :47:112: note: scanning from here | `-ClassTemplateDecl 0x55d7f80dc0a0 <> implicit RasterizerOrderedStructuredBuffer ^ :48:5: note: possible intended match here | |-TemplateTypeParmDecl 0x55d7f80dc000 <> typename depth 0 index 0 element_type ^ Input file: Check file: /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl -dump-input=help explains the following input dump. Input was: << . . . 42: | | `-FinalAttr 0x55d7f80db7c8 <> Implicit final 43: | |-ClassTemplateDecl 0x55d7f80dbcb0 <> implicit ConsumeStructuredBuffer 44: | | |-TemplateTypeParmDecl 0x55d7f80dbc10 <> typename depth 0 index 0 element_type 45: | | `-CXXRecordDecl 0x55d7f80dbb10 <> implicit class ConsumeStructuredBuffer 46: | | `-FinalAttr 0x55d7f80dbbb8 <> Implicit final 47: | `-ClassTemplateDecl 0x55d7f80dc0a0 <> implicit RasterizerOrderedStructuredBuffer next:15'0 X error: no match found 48: | |-TemplateTypeParmDecl 0x55d
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `openmp-offload-sles-build-only` running on `rocm-worker-hw-04-sles` while building `clang` at step 6 "Add check check-clang". Full details are available at: https://lab.llvm.org/buildbot/#/builders/140/builds/10923 Here is the relevant piece of the build log for the reference ``` Step 6 (Add check check-clang) failure: test (failure) TEST 'Clang :: AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang -cc1 -internal-isystem /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl | /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/FileCheck -check-prefix=EMPTY /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl + /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/FileCheck -check-prefix=EMPTY /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl + /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang -cc1 -internal-isystem /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl:15:16: error: EMPTY-NEXT: expected string not found in input // EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> class depth 0 index 0 element_type ^ :47:107: note: scanning from here | `-ClassTemplateDecl 0xc81a9b0 <> implicit RasterizerOrderedStructuredBuffer ^ :48:5: note: possible intended match here | |-TemplateTypeParmDecl 0xc81a910 <> typename depth 0 index 0 element_type ^ Input file: Check file: /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl -dump-input=help explains the following input dump. Input was: << . . . 42: | | `-FinalAttr 0xc81a0d8 <> Implicit final 43: | |-ClassTemplateDecl 0xc81a5c0 <> implicit ConsumeStructuredBuffer 44: | | |-TemplateTypeParmDecl 0xc81a520 <> typename depth 0 index 0 element_type 45: | | `-CXXRecordDecl 0xc81a420 <> implicit class ConsumeStructuredBuffer 46: | | `-FinalAttr 0xc81a4c8 <> Implicit final 47: | `-ClassTemplateDecl 0xc81a9b0 <> implicit RasterizerOrderedStructuredBuffer next:15'0 X error: no match found 48: | |-TemplateTypeParmDecl 0xc81a910 <> typename depth 0 index 0 element_type next:15'0 ~ next:15'1 ? possible intended match 49: | `-CXXRecordDecl 0xc81a810 <> implicit class RasterizerOrderedStructuredBuffer next:15'0 ~~~ 50: | `-FinalAttr 0xc81a8b8 <> Implicit final next:15'0 51: |-ConceptDecl 0xc7ef030 <> __is_typed_resource_element_compatible next:15'0 ~~~ 52: | |-TemplateTypeParmDecl 0xc7eef18 <> referenced typename depth 0 index 0 element_type next:15'0 53: | `-BinaryOperator 0xc7ef010 <> 'bool' lvalue '<=' next:15'0 ~ . . ... ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-ve-ninja` running on `hpce-ve-main` while building `clang` at step 4 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/12/builds/9628 Here is the relevant piece of the build log for the reference ``` Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/ve-linux.py ...' (failure) ... [295/301] Linking CXX executable tools/clang/unittests/Driver/ClangDriverTests [296/301] Linking CXX executable tools/clang/unittests/CodeGen/ClangCodeGenTests [297/301] Linking CXX executable tools/clang/unittests/Tooling/ToolingTests [298/301] Linking CXX executable tools/clang/unittests/Frontend/FrontendTests [299/301] Linking CXX executable tools/clang/unittests/Interpreter/ExceptionTests/ClangReplInterpreterExceptionTests [300/301] Linking CXX executable tools/clang/unittests/Interpreter/ClangReplInterpreterTests [300/301] Running the Clang regression tests -- Testing: 21335 tests, 48 workers -- llvm-lit: /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using clang: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang Testing: FAIL: Clang :: AST/HLSL/ConsumeStructuredBuffer-AST.hlsl (192 of 21335) TEST 'Clang :: AST/HLSL/ConsumeStructuredBuffer-AST.hlsl' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl | /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck -check-prefix=EMPTY /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl + /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 -internal-isystem /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl + /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/FileCheck -check-prefix=EMPTY /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl:15:16: error: EMPTY-NEXT: expected string not found in input // EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> class depth 0 index 0 element_type ^ :43:97: note: scanning from here | |-ClassTemplateDecl 0x8330f40 <> implicit ConsumeStructuredBuffer ^ :44:7: note: possible intended match here | | |-TemplateTypeParmDecl 0x8330ea0 <> typename depth 0 index 0 element_type ^ Input file: Check file: /scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl -dump-input=help explains the following input dump. Input was: << . . . 38: | | `-FinalAttr 0x832e778 <> Implicit final 39: | |-ClassTemplateDecl 0x8330b50 <> implicit AppendStructuredBuffer 40: | | |-TemplateTypeParmDecl 0x8330ab0 <> typename depth 0 index 0 element_type 41: | | `-CXXRecordDecl 0x83309b0 <> implicit class AppendStructuredBuffer 42: | | `-FinalAttr 0x8330a58 <> Implicit final 43: | |-ClassTemplateDecl 0x8330f40 <> implicit ConsumeStructuredBuffer next:15'0 X error: no match found 44: | | |-TemplateTypeParmDecl 0x8330ea0 <> typename depth 0 index 0 element_type next:15'0 ~~~ next:15'1 ? possible intended match Step 8 (check-llvm) failure: check-llvm (failure) ... [295/301] Linking CXX executable tools/clang/unittests/Driver/ClangDriverTests [296/301] Linking CXX executable tools/clang/unittests/CodeGen/ClangCodeGenTests [297/301] Linking CXX executable tools/clang/unittests/Tooling/ToolingTests [298/301] Linking CXX executable tools/clang/unittests/Frontend/FrontendTests [299/301] Linking CXX executable tools/clang/unittests/Interpreter/ExceptionTests/ClangReplInterpreterExceptionTests [300/301] Linking CXX executable tools/clang/unittests/Interpreter/Cl
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-cmake-x86_64-avx512-linux` running on `avx512-intel64` while building `clang` at step 7 "ninja check 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/133/builds/6845 Here is the relevant piece of the build log for the reference ``` Step 7 (ninja check 1) failure: stage 1 checked (failure) TEST 'Clang :: AST/HLSL/ConsumeStructuredBuffer-AST.hlsl' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/clang -cc1 -internal-isystem /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl | /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/FileCheck -check-prefix=EMPTY /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl + /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/clang -cc1 -internal-isystem /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl + /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/FileCheck -check-prefix=EMPTY /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl:15:16: error: EMPTY-NEXT: expected string not found in input // EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> class depth 0 index 0 element_type ^ :43:97: note: scanning from here | |-ClassTemplateDecl 0xa161520 <> implicit ConsumeStructuredBuffer ^ :44:7: note: possible intended match here | | |-TemplateTypeParmDecl 0xa161480 <> typename depth 0 index 0 element_type ^ Input file: Check file: /localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl -dump-input=help explains the following input dump. Input was: << . . . 38: | | `-FinalAttr 0xa15ed58 <> Implicit final 39: | |-ClassTemplateDecl 0xa161130 <> implicit AppendStructuredBuffer 40: | | |-TemplateTypeParmDecl 0xa161090 <> typename depth 0 index 0 element_type 41: | | `-CXXRecordDecl 0xa160f90 <> implicit class AppendStructuredBuffer 42: | | `-FinalAttr 0xa161038 <> Implicit final 43: | |-ClassTemplateDecl 0xa161520 <> implicit ConsumeStructuredBuffer next:15'0 X error: no match found 44: | | |-TemplateTypeParmDecl 0xa161480 <> typename depth 0 index 0 element_type next:15'0 ~~~ next:15'1 ? possible intended match 45: | | `-CXXRecordDecl 0xa161380 <> implicit class ConsumeStructuredBuffer next:15'0 ~~~ 46: | | `-FinalAttr 0xa161428 <> Implicit final next:15'0 ~~ 47: | `-ClassTemplateDecl 0xa161910 <> implicit RasterizerOrderedStructuredBuffer next:15'0 ~~~ 48: | |-TemplateTypeParmDecl 0xa161870 <> typename depth 0 index 0 element_type next:15'0 ~ 49: | `-CXXRecordDecl 0xa161770 <> implicit class RasterizerOrderedStructuredBuffer next:15'0 ~~~ . . ... ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-sie-ubuntu-fast` running on `sie-linux-worker` while building `clang` at step 6 "test-build-unified-tree-check-all". Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/11651 Here is the relevant piece of the build log for the reference ``` Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'Clang :: AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck -check-prefix=EMPTY /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl + /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang -cc1 -internal-isystem /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/20/include -nostdsysteminc -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl + /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck -check-prefix=EMPTY /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl [1m/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl:15:16: [0m[0;1;31merror: [0m[1mEMPTY-NEXT: expected string not found in input [0m// EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> class depth 0 index 0 element_type [0;1;32m ^ [0m[1m:47:112: [0m[0;1;30mnote: [0m[1mscanning from here [0m| `-ClassTemplateDecl 0x59950c8a2340 <> implicit RasterizerOrderedStructuredBuffer [0;1;32m ^ [0m[1m:48:5: [0m[0;1;30mnote: [0m[1mpossible intended match here [0m| |-TemplateTypeParmDecl 0x59950c8a22a0 <> typename depth 0 index 0 element_type [0;1;32m^ [0m Input file: Check file: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl -dump-input=help explains the following input dump. Input was: << [1m[0m[0;1;30m 1: [0m[1m[0;1;46mTranslationUnitDecl 0x59950c875bd8 <> [0m [0;1;30m 2: [0m[1m[0;1;46m|-NamespaceDecl 0x59950c8764f8 <> implicit hlsl [0m [0;1;30m 3: [0m[1m[0;1;46m| |-TypeAliasTemplateDecl 0x59950c876850 <> implicit vector [0m [0;1;30m 4: [0m[1m[0;1;46m| | |-TemplateTypeParmDecl 0x59950c876580 <> class depth 0 index 0 element [0m [0;1;30m 5: [0m[1m[0;1;46m| | | `-TemplateArgument type 'float' [0m [0;1;30m 6: [0m[1m[0;1;46m| | | `-BuiltinType 0x59950c875de0 'float' [0m [0;1;30m 7: [0m[1m[0;1;46m| | |-NonTypeTemplateParmDecl 0x59950c876680 <> 'int' depth 0 index 1 element_count [0m [0;1;30m 8: [0m[1m[0;1;46m| | | `-TemplateArgument expr '4' [0m [0;1;30m 9: [0m[1m[0;1;46m| | | `-IntegerLiteral 0x59950c8766d8 <> 'int' 4 [0m [0;1;30m 10: [0m[1m[0;1;46m| | `-TypeAliasDecl 0x59950c8767f0 <> implicit vector 'vector' [0m [0;1;30m 11: [0m[1m[0;1;46m| | `-DependentSizedExtVectorType 0x59950c8767a0 'vector' dependent [0m [0;1;30m 12: [0m[1m[0;1;46m| | |-TemplateTypeParmType 0x59950c876600 'element' dependent depth 0 index 0 [0m [0;1;30m 13: [0m[1m[0;1;46m| | | `-TemplateTypeParm 0x59950c876580 'element' [0m [0;1;30m 14: [0m[1m[0;1;46m| | `-DeclRefExpr 0x59950c876740 <> 'int' lvalue NonTypeTemplateParm 0x59950c876680 'element_count' 'int' [0m [0;1;30m 15: [0m[1m[0;1;46m| |-ClassTemplateDecl 0x59950c89ecb8 <> implicit RWBuffer [0m [0;1;30m 16: [0m[1m[0;1;46m| | |-TemplateTypeParmDecl 0x59950c876b08 <> typename depth 0 index 0 element_type [0m [0;1;30m 17: [0m[1m[0;1;46m| | |-ConceptSpecializationExpr 0x59950c89ec58 <> 'bool' Concept 0x59950c8769c0 '__is_typed_resource_element_compatible' [0m [0;1;30m 18: [0m[1m[0;1;46m| | | |-ImplicitConceptSpecializationDecl 0x59950c89eb90 <> [0m [0;1;30m
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 closed https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/llvm-beanz approved this pull request. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +583,103 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + QualType UnsignedLongType = Context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + QualType TType = Context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + TypeSourceInfo *TTypeSourceInfo = + Context.getTrivialTypeSourceInfo(TType, NameLoc); + + UnaryExprOrTypeTraitExpr *sizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr( + UETT_SizeOf, TTypeSourceInfo, UnsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + QualType SizeType = Context.getSizeType(); + llvm::APInt SizeValue = llvm::APInt(Context.getTypeSize(SizeType), 16); + IntegerLiteral *SizeLiteral = + new (Context) IntegerLiteral(Context, SizeValue, SizeType, NameLoc); + + QualType BoolTy = Context.BoolTy; + + BinaryOperator *binaryOperator = + BinaryOperator::Create(Context, sizeOfExpr, // Left-hand side expression + SizeLiteral, // Right-hand side expression + BO_LE, // Binary operator kind (<=) + BoolTy, // Result type (bool) + VK_LValue, // Value kind + OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + ASTContext &Context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *SizeOfLEQ16 = constructSizeOfLEQ16Expr(Context, NameLoc, T); + // TODO: add the 'builtin_hlsl_is_typed_resource_element_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T'. + // Defined in issue https://github.com/llvm/llvm-project/issues/113223 + return SizeOfLEQ16; +} + +ConceptDecl *constructTypedBufferConceptDecl(Sema &S, NamespaceDecl *NSD) { + ASTContext &Context = S.getASTContext(); + DeclContext *DC = NSD->getDeclContext(); + SourceLocation DeclLoc = SourceLocation(); + + IdentifierInfo &ElementTypeII = Context.Idents.get("element_type"); + TemplateTypeParmDecl *T = TemplateTypeParmDecl::Create( + Context, Context.getTranslationUnitDecl(), DeclLoc, DeclLoc, llvm-beanz wrote: Pretty sure this is also wrong here: ```suggestion Context, NSD->getDeclContext(), DeclLoc, DeclLoc, ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +583,103 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + QualType UnsignedLongType = Context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + QualType TType = Context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + TypeSourceInfo *TTypeSourceInfo = + Context.getTrivialTypeSourceInfo(TType, NameLoc); + + UnaryExprOrTypeTraitExpr *sizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr( + UETT_SizeOf, TTypeSourceInfo, UnsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + QualType SizeType = Context.getSizeType(); + llvm::APInt SizeValue = llvm::APInt(Context.getTypeSize(SizeType), 16); + IntegerLiteral *SizeLiteral = + new (Context) IntegerLiteral(Context, SizeValue, SizeType, NameLoc); + + QualType BoolTy = Context.BoolTy; + + BinaryOperator *binaryOperator = + BinaryOperator::Create(Context, sizeOfExpr, // Left-hand side expression + SizeLiteral, // Right-hand side expression + BO_LE, // Binary operator kind (<=) + BoolTy, // Result type (bool) + VK_LValue, // Value kind + OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + ASTContext &Context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *SizeOfLEQ16 = constructSizeOfLEQ16Expr(Context, NameLoc, T); + // TODO: add the 'builtin_hlsl_is_typed_resource_element_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T'. + // Defined in issue https://github.com/llvm/llvm-project/issues/113223 + return SizeOfLEQ16; +} + +ConceptDecl *constructTypedBufferConceptDecl(Sema &S, NamespaceDecl *NSD) { + ASTContext &Context = S.getASTContext(); + DeclContext *DC = NSD->getDeclContext(); + SourceLocation DeclLoc = SourceLocation(); + + IdentifierInfo &ElementTypeII = Context.Idents.get("element_type"); + TemplateTypeParmDecl *T = TemplateTypeParmDecl::Create( + Context, Context.getTranslationUnitDecl(), DeclLoc, DeclLoc, + /*depth=*/0, + /*position=*/0, + /*id=*/&ElementTypeII, + /*Typename=*/true, + /*ParameterPack=*/false); + + T->setDeclContext(DC); + T->setReferenced(); + + // Create and Attach Template Parameter List to ConceptDecl + TemplateParameterList *ConceptParams = TemplateParameterList::Create( + Context, DeclLoc, DeclLoc, {T}, DeclLoc, nullptr); + + DeclarationName DeclName = DeclarationName( + &Context.Idents.get("__is_typed_resource_element_compatible")); + Expr *ConstraintExpr = constructTypedBufferConstraintExpr(S, DeclLoc, T); + + // Create a ConceptDecl + ConceptDecl *CD = + ConceptDecl::Create(Context, Context.getTranslationUnitDecl(), DeclLoc, + DeclName, ConceptParams, ConstraintExpr); + + // Attach the template parameter list to the ConceptDecl + CD->setTemplateParameters(ConceptParams); + + // Add the concept declaration to the Translation Unit Decl + Context.getTranslationUnitDecl()->addDecl(CD); llvm-beanz wrote: We should be putting the concepts under the `hlsl` namespace not under the top level declaration where they may conflict with user-defined declarations. ```suggestion NSD->getDeclContext()->addDecl(CD); ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +583,103 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + QualType UnsignedLongType = Context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + QualType TType = Context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + TypeSourceInfo *TTypeSourceInfo = + Context.getTrivialTypeSourceInfo(TType, NameLoc); + + UnaryExprOrTypeTraitExpr *sizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr( + UETT_SizeOf, TTypeSourceInfo, UnsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + QualType SizeType = Context.getSizeType(); + llvm::APInt SizeValue = llvm::APInt(Context.getTypeSize(SizeType), 16); + IntegerLiteral *SizeLiteral = + new (Context) IntegerLiteral(Context, SizeValue, SizeType, NameLoc); + + QualType BoolTy = Context.BoolTy; + + BinaryOperator *binaryOperator = + BinaryOperator::Create(Context, sizeOfExpr, // Left-hand side expression + SizeLiteral, // Right-hand side expression + BO_LE, // Binary operator kind (<=) + BoolTy, // Result type (bool) + VK_LValue, // Value kind + OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + ASTContext &Context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *SizeOfLEQ16 = constructSizeOfLEQ16Expr(Context, NameLoc, T); + // TODO: add the 'builtin_hlsl_is_typed_resource_element_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T'. + // Defined in issue https://github.com/llvm/llvm-project/issues/113223 + return SizeOfLEQ16; +} + +ConceptDecl *constructTypedBufferConceptDecl(Sema &S, NamespaceDecl *NSD) { + ASTContext &Context = S.getASTContext(); + DeclContext *DC = NSD->getDeclContext(); + SourceLocation DeclLoc = SourceLocation(); + + IdentifierInfo &ElementTypeII = Context.Idents.get("element_type"); + TemplateTypeParmDecl *T = TemplateTypeParmDecl::Create( + Context, Context.getTranslationUnitDecl(), DeclLoc, DeclLoc, + /*depth=*/0, + /*position=*/0, + /*id=*/&ElementTypeII, + /*Typename=*/true, + /*ParameterPack=*/false); + + T->setDeclContext(DC); + T->setReferenced(); + + // Create and Attach Template Parameter List to ConceptDecl + TemplateParameterList *ConceptParams = TemplateParameterList::Create( + Context, DeclLoc, DeclLoc, {T}, DeclLoc, nullptr); + + DeclarationName DeclName = DeclarationName( + &Context.Idents.get("__is_typed_resource_element_compatible")); + Expr *ConstraintExpr = constructTypedBufferConstraintExpr(S, DeclLoc, T); + + // Create a ConceptDecl + ConceptDecl *CD = + ConceptDecl::Create(Context, Context.getTranslationUnitDecl(), DeclLoc, llvm-beanz wrote: ```suggestion ConceptDecl::Create(Context, NSD->getDeclContext(), DeclLoc, ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,129 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The concept specialization expression (CSE) constructed in + constructConceptSpecializationExpr is constructed so that it + matches the CSE that is constructed when parsing the below C++ code: + + template + concept is_typed_resource_element_compatible = sizeof(T) <= 16; + + template requires + is_typed_resource_element_compatible + struct RWBuffer { + element_type Val; + }; + + int fn() { + RWBuffer Buf; + } + + When dumping the AST and filtering for "RWBuffer", the resulting AST + structure is what we're trying to construct below, specifically the + CSE portion. + */ + ConceptSpecializationExpr * + constructConceptSpecializationExpr(Sema &S, ConceptDecl *CD) { +ASTContext &Context = S.getASTContext(); +SourceLocation Loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), Loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(Loc, Loc); + +// Assume that the concept decl has just one template parameter +// This parameter should have been added when CD was constructed +// in getTypedBufferConceptDecl +assert(CD->getTemplateParameters()->size() == 1 && + "unexpected concept decl parameter count"); +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +// this TemplateTypeParmDecl is the template for the resource, and is +// used to construct a template argumentthat will be used +// to construct the ImplicitConceptSpecializationDecl +TemplateTypeParmDecl *T = TemplateTypeParmDecl::Create( +Context, // AST context +Context.getTranslationUnitDecl(), // DeclContext llvm-beanz wrote: This is where the DeclContext is wrong that I referenced in https://github.com/llvm/llvm-project/pull/112600/files/6edf031b5e736b38cf3551ccc872351f9c8a07ca#r1835111011 ```suggestion Builder.Record->getDeclContext();, // DeclContext ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,127 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The concept specialization expression (CSE) constructed below is constructed + so that it matches the CSE that is constructed when parsing + the below C++ code: + + template + concept is_typed_resource_element_compatible =sizeof(T) <= 16; + + template requires + is_typed_resource_element_compatible + + struct RWBuffer { + element_type Val; + }; + + int fn() { + RWBuffer Buf; + } + + When dumping the AST and filtering for "RWBuffer", the resulting AST + structure is what we're trying to construct below, specifically the + CSE portion. + */ + ConceptSpecializationExpr * + constructConceptSpecializationExpr(Sema &S, ConceptDecl *CD) { +ASTContext &Context = S.getASTContext(); +SourceLocation Loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), Loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(Loc, Loc); + +// Assume that the concept decl has just one template parameter +// This parameter should have been added when CD was constructed +// in getTypedBufferConceptDecl +assert(CD->getTemplateParameters()->size() == 1 && + "unexpected concept decl parameter count"); +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +// this fake TemplateTypeParmDecl is used to construct a template argument +// that will be used to construct the ImplicitConceptSpecializationDecl bob80905 wrote: On further investigation, yes I believe it is being placed into the AST. I didn't realize that setting the DeclContext correlated with AST placement. However, comparing the generated AST with similar C++ code, I do think the declaration context for this template type parm decl is correct. (That is, the context is the ClassTemplateDecl, and it shows up directly indented under the ClassTemplateDecl in the AST. I've added tests for the concept declaration AST. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,127 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The concept specialization expression (CSE) constructed below is constructed + so that it matches the CSE that is constructed when parsing + the below C++ code: + + template + concept is_typed_resource_element_compatible =sizeof(T) <= 16; + + template requires + is_typed_resource_element_compatible + + struct RWBuffer { + element_type Val; + }; + + int fn() { + RWBuffer Buf; + } + + When dumping the AST and filtering for "RWBuffer", the resulting AST + structure is what we're trying to construct below, specifically the + CSE portion. + */ + ConceptSpecializationExpr * + constructConceptSpecializationExpr(Sema &S, ConceptDecl *CD) { +ASTContext &Context = S.getASTContext(); +SourceLocation Loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), Loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(Loc, Loc); + +// Assume that the concept decl has just one template parameter +// This parameter should have been added when CD was constructed +// in getTypedBufferConceptDecl +assert(CD->getTemplateParameters()->size() == 1 && + "unexpected concept decl parameter count"); +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +// this fake TemplateTypeParmDecl is used to construct a template argument +// that will be used to construct the ImplicitConceptSpecializationDecl llvm-beanz wrote: This sounds wrong... Like, completely wrong. You're absolutely adding it to the AST, that's what happens when you create a declaration and put it into a declaration context. This also seems like we're putting this declaration into the wrong declaration context. I don't see any of your tests verifying the AST shape of the concept declaration. Can you add tests for that so that we can see what the concept's AST looks like? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,127 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The concept specialization expression (CSE) constructed below is constructed + so that it matches the CSE that is constructed when parsing + the below C++ code: + + template + concept is_typed_resource_element_compatible =sizeof(T) <= 16; + + template requires + is_typed_resource_element_compatible + + struct RWBuffer { + element_type Val; + }; + + int fn() { + RWBuffer Buf; + } + + When dumping the AST and filtering for "RWBuffer", the resulting AST + structure is what we're trying to construct below, specifically the + CSE portion. + */ + ConceptSpecializationExpr * + constructConceptSpecializationExpr(Sema &S, ConceptDecl *CD) { +ASTContext &Context = S.getASTContext(); +SourceLocation Loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), Loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(Loc, Loc); + +// Assume that the concept decl has just one template parameter +// This parameter should have been added when CD was constructed +// in getTypedBufferConceptDecl +assert(CD->getTemplateParameters()->size() == 1 && + "unexpected concept decl parameter count"); +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +// this fake TemplateTypeParmDecl is used to construct a template argument +// that will be used to construct the ImplicitConceptSpecializationDecl +TemplateTypeParmDecl *T = TemplateTypeParmDecl::Create( +Context, // AST context +Context.getTranslationUnitDecl(), // DeclContext +SourceLocation(), SourceLocation(), +/*depth=*/0,// Depth in the template parameter list +/*position=*/0, // Position in the template parameter list +/*id=*/nullptr, // Identifier for 'T' +/*Typename=*/true, // Indicates this is a 'typename' or 'class' +/*ParameterPack=*/false,// Not a parameter pack +/*HasTypeConstraint=*/false // Has no type constraint +); + +T->setDeclContext(DC); + +QualType ConceptTType = Context.getTypeDeclType(ConceptTTPD); + +// this is the 2nd template argument node in the AST above bob80905 wrote: Ah, this was when I had the entire AST inside a comment previously, haven't updated it, will fix! https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,127 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The concept specialization expression (CSE) constructed below is constructed + so that it matches the CSE that is constructed when parsing + the below C++ code: + + template + concept is_typed_resource_element_compatible =sizeof(T) <= 16; + + template requires + is_typed_resource_element_compatible + + struct RWBuffer { + element_type Val; + }; + + int fn() { + RWBuffer Buf; + } + + When dumping the AST and filtering for "RWBuffer", the resulting AST + structure is what we're trying to construct below, specifically the + CSE portion. + */ + ConceptSpecializationExpr * + constructConceptSpecializationExpr(Sema &S, ConceptDecl *CD) { +ASTContext &Context = S.getASTContext(); +SourceLocation Loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), Loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(Loc, Loc); + +// Assume that the concept decl has just one template parameter +// This parameter should have been added when CD was constructed +// in getTypedBufferConceptDecl +assert(CD->getTemplateParameters()->size() == 1 && + "unexpected concept decl parameter count"); +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +// this fake TemplateTypeParmDecl is used to construct a template argument +// that will be used to construct the ImplicitConceptSpecializationDecl bob80905 wrote: It isn't being placed into the AST, the sole reason for its existence is to allow a path to construct a TemplateArgument, and that TemplateArgument will actually be placed into the AST. The fake TemplateTypeParmDecl is otherwise unused and discarded. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,127 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The concept specialization expression (CSE) constructed below is constructed + so that it matches the CSE that is constructed when parsing + the below C++ code: + + template + concept is_typed_resource_element_compatible =sizeof(T) <= 16; + + template requires + is_typed_resource_element_compatible + + struct RWBuffer { + element_type Val; bob80905 wrote: I agree that when parsing the C++ code in the comment, it produces more of the AST than the function is producing, but I still believe that including that extra context in the comments is helpful. The C++ code adds the structure "RWBuffer", and though it isn't being produced by `constructConceptSpecializationExpr`, it helps to know what code can be copy pasted into godbolt, for example, to see the AST that would be produced. I had originally wanted to paste the AST that would be produced, but figured getting the source code would help explain the code better and also allow those who are interested to get the AST from the code. The first point of the comment says that "The concept specialization expression (CSE) constructed below is constructed so that it matches the CSE that is constructed when parsing the below C++ code:" Which is still accurate. The code in the function isn't claiming to be responsible for the whole AST. I will reword it slightly for more clarity. For your last 2 questions, yes I think your statements are accurate. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/damyanp edited https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,127 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The concept specialization expression (CSE) constructed below is constructed + so that it matches the CSE that is constructed when parsing + the below C++ code: + + template + concept is_typed_resource_element_compatible =sizeof(T) <= 16; + + template requires + is_typed_resource_element_compatible + damyanp wrote: The blank line between the template bit and the struct really confused me for a while trying to read this. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,127 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The concept specialization expression (CSE) constructed below is constructed + so that it matches the CSE that is constructed when parsing + the below C++ code: + + template + concept is_typed_resource_element_compatible =sizeof(T) <= 16; + + template requires + is_typed_resource_element_compatible + + struct RWBuffer { + element_type Val; damyanp wrote: I don't think that the code in this comment really matches the AST that's being built. RWBuffer doesn't have a member of type element_type, for example. I _think_ that this function is just building up the AST that corresponds to the `requires is_typed_resource_element_compatible` part? The AST nodes for ` template concept is_typed_resource_element_compatible =sizeof(T) <= 16;` itself is created in constructTypedBufferConceptDecl? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,127 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The concept specialization expression (CSE) constructed below is constructed + so that it matches the CSE that is constructed when parsing + the below C++ code: + + template + concept is_typed_resource_element_compatible =sizeof(T) <= 16; + + template requires + is_typed_resource_element_compatible + + struct RWBuffer { + element_type Val; + }; + + int fn() { + RWBuffer Buf; + } + + When dumping the AST and filtering for "RWBuffer", the resulting AST + structure is what we're trying to construct below, specifically the + CSE portion. + */ + ConceptSpecializationExpr * + constructConceptSpecializationExpr(Sema &S, ConceptDecl *CD) { +ASTContext &Context = S.getASTContext(); +SourceLocation Loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), Loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(Loc, Loc); + +// Assume that the concept decl has just one template parameter +// This parameter should have been added when CD was constructed +// in getTypedBufferConceptDecl +assert(CD->getTemplateParameters()->size() == 1 && + "unexpected concept decl parameter count"); +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +// this fake TemplateTypeParmDecl is used to construct a template argument +// that will be used to construct the ImplicitConceptSpecializationDecl +TemplateTypeParmDecl *T = TemplateTypeParmDecl::Create( +Context, // AST context +Context.getTranslationUnitDecl(), // DeclContext +SourceLocation(), SourceLocation(), +/*depth=*/0,// Depth in the template parameter list +/*position=*/0, // Position in the template parameter list +/*id=*/nullptr, // Identifier for 'T' +/*Typename=*/true, // Indicates this is a 'typename' or 'class' +/*ParameterPack=*/false,// Not a parameter pack +/*HasTypeConstraint=*/false // Has no type constraint +); + +T->setDeclContext(DC); + +QualType ConceptTType = Context.getTypeDeclType(ConceptTTPD); + +// this is the 2nd template argument node in the AST above damyanp wrote: I'm not entirely sure what "the AST above" refers to. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/damyanp commented: Some notes, mostly about the comments. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,127 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The concept specialization expression (CSE) constructed below is constructed + so that it matches the CSE that is constructed when parsing + the below C++ code: + + template + concept is_typed_resource_element_compatible =sizeof(T) <= 16; + + template requires + is_typed_resource_element_compatible + + struct RWBuffer { + element_type Val; + }; + + int fn() { + RWBuffer Buf; + } + + When dumping the AST and filtering for "RWBuffer", the resulting AST + structure is what we're trying to construct below, specifically the + CSE portion. + */ + ConceptSpecializationExpr * + constructConceptSpecializationExpr(Sema &S, ConceptDecl *CD) { +ASTContext &Context = S.getASTContext(); +SourceLocation Loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), Loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(Loc, Loc); + +// Assume that the concept decl has just one template parameter +// This parameter should have been added when CD was constructed +// in getTypedBufferConceptDecl +assert(CD->getTemplateParameters()->size() == 1 && + "unexpected concept decl parameter count"); +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +// this fake TemplateTypeParmDecl is used to construct a template argument +// that will be used to construct the ImplicitConceptSpecializationDecl damyanp wrote: What's fake about it? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,127 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The concept specialization expression (CSE) constructed below is constructed + so that it matches the CSE that is constructed when parsing + the below C++ code: + + template + concept is_valid_line_vector =sizeof(T) <= 16; + + template requires is_valid_line_vector + + struct RWBuffer { + element_type Val; + }; + + int fn() { + RWBuffer Buf; + } + + When dumping the AST and filtering for "RWBuffer", the resulting AST + structure is what we're trying to construct below, specifically the + CSE portion. + */ + ConceptSpecializationExpr * + constructConceptSpecializationExpr(Sema &S, ConceptDecl *CD) { +ASTContext &Context = S.getASTContext(); +SourceLocation Loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), Loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(Loc, Loc); + +// Assume that the concept decl has just one template parameter +// This parameter should have been added when CD was constructed +// in getTypedBufferConceptDecl +assert(CD->getTemplateParameters()->size() == 1 && + "unexpected concept decl parameter count"); +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +// this fake TemplateTypeParmDecl is used to construct a template argument +// that will be used to construct the ImplicitConceptSpecializationDecl +TemplateTypeParmDecl *T = TemplateTypeParmDecl::Create( +Context, // AST context +Context.getTranslationUnitDecl(), // DeclContext +SourceLocation(), SourceLocation(), +/*depth=*/0,// Depth in the template parameter list +/*position=*/0, // Position in the template parameter list +/*id=*/nullptr, // Identifier for 'T' +/*Typename=*/true, // Indicates this is a 'typename' or 'class' +/*ParameterPack=*/false,// Not a parameter pack +/*HasTypeConstraint=*/false // Has no type constraint +); + +T->setDeclContext(DC); +T->setReferenced(); bob80905 wrote: Setting the decl context is necessary because it puts the decl into the right indentation in the AST dump. Otherwise, I believe the decl would be placed at the same scope as one indentation below the translation unit decl, which is not where the decl belongs. I'll see if I can get away with removing setReferenced here. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/hekota approved this pull request. Few minor things, otherwise LGTM! https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,127 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The concept specialization expression (CSE) constructed below is constructed + so that it matches the CSE that is constructed when parsing + the below C++ code: + + template + concept is_valid_line_vector =sizeof(T) <= 16; + + template requires is_valid_line_vector hekota wrote: This still uses the old name. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,127 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The concept specialization expression (CSE) constructed below is constructed + so that it matches the CSE that is constructed when parsing + the below C++ code: + + template + concept is_valid_line_vector =sizeof(T) <= 16; + + template requires is_valid_line_vector + + struct RWBuffer { + element_type Val; + }; + + int fn() { + RWBuffer Buf; + } + + When dumping the AST and filtering for "RWBuffer", the resulting AST + structure is what we're trying to construct below, specifically the + CSE portion. + */ + ConceptSpecializationExpr * + constructConceptSpecializationExpr(Sema &S, ConceptDecl *CD) { +ASTContext &Context = S.getASTContext(); +SourceLocation Loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), Loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(Loc, Loc); + +// Assume that the concept decl has just one template parameter +// This parameter should have been added when CD was constructed +// in getTypedBufferConceptDecl +assert(CD->getTemplateParameters()->size() == 1 && + "unexpected concept decl parameter count"); +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +// this fake TemplateTypeParmDecl is used to construct a template argument +// that will be used to construct the ImplicitConceptSpecializationDecl +TemplateTypeParmDecl *T = TemplateTypeParmDecl::Create( +Context, // AST context +Context.getTranslationUnitDecl(), // DeclContext +SourceLocation(), SourceLocation(), +/*depth=*/0,// Depth in the template parameter list +/*position=*/0, // Position in the template parameter list +/*id=*/nullptr, // Identifier for 'T' +/*Typename=*/true, // Indicates this is a 'typename' or 'class' +/*ParameterPack=*/false,// Not a parameter pack +/*HasTypeConstraint=*/false // Has no type constraint +); + +T->setDeclContext(DC); +T->setReferenced(); hekota wrote: Why do you need to set this explicitly? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +581,105 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + QualType UnsignedLongType = Context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + QualType TType = Context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + TypeSourceInfo *TTypeSourceInfo = + Context.getTrivialTypeSourceInfo(TType, NameLoc); + + UnaryExprOrTypeTraitExpr *sizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr( + UETT_SizeOf, TTypeSourceInfo, UnsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + QualType SizeType = Context.getSizeType(); + llvm::APInt SizeValue = llvm::APInt(Context.getTypeSize(SizeType), 16); + IntegerLiteral *SizeLiteral = + new (Context) IntegerLiteral(Context, SizeValue, SizeType, NameLoc); + + QualType BoolTy = Context.BoolTy; + + BinaryOperator *binaryOperator = + BinaryOperator::Create(Context, sizeOfExpr, // Left-hand side expression + SizeLiteral, // Right-hand side expression + BO_LE, // Binary operator kind (<=) + BoolTy, // Result type (bool) + VK_LValue, // Value kind + OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + ASTContext &Context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *SizeOfLEQ16 = constructSizeOfLEQ16Expr(Context, NameLoc, T); + // TODO: add the 'builtin_hlsl_is_typed_resource_element_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T'. + // Defined in issue https://github.com/llvm/llvm-project/issues/113223 + return SizeOfLEQ16; +} + +ConceptDecl *constructTypedBufferConceptDecl(Sema &S, NamespaceDecl *NSD) { + ASTContext &Context = S.getASTContext(); + DeclContext *DC = NSD->getDeclContext(); + SourceLocation DeclLoc = SourceLocation(); + + IdentifierInfo &IsTypedResourceElementCompatibleII = + Context.Idents.get("__is_typed_resource_element_compatible"); hekota wrote: Nit - move this just before DeclName declaration, or better yet use `Context.Idents.get("__is_typed_resource_element_compatible")` directly in the DeclarationName constructor. It makes it easier to read when variables are declared closer to where they are is used. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/hekota edited https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +581,105 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + QualType UnsignedLongType = Context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + QualType TType = Context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + TypeSourceInfo *TTypeSourceInfo = + Context.getTrivialTypeSourceInfo(TType, NameLoc); + + UnaryExprOrTypeTraitExpr *sizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr( + UETT_SizeOf, TTypeSourceInfo, UnsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + QualType SizeType = Context.getSizeType(); + llvm::APInt SizeValue = llvm::APInt(Context.getTypeSize(SizeType), 16); + IntegerLiteral *SizeLiteral = + new (Context) IntegerLiteral(Context, SizeValue, SizeType, NameLoc); + + QualType BoolTy = Context.BoolTy; + + BinaryOperator *binaryOperator = + BinaryOperator::Create(Context, sizeOfExpr, // Left-hand side expression + SizeLiteral, // Right-hand side expression + BO_LE, // Binary operator kind (<=) + BoolTy, // Result type (bool) + VK_LValue, // Value kind + OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + ASTContext &Context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *SizeOfLEQ16 = constructSizeOfLEQ16Expr(Context, NameLoc, T); + // TODO: add the 'builtin_hlsl_is_typed_resource_element_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T'. + // Defined in issue https://github.com/llvm/llvm-project/issues/113223 + return SizeOfLEQ16; +} + +ConceptDecl *constructTypedBufferConceptDecl(Sema &S, NamespaceDecl *NSD) { + ASTContext &Context = S.getASTContext(); + DeclContext *DC = NSD->getDeclContext(); + SourceLocation DeclLoc = SourceLocation(); + + IdentifierInfo &IsTypedResourceElementCompatibleII = + Context.Idents.get("__is_typed_resource_element_compatible"); + IdentifierInfo &ElementTypeII = Context.Idents.get("element_type"); + TemplateTypeParmDecl *T = TemplateTypeParmDecl::Create( + Context, Context.getTranslationUnitDecl(), DeclLoc, DeclLoc, + /*depth=*/0, + /*position=*/0, + /*id=*/&ElementTypeII, + /*Typename=*/true, + /*ParameterPack=*/false); + + T->setDeclContext(DC); + T->setReferenced(); + + // Create and Attach Template Parameter List to ConceptDecl + TemplateParameterList *ConceptParams = TemplateParameterList::Create( + Context, DeclLoc, DeclLoc, {T}, DeclLoc, nullptr); + + DeclarationName DeclName = + DeclarationName(&IsTypedResourceElementCompatibleII); + Expr *ConstraintExpr = constructTypedBufferConstraintExpr(S, DeclLoc, T); + + // Create a ConceptDecl + ConceptDecl *CD = + ConceptDecl::Create(Context, Context.getTranslationUnitDecl(), DeclLoc, + DeclName, ConceptParams, ConstraintExpr); + + // Attach the template parameter list to the ConceptDecl + CD->setTemplateParameters(ConceptParams); + + // Add the concept declaration to the Translation Unit Decl + Context.getTranslationUnitDecl()->addDecl(CD); + + return CD; +} + void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { CXXRecordDecl *Decl; + ConceptDecl *TypeBufferConcept = hekota wrote: Typo ```suggestion ConceptDecl *TypedBufferConcept = ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
bob80905 wrote: > Since your PR that adds `__builtin_hlsl_is_typed_resource_element_compatible` > is merged do you want to incorporate here? I'd prefer not to, because this PR is already pretty big and I have a separate task that is singularly dedicated to finalizing the constraint expression, which will include incorporating the new builtin. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
hekota wrote: Since your PR that adds `__builtin_hlsl_is_typed_resource_element_compatible` is merged do you want to incorporate here? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 edited https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +581,102 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + QualType UnsignedLongType = Context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + QualType TType = Context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + TypeSourceInfo *TTypeSourceInfo = + Context.getTrivialTypeSourceInfo(TType, NameLoc); + + UnaryExprOrTypeTraitExpr *sizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr( + UETT_SizeOf, TTypeSourceInfo, UnsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + QualType SizeType = Context.getSizeType(); + llvm::APInt SizeValue = llvm::APInt(Context.getTypeSize(SizeType), 16); + IntegerLiteral *SizeLiteral = + new (Context) IntegerLiteral(Context, SizeValue, SizeType, NameLoc); + + QualType BoolTy = Context.BoolTy; + + BinaryOperator *binaryOperator = + BinaryOperator::Create(Context, sizeOfExpr, // Left-hand side expression + SizeLiteral, // Right-hand side expression + BO_LE, // Binary operator kind (<=) + BoolTy, // Result type (bool) + VK_LValue, // Value kind + OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + ASTContext &Context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *SizeOfLEQ16 = constructSizeOfLEQ16Expr(Context, NameLoc, T); + // TODO: add the '__builtin_hlsl_is_line_vector_layout_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T' + return SizeOfLEQ16; +} + +ConceptDecl *constructTypedBufferConceptDecl(Sema &S) { + DeclContext *DC = S.CurContext; llvm-beanz wrote: Do we want this to be Sema's current context, or the HLSL namespace context? My guess is the later. It probably doesn't matter too much, but it would be nice to make sure we're not injecting AST nodes into the top-level declaration context or a user-defined context. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +581,102 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + QualType UnsignedLongType = Context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + QualType TType = Context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + TypeSourceInfo *TTypeSourceInfo = + Context.getTrivialTypeSourceInfo(TType, NameLoc); + + UnaryExprOrTypeTraitExpr *sizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr( + UETT_SizeOf, TTypeSourceInfo, UnsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + QualType SizeType = Context.getSizeType(); + llvm::APInt SizeValue = llvm::APInt(Context.getTypeSize(SizeType), 16); + IntegerLiteral *SizeLiteral = + new (Context) IntegerLiteral(Context, SizeValue, SizeType, NameLoc); + + QualType BoolTy = Context.BoolTy; + + BinaryOperator *binaryOperator = + BinaryOperator::Create(Context, sizeOfExpr, // Left-hand side expression + SizeLiteral, // Right-hand side expression + BO_LE, // Binary operator kind (<=) + BoolTy, // Result type (bool) + VK_LValue, // Value kind + OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + ASTContext &Context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *SizeOfLEQ16 = constructSizeOfLEQ16Expr(Context, NameLoc, T); + // TODO: add the '__builtin_hlsl_is_line_vector_layout_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T' + return SizeOfLEQ16; +} + +ConceptDecl *constructTypedBufferConceptDecl(Sema &S) { + DeclContext *DC = S.CurContext; + ASTContext &Context = S.getASTContext(); + SourceLocation DeclLoc = SourceLocation(); + + IdentifierInfo &IsValidLineVectorII = + Context.Idents.get("is_valid_line_vector"); llvm-beanz wrote: I think we also had a different name for this... Can you also prefix the name with double underscore (`__`) since it is an implementation detail in the compiler rather than an intentionally user-surfaced language feature? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/llvm-beanz commented: Mostly looking good to me. A few small comments. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +581,102 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + QualType UnsignedLongType = Context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + QualType TType = Context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + TypeSourceInfo *TTypeSourceInfo = + Context.getTrivialTypeSourceInfo(TType, NameLoc); + + UnaryExprOrTypeTraitExpr *sizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr( + UETT_SizeOf, TTypeSourceInfo, UnsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + QualType SizeType = Context.getSizeType(); + llvm::APInt SizeValue = llvm::APInt(Context.getTypeSize(SizeType), 16); + IntegerLiteral *SizeLiteral = + new (Context) IntegerLiteral(Context, SizeValue, SizeType, NameLoc); + + QualType BoolTy = Context.BoolTy; + + BinaryOperator *binaryOperator = + BinaryOperator::Create(Context, sizeOfExpr, // Left-hand side expression + SizeLiteral, // Right-hand side expression + BO_LE, // Binary operator kind (<=) + BoolTy, // Result type (bool) + VK_LValue, // Value kind + OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + ASTContext &Context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *SizeOfLEQ16 = constructSizeOfLEQ16Expr(Context, NameLoc, T); + // TODO: add the '__builtin_hlsl_is_line_vector_layout_compatible' builtin llvm-beanz wrote: I think we had agreed on a different name for this. Also is there an issue filed that you can reference in this TODO? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/llvm-beanz edited https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +582,101 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + QualType UnsignedLongType = Context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + QualType TType = Context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + TypeSourceInfo *TTypeSourceInfo = + Context.getTrivialTypeSourceInfo(TType, NameLoc); + + UnaryExprOrTypeTraitExpr *sizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr( + UETT_SizeOf, TTypeSourceInfo, UnsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + QualType SizeType = Context.getSizeType(); + llvm::APInt SizeValue = llvm::APInt(Context.getTypeSize(SizeType), 16); + IntegerLiteral *SizeLiteral = + new (Context) IntegerLiteral(Context, SizeValue, SizeType, NameLoc); + + QualType BoolTy = Context.BoolTy; + + BinaryOperator *binaryOperator = + BinaryOperator::Create(Context, sizeOfExpr, // Left-hand side expression + SizeLiteral, // Right-hand side expression + BO_LE, // Binary operator kind (<=) + BoolTy, // Result type (bool) + VK_LValue, // Value kind + OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + ASTContext &Context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *SizeOfLEQ16 = constructSizeOfLEQ16Expr(Context, NameLoc, T); + // TODO: add the '__builtin_hlsl_is_line_vector_layout_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T' + return SizeOfLEQ16; +} + +ConceptDecl *constructTypedBufferConceptDecl(Sema &S) { + DeclContext *DC = S.CurContext; + ASTContext &Context = S.getASTContext(); + SourceLocation DeclLoc = SourceLocation(); + + IdentifierInfo &IsValidLineVectorII = + Context.Idents.get("is_valid_line_vector"); + IdentifierInfo &ElementTypeII = Context.Idents.get("element_type"); + TemplateTypeParmDecl *T = TemplateTypeParmDecl::Create( + Context, Context.getTranslationUnitDecl(), DeclLoc, DeclLoc, + /*depth=*/0, + /*position=*/0, + /*id=*/&ElementTypeII, + /*Typename=*/true, + /*ParameterPack=*/false); + + T->setDeclContext(DC); + T->setReferenced(); + + // Create and Attach Template Parameter List to ConceptDecl + TemplateParameterList *ConceptParams = TemplateParameterList::Create( + Context, DeclLoc, DeclLoc, {T}, DeclLoc, nullptr); + + DeclarationName DeclName = DeclarationName(&IsValidLineVectorII); + Expr *ConstraintExpr = constructTypedBufferConstraintExpr(S, DeclLoc, T); + + // Create a ConceptDecl + ConceptDecl *CD = + ConceptDecl::Create(Context, Context.getTranslationUnitDecl(), DeclLoc, + DeclName, ConceptParams, ConstraintExpr); + + // Attach the template parameter list to the ConceptDecl + CD->setTemplateParameters(ConceptParams); + + // Add the concept declaration to the Translation Unit Decl + Context.getTranslationUnitDecl()->addDecl(CD); + + return CD; +} + void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { CXXRecordDecl *Decl; + ConceptDecl *CD = constructTypedBufferConceptDecl(*SemaPtr); bob80905 wrote: Right, updated. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +582,101 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + QualType UnsignedLongType = Context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + QualType TType = Context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + TypeSourceInfo *TTypeSourceInfo = + Context.getTrivialTypeSourceInfo(TType, NameLoc); + + UnaryExprOrTypeTraitExpr *sizeOfExpr = new (Context) UnaryExprOrTypeTraitExpr( + UETT_SizeOf, TTypeSourceInfo, UnsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + QualType SizeType = Context.getSizeType(); + llvm::APInt SizeValue = llvm::APInt(Context.getTypeSize(SizeType), 16); + IntegerLiteral *SizeLiteral = + new (Context) IntegerLiteral(Context, SizeValue, SizeType, NameLoc); + + QualType BoolTy = Context.BoolTy; + + BinaryOperator *binaryOperator = + BinaryOperator::Create(Context, sizeOfExpr, // Left-hand side expression + SizeLiteral, // Right-hand side expression + BO_LE, // Binary operator kind (<=) + BoolTy, // Result type (bool) + VK_LValue, // Value kind + OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + ASTContext &Context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *SizeOfLEQ16 = constructSizeOfLEQ16Expr(Context, NameLoc, T); + // TODO: add the '__builtin_hlsl_is_line_vector_layout_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T' + return SizeOfLEQ16; +} + +ConceptDecl *constructTypedBufferConceptDecl(Sema &S) { + DeclContext *DC = S.CurContext; + ASTContext &Context = S.getASTContext(); + SourceLocation DeclLoc = SourceLocation(); + + IdentifierInfo &IsValidLineVectorII = + Context.Idents.get("is_valid_line_vector"); + IdentifierInfo &ElementTypeII = Context.Idents.get("element_type"); + TemplateTypeParmDecl *T = TemplateTypeParmDecl::Create( + Context, Context.getTranslationUnitDecl(), DeclLoc, DeclLoc, + /*depth=*/0, + /*position=*/0, + /*id=*/&ElementTypeII, + /*Typename=*/true, + /*ParameterPack=*/false); + + T->setDeclContext(DC); + T->setReferenced(); + + // Create and Attach Template Parameter List to ConceptDecl + TemplateParameterList *ConceptParams = TemplateParameterList::Create( + Context, DeclLoc, DeclLoc, {T}, DeclLoc, nullptr); + + DeclarationName DeclName = DeclarationName(&IsValidLineVectorII); + Expr *ConstraintExpr = constructTypedBufferConstraintExpr(S, DeclLoc, T); + + // Create a ConceptDecl + ConceptDecl *CD = + ConceptDecl::Create(Context, Context.getTranslationUnitDecl(), DeclLoc, + DeclName, ConceptParams, ConstraintExpr); + + // Attach the template parameter list to the ConceptDecl + CD->setTemplateParameters(ConceptParams); + + // Add the concept declaration to the Translation Unit Decl + Context.getTranslationUnitDecl()->addDecl(CD); + + return CD; +} + void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() { CXXRecordDecl *Decl; + ConceptDecl *CD = constructTypedBufferConceptDecl(*SemaPtr); hekota wrote: I'd probably use a more descriptive name here, like `TypeBufferConcept` since as we'll need to have one for RawBuffers as well, right? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,99 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - +Decl->setReferenced(); hekota wrote: `referenced' means the declaration is referenced/used somewhere in the source code, you should not be setting it here. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/damyanp commented: LGTM. Would be good to get review from someone more familiar with ASTs and external sema source. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 76196998e25b98d81abc437708622261810782ca ab7c20059e5fafd33624ed166e747ee473248551 --extensions cpp -- clang/lib/Sema/HLSLExternalSemaSource.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 7d0251a423..72ca3b4371 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -358,8 +358,8 @@ struct TemplateParameterListBuilder { structure is what we're trying to construct below, specifically the CSE portion. */ - ConceptSpecializationExpr *constructConceptSpecializationExpr(Sema &S, - ConceptDecl *CD) { + ConceptSpecializationExpr * + constructConceptSpecializationExpr(Sema &S, ConceptDecl *CD) { ASTContext &Context = S.getASTContext(); SourceLocation Loc = Builder.Record->getBeginLoc(); DeclarationNameInfo DNI(CD->getDeclName(), Loc); @@ -582,8 +582,9 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } -BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context, SourceLocation NameLoc, - TemplateTypeParmDecl *T) { +BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { // Obtain the QualType for 'unsigned long' QualType UnsignedLongType = Context.UnsignedLongTy; @@ -619,7 +620,7 @@ BinaryOperator *constructSizeOfLEQ16Expr(ASTContext &Context, SourceLocation Nam } Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, - TemplateTypeParmDecl *T) { + TemplateTypeParmDecl *T) { ASTContext &Context = S.getASTContext(); // first get the "sizeof(T) <= 16" expression, as a binary operator `` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +573,103 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *getSizeOfLEQ16Expr(clang::ASTContext &context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + clang::QualType unsignedLongType = context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + clang::QualType TType = context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + clang::TypeSourceInfo *TTypeSourceInfo = + context.getTrivialTypeSourceInfo(TType, NameLoc); + + clang::UnaryExprOrTypeTraitExpr *sizeOfExpr = new (context) + clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, + unsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + clang::QualType sizeType = context.getSizeType(); + llvm::APInt sizeValue = llvm::APInt(context.getTypeSize(sizeType), 16); + clang::IntegerLiteral *sizeLiteral = new (context) + clang::IntegerLiteral(context, sizeValue, sizeType, NameLoc); bob80905 wrote: I think I've got them all. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -1,64 +1,64 @@ -// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY %s | FileCheck -check-prefix=EMPTY %s bob80905 wrote: Fixed! https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,99 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - +Decl->setReferenced(); Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + ConceptSpecializationExpr *getConceptSpecializationExpr(Sema &S, + ConceptDecl *CD) { +ASTContext &context = S.getASTContext(); +SourceLocation loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(loc, loc); + +// assume that the concept decl has just one template parameter +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +clang::TemplateTypeParmDecl *T = clang::TemplateTypeParmDecl::Create( bob80905 wrote: Added! I've left out the expected AST structure since it probably won't ever conform to clang format. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/112600 >From 0739f6da81d7c1edd9578ae4ff9dd699e5c828c6 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 10 Oct 2024 14:31:25 -0700 Subject: [PATCH 01/14] ConceptSpecializationExpr shows up in AST!!! --- .../clang/Sema/HLSLExternalSemaSource.h | 2 + clang/lib/AST/DeclTemplate.cpp| 6 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 154 +- 3 files changed, 158 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h b/clang/include/clang/Sema/HLSLExternalSemaSource.h index 3c7495e66055dc..0266bc0f8b336e 100644 --- a/clang/include/clang/Sema/HLSLExternalSemaSource.h +++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h @@ -47,6 +47,8 @@ class HLSLExternalSemaSource : public ExternalSemaSource { using ExternalASTSource::CompleteType; /// Complete an incomplete HLSL builtin type void CompleteType(TagDecl *Tag) override; + + ConceptDecl *getTypedBufferConceptDecl(Sema &S, CXXRecordDecl *Decl); }; } // namespace clang diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 6fe817c5ef1c6b..2eae6d14718b86 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1080,10 +1080,10 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, DeclContext *DC, TemplateParameterList *Params, Expr *ConstraintExpr) { bool Invalid = AdoptTemplateParameterList(Params, DC); - auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); + auto *CD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); if (Invalid) -TD->setInvalidDecl(); - return TD; +CD->setInvalidDecl(); + return CD; } ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 2913d16fca4823..8104513857027c 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -304,6 +304,7 @@ struct BuiltinTypeDeclBuilder { TemplateParameterListBuilder addTemplateArgumentList(Sema &S); BuiltinTypeDeclBuilder &addSimpleTemplateParams(Sema &S, ArrayRef Names); + BuiltinTypeDeclBuilder &addConceptSpecializationExpr(Sema &S); }; struct TemplateParameterListBuilder { @@ -326,7 +327,8 @@ struct TemplateParameterListBuilder { SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), /* Typename */ false, -/* ParameterPack */ false); +/* ParameterPack */ false, +/* HasTypeConstraint*/ true); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), @@ -336,6 +338,152 @@ struct TemplateParameterListBuilder { return *this; } + Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { +clang::ASTContext &context = S.getASTContext(); +// Obtain the QualType for 'unsigned long' +clang::QualType unsignedLongType = context.UnsignedLongTy; + +// Create a QualType that points to this TemplateTypeParmDecl +clang::QualType TType = context.getTypeDeclType(T); + +// Create a TypeSourceInfo for the template type parameter 'T' +clang::TypeSourceInfo *TTypeSourceInfo = +context.getTrivialTypeSourceInfo(TType, NameLoc); + +clang::UnaryExprOrTypeTraitExpr *sizeofExpr = new (S.getASTContext()) +clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, +unsignedLongType, NameLoc, NameLoc); + +// Create an IntegerLiteral for the value '16' +llvm::APInt intValue(context.getIntWidth(context.IntTy), 4); +clang::IntegerLiteral *intLiteral = new (context) +clang::IntegerLiteral(context, intValue, context.IntTy, NameLoc); + +// Create an ImplicitCastExpr to cast 'int' to 'unsigned long' +FPOptionsOverride fpoo = FPOptionsOverride(); +clang::ImplicitCastExpr *implicitCastExpr = clang::ImplicitCastExpr::Create( +context, +unsignedLongType, // The type we are casting to (QualType for 'unsigned + // long') +clang::CK_IntegralCast, // CastKind (e.g., Integral cast) +intLiteral, // Sub-expression being cast +nullptr,// Base path, usually null for implicit casts +clang::VK_XValue, +fpoo // Value kind, typically VK_RValue for implicit casts +); + +clang::QualType BoolTy = context.BoolTy; + +clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( +context, sizeofExpr, // Left-hand side expression +
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,119 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - +Decl->setReferenced(); Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The desired result AST after this function constructs the concept + specialization Expression is as follows: + + |-ConceptSpecializationExpr 0xdd5d408 'bool' Concept bob80905 wrote: Yes, this was meant to show the AST structure. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +573,103 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *getSizeOfLEQ16Expr(clang::ASTContext &context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + clang::QualType unsignedLongType = context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + clang::QualType TType = context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + clang::TypeSourceInfo *TTypeSourceInfo = + context.getTrivialTypeSourceInfo(TType, NameLoc); + + clang::UnaryExprOrTypeTraitExpr *sizeOfExpr = new (context) + clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, + unsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + clang::QualType sizeType = context.getSizeType(); + llvm::APInt sizeValue = llvm::APInt(context.getTypeSize(sizeType), 16); + clang::IntegerLiteral *sizeLiteral = new (context) + clang::IntegerLiteral(context, sizeValue, sizeType, NameLoc); damyanp wrote: There's many cases of it throughout these changes, I'm not going to call them all out now - but LMK if you think you've got them all and I'll look again for any that are missed. (FWIW, it's not my preferred convention, so I spot these by looking for variable names that look 'right' to me, and know that they're actually 'wrong' because they look 'right' to me.) https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,119 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - +Decl->setReferenced(); Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + /* + The desired result AST after this function constructs the concept + specialization Expression is as follows: + + |-ConceptSpecializationExpr 0xdd5d408 'bool' Concept damyanp wrote: Did some autoformatter do something bad with the formatting here? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -1,64 +1,64 @@ -// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY %s | FileCheck -check-prefix=EMPTY %s damyanp wrote: We should try to fix this before completing the PR. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/damyanp commented: Some more notes https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +573,103 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *getSizeOfLEQ16Expr(clang::ASTContext &context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + clang::QualType unsignedLongType = context.UnsignedLongTy; damyanp wrote: There's a `using namespace clang` at the beginning of this cpp file, so I don't think any of these `clang::` qualifications are necessary. A quick survey of the rest of the existing code suggests that they are usually omitted. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,99 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - +Decl->setReferenced(); damyanp wrote: @llvm-beanz / @bogner - did you write this originally? Do you have any insights on what the right thing to do here is? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +573,103 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *getSizeOfLEQ16Expr(clang::ASTContext &context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + clang::QualType unsignedLongType = context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + clang::QualType TType = context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + clang::TypeSourceInfo *TTypeSourceInfo = + context.getTrivialTypeSourceInfo(TType, NameLoc); + + clang::UnaryExprOrTypeTraitExpr *sizeOfExpr = new (context) + clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, + unsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + clang::QualType sizeType = context.getSizeType(); + llvm::APInt sizeValue = llvm::APInt(context.getTypeSize(sizeType), 16); + clang::IntegerLiteral *sizeLiteral = new (context) + clang::IntegerLiteral(context, sizeValue, sizeType, NameLoc); damyanp wrote: These variables don't follow the expected naming convention (of starting with a capital letter). * `sizeOfExpr` * `sizeType` * `sizeLiteral` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,99 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - +Decl->setReferenced(); Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + ConceptSpecializationExpr *getConceptSpecializationExpr(Sema &S, + ConceptDecl *CD) { +ASTContext &context = S.getASTContext(); +SourceLocation loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(loc, loc); + +// assume that the concept decl has just one template parameter +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +clang::TemplateTypeParmDecl *T = clang::TemplateTypeParmDecl::Create( damyanp wrote: Would it not be meaningful to show the C++ code that generated this AST? I think that would help me understand it all better, but maybe if I saw it I'd realize I was wrong! :) https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +573,103 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *getSizeOfLEQ16Expr(clang::ASTContext &context, damyanp wrote: ```suggestion BinaryOperator *getSizeOfLEQ16Expr(clang::ASTContext &Context, ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/damyanp edited https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/112600 >From 0739f6da81d7c1edd9578ae4ff9dd699e5c828c6 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 10 Oct 2024 14:31:25 -0700 Subject: [PATCH 01/14] ConceptSpecializationExpr shows up in AST!!! --- .../clang/Sema/HLSLExternalSemaSource.h | 2 + clang/lib/AST/DeclTemplate.cpp| 6 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 154 +- 3 files changed, 158 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h b/clang/include/clang/Sema/HLSLExternalSemaSource.h index 3c7495e66055dc..0266bc0f8b336e 100644 --- a/clang/include/clang/Sema/HLSLExternalSemaSource.h +++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h @@ -47,6 +47,8 @@ class HLSLExternalSemaSource : public ExternalSemaSource { using ExternalASTSource::CompleteType; /// Complete an incomplete HLSL builtin type void CompleteType(TagDecl *Tag) override; + + ConceptDecl *getTypedBufferConceptDecl(Sema &S, CXXRecordDecl *Decl); }; } // namespace clang diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 6fe817c5ef1c6b..2eae6d14718b86 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1080,10 +1080,10 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, DeclContext *DC, TemplateParameterList *Params, Expr *ConstraintExpr) { bool Invalid = AdoptTemplateParameterList(Params, DC); - auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); + auto *CD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); if (Invalid) -TD->setInvalidDecl(); - return TD; +CD->setInvalidDecl(); + return CD; } ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 2913d16fca4823..8104513857027c 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -304,6 +304,7 @@ struct BuiltinTypeDeclBuilder { TemplateParameterListBuilder addTemplateArgumentList(Sema &S); BuiltinTypeDeclBuilder &addSimpleTemplateParams(Sema &S, ArrayRef Names); + BuiltinTypeDeclBuilder &addConceptSpecializationExpr(Sema &S); }; struct TemplateParameterListBuilder { @@ -326,7 +327,8 @@ struct TemplateParameterListBuilder { SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), /* Typename */ false, -/* ParameterPack */ false); +/* ParameterPack */ false, +/* HasTypeConstraint*/ true); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), @@ -336,6 +338,152 @@ struct TemplateParameterListBuilder { return *this; } + Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { +clang::ASTContext &context = S.getASTContext(); +// Obtain the QualType for 'unsigned long' +clang::QualType unsignedLongType = context.UnsignedLongTy; + +// Create a QualType that points to this TemplateTypeParmDecl +clang::QualType TType = context.getTypeDeclType(T); + +// Create a TypeSourceInfo for the template type parameter 'T' +clang::TypeSourceInfo *TTypeSourceInfo = +context.getTrivialTypeSourceInfo(TType, NameLoc); + +clang::UnaryExprOrTypeTraitExpr *sizeofExpr = new (S.getASTContext()) +clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, +unsignedLongType, NameLoc, NameLoc); + +// Create an IntegerLiteral for the value '16' +llvm::APInt intValue(context.getIntWidth(context.IntTy), 4); +clang::IntegerLiteral *intLiteral = new (context) +clang::IntegerLiteral(context, intValue, context.IntTy, NameLoc); + +// Create an ImplicitCastExpr to cast 'int' to 'unsigned long' +FPOptionsOverride fpoo = FPOptionsOverride(); +clang::ImplicitCastExpr *implicitCastExpr = clang::ImplicitCastExpr::Create( +context, +unsignedLongType, // The type we are casting to (QualType for 'unsigned + // long') +clang::CK_IntegralCast, // CastKind (e.g., Integral cast) +intLiteral, // Sub-expression being cast +nullptr,// Base path, usually null for implicit casts +clang::VK_XValue, +fpoo // Value kind, typically VK_RValue for implicit casts +); + +clang::QualType BoolTy = context.BoolTy; + +clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( +context, sizeofExpr, // Left-hand side expression +
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -1,64 +1,64 @@ -// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY %s | FileCheck -check-prefix=EMPTY %s bob80905 wrote: Yes, line endings seem to be messed up. I've checked out main for both these files and only changed the necessary parts, and pushed, but there must be some automatic thing my editor is doing to mess up the line endings. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,99 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - +Decl->setReferenced(); Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + ConceptSpecializationExpr *getConceptSpecializationExpr(Sema &S, + ConceptDecl *CD) { +ASTContext &context = S.getASTContext(); +SourceLocation loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(loc, loc); + +// assume that the concept decl has just one template parameter +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +clang::TemplateTypeParmDecl *T = clang::TemplateTypeParmDecl::Create( bob80905 wrote: I've added some helpful comments. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,101 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - +Decl->setReferenced(); Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + ConceptSpecializationExpr *getConceptSpecializationExpr(Sema &S, + ConceptDecl *CD) { +ASTContext &context = S.getASTContext(); +SourceLocation loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(loc, loc); + +// assume that the concept decl has just one template parameter +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +clang::TemplateTypeParmDecl *T = clang::TemplateTypeParmDecl::Create( +context, // AST context +context.getTranslationUnitDecl(), // DeclContext +SourceLocation(), SourceLocation(), +/*depth=*/0,// Depth in the template parameter list +/*position=*/0, // Position in the template parameter list +/*id=*/nullptr, // Identifier for 'T' +/*Typename=*/true, // Indicates this is a 'typename' or 'class' +/*ParameterPack=*/false,// Not a parameter pack +/*HasTypeConstraint=*/false // Not a parameter pack +); + +T->setDeclContext(DC); +T->setReferenced(); + +clang::QualType ConceptTType = context.getTypeDeclType(ConceptTTPD); + +TemplateArgument ConceptTA = TemplateArgument(ConceptTType); + +std::vector ConceptConvertedArgsVec = {ConceptTA}; +ArrayRef ConceptConvertedArgs = ConceptConvertedArgsVec; + +clang::QualType CSETType = context.getTypeDeclType(T); + +TemplateArgument CSETA = TemplateArgument(CSETType); + +std::vector CSEConvertedArgsVec = {CSETA}; +ArrayRef CSEConvertedArgs = CSEConvertedArgsVec; + +ImplicitConceptSpecializationDecl *ImplicitCSEDecl = +ImplicitConceptSpecializationDecl::Create( +context, Builder.Record->getDeclContext(), loc, CSEConvertedArgs); + +const ConstraintSatisfaction CS(CD, ConceptConvertedArgs); llvm-beanz wrote: ```suggestion clang::QualType CSETType = context.getTypeDeclType(T); TemplateArgument CSETA = TemplateArgument(CSETType); ImplicitConceptSpecializationDecl *ImplicitCSEDecl = ImplicitConceptSpecializationDecl::Create( context, Builder.Record->getDeclContext(), loc, {CSETA}); const ConstraintSatisfaction CS(CD, {ConceptTA}); ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +555,106 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *getSizeOfLEQ16Expr(clang::ASTContext &context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + clang::QualType unsignedLongType = context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + clang::QualType TType = context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + clang::TypeSourceInfo *TTypeSourceInfo = + context.getTrivialTypeSourceInfo(TType, NameLoc); + + clang::UnaryExprOrTypeTraitExpr *sizeOfExpr = new (context) + clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, + unsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + clang::QualType sizeType = context.getSizeType(); + llvm::APInt sizeValue = llvm::APInt(context.getTypeSize(sizeType), 16); + clang::IntegerLiteral *sizeLiteral = new (context) + clang::IntegerLiteral(context, sizeValue, sizeType, NameLoc); + + clang::QualType BoolTy = context.BoolTy; + + clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( + context, sizeOfExpr, // Left-hand side expression + sizeLiteral, // Right-hand side expression + clang::BO_LE,// Binary operator kind (<=) + BoolTy, // Result type (bool) + clang::VK_LValue,// Value kind + clang::OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + clang::ASTContext &context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *sizeOfLEQ16 = getSizeOfLEQ16Expr(context, NameLoc, T); + // TODO: add the '__builtin_hlsl_is_line_vector_layout_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T' + return sizeOfLEQ16; +} + +ConceptDecl *getTypedBufferConceptDecl(Sema &S) { + DeclContext *DC = S.CurContext; + clang::ASTContext &context = S.getASTContext(); + SourceLocation DeclLoc = SourceLocation(); + + IdentifierInfo &IsValidLineVectorII = + context.Idents.get("is_valid_line_vector"); + IdentifierInfo &ElementTypeII = context.Idents.get("element_type"); + clang::TemplateTypeParmDecl *T = clang::TemplateTypeParmDecl::Create( + context, context.getTranslationUnitDecl(), DeclLoc, DeclLoc, + /*depth=*/0, + /*position=*/0, + /*id=*/&ElementTypeII, + /*Typename=*/true, + /*ParameterPack=*/false); + + T->setDeclContext(DC); + T->setReferenced(); + + // Create and Attach Template Parameter List to ConceptDecl + std::vector TemplateParamsVec = {T}; + llvm::ArrayRef TemplateParams(TemplateParamsVec); + + clang::TemplateParameterList *ConceptParams = + clang::TemplateParameterList::Create(context, DeclLoc, DeclLoc, + TemplateParams, DeclLoc, nullptr); llvm-beanz wrote: ```suggestion clang::TemplateParameterList *ConceptParams = clang::TemplateParameterList::Create(context, DeclLoc, DeclLoc, {T}, DeclLoc, nullptr); ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,99 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - +Decl->setReferenced(); bob80905 wrote: This is an odd addition that I am not 100% convinced is absolutely necessary, although I haven't tried testing without it. I don't think it's a bugfix per se. The reason this line exists is because I am trying to match this AST as perfectly as possible, and it served as a guide throughout my development (Thanks to Chris): https://godbolt.org/z/Gq4hdTcrK The AST that is constructed in this PR is constructed *as if* the code in the godbolt link were defined and parsed somewhere, and the code in the link uses typename and is referenced. So, I set the appropriate decl as referenced, and make sure it's represented with a typename rather than a class. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/112600 >From 0739f6da81d7c1edd9578ae4ff9dd699e5c828c6 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 10 Oct 2024 14:31:25 -0700 Subject: [PATCH 01/13] ConceptSpecializationExpr shows up in AST!!! --- .../clang/Sema/HLSLExternalSemaSource.h | 2 + clang/lib/AST/DeclTemplate.cpp| 6 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 154 +- 3 files changed, 158 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h b/clang/include/clang/Sema/HLSLExternalSemaSource.h index 3c7495e66055dc..0266bc0f8b336e 100644 --- a/clang/include/clang/Sema/HLSLExternalSemaSource.h +++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h @@ -47,6 +47,8 @@ class HLSLExternalSemaSource : public ExternalSemaSource { using ExternalASTSource::CompleteType; /// Complete an incomplete HLSL builtin type void CompleteType(TagDecl *Tag) override; + + ConceptDecl *getTypedBufferConceptDecl(Sema &S, CXXRecordDecl *Decl); }; } // namespace clang diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 6fe817c5ef1c6b..2eae6d14718b86 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1080,10 +1080,10 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, DeclContext *DC, TemplateParameterList *Params, Expr *ConstraintExpr) { bool Invalid = AdoptTemplateParameterList(Params, DC); - auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); + auto *CD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); if (Invalid) -TD->setInvalidDecl(); - return TD; +CD->setInvalidDecl(); + return CD; } ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 2913d16fca4823..8104513857027c 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -304,6 +304,7 @@ struct BuiltinTypeDeclBuilder { TemplateParameterListBuilder addTemplateArgumentList(Sema &S); BuiltinTypeDeclBuilder &addSimpleTemplateParams(Sema &S, ArrayRef Names); + BuiltinTypeDeclBuilder &addConceptSpecializationExpr(Sema &S); }; struct TemplateParameterListBuilder { @@ -326,7 +327,8 @@ struct TemplateParameterListBuilder { SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), /* Typename */ false, -/* ParameterPack */ false); +/* ParameterPack */ false, +/* HasTypeConstraint*/ true); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), @@ -336,6 +338,152 @@ struct TemplateParameterListBuilder { return *this; } + Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { +clang::ASTContext &context = S.getASTContext(); +// Obtain the QualType for 'unsigned long' +clang::QualType unsignedLongType = context.UnsignedLongTy; + +// Create a QualType that points to this TemplateTypeParmDecl +clang::QualType TType = context.getTypeDeclType(T); + +// Create a TypeSourceInfo for the template type parameter 'T' +clang::TypeSourceInfo *TTypeSourceInfo = +context.getTrivialTypeSourceInfo(TType, NameLoc); + +clang::UnaryExprOrTypeTraitExpr *sizeofExpr = new (S.getASTContext()) +clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, +unsignedLongType, NameLoc, NameLoc); + +// Create an IntegerLiteral for the value '16' +llvm::APInt intValue(context.getIntWidth(context.IntTy), 4); +clang::IntegerLiteral *intLiteral = new (context) +clang::IntegerLiteral(context, intValue, context.IntTy, NameLoc); + +// Create an ImplicitCastExpr to cast 'int' to 'unsigned long' +FPOptionsOverride fpoo = FPOptionsOverride(); +clang::ImplicitCastExpr *implicitCastExpr = clang::ImplicitCastExpr::Create( +context, +unsignedLongType, // The type we are casting to (QualType for 'unsigned + // long') +clang::CK_IntegralCast, // CastKind (e.g., Integral cast) +intLiteral, // Sub-expression being cast +nullptr,// Base path, usually null for implicit casts +clang::VK_XValue, +fpoo // Value kind, typically VK_RValue for implicit casts +); + +clang::QualType BoolTy = context.BoolTy; + +clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( +context, sizeofExpr, // Left-hand side expression +
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -356,6 +426,9 @@ struct TemplateParameterListBuilder { QualType T = Builder.Template->getInjectedClassNameSpecialization(); T = S.Context.getInjectedClassNameType(Builder.Record, T); +ArrayRef TempArgs = +Builder.Template->getInjectedTemplateArgs(); pow2clk wrote: Unused variable `TempArgs`? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,99 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - +Decl->setReferenced(); Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + ConceptSpecializationExpr *getConceptSpecializationExpr(Sema &S, + ConceptDecl *CD) { +ASTContext &context = S.getASTContext(); +SourceLocation loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(loc, loc); + +// assume that the concept decl has just one template parameter +TemplateTypeParmDecl *ConceptTTPD = dyn_cast( +CD->getTemplateParameters()->getParam(0)); + +clang::TemplateTypeParmDecl *T = clang::TemplateTypeParmDecl::Create( damyanp wrote: I wonder if some psuedo-c++ code in a comment showing what this these AST nodes represent would help someone reading this? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,99 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - +Decl->setReferenced(); Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + ConceptSpecializationExpr *getConceptSpecializationExpr(Sema &S, + ConceptDecl *CD) { +ASTContext &context = S.getASTContext(); +SourceLocation loc = Builder.Record->getBeginLoc(); +DeclarationNameInfo DNI(CD->getDeclName(), loc); +NestedNameSpecifierLoc NNSLoc; +DeclContext *DC = Builder.Record->getDeclContext(); +TemplateArgumentListInfo TALI(loc, loc); + +// assume that the concept decl has just one template parameter damyanp wrote: Is this assumption something we capture in a simple assert? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,99 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - +Decl->setReferenced(); damyanp wrote: Is this a good bugfix we'd want independently of the concepts change? Or is this something that had to change because we're also using concepts now? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -1,64 +1,64 @@ -// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump -DEMPTY %s | FileCheck -check-prefix=EMPTY %s damyanp wrote: hmmmaybe a line endings change issue on this file? I'm wondering if some config in the root of this repo has changed since I've heard other people mention line endings getting messed up? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/damyanp commented: Some comments based on a quick read through: https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/damyanp edited https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -323,30 +324,99 @@ struct TemplateParameterListBuilder { S.Context, Builder.Record->getDeclContext(), SourceLocation(), SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), -/* Typename */ false, -/* ParameterPack */ false); +/* Typename */ true, +/* ParameterPack */ false, +/* HasTypeConstraint*/ false); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), SourceLocation())); - +Decl->setReferenced(); Params.emplace_back(Decl); return *this; } - BuiltinTypeDeclBuilder &finalizeTemplateArgs() { + ConceptSpecializationExpr *getConceptSpecializationExpr(Sema &S, + ConceptDecl *CD) { +ASTContext &context = S.getASTContext(); +SourceLocation loc = Builder.Record->getBeginLoc(); damyanp wrote: ```suggestion ASTContext &Context = S.getASTContext(); SourceLocation Loc = Builder.Record->getBeginLoc(); ``` https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -1078,10 +1078,10 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, DeclContext *DC, TemplateParameterList *Params, Expr *ConstraintExpr) { bool Invalid = AdoptTemplateParameterList(Params, DC); - auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); + auto *CD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); if (Invalid) -TD->setInvalidDecl(); - return TD; +CD->setInvalidDecl(); + return CD; damyanp wrote: This seems like a NFC change in DeclTemplate? Might be better to pull this out into a separate PR. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +554,109 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *getSizeOfLEQ16Expr(clang::ASTContext &context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + clang::QualType unsignedLongType = context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + clang::QualType TType = context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + clang::TypeSourceInfo *TTypeSourceInfo = + context.getTrivialTypeSourceInfo(TType, NameLoc); + + clang::UnaryExprOrTypeTraitExpr *sizeOfExpr = new (context) + clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, + unsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + clang::QualType sizeType = context.getSizeType(); + llvm::APInt sizeValue = llvm::APInt(context.getTypeSize(sizeType), 16); + clang::IntegerLiteral *sizeLiteral = new (context) + clang::IntegerLiteral(context, sizeValue, sizeType, NameLoc); + + clang::QualType BoolTy = context.BoolTy; + + clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( + context, sizeOfExpr, // Left-hand side expression + sizeLiteral, // Right-hand side expression + clang::BO_LE,// Binary operator kind (<=) + BoolTy, // Result type (bool) + clang::VK_LValue,// Value kind + clang::OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + clang::ASTContext &context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *sizeOfLEQ16 = getSizeOfLEQ16Expr(context, NameLoc, T); + // TODO: add the '__builtin_hlsl_is_line_vector_layout_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T' + return sizeOfLEQ16; +} + +ConceptDecl *getTypedBufferConceptDecl(Sema &S) { + DeclContext *DC = S.CurContext; + clang::ASTContext &context = S.getASTContext(); + SourceLocation DeclLoc = SourceLocation(); + + IdentifierInfo &IsValidLineVectorII = + context.Idents.get("is_valid_line_vector"); + IdentifierInfo &ElementTypeII = context.Idents.get("element_type"); + clang::TemplateTypeParmDecl *T = clang::TemplateTypeParmDecl::Create( + context, context.getTranslationUnitDecl(), DeclLoc, DeclLoc, + /*depth=*/0, + /*position=*/0, + /*id=*/&ElementTypeII, + /*Typename=*/true, + /*ParameterPack=*/false); + + T->setDeclContext(DC); + T->setReferenced(); + + // Create and Attach Template Parameter List to ConceptDecl + llvm::ArrayRef TemplateParams = {T}; + clang::TemplateParameterList *ConceptParams = + clang::TemplateParameterList::Create(context, DeclLoc, DeclLoc, + TemplateParams, DeclLoc, nullptr); + + DeclarationName DeclName = DeclarationName(&IsValidLineVectorII); + Expr *ConstraintExpr = getTypedBufferConstraintExpr(S, DeclLoc, T); + + // Create a ConceptDecl + clang::ConceptDecl *conceptDecl = clang::ConceptDecl::Create( + context, + context.getTranslationUnitDecl(), // DeclContext + DeclLoc, // Source location of start of concept + DeclName, // Source location of end of concept + ConceptParams,// Template type parameter + ConstraintExpr// Expression defining the concept damyanp wrote: Yeah, it spotted something questionable, but the suggested fix was worse! https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/112600 >From 0739f6da81d7c1edd9578ae4ff9dd699e5c828c6 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 10 Oct 2024 14:31:25 -0700 Subject: [PATCH 01/12] ConceptSpecializationExpr shows up in AST!!! --- .../clang/Sema/HLSLExternalSemaSource.h | 2 + clang/lib/AST/DeclTemplate.cpp| 6 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 154 +- 3 files changed, 158 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h b/clang/include/clang/Sema/HLSLExternalSemaSource.h index 3c7495e66055dc..0266bc0f8b336e 100644 --- a/clang/include/clang/Sema/HLSLExternalSemaSource.h +++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h @@ -47,6 +47,8 @@ class HLSLExternalSemaSource : public ExternalSemaSource { using ExternalASTSource::CompleteType; /// Complete an incomplete HLSL builtin type void CompleteType(TagDecl *Tag) override; + + ConceptDecl *getTypedBufferConceptDecl(Sema &S, CXXRecordDecl *Decl); }; } // namespace clang diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 6fe817c5ef1c6b..2eae6d14718b86 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1080,10 +1080,10 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, DeclContext *DC, TemplateParameterList *Params, Expr *ConstraintExpr) { bool Invalid = AdoptTemplateParameterList(Params, DC); - auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); + auto *CD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); if (Invalid) -TD->setInvalidDecl(); - return TD; +CD->setInvalidDecl(); + return CD; } ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 2913d16fca4823..8104513857027c 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -304,6 +304,7 @@ struct BuiltinTypeDeclBuilder { TemplateParameterListBuilder addTemplateArgumentList(Sema &S); BuiltinTypeDeclBuilder &addSimpleTemplateParams(Sema &S, ArrayRef Names); + BuiltinTypeDeclBuilder &addConceptSpecializationExpr(Sema &S); }; struct TemplateParameterListBuilder { @@ -326,7 +327,8 @@ struct TemplateParameterListBuilder { SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), /* Typename */ false, -/* ParameterPack */ false); +/* ParameterPack */ false, +/* HasTypeConstraint*/ true); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), @@ -336,6 +338,152 @@ struct TemplateParameterListBuilder { return *this; } + Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { +clang::ASTContext &context = S.getASTContext(); +// Obtain the QualType for 'unsigned long' +clang::QualType unsignedLongType = context.UnsignedLongTy; + +// Create a QualType that points to this TemplateTypeParmDecl +clang::QualType TType = context.getTypeDeclType(T); + +// Create a TypeSourceInfo for the template type parameter 'T' +clang::TypeSourceInfo *TTypeSourceInfo = +context.getTrivialTypeSourceInfo(TType, NameLoc); + +clang::UnaryExprOrTypeTraitExpr *sizeofExpr = new (S.getASTContext()) +clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, +unsignedLongType, NameLoc, NameLoc); + +// Create an IntegerLiteral for the value '16' +llvm::APInt intValue(context.getIntWidth(context.IntTy), 4); +clang::IntegerLiteral *intLiteral = new (context) +clang::IntegerLiteral(context, intValue, context.IntTy, NameLoc); + +// Create an ImplicitCastExpr to cast 'int' to 'unsigned long' +FPOptionsOverride fpoo = FPOptionsOverride(); +clang::ImplicitCastExpr *implicitCastExpr = clang::ImplicitCastExpr::Create( +context, +unsignedLongType, // The type we are casting to (QualType for 'unsigned + // long') +clang::CK_IntegralCast, // CastKind (e.g., Integral cast) +intLiteral, // Sub-expression being cast +nullptr,// Base path, usually null for implicit casts +clang::VK_XValue, +fpoo // Value kind, typically VK_RValue for implicit casts +); + +clang::QualType BoolTy = context.BoolTy; + +clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( +context, sizeofExpr, // Left-hand side expression +
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +554,109 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *getSizeOfLEQ16Expr(clang::ASTContext &context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + clang::QualType unsignedLongType = context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + clang::QualType TType = context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + clang::TypeSourceInfo *TTypeSourceInfo = + context.getTrivialTypeSourceInfo(TType, NameLoc); + + clang::UnaryExprOrTypeTraitExpr *sizeOfExpr = new (context) + clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, + unsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + clang::QualType sizeType = context.getSizeType(); + llvm::APInt sizeValue = llvm::APInt(context.getTypeSize(sizeType), 16); + clang::IntegerLiteral *sizeLiteral = new (context) + clang::IntegerLiteral(context, sizeValue, sizeType, NameLoc); + + clang::QualType BoolTy = context.BoolTy; + + clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( + context, sizeOfExpr, // Left-hand side expression + sizeLiteral, // Right-hand side expression + clang::BO_LE,// Binary operator kind (<=) + BoolTy, // Result type (bool) + clang::VK_LValue,// Value kind + clang::OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + clang::ASTContext &context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *sizeOfLEQ16 = getSizeOfLEQ16Expr(context, NameLoc, T); + // TODO: add the '__builtin_hlsl_is_line_vector_layout_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T' + return sizeOfLEQ16; +} + +ConceptDecl *getTypedBufferConceptDecl(Sema &S) { + DeclContext *DC = S.CurContext; + clang::ASTContext &context = S.getASTContext(); + SourceLocation DeclLoc = SourceLocation(); + + IdentifierInfo &IsValidLineVectorII = + context.Idents.get("is_valid_line_vector"); + IdentifierInfo &ElementTypeII = context.Idents.get("element_type"); + clang::TemplateTypeParmDecl *T = clang::TemplateTypeParmDecl::Create( + context, context.getTranslationUnitDecl(), DeclLoc, DeclLoc, + /*depth=*/0, + /*position=*/0, + /*id=*/&ElementTypeII, + /*Typename=*/true, + /*ParameterPack=*/false); + + T->setDeclContext(DC); + T->setReferenced(); + + // Create and Attach Template Parameter List to ConceptDecl + llvm::ArrayRef TemplateParams = {T}; + clang::TemplateParameterList *ConceptParams = + clang::TemplateParameterList::Create(context, DeclLoc, DeclLoc, + TemplateParams, DeclLoc, nullptr); + + DeclarationName DeclName = DeclarationName(&IsValidLineVectorII); + Expr *ConstraintExpr = getTypedBufferConstraintExpr(S, DeclLoc, T); + + // Create a ConceptDecl + clang::ConceptDecl *conceptDecl = clang::ConceptDecl::Create( + context, + context.getTranslationUnitDecl(), // DeclContext + DeclLoc, // Source location of start of concept + DeclName, // Source location of end of concept + ConceptParams,// Template type parameter + ConstraintExpr// Expression defining the concept bob80905 wrote: This is no longer the latest version of the file. But the reason I disagreed is because, the Create function does not take that many arguments. An extra argument was added when it shouldn't have been. I've removed the comments. https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/112600 >From 0739f6da81d7c1edd9578ae4ff9dd699e5c828c6 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 10 Oct 2024 14:31:25 -0700 Subject: [PATCH 01/11] ConceptSpecializationExpr shows up in AST!!! --- .../clang/Sema/HLSLExternalSemaSource.h | 2 + clang/lib/AST/DeclTemplate.cpp| 6 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 154 +- 3 files changed, 158 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h b/clang/include/clang/Sema/HLSLExternalSemaSource.h index 3c7495e66055dc..0266bc0f8b336e 100644 --- a/clang/include/clang/Sema/HLSLExternalSemaSource.h +++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h @@ -47,6 +47,8 @@ class HLSLExternalSemaSource : public ExternalSemaSource { using ExternalASTSource::CompleteType; /// Complete an incomplete HLSL builtin type void CompleteType(TagDecl *Tag) override; + + ConceptDecl *getTypedBufferConceptDecl(Sema &S, CXXRecordDecl *Decl); }; } // namespace clang diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 6fe817c5ef1c6b..2eae6d14718b86 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1080,10 +1080,10 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, DeclContext *DC, TemplateParameterList *Params, Expr *ConstraintExpr) { bool Invalid = AdoptTemplateParameterList(Params, DC); - auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); + auto *CD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); if (Invalid) -TD->setInvalidDecl(); - return TD; +CD->setInvalidDecl(); + return CD; } ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 2913d16fca4823..8104513857027c 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -304,6 +304,7 @@ struct BuiltinTypeDeclBuilder { TemplateParameterListBuilder addTemplateArgumentList(Sema &S); BuiltinTypeDeclBuilder &addSimpleTemplateParams(Sema &S, ArrayRef Names); + BuiltinTypeDeclBuilder &addConceptSpecializationExpr(Sema &S); }; struct TemplateParameterListBuilder { @@ -326,7 +327,8 @@ struct TemplateParameterListBuilder { SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), /* Typename */ false, -/* ParameterPack */ false); +/* ParameterPack */ false, +/* HasTypeConstraint*/ true); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), @@ -336,6 +338,152 @@ struct TemplateParameterListBuilder { return *this; } + Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { +clang::ASTContext &context = S.getASTContext(); +// Obtain the QualType for 'unsigned long' +clang::QualType unsignedLongType = context.UnsignedLongTy; + +// Create a QualType that points to this TemplateTypeParmDecl +clang::QualType TType = context.getTypeDeclType(T); + +// Create a TypeSourceInfo for the template type parameter 'T' +clang::TypeSourceInfo *TTypeSourceInfo = +context.getTrivialTypeSourceInfo(TType, NameLoc); + +clang::UnaryExprOrTypeTraitExpr *sizeofExpr = new (S.getASTContext()) +clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, +unsignedLongType, NameLoc, NameLoc); + +// Create an IntegerLiteral for the value '16' +llvm::APInt intValue(context.getIntWidth(context.IntTy), 4); +clang::IntegerLiteral *intLiteral = new (context) +clang::IntegerLiteral(context, intValue, context.IntTy, NameLoc); + +// Create an ImplicitCastExpr to cast 'int' to 'unsigned long' +FPOptionsOverride fpoo = FPOptionsOverride(); +clang::ImplicitCastExpr *implicitCastExpr = clang::ImplicitCastExpr::Create( +context, +unsignedLongType, // The type we are casting to (QualType for 'unsigned + // long') +clang::CK_IntegralCast, // CastKind (e.g., Integral cast) +intLiteral, // Sub-expression being cast +nullptr,// Base path, usually null for implicit casts +clang::VK_XValue, +fpoo // Value kind, typically VK_RValue for implicit casts +); + +clang::QualType BoolTy = context.BoolTy; + +clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( +context, sizeofExpr, // Left-hand side expression +
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +554,109 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *getSizeOfLEQ16Expr(clang::ASTContext &context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + clang::QualType unsignedLongType = context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + clang::QualType TType = context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + clang::TypeSourceInfo *TTypeSourceInfo = + context.getTrivialTypeSourceInfo(TType, NameLoc); + + clang::UnaryExprOrTypeTraitExpr *sizeOfExpr = new (context) + clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, + unsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + clang::QualType sizeType = context.getSizeType(); + llvm::APInt sizeValue = llvm::APInt(context.getTypeSize(sizeType), 16); + clang::IntegerLiteral *sizeLiteral = new (context) + clang::IntegerLiteral(context, sizeValue, sizeType, NameLoc); + + clang::QualType BoolTy = context.BoolTy; + + clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( + context, sizeOfExpr, // Left-hand side expression + sizeLiteral, // Right-hand side expression + clang::BO_LE,// Binary operator kind (<=) + BoolTy, // Result type (bool) + clang::VK_LValue,// Value kind + clang::OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + clang::ASTContext &context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *sizeOfLEQ16 = getSizeOfLEQ16Expr(context, NameLoc, T); + // TODO: add the '__builtin_hlsl_is_line_vector_layout_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T' + return sizeOfLEQ16; +} + +ConceptDecl *getTypedBufferConceptDecl(Sema &S) { + DeclContext *DC = S.CurContext; + clang::ASTContext &context = S.getASTContext(); + SourceLocation DeclLoc = SourceLocation(); + + IdentifierInfo &IsValidLineVectorII = + context.Idents.get("is_valid_line_vector"); + IdentifierInfo &ElementTypeII = context.Idents.get("element_type"); + clang::TemplateTypeParmDecl *T = clang::TemplateTypeParmDecl::Create( + context, context.getTranslationUnitDecl(), DeclLoc, DeclLoc, + /*depth=*/0, + /*position=*/0, + /*id=*/&ElementTypeII, + /*Typename=*/true, + /*ParameterPack=*/false); + + T->setDeclContext(DC); + T->setReferenced(); + + // Create and Attach Template Parameter List to ConceptDecl + llvm::ArrayRef TemplateParams = {T}; + clang::TemplateParameterList *ConceptParams = + clang::TemplateParameterList::Create(context, DeclLoc, DeclLoc, + TemplateParams, DeclLoc, nullptr); + + DeclarationName DeclName = DeclarationName(&IsValidLineVectorII); + Expr *ConstraintExpr = getTypedBufferConstraintExpr(S, DeclLoc, T); + + // Create a ConceptDecl + clang::ConceptDecl *conceptDecl = clang::ConceptDecl::Create( + context, + context.getTranslationUnitDecl(), // DeclContext + DeclLoc, // Source location of start of concept + DeclName, // Source location of end of concept + ConceptParams,// Template type parameter + ConstraintExpr// Expression defining the concept damyanp wrote: Looks like the comment next to `DeclName` is incorrect though? https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 ready_for_review https://github.com/llvm/llvm-project/pull/112600 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/112600 >From 0739f6da81d7c1edd9578ae4ff9dd699e5c828c6 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 10 Oct 2024 14:31:25 -0700 Subject: [PATCH 01/11] ConceptSpecializationExpr shows up in AST!!! --- .../clang/Sema/HLSLExternalSemaSource.h | 2 + clang/lib/AST/DeclTemplate.cpp| 6 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 154 +- 3 files changed, 158 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h b/clang/include/clang/Sema/HLSLExternalSemaSource.h index 3c7495e66055dc..0266bc0f8b336e 100644 --- a/clang/include/clang/Sema/HLSLExternalSemaSource.h +++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h @@ -47,6 +47,8 @@ class HLSLExternalSemaSource : public ExternalSemaSource { using ExternalASTSource::CompleteType; /// Complete an incomplete HLSL builtin type void CompleteType(TagDecl *Tag) override; + + ConceptDecl *getTypedBufferConceptDecl(Sema &S, CXXRecordDecl *Decl); }; } // namespace clang diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 6fe817c5ef1c6b..2eae6d14718b86 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1080,10 +1080,10 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, DeclContext *DC, TemplateParameterList *Params, Expr *ConstraintExpr) { bool Invalid = AdoptTemplateParameterList(Params, DC); - auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); + auto *CD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); if (Invalid) -TD->setInvalidDecl(); - return TD; +CD->setInvalidDecl(); + return CD; } ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 2913d16fca4823..8104513857027c 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -304,6 +304,7 @@ struct BuiltinTypeDeclBuilder { TemplateParameterListBuilder addTemplateArgumentList(Sema &S); BuiltinTypeDeclBuilder &addSimpleTemplateParams(Sema &S, ArrayRef Names); + BuiltinTypeDeclBuilder &addConceptSpecializationExpr(Sema &S); }; struct TemplateParameterListBuilder { @@ -326,7 +327,8 @@ struct TemplateParameterListBuilder { SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), /* Typename */ false, -/* ParameterPack */ false); +/* ParameterPack */ false, +/* HasTypeConstraint*/ true); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), @@ -336,6 +338,152 @@ struct TemplateParameterListBuilder { return *this; } + Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { +clang::ASTContext &context = S.getASTContext(); +// Obtain the QualType for 'unsigned long' +clang::QualType unsignedLongType = context.UnsignedLongTy; + +// Create a QualType that points to this TemplateTypeParmDecl +clang::QualType TType = context.getTypeDeclType(T); + +// Create a TypeSourceInfo for the template type parameter 'T' +clang::TypeSourceInfo *TTypeSourceInfo = +context.getTrivialTypeSourceInfo(TType, NameLoc); + +clang::UnaryExprOrTypeTraitExpr *sizeofExpr = new (S.getASTContext()) +clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, +unsignedLongType, NameLoc, NameLoc); + +// Create an IntegerLiteral for the value '16' +llvm::APInt intValue(context.getIntWidth(context.IntTy), 4); +clang::IntegerLiteral *intLiteral = new (context) +clang::IntegerLiteral(context, intValue, context.IntTy, NameLoc); + +// Create an ImplicitCastExpr to cast 'int' to 'unsigned long' +FPOptionsOverride fpoo = FPOptionsOverride(); +clang::ImplicitCastExpr *implicitCastExpr = clang::ImplicitCastExpr::Create( +context, +unsignedLongType, // The type we are casting to (QualType for 'unsigned + // long') +clang::CK_IntegralCast, // CastKind (e.g., Integral cast) +intLiteral, // Sub-expression being cast +nullptr,// Base path, usually null for implicit casts +clang::VK_XValue, +fpoo // Value kind, typically VK_RValue for implicit casts +); + +clang::QualType BoolTy = context.BoolTy; + +clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( +context, sizeofExpr, // Left-hand side expression +
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/112600 >From 0739f6da81d7c1edd9578ae4ff9dd699e5c828c6 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 10 Oct 2024 14:31:25 -0700 Subject: [PATCH 01/11] ConceptSpecializationExpr shows up in AST!!! --- .../clang/Sema/HLSLExternalSemaSource.h | 2 + clang/lib/AST/DeclTemplate.cpp| 6 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 154 +- 3 files changed, 158 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h b/clang/include/clang/Sema/HLSLExternalSemaSource.h index 3c7495e66055dc..0266bc0f8b336e 100644 --- a/clang/include/clang/Sema/HLSLExternalSemaSource.h +++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h @@ -47,6 +47,8 @@ class HLSLExternalSemaSource : public ExternalSemaSource { using ExternalASTSource::CompleteType; /// Complete an incomplete HLSL builtin type void CompleteType(TagDecl *Tag) override; + + ConceptDecl *getTypedBufferConceptDecl(Sema &S, CXXRecordDecl *Decl); }; } // namespace clang diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 6fe817c5ef1c6b..2eae6d14718b86 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1080,10 +1080,10 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, DeclContext *DC, TemplateParameterList *Params, Expr *ConstraintExpr) { bool Invalid = AdoptTemplateParameterList(Params, DC); - auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); + auto *CD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); if (Invalid) -TD->setInvalidDecl(); - return TD; +CD->setInvalidDecl(); + return CD; } ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 2913d16fca4823..8104513857027c 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -304,6 +304,7 @@ struct BuiltinTypeDeclBuilder { TemplateParameterListBuilder addTemplateArgumentList(Sema &S); BuiltinTypeDeclBuilder &addSimpleTemplateParams(Sema &S, ArrayRef Names); + BuiltinTypeDeclBuilder &addConceptSpecializationExpr(Sema &S); }; struct TemplateParameterListBuilder { @@ -326,7 +327,8 @@ struct TemplateParameterListBuilder { SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), /* Typename */ false, -/* ParameterPack */ false); +/* ParameterPack */ false, +/* HasTypeConstraint*/ true); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), @@ -336,6 +338,152 @@ struct TemplateParameterListBuilder { return *this; } + Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { +clang::ASTContext &context = S.getASTContext(); +// Obtain the QualType for 'unsigned long' +clang::QualType unsignedLongType = context.UnsignedLongTy; + +// Create a QualType that points to this TemplateTypeParmDecl +clang::QualType TType = context.getTypeDeclType(T); + +// Create a TypeSourceInfo for the template type parameter 'T' +clang::TypeSourceInfo *TTypeSourceInfo = +context.getTrivialTypeSourceInfo(TType, NameLoc); + +clang::UnaryExprOrTypeTraitExpr *sizeofExpr = new (S.getASTContext()) +clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, +unsignedLongType, NameLoc, NameLoc); + +// Create an IntegerLiteral for the value '16' +llvm::APInt intValue(context.getIntWidth(context.IntTy), 4); +clang::IntegerLiteral *intLiteral = new (context) +clang::IntegerLiteral(context, intValue, context.IntTy, NameLoc); + +// Create an ImplicitCastExpr to cast 'int' to 'unsigned long' +FPOptionsOverride fpoo = FPOptionsOverride(); +clang::ImplicitCastExpr *implicitCastExpr = clang::ImplicitCastExpr::Create( +context, +unsignedLongType, // The type we are casting to (QualType for 'unsigned + // long') +clang::CK_IntegralCast, // CastKind (e.g., Integral cast) +intLiteral, // Sub-expression being cast +nullptr,// Base path, usually null for implicit casts +clang::VK_XValue, +fpoo // Value kind, typically VK_RValue for implicit casts +); + +clang::QualType BoolTy = context.BoolTy; + +clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( +context, sizeofExpr, // Left-hand side expression +
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
@@ -483,10 +554,109 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S, .addDefaultHandleConstructor(S, RC); } +BinaryOperator *getSizeOfLEQ16Expr(clang::ASTContext &context, + SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + // Obtain the QualType for 'unsigned long' + clang::QualType unsignedLongType = context.UnsignedLongTy; + + // Create a QualType that points to this TemplateTypeParmDecl + clang::QualType TType = context.getTypeDeclType(T); + + // Create a TypeSourceInfo for the template type parameter 'T' + clang::TypeSourceInfo *TTypeSourceInfo = + context.getTrivialTypeSourceInfo(TType, NameLoc); + + clang::UnaryExprOrTypeTraitExpr *sizeOfExpr = new (context) + clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, + unsignedLongType, NameLoc, NameLoc); + + // Create an IntegerLiteral for the value '16' with size type + clang::QualType sizeType = context.getSizeType(); + llvm::APInt sizeValue = llvm::APInt(context.getTypeSize(sizeType), 16); + clang::IntegerLiteral *sizeLiteral = new (context) + clang::IntegerLiteral(context, sizeValue, sizeType, NameLoc); + + clang::QualType BoolTy = context.BoolTy; + + clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( + context, sizeOfExpr, // Left-hand side expression + sizeLiteral, // Right-hand side expression + clang::BO_LE,// Binary operator kind (<=) + BoolTy, // Result type (bool) + clang::VK_LValue,// Value kind + clang::OK_Ordinary, // Object kind + NameLoc, // Source location of operator + FPOptionsOverride()); + + return binaryOperator; +} + +Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { + clang::ASTContext &context = S.getASTContext(); + + // first get the "sizeof(T) <= 16" expression, as a binary operator + BinaryOperator *sizeOfLEQ16 = getSizeOfLEQ16Expr(context, NameLoc, T); + // TODO: add the '__builtin_hlsl_is_line_vector_layout_compatible' builtin + // and return a binary operator that evaluates the builtin on the given + // template type parameter 'T' + return sizeOfLEQ16; +} + +ConceptDecl *getTypedBufferConceptDecl(Sema &S) { + DeclContext *DC = S.CurContext; + clang::ASTContext &context = S.getASTContext(); + SourceLocation DeclLoc = SourceLocation(); + + IdentifierInfo &IsValidLineVectorII = + context.Idents.get("is_valid_line_vector"); + IdentifierInfo &ElementTypeII = context.Idents.get("element_type"); + clang::TemplateTypeParmDecl *T = clang::TemplateTypeParmDecl::Create( + context, context.getTranslationUnitDecl(), DeclLoc, DeclLoc, + /*depth=*/0, + /*position=*/0, + /*id=*/&ElementTypeII, + /*Typename=*/true, + /*ParameterPack=*/false); + + T->setDeclContext(DC); + T->setReferenced(); + + // Create and Attach Template Parameter List to ConceptDecl + llvm::ArrayRef TemplateParams = {T}; + clang::TemplateParameterList *ConceptParams = + clang::TemplateParameterList::Create(context, DeclLoc, DeclLoc, + TemplateParams, DeclLoc, nullptr); + + DeclarationName DeclName = DeclarationName(&IsValidLineVectorII); + Expr *ConstraintExpr = getTypedBufferConstraintExpr(S, DeclLoc, T); + + // Create a ConceptDecl + clang::ConceptDecl *conceptDecl = clang::ConceptDecl::Create( + context, + context.getTranslationUnitDecl(), // DeclContext + DeclLoc, // Source location of start of concept + DeclName, // Source location of end of concept + ConceptParams,// Template type parameter + ConstraintExpr// Expression defining the concept graphite-app[bot] wrote: The `DeclName` parameter is incorrectly used as the location in the `ConceptDecl::Create` call. To fix this, replace `DeclName` with `DeclLoc` for the location parameter, and use `DeclName` as the name parameter. Here's the corrected code: ```cpp clang::ConceptDecl *conceptDecl = clang::ConceptDecl::Create( context, context.getTranslationUnitDecl(), // DeclContext DeclLoc, // Source location of start of concept DeclLoc, // Source location of end of concept DeclName, // Name of the concept ConceptParams,// Template type parameter ConstraintExpr// Expression defining the concept ); ``` This change ensures that the concept declaration is created with the correct location and name parameters. *Spotted by [Graphite Reviewer](https://app.graphite.dev/graphite-reviewer/?org=llvm&ref=ai-review-comment)*Is this helpful? React 👍 or 👎 t
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/112600 >From 0739f6da81d7c1edd9578ae4ff9dd699e5c828c6 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 10 Oct 2024 14:31:25 -0700 Subject: [PATCH 01/10] ConceptSpecializationExpr shows up in AST!!! --- .../clang/Sema/HLSLExternalSemaSource.h | 2 + clang/lib/AST/DeclTemplate.cpp| 6 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 154 +- 3 files changed, 158 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h b/clang/include/clang/Sema/HLSLExternalSemaSource.h index 3c7495e66055dc..0266bc0f8b336e 100644 --- a/clang/include/clang/Sema/HLSLExternalSemaSource.h +++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h @@ -47,6 +47,8 @@ class HLSLExternalSemaSource : public ExternalSemaSource { using ExternalASTSource::CompleteType; /// Complete an incomplete HLSL builtin type void CompleteType(TagDecl *Tag) override; + + ConceptDecl *getTypedBufferConceptDecl(Sema &S, CXXRecordDecl *Decl); }; } // namespace clang diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 6fe817c5ef1c6b..2eae6d14718b86 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1080,10 +1080,10 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, DeclContext *DC, TemplateParameterList *Params, Expr *ConstraintExpr) { bool Invalid = AdoptTemplateParameterList(Params, DC); - auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); + auto *CD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); if (Invalid) -TD->setInvalidDecl(); - return TD; +CD->setInvalidDecl(); + return CD; } ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 2913d16fca4823..8104513857027c 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -304,6 +304,7 @@ struct BuiltinTypeDeclBuilder { TemplateParameterListBuilder addTemplateArgumentList(Sema &S); BuiltinTypeDeclBuilder &addSimpleTemplateParams(Sema &S, ArrayRef Names); + BuiltinTypeDeclBuilder &addConceptSpecializationExpr(Sema &S); }; struct TemplateParameterListBuilder { @@ -326,7 +327,8 @@ struct TemplateParameterListBuilder { SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), /* Typename */ false, -/* ParameterPack */ false); +/* ParameterPack */ false, +/* HasTypeConstraint*/ true); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), @@ -336,6 +338,152 @@ struct TemplateParameterListBuilder { return *this; } + Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { +clang::ASTContext &context = S.getASTContext(); +// Obtain the QualType for 'unsigned long' +clang::QualType unsignedLongType = context.UnsignedLongTy; + +// Create a QualType that points to this TemplateTypeParmDecl +clang::QualType TType = context.getTypeDeclType(T); + +// Create a TypeSourceInfo for the template type parameter 'T' +clang::TypeSourceInfo *TTypeSourceInfo = +context.getTrivialTypeSourceInfo(TType, NameLoc); + +clang::UnaryExprOrTypeTraitExpr *sizeofExpr = new (S.getASTContext()) +clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, +unsignedLongType, NameLoc, NameLoc); + +// Create an IntegerLiteral for the value '16' +llvm::APInt intValue(context.getIntWidth(context.IntTy), 4); +clang::IntegerLiteral *intLiteral = new (context) +clang::IntegerLiteral(context, intValue, context.IntTy, NameLoc); + +// Create an ImplicitCastExpr to cast 'int' to 'unsigned long' +FPOptionsOverride fpoo = FPOptionsOverride(); +clang::ImplicitCastExpr *implicitCastExpr = clang::ImplicitCastExpr::Create( +context, +unsignedLongType, // The type we are casting to (QualType for 'unsigned + // long') +clang::CK_IntegralCast, // CastKind (e.g., Integral cast) +intLiteral, // Sub-expression being cast +nullptr,// Base path, usually null for implicit casts +clang::VK_XValue, +fpoo // Value kind, typically VK_RValue for implicit casts +); + +clang::QualType BoolTy = context.BoolTy; + +clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( +context, sizeofExpr, // Left-hand side expression +
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/112600 >From 0739f6da81d7c1edd9578ae4ff9dd699e5c828c6 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 10 Oct 2024 14:31:25 -0700 Subject: [PATCH 1/8] ConceptSpecializationExpr shows up in AST!!! --- .../clang/Sema/HLSLExternalSemaSource.h | 2 + clang/lib/AST/DeclTemplate.cpp| 6 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 154 +- 3 files changed, 158 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h b/clang/include/clang/Sema/HLSLExternalSemaSource.h index 3c7495e66055dc..0266bc0f8b336e 100644 --- a/clang/include/clang/Sema/HLSLExternalSemaSource.h +++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h @@ -47,6 +47,8 @@ class HLSLExternalSemaSource : public ExternalSemaSource { using ExternalASTSource::CompleteType; /// Complete an incomplete HLSL builtin type void CompleteType(TagDecl *Tag) override; + + ConceptDecl *getTypedBufferConceptDecl(Sema &S, CXXRecordDecl *Decl); }; } // namespace clang diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 6fe817c5ef1c6b..2eae6d14718b86 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1080,10 +1080,10 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, DeclContext *DC, TemplateParameterList *Params, Expr *ConstraintExpr) { bool Invalid = AdoptTemplateParameterList(Params, DC); - auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); + auto *CD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); if (Invalid) -TD->setInvalidDecl(); - return TD; +CD->setInvalidDecl(); + return CD; } ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 2913d16fca4823..8104513857027c 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -304,6 +304,7 @@ struct BuiltinTypeDeclBuilder { TemplateParameterListBuilder addTemplateArgumentList(Sema &S); BuiltinTypeDeclBuilder &addSimpleTemplateParams(Sema &S, ArrayRef Names); + BuiltinTypeDeclBuilder &addConceptSpecializationExpr(Sema &S); }; struct TemplateParameterListBuilder { @@ -326,7 +327,8 @@ struct TemplateParameterListBuilder { SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), /* Typename */ false, -/* ParameterPack */ false); +/* ParameterPack */ false, +/* HasTypeConstraint*/ true); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), @@ -336,6 +338,152 @@ struct TemplateParameterListBuilder { return *this; } + Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { +clang::ASTContext &context = S.getASTContext(); +// Obtain the QualType for 'unsigned long' +clang::QualType unsignedLongType = context.UnsignedLongTy; + +// Create a QualType that points to this TemplateTypeParmDecl +clang::QualType TType = context.getTypeDeclType(T); + +// Create a TypeSourceInfo for the template type parameter 'T' +clang::TypeSourceInfo *TTypeSourceInfo = +context.getTrivialTypeSourceInfo(TType, NameLoc); + +clang::UnaryExprOrTypeTraitExpr *sizeofExpr = new (S.getASTContext()) +clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, +unsignedLongType, NameLoc, NameLoc); + +// Create an IntegerLiteral for the value '16' +llvm::APInt intValue(context.getIntWidth(context.IntTy), 4); +clang::IntegerLiteral *intLiteral = new (context) +clang::IntegerLiteral(context, intValue, context.IntTy, NameLoc); + +// Create an ImplicitCastExpr to cast 'int' to 'unsigned long' +FPOptionsOverride fpoo = FPOptionsOverride(); +clang::ImplicitCastExpr *implicitCastExpr = clang::ImplicitCastExpr::Create( +context, +unsignedLongType, // The type we are casting to (QualType for 'unsigned + // long') +clang::CK_IntegralCast, // CastKind (e.g., Integral cast) +intLiteral, // Sub-expression being cast +nullptr,// Base path, usually null for implicit casts +clang::VK_XValue, +fpoo // Value kind, typically VK_RValue for implicit casts +); + +clang::QualType BoolTy = context.BoolTy; + +clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( +context, sizeofExpr, // Left-hand side expression +
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/112600 >From 0739f6da81d7c1edd9578ae4ff9dd699e5c828c6 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 10 Oct 2024 14:31:25 -0700 Subject: [PATCH 1/7] ConceptSpecializationExpr shows up in AST!!! --- .../clang/Sema/HLSLExternalSemaSource.h | 2 + clang/lib/AST/DeclTemplate.cpp| 6 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 154 +- 3 files changed, 158 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h b/clang/include/clang/Sema/HLSLExternalSemaSource.h index 3c7495e66055dc..0266bc0f8b336e 100644 --- a/clang/include/clang/Sema/HLSLExternalSemaSource.h +++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h @@ -47,6 +47,8 @@ class HLSLExternalSemaSource : public ExternalSemaSource { using ExternalASTSource::CompleteType; /// Complete an incomplete HLSL builtin type void CompleteType(TagDecl *Tag) override; + + ConceptDecl *getTypedBufferConceptDecl(Sema &S, CXXRecordDecl *Decl); }; } // namespace clang diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 6fe817c5ef1c6b..2eae6d14718b86 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1080,10 +1080,10 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, DeclContext *DC, TemplateParameterList *Params, Expr *ConstraintExpr) { bool Invalid = AdoptTemplateParameterList(Params, DC); - auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); + auto *CD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); if (Invalid) -TD->setInvalidDecl(); - return TD; +CD->setInvalidDecl(); + return CD; } ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 2913d16fca4823..8104513857027c 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -304,6 +304,7 @@ struct BuiltinTypeDeclBuilder { TemplateParameterListBuilder addTemplateArgumentList(Sema &S); BuiltinTypeDeclBuilder &addSimpleTemplateParams(Sema &S, ArrayRef Names); + BuiltinTypeDeclBuilder &addConceptSpecializationExpr(Sema &S); }; struct TemplateParameterListBuilder { @@ -326,7 +327,8 @@ struct TemplateParameterListBuilder { SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), /* Typename */ false, -/* ParameterPack */ false); +/* ParameterPack */ false, +/* HasTypeConstraint*/ true); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), @@ -336,6 +338,152 @@ struct TemplateParameterListBuilder { return *this; } + Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { +clang::ASTContext &context = S.getASTContext(); +// Obtain the QualType for 'unsigned long' +clang::QualType unsignedLongType = context.UnsignedLongTy; + +// Create a QualType that points to this TemplateTypeParmDecl +clang::QualType TType = context.getTypeDeclType(T); + +// Create a TypeSourceInfo for the template type parameter 'T' +clang::TypeSourceInfo *TTypeSourceInfo = +context.getTrivialTypeSourceInfo(TType, NameLoc); + +clang::UnaryExprOrTypeTraitExpr *sizeofExpr = new (S.getASTContext()) +clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, +unsignedLongType, NameLoc, NameLoc); + +// Create an IntegerLiteral for the value '16' +llvm::APInt intValue(context.getIntWidth(context.IntTy), 4); +clang::IntegerLiteral *intLiteral = new (context) +clang::IntegerLiteral(context, intValue, context.IntTy, NameLoc); + +// Create an ImplicitCastExpr to cast 'int' to 'unsigned long' +FPOptionsOverride fpoo = FPOptionsOverride(); +clang::ImplicitCastExpr *implicitCastExpr = clang::ImplicitCastExpr::Create( +context, +unsignedLongType, // The type we are casting to (QualType for 'unsigned + // long') +clang::CK_IntegralCast, // CastKind (e.g., Integral cast) +intLiteral, // Sub-expression being cast +nullptr,// Base path, usually null for implicit casts +clang::VK_XValue, +fpoo // Value kind, typically VK_RValue for implicit casts +); + +clang::QualType BoolTy = context.BoolTy; + +clang::BinaryOperator *binaryOperator = clang::BinaryOperator::Create( +context, sizeofExpr, // Left-hand side expression +
[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)
https://github.com/bob80905 created https://github.com/llvm/llvm-project/pull/112600 This PR is step one on the journey to implement resource element type validation via C++20 concepts. The PR sets up the infrastructure for injecting implicit concept decls / concept specialization expressions into the AST, which will then be evaluated after template arguments are instantiated. This is not meant to be a complete implementation of the desired validation for HLSL, there are a couple of missing elements: 1. We need the __builtin_hlsl_is_line_vector_layout_compatible builtin to be implemented. 2. We need other constraints, like is_intangible, and verifying that the template type is not a bool or enum 3. We need to put the first 2 points together, and construct a finalized constraint expression, which should differ between typed and raw buffers This is just an initial PR that puts some of the core infrastructure in place. >From 0739f6da81d7c1edd9578ae4ff9dd699e5c828c6 Mon Sep 17 00:00:00 2001 From: Joshua Batista Date: Thu, 10 Oct 2024 14:31:25 -0700 Subject: [PATCH 1/7] ConceptSpecializationExpr shows up in AST!!! --- .../clang/Sema/HLSLExternalSemaSource.h | 2 + clang/lib/AST/DeclTemplate.cpp| 6 +- clang/lib/Sema/HLSLExternalSemaSource.cpp | 154 +- 3 files changed, 158 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h b/clang/include/clang/Sema/HLSLExternalSemaSource.h index 3c7495e66055dc..0266bc0f8b336e 100644 --- a/clang/include/clang/Sema/HLSLExternalSemaSource.h +++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h @@ -47,6 +47,8 @@ class HLSLExternalSemaSource : public ExternalSemaSource { using ExternalASTSource::CompleteType; /// Complete an incomplete HLSL builtin type void CompleteType(TagDecl *Tag) override; + + ConceptDecl *getTypedBufferConceptDecl(Sema &S, CXXRecordDecl *Decl); }; } // namespace clang diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 6fe817c5ef1c6b..2eae6d14718b86 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1080,10 +1080,10 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, DeclContext *DC, TemplateParameterList *Params, Expr *ConstraintExpr) { bool Invalid = AdoptTemplateParameterList(Params, DC); - auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); + auto *CD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr); if (Invalid) -TD->setInvalidDecl(); - return TD; +CD->setInvalidDecl(); + return CD; } ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) { diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp b/clang/lib/Sema/HLSLExternalSemaSource.cpp index 2913d16fca4823..8104513857027c 100644 --- a/clang/lib/Sema/HLSLExternalSemaSource.cpp +++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp @@ -304,6 +304,7 @@ struct BuiltinTypeDeclBuilder { TemplateParameterListBuilder addTemplateArgumentList(Sema &S); BuiltinTypeDeclBuilder &addSimpleTemplateParams(Sema &S, ArrayRef Names); + BuiltinTypeDeclBuilder &addConceptSpecializationExpr(Sema &S); }; struct TemplateParameterListBuilder { @@ -326,7 +327,8 @@ struct TemplateParameterListBuilder { SourceLocation(), /* TemplateDepth */ 0, Position, &S.Context.Idents.get(Name, tok::TokenKind::identifier), /* Typename */ false, -/* ParameterPack */ false); +/* ParameterPack */ false, +/* HasTypeConstraint*/ true); if (!DefaultValue.isNull()) Decl->setDefaultArgument( S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(), @@ -336,6 +338,152 @@ struct TemplateParameterListBuilder { return *this; } + Expr *getTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc, + TemplateTypeParmDecl *T) { +clang::ASTContext &context = S.getASTContext(); +// Obtain the QualType for 'unsigned long' +clang::QualType unsignedLongType = context.UnsignedLongTy; + +// Create a QualType that points to this TemplateTypeParmDecl +clang::QualType TType = context.getTypeDeclType(T); + +// Create a TypeSourceInfo for the template type parameter 'T' +clang::TypeSourceInfo *TTypeSourceInfo = +context.getTrivialTypeSourceInfo(TType, NameLoc); + +clang::UnaryExprOrTypeTraitExpr *sizeofExpr = new (S.getASTContext()) +clang::UnaryExprOrTypeTraitExpr(clang::UETT_SizeOf, TTypeSourceInfo, +unsignedLongType, NameLoc, NameLoc); + +// Create an IntegerLiteral for the value '16' +llvm::APInt intValue(context.getIntWidth(context.IntTy), 4); +clang::IntegerLiteral *intLiteral = new (context) +clang::IntegerLiteral(context, intValue, context.IntTy,