Skip to content

[clang] Can't compile RISC-V vector intrisics with precompiled headers (PCH) #109634

@Ferdi265

Description

@Ferdi265

Summary

Clang supports RISC-V vector intrinsics (#include <riscv_vector.h>), but fails to compile them when precompiled headers (PCH) are being used. This affects clangd since it precompiles the header-portion of source files.

Testcase

Dependencies on Debian/Ubuntu: clang, gcc-multilib

// test.h
#ifndef TEST_H_
#define TEST_H_

#include <riscv_vector.h>

#endif
// test.c
#include "test.h"

vuint64m4_t v_add(vuint64m4_t a, vuint64m4_t b, size_t vl) {
    return __riscv_vadd_vv_u64m4(a, b, vl);
}

Compile without PCH:

$ clang --target=riscv64-linux-gnu -march=rv64gcv -c test.c -o test.o

Compile with PCH:

$ clang --target=riscv64-linux-gnu -march=rv64gcv -x c-header test.h -o test.h.pch
$ clang --target=riscv64-linux-gnu -march=rv64gcv -include-pch test.h.pch -c test.c -o test.o
test.c:4:12: error: call to undeclared function '__riscv_vadd_vv_u64m4'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    4 |     return __riscv_vadd_vv_u64m4(a, b, vl);
      |            ^
test.c:4:12: error: returning 'int' from a function with incompatible result type 'vuint64m4_t' (aka '__rvv_uint64m4_t')
    4 |     return __riscv_vadd_vv_u64m4(a, b, vl);
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.

Expected Behaviour

PCH doesn't cause a difference in behaviour.

Actual Behaviour

Functions declared by #pragma clang riscv intrinsic vector (from <riscv_vector.h>) don't exist when using PCH.

Versions

Tested with Clang 18.1.8-2 on Arch Linux, Clang 18.1.8 on Android Termux, and Clang 18.0-59 on Ubuntu 24.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:PCHPrecompiled headers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions