[LLVMbugs] [Bug 22802] New: Void functions marked pure attribute are not called

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Mar 5 03:41:09 PST 2015


http://llvm.org/bugs/show_bug.cgi?id=22802

            Bug ID: 22802
           Summary: Void functions marked pure attribute are not called
           Product: clang
           Version: 3.5
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: fuscated at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I'm testing if the pure attribute is useful and stumbled upon this problem
case:

--- test_pure.cpp
#include <stdio.h>

void myPure(void *ptr) __attribute__ ((pure));
void myPure(void *ptr) {
    float *p=reinterpret_cast<float*>(ptr);
    p[0]=1.0f;
    p[1]=2.0f;
    p[2]=3.0f;
}

int main() {
    float f[3]={};
    myPure(f);
    printf("f %.3f, %.3f, %.3f\n", f[0], f[1], f[2]);
    return 0;
}

$ clang++-3.5 -Weverything test_pure.cpp
$ ./a.out 
f 0.000, 0.000, 0.000

The result is that the function is not called, because it is void function.
Ideally I would be happy if the compiler can detect that ptr is an output
parameter and thus treat the function as having void* output.
I'm not sure if this is possible to implement, but if not I'd be happy if the
compiler emits a warning or an error when it detects this case.

-- 
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/20150305/5872c755/attachment.html>


More information about the llvm-bugs mailing list