Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

false diagnostics with -fopenmp #113

Open
scturtle opened this issue Nov 9, 2018 · 10 comments
Open

false diagnostics with -fopenmp #113

scturtle opened this issue Nov 9, 2018 · 10 comments
Labels
clang clang bugs/enhancement

Comments

@scturtle
Copy link
Contributor

scturtle commented Nov 9, 2018

Latest ccls compiled with LLVM 7. -fopenmp causes false diagnostics.

#include <Eigen/Core>
#include <glog/logging.h>
int main() {LOG(INFO);} //  ccls: use of undeclared identifier 'INFO' (lsp-ui)

I just remove -fopenmp from args manually at the time. May not be a good solution.

@MaskRay
Copy link
Owner

MaskRay commented Nov 9, 2018

@acowley seems to have the same issue. I'll investigate what -fopenmp does

@acowley
Copy link
Contributor

acowley commented Nov 9, 2018

Yes, I add it as a filtered flag to the ccls startup options. The only downside is warnings about unknown openmp pragmas in my code.

@MaskRay
Copy link
Owner

MaskRay commented Nov 10, 2018

With clang trunk, I cannot reproduce the spurious diagnostic with

hg clone https://bitbucket.org/eigen/eigen

git clone https://github.com/google/glog
cd glog; ./autogen.sh; ./configure; make -j

and clang -Ieigen -Iglog/src -fopenmp ...

Have you tried running clang '-###' -fsyntax-only -I/tmp/p/eigen -I/tmp/p/glog/src a.cc and updating .ccls (or compile_commands.json) with the clang -cc1 options? Delete suspicious option one by one to narrow down.

clang.excludeArgs: ["-fopenmp"]

@scturtle
Copy link
Contributor Author

cd eigen; hg up 3.3.5. The latest stable release version of eigen should be able to reproduce it. There should be a bug in it that frustrates ccls a lot.

@MaskRay
Copy link
Owner

MaskRay commented Nov 10, 2018

Sorry I can reproduce it, with either head or 3.3.5

It is an issue of preamble building with -fopenmp.

In clang_complete.cc:DiagnosticMain, if I don't use preamble (basically longest prefix of preprocessor tokens), the spurious error goes away.

-    std::shared_ptr<PreambleData> preamble = session->GetPreamble();
     std::shared_ptr<PreambleData> preamble;

"use of undeclared identifier" is the fallout of an earlier issue.
When building the preamble in clang/lib/Parse/ParseOpenMP.cpp ParseOpenMPDeclarativeDirectiveWithExtDecl, this is reported as a diag::err_omp_unexpected_directive because Tok is clang:;tok::TokenKind::identifier.

 929|   case OMPD_target_teams_distribute_simd:
 930|     Diag(Tok, diag::err_omp_unexpected_directive)
 931|         << 1 << getOpenMPDirectiveName(DKind);
 932|     break;

(gdb) p SourceLocation::getFromRawEncoding(Tok.Loc).printToString(PP.getSourceManager())
$18 = "/tmp/p/eigen/Eigen/src/Core/products/Parallelizer.h:134:15"

@MaskRay MaskRay added clang clang bugs/enhancement and removed investigating labels Nov 11, 2018
@Riatre
Copy link
Contributor

Riatre commented Nov 12, 2018

To me it looks like this is actually very similar to the "-Werror leads to spurious diagnostics" case. It is an issue of preamble building with both SkipFunctionBodies and -fopenmp.

Eigen/src/Core/products/Parallelizer.h:134:15 is a pragma clause related to OpenMP, it references a local variable which is skipped because of SkipFunctionBodies, but the pragma itself is not skipped, thus the error.

@MaskRay
Copy link
Owner

MaskRay commented Nov 12, 2018

@Riatre I feel this same. When I get more time I'll study more about clang's lexer/parser.

@amosbird
Copy link
Contributor

another MVE for this

#include <vector>

#include <parallel/algorithm>

int main() {
    std::vector<int> a = { 3, 2, 1 };
    __gnu_parallel::sort(std::begin(a), std::end(a));
    return 0;
}

@bastianbeischer
Copy link

@MaskRay @Riatre This is still an open issue with LLVM 8 and latest ccls for me. As far as I understand this is a LLVM problem and not directly related to ccls. So is there a bug report for LLVM/clang to track this?

@vvhitedog
Copy link

vvhitedog commented Apr 4, 2020

FYI this is still very much an issue in LLVM 9.0.1, with the latest ccls at time of writing. Turning off openmp in a project that utilizes Eigen fixes all the false diagnostics.

Obviously, not a great option for development, but doable for now, would like to see a fix if possible, can help if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang clang bugs/enhancement
Projects
None yet
Development

No branches or pull requests

7 participants