[clang] [clang][analyzer] Ignore unnamed bitfields in UninitializedObject (PR #132427)

2025-03-21 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 updated 
https://github.com/llvm/llvm-project/pull/132427

>From 72aafcc255bbcfccb3fa5317e260faf97a3dfed5 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Fri, 21 Mar 2025 20:45:11 +0530
Subject: [PATCH 1/3] [clang][analyzer] Removed warnings for unnamed bitfields

---
 .../UninitializedObject/UninitializedObjectChecker.cpp| 4 
 1 file changed, 4 insertions(+)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index 6e1222fedad3e..bf954c3711309 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -332,6 +332,10 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
 }
 
 if (isPrimitiveType(T)) {
+  if (I->isUnnamedBitField()) {
+IsAnyFieldInitialized = true;
+continue;
+  }
   if (isPrimitiveUninit(V)) {
 if (addFieldToUninits(LocalChain.add(RegularField(FR
   ContainsUninitField = true;

>From ff01085e3e7aaab4a5dd54e69b3f5be19d43001f Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Fri, 21 Mar 2025 22:46:33 +0530
Subject: [PATCH 2/3] removed IsAnyFieldInitialized after isUnnamedBitField

---
 .../Checkers/UninitializedObject/UninitializedObjectChecker.cpp  | 1 -
 1 file changed, 1 deletion(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index bf954c3711309..bf7759975b3ec 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -333,7 +333,6 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
 
 if (isPrimitiveType(T)) {
   if (I->isUnnamedBitField()) {
-IsAnyFieldInitialized = true;
 continue;
   }
   if (isPrimitiveUninit(V)) {

>From fdff9198f3355ff2f27da5f8682875ba500cbeb9 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Sat, 22 Mar 2025 03:34:17 +0530
Subject: [PATCH 3/3] added regression tests for unnamed bitfield

---
 .../Analysis/cxx-uninitialized-object.cpp | 21 +++
 1 file changed, 21 insertions(+)

diff --git a/clang/test/Analysis/cxx-uninitialized-object.cpp 
b/clang/test/Analysis/cxx-uninitialized-object.cpp
index e3fa8ae8d7f29..43b1628388509 100644
--- a/clang/test/Analysis/cxx-uninitialized-object.cpp
+++ b/clang/test/Analysis/cxx-uninitialized-object.cpp
@@ -1182,3 +1182,24 @@ void fComplexTest() {
   // TODO: we should emit a warning for x2.x and x2.y.
   ComplexUninitTest x2;
 }
+
+struct PaddingBitfieldTest {
+  int a;
+  long long : 7; // padding, previously flagged as uninitialized
+  PaddingBitfieldTest(int a) : a(a) {}
+};
+
+void fPaddingBitfieldTest() {
+  PaddingBitfieldTest pb(42);
+  // no-warning: Unnamed bitfield is now ignored, fixing false positive
+}
+
+struct NamedBitfieldTest {
+  int b; 
+  long long named : 7; // expected-note{{uninitialized field 'this->named'}}
+  NamedBitfieldTest(int b) : b(b) {} // expected-warning{{1 uninitialized 
field at the end of the constructor call}}
+};
+
+void fNamedBitfieldTest() {
+  NamedBitfieldTest nb(42); 
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Ignore unnamed bitfields in UninitializedObject (PR #132427)

2025-03-21 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 edited 
https://github.com/llvm/llvm-project/pull/132427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Unnamed fields (PR #132427)

2025-03-21 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 created 
https://github.com/llvm/llvm-project/pull/132427

Fixes #132001 

Edit ```isNonUnionUninit``` (caller of ```isPrimitiveUninit```): Add a check 
before calling ```isPrimitiveUninit```
```cpp
if (isPrimitiveType(T)) {
  if (I->isUnnamedBitField()) {
continue;
  }
  if (isPrimitiveUninit(V)) {
if (addFieldToUninits(LocalChain.add(RegularField(FR
  ContainsUninitField = true;
  }
  continue;
}
```

**Test Results**
```bash
Testing Time: 221.93s

Total Discovered Tests: 991
  Unsupported  :  16 (1.61%)
  Passed   : 968 (97.68%)
  Expectedly Failed:   7 (0.71%)
[100%] Built target check-clang-analysis
```

>From 72aafcc255bbcfccb3fa5317e260faf97a3dfed5 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Fri, 21 Mar 2025 20:45:11 +0530
Subject: [PATCH 1/2] [clang][analyzer] Removed warnings for unnamed bitfields

---
 .../UninitializedObject/UninitializedObjectChecker.cpp| 4 
 1 file changed, 4 insertions(+)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index 6e1222fedad3e..bf954c3711309 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -332,6 +332,10 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
 }
 
 if (isPrimitiveType(T)) {
+  if (I->isUnnamedBitField()) {
+IsAnyFieldInitialized = true;
+continue;
+  }
   if (isPrimitiveUninit(V)) {
 if (addFieldToUninits(LocalChain.add(RegularField(FR
   ContainsUninitField = true;

>From ff01085e3e7aaab4a5dd54e69b3f5be19d43001f Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Fri, 21 Mar 2025 22:46:33 +0530
Subject: [PATCH 2/2] removed IsAnyFieldInitialized after isUnnamedBitField

---
 .../Checkers/UninitializedObject/UninitializedObjectChecker.cpp  | 1 -
 1 file changed, 1 deletion(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index bf954c3711309..bf7759975b3ec 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -333,7 +333,6 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
 
 if (isPrimitiveType(T)) {
   if (I->isUnnamedBitField()) {
-IsAnyFieldInitialized = true;
 continue;
   }
   if (isPrimitiveUninit(V)) {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Ignore unnamed bitfields in UninitializedObject (PR #132427)

2025-03-21 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 edited 
https://github.com/llvm/llvm-project/pull/132427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Ignore unnamed bitfields in UninitializedObject (PR #132427)

2025-03-21 Thread Abhinav Kumar via cfe-commits

kr-2003 wrote:

> Could you add a test case that fails before your patch?

Sure, here it is

## Testcase
```cpp
struct S
{
S(bool b)
: b(b)
{}
bool b{false};
long long : 7; // padding
};

void f()
{
S s(true);
}
```
### Before Patch
https://github.com/user-attachments/assets/557a81a7-d569-48b2-b7db-18513d9e271d";
 />

### After Patch
https://github.com/user-attachments/assets/8e025041-e368-4e86-9e91-8f426333f2f3";
 />


https://github.com/llvm/llvm-project/pull/132427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Ignore unnamed bitfields in UninitializedObject (PR #132427)

2025-03-21 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 edited 
https://github.com/llvm/llvm-project/pull/132427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Ignore unnamed bitfields in UninitializedObject (PR #132427)

2025-03-21 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 edited 
https://github.com/llvm/llvm-project/pull/132427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Ignore unnamed bitfields in UninitializedObjectChecker (PR #132427)

2025-03-26 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 updated 
https://github.com/llvm/llvm-project/pull/132427

>From 72aafcc255bbcfccb3fa5317e260faf97a3dfed5 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Fri, 21 Mar 2025 20:45:11 +0530
Subject: [PATCH 1/4] [clang][analyzer] Removed warnings for unnamed bitfields

---
 .../UninitializedObject/UninitializedObjectChecker.cpp| 4 
 1 file changed, 4 insertions(+)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index 6e1222fedad3e..bf954c3711309 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -332,6 +332,10 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
 }
 
 if (isPrimitiveType(T)) {
+  if (I->isUnnamedBitField()) {
+IsAnyFieldInitialized = true;
+continue;
+  }
   if (isPrimitiveUninit(V)) {
 if (addFieldToUninits(LocalChain.add(RegularField(FR
   ContainsUninitField = true;

>From ff01085e3e7aaab4a5dd54e69b3f5be19d43001f Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Fri, 21 Mar 2025 22:46:33 +0530
Subject: [PATCH 2/4] removed IsAnyFieldInitialized after isUnnamedBitField

---
 .../Checkers/UninitializedObject/UninitializedObjectChecker.cpp  | 1 -
 1 file changed, 1 deletion(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index bf954c3711309..bf7759975b3ec 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -333,7 +333,6 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
 
 if (isPrimitiveType(T)) {
   if (I->isUnnamedBitField()) {
-IsAnyFieldInitialized = true;
 continue;
   }
   if (isPrimitiveUninit(V)) {

>From fdff9198f3355ff2f27da5f8682875ba500cbeb9 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Sat, 22 Mar 2025 03:34:17 +0530
Subject: [PATCH 3/4] added regression tests for unnamed bitfield

---
 .../Analysis/cxx-uninitialized-object.cpp | 21 +++
 1 file changed, 21 insertions(+)

diff --git a/clang/test/Analysis/cxx-uninitialized-object.cpp 
b/clang/test/Analysis/cxx-uninitialized-object.cpp
index e3fa8ae8d7f29..43b1628388509 100644
--- a/clang/test/Analysis/cxx-uninitialized-object.cpp
+++ b/clang/test/Analysis/cxx-uninitialized-object.cpp
@@ -1182,3 +1182,24 @@ void fComplexTest() {
   // TODO: we should emit a warning for x2.x and x2.y.
   ComplexUninitTest x2;
 }
+
+struct PaddingBitfieldTest {
+  int a;
+  long long : 7; // padding, previously flagged as uninitialized
+  PaddingBitfieldTest(int a) : a(a) {}
+};
+
+void fPaddingBitfieldTest() {
+  PaddingBitfieldTest pb(42);
+  // no-warning: Unnamed bitfield is now ignored, fixing false positive
+}
+
+struct NamedBitfieldTest {
+  int b; 
+  long long named : 7; // expected-note{{uninitialized field 'this->named'}}
+  NamedBitfieldTest(int b) : b(b) {} // expected-warning{{1 uninitialized 
field at the end of the constructor call}}
+};
+
+void fNamedBitfieldTest() {
+  NamedBitfieldTest nb(42); 
+}

>From 1dcddea465721ad58fe69a749c8b6e570d727d57 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Wed, 26 Mar 2025 15:45:16 +0530
Subject: [PATCH 4/4] checking unnamed bitfield

---
 .../UninitializedObject/UninitializedObjectChecker.cpp | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index bf7759975b3ec..98b0fbeb72fbb 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -291,7 +291,9 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
 
   // Are all of this non-union's fields initialized?
   for (const FieldDecl *I : RD->fields()) {
-
+if (I->isUnnamedBitField()) {
+  continue;
+}
 const auto FieldVal =
 State->getLValue(I, loc::MemRegionVal(R)).castAs();
 const auto *FR = FieldVal.getRegionAs();
@@ -332,9 +334,6 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
 }
 
 if (isPrimitiveType(T)) {
-  if (I->isUnnamedBitField()) {
-continue;
-  }
   if (isPrimitiveUninit(V)) {
 if (addFieldToUninits(LocalChain.add(RegularField(FR
   ContainsUninitField = true;

___
cfe-commits mailing lis

[clang] [clang][analyzer] Ignore unnamed bitfields in UninitializedObjectChecker (PR #132427)

2025-03-26 Thread Abhinav Kumar via cfe-commits

kr-2003 wrote:

> > My proposal is to judge the current `FieldDecl` at the beginning of the 
> > loop, and if it's a UnamedBitField, just skip it, because at that point the 
> > UnamedBitField's static check should be passing. If it's a NamedBitField 
> > then it needs to be initialized to pass the static check (i.e. go deeper to 
> > determine the type, value or whatever).
> 
> Exactly. I think it makes a lot more sense to check this as early as possible 
> to have a reduced set of possibilities to think about later. @kr-2003 Could 
> you please update your PR accordingly?
> 
> > The current test cases are sufficient. I'm not sure about the answers to 
> > the other questions.
> 
> I agree.

Done

https://github.com/llvm/llvm-project/pull/132427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Implement value printing of custom types (PR #84769)

2025-04-18 Thread Abhinav Kumar via cfe-commits

kr-2003 wrote:

Hey, @vgvassilev 

Curious to know the status of this. Thank you.

https://github.com/llvm/llvm-project/pull/84769
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] fix error recovery while parsing completely fails (PR #127087)

2025-02-19 Thread Abhinav Kumar via cfe-commits

kr-2003 wrote:

> Hmmm confused !
> 
> So does it really come down to the flag responsible for enabling assertions.
> `LLVM_ENABLE_ASSERTIONS=ON`

Seems like it. This is the only flag that explains this behaviour.

https://github.com/llvm/llvm-project/pull/127087
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] fix error recovery while parsing completely fails (PR #127087)

2025-02-18 Thread Abhinav Kumar via cfe-commits

kr-2003 wrote:

> My theory with limited testing: The crash is caused by assertion failure at 
> https://github.com/llvm/llvm-project/blob/eb7c947272952d40d3235d89652a10da52cb2b4d/clang/lib/AST/DeclBase.cpp#L1757C1-L1758C54.
>  So if we disable assertions it does not crash, and crashes otherwise. Maybe 
> you can confirm this. There is a flaw in the logic of recovering from 
> syntax/semantic errors.

Even without removing those assertions, the malformed try-catch block gave 
parsing error successfully if we build it with the following flags.
```-DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=clang 
-DLLVM_USE_SPLIT_DWARF=ON -DLLVM_USE_LINKER=lld```

https://github.com/llvm/llvm-project/pull/127087
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] fix error recovery while parsing completely fails (PR #127087)

2025-02-17 Thread Abhinav Kumar via cfe-commits

kr-2003 wrote:

> There are quite some observations made by @kr-2003 and me here.
> 
> 1. We realize even without this fix, stuff worked perfectly on our Macos ARM 
> devices. So looks like a Ubuntu issue anyways
> 
> ![image](https://private-user-images.githubusercontent.com/87052487/414089130-666d5cc4-1f42-4c4a-8ff6-81aa67bc4650.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk4NTMwNjksIm5iZiI6MTczOTg1Mjc2OSwicGF0aCI6Ii84NzA1MjQ4Ny80MTQwODkxMzAtNjY2ZDVjYzQtMWY0Mi00YzRhLThmZjYtODFhYTY3YmM0NjUwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE4VDA0MjYwOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYxZDhhMmQyZTAzMzg4NTM0OGExMmJkZmI3NTUyMTM4MDUzYWNlMzlkNGIzYzVkYjYxY2IyYzhlZDdhYWRhMGYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.1XaiqgvI8dYqCgIWeJ2U2bwUyZ0Cps0-ELIfAryGdc0)
> 
> 2. Obviously the try-catch block works when wrapped inside a class/function 
> (not a top level decl)
> 3. If we build clang-repl with different configs, it works even on ubuntu
> 
> i) `-DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=clang 
> -DLLVM_USE_SPLIT_DWARF=ON -DLLVM_USE_LINKER=lld`
> 
> With this
> 
> ```
> (base) abhinav@jarvis-2223:~/Desktop/Coding/llvm-project/build/bin$ 
> ./clang-repl --version
> LLVM (http://llvm.org/):
>   LLVM version 20.1.0-rc1
>   Optimized build.
> (base) abhinav@jarvis-2223:~/Desktop/Coding/llvm-project/build/bin$ 
> ./clang-repl
> clang-repl> #include 
> clang-repl> try { throw 1; } catch { std::cout << "Caught Exception" << 
> std::endl; }
> In file included from <<< inputs >>>:1:
> input_line_2:1:23: error: expected '('
> 1 | try { throw 1; } catch { std::cout << "Caught Exception" << 
> std::endl; }
>   |   ^
>   |   (
> error: Parsing failed.
> clang-repl>
> ```
> 
> ii) With the following it fails.
> 
> ```
> -DLLVM_ENABLE_PROJECTS=clang\
> -DLLVM_TARGETS_TO_BUILD="host;NVPTX"\
> -DCMAKE_BUILD_TYPE=Release  \
> -DLLVM_ENABLE_ASSERTIONS=ON \
> -DCLANG_ENABLE_STATIC_ANALYZER=OFF  \
> -DCLANG_ENABLE_ARCMT=OFF\
> -DCLANG_ENABLE_FORMAT=OFF   \
> -DCLANG_ENABLE_BOOTSTRAP=OFF\
> -DLLVM_ENABLE_ZSTD=OFF  \
> -DLLVM_ENABLE_TERMINFO=OFF  \
> -DLLVM_ENABLE_LIBXML2=OFF   \
> 
> ```
> 
> Abhinav, could you also past the diff between how using two different configs 
> affects the build ? Maybe that might point us to the root cause behind all of 
> this.

Sure, this is diff of two CMakeCache.txt files when built with different flags.

```
2c2
< # For build in directory: /home/abhinav/Desktop/Coding/llvm-project/build
---
> # For build in directory: 
> /home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/build
76a77,79
> //Build clang-format VS plugin
> BUILD_CLANG_FORMAT_VS_PLUGIN:BOOL=OFF
> 
89,91d91
< //Host clang executable. Saves building if cross-compiling.
< CLANG:STRING=
< 
128c128,134
< CLANG_ENABLE_ARCMT:BOOL=ON
---
> CLANG_ENABLE_ARCMT:BOOL=OFF
> 
> //No help, variable specified on the command line.
> CLANG_ENABLE_BOOTSTRAP:UNINITIALIZED=OFF
> 
> //No help, variable specified on the command line.
> CLANG_ENABLE_FORMAT:UNINITIALIZED=OFF
134c140
< CLANG_ENABLE_LIBXML2:BOOL=ON
---
> CLANG_ENABLE_LIBXML2:BOOL=OFF
140c146
< CLANG_ENABLE_STATIC_ANALYZER:BOOL=ON
---
> CLANG_ENABLE_STATIC_ANALYZER:BOOL=OFF
144c150
< CLANG_EXECUTABLE_VERSION:STRING=20
---
> CLANG_EXECUTABLE_VERSION:STRING=19
158,163d163
< //Install the scan-build tool
< CLANG_INSTALL_SCANBUILD:BOOL=ON
< 
< //Install the scan-view tool
< CLANG_INSTALL_SCANVIEW:BOOL=ON
< 
169c169
< 
CLANG_PGO_TRAINING_DATA:PATH=/home/abhinav/Desktop/Coding/llvm-project/clang/utils/perf-training
---
> CLANG_PGO_TRAINING_DATA:PATH=/home/abhinav/Desktop/Coding/CERN_HSF_Compiler_Research/llvm-project/clang/utils/perf-training
212c212
< //Whether to build arcmt-test as part of CLANG
---
> //Whether to build ARCMT_TEST as part of CLANG
215c215
< //Whether to build clang-check as part of CLANG
---
> //Whether to build CLANG_CHECK as part of CLANG
221c221
< //Whether to build clang-extdef-mapping as part of CLANG
---
> //Whether to build CLANG_EXTDEF_MAPPING as part of CLANG
226a227,229
> //Whether to build clang-format-vs as part of CLANG
> CLANG_TOOL_CLANG_FORMAT_VS_BUILD:BOOL=ON
> 
250a254,256
> //Whether to build clang-rename as part of CLANG
> CLANG_TOOL_CLANG_RENAME_BUILD:BOOL=ON
> 
260,263c266
< //Whether to build clang-sycl-linker as part of CLANG
< CLANG_TOOL_CLANG_SYCL_LINKER_BUILD:BOOL=ON
< 
< //Whether to build c-arcmt

[clang] [llvm] [Clang-Repl] Add pipe-based redirection and fetch PID of launched executor (PR #147478)

2025-07-08 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 updated 
https://github.com/llvm/llvm-project/pull/147478

>From fbe4344831538480be33accd35ef618c6d0e50b3 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Tue, 1 Jul 2025 18:55:21 +0530
Subject: [PATCH 1/6] pipes for redirection in oop jit

---
 .../clang/Interpreter/RemoteJITUtils.h|  6 +++-
 clang/lib/Interpreter/RemoteJITUtils.cpp  | 32 ++-
 llvm/lib/ExecutionEngine/Orc/LLJIT.cpp| 15 +
 3 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Interpreter/RemoteJITUtils.h 
b/clang/include/clang/Interpreter/RemoteJITUtils.h
index 8705a3b1f669d..825143f008a45 100644
--- a/clang/include/clang/Interpreter/RemoteJITUtils.h
+++ b/clang/include/clang/Interpreter/RemoteJITUtils.h
@@ -26,7 +26,7 @@
 
 llvm::Expected>
 launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
-   llvm::StringRef SlabAllocateSizeString);
+   llvm::StringRef SlabAllocateSizeString, int stdin_fd = 0, int 
stdout_fd = 1, int stderr_fd = 2);
 
 /// Create a JITLinkExecutor that connects to the given network address
 /// through a TCP socket. A valid NetworkAddress provides hostname and port,
@@ -35,4 +35,8 @@ llvm::Expected>
 connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
  llvm::StringRef SlabAllocateSizeString);
 
+/// Get the PID of the last launched executor.
+/// This is useful for debugging or for cleanup purposes.
+pid_t getLastLaunchedExecutorPID();
+
 #endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
diff --git a/clang/lib/Interpreter/RemoteJITUtils.cpp 
b/clang/lib/Interpreter/RemoteJITUtils.cpp
index c0e663b764785..8324aeaaf689c 100644
--- a/clang/lib/Interpreter/RemoteJITUtils.cpp
+++ b/clang/lib/Interpreter/RemoteJITUtils.cpp
@@ -33,6 +33,8 @@
 using namespace llvm;
 using namespace llvm::orc;
 
+static std::atomic LaunchedExecutorPID{-1};
+
 Expected getSlabAllocSize(StringRef SizeString) {
   SizeString = SizeString.trim();
 
@@ -91,7 +93,7 @@ createSharedMemoryManager(SimpleRemoteEPC &SREPC,
 
 Expected>
 launchExecutor(StringRef ExecutablePath, bool UseSharedMemory,
-   llvm::StringRef SlabAllocateSizeString) {
+   llvm::StringRef SlabAllocateSizeString, int stdin_fd, int 
stdout_fd, int stderr_fd) {
 #ifndef LLVM_ON_UNIX
   // FIXME: Add support for Windows.
   return make_error("-" + ExecutablePath +
@@ -134,6 +136,28 @@ launchExecutor(StringRef ExecutablePath, bool 
UseSharedMemory,
 close(ToExecutor[WriteEnd]);
 close(FromExecutor[ReadEnd]);
 
+if (stdin_fd != 0) {
+  dup2(stdin_fd, STDIN_FILENO);
+  if (stdin_fd != STDIN_FILENO)
+close(stdin_fd);
+}
+
+if (stdout_fd != 1) {
+  dup2(stdout_fd, STDOUT_FILENO);
+  if (stdout_fd != STDOUT_FILENO)
+close(stdout_fd);
+
+  setvbuf(stdout, NULL, _IONBF, 0);
+}
+
+if (stderr_fd != 2) {
+  dup2(stderr_fd, STDERR_FILENO);
+  if (stderr_fd != STDERR_FILENO)
+close(stderr_fd);
+
+  setvbuf(stderr, NULL, _IONBF, 0);
+}
+
 // Execute the child process.
 std::unique_ptr ExecutorPath, FDSpecifier;
 {
@@ -155,6 +179,8 @@ launchExecutor(StringRef ExecutablePath, bool 
UseSharedMemory,
  << ExecutorPath.get() << "\"\n";
   exit(1);
 }
+  } else {
+ LaunchedExecutorPID = ChildPID;
   }
   // else we're the parent...
 
@@ -265,3 +291,7 @@ connectTCPSocket(StringRef NetworkAddress, bool 
UseSharedMemory,
   std::move(S), *SockFD, *SockFD);
 #endif
 }
+
+pid_t getLastLaunchedExecutorPID() {
+  return LaunchedExecutorPID;
+}
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp 
b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 4e3c09e970cbe..67bb7dd8ad08f 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -632,16 +632,19 @@ Error ORCPlatformSupport::initialize(orc::JITDylib &JD) {
   int32_t result;
   auto E = ES.callSPSWrapper(WrapperAddr->getAddress(),
  result, DSOHandles[&JD]);
-  if (result)
+  if (E)
+return E;
+  else if (result)
 return make_error("dlupdate failed",
inconvertibleErrorCode());
-  return E;
-}
-return ES.callSPSWrapper(WrapperAddr->getAddress(),
-   DSOHandles[&JD], JD.getName(),
-   int32_t(ORC_RT_RTLD_LAZY));
+} else
+  return ES.callSPSWrapper(WrapperAddr->getAddress(),
+ DSOHandles[&JD], JD.getName(),
+ int32_t(ORC_RT_RTLD_LAZY));
   } else
 return WrapperAddr.takeError();
+
+  return Error::success();
 }
 
 Error ORCPlatformSupport::deinitialize(orc::JITDylib &JD) {

>From b207b1f4c4e639d86d0a03d28437f7e170f5d400 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Mon, 7 Jul 2025 11:50:20 +0530

[clang] [llvm] [Clang-Repl] Add pipe-based redirection and fetch PID of launched executor (PR #147478)

2025-07-08 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 updated 
https://github.com/llvm/llvm-project/pull/147478

>From fbe4344831538480be33accd35ef618c6d0e50b3 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Tue, 1 Jul 2025 18:55:21 +0530
Subject: [PATCH 1/5] pipes for redirection in oop jit

---
 .../clang/Interpreter/RemoteJITUtils.h|  6 +++-
 clang/lib/Interpreter/RemoteJITUtils.cpp  | 32 ++-
 llvm/lib/ExecutionEngine/Orc/LLJIT.cpp| 15 +
 3 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Interpreter/RemoteJITUtils.h 
b/clang/include/clang/Interpreter/RemoteJITUtils.h
index 8705a3b1f669d..825143f008a45 100644
--- a/clang/include/clang/Interpreter/RemoteJITUtils.h
+++ b/clang/include/clang/Interpreter/RemoteJITUtils.h
@@ -26,7 +26,7 @@
 
 llvm::Expected>
 launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
-   llvm::StringRef SlabAllocateSizeString);
+   llvm::StringRef SlabAllocateSizeString, int stdin_fd = 0, int 
stdout_fd = 1, int stderr_fd = 2);
 
 /// Create a JITLinkExecutor that connects to the given network address
 /// through a TCP socket. A valid NetworkAddress provides hostname and port,
@@ -35,4 +35,8 @@ llvm::Expected>
 connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
  llvm::StringRef SlabAllocateSizeString);
 
+/// Get the PID of the last launched executor.
+/// This is useful for debugging or for cleanup purposes.
+pid_t getLastLaunchedExecutorPID();
+
 #endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
diff --git a/clang/lib/Interpreter/RemoteJITUtils.cpp 
b/clang/lib/Interpreter/RemoteJITUtils.cpp
index c0e663b764785..8324aeaaf689c 100644
--- a/clang/lib/Interpreter/RemoteJITUtils.cpp
+++ b/clang/lib/Interpreter/RemoteJITUtils.cpp
@@ -33,6 +33,8 @@
 using namespace llvm;
 using namespace llvm::orc;
 
+static std::atomic LaunchedExecutorPID{-1};
+
 Expected getSlabAllocSize(StringRef SizeString) {
   SizeString = SizeString.trim();
 
@@ -91,7 +93,7 @@ createSharedMemoryManager(SimpleRemoteEPC &SREPC,
 
 Expected>
 launchExecutor(StringRef ExecutablePath, bool UseSharedMemory,
-   llvm::StringRef SlabAllocateSizeString) {
+   llvm::StringRef SlabAllocateSizeString, int stdin_fd, int 
stdout_fd, int stderr_fd) {
 #ifndef LLVM_ON_UNIX
   // FIXME: Add support for Windows.
   return make_error("-" + ExecutablePath +
@@ -134,6 +136,28 @@ launchExecutor(StringRef ExecutablePath, bool 
UseSharedMemory,
 close(ToExecutor[WriteEnd]);
 close(FromExecutor[ReadEnd]);
 
+if (stdin_fd != 0) {
+  dup2(stdin_fd, STDIN_FILENO);
+  if (stdin_fd != STDIN_FILENO)
+close(stdin_fd);
+}
+
+if (stdout_fd != 1) {
+  dup2(stdout_fd, STDOUT_FILENO);
+  if (stdout_fd != STDOUT_FILENO)
+close(stdout_fd);
+
+  setvbuf(stdout, NULL, _IONBF, 0);
+}
+
+if (stderr_fd != 2) {
+  dup2(stderr_fd, STDERR_FILENO);
+  if (stderr_fd != STDERR_FILENO)
+close(stderr_fd);
+
+  setvbuf(stderr, NULL, _IONBF, 0);
+}
+
 // Execute the child process.
 std::unique_ptr ExecutorPath, FDSpecifier;
 {
@@ -155,6 +179,8 @@ launchExecutor(StringRef ExecutablePath, bool 
UseSharedMemory,
  << ExecutorPath.get() << "\"\n";
   exit(1);
 }
+  } else {
+ LaunchedExecutorPID = ChildPID;
   }
   // else we're the parent...
 
@@ -265,3 +291,7 @@ connectTCPSocket(StringRef NetworkAddress, bool 
UseSharedMemory,
   std::move(S), *SockFD, *SockFD);
 #endif
 }
+
+pid_t getLastLaunchedExecutorPID() {
+  return LaunchedExecutorPID;
+}
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp 
b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 4e3c09e970cbe..67bb7dd8ad08f 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -632,16 +632,19 @@ Error ORCPlatformSupport::initialize(orc::JITDylib &JD) {
   int32_t result;
   auto E = ES.callSPSWrapper(WrapperAddr->getAddress(),
  result, DSOHandles[&JD]);
-  if (result)
+  if (E)
+return E;
+  else if (result)
 return make_error("dlupdate failed",
inconvertibleErrorCode());
-  return E;
-}
-return ES.callSPSWrapper(WrapperAddr->getAddress(),
-   DSOHandles[&JD], JD.getName(),
-   int32_t(ORC_RT_RTLD_LAZY));
+} else
+  return ES.callSPSWrapper(WrapperAddr->getAddress(),
+ DSOHandles[&JD], JD.getName(),
+ int32_t(ORC_RT_RTLD_LAZY));
   } else
 return WrapperAddr.takeError();
+
+  return Error::success();
 }
 
 Error ORCPlatformSupport::deinitialize(orc::JITDylib &JD) {

>From b207b1f4c4e639d86d0a03d28437f7e170f5d400 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Mon, 7 Jul 2025 11:50:20 +0530

[clang] [llvm] [Clang-Repl] Add pipe-based redirection and fetch PID of launched executor (PR #147478)

2025-07-08 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 created 
https://github.com/llvm/llvm-project/pull/147478

This PR introduces:
1. Pipe based redirection for ``stdin``, ``stdout`` and ``stderr`` for 
out-of-process(OOP) JIT execution.
2. Fetching PID of the launched out-of-process(OOP) JIT executor.

>From fbe4344831538480be33accd35ef618c6d0e50b3 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Tue, 1 Jul 2025 18:55:21 +0530
Subject: [PATCH 1/3] pipes for redirection in oop jit

---
 .../clang/Interpreter/RemoteJITUtils.h|  6 +++-
 clang/lib/Interpreter/RemoteJITUtils.cpp  | 32 ++-
 llvm/lib/ExecutionEngine/Orc/LLJIT.cpp| 15 +
 3 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Interpreter/RemoteJITUtils.h 
b/clang/include/clang/Interpreter/RemoteJITUtils.h
index 8705a3b1f669d..825143f008a45 100644
--- a/clang/include/clang/Interpreter/RemoteJITUtils.h
+++ b/clang/include/clang/Interpreter/RemoteJITUtils.h
@@ -26,7 +26,7 @@
 
 llvm::Expected>
 launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
-   llvm::StringRef SlabAllocateSizeString);
+   llvm::StringRef SlabAllocateSizeString, int stdin_fd = 0, int 
stdout_fd = 1, int stderr_fd = 2);
 
 /// Create a JITLinkExecutor that connects to the given network address
 /// through a TCP socket. A valid NetworkAddress provides hostname and port,
@@ -35,4 +35,8 @@ llvm::Expected>
 connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
  llvm::StringRef SlabAllocateSizeString);
 
+/// Get the PID of the last launched executor.
+/// This is useful for debugging or for cleanup purposes.
+pid_t getLastLaunchedExecutorPID();
+
 #endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
diff --git a/clang/lib/Interpreter/RemoteJITUtils.cpp 
b/clang/lib/Interpreter/RemoteJITUtils.cpp
index c0e663b764785..8324aeaaf689c 100644
--- a/clang/lib/Interpreter/RemoteJITUtils.cpp
+++ b/clang/lib/Interpreter/RemoteJITUtils.cpp
@@ -33,6 +33,8 @@
 using namespace llvm;
 using namespace llvm::orc;
 
+static std::atomic LaunchedExecutorPID{-1};
+
 Expected getSlabAllocSize(StringRef SizeString) {
   SizeString = SizeString.trim();
 
@@ -91,7 +93,7 @@ createSharedMemoryManager(SimpleRemoteEPC &SREPC,
 
 Expected>
 launchExecutor(StringRef ExecutablePath, bool UseSharedMemory,
-   llvm::StringRef SlabAllocateSizeString) {
+   llvm::StringRef SlabAllocateSizeString, int stdin_fd, int 
stdout_fd, int stderr_fd) {
 #ifndef LLVM_ON_UNIX
   // FIXME: Add support for Windows.
   return make_error("-" + ExecutablePath +
@@ -134,6 +136,28 @@ launchExecutor(StringRef ExecutablePath, bool 
UseSharedMemory,
 close(ToExecutor[WriteEnd]);
 close(FromExecutor[ReadEnd]);
 
+if (stdin_fd != 0) {
+  dup2(stdin_fd, STDIN_FILENO);
+  if (stdin_fd != STDIN_FILENO)
+close(stdin_fd);
+}
+
+if (stdout_fd != 1) {
+  dup2(stdout_fd, STDOUT_FILENO);
+  if (stdout_fd != STDOUT_FILENO)
+close(stdout_fd);
+
+  setvbuf(stdout, NULL, _IONBF, 0);
+}
+
+if (stderr_fd != 2) {
+  dup2(stderr_fd, STDERR_FILENO);
+  if (stderr_fd != STDERR_FILENO)
+close(stderr_fd);
+
+  setvbuf(stderr, NULL, _IONBF, 0);
+}
+
 // Execute the child process.
 std::unique_ptr ExecutorPath, FDSpecifier;
 {
@@ -155,6 +179,8 @@ launchExecutor(StringRef ExecutablePath, bool 
UseSharedMemory,
  << ExecutorPath.get() << "\"\n";
   exit(1);
 }
+  } else {
+ LaunchedExecutorPID = ChildPID;
   }
   // else we're the parent...
 
@@ -265,3 +291,7 @@ connectTCPSocket(StringRef NetworkAddress, bool 
UseSharedMemory,
   std::move(S), *SockFD, *SockFD);
 #endif
 }
+
+pid_t getLastLaunchedExecutorPID() {
+  return LaunchedExecutorPID;
+}
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp 
b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 4e3c09e970cbe..67bb7dd8ad08f 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -632,16 +632,19 @@ Error ORCPlatformSupport::initialize(orc::JITDylib &JD) {
   int32_t result;
   auto E = ES.callSPSWrapper(WrapperAddr->getAddress(),
  result, DSOHandles[&JD]);
-  if (result)
+  if (E)
+return E;
+  else if (result)
 return make_error("dlupdate failed",
inconvertibleErrorCode());
-  return E;
-}
-return ES.callSPSWrapper(WrapperAddr->getAddress(),
-   DSOHandles[&JD], JD.getName(),
-   int32_t(ORC_RT_RTLD_LAZY));
+} else
+  return ES.callSPSWrapper(WrapperAddr->getAddress(),
+ DSOHandles[&JD], JD.getName(),
+ int32_t(ORC_RT_RTLD_LAZY));
   } else
 return WrapperAddr.takeError();
+
+  return Error::success(

[clang] [llvm] [Clang-Repl] Add pipe-based redirection and fetch PID of launched executor (PR #147478)

2025-07-08 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 updated 
https://github.com/llvm/llvm-project/pull/147478

>From fbe4344831538480be33accd35ef618c6d0e50b3 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Tue, 1 Jul 2025 18:55:21 +0530
Subject: [PATCH 1/4] pipes for redirection in oop jit

---
 .../clang/Interpreter/RemoteJITUtils.h|  6 +++-
 clang/lib/Interpreter/RemoteJITUtils.cpp  | 32 ++-
 llvm/lib/ExecutionEngine/Orc/LLJIT.cpp| 15 +
 3 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Interpreter/RemoteJITUtils.h 
b/clang/include/clang/Interpreter/RemoteJITUtils.h
index 8705a3b1f669d..825143f008a45 100644
--- a/clang/include/clang/Interpreter/RemoteJITUtils.h
+++ b/clang/include/clang/Interpreter/RemoteJITUtils.h
@@ -26,7 +26,7 @@
 
 llvm::Expected>
 launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
-   llvm::StringRef SlabAllocateSizeString);
+   llvm::StringRef SlabAllocateSizeString, int stdin_fd = 0, int 
stdout_fd = 1, int stderr_fd = 2);
 
 /// Create a JITLinkExecutor that connects to the given network address
 /// through a TCP socket. A valid NetworkAddress provides hostname and port,
@@ -35,4 +35,8 @@ llvm::Expected>
 connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
  llvm::StringRef SlabAllocateSizeString);
 
+/// Get the PID of the last launched executor.
+/// This is useful for debugging or for cleanup purposes.
+pid_t getLastLaunchedExecutorPID();
+
 #endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
diff --git a/clang/lib/Interpreter/RemoteJITUtils.cpp 
b/clang/lib/Interpreter/RemoteJITUtils.cpp
index c0e663b764785..8324aeaaf689c 100644
--- a/clang/lib/Interpreter/RemoteJITUtils.cpp
+++ b/clang/lib/Interpreter/RemoteJITUtils.cpp
@@ -33,6 +33,8 @@
 using namespace llvm;
 using namespace llvm::orc;
 
+static std::atomic LaunchedExecutorPID{-1};
+
 Expected getSlabAllocSize(StringRef SizeString) {
   SizeString = SizeString.trim();
 
@@ -91,7 +93,7 @@ createSharedMemoryManager(SimpleRemoteEPC &SREPC,
 
 Expected>
 launchExecutor(StringRef ExecutablePath, bool UseSharedMemory,
-   llvm::StringRef SlabAllocateSizeString) {
+   llvm::StringRef SlabAllocateSizeString, int stdin_fd, int 
stdout_fd, int stderr_fd) {
 #ifndef LLVM_ON_UNIX
   // FIXME: Add support for Windows.
   return make_error("-" + ExecutablePath +
@@ -134,6 +136,28 @@ launchExecutor(StringRef ExecutablePath, bool 
UseSharedMemory,
 close(ToExecutor[WriteEnd]);
 close(FromExecutor[ReadEnd]);
 
+if (stdin_fd != 0) {
+  dup2(stdin_fd, STDIN_FILENO);
+  if (stdin_fd != STDIN_FILENO)
+close(stdin_fd);
+}
+
+if (stdout_fd != 1) {
+  dup2(stdout_fd, STDOUT_FILENO);
+  if (stdout_fd != STDOUT_FILENO)
+close(stdout_fd);
+
+  setvbuf(stdout, NULL, _IONBF, 0);
+}
+
+if (stderr_fd != 2) {
+  dup2(stderr_fd, STDERR_FILENO);
+  if (stderr_fd != STDERR_FILENO)
+close(stderr_fd);
+
+  setvbuf(stderr, NULL, _IONBF, 0);
+}
+
 // Execute the child process.
 std::unique_ptr ExecutorPath, FDSpecifier;
 {
@@ -155,6 +179,8 @@ launchExecutor(StringRef ExecutablePath, bool 
UseSharedMemory,
  << ExecutorPath.get() << "\"\n";
   exit(1);
 }
+  } else {
+ LaunchedExecutorPID = ChildPID;
   }
   // else we're the parent...
 
@@ -265,3 +291,7 @@ connectTCPSocket(StringRef NetworkAddress, bool 
UseSharedMemory,
   std::move(S), *SockFD, *SockFD);
 #endif
 }
+
+pid_t getLastLaunchedExecutorPID() {
+  return LaunchedExecutorPID;
+}
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp 
b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 4e3c09e970cbe..67bb7dd8ad08f 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -632,16 +632,19 @@ Error ORCPlatformSupport::initialize(orc::JITDylib &JD) {
   int32_t result;
   auto E = ES.callSPSWrapper(WrapperAddr->getAddress(),
  result, DSOHandles[&JD]);
-  if (result)
+  if (E)
+return E;
+  else if (result)
 return make_error("dlupdate failed",
inconvertibleErrorCode());
-  return E;
-}
-return ES.callSPSWrapper(WrapperAddr->getAddress(),
-   DSOHandles[&JD], JD.getName(),
-   int32_t(ORC_RT_RTLD_LAZY));
+} else
+  return ES.callSPSWrapper(WrapperAddr->getAddress(),
+ DSOHandles[&JD], JD.getName(),
+ int32_t(ORC_RT_RTLD_LAZY));
   } else
 return WrapperAddr.takeError();
+
+  return Error::success();
 }
 
 Error ORCPlatformSupport::deinitialize(orc::JITDylib &JD) {

>From b207b1f4c4e639d86d0a03d28437f7e170f5d400 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Mon, 7 Jul 2025 11:50:20 +0530

[clang] [llvm] [Clang-Repl] Add pipe-based redirection and fetch PID of launched executor (PR #147478)

2025-07-09 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 updated 
https://github.com/llvm/llvm-project/pull/147478

>From fbe4344831538480be33accd35ef618c6d0e50b3 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Tue, 1 Jul 2025 18:55:21 +0530
Subject: [PATCH 1/7] pipes for redirection in oop jit

---
 .../clang/Interpreter/RemoteJITUtils.h|  6 +++-
 clang/lib/Interpreter/RemoteJITUtils.cpp  | 32 ++-
 llvm/lib/ExecutionEngine/Orc/LLJIT.cpp| 15 +
 3 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Interpreter/RemoteJITUtils.h 
b/clang/include/clang/Interpreter/RemoteJITUtils.h
index 8705a3b1f669d..825143f008a45 100644
--- a/clang/include/clang/Interpreter/RemoteJITUtils.h
+++ b/clang/include/clang/Interpreter/RemoteJITUtils.h
@@ -26,7 +26,7 @@
 
 llvm::Expected>
 launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
-   llvm::StringRef SlabAllocateSizeString);
+   llvm::StringRef SlabAllocateSizeString, int stdin_fd = 0, int 
stdout_fd = 1, int stderr_fd = 2);
 
 /// Create a JITLinkExecutor that connects to the given network address
 /// through a TCP socket. A valid NetworkAddress provides hostname and port,
@@ -35,4 +35,8 @@ llvm::Expected>
 connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
  llvm::StringRef SlabAllocateSizeString);
 
+/// Get the PID of the last launched executor.
+/// This is useful for debugging or for cleanup purposes.
+pid_t getLastLaunchedExecutorPID();
+
 #endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
diff --git a/clang/lib/Interpreter/RemoteJITUtils.cpp 
b/clang/lib/Interpreter/RemoteJITUtils.cpp
index c0e663b764785..8324aeaaf689c 100644
--- a/clang/lib/Interpreter/RemoteJITUtils.cpp
+++ b/clang/lib/Interpreter/RemoteJITUtils.cpp
@@ -33,6 +33,8 @@
 using namespace llvm;
 using namespace llvm::orc;
 
+static std::atomic LaunchedExecutorPID{-1};
+
 Expected getSlabAllocSize(StringRef SizeString) {
   SizeString = SizeString.trim();
 
@@ -91,7 +93,7 @@ createSharedMemoryManager(SimpleRemoteEPC &SREPC,
 
 Expected>
 launchExecutor(StringRef ExecutablePath, bool UseSharedMemory,
-   llvm::StringRef SlabAllocateSizeString) {
+   llvm::StringRef SlabAllocateSizeString, int stdin_fd, int 
stdout_fd, int stderr_fd) {
 #ifndef LLVM_ON_UNIX
   // FIXME: Add support for Windows.
   return make_error("-" + ExecutablePath +
@@ -134,6 +136,28 @@ launchExecutor(StringRef ExecutablePath, bool 
UseSharedMemory,
 close(ToExecutor[WriteEnd]);
 close(FromExecutor[ReadEnd]);
 
+if (stdin_fd != 0) {
+  dup2(stdin_fd, STDIN_FILENO);
+  if (stdin_fd != STDIN_FILENO)
+close(stdin_fd);
+}
+
+if (stdout_fd != 1) {
+  dup2(stdout_fd, STDOUT_FILENO);
+  if (stdout_fd != STDOUT_FILENO)
+close(stdout_fd);
+
+  setvbuf(stdout, NULL, _IONBF, 0);
+}
+
+if (stderr_fd != 2) {
+  dup2(stderr_fd, STDERR_FILENO);
+  if (stderr_fd != STDERR_FILENO)
+close(stderr_fd);
+
+  setvbuf(stderr, NULL, _IONBF, 0);
+}
+
 // Execute the child process.
 std::unique_ptr ExecutorPath, FDSpecifier;
 {
@@ -155,6 +179,8 @@ launchExecutor(StringRef ExecutablePath, bool 
UseSharedMemory,
  << ExecutorPath.get() << "\"\n";
   exit(1);
 }
+  } else {
+ LaunchedExecutorPID = ChildPID;
   }
   // else we're the parent...
 
@@ -265,3 +291,7 @@ connectTCPSocket(StringRef NetworkAddress, bool 
UseSharedMemory,
   std::move(S), *SockFD, *SockFD);
 #endif
 }
+
+pid_t getLastLaunchedExecutorPID() {
+  return LaunchedExecutorPID;
+}
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp 
b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 4e3c09e970cbe..67bb7dd8ad08f 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -632,16 +632,19 @@ Error ORCPlatformSupport::initialize(orc::JITDylib &JD) {
   int32_t result;
   auto E = ES.callSPSWrapper(WrapperAddr->getAddress(),
  result, DSOHandles[&JD]);
-  if (result)
+  if (E)
+return E;
+  else if (result)
 return make_error("dlupdate failed",
inconvertibleErrorCode());
-  return E;
-}
-return ES.callSPSWrapper(WrapperAddr->getAddress(),
-   DSOHandles[&JD], JD.getName(),
-   int32_t(ORC_RT_RTLD_LAZY));
+} else
+  return ES.callSPSWrapper(WrapperAddr->getAddress(),
+ DSOHandles[&JD], JD.getName(),
+ int32_t(ORC_RT_RTLD_LAZY));
   } else
 return WrapperAddr.takeError();
+
+  return Error::success();
 }
 
 Error ORCPlatformSupport::deinitialize(orc::JITDylib &JD) {

>From b207b1f4c4e639d86d0a03d28437f7e170f5d400 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Mon, 7 Jul 2025 11:50:20 +0530

[clang] [llvm] [Clang-Repl] Add custom function as lambda in launchExecutor and fetch PID of launched executor (PR #147478)

2025-07-09 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 edited 
https://github.com/llvm/llvm-project/pull/147478
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Clang-Repl] Add custom function as lambda in launchExecutor and fetch PID of launched executor (PR #147478)

2025-07-09 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 edited 
https://github.com/llvm/llvm-project/pull/147478
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Clang-Repl] Add custom function as lambda in launchExecutor and fetch PID of launched executor (PR #147478)

2025-07-09 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 updated 
https://github.com/llvm/llvm-project/pull/147478

>From fbe4344831538480be33accd35ef618c6d0e50b3 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Tue, 1 Jul 2025 18:55:21 +0530
Subject: [PATCH 1/8] pipes for redirection in oop jit

---
 .../clang/Interpreter/RemoteJITUtils.h|  6 +++-
 clang/lib/Interpreter/RemoteJITUtils.cpp  | 32 ++-
 llvm/lib/ExecutionEngine/Orc/LLJIT.cpp| 15 +
 3 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Interpreter/RemoteJITUtils.h 
b/clang/include/clang/Interpreter/RemoteJITUtils.h
index 8705a3b1f669d..825143f008a45 100644
--- a/clang/include/clang/Interpreter/RemoteJITUtils.h
+++ b/clang/include/clang/Interpreter/RemoteJITUtils.h
@@ -26,7 +26,7 @@
 
 llvm::Expected>
 launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
-   llvm::StringRef SlabAllocateSizeString);
+   llvm::StringRef SlabAllocateSizeString, int stdin_fd = 0, int 
stdout_fd = 1, int stderr_fd = 2);
 
 /// Create a JITLinkExecutor that connects to the given network address
 /// through a TCP socket. A valid NetworkAddress provides hostname and port,
@@ -35,4 +35,8 @@ llvm::Expected>
 connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
  llvm::StringRef SlabAllocateSizeString);
 
+/// Get the PID of the last launched executor.
+/// This is useful for debugging or for cleanup purposes.
+pid_t getLastLaunchedExecutorPID();
+
 #endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
diff --git a/clang/lib/Interpreter/RemoteJITUtils.cpp 
b/clang/lib/Interpreter/RemoteJITUtils.cpp
index c0e663b764785..8324aeaaf689c 100644
--- a/clang/lib/Interpreter/RemoteJITUtils.cpp
+++ b/clang/lib/Interpreter/RemoteJITUtils.cpp
@@ -33,6 +33,8 @@
 using namespace llvm;
 using namespace llvm::orc;
 
+static std::atomic LaunchedExecutorPID{-1};
+
 Expected getSlabAllocSize(StringRef SizeString) {
   SizeString = SizeString.trim();
 
@@ -91,7 +93,7 @@ createSharedMemoryManager(SimpleRemoteEPC &SREPC,
 
 Expected>
 launchExecutor(StringRef ExecutablePath, bool UseSharedMemory,
-   llvm::StringRef SlabAllocateSizeString) {
+   llvm::StringRef SlabAllocateSizeString, int stdin_fd, int 
stdout_fd, int stderr_fd) {
 #ifndef LLVM_ON_UNIX
   // FIXME: Add support for Windows.
   return make_error("-" + ExecutablePath +
@@ -134,6 +136,28 @@ launchExecutor(StringRef ExecutablePath, bool 
UseSharedMemory,
 close(ToExecutor[WriteEnd]);
 close(FromExecutor[ReadEnd]);
 
+if (stdin_fd != 0) {
+  dup2(stdin_fd, STDIN_FILENO);
+  if (stdin_fd != STDIN_FILENO)
+close(stdin_fd);
+}
+
+if (stdout_fd != 1) {
+  dup2(stdout_fd, STDOUT_FILENO);
+  if (stdout_fd != STDOUT_FILENO)
+close(stdout_fd);
+
+  setvbuf(stdout, NULL, _IONBF, 0);
+}
+
+if (stderr_fd != 2) {
+  dup2(stderr_fd, STDERR_FILENO);
+  if (stderr_fd != STDERR_FILENO)
+close(stderr_fd);
+
+  setvbuf(stderr, NULL, _IONBF, 0);
+}
+
 // Execute the child process.
 std::unique_ptr ExecutorPath, FDSpecifier;
 {
@@ -155,6 +179,8 @@ launchExecutor(StringRef ExecutablePath, bool 
UseSharedMemory,
  << ExecutorPath.get() << "\"\n";
   exit(1);
 }
+  } else {
+ LaunchedExecutorPID = ChildPID;
   }
   // else we're the parent...
 
@@ -265,3 +291,7 @@ connectTCPSocket(StringRef NetworkAddress, bool 
UseSharedMemory,
   std::move(S), *SockFD, *SockFD);
 #endif
 }
+
+pid_t getLastLaunchedExecutorPID() {
+  return LaunchedExecutorPID;
+}
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp 
b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 4e3c09e970cbe..67bb7dd8ad08f 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -632,16 +632,19 @@ Error ORCPlatformSupport::initialize(orc::JITDylib &JD) {
   int32_t result;
   auto E = ES.callSPSWrapper(WrapperAddr->getAddress(),
  result, DSOHandles[&JD]);
-  if (result)
+  if (E)
+return E;
+  else if (result)
 return make_error("dlupdate failed",
inconvertibleErrorCode());
-  return E;
-}
-return ES.callSPSWrapper(WrapperAddr->getAddress(),
-   DSOHandles[&JD], JD.getName(),
-   int32_t(ORC_RT_RTLD_LAZY));
+} else
+  return ES.callSPSWrapper(WrapperAddr->getAddress(),
+ DSOHandles[&JD], JD.getName(),
+ int32_t(ORC_RT_RTLD_LAZY));
   } else
 return WrapperAddr.takeError();
+
+  return Error::success();
 }
 
 Error ORCPlatformSupport::deinitialize(orc::JITDylib &JD) {

>From b207b1f4c4e639d86d0a03d28437f7e170f5d400 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Mon, 7 Jul 2025 11:50:20 +0530

[clang] [llvm] [Clang-Repl] Add custom function as lambda in launchExecutor and fetch PID of launched executor (PR #147478)

2025-07-09 Thread Abhinav Kumar via cfe-commits


@@ -23,10 +23,19 @@
 #include 
 #include 
 #include 
+#ifdef LLVM_ON_UNIX
+#include 
+#else
+// Windows/MSVC fallback
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+#endif

kr-2003 wrote:

yes, i don't think we need these now

https://github.com/llvm/llvm-project/pull/147478
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Clang-Repl] Add custom function as lambda in launchExecutor and fetch PID of launched executor (PR #147478)

2025-07-09 Thread Abhinav Kumar via cfe-commits

kr-2003 wrote:

> We will probably need a test in clang/unittest/Interpreter

Ok. So, replicating clang-repl's way of creating interpreter when 
out-of-process should work, right?

https://github.com/llvm/llvm-project/pull/147478
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits