【问题标题】:While building LLVM got errors in AlignOf.h在构建 LLVM 时,AlignOf.h 出现错误
【发布时间】:2017-07-31 22:28:41
【问题描述】:

我在使用 cmake 和 Visual Studio 14 2015 从官方源文件构建 LLVM 时遇到多个错误,并且无法弄清楚为什么会发生这种情况,这些错误出现的原因是什么?

D:\LLVM\build\llvm\include\llvm/Support/AlignOf.h(57): 错误 C2988:无法识别的模板声明/定义 [D:\LLVM\build\build\lib\System\LLVMSystem.vcxproj] D:\LLVM\build\llvm\include\llvm/Support/AlignOf.h(57): 错误 C2059:语法错误:'alignof' [D:\LLVM\build\build\lib\System\LLVMSystem.vcxproj] D:\LLVM\build\llvm\include\llvm/Support/AlignOf.h(59): 错误 C2143:语法错误:缺少“;”前 '}' [D:\LLVM\build\build\lib\System\LLVMSystem.vcxproj]

这是 AlignOf.h 文件中的代码:

#ifndef LLVM_SUPPORT_ALIGNOF_H
#define LLVM_SUPPORT_ALIGNOF_H

namespace llvm {

template <typename T>
struct AlignmentCalcImpl {
  char x;
  T t;
private:
  AlignmentCalcImpl() {} // Never instantiate.
};

/// AlignOf - A templated class that contains an enum value representing
///  the alignment of the template argument.  For example,
///  AlignOf<int>::Alignment represents the alignment of type "int".  The
///  alignment calculated is the minimum alignment, and not necessarily
///  the "desired" alignment returned by GCC's __alignof__ (for example).  Note
///  that because the alignment is an enum value, it can be used as a
///  compile-time constant (e.g., for template instantiation).
template <typename T>
struct AlignOf {
  enum { Alignment =
         static_cast<unsigned int>(sizeof(AlignmentCalcImpl<T>) - sizeof(T)) };

  enum { Alignment_GreaterEqual_2Bytes = Alignment >= 2 ? 1 : 0 };
  enum { Alignment_GreaterEqual_4Bytes = Alignment >= 4 ? 1 : 0 };
  enum { Alignment_GreaterEqual_8Bytes = Alignment >= 8 ? 1 : 0 };
  enum { Alignment_GreaterEqual_16Bytes = Alignment >= 16 ? 1 : 0 };

  enum { Alignment_LessEqual_2Bytes = Alignment <= 2 ? 1 : 0 };
  enum { Alignment_LessEqual_4Bytes = Alignment <= 4 ? 1 : 0 };
  enum { Alignment_LessEqual_8Bytes = Alignment <= 8 ? 1 : 0 };
  enum { Alignment_LessEqual_16Bytes = Alignment <= 16 ? 1 : 0 };

};

/// alignof - A templated function that returns the mininum alignment of
///  of a type.  This provides no extra functionality beyond the AlignOf
///  class besides some cosmetic cleanliness.  Example usage:
///  alignof<int>() returns the alignment of an int.
template <typename T>
static inline unsigned alignof() { return AlignOf<T>::Alignment; }

} // end namespace llvm
#endif 

【问题讨论】:

  • 你甚至可以使用 microsoft cl.exe 编译器构建 llvm 吗?
  • 在构建时,我正在遵循官方 llvm 指南“使用 CMake 构建 LLVM”llvm.org/docs/CMake.html,并在 AlignOf.h 中获得“无法识别的模板声明”,任何线索为什么会出现问题?跨度>

标签: c++ llvm


【解决方案1】:

我认为这主要是由于头文件中alignof和alignOf的差异。

这为我解决了这个问题: http://llvm.org/viewvc/llvm-project?view=revision&revision=117774

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多