Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
  • This project
    • Loading...
  • Sign in / Register
S
swiftshader
  • Project
    • Overview
    • Details
    • Activity
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 0
    • Issues 0
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Chen Yisong
  • swiftshader
  • Repository

Switch branch/tag
  • swiftshader
  • CMakeLists.txt
Find file
BlameHistoryPermalink
  • Nicolas Capens's avatar
    Fix -Wundefined-var-template warnings · 6f126055
    Nicolas Capens authored Jun 27, 2021
    This warning, which we treat as an error, occurs when a static member of
    an implicitly instatiated template class is referenced, but there is no
    definition available in the current translation unit.
    
    Note that with a non-template class this isn't a problem, since there
    can only be one definition, which is expected to be resolved at link
    time. But with a template class each instantiation can have a different
    static member variable definition.
    
    This warning typically occurs when the definition is available in
    another translation unit, so it may be tempting to move that definition
    into the header file to make it available to any translation unit where
    the static member may be referenced. However, this typically leads to
    multiple-definition errors.
    
    Like all multiple-definition errors, we can address that by declaring,
    not defining, the variable in the header, and leaving the definition in
    one translation unit. In the case of a non-template class the
    declaration in the class definition suffices since it's fully
    instantiated, but for a template class we need to re-declare the static
    member for the explicit instantiation.
    
    Concretely, in this case Subzero has a template class for x86
    instructions, with a static member for the Opcode string. This string is
    different for each instantiation of the instruction template, so we need
    to forward-declare each instantiated class's static member in the
    header. There's already a macro for the definitions, which is repurposed
    for declaring the instantiated members in the header.
    
    Note that the C++ reference states that "An explicit specialization of a
    static data member of a template is a definition if the declaration
    includes an initializer; otherwise, it is a declaration."
    (https://en.cppreference.com/w/cpp/language/template_specialization)
    But Visual Studio treats them as definitions anyway, leading to
    multiple-definition errors. Note that we can't add 'extern' to
    explicitly make it a declaration only, because storage-class specifiers
    are not valid for class members. So we just omit the declaration for
    compilers other than Clang, which don't have this warning enabled
    anyway.
    
    Bug: chromium:604888
    Change-Id: I63b58ecdf956ff264e6d25738684b513f05b268b
    Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/55208
    Kokoro-Result: kokoro <noreply+kokoro@google.com>
    Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
    Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
    6f126055
CMakeLists.txt 40.1 KB
EditWeb IDE
×

Replace CMakeLists.txt

Attach a file by drag & drop or click to upload


Cancel
A new branch will be created in your fork and a new merge request will be started.