Skip to content
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

Emit a "Count" member or constant for enums #90

Open
jfroy opened this issue Jan 18, 2019 · 4 comments
Open

Emit a "Count" member or constant for enums #90

jfroy opened this issue Jan 18, 2019 · 4 comments
Labels

Comments

@jfroy
Copy link

jfroy commented Jan 18, 2019

We just found and fixed a major buffer overflow in a compiler caused by an out-of-date spirv op count constant. Looking at spirv.hpp, there is no machine-generate count enum member or constant for the various enums. This seems like an easy addition that would help prevent unfortunate bugs.

@johnkslang
Copy link
Member

johnkslang commented Jan 21, 2019

Do you have an example count?

Counts should have been dropped in official headers long ago, because we are now using what is effectively a sparse space, with extensions bringing in unpredictable ranges.

The model should be to switch on values you know about, but not to make arrays sized by enum values, which is the key reason the headers don't provide such a count.

@jfroy
Copy link
Author

jfroy commented Jan 23, 2019 via email

@johnkslang
Copy link
Member

Just opcodes? I guess you could size the array as 2^16. Any number less than that could suddenly show up as an opcode. As you note, sizing arrays this way is quite fragile, and is the reason we don't supply a count, especially since it could be immediately obsoleted by an extension, especially a non-public extension.

What about the all other enumerants?

@jfroy
Copy link
Author

jfroy commented Jan 24, 2019

They have

  • Count of BuiltIn (non-extension)
  • Extension BuiltIn range (start, end)
  • Op count
  • ExecutionModel count
  • DimCount count
  • Decoration count
  • StorageClass count
  • Scope count
  • GroupOperation count
  • SourceLanguage count
  • AddressingModel count
  • MemoryModel count
  • ExecutionMode count
  • Capability count (non-extension)
  • Capability extension range (start, end)
  • AccessQualifier count
  • MemoryAccessMask count
  • MemorySemanticsMask count
  • LoopControlMask count
  • SelectionControlMask count
  • FunctionControlMask count
  • ImageFormat count (non-extension)
  • ImageFormat extension count
  • ImageOperandsShift count

All of these are used. In some cases, only for reflection code, but many also for codegen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants