-
Notifications
You must be signed in to change notification settings - Fork 871
Disallow built-in internal types to be inferred by auto #8510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joaosaffran
wants to merge
9
commits into
microsoft:main
Choose a base branch
from
joaosaffran:auto/not-infer-builtin-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+185
−0
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
acf7235
deny built in types
joaosaffran cc2eb8f
clean up
joaosaffran 8a363cc
address tex comments
joaosaffran c7e29f4
clean up
joaosaffran 69045d5
format
joaosaffran 8dc7932
address comments from beanz
joaosaffran 36aede0
clean up
joaosaffran 6adf8a0
Update tools/clang/lib/Sema/SemaHLSL.cpp
joaosaffran bf83962
fix
joaosaffran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tools/clang/test/HLSLFileCheckLit/hlsl/auto/auto-deducible-types.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // RUN: %dxc -T cs_6_0 -HV 202x -verify %s | ||
| // expected-no-diagnostics | ||
|
|
||
| struct MyStruct { | ||
| float a; | ||
| int b; | ||
| }; | ||
|
|
||
| Texture2D<float4> tex : register(t0); | ||
| SamplerState samp : register(s0); | ||
| RWBuffer<float> output : register(u0); | ||
|
|
||
| [numthreads(1,1,1)] | ||
| void main() { | ||
| // Scalars. | ||
| auto i = 5; | ||
| auto f = 1.5f; | ||
| auto b = true; | ||
|
|
||
| // Vectors. | ||
| auto v = float4(1, 2, 3, 4); | ||
|
|
||
|
|
||
| // Matrices. | ||
| float2x2 matInit = { 1, 2, 3, 4 }; | ||
| auto m = matInit; | ||
| auto row = m[0]; | ||
| auto elem = m[0][0]; | ||
|
|
||
| // User-defined structs. | ||
| MyStruct s = { 1.0f, 2 }; | ||
| auto sCopy = s; | ||
|
|
||
| // Resource objects (their handles are copyable, so binding one is allowed). | ||
| auto t = tex; | ||
|
|
||
| // Use every value to prevent dead-code elimination. | ||
| output[0] = (float)i + f + (float)b + v.x + m._11 + row.x + elem + sCopy.a + | ||
| (float)sCopy.b + t.SampleLevel(samp, float2(0, 0), 0).x; | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
tools/clang/test/HLSLFileCheckLit/hlsl/auto/auto-no-subobject.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // RUN: %dxc -T lib_6_3 -HV 202x -verify %s | ||
|
|
||
| GlobalRootSignature grs = {"CBV(b0)"}; | ||
| LocalRootSignature lrs = {"UAV(u0)"}; | ||
| StateObjectConfig soc = { STATE_OBJECT_FLAGS_ALLOW_LOCAL_DEPENDENCIES_ON_EXTERNAL_DEFINITONS }; | ||
| SubobjectToExportsAssociation sea = { "grs", "a;b" }; | ||
| RaytracingShaderConfig rsc = { 128, 64 }; | ||
| RaytracingPipelineConfig rpc = { 512 }; | ||
| RaytracingPipelineConfig1 rpc1 = { 32, RAYTRACING_PIPELINE_FLAG_ALLOW_OPACITY_MICROMAPS }; | ||
| TriangleHitGroup trHitGt = { "a", "b" }; | ||
| ProceduralPrimitiveHitGroup ppHitGt = { "a", "b", "c" }; | ||
|
|
||
| void useSubobjects() { | ||
| // expected-error@+1 {{'auto' cannot deduce type 'GlobalRootSignature'}} | ||
| auto a = grs; | ||
| // expected-error@+1 {{'auto' cannot deduce type 'LocalRootSignature'}} | ||
| auto b = lrs; | ||
| // expected-error@+1 {{'auto' cannot deduce type 'StateObjectConfig'}} | ||
| auto c = soc; | ||
| // expected-error@+1 {{'auto' cannot deduce type 'SubobjectToExportsAssociation'}} | ||
| auto d = sea; | ||
| // expected-error@+1 {{'auto' cannot deduce type 'RaytracingShaderConfig'}} | ||
| auto e = rsc; | ||
| // expected-error@+1 {{'auto' cannot deduce type 'RaytracingPipelineConfig'}} | ||
| auto f = rpc; | ||
| // expected-error@+1 {{'auto' cannot deduce type 'RaytracingPipelineConfig1'}} | ||
| auto g = rpc1; | ||
| // expected-error@+1 {{'auto' cannot deduce type 'TriangleHitGroup'}} | ||
| auto h = trHitGt; | ||
| // expected-error@+1 {{'auto' cannot deduce type 'ProceduralPrimitiveHitGroup'}} | ||
| auto i = ppHitGt; | ||
| } |
27 changes: 27 additions & 0 deletions
27
tools/clang/test/HLSLFileCheckLit/hlsl/auto/auto-undeducible-types.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // RUN: %dxc -T cs_6_0 -HV 202x -verify %s | ||
|
|
||
|
|
||
| void voidFunc() {} | ||
|
|
||
| Texture2D<float4> tex : register(t0); | ||
| Texture2DMS<float4> texMS : register(t1); | ||
|
|
||
| [numthreads(1,1,1)] | ||
| void main() { | ||
| int y = 1; | ||
|
|
||
| // expected-error@+1 {{'auto' cannot deduce type}} | ||
| auto str = "abc"; | ||
|
|
||
| // expected-error@+1 {{variable has incomplete type 'void'}} | ||
| auto x = voidFunc(); | ||
|
|
||
| // expected-error@+1 {{variable has incomplete type 'void'}} | ||
| auto v = (void)y; | ||
|
|
||
| // expected-error@+1 {{'auto' cannot deduce type}} | ||
| auto m = tex.mips; | ||
|
|
||
| // expected-error@+1 {{'auto' cannot deduce type}} | ||
| auto s = texMS.sample; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // RUN: %dxc -T ps_6_0 -ast-dump-implicit %s | FileCheck %s | ||
|
|
||
| // This test verifies that the inner indexer object types backing .mips and | ||
| // .sample (mips_type / mips_slice_type, sample_type / sample_slice_type) carry | ||
| // the implicit HLSLNonAutoDeducibleAttr, so that 'auto' cannot deduce them. | ||
| // See also subobjects-ast-dump.hlsl, which checks the same attribute on | ||
| // subobject types. | ||
|
|
||
| Texture2D<float4> srv; | ||
| Texture2DMS<float4> srvMS; | ||
|
|
||
| float4 main() : SV_Target { | ||
| return 0; | ||
| } | ||
|
|
||
| // The slice type is created before the indexer type, so it is dumped first; | ||
| // each carries the attribute as its first child. Texture2D (.mips) is referenced | ||
| // before Texture2DMS (.sample), so the mips records are dumped first. | ||
|
|
||
| // CHECK: CXXRecordDecl {{0x[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> implicit {{.*}}mips_slice_type definition | ||
| // CHECK-NEXT: HLSLNonAutoDeducibleAttr {{0x[0-9a-fA-F]+}} <<invalid sloc>> Implicit | ||
| // CHECK: CXXRecordDecl {{0x[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> implicit {{.*}}mips_type definition | ||
| // CHECK-NEXT: HLSLNonAutoDeducibleAttr {{0x[0-9a-fA-F]+}} <<invalid sloc>> Implicit | ||
| // CHECK: CXXRecordDecl {{0x[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> implicit {{.*}}sample_slice_type definition | ||
| // CHECK-NEXT: HLSLNonAutoDeducibleAttr {{0x[0-9a-fA-F]+}} <<invalid sloc>> Implicit | ||
| // CHECK: CXXRecordDecl {{0x[0-9a-fA-F]+}} <<invalid sloc>> <invalid sloc> implicit {{.*}}sample_type definition | ||
| // CHECK-NEXT: HLSLNonAutoDeducibleAttr {{0x[0-9a-fA-F]+}} <<invalid sloc>> Implicit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about something like?
auto row = m[0];