checkedc / checkedc-clang

This repo contains a version of clang that is being modified to support Checked C. Checked C is an extension to C that lets programmers write C code that is guaranteed by the compiler to be type-safe.
https://www.checkedc.org
504 stars 76 forks source link

clang 17 upgrade: remaining 3C failing tests #1209

Open dtarditi opened 1 month ago

dtarditi commented 1 month ago

With this PR, there are 6 failing 3C test cases:

  Clang :: 3C/3d-allocation.c
  Clang :: 3C/function_typedef.c
  Clang :: 3C/itype_nt_arr_cast.c
  Clang :: 3C/itype_undef.c
  Clang :: 3C/prototype_success1.c
  Clang :: 3C/prototype_success2.c
  Clang :: 3C/valist.c

I debugged 3C/prototype_success2.c, which is oddly compiled when you run the 3C\prototype_success1.c test. The 3C failure is due to trying to get a source location for a compiler-generated variable declaration. The test case that triggers the failures shows the problem:

_Ptr<int> foo(int *, char);

In the prototype declaration, only the types of the arguments are declared. The compiler generates a variable declaration. When 3C tries to fetch the source code location, an assert happens.

Here's a partial call stack. This is on Windows using the VS Studio debugger:

>   3c.exe!HandleAbort(int Sig) Line 415    C++
    [External Code] 
    3c.exe!clang::SourceManager::getFileIDLoaded(unsigned int SLocOffset) Line 868  C++
    3c.exe!clang::SourceManager::getFileIDSlow(unsigned int SLocOffset) Line 779    C++
    3c.exe!clang::SourceManager::getFileID(unsigned int SLocOffset) Line 1831   C++
    3c.exe!clang::SourceManager::getFileID(clang::SourceLocation SpellingLoc) Line 1120 C++
    3c.exe!clang::SourceManager::getExpansionLocSlowCase(clang::SourceLocation Loc) Line 946    C++
    3c.exe!clang::SourceManager::getExpansionLoc(clang::SourceLocation Loc) Line 1172   C++
    3c.exe!PersistentSourceLoc::mkPSL(clang::SourceRange SR, clang::SourceLocation SL, const clang::ASTContext & Context) Line 61   C++
    3c.exe!PersistentSourceLoc::mkPSL(const clang::Decl * D, const clang::ASTContext & C) Line 26   C++
    3c.exe!MappingVisitor::VisitDecl(clang::Decl * D) Line 18   C++
    3c.exe!clang::RecursiveASTVisitor<MappingVisitor>::WalkUpFromDecl(clang::Decl * D) Line 440 C++
    3c.exe!clang::RecursiveASTVisitor<MappingVisitor>::WalkUpFromNamedDecl(clang::NamedDecl * D) Line 107   C++
souragc commented 1 month ago

Hi David,

I cloned this repo's branch 17-init-main and tried running the 3C tests. I am only getting two tests which are failing. Can you post the commit on which you got the above results? Also, it looked like this repo is missing a change to the CMakeLists.txt from the 17-init-main branch of the archived fork. So I used the archive during my building. Please let me know if I should be building differently.

dtarditi commented 1 month ago

Hi Sourag,

Thanks for pointing out there was an issue with the checkedc repo. It didn't have the 17-init-main branch from the archive. I have pushed that branch to the checkedc repo. I merged the most recent changes from main into the 17-init-main branch also.

For the 3C tests, I did a debug build on x64 Windows. I used this cmake command:

cmake -G Ninja -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Debug c:\checkedc\checkedc-clang\llvm

followed by

ninja checked-clang

It could be the type of build or that platform that is causing the difference. Note that running checked-clang with a debug build is quite slow. It takes over an hour on my test system.