[all-commits] [llvm/llvm-project] 049d86: [CUDA][HIP] Fix constexpr variables for C++17

Yaxun (Sam) Liu via All-commits all-commits at lists.llvm.org
Wed Jun 3 18:57:36 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 049d860707ef22978b9379fee6dce38c66a22671
      https://github.com/llvm/llvm-project/commit/049d860707ef22978b9379fee6dce38c66a22671
  Author: Yaxun (Sam) Liu <yaxun.liu at amd.com>
  Date:   2020-06-03 (Wed, 03 Jun 2020)

  Changed paths:
    M clang/include/clang/Sema/Sema.h
    M clang/lib/Sema/SemaCUDA.cpp
    M clang/lib/Sema/SemaDecl.cpp
    M clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
    A clang/test/CodeGenCUDA/constexpr-variables.cu
    A clang/test/SemaCUDA/constexpr-variables.cu

  Log Message:
  -----------
  [CUDA][HIP] Fix constexpr variables for C++17

constexpr variables are compile time constants and implicitly const, therefore
they are safe to emit on both device and host side. Besides, in many cases
they are intended for both device and host, therefore it makes sense
to emit them on both device and host sides if necessary.

In most cases constexpr variables are used as rvalue and the variables
themselves do not need to be emitted. However if their address is taken,
then they need to be emitted.

For C++14, clang is able to handle that since clang emits them with
available_externally linkage together with the initializer.

However for C++17, the constexpr static data member of a class or template class
become inline variables implicitly. Therefore they become definitions with
linkonce_odr or weak_odr linkages. As such, they can not have available_externally
linkage.

This patch fixes that by adding implicit constant attribute to
file scope constexpr variables and constexpr static data members
in device compilation.

Differential Revision: https://reviews.llvm.org/D79237




More information about the All-commits mailing list