[llvm-bugs] [Bug 51289] New: clang reports an wrong message when using a builtin function with address space

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jul 31 00:38:36 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51289

            Bug ID: 51289
           Summary: clang reports an wrong message when using a builtin
                    function with address space
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: roninjiang at tencent.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

The address space is rarely used in other targets

so please add the following definition to include/clang/Basic/Builtins.def to
reproduce

BUILTIN(__builtin_copy_h2c, "vi*2i*1i*", "nc")

After compilation then we can run the following test:

#define AS1 __attribute__((address_space(1)))
#define AS2 __attribute__((address_space(2)))
void test(AS2 int* a, AS1 int* b) {
  __builtin_copy_h2c(a, b, a);
}

with the command:
clang bug.cpp  -fsyntax-only

The output of clang:
error: too many arguments to function call, expected 1, have 3; did you mean
'::__builtin_copy_h2c'?
bug.cpp:5:3: note: '::__builtin_copy_h2c' declared here
  __builtin_copy_h2c(a, b, a);
  ^
1 error generated.

I think this message is not correct, because this builtin should expect 3
arguments.

I debuged this problem and found the root cause should be a bug in
clang/lib/Sema/SemaExpr.cpp around line 6266 (lastest main branch, in function
"rewriteBuiltinFunctionDecl").

 6264     QualType PointeeType = ParamType->getPointeeType();
 6265     if (PointeeType.hasAddressSpace())
 6266       continue;
 6267

I believe here missed a push_back before "continue", i.e.:
OverloadParams.push_back(ParamType);


Please help to confirm this bug.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210731/a28548ff/attachment.html>


More information about the llvm-bugs mailing list