Skip to content

Weird Clang's branch coverage with macros from system headers #78920

Closed
@chapuni

Description

@chapuni

Clang eliminates whole MACRO expr in branch coverage.

(https://godbolt.org/z/3o9MTf4eW)

/* header.h */
#define ISN(c) ('0' <= (c) && (c) <= '9')
#include <header.h>
int isx(int c) {
    return (ISN(c) || ('A' <= c && c <= 'F'));
}
clang -fprofile-instr-generate -fcoverage-mapping -Xclang -dump-coverage-mapping -isystem .

The emission of the record is as below; ISN(c) cannot be seen nor evaluated.
Could I see the condition of ISN(c)?

isx:
  File 0, 9:16 -> 11:2 = #0
  File 0, 10:23 -> 10:45 = #1
  File 0, 10:24 -> 10:32 = #1
  Branch,File 0, 10:24 -> 10:32 = #4, (#1 - #4)
  File 0, 10:36 -> 10:44 = #4
  Branch,File 0, 10:36 -> 10:44 = #5, (#4 - #5)

WIth -fcoverage-mcdc, llvm-cov crashes. (cc: @evodius96)
A workaround is adding -mllvm -system-headers-coverage to clang.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Needs Triage

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions