简体   繁体   English

我是否在简单的OpenMP for循环中滥用了引用变量,还是一个clang bug?

[英]Did I misuse a reference variable in a simple OpenMP for loop, or is it a clang bug?

I think I have found a clang++ bug, but would appreciate advice on whether my code is correct. 我想我已经发现了一个clang ++ bug,但是我很欣赏有关我的代码是否正确的建议。 Clang static analyzer thinks it is okay, and it compiles with no problems, but when compiled with clang 3.7, it gets the size off a passed reference vector completely wrong. Clang静态分析器认为它没问题,并且编译时没有问题,但是当使用clang 3.7进行编译时,它会使传递的参考向量的大小完全错误。 GCC and clang 3.8 both give the correct answer. GCC和clang 3.8都给出了正确的答案。 I've reduced it to this test case: 我把它减少到这个测试用例:

#include <vector>
#include <iostream>
// including or excluding omp makes no difference
#include <omp.h>

void doSomething(std::vector<int> &k) {
#pragma omp for
    for (int i=0; i<2; ++i) {
            std::cout << k.size() << "\n";
    }
}

int main() {
    std::vector<int> v;
    v.push_back(1);

    std::vector<int> &j = v;
    doSomething(j);
    return(0);
}

with libomp (I think), rather than libgomp: 用libomp(我想),而不是libgomp:

clang-3.7++ -fopenmp clang-err.cpp
./a.out
18446708892352074976
18446708892352074976


clang-3.8++ -fopenmp clang-err.cpp
./a.out
1
1

I could not find such a bug present in clang 3.7 but fixed in 3.8. 我在clang 3.7中找不到这样的bug但在3.8中修复了。 I do not know how to tell whether I am using libomp for sure, although this is how LLVM/clang was compiled. 我不知道如何确定我是否正在使用libomp,尽管这是LLVM / clang的编译方式。 It seems like such a simple thing, so I suspect I am doing something strange rather than there being a real clang bug. 这似乎是一件简单的事情,所以我怀疑我做的事情很奇怪,而不是真正的铿锵声。

If the consensus is a clang bug, I'll report it against 3.7. 如果共识是一个铿锵的错误,我将针对3.7进行报告。 Thanks. 谢谢。

It does appear to be a clang bug in the current release 3.7. 它似乎是当前版本3.7中的一个铿锵声 However, surprisingly, the bug assignee closed the bug against 3.7 because it is fixed in 3.8. 然而,令人惊讶的是,bug受让人关闭了针对3.7的错误,因为它已修复为3.8。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM