ManuelJBrito updated this revision to Diff 494024.
ManuelJBrito added a comment.

- set Invalid in type checking
- add builtin documentation
- add release note




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142388

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-nondet.c
  clang/test/CodeGen/builtins-nondeterministic-value.c

Index: clang/test/CodeGen/builtins-nondeterministic-value.c
===================================================================
--- clang/test/CodeGen/builtins-nondeterministic-value.c
+++ clang/test/CodeGen/builtins-nondeterministic-value.c
@@ -9,7 +9,7 @@
 // CHECK: store i32 [[X:%.*]], ptr [[A]], align 4
 // CHECK: [[R:%.*]] = freeze i32 poison
 // CHECK: ret i32 [[R]]
-  return __builtin_nondet(x);
+  return __builtin_nondeterministic_value(x);
 } 
 
 float clang_nondet_f( float x ) {
@@ -18,7 +18,7 @@
 // CHECK: store float [[X:%.*]], ptr [[A]], align 4
 // CHECK: [[R:%.*]] = freeze float poison
 // CHECK: ret float [[R]]
-  return __builtin_nondet(x);
+  return __builtin_nondeterministic_value(x);
 }
 
 double clang_nondet_d( double x ) {
@@ -27,7 +27,7 @@
 // CHECK: store double [[X:%.*]], ptr [[A]], align 8
 // CHECK: [[R:%.*]] = freeze double poison
 // CHECK: ret double [[R]]
-  return __builtin_nondet(x);
+  return __builtin_nondeterministic_value(x);
 } 
 
 _Bool clang_nondet_b( _Bool x) {
@@ -37,7 +37,7 @@
 // CHECK: store i8 [[B]], ptr [[A]], align 1
 // CHECK: [[R:%.*]] = freeze i1 poison
 // CHECK: ret i1 [[R]]
-  return __builtin_nondet(x);
+  return __builtin_nondeterministic_value(x);
 } 
 
 float4 clang_nondet_fv( float4 x ) {
@@ -46,7 +46,7 @@
 // CHECK: store <4 x float> [[X:%.*]], ptr [[A]], align 16
 // CHECK: [[R:%.*]] = freeze <4 x float> poison
 // CHECK: ret <4 x float> [[R]]
-  return __builtin_nondet(x);
+  return __builtin_nondeterministic_value(x);
 } 
 
 bool4 clang_nondet_bv( bool4 x ) {
@@ -57,6 +57,5 @@
 // CHECK: store i8 [[B]], ptr [[A]], align 1
 // CHECK: [[R:%.*]] = freeze <4 x i1> poison
 // CHECK: ret <4 x i1> [[R]]
-  return __builtin_nondet(x);
+  return __builtin_nondeterministic_value(x);
 } 
-
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2580,8 +2580,8 @@
     break;
   }
 
-  case Builtin::BI__builtin_nondet: {
-    if (SemaBuiltinNonDet(TheCall))
+  case Builtin::BI__builtin_nondeterministic_value: {
+    if (SemaBuiltinNonDeterministicValue(TheCall))
       return ExprError();
     break;
   }
@@ -17805,12 +17805,19 @@
   return false;
 }
 
-bool Sema::SemaBuiltinNonDet(CallExpr *TheCall) {
+bool Sema::SemaBuiltinNonDeterministicValue(CallExpr *TheCall) {
   if (checkArgCount(*this, TheCall, 1))
     return true;
 
   ExprResult Arg = TheCall->getArg(0);
   QualType TyArg = Arg.get()->getType();
+
+  if (!TyArg->isBuiltinType() && !TyArg->isVectorType()) {
+    Diag(TheCall->getArg(0)->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+           << 1 << /*vector, integer or floating point ty*/ 0 << TyArg;
+    return true;
+  }
+
   TheCall->setType(TyArg);
   return false;
 }
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3060,9 +3060,12 @@
     return RValue::get(V);
   }
 
-  case Builtin::BI__builtin_nondet: {
-    Value *Result = PoisonValue::get(ConvertType(E->getArg(0)->getType()));
+  case Builtin::BI__builtin_nondeterministic_value: {
+    llvm::Type *Ty = ConvertType(E->getArg(0)->getType()); 
+
+    Value *Result = PoisonValue::get(Ty);
     Result = Builder.CreateFreeze(Result);
+
     return RValue::get(Result);
   }
 
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -13529,7 +13529,7 @@
   bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall);
   bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall);
 
-  bool SemaBuiltinNonDet(CallExpr *TheCall);
+  bool SemaBuiltinNonDeterministicValue(CallExpr *TheCall);
 
   // Matrix builtin handling.
   ExprResult SemaBuiltinMatrixTranspose(CallExpr *TheCall,
Index: clang/include/clang/Basic/Builtins.def
===================================================================
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -655,7 +655,7 @@
 BUILTIN(__builtin_alloca_with_align, "v*zIz", "Fn")
 BUILTIN(__builtin_alloca_with_align_uninitialized, "v*zIz", "Fn")
 BUILTIN(__builtin_call_with_static_chain, "v.", "nt")
-BUILTIN(__builtin_nondet, "v.", "nt")
+BUILTIN(__builtin_nondeterministic_value, "v.", "nt")
 
 BUILTIN(__builtin_elementwise_abs, "v.", "nct")
 BUILTIN(__builtin_elementwise_max, "v.", "nct")
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -508,6 +508,8 @@
   ``#pragma unused``.
 - Now diagnoses use of a member access expression or array subscript expression
   within ``__builtin_offsetof`` and ``offsetof`` as being a Clang extension.
+- Clang now supports ``__builtin_nondeterministic_value`` that returns a 
+  nondeterministic value of the same type as the provided argument.
 
 New Compiler Flags
 ------------------
Index: clang/docs/LanguageExtensions.rst
===================================================================
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -3081,6 +3081,32 @@
 
 Query for this feature with ``__has_builtin(__builtin_trap)``.
 
+``__builtin_nondeterministic_value``
+------------------------------------
+
+``__builtin_nondeterministic_value`` returns a valid nondeterministic value of the same type as the provided argument.
+
+**Syntax**:
+
+.. code-block:: c++
+
+    type __builtin_nondeterministic_value(type x)
+
+**Examples**:
+
+.. code-block:: c++
+
+    int x = __builtin_nondeterministic_value(x);
+    float y = __builtin_nondeterministic_value(y);
+    __m256i a = __builtin_nondeterministic_value(a);
+
+**Description**
+
+Each call to ``__builtin_nondeterministic_value`` returns a valid value of the type given by the argument.
+
+The types currently supported are: integer types, floating-point types, vector types.
+
+Query for this feature with ``__has_builtin(__builtin_nondeterministic_value)``.
 
 ``__builtin_sycl_unique_stable_name``
 -------------------------------------
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to