Undefined Behavior - 2020.2 English

Versal ACAP AI Engine Programming Environment User Guide (UG1076)

Document ID
UG1076
Release Date
2020-11-24
Version
2020.2 English

Using the restrict keyword improves performance as shown in the previous topic. However there are issues if the keyword is used inappropriately. The restrict child pointers must be used in a different block-level scope than the parent pointers, such as pointer p and q as shown in the following example.

Working Example 1

Figure 1. Use of restrict Keyword

Use of parent pointers in the same scope might break the restrict contract which produces an undefined behavior, such as pointers p and q in the following example.

Figure 2. Undefined Behavior

Working Example 2

This can also happen during the load operation, as shown in the green text in the following figure.

Figure 3. Load Operation

The undefined behavior occurs when the restrict pointers are used within the same scope, such as pointers p and q in the following example.

Figure 4. Restricted Pointers in Same Scope

Working Example with Inline Function

The first example code below shows the working inline function call, in which the pointer p and the pointer q are used in different scopes.

Figure 5. Inline Function Calls

The undefined behavior occurs when the restrict pointers are used within the same scope, such as pointers p and q in the following example.

Figure 6. Inline Function Calls - Same Scope