[PATCH] D156858: Add Documentation for Execution Results Handling in Clang-REPL

2023-08-13 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 549745.
Krishna-13-cyber added a comment.

- Address the comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156858/new/

https://reviews.llvm.org/D156858

Files:
  clang/docs/ClangRepl.rst
  clang/docs/conf.py

Index: clang/docs/conf.py
===
--- clang/docs/conf.py
+++ clang/docs/conf.py
@@ -49,6 +49,7 @@
 if sphinx.version_info >= (3, 0):
 # This requires 0.5 or later.
 extensions.append("recommonmark")
+extensions.append('sphinx.ext.graphviz')
 else:
 source_parsers = {".md": "recommonmark.parser.CommonMarkParser"}
 source_suffix[".md"] = "markdown"
Index: clang/docs/ClangRepl.rst
===
--- clang/docs/ClangRepl.rst
+++ clang/docs/ClangRepl.rst
@@ -213,6 +213,411 @@
 automatic language interoperability. It also helps static languages such as C/C++ become
 apt for data science.
 
+Execution Results Handling in Clang-Repl
+
+
+Execution Results Handling features discussed below help extend the Clang-Repl
+functionality by creating an interface between the execution results of a
+program and the compiled program.
+
+1. **Capture Execution Results**: This feature helps capture the execution results
+of a program and bring them back to the compiled program.
+
+2. **Dump Captured Execution Results**: This feature helps create a temporary dump
+for Value Printing/Automatic Printf, that is, to display the value and type of
+the captured data.
+
+
+1. Capture Execution Results
+
+
+In many cases, it is useful to bring back the program execution result to the
+compiled program. This result can be stored in an object of type **Value**.
+
+How Execution Results are captured (Value Synthesis):
+-
+
+The synthesizer chooses which expression to synthesize, and then it replaces
+the original expression with the synthesized expression. Depending on the
+expression type, it may choose to save an object (``LastValue``) of type 'value'
+while allocating memory to it (``SetValueWithAlloc()``), or not (
+``SetValueNoAlloc()``).
+
+.. graphviz::
+:name: valuesynthesis
+:caption: Value Synthesis
+:alt: Shows how an object of type 'Value' is synthesized
+:align: center
+
+ digraph "valuesynthesis" {
+ rankdir="LR";
+ graph [fontname="Verdana", fontsize="12"];
+ node [fontname="Verdana", fontsize="12"];
+ edge [fontname="Sans", fontsize="9"];
+
+ start [label=" Create an Object \n 'Last Value' \n of type 'Value' ", shape="note", fontcolor=white, fillcolor="#ff", style=filled];
+ assign [label=" Assign the result \n to the 'LastValue' \n (based on respective \n Memory Allocation \n scenario) ", shape="box"]
+ print [label=" Pretty Print \n the Value Object ", shape="Msquare", fillcolor="yellow", style=filled];
+ start -> assign;
+ assign -> print;
+
+   subgraph SynthesizeExpression {
+ synth [label=" SynthesizeExpr() ", shape="note", fontcolor=white, fillcolor="#ff", style=filled];
+ mem [label=" New Memory \n Allocation? ", shape="diamond"];
+ withaloc [label=" SetValueWithAlloc() ", shape="box"];
+ noaloc [label=" SetValueNoAlloc() ", shape="box"];
+ right [label=" 1. RValue Structure \n (a temporary value)", shape="box"];
+ left2 [label=" 2. LValue Structure \n (a variable with \n an address)", shape="box"];
+ left3 [label=" 3. Built-In Type \n (int, float, etc.)", shape="box"];
+ output [label=" move to 'Assign' step ", shape="box"];
+
+ synth -> mem;
+ mem -> withaloc [label="Yes"];
+ mem -> noaloc [label="No"];
+ withaloc -> right;
+ noaloc -> left2;
+ noaloc -> left3;
+ right -> output;
+ left2 -> output;
+ left3 -> output;
+  }
+output -> assign
+  }
+
+Where is the captured result stored?
+
+
+``LastValue`` holds the last result of the value printing. It is a class member
+because it can be accessed even after subsequent inputs.
+
+**Note:** If no value printing happens, then it is in an invalid state.
+
+Improving Efficiency and User Experience
+
+
+The Value object is essentially used to create a mapping between an expression
+'type' and the allocated 'memory'. Built-in types (bool, char, int,
+float, double, etc.) are copyable. Their their memory allocation size is known
+and the Value object can introduce a small-buffer optimization.
+In case of objects, the ``Value`` class provides reference-counted memory
+management.
+
+The 

[PATCH] D156858: Add Documentation for Execution Results Handling in Clang-REPL

2023-08-10 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 549034.
Krishna-13-cyber added a comment.

- Address the comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156858/new/

https://reviews.llvm.org/D156858

Files:
  clang/docs/ClangRepl.rst
  clang/docs/autoprint.png
  clang/docs/prettyprint.png
  clang/docs/valuesynth.png

Index: clang/docs/ClangRepl.rst
===
--- clang/docs/ClangRepl.rst
+++ clang/docs/ClangRepl.rst
@@ -215,6 +215,319 @@
 automatic language interoperability. It also helps static languages such as C/C++ become
 apt for data science.
 
+Execution Results Handling in Clang-Repl
+
+
+Execution Results Handling features discussed below help extend the Clang-REPL 
+functionality by creating an interface between the execution results of a 
+program and the compiled program.
+
+1. **Capture Execution Results**: This feature helps capture the execution results 
+of a program and bring them back to the compiled program.
+
+2. **Dump Captured Execution Results**: This feature helps create a temporary dump 
+for Value Printing/Automatic Printf, that is, to display the value and type of 
+the captured data. 
+
+
+1. Capture Execution Results
+
+
+In many cases, it is useful to bring back the program execution result to the 
+compiled program. This result can be stored in an object of type **Value**.
+
+How Execution Results are captured (Value Synthesis):
+-
+
+The synthesizer chooses which expression to synthesize, and then it replaces 
+the original expression with the synthesized expression. Depending on the 
+expression type, it may choose to save an object (``LastValue``) of type 'value'
+while allocating memory to it (``SetValueWithAlloc()``), or not (
+``SetValueNoAlloc()``).
+
+.. image:: valuesynth.png
+   :align: center
+   :alt: valuesynth design
+
+Where is the captured result stored?
+
+
+``LastValue`` holds the last result of the value printing. It is a class member 
+because it can be accessed even after subsequent inputs. 
+
+**Note:** If no value printing happens, then it is in an invalid state. 
+
+Improving Efficiency and User Experience
+
+
+The Value object is essentially used to create a mapping between an expression 
+'type' and the 'memory' to be allocated. Built-in types (bool, char, int, 
+float, double, etc.) are simpler, since their memory allocation size is known. 
+In case of objects, a pointer can be saved, since the size of the object is 
+not known.
+
+For further improvement, the underlying Clang Type is also identified. For 
+example, ``X(char, Char_S)``, where ``Char_S`` is the Clang type. Clang types are 
+very efficient, which is important since these will be used in hotspots (high 
+utilization areas of the program). The ``Value.h`` header file has a very low 
+token count and was developed with strict constraints in mind, since it can 
+affect the performance of the interpreter.
+
+This also enables the user to receive the computed 'type' back in their code 
+and then transform the type into something else (e.g., transform a double into 
+a float). Normally, the compiler can handle these conversions transparently, 
+but in interpreter mode, the compiler cannot see all the 'from' and 'to' types,
+so it cannot implicitly do the conversions. So this logic enables providing 
+these conversions on request. 
+
+On-request conversions can help improve the user experience, by allowing 
+conversion to a desired 'to' type, when the 'from' type is unknown or unclear
+
+Significance of this Feature
+
+
+The 'Value' object enables wrapping a memory region that comes from the 
+JIT, and bringing it back to the compiled code (and vice versa). 
+This is a very useful functionality when:
+
+- connecting an interpreter to the compiled code, or
+- connecting an interpreter in another language.
+
+For example, the CPPYY code makes use of this feature to enable running 
+C++ within Python. It enables transporting values/information between C++ 
+and Python.
+
+In a nutshell, this feature enables a new way of developing code, paving the 
+way for language interoperability and easier interactive programming.
+
+Implementation Details
+==
+
+Interpreter as a REPL vs. as a Library
+--
+
+1 - If we're using the interpreter in interactive (REPL) mode, it will dump 
+the value (i.e., value printing).
+
+.. code-block:: console
+
+  if (LastValue.isValid()) {
+if (!V) {
+  LastValue.dump();
+  LastValue.clear();
+} else
+  *V = std::move(LastValue);
+  }
+
+
+2 - If we're using the interpreter as a library, then it will pass the value 
+to the user.
+
+Incremental AST Consumer

[PATCH] D156858: Add Documentation for Execution Results Handling in Clang-REPL

2023-08-06 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 547574.
Krishna-13-cyber added a comment.

- Update section of Execution Results Handling in Clang-REPL


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156858/new/

https://reviews.llvm.org/D156858

Files:
  clang/docs/ClangRepl.rst
  clang/docs/ExecutionResultsHandling.rst
  clang/docs/autoprint.png
  clang/docs/index.rst
  clang/docs/prettyprint.png
  clang/docs/valuesynth.png

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -93,6 +93,7 @@
ClangOffloadBundler
ClangOffloadPackager
ClangRepl
+   ExecutionResultsHandling
 
 Design Documents
 
Index: clang/docs/ExecutionResultsHandling.rst
===
--- /dev/null
+++ clang/docs/ExecutionResultsHandling.rst
@@ -0,0 +1,333 @@
+=
+Execution Results Handling in Clang-REPL
+=
+
+Execution Results Handling features discussed below help extend the Clang-REPL 
+functionality by creating an interface between the execution results of a 
+program and the compiled program.
+
+1. **Capture Execution Results**: This feature helps capture the execution results 
+of a program and bring them back to the compiled program.
+
+2. **Dump Captured Execution Results**: This feature helps create a temporary dump 
+for Value Printing/Automatic Printf, that is, to display the value and type of 
+the captured data. 
+
+
+1. Capture Execution Results
+
+
+In many cases, it is useful to bring back the program execution result to the 
+compiled program. This result can be stored in an object of type **Value**.
+
+How Execution Results are captured (Value Synthesis):
+-
+
+The synthesizer chooses which expression to synthesize, and then it replaces 
+the original expression with the synthesized expression. Depending on the 
+expression type, it may choose to save an object (``LastValue``) of type 'value'
+while allocating memory to it (``SetValueWithAlloc()``), or not (
+``SetValueNoAlloc()``).
+
+.. image:: valuesynth.png
+   :align: center
+   :alt: valuesynth design
+
+Where is the captured result stored?
+
+
+``LastValue`` holds the last result of the value printing. It is a class member 
+because it can be accessed even after subsequent inputs. 
+
+**Note:** If no value printing happens, then it is in an invalid state. 
+
+Improving Efficiency and User Experience
+
+
+The Value object is essentially used to create a mapping between an expression 
+'type' and the 'memory' to be allocated. Built-in types (bool, char, int, 
+float, double, etc.) are simpler, since their memory allocation size is known. 
+In case of objects, a pointer can be saved, since the size of the object is 
+not known.
+
+For further improvement, the underlying Clang Type is also identified. For 
+example, ``X(char, Char_S)``, where ``Char_S`` is the Clang type. Clang types are 
+very efficient, which is important since these will be used in hotspots (high 
+utilization areas of the program). The ``Value.h`` header file has a very low 
+token count and was developed with strict constraints in mind, since it can 
+affect the performance of the interpreter.
+
+This also enables the user to receive the computed 'type' back in their code 
+and then transform the type into something else (e.g., transform a double into 
+a float). Normally, the compiler can handle these conversions transparently, 
+but in interpreter mode, the compiler cannot see all the 'from' and 'to' types,
+so it cannot implicitly do the conversions. So this logic enables providing 
+these conversions on request. 
+
+On-request conversions can help improve the user experience, by allowing 
+conversion to a desired 'to' type, when the 'from' type is unknown or unclear
+
+Significance of this Feature
+
+
+The 'Value' object enables wrapping a memory region that comes from the 
+JIT, and bringing it back to the compiled code (and vice versa). 
+This is a very useful functionality when:
+
+- connecting an interpreter to the compiled code, or
+- connecting an interpreter in another language.
+
+For example, the CPPYY code makes use of this feature to enable running 
+C++ within Python. It enables transporting values/information between C++ 
+and Python.
+
+In a nutshell, this feature enables a new way of developing code, paving the 
+way for language interoperability and easier interactive programming.
+
+Implementation Details
+==
+
+Interpreter as a REPL vs. as a Library
+--
+
+1 - If we're using the interpreter in interactive (REPL) mode, it will dump 
+the 

[PATCH] D156858: Add Documentation for Execution Results Handling in Clang-REPL

2023-08-06 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 547529.
Krishna-13-cyber added a comment.

- Address the comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156858/new/

https://reviews.llvm.org/D156858

Files:
  clang/docs/ClangRepl.rst
  clang/docs/ExecutionResultsHandling.rst
  clang/docs/autoprint.png
  clang/docs/index.rst
  clang/docs/prettyprint.png
  clang/docs/valuesynth.png

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -93,6 +93,7 @@
ClangOffloadBundler
ClangOffloadPackager
ClangRepl
+   ExecutionResultsHandling
 
 Design Documents
 
Index: clang/docs/ExecutionResultsHandling.rst
===
--- /dev/null
+++ clang/docs/ExecutionResultsHandling.rst
@@ -0,0 +1,333 @@
+=
+Execution Results Handling in Clang-REPL
+=
+
+Execution Results Handling features discussed below help extend the Clang-REPL 
+functionality by creating an interface between the execution results of a 
+program and the compiled program.
+
+1. **Capture Execution Results**: This feature helps capture the execution results 
+of a program and bring them back to the compiled program.
+
+2. **Dump Captured Execution Results**: This feature helps create a temporary dump 
+for Value Printing/Automatic Printf, that is, to display the value and type of 
+the captured data. 
+
+
+1. Capture Execution Results
+
+
+In many cases, it is useful to bring back the program execution result to the 
+compiled program. This result can be stored in an object of type **Value**.
+
+How Execution Results are captured (Value Synthesis):
+-
+
+The synthesizer chooses which expression to synthesize, and then it replaces 
+the original expression with the synthesized expression. Depending on the 
+expression type, it may choose to save an object (``LastValue``) of type 'value'
+while allocating memory to it (``SetValueWithAlloc()``), or not (
+``SetValueNoAlloc()``).
+
+.. image:: valuesynth.png
+   :align: center
+   :alt: valuesynth design
+
+Where is the captured result stored?
+
+
+``LastValue`` holds the last result of the value printing. It is a class member 
+because it can be accessed even after subsequent inputs. 
+
+**Note:** If no value printing happens, then it is in an invalid state. 
+
+Improving Efficiency and User Experience
+
+
+The Value object is essentially used to create a mapping between an expression 
+'type' and the 'memory' to be allocated. Built-in types (bool, char, int, 
+float, double, etc.) are simpler, since their memory allocation size is known. 
+In case of objects, a pointer can be saved, since the size of the object is 
+not known.
+
+For further improvement, the underlying Clang Type is also identified. For 
+example, ``X(char, Char_S)``, where ``Char_S`` is the Clang type. Clang types are 
+very efficient, which is important since these will be used in hotspots (high 
+utilization areas of the program). The ``Value.h`` header file has a very low 
+token count and was developed with strict constraints in mind, since it can 
+affect the performance of the interpreter.
+
+This also enables the user to receive the computed 'type' back in their code 
+and then transform the type into something else (e.g., transform a double into 
+a float). Normally, the compiler can handle these conversions transparently, 
+but in interpreter mode, the compiler cannot see all the 'from' and 'to' types,
+so it cannot implicitly do the conversions. So this logic enables providing 
+these conversions on request. 
+
+On-request conversions can help improve the user experience, by allowing 
+conversion to a desired 'to' type, when the 'from' type is unknown or unclear
+
+Significance of this Feature
+
+
+The 'Value' object enables wrapping a memory region that comes from the 
+JIT, and bringing it back to the compiled code (and vice versa). 
+This is a very useful functionality when:
+
+- connecting an interpreter to the compiled code, or
+- connecting an interpreter in another language.
+
+For example, the CPPYY code makes use of this feature to enable running 
+C++ within Python. It enables transporting values/information between C++ 
+and Python.
+
+In a nutshell, this feature enables a new way of developing code, paving the 
+way for language interoperability and easier interactive programming.
+
+Implementation Details
+==
+
+Interpreter as a REPL vs. as a Library
+--
+
+1 - If we're using the interpreter in interactive (REPL) mode, it will dump 
+the value (i.e., value printing).
+
+.. 

[PATCH] D156858: Add Documentation for Execution Results Handling in Clang-REPL

2023-08-04 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 547231.
Krishna-13-cyber added a comment.

- Addressed the comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156858/new/

https://reviews.llvm.org/D156858

Files:
  clang/docs/ClangRepl.rst
  clang/docs/ExecutionResultsHandling.rst
  clang/docs/autoprint.png
  clang/docs/index.rst
  clang/docs/prettyprint.png
  clang/docs/valuesynth.png

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -93,6 +93,7 @@
ClangOffloadBundler
ClangOffloadPackager
ClangRepl
+   ExecutionResultsHandling
 
 Design Documents
 
Index: clang/docs/ExecutionResultsHandling.rst
===
--- /dev/null
+++ clang/docs/ExecutionResultsHandling.rst
@@ -0,0 +1,341 @@
+=
+Execution Results Handling in Clang-REPL
+=
+
+Execution Results Handling features discussed below help extend the Clang-REPL 
+functionality by creating an interface between the execution results of a 
+program and the compiled program.
+
+- The Automatic Printf feature makes it easy to display variable values 
+  during program execution.
+
+- The Value Synthesis feature helps store the execution results 
+  (to be able to bring them back to the compiled program).
+
+- The Pretty Printing feature helps create a temporary dump to display the value
+  and type (pretty print) of the desired data. 
+
+1. Automatic Printf
+===
+
+The `Automatic Printf` feature makes it easy to display variable values during 
+program execution. Using the `printf` function repeatedly is not required. 
+This is achieved using an extension in the `libclangInterpreter` library.
+
+To automatically print the value of an expression, simply write the expression 
+in the global scope **without a semicolon**.
+
+.. image:: autoprint.png
+   :align: center
+   :alt: autoprint design
+
+Examples
+
+.. code-block:: console
+
+clang-repl> int x = 42;
+clang-repl> x   // equivalent to calling printf("(int &) %d\n", x);
+(int &) 42
+
+clang-repl> std::vector v = {1,2,3};
+clang-repl> v  // This syntax is fine after D127284 
+(std::vector &) {1,2,3}
+
+clang-repl> "Hello, interactive C++!"
+(const char [24]) "Hello, interactive C++!"
+
+Significance of this feature
+
+
+Inspired by a similar implementation in `Cling `_,
+this feature added to upstream Clang repo has essentially extended the syntax of
+C++,so that it can be more helpful for people that are writing code for data 
+science applications.
+ 
+This is useful, for example, when you want to experiment with a set of values 
+against a set of functions, and you'd like to know the results right away. 
+This is similar to how Python works (hence its popularity in data science 
+research), but the superior performance of C++, along with this flexibility 
+makes it a more attractive option.
+
+Annotation Token (annot_repl_input_end)
+---
+
+This feature uses a new token (annot_repl_input_end) to consider printing the 
+value of an expression if it doesn't end with a semicolon. When parsing an 
+Expression Statement, if the last semicolon is missing, then the code will 
+pretend that there one and set a marker there for later utilization, and 
+continue parsing.
+
+A semicolon is normally required in C++, but this feature expands the C++ 
+syntax to handle cases where a missing semicolon is expected (i.e., when 
+handling an expression statement). It also makes sure that an error is not 
+generated for the missing semicolon in this specific case. 
+
+This is accomplished by identifying the end position of the user input 
+(expression statement). This helps store and return the expression statement 
+effectively, so that it can be printed (displayed to the user automatically).
+
+**Note:** This logic is only available for C++ for now, since part of the 
+implementation itself requires C++ features. Future versions may support more 
+languages.
+
+.. code-block:: console
+
+  Token *CurTok = nullptr;
+  // If the semicolon is missing at the end of REPL input, consider if
+  // we want to do value printing. Note this is only enabled in C++ mode
+  // since part of the implementation requires C++ language features.
+  // Note we shouldn't eat the token since the callback needs it.
+  if (Tok.is(tok::annot_repl_input_end) && Actions.getLangOpts().CPlusPlus)
+CurTok = 
+  else
+// Otherwise, eat the semicolon.
+ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
+
+  StmtResult R = handleExprStmt(Expr, StmtCtx);
+  if (CurTok && !R.isInvalid())
+CurTok->setAnnotationValue(R.get());
+
+  return R;
+}
+
+AST 

[PATCH] D156877: Update Clang-REPL docs with removing the redundant subsections

2023-08-02 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber created this revision.
Krishna-13-cyber added a reviewer: v.g.vassilev.
Herald added a project: All.
Krishna-13-cyber requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The Clang documentation is currently displaying 3 subsections for the same 
Clang-REPL docs instead of one subsection.
This patch fixes the above problem and displays just one subsection for 
Clang-REPL under the section of Using `Clang Tools`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156877

Files:
  clang/docs/ClangRepl.rst


Index: clang/docs/ClangRepl.rst
===
--- clang/docs/ClangRepl.rst
+++ clang/docs/ClangRepl.rst
@@ -47,7 +47,6 @@
 
 8. The machine code is then executed.
 
-===
 Build Instructions:
 ===
 
@@ -75,7 +74,6 @@
clang-repl>
 
 
-
 Clang-Repl Usage
 
 


Index: clang/docs/ClangRepl.rst
===
--- clang/docs/ClangRepl.rst
+++ clang/docs/ClangRepl.rst
@@ -47,7 +47,6 @@
 
 8. The machine code is then executed.
 
-===
 Build Instructions:
 ===
 
@@ -75,7 +74,6 @@
clang-repl>
 
 
-
 Clang-Repl Usage
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156858: Add Documentation for Execution Results Handling in Clang-REPL

2023-08-02 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber created this revision.
Krishna-13-cyber added reviewers: v.g.vassilev, davidlange6, QuillPusher.
Herald added a subscriber: arphaman.
Herald added a project: All.
Krishna-13-cyber requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds documentation for execution results handling in Clang-REPL with 
the below features:

- Automatic Printf feature
- Value Synthesis feature
- Pretty Printing feature


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156858

Files:
  clang/docs/ExecutionResultsHandling.rst
  clang/docs/autoprint.png
  clang/docs/index.rst
  clang/docs/prettyprint.png
  clang/docs/valuesynth.png

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -93,6 +93,7 @@
ClangOffloadBundler
ClangOffloadPackager
ClangRepl
+   ExecutionResultsHandling
 
 Design Documents
 
Index: clang/docs/ExecutionResultsHandling.rst
===
--- /dev/null
+++ clang/docs/ExecutionResultsHandling.rst
@@ -0,0 +1,381 @@
+=
+Execution Results Handling in Clang-REPL
+=
+
+Execution Results Handling features discussed below help extend the Clang-REPL 
+functionality by creating an interface between the execution results of a 
+program and the compiled program.
+
+- The Automatic Printf feature makes it easy to display variable values 
+  during program execution.
+
+- The Value Synthesis feature helps store the execution results 
+  (to be able to bring them back to the compiled program).
+
+- The Pretty Printing feature helps create a temporary dump to display the value
+  and type (pretty print) of the desired data. 
+
+1. Automatic Printf
+===
+
+The `Automatic Printf` feature makes it easy to display variable values during 
+program execution. Using the `printf` function repeatedly is not required. 
+This is achieved using an extension in the `libclangInterpreter` library.
+
+To automatically print the value of an expression, simply write the expression 
+in the global scope **without a semicolon**.
+
+.. image:: autoprint.png
+   :align: center
+   :alt: autoprint design
+
+Examples
+
+.. code-block:: console
+
+clang-repl> int x = 42;
+clang-repl> x   // equivalent to calling printf("(int &) %d\n", x);
+(int &) 42
+
+clang-repl> std::vector v = {1,2,3};
+clang-repl> v  // This syntax is fine after D127284 
+(std::vector &) {1,2,3}
+
+clang-repl> "Hello, interactive C++!"
+(const char [24]) "Hello, interactive C++!"
+
+Significance of this feature
+
+
+Inspired by a similar implementation in `Cling `_,
+this feature added to upstream Clang repo has essentially extended the syntax of C++,
+so that it can be more helpful for people that are writing code for data science applications.
+ 
+This is useful, for example, when you want to experiment with a set of values 
+against a set of functions, and you'd like to know the results right-away. 
+This is similar to how Python works (hence its popularity in data science 
+research), but the superior performance of C++, along with this flexibility 
+makes it a more attractive option.
+
+Annotation Token (annot_repl_input_end)
+---
+
+This feature uses a new token (annot_repl_input_end) to consider printing the 
+value of an expression if it doesn't end with a semicolon. When parsing an 
+Expression Statement, if the last semicolon is missing, then the code will 
+pretend that there one and set a marker there for later utilization, and 
+continue parsing.
+
+A semicolon is normally required in C++, but this feature expands the C++ 
+syntax to handle cases where a missing semicolon is expected (i.e., when 
+handling an expression statement). It also makes sure that an error is not 
+generated for the missing semicolon in this specific case. 
+
+This is accomplished by identifying the end position of the user input 
+(expression statement). This helps store and return the expression statement 
+effectively, so that it can be printed (displayed to the user automatically).
+
+**Note:** This logic is only available for C++ for now, since part of the 
+implementation itself requires C++ features. Future versions may support more 
+languages.
+
+.. code-block:: console
+
+  Token *CurTok = nullptr;
+  // If the semicolon is missing at the end of REPL input, consider if
+  // we want to do value printing. Note this is only enabled in C++ mode
+  // since part of the implementation requires C++ language features.
+  // Note we shouldn't eat the token since the callback needs it.
+  if (Tok.is(tok::annot_repl_input_end) && Actions.getLangOpts().CPlusPlus)
+CurTok = 
+ 

[PATCH] D147888: Update declaration message of extern linkage

2023-07-02 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber added a comment.

In D147888#4466998 , @aaron.ballman 
wrote:

> I think the existing wording is pretty reasonable, changing "non-static 
> declaration" into "extern declaration" isn't really giving the user any more 
> information to help them resolve the issue. "please pick exactly one" doesn't 
> seem likely to help the user either -- they already know there's a conflict, 
> so picking one is already the solution the user is likely to have in mind. 
> The hard part for the user is with figuring which one to pick, but we have no 
> way to help them make that choice. So I'm not certain changes are needed in 
> this space (I'm not opposed either), but I do think the idea @cjdb had to 
> combine all these diagnostics into one using `%select` could be helpful. 
> However, there are enough options that it could also be pretty complex to 
> reason about. There's static, extern, and thread-local, as well as "non-" 
> versions of each of those, so there are quite a few combinations.

Yes I agree with this,
Changing the whole set of diagnostics will be quite challenging, but I think 
`extern` has an edge over  `non-static` declaration when we are able to see the 
diagnostics in gcc if are not going with the `pick-exactly one` convention.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147888/new/

https://reviews.llvm.org/D147888

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


[PATCH] D152109: Update clang-repl documentation

2023-06-30 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber added a comment.

In D152109#4464563 , @v.g.vassilev 
wrote:

> LGTM! If you don't have commit access I can commit this on your behalf.

Yes,
It would be great if you could land it on my behalf!
Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152109/new/

https://reviews.llvm.org/D152109

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


[PATCH] D147888: Update declaration message of extern linkage

2023-06-30 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber added a comment.

In D147888#4463163 , @tbaeder wrote:

> Ping.

Thanks for the ping! Does this require any further modification?
I think if we will have to change the whole set of diagnostics if we go with 
this change of `pick exactly one ` convention.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147888/new/

https://reviews.llvm.org/D147888

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


[PATCH] D152109: Update clang-repl documentation

2023-06-30 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 536221.
Krishna-13-cyber marked 2 inline comments as done.
Krishna-13-cyber added a comment.

- Update with addressing the comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152109/new/

https://reviews.llvm.org/D152109

Files:
  clang/docs/ClangRepl.rst

Index: clang/docs/ClangRepl.rst
===
--- clang/docs/ClangRepl.rst
+++ clang/docs/ClangRepl.rst
@@ -16,22 +16,6 @@
 of Cling upstream, making them useful and available to a broader audience.
 
 
-
-Clang-Repl Usage
-
-
-
-.. code-block:: text
-
-  clang-repl> #include 
-  clang-repl> int f() { std::cout << "Hello Interpreted World!\n"; return 0; }
-  clang-repl> auto r = f();
-  // Prints Hello Interpreted World!
-
-Note that the implementation is not complete and highly experimental. We do
-not yet support statements on the global scope, for example.
-
-
 Clang-Repl Basic Data Flow
 ==
 
@@ -63,14 +47,173 @@
 
 8. The machine code is then executed.
 
+===
+Build Instructions:
+===
+
+
+.. code-block:: console
+
+   $ cd llvm-project
+   $ mkdir build
+   $ cd build
+   $ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" ../llvm
+
+**Note here**, above RelWithDebInfo - Debug / Release
+
+.. code-block:: console
+
+   cmake --build . --target clang clang-repl -j n
+  OR
+   cmake --build . --target clang clang-repl
+
+**Clang-repl** is built under llvm-project/build/bin. Proceed into the directory **llvm-project/build/bin**
+
+.. code-block:: console
+
+   ./clang-repl
+   clang-repl>
+
+
+
+Clang-Repl Usage
+
+
+**Clang-Repl** is an interactive C++ interpreter that allows for incremental
+compilation. It supports interactive programming for C++ in a
+read-evaluate-print-loop (REPL) style. It uses Clang as a library to compile the
+high level programming language into LLVM IR. Then the LLVM IR is executed by
+the LLVM just-in-time (JIT) infrastructure.
+
+
+Basic:
+==
+
+.. code-block:: text
+
+  clang-repl> #include 
+  clang-repl> int f() { std::cout << "Hello Interpreted World!\n"; return 0; }
+  clang-repl> auto r = f();
+   // Prints Hello Interpreted World!
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> using namespace std;
+   clang-repl> std::cout << "Welcome to CLANG-REPL" << std::endl;
+   Welcome to CLANG-REPL
+   // Prints Welcome to CLANG-REPL
+
+
+Function Definitions and Calls:
+===
+
+.. code-block:: text
+
+   clang-repl> #include 
+   clang-repl> int sum(int a, int b){ return a+b; };
+   clang-repl> int c = sum(9,10);
+   clang-repl> std::cout << c << std::endl;
+   19
+   clang-repl>
+
+Iterative Structures:
+=
+
+.. code-block:: text
+
+   clang-repl> #include 
+   clang-repl> for (int i = 0;i < 3;i++){ std::cout << i << std::endl;}
+   0
+   1
+   2
+   clang-repl> while(i < 7){ i++; std::cout << i << std::endl;}
+   4
+   5
+   6
+   7
+
+Classes and Structures:
+===
+
+.. code-block:: text
+
+   clang-repl> #include 
+   clang-repl> class Rectangle {int width, height; public: void set_values (int,int);\
+   clang-repl... int area() {return width*height;}};
+   clang-repl>  void Rectangle::set_values (int x, int y) { width = x;height = y;}
+   clang-repl> int main () { Rectangle rect;rect.set_values (3,4);\
+   clang-repl... std::cout << "area: " << rect.area() << std::endl;\
+   clang-repl... return 0;}
+   clang-repl> main();
+   area: 12
+   clang-repl>
+   // Note: This '\' can be used for continuation of the statements in the next line
+
+Lamdas:
+===
+
+.. code-block:: text
+
+   clang-repl> #include 
+   clang-repl> using namespace std;
+   clang-repl> auto welcome = []()  { std::cout << "Welcome to REPL" << std::endl;};
+   clang-repl> welcome();
+   Welcome to REPL
+
+Using Dynamic Library:
+==
+
+.. code-block:: text
+
+   clang-repl> %lib print.so
+   clang-repl> #include"print.hpp"
+   clang-repl> print(9);
+   9
+
+**Generation of dynamic library**
+
+.. code-block:: text
+
+   // print.cpp
+   #include 
+   #include "print.hpp"
+
+   void print(int a)
+   {
+  std::cout << a << std::endl;
+   }
+
+   // print.hpp
+   void print (int a);
+
+   // Commands
+   clang++-17  -c -o print.o print.cpp
+   clang-17 -shared print.o -o print.so
+
+Comments:
+=
+
+.. code-block:: text
+
+   clang-repl> // Comments in Clang-Repl
+   clang-repl> /* Comments in Clang-Repl */
+
+
+Closure or Termination:
+===
+
+.. code-block:: text
+
+   clang-repl>%quit
+
 
-Just like Clang, Clang-Repl can be integrated in existing applications as a
-library (via using the clangInterpreter library). This turning your C++ compiler
-into a service which incrementally can consume and execute code. The

[PATCH] D149000: Update with warning message for comparison to NULL pointer

2023-06-14 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber added a comment.

In D149000#4420607 , @aaron.ballman 
wrote:

> LGTM! There's still a formatting issue in warn-tautological-compare.c but I 
> can fix that up when landing, assuming you still need me to land this on your 
> behalf. (If you can land it on your own, then feel free to fix the formatting 
> issue when you land it.)

Yes, I don't have the commit access to the repository, It would be great if you 
could land it on my behalf. Apologies for missing out on the formatting issues.
Thanks a lot!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149000/new/

https://reviews.llvm.org/D149000

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


[PATCH] D149000: Update with warning message for comparison to NULL pointer

2023-06-14 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 531243.
Krishna-13-cyber removed a reviewer: Quuxplusone.
Krishna-13-cyber added a comment.

- Update with the given suggestion
- Add release notes

Thanks a lot @aaron.ballman for the instant assistance.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149000/new/

https://reviews.llvm.org/D149000

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/conditional-expr.c
  clang/test/Sema/warn-tautological-compare.c


Index: clang/test/Sema/warn-tautological-compare.c
===
--- clang/test/Sema/warn-tautological-compare.c
+++ clang/test/Sema/warn-tautological-compare.c
@@ -93,3 +93,9 @@
   x = array ? 1 : 0; // expected-warning {{address of array}}
   x =  ? 1 : 0;// expected-warning {{address of 'x'}}
 }
+
+void test4(void)
+{
+int *a = (void *) 0;
+int b = () == ((void *) 0); // expected-warning {{comparison of address of 
'a' equal to a null pointer is always false}}
+}
Index: clang/test/Sema/conditional-expr.c
===
--- clang/test/Sema/conditional-expr.c
+++ clang/test/Sema/conditional-expr.c
@@ -86,7 +86,8 @@
 
 int Postgresql(void) {
   char x;
-  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 
0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids 
conditional expressions with only one void side}}
+  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 
0)), (unsigned long) ((void *) 0)); /* expected-warning {{C99 forbids 
conditional expressions with only one void side}}
+   
  expected-warning {{comparison of address of 
'x' not equal to a null pointer is always true}} */
 }
 
 #define nil ((void*) 0)
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14844,7 +14844,7 @@
 
   bool IsAddressOf = false;
 
-  if (UnaryOperator *UO = dyn_cast(E)) {
+  if (auto *UO = dyn_cast(E->IgnoreParens())) {
 if (UO->getOpcode() != UO_AddrOf)
   return;
 IsAddressOf = true;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -340,6 +340,8 @@
   can be controlled using ``-fcaret-diagnostics-max-lines=``.
 - Clang no longer emits ``-Wunused-variable`` warnings for variables declared
   with ``__attribute__((cleanup(...)))`` to match GCC's behavior.
+- Clang now issues expected warnings for situations of comparing with NULL 
pointers.
+  (`#42992: `_)
 
 Bug Fixes in This Version
 -


Index: clang/test/Sema/warn-tautological-compare.c
===
--- clang/test/Sema/warn-tautological-compare.c
+++ clang/test/Sema/warn-tautological-compare.c
@@ -93,3 +93,9 @@
   x = array ? 1 : 0; // expected-warning {{address of array}}
   x =  ? 1 : 0;// expected-warning {{address of 'x'}}
 }
+
+void test4(void)
+{
+int *a = (void *) 0;
+int b = () == ((void *) 0); // expected-warning {{comparison of address of 'a' equal to a null pointer is always false}}
+}
Index: clang/test/Sema/conditional-expr.c
===
--- clang/test/Sema/conditional-expr.c
+++ clang/test/Sema/conditional-expr.c
@@ -86,7 +86,8 @@
 
 int Postgresql(void) {
   char x;
-  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}}
+  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); /* expected-warning {{C99 forbids conditional expressions with only one void side}}
+ expected-warning {{comparison of address of 'x' not equal to a null pointer is always true}} */
 }
 
 #define nil ((void*) 0)
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14844,7 +14844,7 @@
 
   bool IsAddressOf = false;
 
-  if (UnaryOperator *UO = dyn_cast(E)) {
+  if (auto *UO = dyn_cast(E->IgnoreParens())) {
 if (UO->getOpcode() != UO_AddrOf)
   return;
 IsAddressOf = true;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -340,6 +340,8 @@
   can be controlled using 

[PATCH] D152109: Update clang-repl documentation

2023-06-10 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 530227.
Krishna-13-cyber added a comment.

- Update with addressing the comments
- Update with example of Dynamic library usage in repl


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152109/new/

https://reviews.llvm.org/D152109

Files:
  clang/docs/ClangRepl.rst

Index: clang/docs/ClangRepl.rst
===
--- clang/docs/ClangRepl.rst
+++ clang/docs/ClangRepl.rst
@@ -16,22 +16,6 @@
 of Cling upstream, making them useful and available to a broader audience.
 
 
-
-Clang-Repl Usage
-
-
-
-.. code-block:: text
-
-  clang-repl> #include 
-  clang-repl> int f() { std::cout << "Hello Interpreted World!\n"; return 0; }
-  clang-repl> auto r = f();
-  // Prints Hello Interpreted World!
-
-Note that the implementation is not complete and highly experimental. We do
-not yet support statements on the global scope, for example.
-
-
 Clang-Repl Basic Data Flow
 ==
 
@@ -63,14 +47,170 @@
 
 8. The machine code is then executed.
 
+===
+Build Instructions:
+===
+
+
+.. code-block:: console
+
+
+   $ cd llvm-project
+   $ mkdir build
+   $ cd build
+   $ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" ../llvm
+
+**Note here**, above RelWithDebInfo - Debug / Release
+
+.. code-block:: console
+
+   cmake --build . --target clang clang-repl -j n
+  OR
+   cmake --build . --target clang clang-repl
+
+**Clang-repl** is built under llvm-project/build/bin. Proceed into the directory **llvm-project/build/bin**
+
+.. code-block:: console
+
+   ./clang-repl
+   clang-repl>
+
+
+
+Clang-Repl Usage
+
+
+**Clang-Repl** is an interactive C++ interpreter that allows for incremental
+compilation. It supports interactive programming for C++ in a
+read-evaluate-print-loop (REPL) style. It uses Clang as a library to compile the
+high level programming language into LLVM IR. Then the LLVM IR is executed by
+the LLVM just-in-time (JIT) infrastructure.
+
+
+Basic:
+==
+
+
+.. code-block:: text
+
+  clang-repl> #include 
+  clang-repl> int f() { std::cout << "Hello Interpreted World!\n"; return 0; }
+  clang-repl> auto r = f();
+   // Prints Hello Interpreted World!
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> using namespace std;
+   clang-repl> std::cout << "Welcome to CLANG-REPL" << std::endl;
+   Welcome to CLANG-REPL
+   // Prints Welcome to CLANG-REPL
+
+
+Function Definitions and Calls:
+===
+
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> int sum(int a, int b){ return a+b; };
+   clang-repl> int c = sum(9,10);
+   clang-repl> std::cout << c;
+   19clang-repl>
+
+Iterative Structures:
+=
+
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> for (int i = 0;i < 3;i++){ std::cout << i << std::endl;}
+   0
+   1
+   2
+   clang-repl> while(i < 7){ i++; std::cout << i << std::endl;}
+   4
+   5
+   6
+   7
+
+Classes and Structures:
+===
+
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> class Rectangle {int width, height; public: void set_values (int,int);\
+   clang-repl... int area() {return width*height;}};
+   clang-repl>  void Rectangle::set_values (int x, int y) { width = x;height = y;}
+   clang-repl> int main () { Rectangle rect;rect.set_values (3,4);\
+   clang-repl... std::cout << "area: " << rect.area();return 0;}
+   clang-repl> main();
+   area: 12clang-repl>
+   // Note: This '\' can be used for continuation of the statements in the next line
+
+Lamdas:
+===
+
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> using namespace std;
+   clang-repl> auto welcome = []()  { std::cout << "Welcome to REPL" << std::endl;};
+   clang-repl> welcome();
+   Welcome to REPL
+
+Using Dynamic Library:
+==
+
+.. code-block:: text
+
+   clang-repl> %lib print.so
+   clang-repl> #include"print.hpp"
+   clang-repl> print(9);
+   9
+
+**Generation of dynamic library**
+
+.. code-block:: text
+
+
+   // print.cpp
+   #include
+   #include"print.hpp"
+
+   void print(int a)
+   {
+  std::cout << a << std::endl;
+   }
+
+   // print.hpp
+   void print (int a);
+
+   // Commands
+   clang++-17  -c -o print.o print.cpp
+   clang-17 -shared print.o -o print.so
+
+
+Closure or Termination:
+===
+
+
+.. code-block:: text
+
+   clang-repl>%quit
+
 
-Just like Clang, Clang-Repl can be integrated in existing applications as a
-library (via using the clangInterpreter library). This turning your C++ compiler
-into a service which incrementally can consume and execute code. The
-**Compiler as A Service** (**CaaS**) concept helps supporting move advanced use
-cases such as template instantiations on demand and automatic language
-interoperability. It also 

[PATCH] D152109: Update clang-repl documentation

2023-06-07 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 529287.
Krishna-13-cyber added a comment.

- Update with addressing the comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152109/new/

https://reviews.llvm.org/D152109

Files:
  clang/docs/ClangRepl.rst

Index: clang/docs/ClangRepl.rst
===
--- clang/docs/ClangRepl.rst
+++ clang/docs/ClangRepl.rst
@@ -16,22 +16,6 @@
 of Cling upstream, making them useful and available to a broader audience.
 
 
-
-Clang-Repl Usage
-
-
-
-.. code-block:: text
-
-  clang-repl> #include 
-  clang-repl> int f() { std::cout << "Hello Interpreted World!\n"; return 0; }
-  clang-repl> auto r = f();
-  // Prints Hello Interpreted World!
-
-Note that the implementation is not complete and highly experimental. We do
-not yet support statements on the global scope, for example.
-
-
 Clang-Repl Basic Data Flow
 ==
 
@@ -63,14 +47,135 @@
 
 8. The machine code is then executed.
 
+===
+Build Instructions:
+===
+
+
+.. code-block:: console
+
+
+   $ cd llvm-project
+   $ mkdir build
+   $ cd build
+   $ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" ../llvm
+
+**Note here**, above RelWithDebInfo - Debug / Release
+
+.. code-block:: console
+
+   cmake --build . --target clang clang-repl -j n
+  OR
+   cmake --build . --target clang clang-repl
+
+**Clang-repl** is built under llvm-project/build/bin. Proceed into the directory **llvm-project/build/bin**
+
+.. code-block:: console
+
+   ./clang-repl
+   clang-repl>
+
+
+
+Clang-Repl-Usage
+
+
+**Clang-Repl** is an interactive C++ interpreter that allows for incremental
+compilation. It supports interactive programming for C++ in a
+read-evaluate-print-loop (REPL) style. It uses Clang as a library to compile the
+high level programming language into LLVM IR. Then the LLVM IR is executed by
+the LLVM just-in-time (JIT) infrastructure.
+
+
+Basic:
+==
+
+
+.. code-block:: text
+
+  clang-repl> #include 
+  clang-repl> int f() { std::cout << "Hello Interpreted World!\n"; return 0; }
+  clang-repl> auto r = f();
+   // Prints Hello Interpreted World!
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> using namespace std;
+   clang-repl> std::cout << "Welcome to CLANG-REPL" << std::endl;
+   Welcome to CLANG-REPL
+   // Prints Welcome to CLANG-REPL
+
+
+Function Definitions and Calls:
+===
+
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> int sum(int a, int b){ return a+b; };
+   clang-repl> int c = sum(9,10);
+   clang-repl> std::cout << c;
+   19clang-repl>
+
+Iterative Structures:
+=
+
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> for (int i = 0;i < 3;i++){ std::cout << i << std::endl;}
+   0
+   1
+   2
+   clang-repl> while(i < 7){ i++; std::cout << i << std::endl;}
+   4
+   5
+   6
+   7
+
+Classes and Structures:
+===
+
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> class Rectangle {int width, height; public: void set_values (int,int);int area() {return width*height;}};
+   clang-repl>  void Rectangle::set_values (int x, int y) { width = x;height = y;}
+   clang-repl> int main () { Rectangle rect;rect.set_values (3,4); std::cout << "area: " << rect.area();return 0;}
+   clang-repl> main();
+   area: 12clang-repl>
+
+Lamdas:
+===
+
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> using namespace std;
+   clang-repl> auto welcome = []()  { std::cout << "Welcome to REPL" << std::endl;};
+   clang-repl> welcome();
+   Welcome to REPL
+
+Closure or Termination:
+===
+
+
+.. code-block:: text
+
+   clang-repl>%quit
+
 
-Just like Clang, Clang-Repl can be integrated in existing applications as a
-library (via using the clangInterpreter library). This turning your C++ compiler
-into a service which incrementally can consume and execute code. The
-**Compiler as A Service** (**CaaS**) concept helps supporting move advanced use
-cases such as template instantiations on demand and automatic language
-interoperability. It also helps static languages such as C/C++ become apt for
-data science.
+Just like Clang, Clang-Repl can be integrated in existing applications as a library 
+(using the clangInterpreter library). This turns your C++ compiler into a service that 
+can incrementally consume and execute code. The **Compiler as A Service** (**CaaS**) 
+concept helps support advanced use cases such as template instantiations on demand and 
+automatic language interoperability. It also helps static languages such as C/C++ become 
+apt for data science.
 
 
 Related Reading
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D152109: Update clang-repl documentation

2023-06-04 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber created this revision.
Krishna-13-cyber added reviewers: v.g.vassilev, QuillPusher, davidlange6.
Herald added a project: All.
Krishna-13-cyber requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Update Clang-repl documentation with:-

- Add usage and build instructions
- Add examples depicting their usage in clang-repl.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152109

Files:
  clang/docs/ClangRepl.rst

Index: clang/docs/ClangRepl.rst
===
--- clang/docs/ClangRepl.rst
+++ clang/docs/ClangRepl.rst
@@ -16,22 +16,6 @@
 of Cling upstream, making them useful and available to a broader audience.
 
 
-
-Clang-Repl Usage
-
-
-
-.. code-block:: text
-
-  clang-repl> #include 
-  clang-repl> int f() { std::cout << "Hello Interpreted World!\n"; return 0; }
-  clang-repl> auto r = f();
-  // Prints Hello Interpreted World!
-
-Note that the implementation is not complete and highly experimental. We do
-not yet support statements on the global scope, for example.
-
-
 Clang-Repl Basic Data Flow
 ==
 
@@ -64,6 +48,133 @@
 8. The machine code is then executed.
 
 
+Just like Clang, Clang-Repl can be integrated in existing applications as a
+library (via using the clangInterpreter library). This turning your C++ compiler
+into a service which incrementally can consume and execute code. The
+**Compiler as A Service** (**CaaS**) concept helps supporting move advanced use
+cases such as template instantiations on demand and automatic language
+interoperability. It also helps static languages such as C/C++ become apt for
+data science.
+
+
+Clang-Repl-Usage
+
+
+**Clang-Repl** is an interactive C++ interpreter that allows for incremental
+compilation. It supports interactive programming for C++ in a
+read-evaluate-print-loop (REPL) style. It uses Clang as a library to compile the
+high level programming language into LLVM IR. Then the LLVM IR is executed by
+the LLVM just-in-time (JIT) infrastructure.
+
+Build Instructions:
+===
+
+
+.. code-block:: console
+
+   $ cd llvm-project
+   $ mkdir build
+   $ cd build
+   $ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" ../llvm
+
+**Note here**, above RelWithDebInfo - Debug / Release
+
+.. code-block:: console
+
+   cmake --build . --target clang clang-repl -j n
+  OR
+   cmake --build . --target clang clang-repl
+
+**Clang-repl** is built under llvm-project/build/bin.roceeding into the directory **llvm-project/build/bin**
+
+.. code-block:: console
+
+   ./clang-repl
+   clang-repl>
+
+
+Basic:
+==
+.. code-block:: text
+
+  clang-repl> #include 
+  clang-repl> int f() { std::cout << "Hello Interpreted World!\n"; return 0; }
+  clang-repl> auto r = f();
+   // Prints Hello Interpreted World!
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> using namespace std;
+   clang-repl> std::cout << "Welcome to CLANG-REPL" << std::endl;
+   Welcome to CLANG-REPL
+   // Prints Welcome to CLANG-REPL
+
+
+Function Definitions and Calls:
+===
+
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> int sum(int a, int b){ return a+b; };
+   clang-repl> int c = sum(9,10);
+   clang-repl> std::cout << c;
+   19clang-repl>
+
+Iterative Structures:
+=
+
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> for (int i = 0;i < 3;i++){ std::cout << i << std::endl;}
+   0
+   1
+   2
+   clang-repl> while(i < 7){ i++; std::cout << i << std::endl;}
+   4
+   5
+   6
+   7
+
+Classes and Structures:
+===
+
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> class Rectangle {int width, height; public: void set_values (int,int);int area() {return width*height;}};
+   clang-repl>  void Rectangle::set_values (int x, int y) { width = x;height = y;}
+   clang-repl> int main () { Rectangle rect;rect.set_values (3,4); std::cout << "area: " << rect.area();return 0;}
+   clang-repl> main();
+   area: 12clang-repl>
+
+Lamdas:
+===
+
+
+.. code-block:: text
+
+   clang-repl> #include
+   clang-repl> using namespace std;
+   clang-repl> auto welcome = []()  { std::cout << "Welcome to REPL" << std::endl;};
+   clang-repl> welcome();
+   Welcome to REPL
+
+Closure or Termination:
+===
+
+
+.. code-block:: text
+
+   clang-repl>%quit
+
+
+
 Just like Clang, Clang-Repl can be integrated in existing applications as a
 library (via using the clangInterpreter library). This turning your C++ compiler
 into a service which incrementally can consume and execute code. The
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147888: Update declaration message of extern linkage

2023-04-29 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber added a comment.

In D147888#4288149 , 
@Krishna-13-cyber wrote:

> I have tried a little modification from my side thinking on a beneficial 
> note. I will make the changes to all the other test files as well if this 
> diagnostic representation goes well after mentor review.
>
> For refactoring and restructuring the whole of the re-declaration would need 
> some time I have been through it and would initiate another patch for that,In 
> the concern of giving or having just one diagnostic for getting all cases of 
> re-declaration would also need multiple conditional or switch statements 
> inside our function block.At present we have the same with conditional 
> statements taking care of each linkage but it has multiple permutations of 
> diagnostic messages which is nice but can be improved.GCC differs only for 
> this case of extern linkage which can be better/precise in clang where as 
> others seem to be more precise in clang than former as I worked out with good 
> number of test cases regarding this.

Ping!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147888/new/

https://reviews.llvm.org/D147888

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


[PATCH] D149000: Update with warning message for comparison to NULL pointer

2023-04-26 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 517151.
Krishna-13-cyber added a comment.

- Updated with re-adding the required diagnostic message


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149000/new/

https://reviews.llvm.org/D149000

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/conditional-expr.c
  clang/test/Sema/warn-tautological-compare.c


Index: clang/test/Sema/warn-tautological-compare.c
===
--- clang/test/Sema/warn-tautological-compare.c
+++ clang/test/Sema/warn-tautological-compare.c
@@ -93,3 +93,9 @@
   x = array ? 1 : 0; // expected-warning {{address of array}}
   x =  ? 1 : 0;// expected-warning {{address of 'x'}}
 }
+
+void test4(void)
+{
+int *a = (void *) 0;
+int b = () == ((void *) 0); // expected-warning {{comparison of address of 
'a' equal to a null pointer is always false}}
+}
Index: clang/test/Sema/conditional-expr.c
===
--- clang/test/Sema/conditional-expr.c
+++ clang/test/Sema/conditional-expr.c
@@ -86,7 +86,8 @@
 
 int Postgresql(void) {
   char x;
-  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 
0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids 
conditional expressions with only one void side}}
+  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 
0)), (unsigned long) ((void *) 0)); /* expected-warning {{C99 forbids 
conditional expressions with only one void side}}
+   
  expected-warning {{comparison of address of 
'x' not equal to a null pointer is always true}} */
 }
 
 #define nil ((void*) 0)
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14723,7 +14723,7 @@
 
   bool IsAddressOf = false;
 
-  if (UnaryOperator *UO = dyn_cast(E)) {
+  if (UnaryOperator *UO = dyn_cast(E->IgnoreParenCasts())) {
 if (UO->getOpcode() != UO_AddrOf)
   return;
 IsAddressOf = true;


Index: clang/test/Sema/warn-tautological-compare.c
===
--- clang/test/Sema/warn-tautological-compare.c
+++ clang/test/Sema/warn-tautological-compare.c
@@ -93,3 +93,9 @@
   x = array ? 1 : 0; // expected-warning {{address of array}}
   x =  ? 1 : 0;// expected-warning {{address of 'x'}}
 }
+
+void test4(void)
+{
+int *a = (void *) 0;
+int b = () == ((void *) 0); // expected-warning {{comparison of address of 'a' equal to a null pointer is always false}}
+}
Index: clang/test/Sema/conditional-expr.c
===
--- clang/test/Sema/conditional-expr.c
+++ clang/test/Sema/conditional-expr.c
@@ -86,7 +86,8 @@
 
 int Postgresql(void) {
   char x;
-  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}}
+  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); /* expected-warning {{C99 forbids conditional expressions with only one void side}}
+ expected-warning {{comparison of address of 'x' not equal to a null pointer is always true}} */
 }
 
 #define nil ((void*) 0)
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14723,7 +14723,7 @@
 
   bool IsAddressOf = false;
 
-  if (UnaryOperator *UO = dyn_cast(E)) {
+  if (UnaryOperator *UO = dyn_cast(E->IgnoreParenCasts())) {
 if (UO->getOpcode() != UO_AddrOf)
   return;
 IsAddressOf = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149000: Update with warning message for comparison to NULL pointer

2023-04-25 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 516857.
Krishna-13-cyber added a comment.

- Updated with reviewed changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149000/new/

https://reviews.llvm.org/D149000

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/conditional-expr.c
  clang/test/Sema/warn-tautological-compare.c


Index: clang/test/Sema/warn-tautological-compare.c
===
--- clang/test/Sema/warn-tautological-compare.c
+++ clang/test/Sema/warn-tautological-compare.c
@@ -93,3 +93,9 @@
   x = array ? 1 : 0; // expected-warning {{address of array}}
   x =  ? 1 : 0;// expected-warning {{address of 'x'}}
 }
+
+void test4(void)
+{
+int *a = (void *) 0;
+int b = () == ((void *) 0); // expected-warning {{comparison of address of 
'a' equal to a null pointer is always false}}
+}
Index: clang/test/Sema/conditional-expr.c
===
--- clang/test/Sema/conditional-expr.c
+++ clang/test/Sema/conditional-expr.c
@@ -86,7 +86,7 @@
 
 int Postgresql(void) {
   char x;
-  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 
0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids 
conditional expressions with only one void side}}
+  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 
0)), (unsigned long) ((void *) 0)); // expected-warning {{comparison of address 
of 'x' not equal to a null pointer is always true}}
 }
 
 #define nil ((void*) 0)
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14723,7 +14723,7 @@
 
   bool IsAddressOf = false;
 
-  if (UnaryOperator *UO = dyn_cast(E)) {
+  if (UnaryOperator *UO = dyn_cast(E->IgnoreParenCasts())) {
 if (UO->getOpcode() != UO_AddrOf)
   return;
 IsAddressOf = true;


Index: clang/test/Sema/warn-tautological-compare.c
===
--- clang/test/Sema/warn-tautological-compare.c
+++ clang/test/Sema/warn-tautological-compare.c
@@ -93,3 +93,9 @@
   x = array ? 1 : 0; // expected-warning {{address of array}}
   x =  ? 1 : 0;// expected-warning {{address of 'x'}}
 }
+
+void test4(void)
+{
+int *a = (void *) 0;
+int b = () == ((void *) 0); // expected-warning {{comparison of address of 'a' equal to a null pointer is always false}}
+}
Index: clang/test/Sema/conditional-expr.c
===
--- clang/test/Sema/conditional-expr.c
+++ clang/test/Sema/conditional-expr.c
@@ -86,7 +86,7 @@
 
 int Postgresql(void) {
   char x;
-  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}}
+  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{comparison of address of 'x' not equal to a null pointer is always true}}
 }
 
 #define nil ((void*) 0)
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14723,7 +14723,7 @@
 
   bool IsAddressOf = false;
 
-  if (UnaryOperator *UO = dyn_cast(E)) {
+  if (UnaryOperator *UO = dyn_cast(E->IgnoreParenCasts())) {
 if (UO->getOpcode() != UO_AddrOf)
   return;
 IsAddressOf = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149000: Update with warning message for comparison to NULL pointer

2023-04-24 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 516397.
Krishna-13-cyber added a comment.

- Update with addition of testcase
- There is an issue for which the build fails,actually when I replace the 
diagnostic by `comparison of address of 'x' not equal to a null pointer is 
always true` in **/clang/test/Sema/conditional-expr.c Line 89**,it shows `C99 
forbids conditional expressions with only one void side` and vice versa.It 
regresses either ways.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149000/new/

https://reviews.llvm.org/D149000

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/conditional-expr.c
  clang/test/Sema/warn-tautological-compare.c
  clang/test/SemaCXX/constant-expression-cxx2a.cpp


Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -249,7 +249,7 @@
   // During construction of C, A is unambiguous subobject of dynamic type C.
   static_assert(g.c == (C*));
   // ... but in the complete object, the same is not true, so the runtime 
fails.
-  static_assert(dynamic_cast(static_cast()) == nullptr);
+  static_assert(dynamic_cast(static_cast()) == 
nullptr); // expected-warning {{comparison of address of 'g' equal to a null 
pointer is always false}}
 
   // dynamic_cast produces a pointer to the object of the dynamic type.
   static_assert(g.f == (void*)(F*));
Index: clang/test/Sema/warn-tautological-compare.c
===
--- clang/test/Sema/warn-tautological-compare.c
+++ clang/test/Sema/warn-tautological-compare.c
@@ -93,3 +93,9 @@
   x = array ? 1 : 0; // expected-warning {{address of array}}
   x =  ? 1 : 0;// expected-warning {{address of 'x'}}
 }
+
+void test4(void)
+{
+int *a = (void *) 0;
+int b = () == ((void *) 0); // expected-warning {{comparison of address of 
'a' equal to a null pointer is always false}}
+}
\ No newline at end of file
Index: clang/test/Sema/conditional-expr.c
===
--- clang/test/Sema/conditional-expr.c
+++ clang/test/Sema/conditional-expr.c
@@ -86,7 +86,7 @@
 
 int Postgresql(void) {
   char x;
-  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 
0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids 
conditional expressions with only one void side}}
+  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 
0)), (unsigned long) ((void *) 0)); // expected-warning {{comparison of address 
of 'x' not equal to a null pointer is always true}}
 }
 
 #define nil ((void*) 0)
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14723,7 +14723,7 @@
 
   bool IsAddressOf = false;
 
-  if (UnaryOperator *UO = dyn_cast(E)) {
+  if (UnaryOperator *UO = dyn_cast(E->IgnoreParenCasts())) {
 if (UO->getOpcode() != UO_AddrOf)
   return;
 IsAddressOf = true;


Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -249,7 +249,7 @@
   // During construction of C, A is unambiguous subobject of dynamic type C.
   static_assert(g.c == (C*));
   // ... but in the complete object, the same is not true, so the runtime fails.
-  static_assert(dynamic_cast(static_cast()) == nullptr);
+  static_assert(dynamic_cast(static_cast()) == nullptr); // expected-warning {{comparison of address of 'g' equal to a null pointer is always false}}
 
   // dynamic_cast produces a pointer to the object of the dynamic type.
   static_assert(g.f == (void*)(F*));
Index: clang/test/Sema/warn-tautological-compare.c
===
--- clang/test/Sema/warn-tautological-compare.c
+++ clang/test/Sema/warn-tautological-compare.c
@@ -93,3 +93,9 @@
   x = array ? 1 : 0; // expected-warning {{address of array}}
   x =  ? 1 : 0;// expected-warning {{address of 'x'}}
 }
+
+void test4(void)
+{
+int *a = (void *) 0;
+int b = () == ((void *) 0); // expected-warning {{comparison of address of 'a' equal to a null pointer is always false}}
+}
\ No newline at end of file
Index: clang/test/Sema/conditional-expr.c
===
--- clang/test/Sema/conditional-expr.c
+++ clang/test/Sema/conditional-expr.c
@@ -86,7 +86,7 @@
 
 int Postgresql(void) {
   char x;
-  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}}
+  return ) != ((void *) 0)) ? (*() = ((char) 

[PATCH] D149000: Update with warning message for comparison to NULL pointer

2023-04-23 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 516201.
Krishna-13-cyber added a comment.

- Update with diagnostic addition


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149000/new/

https://reviews.llvm.org/D149000

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/conditional-expr.c
  clang/test/SemaCXX/constant-expression-cxx2a.cpp


Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -249,7 +249,7 @@
   // During construction of C, A is unambiguous subobject of dynamic type C.
   static_assert(g.c == (C*));
   // ... but in the complete object, the same is not true, so the runtime 
fails.
-  static_assert(dynamic_cast(static_cast()) == nullptr);
+  static_assert(dynamic_cast(static_cast()) == 
nullptr); // expected-warning {{comparison of address of 'g' equal to a null 
pointer is always false}}
 
   // dynamic_cast produces a pointer to the object of the dynamic type.
   static_assert(g.f == (void*)(F*));
Index: clang/test/Sema/conditional-expr.c
===
--- clang/test/Sema/conditional-expr.c
+++ clang/test/Sema/conditional-expr.c
@@ -86,7 +86,7 @@
 
 int Postgresql(void) {
   char x;
-  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 
0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids 
conditional expressions with only one void side}}
+  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 
0)), (unsigned long) ((void *) 0)); // expected-warning {{comparison of address 
of 'x' not equal to a null pointer is always true}}
 }
 
 #define nil ((void*) 0)
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14723,7 +14723,7 @@
 
   bool IsAddressOf = false;
 
-  if (UnaryOperator *UO = dyn_cast(E)) {
+  if (UnaryOperator *UO = dyn_cast(E->IgnoreParenCasts())) {
 if (UO->getOpcode() != UO_AddrOf)
   return;
 IsAddressOf = true;


Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -249,7 +249,7 @@
   // During construction of C, A is unambiguous subobject of dynamic type C.
   static_assert(g.c == (C*));
   // ... but in the complete object, the same is not true, so the runtime fails.
-  static_assert(dynamic_cast(static_cast()) == nullptr);
+  static_assert(dynamic_cast(static_cast()) == nullptr); // expected-warning {{comparison of address of 'g' equal to a null pointer is always false}}
 
   // dynamic_cast produces a pointer to the object of the dynamic type.
   static_assert(g.f == (void*)(F*));
Index: clang/test/Sema/conditional-expr.c
===
--- clang/test/Sema/conditional-expr.c
+++ clang/test/Sema/conditional-expr.c
@@ -86,7 +86,7 @@
 
 int Postgresql(void) {
   char x;
-  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{C99 forbids conditional expressions with only one void side}}
+  return ) != ((void *) 0)) ? (*() = ((char) 1)) : (void) ((void *) 0)), (unsigned long) ((void *) 0)); // expected-warning {{comparison of address of 'x' not equal to a null pointer is always true}}
 }
 
 #define nil ((void*) 0)
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14723,7 +14723,7 @@
 
   bool IsAddressOf = false;
 
-  if (UnaryOperator *UO = dyn_cast(E)) {
+  if (UnaryOperator *UO = dyn_cast(E->IgnoreParenCasts())) {
 if (UO->getOpcode() != UO_AddrOf)
   return;
 IsAddressOf = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149000: Update with warning message for comparison to NULL pointer

2023-04-22 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 516087.
Krishna-13-cyber added a comment.



- Apologies for uploading some other/incorrect diff
- Updated Diff


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149000/new/

https://reviews.llvm.org/D149000

Files:
  clang/lib/Sema/SemaChecking.cpp


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14723,7 +14723,7 @@
 
   bool IsAddressOf = false;
 
-  if (UnaryOperator *UO = dyn_cast(E)) {
+  if (UnaryOperator *UO = dyn_cast(E->IgnoreParenCasts())) {
 if (UO->getOpcode() != UO_AddrOf)
   return;
 IsAddressOf = true;


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14723,7 +14723,7 @@
 
   bool IsAddressOf = false;
 
-  if (UnaryOperator *UO = dyn_cast(E)) {
+  if (UnaryOperator *UO = dyn_cast(E->IgnoreParenCasts())) {
 if (UO->getOpcode() != UO_AddrOf)
   return;
 IsAddressOf = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149000: Update with warning message for comparison to NULL pointer

2023-04-22 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber created this revision.
Krishna-13-cyber added reviewers: aaron.ballman, tbaeder, Quuxplusone.
Herald added a project: All.
Krishna-13-cyber requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch solves the issue pointed out in 
https://github.com/llvm/llvm-project/issues/42992.
While checking the testcases it fails in one of the cases, I am unsure of the 
fix of that while rest all seems fine.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149000

Files:
  clang/lib/Sema/SemaDeclCXX.cpp


Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,7 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);Op && Op->getOpcode() != 
BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 


Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,7 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);Op && Op->getOpcode() != BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147888: Update declaration message of extern linkage

2023-04-21 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 515843.
Krishna-13-cyber added a comment.

I have tried a little modification from my side thinking on a beneficial note. 
I will make the changes to all the other test files as well if this diagnostic 
representation goes well after mentor review.

For refactoring and restructuring the whole of the re-declaration would need 
some time I have been through it and would initiate another patch for that,In 
the concern of giving or having just one diagnostic for getting all cases of 
re-declaration would also need multiple conditional or switch statements inside 
our function block.At present we have the same with conditional statements 
taking care of each linkage but it has multiple permutations of diagnostic 
messages which is nice but can be improved.GCC differs only for this case of 
extern linkage which can be better/precise in clang where as others seem to be 
more precise in clang than latter as I worked out with good number of test 
cases regarding .


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147888/new/

https://reviews.llvm.org/D147888

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/extern_static.cpp


Index: clang/test/SemaCXX/extern_static.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/extern_static.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wabstract-vbase-init
+void f(void)
+{
+static int x; // expected-note {{previous definition is here}}
+extern int x; // expected-error {{extern declaration of 'x' follows static 
declaration;Please pick exactly one (static or extern)}}
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4637,6 +4637,15 @@
   //   the prior declaration. If no prior declaration is visible, or
   //   if the prior declaration specifies no linkage, then the
   //   identifier has external linkage.
+
+  if (New->hasExternalStorage() &&
+  Old->getCanonicalDecl()->getStorageClass() == SC_Static &&
+  Old->isLocalVarDeclOrParm()) {
+Diag(New->getLocation(), diag::err_extern_static) << New->getDeclName();
+Diag(OldLocation, PrevDiag);
+return New->setInvalidDecl();
+  }
+
   if (New->hasExternalStorage() && Old->hasLinkage())
 /* Okay */;
   else if (New->getCanonicalDecl()->getStorageClass() != SC_Static &&
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5798,11 +5798,13 @@
   "redeclaring non-static %0 as static is a Microsoft extension">,
   InGroup;
 def err_non_static_static : Error<
-  "non-static declaration of %0 follows static declaration">;
+  "non-static declaration of %0 follows static declaration;Please pick exactly 
one (static or non-static)">;
+def err_extern_static : Error<
+  "extern declaration of %0 follows static declaration;Please pick exactly one 
(static or extern)">;
 def err_extern_non_extern : Error<
-  "extern declaration of %0 follows non-extern declaration">;
+  "extern declaration of %0 follows non-extern declaration;Please pick exactly 
one (non-extern or extern)">;
 def err_non_extern_extern : Error<
-  "non-extern declaration of %0 follows extern declaration">;
+  "non-extern declaration of %0 follows extern declaration;Please pick exactly 
one (extern or non-extern)">;
 def err_non_thread_thread : Error<
   "non-thread-local declaration of %0 follows thread-local declaration">;
 def err_thread_non_thread : Error<


Index: clang/test/SemaCXX/extern_static.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/extern_static.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wabstract-vbase-init
+void f(void)
+{
+static int x; // expected-note {{previous definition is here}}
+extern int x; // expected-error {{extern declaration of 'x' follows static declaration;Please pick exactly one (static or extern)}}
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4637,6 +4637,15 @@
   //   the prior declaration. If no prior declaration is visible, or
   //   if the prior declaration specifies no linkage, then the
   //   identifier has external linkage.
+
+  if (New->hasExternalStorage() &&
+  Old->getCanonicalDecl()->getStorageClass() == SC_Static &&
+  Old->isLocalVarDeclOrParm()) {
+Diag(New->getLocation(), diag::err_extern_static) << New->getDeclName();
+Diag(OldLocation, PrevDiag);
+

[PATCH] D147888: Update declaration message of extern linkage

2023-04-19 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber added a comment.

In D147888#4274763 , @cjdb wrote:

> I think we should fundamentally rethink this entire category of diagnostic. 
> Rather than having a static diagnostic per offence stating //what// happened, 
> we should instead have a single diagnostic that captures both what happened, 
> why it's bad, and how to fix it. Something along the lines of
>
>   error: 'x' has been declared with incompatible linkage specifiers (static 
> and extern); please pick exactly one
> extern int x;
> ^~
>   note: previous definition here
> static int x;
> ^~
>
> It'd also be more robust from an engineering perspective, since it means that 
> we won't need to add new diagnostic permutations every time a new linkage 
> specifier is added.



In D147888#4274763 , @cjdb wrote:

> I think we should fundamentally rethink this entire category of diagnostic. 
> Rather than having a static diagnostic per offence stating //what// happened, 
> we should instead have a single diagnostic that captures both what happened, 
> why it's bad, and how to fix it. Something along the lines of
>
>   error: 'x' has been declared with incompatible linkage specifiers (static 
> and extern); please pick exactly one
> extern int x;
> ^~
>   note: previous definition here
> static int x;
> ^~
>
> It'd also be more robust from an engineering perspective, since it means that 
> we won't need to add new diagnostic permutations every time a new linkage 
> specifier is added.

I will try giving this a shot
Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147888/new/

https://reviews.llvm.org/D147888

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


[PATCH] D147888: Update declaration message of extern linkage

2023-04-12 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 512848.
Krishna-13-cyber added a comment.

- Updated with removing redundant flags


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147888/new/

https://reviews.llvm.org/D147888

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/extern_static.cpp


Index: clang/test/SemaCXX/extern_static.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/extern_static.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+void f(void)
+{
+static int x; // expected-note {{previous definition is here}}
+extern int x; // expected-error {{extern declaration of 'x' follows static 
declaration}}
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4637,6 +4637,15 @@
   //   the prior declaration. If no prior declaration is visible, or
   //   if the prior declaration specifies no linkage, then the
   //   identifier has external linkage.
+
+  if (New->hasExternalStorage() &&
+  Old->getCanonicalDecl()->getStorageClass() == SC_Static &&
+  Old->isLocalVarDeclOrParm()) {
+Diag(New->getLocation(), diag::err_extern_static) << New->getDeclName();
+Diag(OldLocation, PrevDiag);
+return New->setInvalidDecl();
+  }
+
   if (New->hasExternalStorage() && Old->hasLinkage())
 /* Okay */;
   else if (New->getCanonicalDecl()->getStorageClass() != SC_Static &&
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5799,6 +5799,8 @@
   InGroup;
 def err_non_static_static : Error<
   "non-static declaration of %0 follows static declaration">;
+def err_extern_static : Error<
+  "extern declaration of %0 follows static declaration">;
 def err_extern_non_extern : Error<
   "extern declaration of %0 follows non-extern declaration">;
 def err_non_extern_extern : Error<


Index: clang/test/SemaCXX/extern_static.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/extern_static.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+void f(void)
+{
+static int x; // expected-note {{previous definition is here}}
+extern int x; // expected-error {{extern declaration of 'x' follows static declaration}}
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4637,6 +4637,15 @@
   //   the prior declaration. If no prior declaration is visible, or
   //   if the prior declaration specifies no linkage, then the
   //   identifier has external linkage.
+
+  if (New->hasExternalStorage() &&
+  Old->getCanonicalDecl()->getStorageClass() == SC_Static &&
+  Old->isLocalVarDeclOrParm()) {
+Diag(New->getLocation(), diag::err_extern_static) << New->getDeclName();
+Diag(OldLocation, PrevDiag);
+return New->setInvalidDecl();
+  }
+
   if (New->hasExternalStorage() && Old->hasLinkage())
 /* Okay */;
   else if (New->getCanonicalDecl()->getStorageClass() != SC_Static &&
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5799,6 +5799,8 @@
   InGroup;
 def err_non_static_static : Error<
   "non-static declaration of %0 follows static declaration">;
+def err_extern_static : Error<
+  "extern declaration of %0 follows static declaration">;
 def err_extern_non_extern : Error<
   "extern declaration of %0 follows non-extern declaration">;
 def err_non_extern_extern : Error<
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147888: Update declaration message of extern linkage

2023-04-09 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber created this revision.
Krishna-13-cyber added reviewers: tbaeder, cjdb, aaron.ballman.
Herald added a project: All.
Krishna-13-cyber requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch aims to improve the diagnostic to much better precision of 
indicating extern declaration being followed after static declaration rather 
than just generic non-static declaration.

**Example Testcase:** https://godbolt.org/z/zMTda6MGG


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147888

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/extern_static.cpp


Index: clang/test/SemaCXX/extern_static.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/extern_static.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wabstract-vbase-init
+void f(void)
+{
+static int x; // expected-note {{previous definition is here}}
+extern int x; // expected-error {{extern declaration of 'x' follows static 
declaration}}
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4637,6 +4637,15 @@
   //   the prior declaration. If no prior declaration is visible, or
   //   if the prior declaration specifies no linkage, then the
   //   identifier has external linkage.
+
+  if (New->hasExternalStorage() &&
+  Old->getCanonicalDecl()->getStorageClass() == SC_Static &&
+  Old->isLocalVarDeclOrParm()) {
+Diag(New->getLocation(), diag::err_extern_static) << New->getDeclName();
+Diag(OldLocation, PrevDiag);
+return New->setInvalidDecl();
+  }
+
   if (New->hasExternalStorage() && Old->hasLinkage())
 /* Okay */;
   else if (New->getCanonicalDecl()->getStorageClass() != SC_Static &&
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5799,6 +5799,8 @@
   InGroup;
 def err_non_static_static : Error<
   "non-static declaration of %0 follows static declaration">;
+def err_extern_static : Error<
+  "extern declaration of %0 follows static declaration">;
 def err_extern_non_extern : Error<
   "extern declaration of %0 follows non-extern declaration">;
 def err_non_extern_extern : Error<


Index: clang/test/SemaCXX/extern_static.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/extern_static.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wabstract-vbase-init
+void f(void)
+{
+static int x; // expected-note {{previous definition is here}}
+extern int x; // expected-error {{extern declaration of 'x' follows static declaration}}
+}
\ No newline at end of file
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4637,6 +4637,15 @@
   //   the prior declaration. If no prior declaration is visible, or
   //   if the prior declaration specifies no linkage, then the
   //   identifier has external linkage.
+
+  if (New->hasExternalStorage() &&
+  Old->getCanonicalDecl()->getStorageClass() == SC_Static &&
+  Old->isLocalVarDeclOrParm()) {
+Diag(New->getLocation(), diag::err_extern_static) << New->getDeclName();
+Diag(OldLocation, PrevDiag);
+return New->setInvalidDecl();
+  }
+
   if (New->hasExternalStorage() && Old->hasLinkage())
 /* Okay */;
   else if (New->getCanonicalDecl()->getStorageClass() != SC_Static &&
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5799,6 +5799,8 @@
   InGroup;
 def err_non_static_static : Error<
   "non-static declaration of %0 follows static declaration">;
+def err_extern_static : Error<
+  "extern declaration of %0 follows static declaration">;
 def err_extern_non_extern : Error<
   "extern declaration of %0 follows non-extern declaration">;
 def err_non_extern_extern : Error<
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146376: Update static_assert message for redundant cases

2023-04-07 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 511630.
Krishna-13-cyber added a comment.

Thanks a lot everyone for helping me out with my first patch. I have uploaded 
the patch again after rebase.
Yes, It would be great if you could land it on my behalf.
Name: Krishna Narayanan
Email: 

Thanks again!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146376/new/

https://reviews.llvm.org/D146376

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
-  static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{static 
assertion failed due to requirement 'invert(true) || invert(true)'}}
+  static_assert(invert(true) == invert(false), ""); // expected-error {{static 
assertion failed due to requirement 'invert(true) == invert(false)'}} \
 // expected-note 
{{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{static assertion 
failed due to requirement 'true && false'}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error 
{{static assertion failed due to requirement 'invert(true) || invert(true) || 
false'}}
+  static_assert((true && invert(true)) || false, ""); // expected-error 
{{static assertion failed due to requirement '(true && invert(true)) || false'}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error 
{{static assertion failed due to requirement 'invert(true)'}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16718,7 +16718,8 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);
+  Op && Op->getOpcode() != BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -213,6 +213,9 @@
 - There were some cases in which the diagnostic for the unavailable attribute
   might not be issued, this fixes those cases.
   (`61815 `_)
+- Clang now avoids unnecessary diagnostic warnings for obvious expressions in
+  the case of binary operators with logical OR operations.
+  (`#57906 `_)
 
 Bug Fixes in This Version
 -


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
-  static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{static assertion failed due to requirement 'invert(true) || invert(true)'}}
+  static_assert(invert(true) == invert(false), ""); // expected-error {{static assertion failed due to requirement 'invert(true) == invert(false)'}} \
 // expected-note {{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{static assertion failed due to requirement 'true && false'}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error {{static assertion failed due to requirement 'invert(true) || invert(true) || false'}}
+  static_assert((true && invert(true)) || false, ""); // expected-error {{static assertion failed due to requirement '(true && invert(true)) || false'}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error {{static assertion failed due to requirement 'invert(true)'}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16718,7 +16718,8 @@
 /// Try to 

[PATCH] D146376: Update static_assert message for redundant cases

2023-04-05 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 511181.
Krishna-13-cyber added a comment.

- Updated with the diagnostic messages (comments for test cases)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146376/new/

https://reviews.llvm.org/D146376

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
-  static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{static 
assertion failed due to requirement 'invert(true) || invert(true)'}}
+  static_assert(invert(true) == invert(false), ""); // expected-error {{static 
assertion failed due to requirement 'invert(true) == invert(false)'}} \
 // expected-note 
{{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{static assertion 
failed due to requirement 'true && false'}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error 
{{static assertion failed due to requirement 'invert(true) || invert(true) || 
false'}}
+  static_assert((true && invert(true)) || false, ""); // expected-error 
{{static assertion failed due to requirement '(true && invert(true)) || false'}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error 
{{static assertion failed due to requirement 'invert(true)'}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,8 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);
+  Op && Op->getOpcode() != BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -179,6 +179,9 @@
 - Clang now avoids duplicate warnings on unreachable ``[[fallthrough]];`` 
statements
   previously issued from ``-Wunreachable-code`` and 
``-Wunreachable-code-fallthrough``
   by prioritizing ``-Wunreachable-code-fallthrough``.
+- Clang now avoids unnecessary diagnostic warnings for obvious expressions in
+  the case of binary operators with logical OR operations.
+  (`#57906 `_)
 
 Bug Fixes in This Version
 -


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
-  static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{static assertion failed due to requirement 'invert(true) || invert(true)'}}
+  static_assert(invert(true) == invert(false), ""); // expected-error {{static assertion failed due to requirement 'invert(true) == invert(false)'}} \
 // expected-note {{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{static assertion failed due to requirement 'true && false'}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error {{static assertion failed due to requirement 'invert(true) || invert(true) || false'}}
+  static_assert((true && invert(true)) || false, ""); // expected-error {{static assertion failed due to requirement '(true && invert(true)) || false'}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error {{static assertion failed due to requirement 'invert(true)'}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,8 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void 

[PATCH] D146376: Update static_assert message for redundant cases

2023-04-04 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 510909.
Krishna-13-cyber added a comment.

- Updated with release note
- I had tried adding more text to the `expected-error` but it already gives a 
diagnostic of `static assertion failed due to requirement` currently. If I try 
additions to `{{failed}}` then we get **error diagnostics expected but not 
seen**.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146376/new/

https://reviews.llvm.org/D146376

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
 // expected-note 
{{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{failed}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error 
{{failed}}
+  static_assert((true && invert(true)) || false, ""); // expected-error 
{{failed}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error 
{{failed}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,8 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);
+  Op && Op->getOpcode() != BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -179,6 +179,9 @@
 - Clang now avoids duplicate warnings on unreachable ``[[fallthrough]];`` 
statements
   previously issued from ``-Wunreachable-code`` and 
``-Wunreachable-code-fallthrough``
   by prioritizing ``-Wunreachable-code-fallthrough``.
+- Clang now avoids unnecessary diagnostic warnings for obvious expressions in
+  the case of binary operators with logical OR operations.
+  (`#57906 `_)
 
 Bug Fixes in This Version
 -


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
   static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
 // expected-note {{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{failed}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error {{failed}}
+  static_assert((true && invert(true)) || false, ""); // expected-error {{failed}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error {{failed}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,8 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);
+  Op && Op->getOpcode() != BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -179,6 +179,9 @@
 - Clang now avoids duplicate warnings on unreachable ``[[fallthrough]];`` statements
   previously issued from ``-Wunreachable-code`` and ``-Wunreachable-code-fallthrough``
   by prioritizing ``-Wunreachable-code-fallthrough``.
+- Clang now avoids unnecessary diagnostic 

[PATCH] D146376: Update static_assert message for redundant cases

2023-04-01 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 510186.
Krishna-13-cyber added a comment.

- Updated diff with `git clang-format HEAD~1`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146376/new/

https://reviews.llvm.org/D146376

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
 // expected-note 
{{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{failed}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error 
{{failed}}
+  static_assert((true && invert(true)) || false, ""); // expected-error 
{{failed}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error 
{{failed}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,8 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);
+  Op && Op->getOpcode() != BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
   static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
 // expected-note {{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{failed}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error {{failed}}
+  static_assert((true && invert(true)) || false, ""); // expected-error {{failed}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error {{failed}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,8 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);
+  Op && Op->getOpcode() != BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-30 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 509632.
Krishna-13-cyber added a comment.
Herald added subscribers: llvm-commits, kadircet, arphaman.
Herald added a project: LLVM.

- Updated patch
- Added testcases for chained operators




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146376/new/

https://reviews.llvm.org/D146376

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp
  llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn


Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
@@ -23,6 +23,7 @@
 "//clang/lib/Lex",
 "//clang/lib/Sema",
 "//clang/lib/Serialization",
+"//clang/lib/Testing",
 "//clang/lib/Tooling",
 "//clang/lib/Tooling/Core",
 "//clang/lib/Tooling/Inclusions",
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
 // expected-note 
{{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{failed}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error 
{{failed}}
+  static_assert((true && invert(true)) || false, ""); // expected-error 
{{failed}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error 
{{failed}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,7 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);Op && Op->getOpcode() != 
BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 


Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/unittests/BUILD.gn
@@ -23,6 +23,7 @@
 "//clang/lib/Lex",
 "//clang/lib/Sema",
 "//clang/lib/Serialization",
+"//clang/lib/Testing",
 "//clang/lib/Tooling",
 "//clang/lib/Tooling/Core",
 "//clang/lib/Tooling/Inclusions",
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,8 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
   static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
 // expected-note {{evaluates to 'false == true'}}
+  static_assert(true && false, ""); // expected-error {{failed}}
+  static_assert(invert(true) || invert(true) || false, ""); // expected-error {{failed}}
+  static_assert((true && invert(true)) || false, ""); // expected-error {{failed}}
+  static_assert(true && invert(false) && invert(true), ""); // expected-error {{failed}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,7 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);Op && Op->getOpcode() != BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-30 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 509589.
Krishna-13-cyber edited the summary of this revision.
Krishna-13-cyber added a comment.

This patch aims to remove some redundant cases of static assert messages where 
the expansions are particularly unhelpful. In this particular patch, we have 
ignored the printing of diagnostic warnings for binary operators with logical 
OR operations.
This is done to prioritise and prefer to emit longer diagnostic warnings for 
more important concerns elsewhere.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146376/new/

https://reviews.llvm.org/D146376

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,9 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
+
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
 // expected-note 
{{evaluates to 'false == true'}}
 
+  static_assert(true && false, ""); // expected-error {{failed}}
+
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,7 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);Op && Op->getOpcode() != 
BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,9 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
+
   static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
 // expected-note {{evaluates to 'false == true'}}
 
+  static_assert(true && false, ""); // expected-error {{failed}}
+
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16715,7 +16715,7 @@
 /// Try to print more useful information about a failed static_assert
 /// with expression \E
 void Sema::DiagnoseStaticAssertDetails(const Expr *E) {
-  if (const auto *Op = dyn_cast(E)) {
+  if (const auto *Op = dyn_cast(E);Op && Op->getOpcode() != BO_LOr) {
 const Expr *LHS = Op->getLHS()->IgnoreParenImpCasts();
 const Expr *RHS = Op->getRHS()->IgnoreParenImpCasts();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-29 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 509249.
Krishna-13-cyber added a comment.

I have removed the redundant comments and have moved the `if' condition above 
with the ongoing conditional statement (to avoid printing obvious expressions).

- Updated static_assert warning message
- Added Test cases




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146376/new/

https://reviews.llvm.org/D146376

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,9 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
+
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
 // expected-note 
{{evaluates to 'false == true'}}
 
+  static_assert(true && false, ""); // expected-error {{failed}}
+
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16725,7 +16725,7 @@
   return;
 
 // Don't print obvious expressions.
-if (!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS))
+if ((!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS)) || 
Op->getOpcode() == BO_LOr)
   return;
 
 struct {


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,9 +258,14 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}}
+
   static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
 // expected-note {{evaluates to 'false == true'}}
 
+  static_assert(true && false, ""); // expected-error {{failed}}
+
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16725,7 +16725,7 @@
   return;
 
 // Don't print obvious expressions.
-if (!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS))
+if ((!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS)) || Op->getOpcode() == BO_LOr)
   return;
 
 struct {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-25 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 508297.
Krishna-13-cyber added a comment.

Updated with the new test cases and implemented the logic suggested for 
ignoring the BO_LOr operators at the top level. My sincere apologies @tbaeder 
that I could not place this logic at the first instance.

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146376/new/

https://reviews.llvm.org/D146376

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,9 +258,17 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  /// Bools are printed with disjunction.
+  static_assert(invert(true) || invert(true), ""); // expected-error 
{{failed}} \
+
+  /// Bools are printed with an expected note.
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
 // expected-note 
{{evaluates to 'false == true'}}
 
+  /// Bools are printed with conjunction.
+  static_assert(true && false, ""); // expected-error {{failed}} \
+
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16728,6 +16728,10 @@
 if (!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS))
   return;
 
+// Ignore BO_LOr operators at the toplevel.
+if (Op->getOpcode() == BO_LOr)
+  return;
+
 struct {
   const clang::Expr *Cond;
   Expr::EvalResult Result;


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,9 +258,17 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  /// Bools are printed with disjunction.
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}} \
+
+  /// Bools are printed with an expected note.
   static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
 // expected-note {{evaluates to 'false == true'}}
 
+  /// Bools are printed with conjunction.
+  static_assert(true && false, ""); // expected-error {{failed}} \
+
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16728,6 +16728,10 @@
 if (!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS))
   return;
 
+// Ignore BO_LOr operators at the toplevel.
+if (Op->getOpcode() == BO_LOr)
+  return;
+
 struct {
   const clang::Expr *Cond;
   Expr::EvalResult Result;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-24 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber added a comment.

The above Binary operator test case says that there are two Boolean 
expressions,**UsefulToPrintExpr** says we can avoid to print these expressions 
as they are don't need a note and are understandable.

So if we go by this we will have to remove the note.By this we are removing 
note for boolean literals as well as expressions.It will be nice to make it 
generic rather than specifically target cases of false || false , false && 
false. As the warning note print out the boolean values which can be avoided 
giving preference to the other diagnostics in terms of boolean literals and 
expressions.

Yes, I making a **new diff for test cases** of conjunction and disjunction as 
well.




Comment at: clang/test/SemaCXX/static-assert.cpp:261-265
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
-// expected-note 
{{evaluates to 'false == true'}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}

cjdb wrote:
> We should also have a test for conjunctions, disjunctions, and negations.
Yes, I making a new diff for test cases of conjunction and disjunction as well.



Comment at: clang/test/SemaCXX/static-assert.cpp:262
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
-// expected-note 
{{evaluates to 'false == true'}}
 

tbaeder wrote:
> This diagnostic should be kept. From looking at the condition, it is not 
> obvious what the two functions evaluate to.
The above Binary operator test case says that there are two Boolean 
expressions,**UsefulToPrintExpr** says we can avoid to print these expressions 
as they are don't need a note and are understandable.

So if we go by this we will have to remove the note.By this we are removing 
note for boolean literals as well as expressions.It will be nice to make it 
generic rather than specifically target cases of false || false , false && 
false. As the warning note print out the boolean values which can be avoided 
giving preference to the other diagnostics in terms of boolean literals and 
expressions.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146376/new/

https://reviews.llvm.org/D146376

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


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-22 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 507413.
Krishna-13-cyber added a comment.

Have worked on the top level with Boolean literals unlike the previous diffs.I 
have updated the test case as well with this new upcoming change.

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146376/new/

https://reviews.llvm.org/D146376

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -259,7 +259,6 @@
 return !b;
   }
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
-// expected-note 
{{evaluates to 'false == true'}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16728,6 +16728,10 @@
 if (!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS))
   return;
 
+// Don't print obvious boolean literals.
+if (LHS->getType()->isBooleanType() && RHS->getType()->isBooleanType())
+  return;
+
 struct {
   const clang::Expr *Cond;
   Expr::EvalResult Result;


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -259,7 +259,6 @@
 return !b;
   }
   static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
-// expected-note {{evaluates to 'false == true'}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16728,6 +16728,10 @@
 if (!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS))
   return;
 
+// Don't print obvious boolean literals.
+if (LHS->getType()->isBooleanType() && RHS->getType()->isBooleanType())
+  return;
+
 struct {
   const clang::Expr *Cond;
   Expr::EvalResult Result;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-21 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 507113.
Krishna-13-cyber added a comment.

I have updated the patch without removing the whole of the previous block.I 
have added a condition to find the case where we don't need a diagnostic 
message to be printed or warned.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146376/new/

https://reviews.llvm.org/D146376

Files:
  clang/lib/Sema/SemaDeclCXX.cpp


Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16723,7 +16723,7 @@
 if ((isa(LHS) && RHS->getType()->isBooleanType()) ||
 (isa(RHS) && LHS->getType()->isBooleanType()))
   return;
-
+  
 // Don't print obvious expressions.
 if (!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS))
   return;
@@ -16744,9 +16744,16 @@
   DiagSide[I].Result.Val, Side->getType(), DiagSide[I].ValueString);
 }
 if (DiagSide[0].Print && DiagSide[1].Print) {
+  if (DiagSide[0].ValueString == SmallString<12>("false") && 
DiagSide[1].ValueString == SmallString<12>("false"))
+  {
+return;
+  }
+  else
+  {
   Diag(Op->getExprLoc(), diag::note_expr_evaluates_to)
   << DiagSide[0].ValueString << Op->getOpcodeStr()
   << DiagSide[1].ValueString << Op->getSourceRange();
+  }
 }
   }
 }


Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16723,7 +16723,7 @@
 if ((isa(LHS) && RHS->getType()->isBooleanType()) ||
 (isa(RHS) && LHS->getType()->isBooleanType()))
   return;
-
+  
 // Don't print obvious expressions.
 if (!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS))
   return;
@@ -16744,9 +16744,16 @@
   DiagSide[I].Result.Val, Side->getType(), DiagSide[I].ValueString);
 }
 if (DiagSide[0].Print && DiagSide[1].Print) {
+  if (DiagSide[0].ValueString == SmallString<12>("false") && DiagSide[1].ValueString == SmallString<12>("false"))
+  {
+return;
+  }
+  else
+  {
   Diag(Op->getExprLoc(), diag::note_expr_evaluates_to)
   << DiagSide[0].ValueString << Op->getOpcodeStr()
   << DiagSide[1].ValueString << Op->getSourceRange();
+  }
 }
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146376: Update static_assert message for redundant cases

2023-03-19 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber created this revision.
Krishna-13-cyber added reviewers: tbaeder, cjdb.
Herald added a project: All.
Krishna-13-cyber requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

There are some simple messages where an expansion isn't particularly helpful or 
needed. We aim to eliminate expansions that don't add much value for user (this 
will give us slightly more room or prioritise to have longer diagnostics 
elsewhere).

The test case for which it has been tested:

  constexpr auto is_gitlab = false;
  constexpr auto is_weekend = false;
  static_assert(is_gitlab or is_weekend);

**Previous warning/error message**:

  :4:1: error: static assertion failed due to requirement 'is_gitlab || 
is_weekend'
  static_assert(is_gitlab or is_weekend);
  ^ ~~~
  :4:25: note: expression evaluates to 'false || false'
  static_assert(is_gitlab or is_weekend);
~~^

**Currrent warning/error message**:

  :4:1: error: static assertion failed due to requirement 'is_gitlab'
  static_assert(is_gitlab and is_weekend);
  ^ ~


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146376

Files:
  clang/lib/Sema/SemaDeclCXX.cpp


Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16744,9 +16744,7 @@
   DiagSide[I].Result.Val, Side->getType(), DiagSide[I].ValueString);
 }
 if (DiagSide[0].Print && DiagSide[1].Print) {
-  Diag(Op->getExprLoc(), diag::note_expr_evaluates_to)
-  << DiagSide[0].ValueString << Op->getOpcodeStr()
-  << DiagSide[1].ValueString << Op->getSourceRange();
+  return;
 }
   }
 }


Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16744,9 +16744,7 @@
   DiagSide[I].Result.Val, Side->getType(), DiagSide[I].ValueString);
 }
 if (DiagSide[0].Print && DiagSide[1].Print) {
-  Diag(Op->getExprLoc(), diag::note_expr_evaluates_to)
-  << DiagSide[0].ValueString << Op->getOpcodeStr()
-  << DiagSide[1].ValueString << Op->getSourceRange();
+  return;
 }
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106674: Runtime for Interop directive

2021-10-24 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna marked 3 inline comments as done.
sriharikrishna added inline comments.



Comment at: openmp/libomptarget/src/interop.cpp:239-242
+  if (interop_val->interop_type == kmp_interop_type_tasksync) {
+__kmpc_omp_wait_deps(loc_ref, gtid, ndeps, dep_list, ndeps_noalias,
+ noalias_dep_list);
+  }

RaviNarayanaswamy wrote:
> Need to flush the queue if interop object was created with targetsync
A TODO has been left because flushing is not supported.



Comment at: openmp/libomptarget/src/interop.cpp:260-263
+  if (interop_val->interop_type == kmp_interop_type_tasksync) {
+__kmpc_omp_wait_deps(loc_ref, gtid, ndeps, dep_list, ndeps_noalias,
+ noalias_dep_list);
+  }

jdoerfert wrote:
> RaviNarayanaswamy wrote:
> > You don't wait for the omp tasks.  Need to flush the queue associated with 
> > the interop through the plugin
> Waiting for omp task is necessary and the above should do it. Flushing and 
> signaling out dependences will be added in the next revision.
A TODOs been left because flushing is not supported.



Comment at: openmp/runtime/src/kmp_ftn_entry.h:1449-1494
+/// TODO: Include the `omp.h` of the current build
+/* OpenMP 5.1 interop */
+typedef intptr_t omp_intptr_t;
+
+/* 0..omp_get_num_interop_properties()-1 are reserved for 
implementation-defined
+ * properties */
+typedef enum omp_interop_property {

jdoerfert wrote:
> RaviNarayanaswamy wrote:
> > Why do you have all this in openmp/runtime.  Openmp should call 
> > libomptarget to get interop properties. if libomptarget is not loaded it 
> > should return 0
> That is exactly what this code does, no? Look for libomptarget and redirect 
> to that one, otherwise return 0.
> Unsure I see your point. FWIW, this is copied from other functions we 
> duplicate in libomp but that actually are part of libomptarget.
Im leaving it as is.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106674/new/

https://reviews.llvm.org/D106674

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


[PATCH] D106674: Runtime for Interop directive

2021-10-24 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 381801.
sriharikrishna marked 16 inline comments as done.
sriharikrishna added a comment.

Runtime for Interop directive


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106674/new/

https://reviews.llvm.org/D106674

Files:
  openmp/libomptarget/include/interop.h
  openmp/libomptarget/include/omptarget.h
  openmp/libomptarget/include/omptargetplugin.h
  openmp/libomptarget/plugins/cuda/src/rtl.cpp
  openmp/libomptarget/plugins/exports
  openmp/libomptarget/src/CMakeLists.txt
  openmp/libomptarget/src/exports
  openmp/libomptarget/src/interop.cpp
  openmp/libomptarget/src/private.h
  openmp/libomptarget/src/rtl.cpp
  openmp/libomptarget/src/rtl.h
  openmp/libomptarget/test/offloading/interop.c
  openmp/runtime/src/dllexports
  openmp/runtime/src/kmp_ftn_entry.h
  openmp/runtime/src/kmp_ftn_os.h

Index: openmp/runtime/src/kmp_ftn_os.h
===
--- openmp/runtime/src/kmp_ftn_os.h
+++ openmp/runtime/src/kmp_ftn_os.h
@@ -140,6 +140,14 @@
 #define FTN_SET_TEAMS_THREAD_LIMIT omp_set_teams_thread_limit
 #define FTN_GET_TEAMS_THREAD_LIMIT omp_get_teams_thread_limit
 
+#define FTN_GET_NUM_INTEROP_PROPERTIES omp_get_num_interop_properties
+#define FTN_GET_INTEROP_INT omp_get_interop_int
+#define FTN_GET_INTEROP_PTR omp_get_interop_ptr
+#define FTN_GET_INTEROP_STR omp_get_interop_str
+#define FTN_GET_INTEROP_NAME omp_get_interop_name
+#define FTN_GET_INTEROP_TYPE_DESC omp_get_interop_type_desc
+#define FTN_GET_INTEROP_RC_DESC omp_get_interop_rc_desc
+
 #endif /* KMP_FTN_PLAIN */
 
 /*  */
Index: openmp/runtime/src/kmp_ftn_entry.h
===
--- openmp/runtime/src/kmp_ftn_entry.h
+++ openmp/runtime/src/kmp_ftn_entry.h
@@ -1446,6 +1446,120 @@
 #endif
 }
 
+/// TODO: Include the `omp.h` of the current build
+/* OpenMP 5.1 interop */
+typedef intptr_t omp_intptr_t;
+
+/* 0..omp_get_num_interop_properties()-1 are reserved for implementation-defined
+ * properties */
+typedef enum omp_interop_property {
+  omp_ipr_fr_id = -1,
+  omp_ipr_fr_name = -2,
+  omp_ipr_vendor = -3,
+  omp_ipr_vendor_name = -4,
+  omp_ipr_device_num = -5,
+  omp_ipr_platform = -6,
+  omp_ipr_device = -7,
+  omp_ipr_device_context = -8,
+  omp_ipr_targetsync = -9,
+  omp_ipr_first = -9
+} omp_interop_property_t;
+
+#define omp_interop_none 0
+
+typedef enum omp_interop_rc {
+  omp_irc_no_value = 1,
+  omp_irc_success = 0,
+  omp_irc_empty = -1,
+  omp_irc_out_of_range = -2,
+  omp_irc_type_int = -3,
+  omp_irc_type_ptr = -4,
+  omp_irc_type_str = -5,
+  omp_irc_other = -6
+} omp_interop_rc_t;
+
+typedef enum omp_interop_fr {
+  omp_ifr_cuda = 1,
+  omp_ifr_cuda_driver = 2,
+  omp_ifr_opencl = 3,
+  omp_ifr_sycl = 4,
+  omp_ifr_hip = 5,
+  omp_ifr_level_zero = 6,
+  omp_ifr_last = 7
+} omp_interop_fr_t;
+
+typedef void *omp_interop_t;
+
+// libomptarget, if loaded, provides this function
+int FTN_STDCALL FTN_GET_NUM_INTEROP_PROPERTIES(const omp_interop_t interop) {
+#if KMP_MIC || KMP_OS_DARWIN || defined(KMP_STUB)
+  return 0;
+#else
+  int (*fptr)(const omp_interop_t);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_num_interop_properties")))
+return (*fptr)(interop);
+  return 0;
+#endif // KMP_MIC || KMP_OS_DARWIN || KMP_OS_WINDOWS || defined(KMP_STUB)
+}
+
+/// TODO Convert FTN_GET_INTEROP_XXX functions into a macro like interop.cpp
+// libomptarget, if loaded, provides this function
+intptr_t FTN_STDCALL FTN_GET_INTEROP_INT(const omp_interop_t interop,
+ omp_interop_property_t property_id,
+ int *err) {
+  intptr_t (*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_int")))
+return (*fptr)(interop, property_id, err);
+  return 0;
+}
+
+// libomptarget, if loaded, provides this function
+void *FTN_STDCALL FTN_GET_INTEROP_PTR(const omp_interop_t interop,
+  omp_interop_property_t property_id,
+  int *err) {
+  void *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_ptr")))
+return (*fptr)(interop, property_id, err);
+  return nullptr;
+}
+
+// libomptarget, if loaded, provides this function
+const char *FTN_STDCALL FTN_GET_INTEROP_STR(const omp_interop_t interop,
+omp_interop_property_t property_id,
+int *err) {
+  const char *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_str")))
+return (*fptr)(interop, property_id, err);
+  return nullptr;
+}
+
+// libomptarget, if loaded, provides this function
+const char *FTN_STDCALL 

[PATCH] D106674: Runtime for Interop directive

2021-10-24 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 381800.
sriharikrishna added a comment.

Runtime for Interop directive


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106674/new/

https://reviews.llvm.org/D106674

Files:
  openmp/libomptarget/include/interop.h
  openmp/libomptarget/include/omptarget.h
  openmp/libomptarget/include/omptargetplugin.h
  openmp/libomptarget/plugins/cuda/src/rtl.cpp
  openmp/libomptarget/plugins/exports
  openmp/libomptarget/src/CMakeLists.txt
  openmp/libomptarget/src/exports
  openmp/libomptarget/src/interop.cpp
  openmp/libomptarget/src/private.h
  openmp/libomptarget/src/rtl.cpp
  openmp/libomptarget/src/rtl.h
  openmp/libomptarget/test/offloading/interop.c
  openmp/runtime/src/dllexports
  openmp/runtime/src/kmp_ftn_entry.h
  openmp/runtime/src/kmp_ftn_os.h

Index: openmp/runtime/src/kmp_ftn_os.h
===
--- openmp/runtime/src/kmp_ftn_os.h
+++ openmp/runtime/src/kmp_ftn_os.h
@@ -140,6 +140,14 @@
 #define FTN_SET_TEAMS_THREAD_LIMIT omp_set_teams_thread_limit
 #define FTN_GET_TEAMS_THREAD_LIMIT omp_get_teams_thread_limit
 
+#define FTN_GET_NUM_INTEROP_PROPERTIES omp_get_num_interop_properties
+#define FTN_GET_INTEROP_INT omp_get_interop_int
+#define FTN_GET_INTEROP_PTR omp_get_interop_ptr
+#define FTN_GET_INTEROP_STR omp_get_interop_str
+#define FTN_GET_INTEROP_NAME omp_get_interop_name
+#define FTN_GET_INTEROP_TYPE_DESC omp_get_interop_type_desc
+#define FTN_GET_INTEROP_RC_DESC omp_get_interop_rc_desc
+
 #endif /* KMP_FTN_PLAIN */
 
 /*  */
Index: openmp/runtime/src/kmp_ftn_entry.h
===
--- openmp/runtime/src/kmp_ftn_entry.h
+++ openmp/runtime/src/kmp_ftn_entry.h
@@ -1446,6 +1446,120 @@
 #endif
 }
 
+/// TODO: Include the `omp.h` of the current build
+/* OpenMP 5.1 interop */
+typedef intptr_t omp_intptr_t;
+
+/* 0..omp_get_num_interop_properties()-1 are reserved for implementation-defined
+ * properties */
+typedef enum omp_interop_property {
+  omp_ipr_fr_id = -1,
+  omp_ipr_fr_name = -2,
+  omp_ipr_vendor = -3,
+  omp_ipr_vendor_name = -4,
+  omp_ipr_device_num = -5,
+  omp_ipr_platform = -6,
+  omp_ipr_device = -7,
+  omp_ipr_device_context = -8,
+  omp_ipr_targetsync = -9,
+  omp_ipr_first = -9
+} omp_interop_property_t;
+
+#define omp_interop_none 0
+
+typedef enum omp_interop_rc {
+  omp_irc_no_value = 1,
+  omp_irc_success = 0,
+  omp_irc_empty = -1,
+  omp_irc_out_of_range = -2,
+  omp_irc_type_int = -3,
+  omp_irc_type_ptr = -4,
+  omp_irc_type_str = -5,
+  omp_irc_other = -6
+} omp_interop_rc_t;
+
+typedef enum omp_interop_fr {
+  omp_ifr_cuda = 1,
+  omp_ifr_cuda_driver = 2,
+  omp_ifr_opencl = 3,
+  omp_ifr_sycl = 4,
+  omp_ifr_hip = 5,
+  omp_ifr_level_zero = 6,
+  omp_ifr_last = 7
+} omp_interop_fr_t;
+
+typedef void *omp_interop_t;
+
+// libomptarget, if loaded, provides this function
+int FTN_STDCALL FTN_GET_NUM_INTEROP_PROPERTIES(const omp_interop_t interop) {
+#if KMP_MIC || KMP_OS_DARWIN || defined(KMP_STUB)
+  return 0;
+#else
+  int (*fptr)(const omp_interop_t);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_num_interop_properties")))
+return (*fptr)(interop);
+  return 0;
+#endif // KMP_MIC || KMP_OS_DARWIN || KMP_OS_WINDOWS || defined(KMP_STUB)
+}
+
+/// TODO Convert FTN_GET_INTEROP_XXX functions into a macro like interop.cpp
+// libomptarget, if loaded, provides this function
+intptr_t FTN_STDCALL FTN_GET_INTEROP_INT(const omp_interop_t interop,
+ omp_interop_property_t property_id,
+ int *err) {
+  intptr_t (*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_int")))
+return (*fptr)(interop, property_id, err);
+  return 0;
+}
+
+// libomptarget, if loaded, provides this function
+void *FTN_STDCALL FTN_GET_INTEROP_PTR(const omp_interop_t interop,
+  omp_interop_property_t property_id,
+  int *err) {
+  void *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_ptr")))
+return (*fptr)(interop, property_id, err);
+  return nullptr;
+}
+
+// libomptarget, if loaded, provides this function
+const char *FTN_STDCALL FTN_GET_INTEROP_STR(const omp_interop_t interop,
+omp_interop_property_t property_id,
+int *err) {
+  const char *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_str")))
+return (*fptr)(interop, property_id, err);
+  return nullptr;
+}
+
+// libomptarget, if loaded, provides this function
+const char *FTN_STDCALL FTN_GET_INTEROP_NAME(
+const omp_interop_t 

[PATCH] D106674: Runtime for Interop directive

2021-10-15 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna marked an inline comment as not done.
sriharikrishna added inline comments.



Comment at: openmp/libomptarget/src/interop.cpp:198-201
+  if (interop_type == kmp_interop_type_tasksync) {
+__kmpc_omp_wait_deps(loc_ref, gtid, ndeps, dep_list, ndeps_noalias,
+ noalias_dep_list);
+  }

RaviNarayanaswamy wrote:
> jdoerfert wrote:
> > RaviNarayanaswamy wrote:
> > > jdoerfert wrote:
> > > > RaviNarayanaswamy wrote:
> > > > > jdoerfert wrote:
> > > > > > RaviNarayanaswamy wrote:
> > > > > > > Interop object does not wait for any task from libomp.  
> > > > > > > Init just initializes the interop object.
> > > > > > > The initialization of interop object should  be done by the 
> > > > > > > plugin as only the plugin knows what properties are supported
> > > > > > > Interop object does not wait for any task from libomp. 
> > > > > > 
> > > > > > I don't know why you think we would not wait for libomp tasks. If 
> > > > > > we have dependences we need to wait for them.
> > > > > > 
> > > > > > > The initialization of interop object should be done by the plugin 
> > > > > > > as only the plugin knows what properties are supported.
> > > > > > 
> > > > > > It is, below. This is the generic part that then redirects to the 
> > > > > > plugin.
> > > > > Libomp would have not invoked the task which calls this routine if 
> > > > > there are dependences.   They must be executed before the task 
> > > > > containing  the interop creation is scheduled.
> > > > > 
> > > > > The interop_type should be passed to plugin and let it initialize the 
> > > > > common for all interop-types and then add based on the interop_type 
> > > > > Libomp would have not invoked the task which calls this routine if 
> > > > > there are dependences. They must be executed before the task 
> > > > > containing the interop creation is scheduled.
> > > > 
> > > > To me it seems you are assuming that we create a task in which this 
> > > > routine is called. We do not, as far as I can tell. See D105876.
> > > > 
> > > > > The interop_type should be passed to plugin and let it initialize the 
> > > > > common for all interop-types and then add based on the interop_type
> > > > 
> > > > So what you are trying to say is that `init_device_info` should take 
> > > > the `interop_type` too? That makes sense to me. But as discussed in 
> > > > other reviews recently, we should not extend the API for "future use 
> > > > cases" but extend it as use cases become relevant. For now it seems we 
> > > > can simply set up the `tgt_device_info` part of the `omp_interop_val_t` 
> > > > without knowing the `interop_type`.
> > > Then need to change this code since the interop_type  can be both 
> > > target_sync and  target which will not be handled correctly.  target_sync 
> > > and target have common initialization + additional  property base don the 
> > > interop_type requested
> > > Then need to change this code since the interop_type can be both 
> > > target_sync and target which will not be handled correctly. target_sync 
> > > and target have common initialization + additional property base don the 
> > > interop_type requested
> > 
> > Could you please elaborate what needs to be changed exactly. What 
> > information is currently not available in the setup as is? What properties 
> > would be different?
> Should be something like this
> 
> // NEED to add _kmp_interop_type_target  to represent interop target
> //  interop_ptr->device_info would initialize the following: device handle, 
> device_context, platform.
> if (interop_type == kmp_interop_type_target) { 
>  if (!Device.RTL || !Device.RTL->init_device_info ||
> Device.RTL->init_device_info(device_id, &(interop_ptr)->device_info,
>  &(interop_ptr)->err_str)) {
>   delete interop_ptr;
>   interop_ptr = omp_interop_none;
>  }
> // Add target sync if  request.
> if (interop_type == kmp_interop_type_tasksync) {
> if (!Device.RTL || !Device.RTL->init_async_info ||
> Device.RTL->init_async_info(device_id, &(interop_ptr)->async_info)) {
>   delete interop_ptr;
>   interop_ptr = omp_interop_none;
>   }
> 
> 
> 
It looks like the code you have written for kmp_interop_type_target already 
exists in the else part. So I am still puzzled about this. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106674/new/

https://reviews.llvm.org/D106674

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


[PATCH] D105876: OMPIRBuilder for Interop directive

2021-09-13 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 372329.
sriharikrishna added a comment.

OMPIRBuilder for Interop directive


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105876/new/

https://reviews.llvm.org/D105876

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/interop_irbuilder.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2736,6 +2736,87 @@
   return Builder.CreateCall(Fn, Args, Name);
 }
 
+CallInst *OpenMPIRBuilder::createOMPInteropInit(
+const LocationDescription , Value *InteropVar,
+omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,
+Value *DependenceAddress, bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(Int32, -1);
+  Constant *InteropTypeVal = ConstantInt::get(Int64, (int)InteropType);
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal = ConstantInt::get(Int32, HaveNowaitClause);
+  Value *Args[] = {
+  Ident,  ThreadId,   InteropVar,InteropTypeVal,
+  Device, NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_init);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropDestroy(
+const LocationDescription , Value *InteropVar, Value *Device,
+Value *NumDependences, Value *DependenceAddress, bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(Int32, -1);
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal = ConstantInt::get(Int32, HaveNowaitClause);
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_destroy);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropUse(const LocationDescription ,
+   Value *InteropVar, Value *Device,
+   Value *NumDependences,
+   Value *DependenceAddress,
+   bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(Int32, -1);
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal = ConstantInt::get(Int32, HaveNowaitClause);
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_use);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
 CallInst *OpenMPIRBuilder::createCachedThreadPrivate(
 const LocationDescription , llvm::Value *Pointer,
 llvm::ConstantInt *Size, const llvm::Twine ) {
Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -374,6 +374,15 @@
 __OMP_RTL(__kmpc_alloc, false, VoidPtr, /* Int */ Int32, SizeTy, VoidPtr)
 __OMP_RTL(__kmpc_free, false, Void, /* Int */ Int32, VoidPtr, VoidPtr)
 

[PATCH] D106674: Runtime for Interop directive

2021-07-28 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 362524.
sriharikrishna added a comment.

Runtime for Interop directive


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106674/new/

https://reviews.llvm.org/D106674

Files:
  openmp/libomptarget/include/interop.h
  openmp/libomptarget/include/omptarget.h
  openmp/libomptarget/include/omptargetplugin.h
  openmp/libomptarget/plugins/cuda/src/rtl.cpp
  openmp/libomptarget/plugins/exports
  openmp/libomptarget/src/CMakeLists.txt
  openmp/libomptarget/src/exports
  openmp/libomptarget/src/interop.cpp
  openmp/libomptarget/src/private.h
  openmp/libomptarget/src/rtl.cpp
  openmp/libomptarget/src/rtl.h
  openmp/runtime/src/dllexports
  openmp/runtime/src/kmp_ftn_entry.h
  openmp/runtime/src/kmp_ftn_os.h

Index: openmp/runtime/src/kmp_ftn_os.h
===
--- openmp/runtime/src/kmp_ftn_os.h
+++ openmp/runtime/src/kmp_ftn_os.h
@@ -140,6 +140,14 @@
 #define FTN_SET_TEAMS_THREAD_LIMIT omp_set_teams_thread_limit
 #define FTN_GET_TEAMS_THREAD_LIMIT omp_get_teams_thread_limit
 
+#define FTN_GET_NUM_INTEROP_PROPERTIES omp_get_num_interop_properties
+#define FTN_GET_INTEROP_INT omp_get_interop_int
+#define FTN_GET_INTEROP_PTR omp_get_interop_ptr
+#define FTN_GET_INTEROP_STR omp_get_interop_str
+#define FTN_GET_INTEROP_NAME omp_get_interop_name
+#define FTN_GET_INTEROP_TYPE_DESC omp_get_interop_type_desc
+#define FTN_GET_INTEROP_RC_DESC omp_get_interop_rc_desc
+
 #endif /* KMP_FTN_PLAIN */
 
 /*  */
Index: openmp/runtime/src/kmp_ftn_entry.h
===
--- openmp/runtime/src/kmp_ftn_entry.h
+++ openmp/runtime/src/kmp_ftn_entry.h
@@ -1446,6 +1446,120 @@
 #endif
 }
 
+/// TODO: Include the `omp.h` of the current build
+/* OpenMP 5.1 interop */
+typedef intptr_t omp_intptr_t;
+
+/* 0..omp_get_num_interop_properties()-1 are reserved for implementation-defined
+ * properties */
+typedef enum omp_interop_property {
+  omp_ipr_fr_id = -1,
+  omp_ipr_fr_name = -2,
+  omp_ipr_vendor = -3,
+  omp_ipr_vendor_name = -4,
+  omp_ipr_device_num = -5,
+  omp_ipr_platform = -6,
+  omp_ipr_device = -7,
+  omp_ipr_device_context = -8,
+  omp_ipr_targetsync = -9,
+  omp_ipr_first = -9
+} omp_interop_property_t;
+
+#define omp_interop_none 0
+
+typedef enum omp_interop_rc {
+  omp_irc_no_value = 1,
+  omp_irc_success = 0,
+  omp_irc_empty = -1,
+  omp_irc_out_of_range = -2,
+  omp_irc_type_int = -3,
+  omp_irc_type_ptr = -4,
+  omp_irc_type_str = -5,
+  omp_irc_other = -6
+} omp_interop_rc_t;
+
+typedef enum omp_interop_fr {
+  omp_ifr_cuda = 1,
+  omp_ifr_cuda_driver = 2,
+  omp_ifr_opencl = 3,
+  omp_ifr_sycl = 4,
+  omp_ifr_hip = 5,
+  omp_ifr_level_zero = 6,
+  omp_ifr_last = 7
+} omp_interop_fr_t;
+
+typedef void *omp_interop_t;
+
+// libomptarget, if loaded, provides this function
+int FTN_STDCALL FTN_GET_NUM_INTEROP_PROPERTIES(const omp_interop_t interop) {
+#if KMP_MIC || KMP_OS_DARWIN || defined(KMP_STUB)
+  return 0;
+#else
+  int (*fptr)(const omp_interop_t);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_num_interop_properties")))
+return (*fptr)(interop);
+  return 0;
+#endif // KMP_MIC || KMP_OS_DARWIN || KMP_OS_WINDOWS || defined(KMP_STUB)
+}
+
+/// TODO Convert FTN_GET_INTEROP_XXX functions into a macro like interop.cpp
+// libomptarget, if loaded, provides this function
+intptr_t FTN_STDCALL FTN_GET_INTEROP_INT(const omp_interop_t interop,
+ omp_interop_property_t property_id,
+ int *err) {
+  intptr_t (*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_int")))
+return (*fptr)(interop, property_id, err);
+  return 0;
+}
+
+// libomptarget, if loaded, provides this function
+void *FTN_STDCALL FTN_GET_INTEROP_PTR(const omp_interop_t interop,
+  omp_interop_property_t property_id,
+  int *err) {
+  void *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_ptr")))
+return (*fptr)(interop, property_id, err);
+  return nullptr;
+}
+
+// libomptarget, if loaded, provides this function
+const char *FTN_STDCALL FTN_GET_INTEROP_STR(const omp_interop_t interop,
+omp_interop_property_t property_id,
+int *err) {
+  const char *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_str")))
+return (*fptr)(interop, property_id, err);
+  return nullptr;
+}
+
+// libomptarget, if loaded, provides this function
+const char *FTN_STDCALL FTN_GET_INTEROP_NAME(
+const omp_interop_t interop, omp_interop_property_t property_id) {
+  const 

[PATCH] D106674: Runtime for Interop directive

2021-07-27 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 362280.
sriharikrishna added a comment.

Runtime for Interop directive


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106674/new/

https://reviews.llvm.org/D106674

Files:
  openmp/libomptarget/include/interop.h
  openmp/libomptarget/include/omptarget.h
  openmp/libomptarget/include/omptargetplugin.h
  openmp/libomptarget/plugins/cuda/src/rtl.cpp
  openmp/libomptarget/plugins/exports
  openmp/libomptarget/src/CMakeLists.txt
  openmp/libomptarget/src/exports
  openmp/libomptarget/src/interop.cpp
  openmp/libomptarget/src/private.h
  openmp/libomptarget/src/rtl.cpp
  openmp/libomptarget/src/rtl.h
  openmp/runtime/src/dllexports
  openmp/runtime/src/kmp_ftn_entry.h
  openmp/runtime/src/kmp_ftn_os.h

Index: openmp/runtime/src/kmp_ftn_os.h
===
--- openmp/runtime/src/kmp_ftn_os.h
+++ openmp/runtime/src/kmp_ftn_os.h
@@ -140,6 +140,14 @@
 #define FTN_SET_TEAMS_THREAD_LIMIT omp_set_teams_thread_limit
 #define FTN_GET_TEAMS_THREAD_LIMIT omp_get_teams_thread_limit
 
+#define FTN_GET_NUM_INTEROP_PROPERTIES omp_get_num_interop_properties
+#define FTN_GET_INTEROP_INT omp_get_interop_int
+#define FTN_GET_INTEROP_PTR omp_get_interop_ptr
+#define FTN_GET_INTEROP_STR omp_get_interop_str
+#define FTN_GET_INTEROP_NAME omp_get_interop_name
+#define FTN_GET_INTEROP_TYPE_DESC omp_get_interop_type_desc
+#define FTN_GET_INTEROP_RC_DESC omp_get_interop_rc_desc
+
 #endif /* KMP_FTN_PLAIN */
 
 /*  */
Index: openmp/runtime/src/kmp_ftn_entry.h
===
--- openmp/runtime/src/kmp_ftn_entry.h
+++ openmp/runtime/src/kmp_ftn_entry.h
@@ -1446,6 +1446,134 @@
 #endif
 }
 
+/// TODO: Include the `omp.h` of the current build
+/* OpenMP 5.1 interop */
+typedef intptr_t omp_intptr_t;
+
+/* 0..omp_get_num_interop_properties()-1 are reserved for implementation-defined
+ * properties */
+typedef enum omp_interop_property {
+  omp_ipr_fr_id = -1,
+  omp_ipr_fr_name = -2,
+  omp_ipr_vendor = -3,
+  omp_ipr_vendor_name = -4,
+  omp_ipr_device_num = -5,
+  omp_ipr_platform = -6,
+  omp_ipr_device = -7,
+  omp_ipr_device_context = -8,
+  omp_ipr_targetsync = -9,
+  omp_ipr_first = -9
+} omp_interop_property_t;
+
+#define omp_interop_none 0
+
+typedef enum omp_interop_rc {
+  omp_irc_no_value = 1,
+  omp_irc_success = 0,
+  omp_irc_empty = -1,
+  omp_irc_out_of_range = -2,
+  omp_irc_type_int = -3,
+  omp_irc_type_ptr = -4,
+  omp_irc_type_str = -5,
+  omp_irc_other = -6
+} omp_interop_rc_t;
+
+typedef enum omp_interop_fr {
+  omp_ifr_cuda = 1,
+  omp_ifr_cuda_driver = 2,
+  omp_ifr_opencl = 3,
+  omp_ifr_sycl = 4,
+  omp_ifr_hip = 5,
+  omp_ifr_level_zero = 6,
+  omp_ifr_last = 7
+} omp_interop_fr_t;
+
+typedef void *omp_interop_t;
+
+// libomptarget, if loaded, provides this function
+int FTN_STDCALL FTN_GET_NUM_INTEROP_PROPERTIES(const omp_interop_t interop) {
+#if KMP_MIC || KMP_OS_DARWIN || defined(KMP_STUB)
+  return 0;
+#else
+  int (*fptr)(const omp_interop_t);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_num_interop_properties"))) {
+return (*fptr)(interop);
+  } else { // liboffload & libomptarget don't exist
+return 0;
+  }
+#endif // KMP_MIC || KMP_OS_DARWIN || KMP_OS_WINDOWS || defined(KMP_STUB)
+}
+
+/// TODO Convert FTN_GET_INTEROP_XXX functions into a macro like interop.cpp
+// libomptarget, if loaded, provides this function
+intptr_t FTN_STDCALL FTN_GET_INTEROP_INT(const omp_interop_t interop,
+ omp_interop_property_t property_id,
+ int *err) {
+  intptr_t (*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_int"))) {
+return (*fptr)(interop, property_id, err);
+  } else { // liboffload & libomptarget don't exist
+return 0;
+  }
+}
+
+// libomptarget, if loaded, provides this function
+void *FTN_STDCALL FTN_GET_INTEROP_PTR(const omp_interop_t interop,
+  omp_interop_property_t property_id,
+  int *err) {
+  void *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_ptr"))) {
+return (*fptr)(interop, property_id, err);
+  } else { // liboffload & libomptarget don't exist
+return (void *)0;
+  }
+}
+
+// libomptarget, if loaded, provides this function
+const char *FTN_STDCALL FTN_GET_INTEROP_STR(const omp_interop_t interop,
+omp_interop_property_t property_id,
+int *err) {
+  const char *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_str"))) {
+return (*fptr)(interop, property_id, err);
+  } else { 

[PATCH] D106674: Runtime for Interop directive

2021-07-27 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 362269.
sriharikrishna added a comment.

Runtime for Interop directive


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106674/new/

https://reviews.llvm.org/D106674

Files:
  openmp/libomptarget/include/interop.h
  openmp/libomptarget/include/omptarget.h
  openmp/libomptarget/include/omptargetplugin.h
  openmp/libomptarget/plugins/cuda/src/rtl.cpp
  openmp/libomptarget/plugins/exports
  openmp/libomptarget/src/CMakeLists.txt
  openmp/libomptarget/src/exports
  openmp/libomptarget/src/interop.cpp
  openmp/libomptarget/src/private.h
  openmp/libomptarget/src/rtl.cpp
  openmp/libomptarget/src/rtl.h
  openmp/runtime/src/dllexports
  openmp/runtime/src/kmp_ftn_entry.h
  openmp/runtime/src/kmp_ftn_os.h

Index: openmp/runtime/src/kmp_ftn_os.h
===
--- openmp/runtime/src/kmp_ftn_os.h
+++ openmp/runtime/src/kmp_ftn_os.h
@@ -140,6 +140,14 @@
 #define FTN_SET_TEAMS_THREAD_LIMIT omp_set_teams_thread_limit
 #define FTN_GET_TEAMS_THREAD_LIMIT omp_get_teams_thread_limit
 
+#define FTN_GET_NUM_INTEROP_PROPERTIES omp_get_num_interop_properties
+#define FTN_GET_INTEROP_INT omp_get_interop_int
+#define FTN_GET_INTEROP_PTR omp_get_interop_ptr
+#define FTN_GET_INTEROP_STR omp_get_interop_str
+#define FTN_GET_INTEROP_NAME omp_get_interop_name
+#define FTN_GET_INTEROP_TYPE_DESC omp_get_interop_type_desc
+#define FTN_GET_INTEROP_RC_DESC omp_get_interop_rc_desc
+
 #endif /* KMP_FTN_PLAIN */
 
 /*  */
Index: openmp/runtime/src/kmp_ftn_entry.h
===
--- openmp/runtime/src/kmp_ftn_entry.h
+++ openmp/runtime/src/kmp_ftn_entry.h
@@ -1446,6 +1446,135 @@
 #endif
 }
 
+/// TODO: Include the `omp.h` of the current build
+/* OpenMP 5.1 interop */
+typedef intptr_t omp_intptr_t;
+
+/* 0..omp_get_num_interop_properties()-1 are reserved for implementation-defined
+ * properties */
+typedef enum omp_interop_property {
+  omp_ipr_fr_id = -1,
+  omp_ipr_fr_name = -2,
+  omp_ipr_vendor = -3,
+  omp_ipr_vendor_name = -4,
+  omp_ipr_device_num = -5,
+  omp_ipr_platform = -6,
+  omp_ipr_device = -7,
+  omp_ipr_device_context = -8,
+  omp_ipr_targetsync = -9,
+  omp_ipr_first = -9
+} omp_interop_property_t;
+
+#define omp_interop_none 0
+
+typedef enum omp_interop_rc {
+  omp_irc_no_value = 1,
+  omp_irc_success = 0,
+  omp_irc_empty = -1,
+  omp_irc_out_of_range = -2,
+  omp_irc_type_int = -3,
+  omp_irc_type_ptr = -4,
+  omp_irc_type_str = -5,
+  omp_irc_other = -6
+} omp_interop_rc_t;
+
+typedef enum omp_interop_fr {
+  omp_ifr_cuda = 1,
+  omp_ifr_cuda_driver = 2,
+  omp_ifr_opencl = 3,
+  omp_ifr_sycl = 4,
+  omp_ifr_hip = 5,
+  omp_ifr_level_zero = 6,
+  omp_ifr_last = 7
+} omp_interop_fr_t;
+
+typedef void *omp_interop_t;
+
+// libomptarget, if loaded, provides this function
+int FTN_STDCALL FTN_GET_NUM_INTEROP_PROPERTIES(const omp_interop_t interop) {
+  assert(0);
+#if KMP_MIC || KMP_OS_DARWIN || defined(KMP_STUB)
+  return 0;
+#else
+  int (*fptr)(const omp_interop_t);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_num_interop_properties"))) {
+return (*fptr)(interop);
+  } else { // liboffload & libomptarget don't exist
+return 0;
+  }
+#endif // KMP_MIC || KMP_OS_DARWIN || KMP_OS_WINDOWS || defined(KMP_STUB)
+}
+
+/// TODO Convert FTN_GET_INTEROP_XXX functions into a macro like interop.cpp
+// libomptarget, if loaded, provides this function
+intptr_t FTN_STDCALL FTN_GET_INTEROP_INT(const omp_interop_t interop,
+ omp_interop_property_t property_id,
+ int *err) {
+  intptr_t (*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_int"))) {
+return (*fptr)(interop, property_id, err);
+  } else { // liboffload & libomptarget don't exist
+return 0;
+  }
+}
+
+// libomptarget, if loaded, provides this function
+void *FTN_STDCALL FTN_GET_INTEROP_PTR(const omp_interop_t interop,
+  omp_interop_property_t property_id,
+  int *err) {
+  void *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_ptr"))) {
+return (*fptr)(interop, property_id, err);
+  } else { // liboffload & libomptarget don't exist
+return (void *)0;
+  }
+}
+
+// libomptarget, if loaded, provides this function
+const char *FTN_STDCALL FTN_GET_INTEROP_STR(const omp_interop_t interop,
+omp_interop_property_t property_id,
+int *err) {
+  const char *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_str"))) {
+return (*fptr)(interop, property_id, err);

[PATCH] D106674: Runtime for Interop directive

2021-07-27 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 362266.
sriharikrishna added a comment.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.

Runtime for Interop directive


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106674/new/

https://reviews.llvm.org/D106674

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/interop_irbuilder.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  openmp/libomptarget/include/interop.h
  openmp/libomptarget/include/omptarget.h
  openmp/libomptarget/include/omptargetplugin.h
  openmp/libomptarget/plugins/cuda/src/rtl.cpp
  openmp/libomptarget/plugins/exports
  openmp/libomptarget/src/CMakeLists.txt
  openmp/libomptarget/src/exports
  openmp/libomptarget/src/interop.cpp
  openmp/libomptarget/src/private.h
  openmp/libomptarget/src/rtl.cpp
  openmp/libomptarget/src/rtl.h
  openmp/runtime/src/dllexports
  openmp/runtime/src/kmp_ftn_entry.h
  openmp/runtime/src/kmp_ftn_os.h

Index: openmp/runtime/src/kmp_ftn_os.h
===
--- openmp/runtime/src/kmp_ftn_os.h
+++ openmp/runtime/src/kmp_ftn_os.h
@@ -140,6 +140,14 @@
 #define FTN_SET_TEAMS_THREAD_LIMIT omp_set_teams_thread_limit
 #define FTN_GET_TEAMS_THREAD_LIMIT omp_get_teams_thread_limit
 
+#define FTN_GET_NUM_INTEROP_PROPERTIES omp_get_num_interop_properties
+#define FTN_GET_INTEROP_INT omp_get_interop_int
+#define FTN_GET_INTEROP_PTR omp_get_interop_ptr
+#define FTN_GET_INTEROP_STR omp_get_interop_str
+#define FTN_GET_INTEROP_NAME omp_get_interop_name
+#define FTN_GET_INTEROP_TYPE_DESC omp_get_interop_type_desc
+#define FTN_GET_INTEROP_RC_DESC omp_get_interop_rc_desc
+
 #endif /* KMP_FTN_PLAIN */
 
 /*  */
Index: openmp/runtime/src/kmp_ftn_entry.h
===
--- openmp/runtime/src/kmp_ftn_entry.h
+++ openmp/runtime/src/kmp_ftn_entry.h
@@ -1446,6 +1446,135 @@
 #endif
 }
 
+/// TODO: Include the `omp.h` of the current build
+/* OpenMP 5.1 interop */
+typedef intptr_t omp_intptr_t;
+
+/* 0..omp_get_num_interop_properties()-1 are reserved for implementation-defined
+ * properties */
+typedef enum omp_interop_property {
+  omp_ipr_fr_id = -1,
+  omp_ipr_fr_name = -2,
+  omp_ipr_vendor = -3,
+  omp_ipr_vendor_name = -4,
+  omp_ipr_device_num = -5,
+  omp_ipr_platform = -6,
+  omp_ipr_device = -7,
+  omp_ipr_device_context = -8,
+  omp_ipr_targetsync = -9,
+  omp_ipr_first = -9
+} omp_interop_property_t;
+
+#define omp_interop_none 0
+
+typedef enum omp_interop_rc {
+  omp_irc_no_value = 1,
+  omp_irc_success = 0,
+  omp_irc_empty = -1,
+  omp_irc_out_of_range = -2,
+  omp_irc_type_int = -3,
+  omp_irc_type_ptr = -4,
+  omp_irc_type_str = -5,
+  omp_irc_other = -6
+} omp_interop_rc_t;
+
+typedef enum omp_interop_fr {
+  omp_ifr_cuda = 1,
+  omp_ifr_cuda_driver = 2,
+  omp_ifr_opencl = 3,
+  omp_ifr_sycl = 4,
+  omp_ifr_hip = 5,
+  omp_ifr_level_zero = 6,
+  omp_ifr_last = 7
+} omp_interop_fr_t;
+
+typedef void *omp_interop_t;
+
+// libomptarget, if loaded, provides this function
+int FTN_STDCALL FTN_GET_NUM_INTEROP_PROPERTIES(const omp_interop_t interop) {
+  assert(0);
+#if KMP_MIC || KMP_OS_DARWIN || defined(KMP_STUB)
+  return 0;
+#else
+  int (*fptr)(const omp_interop_t);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_num_interop_properties"))) {
+return (*fptr)(interop);
+  } else { // liboffload & libomptarget don't exist
+return 0;
+  }
+#endif // KMP_MIC || KMP_OS_DARWIN || KMP_OS_WINDOWS || defined(KMP_STUB)
+}
+
+/// TODO Convert FTN_GET_INTEROP_XXX functions into a macro like interop.cpp
+// libomptarget, if loaded, provides this function
+intptr_t FTN_STDCALL FTN_GET_INTEROP_INT(const omp_interop_t interop,
+ omp_interop_property_t property_id,
+ int *err) {
+  intptr_t (*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_int"))) {
+return (*fptr)(interop, property_id, err);
+  } else { // liboffload & libomptarget don't exist
+return 0;
+  }
+}
+
+// libomptarget, if loaded, provides this function
+void *FTN_STDCALL FTN_GET_INTEROP_PTR(const omp_interop_t interop,
+  omp_interop_property_t property_id,
+  int *err) {
+  void *(*fptr)(const omp_interop_t, omp_interop_property_t, int *);
+  if ((*(void **)() = KMP_DLSYM_NEXT("omp_get_interop_ptr"))) {
+return (*fptr)(interop, property_id, err);
+  } else { // liboffload & libomptarget don't exist
+return (void *)0;
+  }
+}
+
+// 

[PATCH] D105876: OMPIRBuilder for Interop directive

2021-07-27 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 362070.
sriharikrishna added a comment.

OMPIRBuilder for Interop directive


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105876/new/

https://reviews.llvm.org/D105876

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/interop_irbuilder.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2173,6 +2173,90 @@
   return Builder.CreateCall(Fn, Args, Name);
 }
 
+CallInst *OpenMPIRBuilder::createOMPInteropInit(
+const LocationDescription , Value *InteropVar,
+omp::OMPInteropType InteropType, Value *Device, Value *NumDependences,
+Value *DependenceAddress, bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  Constant *InteropTypeVal = ConstantInt::get(Int64, (int)InteropType);
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,   InteropVar,InteropTypeVal,
+  Device, NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_init);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropDestroy(
+const LocationDescription , Value *InteropVar, Value *Device,
+Value *NumDependences, Value *DependenceAddress, bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_destroy);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropUse(const LocationDescription ,
+   Value *InteropVar, Value *Device,
+   Value *NumDependences,
+   Value *DependenceAddress,
+   bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_use);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
 CallInst *OpenMPIRBuilder::createCachedThreadPrivate(
 const LocationDescription , llvm::Value *Pointer,
 llvm::ConstantInt *Size, const llvm::Twine ) {
Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -371,6 +371,15 @@
 

[PATCH] D105876: OMPIRBuilder for Interop directive

2021-07-27 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 361913.
sriharikrishna marked an inline comment as done.
sriharikrishna added a comment.

OMPIRBuilder for Interop directive


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105876/new/

https://reviews.llvm.org/D105876

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/interop_irbuilder.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2173,6 +2173,96 @@
   return Builder.CreateCall(Fn, Args, Name);
 }
 
+CallInst *OpenMPIRBuilder::createOMPInteropInit(const LocationDescription ,
+Value *InteropVar,
+omp::OMPInteropType InteropType,
+Value *Device,
+Value *NumDependences,
+Value *DependenceAddress,
+bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  Constant *InteropTypeVal =
+  ConstantInt::get(Int64, (int)InteropType);
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,   InteropVar,InteropTypeVal,
+  Device, NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_init);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropDestroy(
+const LocationDescription , Value *InteropVar, Value *Device,
+Value *NumDependences, Value *DependenceAddress,
+bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_destroy);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropUse(const LocationDescription ,
+   Value *InteropVar,
+   Value *Device,
+   Value *NumDependences,
+   Value *DependenceAddress,
+   bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___tgt_interop_use);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
 CallInst 

[PATCH] D105876: OMPIRBuilder for Interop directive

2021-07-27 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna marked an inline comment as done.
sriharikrishna added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:6330-6331
+  if (const auto *C = S.getSingleClause()) {
+llvm::Value *InteropvarPtr =
+EmitLValue(C->getInteropVar()).getPointer(*this);
+llvm::omp::OMPInteropType InteropType = llvm::omp::OMPInteropType::Unknown;

ABataev wrote:
> This code is common for all `if-else` braches, move out of the conditional 
> blocks?
Moving the common line out will require checking the kind of clause in the 
directive. So, I prefer to leave it as is. 



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:6335-6336
+  InteropType = llvm::omp::OMPInteropType::Target;
+else if (C->getIsTargetSync())
+  InteropType = llvm::omp::OMPInteropType::TargetSync;
+OMPBuilder.createOMPInteropInit(Builder, InteropvarPtr, InteropType, 
Device,

ABataev wrote:
> Can we have anything else rather than `C->getIsTargetSync()` here? If no, 
> then it should look like this:
> ```
> if (C->getIsTarget()) {
>   InteropType = llvm::omp::OMPInteropType::Target;
> } else {
>   assert(C->getIsTargetSync() && "Expected ...");
>   InteropType = llvm::omp::OMPInteropType::TargetSync;
> }
> ```
The standard only allows for Target and TargetSync. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105876/new/

https://reviews.llvm.org/D105876

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


[PATCH] D105876: OMPIRBuilder for Interop directive

2021-07-23 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 361186.
sriharikrishna added a comment.

OMPIRBuilder for Interop directive. Squashed commit


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105876/new/

https://reviews.llvm.org/D105876

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/interop_irbuilder.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2173,6 +2173,96 @@
   return Builder.CreateCall(Fn, Args, Name);
 }
 
+CallInst *OpenMPIRBuilder::createOMPInteropInit(const LocationDescription ,
+Value *InteropVar,
+omp::OMPInteropType InteropType,
+Value *Device,
+Value *NumDependences,
+Value *DependenceAddress,
+bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  Constant *InteropTypeVal =
+  ConstantInt::get(Int64, (int)InteropType);
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,   InteropVar,InteropTypeVal,
+  Device, NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_interop_init);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropDestroy(
+const LocationDescription , Value *InteropVar, Value *Device,
+Value *NumDependences, Value *DependenceAddress,
+bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_interop_destroy);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropUse(const LocationDescription ,
+   Value *InteropVar,
+   Value *Device,
+   Value *NumDependences,
+   Value *DependenceAddress,
+   bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_interop_use);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
 CallInst 

[PATCH] D105876: OMPIRBuilder for Interop directive

2021-07-22 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 361079.
sriharikrishna added a comment.

OMPIRBuilder for Interop directive. Squashed commit


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105876/new/

https://reviews.llvm.org/D105876

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/interop_irbuilder.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2173,6 +2173,96 @@
   return Builder.CreateCall(Fn, Args, Name);
 }
 
+CallInst *OpenMPIRBuilder::createOMPInteropInit(const LocationDescription ,
+Value *InteropVar,
+omp::OMPInteropType InteropType,
+Value *Device,
+Value *NumDependences,
+Value *DependenceAddress,
+bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  Constant *InteropTypeVal =
+  ConstantInt::get(Int64, (int)InteropType);
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,   InteropVar,InteropTypeVal,
+  Device, NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_interop_init);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropDestroy(
+const LocationDescription , Value *InteropVar, Value *Device,
+Value *NumDependences, Value *DependenceAddress,
+bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_interop_destroy);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropUse(const LocationDescription ,
+   Value *InteropVar,
+   Value *Device,
+   Value *NumDependences,
+   Value *DependenceAddress,
+   bool HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_interop_use);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
 CallInst 

[PATCH] D105876: OMPIRBuilder for Interop directive

2021-07-14 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 358631.
sriharikrishna added a comment.

OMPIRBuilder for Interop directive


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105876/new/

https://reviews.llvm.org/D105876

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/interop_irbuilder.cpp

Index: clang/test/OpenMP/interop_irbuilder.cpp
===
--- clang/test/OpenMP/interop_irbuilder.cpp
+++ clang/test/OpenMP/interop_irbuilder.cpp
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs
-// RUN: %clang_cc1 -verify -fopenmp  -o -  %s
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -emit-llvm %s -o - | FileCheck %s
 
 // expected-no-diagnostics
 typedef void *omp_interop_t;
@@ -23,3 +23,197 @@
   #pragma omp interop destroy(interop) depend(in:D0, D1)
 }
 
+// ###: %clang_cc1 -verify -fopenmp -emit-llvm  -o -| FileCheck  %s
+// CHECK-64-LABEL: @_Z5test1v(
+// CHECK-64-NEXT:  entry:
+// CHECK-64-NEXT:[[DEVICE_ID:%.*]] = alloca i32, align 4
+// CHECK-64-NEXT:[[D0:%.*]] = alloca i32, align 4
+// CHECK-64-NEXT:[[D1:%.*]] = alloca i32, align 4
+// CHECK-64-NEXT:[[INTEROP:%.*]] = alloca i8*, align 8
+// CHECK-64-NEXT:[[DOTDEP_ARR_ADDR:%.*]] = alloca [2 x %struct.kmp_depend_info], align 8
+// CHECK-64-NEXT:[[DEP_COUNTER_ADDR:%.*]] = alloca i64, align 8
+// CHECK-64-NEXT:[[DOTDEP_ARR_ADDR5:%.*]] = alloca [2 x %struct.kmp_depend_info], align 8
+// CHECK-64-NEXT:[[DEP_COUNTER_ADDR6:%.*]] = alloca i64, align 8
+// CHECK-64-NEXT:store i32 4, i32* [[DEVICE_ID]], align 4
+// CHECK-64-NEXT:[[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]])
+// CHECK-64-NEXT:call void @__kmpc_interop_init(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]], i8** [[INTEROP]], i64 1, i32 -1, i32 0, i8* null, i32 0)
+// CHECK-64-NEXT:[[OMP_GLOBAL_THREAD_NUM1:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]])
+// CHECK-64-NEXT:call void @__kmpc_interop_init(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM1]], i8** [[INTEROP]], i64 2, i32 -1, i32 0, i8* null, i32 0)
+// CHECK-64-NEXT:[[TMP0:%.*]] = load i32, i32* [[DEVICE_ID]], align 4
+// CHECK-64-NEXT:[[OMP_GLOBAL_THREAD_NUM2:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]])
+// CHECK-64-NEXT:call void @__kmpc_interop_init(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM2]], i8** [[INTEROP]], i64 1, i32 [[TMP0]], i32 0, i8* null, i32 0)
+// CHECK-64-NEXT:[[TMP1:%.*]] = load i32, i32* [[DEVICE_ID]], align 4
+// CHECK-64-NEXT:[[OMP_GLOBAL_THREAD_NUM3:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1]])
+// CHECK-64-NEXT:call void @__kmpc_interop_init(%struct.ident_t* @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM3]], i8** [[INTEROP]], i64 2, i32 [[TMP1]], i32 0, i8* null, i32 0)
+// CHECK-64-NEXT:[[TMP2:%.*]] = getelementptr inbounds [2 x %struct.kmp_depend_info], [2 x %struct.kmp_depend_info]* [[DOTDEP_ARR_ADDR]], i64 0, i64 0
+// CHECK-64-NEXT:[[TMP3:%.*]] = getelementptr [[STRUCT_KMP_DEPEND_INFO:%.*]], %struct.kmp_depend_info* [[TMP2]], i64 0
+// CHECK-64-NEXT:[[TMP4:%.*]] = getelementptr inbounds [[STRUCT_KMP_DEPEND_INFO]], %struct.kmp_depend_info* [[TMP3]], i32 0, i32 0
+// CHECK-64-NEXT:[[TMP5:%.*]] = ptrtoint i32* [[D0]] to i64
+// CHECK-64-NEXT:store i64 [[TMP5]], i64* [[TMP4]], align 8
+// CHECK-64-NEXT:[[TMP6:%.*]] = getelementptr inbounds [[STRUCT_KMP_DEPEND_INFO]], %struct.kmp_depend_info* [[TMP3]], i32 0, i32 1
+// CHECK-64-NEXT:store i64 4, i64* [[TMP6]], align 8
+// CHECK-64-NEXT:[[TMP7:%.*]] = getelementptr inbounds [[STRUCT_KMP_DEPEND_INFO]], %struct.kmp_depend_info* [[TMP3]], i32 0, i32 2
+// CHECK-64-NEXT:store i8 1, i8* [[TMP7]], align 8
+// CHECK-64-NEXT:[[TMP8:%.*]] = getelementptr [[STRUCT_KMP_DEPEND_INFO]], %struct.kmp_depend_info* [[TMP2]], i64 1
+// CHECK-64-NEXT:[[TMP9:%.*]] = getelementptr inbounds [[STRUCT_KMP_DEPEND_INFO]], %struct.kmp_depend_info* [[TMP8]], i32 0, i32 0
+// CHECK-64-NEXT:[[TMP10:%.*]] = ptrtoint i32* [[D1]] to i64
+// CHECK-64-NEXT:store i64 [[TMP10]], i64* [[TMP9]], align 8
+// CHECK-64-NEXT:[[TMP11:%.*]] = getelementptr inbounds [[STRUCT_KMP_DEPEND_INFO]], %struct.kmp_depend_info* [[TMP8]], i32 0, i32 1
+// CHECK-64-NEXT:store i64 4, i64* [[TMP11]], align 8
+// CHECK-64-NEXT:[[TMP12:%.*]] = getelementptr inbounds [[STRUCT_KMP_DEPEND_INFO]], %struct.kmp_depend_info* [[TMP8]], i32 0, i32 2
+// CHECK-64-NEXT:store i8 1, i8* [[TMP12]], align 8
+// CHECK-64-NEXT:store i64 2, i64* [[DEP_COUNTER_ADDR]], align 8
+// CHECK-64-NEXT:[[TMP13:%.*]] = bitcast %struct.kmp_depend_info* [[TMP2]] to i8*
+// CHECK-64-NEXT:[[OMP_GLOBAL_THREAD_NUM4:%.*]] = call i32 

[PATCH] D105876: OMPIRBuilder for Interop directive

2021-07-14 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna updated this revision to Diff 358587.
sriharikrishna added a comment.

Address reviewer comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105876/new/

https://reviews.llvm.org/D105876

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/interop_irbuilder.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2175,11 +2175,11 @@
 
 CallInst *OpenMPIRBuilder::createOMPInteropInit(const LocationDescription ,
 Value *InteropVar,
-OMPInteropType InteropType,
-llvm::Value *Device,
-llvm::Value *NumDependences,
-llvm::Value *DependenceAddress,
-int HaveNowaitClause) {
+omp::OMPInteropType InteropType,
+Value *Device,
+Value *NumDependences,
+Value *DependenceAddress,
+bool HaveNowaitClause) {
   IRBuilder<>::InsertPointGuard IPG(Builder);
   Builder.restoreIP(Loc.IP);
 
@@ -2188,12 +2188,12 @@
   Value *ThreadId = getOrCreateThreadID(Ident);
   if (Device == NULL)
 Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
-  ConstantInt *InteropTypeVal =
-  ConstantInt::get(M.getContext(), APInt(64, (int)InteropType, true));
+  Constant *InteropTypeVal =
+  ConstantInt::get(Int64, (int)InteropType);
   if (NumDependences == nullptr) {
-NumDependences = ConstantInt::get(M.getContext(), APInt(32, 0, true));
-PointerType *PointerTy_0 = llvm::Type::getInt8PtrTy(M.getContext());
-DependenceAddress = ConstantPointerNull::get(PointerTy_0);
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
   }
   Value *HaveNowaitClauseVal =
   ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
@@ -2207,9 +2207,9 @@
 }
 
 CallInst *OpenMPIRBuilder::createOMPInteropDestroy(
-const LocationDescription , Value *InteropVar, llvm::Value *Device,
-llvm::Value *NumDependences, llvm::Value *DependenceAddress,
-int HaveNowaitClause) {
+const LocationDescription , Value *InteropVar, Value *Device,
+Value *NumDependences, Value *DependenceAddress,
+bool HaveNowaitClause) {
   IRBuilder<>::InsertPointGuard IPG(Builder);
   Builder.restoreIP(Loc.IP);
 
@@ -2219,9 +2219,9 @@
   if (Device == NULL)
 Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
   if (NumDependences == nullptr) {
-NumDependences = ConstantInt::get(M.getContext(), APInt(32, 0, true));
-PointerType *PointerTy_0 = llvm::Type::getInt8PtrTy(M.getContext());
-DependenceAddress = ConstantPointerNull::get(PointerTy_0);
+NumDependences = ConstantInt::get(Int32, 0);
+PointerType *PointerTypeVar = Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTypeVar);
   }
   Value *HaveNowaitClauseVal =
   ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
@@ -2236,10 +2236,10 @@
 
 CallInst *OpenMPIRBuilder::createOMPInteropUse(const LocationDescription ,
Value *InteropVar,
-   llvm::Value *Device,
-   llvm::Value *NumDependences,
-   llvm::Value *DependenceAddress,
-   int HaveNowaitClause) {
+   Value *Device,
+   Value *NumDependences,
+   Value *DependenceAddress,
+   bool HaveNowaitClause) {
   IRBuilder<>::InsertPointGuard IPG(Builder);
   Builder.restoreIP(Loc.IP);
   Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
@@ -2248,9 +2248,9 @@
   if (Device == NULL)
 Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
   if (NumDependences == nullptr) {
-NumDependences = ConstantInt::get(M.getContext(), APInt(32, 0, true));
-PointerType *PointerTy_0 = llvm::Type::getInt8PtrTy(M.getContext());
-DependenceAddress = ConstantPointerNull::get(PointerTy_0);
+

[PATCH] D105876: OMPIRBuilder for Interop directive

2021-07-13 Thread Sri Hari Krishna Narayanan via Phabricator via cfe-commits
sriharikrishna created this revision.
sriharikrishna added reviewers: jdoerfert, ABataev, RaviNarayanaswamy.
Herald added a subscriber: hiraditya.
sriharikrishna requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

Implements the OMPIRBuilder portion for the
Interop directive.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105876

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/interop_irbuilder.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -2173,6 +2173,96 @@
   return Builder.CreateCall(Fn, Args, Name);
 }
 
+CallInst *OpenMPIRBuilder::createOMPInteropInit(const LocationDescription ,
+Value *InteropVar,
+OMPInteropType InteropType,
+llvm::Value *Device,
+llvm::Value *NumDependences,
+llvm::Value *DependenceAddress,
+int HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  ConstantInt *InteropTypeVal =
+  ConstantInt::get(M.getContext(), APInt(64, (int)InteropType, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(M.getContext(), APInt(32, 0, true));
+PointerType *PointerTy_0 = llvm::Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTy_0);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,   InteropVar,InteropTypeVal,
+  Device, NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_interop_init);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropDestroy(
+const LocationDescription , Value *InteropVar, llvm::Value *Device,
+llvm::Value *NumDependences, llvm::Value *DependenceAddress,
+int HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(M.getContext(), APInt(32, 0, true));
+PointerType *PointerTy_0 = llvm::Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTy_0);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {
+  Ident,  ThreadId,  InteropVar, Device,
+  NumDependences, DependenceAddress, HaveNowaitClauseVal};
+
+  Function *Fn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_interop_destroy);
+
+  return Builder.CreateCall(Fn, Args);
+}
+
+CallInst *OpenMPIRBuilder::createOMPInteropUse(const LocationDescription ,
+   Value *InteropVar,
+   llvm::Value *Device,
+   llvm::Value *NumDependences,
+   llvm::Value *DependenceAddress,
+   int HaveNowaitClause) {
+  IRBuilder<>::InsertPointGuard IPG(Builder);
+  Builder.restoreIP(Loc.IP);
+  Constant *SrcLocStr = getOrCreateSrcLocStr(Loc);
+  Value *Ident = getOrCreateIdent(SrcLocStr);
+  Value *ThreadId = getOrCreateThreadID(Ident);
+  if (Device == NULL)
+Device = ConstantInt::get(M.getContext(), APInt(32, -1, true));
+  if (NumDependences == nullptr) {
+NumDependences = ConstantInt::get(M.getContext(), APInt(32, 0, true));
+PointerType *PointerTy_0 = llvm::Type::getInt8PtrTy(M.getContext());
+DependenceAddress = ConstantPointerNull::get(PointerTy_0);
+  }
+  Value *HaveNowaitClauseVal =
+  ConstantInt::get(M.getContext(), APInt(32, HaveNowaitClause, true));
+  Value *Args[] = {