Bug 574865 - Index: Error while parsing
Summary: Index: Error while parsing
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 10.3.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-15 11:42 EDT by Axel Mueller CLA
Modified: 2021-07-17 15:35 EDT (History)
3 users (show)

See Also:


Attachments
test code to reproduce (874 bytes, text/plain)
2021-07-17 07:11 EDT, Axel Mueller CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Axel Mueller CLA 2021-07-15 11:42:03 EDT
When I rebuild the index of my project I get the following entry in the error log:
Error while parsing name/of/source.cpp

java.lang.NullPointerException
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecRangeBasedFor.isEqual(ExecRangeBasedFor.java:103)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecRangeBasedFor.loopOverObject(ExecRangeBasedFor.java:85)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecRangeBasedFor.executeForFunctionCall(ExecRangeBasedFor.java:160)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalUtil.executeStatement(EvalUtil.java:94)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecCompoundStatement.executeForFunctionCall(ExecCompoundStatement.java:63)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalUtil.executeStatement(EvalUtil.java:94)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecIf.executeForFunctionCall(ExecIf.java:52)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalUtil.executeStatement(EvalUtil.java:94)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecCompoundStatement.executeForFunctionCall(ExecCompoundStatement.java:63)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFunctionCall.evaluateFunctionBody(EvalFunctionCall.java:350)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFunctionCall.getValue(EvalFunctionCall.java:187)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable.computeInitialValue(CPPVariable.java:271)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable.getInitialValue(CPPVariable.java:248)
	at org.eclipse.cdt.internal.core.pdom.PDOMWriter.resolveNames(PDOMWriter.java:441)
	at org.eclipse.cdt.internal.core.pdom.PDOMWriter.addSymbols(PDOMWriter.java:284)
	at org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.writeToIndex(AbstractIndexerTask.java:1295)
	at org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.parseFile(AbstractIndexerTask.java:1107)
	at org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.parseLinkage(AbstractIndexerTask.java:944)
	at org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.runTask(AbstractIndexerTask.java:572)
	at org.eclipse.cdt.internal.core.pdom.indexer.PDOMIndexerTask.run(PDOMIndexerTask.java:164)
	at org.eclipse.cdt.internal.core.pdom.indexer.PDOMRebuildTask.run(PDOMRebuildTask.java:94)
	at org.eclipse.cdt.internal.core.pdom.PDOMIndexerJob.run(PDOMIndexerJob.java:160)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)


Unfortunately, I cannot publish the source code file. Is there a way to identify which parts of the source code cause the exception?
Comment 1 Marc-André Laperle CLA 2021-07-16 00:31:39 EDT
It looks like a ranged-based for inside a constexpr function. It's hard to tell the source of the null without sample code. EvalUtil.getValuePair is one that's suspicious since it initializes with ICPPEvaluation updateable = null; and stores it in a pair for use later.
Comment 2 Axel Mueller CLA 2021-07-17 07:11:26 EDT
Created attachment 286799 [details]
test code to reproduce

The hint with the range-based loop in a constexpr was indeed helpful. I was able to isolate the code. If I comment out the line marked with "ERROR WHILE PARSING" then everything is fine.
Comment 3 Marc-André Laperle CLA 2021-07-17 15:35:29 EDT
I was able to reduce it further so that it doesn't depend on std includes

struct array {
  typedef const int *const_iterator;
  int __elems_[1];

  const constexpr int* data() const {
    return __elems_;
  }

  constexpr const_iterator begin() const {
    return const_iterator(data());
  }

  constexpr const_iterator end() const {
    return const_iterator(data() + 1);
  }

  const constexpr int& operator[](int __n) const {
    return __elems_[__n];
  }
};

static inline constexpr auto func() {
  const array a = { };

  for (auto &s : a)
    (void) s;

  return 0;
}

static constexpr auto i = func();

int main() {
  return i;
}