Skip to content

Move pointer/reference rejection to Sema#8436

Merged
llvm-beanz merged 2 commits into
microsoft:mainfrom
llvm-beanz:cbieneman/pointer-rework
May 15, 2026
Merged

Move pointer/reference rejection to Sema#8436
llvm-beanz merged 2 commits into
microsoft:mainfrom
llvm-beanz:cbieneman/pointer-rework

Conversation

@llvm-beanz
Copy link
Copy Markdown
Collaborator

This is a refactoring to move the rejection of pointer and reference types into Sema rather than rejecting it during parsing. This has a few consequences and benefits.

The consequence as seen in the changes to the cpp-errors tests are that we don't see pointer use errors in cases where a parser error prevents sema code from executing (as seen in operator cases).

The benefit is that this also intercepts pointer and reference types that are deduced (via templates, auto or decltype).

This is a refactoring to move the rejection of pointer and reference
types into Sema rather than rejecting it during parsing. This has a few
consequences and benefits.

The consequence as seen in the changes to the cpp-errors tests are that
we don't see pointer use errors in cases where a parser error prevents
sema code from executing (as seen in operator cases).

The benefit is that this also intercepts pointer and reference types
that are deduced (via templates, auto or decltype).
@@ -0,0 +1,65 @@
// RUN: %dxc -T cs_6_0 %s 2>&1 | FileCheck %s --check-prefix=COMPILE
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use CHECK-COMPILE for the prefix? It's generally clearer to use CHECK-<something> than just <something>

../tools/clang/test/SemaHLSL/template-implicit-this-sfinae.hlsl
Comment thread tools/clang/lib/Parse/ParseDecl.cpp
float foo;
void * operator new(int size) { // expected-error {{overloading 'operator new' is not allowed}} expected-error {{pointers are unsupported in HLSL}}
return (void *)0; // expected-error {{pointers are unsupported in HLSL}} expected-error {{cannot convert from 'literal int' to 'void *'}} expected-warning {{'operator new' should not return a null pointer unless it is declared 'throw()'}}
S operator new(int size) { // expected-error {{overloading 'operator new' is not allowed}}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this file, I understand why the 2nd error diagnostic is being removed, but why do the types need to be changed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sema rejecting the return type causes the compiler to skip processing or surfacing diagnostics for the rest of the declaration, so if the return type is a pointer, no further diagnostics are generated.

Copy link
Copy Markdown
Collaborator

@bob80905 bob80905 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@llvm-beanz llvm-beanz merged commit 7284bb1 into microsoft:main May 15, 2026
13 checks passed
@github-project-automation github-project-automation Bot moved this from New to Done in HLSL Roadmap May 15, 2026
@llvm-beanz llvm-beanz deleted the cbieneman/pointer-rework branch May 15, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants