8

似乎-malign-double编译器选项已从 Clang 中删除。示例代码:

#include <stddef.h>
#include <stdio.h>

typedef struct X { char a; long long b; } X;

int main(void)
{
  printf("%zd\n", offsetof(X, b));
  return 0;
}

当使用 GCC 在 32 位模式下编译时 ( -m32),可以根据是否-malign-double启用分别输出 8 或 4。但是 Clang 似乎不支持这个选项:

$ clang test.c -m32 -malign-double
clang: warning: argument unused during compilation: '-malign-double'
$ ./a.out
4

叮当版本:

Apple clang version 3.1 (tags/Apple/clang-318.0.58) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.3.0
Thread model: posix

我似乎在 Clang 支持的编译器标志的完整列表中找不到任何官方文档,它们似乎大部分都遵循 GCC 的文档。

是否有任何电流等效-malign-double于 Clang?还是我现在不得不使用不同的编译器?我需要它来编译一些链接到使用该标志的纯二进制第三方库的代码。

4

1 回答 1

1

现在似乎已修复:

commit 3205dbb3f1f96e77e106f964dcf1b5f69fba4ecc
Author: Craig Topper <craig.topper@intel.com>
Date:   Thu Mar 21 20:07:24 2019 +0000

    [Driver] Pass -malign-double from the driver to the cc1 command line

    -malign-double is currently only implemented in the -cc1 interface.
    But its declared in Options.td so it is a driver option too.
    But you try to use it with the driver you'll get a message about the
    option being unused.

    This patch teaches the driver to pass the option through to cc1 so it won't
    be unused. The Options.td says the option is x86 only but I didn't see any
    x86 specific code in its implementation in cc1 so not sure if the
    documentation is wrong or if I should only pass this option through the
    driver on x86 targets.

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

    llvm-svn: 356706
于 2021-12-28T09:20:08.347 回答