主要内容

目标处理器类型 (-target)

通过选择预定义目标处理器来指定数据类型的大小和端序

描述

指定部署代码的处理器。

目标处理器决定了基础数据类型的大小和目标计算机的端序。如果其他处理器类型共享公共数据属性,则您可以使用其中之一来分析用于未列出的处理器类型的代码。

设置选项

使用以下方法之一设置选项:

  • Polyspace® 用户界面(仅限桌面端产品)- 在您的工程配置中,选择目标和编译器节点,然后为此选项选择一个值。

    要查看类型的大小,请点击目标处理器类型下拉列表右侧的编辑按钮。对于某些编译器,您只能看到该编译器允许的处理器。对于这些编译器,数据类型的大小在用户界面中不可见。有关数据类型的大小,请参阅设置

  • Polyspace 平台用户界面(仅限桌面端产品)- 此选项在 Polyspace 平台用户界面中名为处理器,并显示不同的受支持目标列表。请参阅处理器目标处理器类型选项所支持的目标(列于 设置 中)无法在 Polyspace 平台用户界面中直接选择。如果您在 Polyspace 平台用户界面中打开 psprj Polyspace 工程文件,工程中使用的目标会转换为自定义目标处理器,并在处理器选项中列出。

  • 命令行和选项文件 - 请使用 -target 选项。请参阅命令行信息

为何使用此选项

您可以指定一个目标处理器,以便某些 Polyspace 运行时检查根据该处理器的数据类型大小和其他属性进行量身定制。

例如,与 64 位处理器(如 x86_64)相比,变量在 32 位处理器(如 i386)上可能会因较小的值而溢出。如果您选择 x86_64 进行 Polyspace 分析,但将代码部署到 i386 处理器,则您的 Polyspace 结果并不总是适用。

选择目标处理器后,您可以指定 char 的默认符号是有符号还是无符号。要确定要指定的符号性,请使用您常用的编译器设置编译以下代码:

#include <limits.h>
int array[(char)UCHAR_MAX]; /* If char is signed, the array size is -1
如果代码已编译,则 char 的默认符号是无符号。例如,在 GCC 编译器上,代码可使用 -fsigned-char 标志进行编译,而使用 -funsigned-char 标志则无法成功编译。

设置

默认值:i386

此表显示了在与 generic、GCC、Clang 和 Visual Studio® 编译器配合使用时,各种目标处理器下每种基本数据类型的假定大小。对于某些目标,您可以通过点击目标处理器类型下拉列表右侧的编辑按钮来修改默认大小。这些目标的可选值在表中使用方括号显示。

目标charshortintlonglong longfloatdoublelong doublea指针char 默认符号endian对齐
i38681632326432649632有符号Little32
sparc816323264326412832有符号Big64
m68kb81632326432649632有符号Big64
powerpc816323264326412832无符号Big64
c-16781616323232646416有符号Little64
tms320c3x323232326432326432有符号Little32
sharc21x6132323232643232 [64]32 [64]32有符号Little32
necv85081632323232326432有符号Little32
hc08c81616 [32]32323232 [64]32 [64]16d无符号Big32
hc1281616 [32]32323232 [64]32 [64]326有符号Big32
mpc5xx8163232643232 [64]32 [64]32有符号Big32
c188161632 [24]e3232323216 [24]有符号Little8
x86_648163264 [32]f64326412864signedLittle128
arm81632326432646432有符号Big64
arm64816326464326412864有符号Big128
riscv816323264326412832有符号Big128
riscv64816326464326412864有符号Big128
mcpu...(高级)g8 [16]8 [16]16 [32]3232 [64]3232 [64]32 [64]16 [32]有符号Little32

a For targets where the size of long double is greater than 64 bits, the size used for computations is not always the same as the size listed in this table. The exceptions are:

  • For targets i386, x86_64 and m68k, 80 bits are used for computations, following the practice in common compilers.

  • For the target tms320c3x, 40 bits are used for computation, following the TMS320C3x specifications.

  • If you use a Visual compiler, the size of long double used for computations is the same as size of double, following the specification of Visual C++® compilers.

b The M68k family (68000, 68020, and so on) includes the “ColdFire” processor

c Non-ANSI C specified keywords and compiler implementation-dependent pragmas and interrupt facilities are not taken into account by this support

d  All kinds of pointers (near or far pointer) have 2 bytes (hc08) or 4 bytes (hc12) of width physically.

e The c18 target supports the type short long as 24 bits in size.

f Use option -long-is-32bits to support Microsoft® C/C++ Win64 target.

g  mcpu is a reconfigurable Micro Controller/Processor Unit target. You can use this type to configure one or more generic targets. For more information, see Generic target options.

除了原生支持的编译器之外,Polyspace 还支持各种专用编译器。您可以为这些专用编译器选择受支持的目标处理器:

提示

  • 如果您的处理器未列出,请使用具有相同特性的类似处理器,或创建一个 mcpu 通用目标处理器。请参阅通用目标选项

  • 您还可以使用选项 -custom-target 显式说明基础类型的大小等来创建自定义目标。

  • 如果您的配置同时使用 -custom-target-target 来指定目标,则分析将使用您使用 -custom-target 指定的目标。

命令行信息

参数:-target
值:i386 | sparc | m68k | powerpc | c-167 | tms320c3x | sharc21x61 | necv850 | hc08 | hc12 | mpc5xx | c18 | x86_64 | mcpu
默认值:i386
示例 (Bug Finder):polyspace-bug-finder -target m68k
示例 (Code Prover):polyspace-code-prover -target m68k
示例 (Bug Finder Server):polyspace-bug-finder-server -target m68k
示例 (Code Prover Server):polyspace-code-prover-server -target m68k

您可以使用特定的命令行选项覆盖某些目标的默认值。请参阅通用目标选项中的命令行选项部分。

另请参阅

Polyspace 分析选项

Polyspace 结果