microsoft / microsoft/DirectXShaderCompiler

ClangTidy: clang-analyzer-core.uninitialized.Branch in third_party/dawn/third_party/dxc/tools/clang/tools/libclang/CIndex.cpp

Open
#5,993 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug tech-debt
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description
A preprocessor defintion to block out code not needed for dxc means that TU is expected to be set via
clang_createTranslationUnit2's *out_TU = MakeCXTranslationUnit(CXXIdx, AU.release()); Even though it is not necessary for it to do so becauseCXTranslationUnit TU; is return by value via clang_createTranslationUnit.

https://github.com/microsoft/DirectXShaderCompiler/blob/ceff9b8043df3ac8d7d3ce71b409d83afcd7925b/tools/clang/tools/libclang/CIndex.cpp#L2944:2961

While this is a false positive it is the only case in chromium third party (https://chromium.googlesource.com/external/github.com/microsoft/DirectXShaderCompiler) that violates this rule.

An altenative:

CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx,
                                              const char *ast_filename) {
  CXTranslationUnit TU;
#if 1 // HLSL Change Starts - no support for serialization
  enum CXErrorCode Result = CXError_Failure;
#else 
 enum CXErrorCode Result = 
      clang_createTranslationUnit2(CIdx, ast_filename, &TU);
#endif // HLSL Change Ends - no support for serialization
  (void)Result;
  assert((TU && Result == CXError_Success) ||
         (!TU && Result != CXError_Success));
  return TU;
}

This way you avoid calling clang_createTranslationUnit2 entirely.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in third_party/dawn/third_party/dxc/tools/clang/tools/libclang/CIndex.cpp around lines 2944-2961, focusing on clang_createTranslationUnit and clang_createTranslationUnit2. Review the preprocessor-controlled path and the proposed alternative, then verify that the clang-analyzer-core.uninitialized.Branch warning is resolved without changing the translation-unit behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.